]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 #define mm2inches 0.0393700787402
27 #define inches2mm 25.4
28 #define mm2twips 56.6929133859
29 #define twips2mm 0.0176388888889
30 #define mm2pt 2.83464566929
31 #define pt2mm 0.352777777778
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
51 m_internalDeviceOriginX
= 0;
52 m_internalDeviceOriginY
= 0;
53 m_externalDeviceOriginX
= 0;
54 m_externalDeviceOriginY
= 0;
56 m_logicalScaleX
= 1.0;
57 m_logicalScaleY
= 1.0;
63 m_mappingMode
= MM_TEXT
;
64 m_needComputeScaleX
= FALSE
;
65 m_needComputeScaleY
= FALSE
;
67 m_signX
= 1; // default x-axis left to right
68 m_signY
= 1; // default y-axis top down
70 m_maxX
= m_maxY
= -100000;
71 m_minY
= m_minY
= 100000;
73 m_logicalFunction
= wxCOPY
;
74 // m_textAlignment = wxALIGN_TOP_LEFT;
75 m_backgroundMode
= wxTRANSPARENT
;
77 m_textForegroundColour
= *wxBLACK
;
78 m_textBackgroundColour
= *wxWHITE
;
80 m_font
= *wxNORMAL_FONT
;
81 m_brush
= *wxTRANSPARENT_BRUSH
;
82 m_backgroundBrush
= *wxWHITE_BRUSH
;
84 m_isInteractive
= FALSE
;
86 // m_palette = wxAPP_COLOURMAP;
93 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
97 void wxDC::DrawPoint( wxPoint
& point
)
99 DrawPoint( point
.x
, point
.y
);
102 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
104 int n
= list
->Number();
105 wxPoint
*points
= new wxPoint
[n
];
108 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
110 wxPoint
*point
= (wxPoint
*)node
->Data();
111 points
[i
].x
= point
->x
;
112 points
[i
++].y
= point
->y
;
114 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
118 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
120 int n
= list
->Number();
121 wxPoint
*points
= new wxPoint
[n
];
124 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
126 wxPoint
*point
= (wxPoint
*)node
->Data();
127 points
[i
].x
= point
->x
;
128 points
[i
++].y
= point
->y
;
130 DrawLines( n
, points
, xoffset
, yoffset
);
134 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
137 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
138 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
139 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
141 wxNode
*node
= list
.First();
144 wxPoint
*p
= (wxPoint
*)node
->Data();
150 void wxDC::DrawSpline( wxList
*points
)
152 DrawOpenSpline( points
);
155 void wxDC::DrawSpline( int n
, wxPoint points
[] )
158 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
162 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
167 m_clipX2
= x
+ width
;
168 m_clipY2
= y
+ height
;
171 void wxDC::DestroyClippingRegion(void)
176 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
180 if (x
) *x
= m_clipX1
;
181 if (y
) *y
= m_clipY1
;
182 if (width
) *width
= (m_clipX2
- m_clipX1
);
183 if (height
) *height
= (m_clipY2
- m_clipY1
);
186 *x
= *y
= *width
= *height
= 0;
189 void wxDC::GetSize( int* width
, int* height
) const
191 *width
= m_maxX
-m_minX
;
192 *height
= m_maxY
-m_minY
;
195 void wxDC::GetSizeMM( long* width
, long* height
) const
200 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
201 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
204 void wxDC::SetTextForeground( const wxColour
&col
)
207 m_textForegroundColour
= col
;
210 void wxDC::SetTextBackground( const wxColour
&col
)
213 m_textBackgroundColour
= col
;
216 void wxDC::SetMapMode( int mode
)
221 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
224 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
227 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
230 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
234 SetLogicalScale( 1.0, 1.0 );
239 m_needComputeScaleX
= TRUE
;
240 m_needComputeScaleY
= TRUE
;
244 void wxDC::SetUserScale( double x
, double y
)
246 // allow negative ? -> no
249 ComputeScaleAndOrigin();
252 void wxDC::GetUserScale( double *x
, double *y
)
254 if (x
) *x
= m_userScaleX
;
255 if (y
) *y
= m_userScaleY
;
258 void wxDC::SetLogicalScale( double x
, double y
)
263 ComputeScaleAndOrigin();
266 void wxDC::GetLogicalScale( double *x
, double *y
)
268 if (x
) *x
= m_logicalScaleX
;
269 if (y
) *y
= m_logicalScaleY
;
272 void wxDC::SetLogicalOrigin( long x
, long y
)
274 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
275 m_logicalOriginY
= y
* m_signY
;
276 ComputeScaleAndOrigin();
279 void wxDC::GetLogicalOrigin( long *x
, long *y
)
281 if (x
) *x
= m_logicalOriginX
;
282 if (y
) *y
= m_logicalOriginY
;
285 void wxDC::SetDeviceOrigin( long x
, long y
)
287 m_externalDeviceOriginX
= x
;
288 m_externalDeviceOriginY
= y
;
289 ComputeScaleAndOrigin();
292 void wxDC::GetDeviceOrigin( long *x
, long *y
)
294 // if (x) *x = m_externalDeviceOriginX;
295 // if (y) *y = m_externalDeviceOriginY;
296 if (x
) *x
= m_deviceOriginX
;
297 if (y
) *y
= m_deviceOriginY
;
300 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
302 m_internalDeviceOriginX
= x
;
303 m_internalDeviceOriginY
= y
;
304 ComputeScaleAndOrigin();
307 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
309 if (x
) *x
= m_internalDeviceOriginX
;
310 if (y
) *y
= m_internalDeviceOriginY
;
313 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
315 m_signX
= (xLeftRight
? 1 : -1);
316 m_signY
= (yBottomUp
? -1 : 1);
317 ComputeScaleAndOrigin();
320 long wxDC::DeviceToLogicalX(long x
) const
325 long wxDC::DeviceToLogicalY(long y
) const
330 long wxDC::DeviceToLogicalXRel(long x
) const
332 return XDEV2LOGREL(x
);
335 long wxDC::DeviceToLogicalYRel(long y
) const
337 return YDEV2LOGREL(y
);
340 long wxDC::LogicalToDeviceX(long x
) const
345 long wxDC::LogicalToDeviceY(long y
) const
350 long wxDC::LogicalToDeviceXRel(long x
) const
352 return XLOG2DEVREL(x
);
355 long wxDC::LogicalToDeviceYRel(long y
) const
357 return YLOG2DEVREL(y
);
360 void wxDC::CalcBoundingBox( long x
, long y
)
362 if (x
< m_minX
) m_minX
= x
;
363 if (y
< m_minY
) m_minY
= y
;
364 if (x
> m_maxX
) m_maxX
= x
;
365 if (y
> m_maxY
) m_maxY
= y
;
368 void wxDC::ComputeScaleAndOrigin(void)
370 // CMB: copy scale to see if it changes
371 double origScaleX
= m_scaleX
;
372 double origScaleY
= m_scaleY
;
374 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
375 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
377 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
378 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
380 // CMB: if scale has changed call SetPen to recalulate the line width
381 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
383 // this is a bit artificial, but we need to force wxDC to think
384 // the pen has changed
385 wxPen
* pen
= GetPen();