]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/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 //-----------------------------------------------------------------------------
35 IMPLEMENT_ABSTRACT_CLASS(wxDC
,wxObject
)
41 m_autoSetting
= FALSE
;
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
= wxMM_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_palette = wxAPP_COLOURMAP;
92 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
96 void wxDC::DrawPoint( wxPoint
& point
)
98 DrawPoint( point
.x
, point
.y
);
101 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
103 int n
= list
->Number();
104 wxPoint
*points
= new wxPoint
[n
];
107 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
109 wxPoint
*point
= (wxPoint
*)node
->Data();
110 points
[i
].x
= point
->x
;
111 points
[i
++].y
= point
->y
;
113 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
117 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
119 int n
= list
->Number();
120 wxPoint
*points
= new wxPoint
[n
];
123 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
125 wxPoint
*point
= (wxPoint
*)node
->Data();
126 points
[i
].x
= point
->x
;
127 points
[i
++].y
= point
->y
;
129 DrawLines( n
, points
, xoffset
, yoffset
);
133 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
136 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
137 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
138 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
140 wxNode
*node
= list
.First();
143 wxPoint
*p
= (wxPoint
*)node
->Data();
149 void wxDC::DrawSpline( wxList
*points
)
151 DrawOpenSpline( points
);
154 void wxDC::DrawSpline( int n
, wxPoint points
[] )
157 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
161 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
166 m_clipX2
= x
+ width
;
167 m_clipY2
= y
+ height
;
170 void wxDC::DestroyClippingRegion(void)
175 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
179 if (x
) *x
= m_clipX1
;
180 if (y
) *y
= m_clipY1
;
181 if (width
) *width
= (m_clipX2
- m_clipX1
);
182 if (height
) *height
= (m_clipY2
- m_clipY1
);
185 *x
= *y
= *width
= *height
= 0;
188 void wxDC::GetSize( int* width
, int* height
) const
190 *width
= m_maxX
-m_minX
;
191 *height
= m_maxY
-m_minY
;
194 void wxDC::GetSizeMM( long* width
, long* height
) const
199 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
200 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
203 void wxDC::SetTextForeground( const wxColour
&col
)
206 m_textForegroundColour
= col
;
209 void wxDC::SetTextBackground( const wxColour
&col
)
212 m_textBackgroundColour
= col
;
215 void wxDC::SetMapMode( int mode
)
220 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
223 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
226 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
229 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
233 SetLogicalScale( 1.0, 1.0 );
236 if (mode
!= wxMM_TEXT
)
238 m_needComputeScaleX
= TRUE
;
239 m_needComputeScaleY
= TRUE
;
243 void wxDC::SetUserScale( double x
, double y
)
245 // allow negative ? -> no
248 ComputeScaleAndOrigin();
251 void wxDC::GetUserScale( double *x
, double *y
)
253 if (x
) *x
= m_userScaleX
;
254 if (y
) *y
= m_userScaleY
;
257 void wxDC::SetLogicalScale( double x
, double y
)
262 ComputeScaleAndOrigin();
265 void wxDC::GetLogicalScale( double *x
, double *y
)
267 if (x
) *x
= m_logicalScaleX
;
268 if (y
) *y
= m_logicalScaleY
;
271 void wxDC::SetLogicalOrigin( long x
, long y
)
273 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
274 m_logicalOriginY
= y
* m_signY
;
275 ComputeScaleAndOrigin();
278 void wxDC::GetLogicalOrigin( long *x
, long *y
)
280 if (x
) *x
= m_logicalOriginX
;
281 if (y
) *y
= m_logicalOriginY
;
284 void wxDC::SetDeviceOrigin( long x
, long y
)
286 m_externalDeviceOriginX
= x
;
287 m_externalDeviceOriginY
= y
;
288 ComputeScaleAndOrigin();
291 void wxDC::GetDeviceOrigin( long *x
, long *y
)
293 // if (x) *x = m_externalDeviceOriginX;
294 // if (y) *y = m_externalDeviceOriginY;
295 if (x
) *x
= m_deviceOriginX
;
296 if (y
) *y
= m_deviceOriginY
;
299 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
301 m_internalDeviceOriginX
= x
;
302 m_internalDeviceOriginY
= y
;
303 ComputeScaleAndOrigin();
306 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
308 if (x
) *x
= m_internalDeviceOriginX
;
309 if (y
) *y
= m_internalDeviceOriginY
;
312 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
314 m_signX
= (xLeftRight
? 1 : -1);
315 m_signY
= (yBottomUp
? -1 : 1);
316 ComputeScaleAndOrigin();
319 long wxDC::DeviceToLogicalX(long x
) const
324 long wxDC::DeviceToLogicalY(long y
) const
329 long wxDC::DeviceToLogicalXRel(long x
) const
331 return XDEV2LOGREL(x
);
334 long wxDC::DeviceToLogicalYRel(long y
) const
336 return YDEV2LOGREL(y
);
339 long wxDC::LogicalToDeviceX(long x
) const
344 long wxDC::LogicalToDeviceY(long y
) const
349 long wxDC::LogicalToDeviceXRel(long x
) const
351 return XLOG2DEVREL(x
);
354 long wxDC::LogicalToDeviceYRel(long y
) const
356 return YLOG2DEVREL(y
);
359 void wxDC::CalcBoundingBox( long x
, long y
)
361 if (x
< m_minX
) m_minX
= x
;
362 if (y
< m_minY
) m_minY
= y
;
363 if (x
> m_maxX
) m_maxX
= x
;
364 if (y
> m_maxY
) m_maxY
= y
;
367 void wxDC::ComputeScaleAndOrigin(void)
369 // CMB: copy scale to see if it changes
370 double origScaleX
= m_scaleX
;
371 double origScaleY
= m_scaleY
;
373 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
374 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
376 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
377 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
379 // CMB: if scale has changed call SetPen to recalulate the line width
380 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
382 // this is a bit artificial, but we need to force wxDC to think
383 // the pen has changed
384 wxPen
* pen
= GetPen();