]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxObject
)
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 #define mm2inches 0.0393700787402
25 #define inches2mm 25.4
26 #define mm2twips 56.6929133859
27 #define twips2mm 0.0176388888889
28 #define mm2pt 2.83464566929
29 #define pt2mm 0.352777777778
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
39 m_autoSetting
= FALSE
;
50 m_internalDeviceOriginX
= 0;
51 m_internalDeviceOriginY
= 0;
52 m_externalDeviceOriginX
= 0;
53 m_externalDeviceOriginY
= 0;
55 m_logicalScaleX
= 1.0;
56 m_logicalScaleY
= 1.0;
62 m_mappingMode
= wxMM_TEXT
;
63 m_needComputeScaleX
= FALSE
;
64 m_needComputeScaleY
= FALSE
;
66 m_signX
= 1; // default x-axis left to right
67 m_signY
= 1; // default y-axis top down
69 m_maxX
= m_maxY
= -100000;
70 m_minY
= m_minY
= 100000;
72 m_logicalFunction
= wxCOPY
;
73 // m_textAlignment = wxALIGN_TOP_LEFT;
74 m_backgroundMode
= wxTRANSPARENT
;
76 m_textForegroundColour
= *wxBLACK
;
77 m_textBackgroundColour
= *wxWHITE
;
79 m_font
= *wxNORMAL_FONT
;
80 m_brush
= *wxTRANSPARENT_BRUSH
;
81 m_backgroundBrush
= *wxWHITE_BRUSH
;
83 // m_palette = wxAPP_COLOURMAP;
90 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
94 void wxDC::DrawPoint( wxPoint
& point
)
96 DrawPoint( point
.x
, point
.y
);
99 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
101 int n
= list
->Number();
102 wxPoint
*points
= new wxPoint
[n
];
105 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
107 wxPoint
*point
= (wxPoint
*)node
->Data();
108 points
[i
].x
= point
->x
;
109 points
[i
++].y
= point
->y
;
111 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
115 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
117 int n
= list
->Number();
118 wxPoint
*points
= new wxPoint
[n
];
121 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
123 wxPoint
*point
= (wxPoint
*)node
->Data();
124 points
[i
].x
= point
->x
;
125 points
[i
++].y
= point
->y
;
127 DrawLines( n
, points
, xoffset
, yoffset
);
131 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
134 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
135 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
136 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
138 wxNode
*node
= list
.First();
141 wxPoint
*p
= (wxPoint
*)node
->Data();
147 void wxDC::DrawSpline( int n
, wxPoint points
[] )
150 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
154 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
159 m_clipX2
= x
+ width
;
160 m_clipY2
= y
+ height
;
163 void wxDC::DestroyClippingRegion(void)
168 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
172 if (x
) *x
= m_clipX1
;
173 if (y
) *y
= m_clipY1
;
174 if (width
) *width
= (m_clipX2
- m_clipX1
);
175 if (height
) *height
= (m_clipY2
- m_clipY1
);
178 *x
= *y
= *width
= *height
= 0;
181 void wxDC::GetSize( int* width
, int* height
) const
183 *width
= m_maxX
-m_minX
;
184 *height
= m_maxY
-m_minY
;
187 void wxDC::GetSizeMM( long* width
, long* height
) const
192 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
193 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
196 void wxDC::SetTextForeground( const wxColour
&col
)
199 m_textForegroundColour
= col
;
202 void wxDC::SetTextBackground( const wxColour
&col
)
205 m_textBackgroundColour
= col
;
208 void wxDC::SetMapMode( int mode
)
213 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
216 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
219 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
222 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
226 SetLogicalScale( 1.0, 1.0 );
229 if (mode
!= wxMM_TEXT
)
231 m_needComputeScaleX
= TRUE
;
232 m_needComputeScaleY
= TRUE
;
236 void wxDC::SetUserScale( double x
, double y
)
238 // allow negative ? -> no
241 ComputeScaleAndOrigin();
244 void wxDC::GetUserScale( double *x
, double *y
)
246 if (x
) *x
= m_userScaleX
;
247 if (y
) *y
= m_userScaleY
;
250 void wxDC::SetLogicalScale( double x
, double y
)
255 ComputeScaleAndOrigin();
258 void wxDC::GetLogicalScale( double *x
, double *y
)
260 if (x
) *x
= m_logicalScaleX
;
261 if (y
) *y
= m_logicalScaleY
;
264 void wxDC::SetLogicalOrigin( long x
, long y
)
266 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
267 m_logicalOriginY
= y
* m_signY
;
268 ComputeScaleAndOrigin();
271 void wxDC::GetLogicalOrigin( long *x
, long *y
)
273 if (x
) *x
= m_logicalOriginX
;
274 if (y
) *y
= m_logicalOriginY
;
277 void wxDC::SetDeviceOrigin( long x
, long y
)
279 m_externalDeviceOriginX
= x
;
280 m_externalDeviceOriginY
= y
;
281 ComputeScaleAndOrigin();
284 void wxDC::GetDeviceOrigin( long *x
, long *y
)
286 // if (x) *x = m_externalDeviceOriginX;
287 // if (y) *y = m_externalDeviceOriginY;
288 if (x
) *x
= m_deviceOriginX
;
289 if (y
) *y
= m_deviceOriginY
;
292 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
294 m_internalDeviceOriginX
= x
;
295 m_internalDeviceOriginY
= y
;
296 ComputeScaleAndOrigin();
299 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
301 if (x
) *x
= m_internalDeviceOriginX
;
302 if (y
) *y
= m_internalDeviceOriginY
;
305 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
307 m_signX
= (xLeftRight
? 1 : -1);
308 m_signY
= (yBottomUp
? -1 : 1);
309 ComputeScaleAndOrigin();
312 long wxDC::DeviceToLogicalX(long x
) const
317 long wxDC::DeviceToLogicalY(long y
) const
322 long wxDC::DeviceToLogicalXRel(long x
) const
324 return XDEV2LOGREL(x
);
327 long wxDC::DeviceToLogicalYRel(long y
) const
329 return YDEV2LOGREL(y
);
332 long wxDC::LogicalToDeviceX(long x
) const
337 long wxDC::LogicalToDeviceY(long y
) const
342 long wxDC::LogicalToDeviceXRel(long x
) const
344 return XLOG2DEVREL(x
);
347 long wxDC::LogicalToDeviceYRel(long y
) const
349 return YLOG2DEVREL(y
);
352 void wxDC::CalcBoundingBox( long x
, long y
)
354 if (x
< m_minX
) m_minX
= x
;
355 if (y
< m_minY
) m_minY
= y
;
356 if (x
> m_maxX
) m_maxX
= x
;
357 if (y
> m_maxY
) m_maxY
= y
;
360 void wxDC::ComputeScaleAndOrigin(void)
362 // CMB: copy scale to see if it changes
363 double origScaleX
= m_scaleX
;
364 double origScaleY
= m_scaleY
;
366 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
367 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
369 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
370 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
372 // CMB: if scale has changed call SetPen to recalulate the line width
373 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
375 // this is a bit artificial, but we need to force wxDC to think
376 // the pen has changed
377 wxPen
* pen
= & GetPen();