]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/dc.cpp
4cfe7305cc064d5075db6648e26af22e27b31ef3
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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 //-----------------------------------------------------------------------------
37 IMPLEMENT_ABSTRACT_CLASS(wxDC
,wxObject
)
43 m_autoSetting
= FALSE
;
54 m_internalDeviceOriginX
= 0;
55 m_internalDeviceOriginY
= 0;
56 m_externalDeviceOriginX
= 0;
57 m_externalDeviceOriginY
= 0;
59 m_logicalScaleX
= 1.0;
60 m_logicalScaleY
= 1.0;
66 m_mappingMode
= MM_TEXT
;
67 m_needComputeScaleX
= FALSE
;
68 m_needComputeScaleY
= FALSE
;
70 m_signX
= 1; // default x-axis left to right
71 m_signY
= 1; // default y-axis top down
73 m_maxX
= m_maxY
= -100000;
74 m_minY
= m_minY
= 100000;
76 m_logicalFunction
= wxCOPY
;
77 // m_textAlignment = wxALIGN_TOP_LEFT;
78 m_backgroundMode
= wxTRANSPARENT
;
80 m_textForegroundColour
= *wxBLACK
;
81 m_textBackgroundColour
= *wxWHITE
;
83 m_font
= *wxNORMAL_FONT
;
84 m_brush
= *wxTRANSPARENT_BRUSH
;
85 m_backgroundBrush
= *wxWHITE_BRUSH
;
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::DrawPoint( wxPoint
& point
)
100 DrawPoint( point
.x
, point
.y
);
103 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
105 int n
= list
->Number();
106 wxPoint
*points
= new wxPoint
[n
];
109 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
111 wxPoint
*point
= (wxPoint
*)node
->Data();
112 points
[i
].x
= point
->x
;
113 points
[i
++].y
= point
->y
;
115 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
119 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
121 int n
= list
->Number();
122 wxPoint
*points
= new wxPoint
[n
];
125 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
127 wxPoint
*point
= (wxPoint
*)node
->Data();
128 points
[i
].x
= point
->x
;
129 points
[i
++].y
= point
->y
;
131 DrawLines( n
, points
, xoffset
, yoffset
);
135 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
138 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
139 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
140 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
142 wxNode
*node
= list
.First();
145 wxPoint
*p
= (wxPoint
*)node
->Data();
151 void wxDC::DrawSpline( wxList
*points
)
153 DrawOpenSpline( points
);
156 void wxDC::DrawSpline( int n
, wxPoint points
[] )
159 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
163 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
168 m_clipX2
= x
+ width
;
169 m_clipY2
= y
+ height
;
172 void wxDC::DestroyClippingRegion(void)
177 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
181 if (x
) *x
= m_clipX1
;
182 if (y
) *y
= m_clipY1
;
183 if (width
) *width
= (m_clipX2
- m_clipX1
);
184 if (height
) *height
= (m_clipY2
- m_clipY1
);
187 *x
= *y
= *width
= *height
= 0;
190 void wxDC::GetSize( int* width
, int* height
) const
192 *width
= m_maxX
-m_minX
;
193 *height
= m_maxY
-m_minY
;
196 void wxDC::GetSizeMM( long* width
, long* height
) const
201 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
202 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
205 void wxDC::SetTextForeground( const wxColour
&col
)
208 m_textForegroundColour
= col
;
211 void wxDC::SetTextBackground( const wxColour
&col
)
214 m_textBackgroundColour
= col
;
217 void wxDC::SetMapMode( int mode
)
222 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
225 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
228 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
231 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
235 SetLogicalScale( 1.0, 1.0 );
240 m_needComputeScaleX
= TRUE
;
241 m_needComputeScaleY
= TRUE
;
245 void wxDC::SetUserScale( double x
, double y
)
247 // allow negative ? -> no
250 ComputeScaleAndOrigin();
253 void wxDC::GetUserScale( double *x
, double *y
)
255 if (x
) *x
= m_userScaleX
;
256 if (y
) *y
= m_userScaleY
;
259 void wxDC::SetLogicalScale( double x
, double y
)
264 ComputeScaleAndOrigin();
267 void wxDC::GetLogicalScale( double *x
, double *y
)
269 if (x
) *x
= m_logicalScaleX
;
270 if (y
) *y
= m_logicalScaleY
;
273 void wxDC::SetLogicalOrigin( long x
, long y
)
275 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
276 m_logicalOriginY
= y
* m_signY
;
277 ComputeScaleAndOrigin();
280 void wxDC::GetLogicalOrigin( long *x
, long *y
)
282 if (x
) *x
= m_logicalOriginX
;
283 if (y
) *y
= m_logicalOriginY
;
286 void wxDC::SetDeviceOrigin( long x
, long y
)
288 m_externalDeviceOriginX
= x
;
289 m_externalDeviceOriginY
= y
;
290 ComputeScaleAndOrigin();
293 void wxDC::GetDeviceOrigin( long *x
, long *y
)
295 // if (x) *x = m_externalDeviceOriginX;
296 // if (y) *y = m_externalDeviceOriginY;
297 if (x
) *x
= m_deviceOriginX
;
298 if (y
) *y
= m_deviceOriginY
;
301 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
303 m_internalDeviceOriginX
= x
;
304 m_internalDeviceOriginY
= y
;
305 ComputeScaleAndOrigin();
308 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
310 if (x
) *x
= m_internalDeviceOriginX
;
311 if (y
) *y
= m_internalDeviceOriginY
;
314 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
316 m_signX
= (xLeftRight
? 1 : -1);
317 m_signY
= (yBottomUp
? -1 : 1);
318 ComputeScaleAndOrigin();
321 long wxDC::DeviceToLogicalX(long x
) const
326 long wxDC::DeviceToLogicalY(long y
) const
331 long wxDC::DeviceToLogicalXRel(long x
) const
333 return XDEV2LOGREL(x
);
336 long wxDC::DeviceToLogicalYRel(long y
) const
338 return YDEV2LOGREL(y
);
341 long wxDC::LogicalToDeviceX(long x
) const
346 long wxDC::LogicalToDeviceY(long y
) const
351 long wxDC::LogicalToDeviceXRel(long x
) const
353 return XLOG2DEVREL(x
);
356 long wxDC::LogicalToDeviceYRel(long y
) const
358 return YLOG2DEVREL(y
);
361 void wxDC::CalcBoundingBox( long x
, long y
)
363 if (x
< m_minX
) m_minX
= x
;
364 if (y
< m_minY
) m_minY
= y
;
365 if (x
> m_maxX
) m_maxX
= x
;
366 if (y
> m_maxY
) m_maxY
= y
;
369 void wxDC::ComputeScaleAndOrigin(void)
371 // CMB: copy scale to see if it changes
372 double origScaleX
= m_scaleX
;
373 double origScaleY
= m_scaleY
;
375 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
376 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
378 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
379 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
381 // CMB: if scale has changed call SetPen to recalulate the line width
382 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
384 // this is a bit artificial, but we need to force wxDC to think
385 // the pen has changed
386 wxPen
* pen
= GetPen();