]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "dc.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 #define mm2inches 0.0393700787402
23 #define inches2mm 25.4
24 #define mm2twips 56.6929133859
25 #define twips2mm 0.0176388888889
26 #define mm2pt 2.83464566929
27 #define pt2mm 0.352777777778
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 IMPLEMENT_ABSTRACT_CLASS(wxDC
,wxObject
)
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
= MM_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::DrawArc( long WXUNUSED(x1
), long WXUNUSED(y1
), long WXUNUSED(x2
), long WXUNUSED(y2
),
91 double WXUNUSED(xc
), double WXUNUSED(yc
) )
95 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
99 void wxDC::DrawPoint( wxPoint
& point
)
101 DrawPoint( point
.x
, point
.y
);
104 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
106 int n
= list
->Number();
107 wxPoint
*points
= new wxPoint
[n
];
110 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
112 wxPoint
*point
= (wxPoint
*)node
->Data();
113 points
[i
].x
= point
->x
;
114 points
[i
++].y
= point
->y
;
116 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
120 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
122 int n
= list
->Number();
123 wxPoint
*points
= new wxPoint
[n
];
126 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
128 wxPoint
*point
= (wxPoint
*)node
->Data();
129 points
[i
].x
= point
->x
;
130 points
[i
++].y
= point
->y
;
132 DrawLines( n
, points
, xoffset
, yoffset
);
136 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
139 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
140 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
141 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
143 wxNode
*node
= list
.First();
146 wxPoint
*p
= (wxPoint
*)node
->Data();
152 void wxDC::DrawSpline( wxList
*points
)
154 DrawOpenSpline( points
);
157 void wxDC::DrawSpline( int n
, wxPoint points
[] )
160 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
164 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
169 m_clipX2
= x
+ width
;
170 m_clipY2
= y
+ height
;
173 void wxDC::DestroyClippingRegion(void)
178 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
182 if (x
) *x
= m_clipX1
;
183 if (y
) *y
= m_clipY1
;
184 if (width
) *width
= (m_clipX2
- m_clipX1
);
185 if (height
) *height
= (m_clipY2
- m_clipY1
);
188 *x
= *y
= *width
= *height
= 0;
191 void wxDC::GetSize( int* width
, int* height
) const
193 *width
= m_maxX
-m_minX
;
194 *height
= m_maxY
-m_minY
;
197 void wxDC::GetSizeMM( long* width
, long* height
) const
202 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
203 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
206 void wxDC::SetTextForeground( const wxColour
&col
)
209 m_textForegroundColour
= col
;
212 void wxDC::SetTextBackground( const wxColour
&col
)
215 m_textBackgroundColour
= col
;
218 void wxDC::SetMapMode( int mode
)
223 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
226 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
229 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
232 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
236 SetLogicalScale( 1.0, 1.0 );
241 m_needComputeScaleX
= TRUE
;
242 m_needComputeScaleY
= TRUE
;
246 void wxDC::SetUserScale( double x
, double y
)
248 // allow negative ? -> no
251 ComputeScaleAndOrigin();
254 void wxDC::GetUserScale( double *x
, double *y
)
256 if (x
) *x
= m_userScaleX
;
257 if (y
) *y
= m_userScaleY
;
260 void wxDC::SetLogicalScale( double x
, double y
)
265 ComputeScaleAndOrigin();
268 void wxDC::GetLogicalScale( double *x
, double *y
)
270 if (x
) *x
= m_logicalScaleX
;
271 if (y
) *y
= m_logicalScaleY
;
274 void wxDC::SetLogicalOrigin( long x
, long y
)
276 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
277 m_logicalOriginY
= y
* m_signY
;
278 ComputeScaleAndOrigin();
281 void wxDC::GetLogicalOrigin( long *x
, long *y
)
283 if (x
) *x
= m_logicalOriginX
;
284 if (y
) *y
= m_logicalOriginY
;
287 void wxDC::SetDeviceOrigin( long x
, long y
)
289 m_externalDeviceOriginX
= x
;
290 m_externalDeviceOriginY
= y
;
291 ComputeScaleAndOrigin();
294 void wxDC::GetDeviceOrigin( long *x
, long *y
)
296 // if (x) *x = m_externalDeviceOriginX;
297 // if (y) *y = m_externalDeviceOriginY;
298 if (x
) *x
= m_deviceOriginX
;
299 if (y
) *y
= m_deviceOriginY
;
302 void wxDC::SetInternalDeviceOrigin( long x
, long y
)
304 m_internalDeviceOriginX
= x
;
305 m_internalDeviceOriginY
= y
;
306 ComputeScaleAndOrigin();
309 void wxDC::GetInternalDeviceOrigin( long *x
, long *y
)
311 if (x
) *x
= m_internalDeviceOriginX
;
312 if (y
) *y
= m_internalDeviceOriginY
;
315 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
317 m_signX
= (xLeftRight
? 1 : -1);
318 m_signY
= (yBottomUp
? -1 : 1);
319 ComputeScaleAndOrigin();
322 long wxDC::DeviceToLogicalX(long x
) const
327 long wxDC::DeviceToLogicalY(long y
) const
332 long wxDC::DeviceToLogicalXRel(long x
) const
334 return XDEV2LOGREL(x
);
337 long wxDC::DeviceToLogicalYRel(long y
) const
339 return YDEV2LOGREL(y
);
342 long wxDC::LogicalToDeviceX(long x
) const
347 long wxDC::LogicalToDeviceY(long y
) const
352 long wxDC::LogicalToDeviceXRel(long x
) const
354 return XLOG2DEVREL(x
);
357 long wxDC::LogicalToDeviceYRel(long y
) const
359 return YLOG2DEVREL(y
);
362 void wxDC::CalcBoundingBox( long x
, long y
)
364 if (x
< m_minX
) m_minX
= x
;
365 if (y
< m_minY
) m_minY
= y
;
366 if (x
> m_maxX
) m_maxX
= x
;
367 if (y
> m_maxY
) m_maxY
= y
;
370 void wxDC::ComputeScaleAndOrigin(void)
372 // CMB: copy scale to see if it changes
373 double origScaleX
= m_scaleX
;
374 double origScaleY
= m_scaleY
;
376 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
377 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
379 m_deviceOriginX
= m_internalDeviceOriginX
+ m_externalDeviceOriginX
;
380 m_deviceOriginY
= m_internalDeviceOriginY
+ m_externalDeviceOriginY
;
382 // CMB: if scale has changed call SetPen to recalulate the line width
383 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
385 // this is a bit artificial, but we need to force wxDC to think
386 // the pen has changed
387 wxPen
* pen
= GetPen();