]>
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"
17 #include "wx/dcmemory.h"
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
23 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
27 #define mm2inches 0.0393700787402
28 #define inches2mm 25.4
29 #define mm2twips 56.6929133859
30 #define twips2mm 0.0176388888889
31 #define mm2pt 2.83464566929
32 #define pt2mm 0.352777777778
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
52 m_internalDeviceOriginX
= 0;
53 m_internalDeviceOriginY
= 0;
54 m_externalDeviceOriginX
= 0;
55 m_externalDeviceOriginY
= 0;
57 m_logicalScaleX
= 1.0;
58 m_logicalScaleY
= 1.0;
64 m_mappingMode
= MM_TEXT
;
65 m_needComputeScaleX
= FALSE
;
66 m_needComputeScaleY
= FALSE
;
68 m_signX
= 1; // default x-axis left to right
69 m_signY
= 1; // default y-axis top down
71 m_maxX
= m_maxY
= -100000;
72 m_minY
= m_minY
= 100000;
74 m_logicalFunction
= wxCOPY
;
75 // m_textAlignment = wxALIGN_TOP_LEFT;
76 m_backgroundMode
= wxTRANSPARENT
;
78 m_textForegroundColour
= *wxBLACK
;
79 m_textBackgroundColour
= *wxWHITE
;
81 m_font
= *wxNORMAL_FONT
;
82 m_brush
= *wxTRANSPARENT_BRUSH
;
83 m_backgroundBrush
= *wxWHITE_BRUSH
;
85 m_isInteractive
= FALSE
;
87 // m_palette = wxAPP_COLOURMAP;
94 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
98 void wxDC::DrawBitmap( const wxBitmap
& bitmap
, long x
, long y
, bool useMask
)
104 memDC
.SelectObject(bitmap
);
106 /* Not sure if we need this. The mask should leave the
107 * masked areas as per the original background of this DC.
110 // There might be transparent areas, so make these
111 // the same colour as this DC
112 memDC.SetBackground(* GetBackground());
117 Blit(x
, y
, bitmap
.GetWidth(), bitmap
.GetHeight(), & memDC
, 0, 0, wxCOPY
, useMask
);
119 memDC
.SelectObject(wxNullBitmap
);
123 void wxDC::DrawPoint( wxPoint
& point
)
125 DrawPoint( point
.x
, point
.y
);
128 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
130 int n
= list
->Number();
131 wxPoint
*points
= new wxPoint
[n
];
134 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
136 wxPoint
*point
= (wxPoint
*)node
->Data();
137 points
[i
].x
= point
->x
;
138 points
[i
++].y
= point
->y
;
140 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
144 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
146 int n
= list
->Number();
147 wxPoint
*points
= new wxPoint
[n
];
150 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
152 wxPoint
*point
= (wxPoint
*)node
->Data();
153 points
[i
].x
= point
->x
;
154 points
[i
++].y
= point
->y
;
156 DrawLines( n
, points
, xoffset
, yoffset
);
160 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
163 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
164 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
165 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
167 wxNode
*node
= list
.First();
170 wxPoint
*p
= (wxPoint
*)node
->Data();
176 void wxDC::DrawSpline( int n
, wxPoint points
[] )
179 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
183 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
188 m_clipX2
= x
+ width
;
189 m_clipY2
= y
+ height
;
192 void wxDC::DestroyClippingRegion(void)
197 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
201 if (x
) *x
= m_clipX1
;
202 if (y
) *y
= m_clipY1
;
203 if (width
) *width
= (m_clipX2
- m_clipX1
);
204 if (height
) *height
= (m_clipY2
- m_clipY1
);
207 *x
= *y
= *width
= *height
= 0;
210 void wxDC::GetSize( int* width
, int* height
) const
212 *width
= m_maxX
-m_minX
;
213 *height
= m_maxY
-m_minY
;
216 void wxDC::GetSizeMM( long* width
, long* height
) const
221 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
222 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
225 void wxDC::SetTextForeground( const wxColour
&col
)
228 m_textForegroundColour
= col
;
231 void wxDC::SetTextBackground( const wxColour
&col
)
234 m_textBackgroundColour
= col
;
237 void wxDC::SetMapMode( int mode
)
242 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
245 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
248 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
251 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
255 SetLogicalScale( 1.0, 1.0 );
260 m_needComputeScaleX
= TRUE
;
261 m_needComputeScaleY
= TRUE
;
265 void wxDC::SetUserScale( double x
, double y
)
267 // allow negative ? -> no
270 ComputeScaleAndOrigin();
273 void wxDC::GetUserScale( double *x
, double *y
)
275 if (x
) *x
= m_userScaleX
;
276 if (y
) *y
= m_userScaleY
;
279 void wxDC::SetLogicalScale( double x
, double y
)
284 ComputeScaleAndOrigin();
287 void wxDC::GetLogicalScale( double *x
, double *y
)
289 if (x
) *x
= m_logicalScaleX
;
290 if (y
) *y
= m_logicalScaleY
;
293 void wxDC::SetLogicalOrigin( long x
, long y
)
295 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
296 m_logicalOriginY
= y
* m_signY
;
297 ComputeScaleAndOrigin();
300 void wxDC::GetLogicalOrigin( long *x
, long *y
)
302 if (x
) *x
= m_logicalOriginX
;
303 if (y
) *y
= m_logicalOriginY
;
306 void wxDC::SetDeviceOrigin( long x
, long y
)
308 m_externalDeviceOriginX
= x
;
309 m_externalDeviceOriginY
= y
;
310 ComputeScaleAndOrigin();
313 void wxDC::GetDeviceOrigin( long *x
, long *y
)
315 // if (x) *x = m_externalDeviceOriginX;
316 // if (y) *y = m_externalDeviceOriginY;
317 if (x
) *x
= m_deviceOriginX
;
318 if (y
) *y
= m_deviceOriginY
;
321 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
323 m_internalDeviceOriginX
= x
;
324 m_internalDeviceOriginY
= y
;
325 ComputeScaleAndOrigin();
328 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
330 if (x
) *x
= m_internalDeviceOriginX
;
331 if (y
) *y
= m_internalDeviceOriginY
;
334 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
336 m_signX
= (xLeftRight
? 1 : -1);
337 m_signY
= (yBottomUp
? -1 : 1);
338 ComputeScaleAndOrigin();
341 long wxDC::DeviceToLogicalX(long x
) const
346 long wxDC::DeviceToLogicalY(long y
) const
351 long wxDC::DeviceToLogicalXRel(long x
) const
353 return XDEV2LOGREL(x
);
356 long wxDC::DeviceToLogicalYRel(long y
) const
358 return YDEV2LOGREL(y
);
361 long wxDC::LogicalToDeviceX(long x
) const
366 long wxDC::LogicalToDeviceY(long y
) const
371 long wxDC::LogicalToDeviceXRel(long x
) const
373 return XLOG2DEVREL(x
);
376 long wxDC::LogicalToDeviceYRel(long y
) const
378 return YLOG2DEVREL(y
);
381 void wxDC::CalcBoundingBox( long x
, long y
)
383 if (x
< m_minX
) m_minX
= x
;
384 if (y
< m_minY
) m_minY
= y
;
385 if (x
> m_maxX
) m_maxX
= x
;
386 if (y
> m_maxY
) m_maxY
= y
;
389 void wxDC::ComputeScaleAndOrigin(void)
391 // CMB: copy scale to see if it changes
392 double origScaleX
= m_scaleX
;
393 double origScaleY
= m_scaleY
;
395 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
396 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
398 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
399 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
401 // CMB: if scale has changed call SetPen to recalulate the line width
402 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
404 // this is a bit artificial, but we need to force wxDC to think
405 // the pen has changed
406 wxPen
* pen
= GetPen();