]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dc.h"
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
;
53 m_logicalScaleX
= 1.0;
54 m_logicalScaleY
= 1.0;
60 m_mappingMode
= MM_TEXT
;
61 m_needComputeScaleX
= FALSE
;
62 m_needComputeScaleY
= FALSE
;
64 m_signX
= 1; // default x-axis left to right
65 m_signY
= 1; // default y-axis top down
67 m_maxX
= m_maxY
= -100000;
68 m_minY
= m_minY
= 100000;
70 m_logicalFunction
= wxCOPY
;
71 // m_textAlignment = wxALIGN_TOP_LEFT;
72 m_backgroundMode
= wxTRANSPARENT
;
74 m_textForegroundColour
= *wxBLACK
;
75 m_textBackgroundColour
= *wxWHITE
;
77 m_font
= *wxNORMAL_FONT
;
78 m_brush
= *wxTRANSPARENT_BRUSH
;
79 m_backgroundBrush
= *wxWHITE_BRUSH
;
81 // m_palette = wxAPP_COLOURMAP;
93 void wxDC::DrawArc( long WXUNUSED(x1
), long WXUNUSED(y1
), long WXUNUSED(x2
), long WXUNUSED(y2
),
94 double WXUNUSED(xc
), double WXUNUSED(yc
) )
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
;
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
;
133 DrawLines( n
, points
, xoffset
, yoffset
);
137 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
140 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
141 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
142 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
144 wxNode
*node
= list
.First();
147 wxPoint
*p
= (wxPoint
*)node
->Data();
153 void wxDC::DrawSpline( int n
, wxPoint points
[] )
156 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
160 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
165 m_clipX2
= x
+ width
;
166 m_clipY2
= y
+ height
;
169 void wxDC::DestroyClippingRegion()
174 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
178 if (x
) *x
= m_clipX1
;
179 if (y
) *y
= m_clipY1
;
180 if (width
) *width
= (m_clipX2
- m_clipX1
);
181 if (height
) *height
= (m_clipY2
- m_clipY1
);
185 *x
= *y
= *width
= *height
= 0;
189 void wxDC::GetSize( int* width
, int* height
) const
191 if (width
) *width
= m_maxX
-m_minX
;
192 if (height
) *height
= m_maxY
-m_minY
;
195 void wxDC::GetSizeMM( long* width
, long* height
) const
200 if (width
) *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
201 if (height
) *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
204 void wxDC::SetTextForeground( const wxColour
&col
)
206 m_textForegroundColour
= col
;
209 void wxDC::SetTextBackground( const wxColour
&col
)
211 m_textBackgroundColour
= col
;
214 void wxDC::SetMapMode( int mode
)
219 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
222 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
225 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
228 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
232 SetLogicalScale( 1.0, 1.0 );
235 /* we don't do this mega optimisation
238 m_needComputeScaleX = TRUE;
239 m_needComputeScaleY = TRUE;
244 void wxDC::SetUserScale( double x
, double y
)
246 // allow negative ? -> no
249 ComputeScaleAndOrigin();
252 void wxDC::GetUserScale( double *x
, double *y
)
254 if (x
) *x
= m_userScaleX
;
255 if (y
) *y
= m_userScaleY
;
258 void wxDC::SetLogicalScale( double x
, double y
)
263 ComputeScaleAndOrigin();
266 void wxDC::GetLogicalScale( double *x
, double *y
)
268 if (x
) *x
= m_logicalScaleX
;
269 if (y
) *y
= m_logicalScaleY
;
272 void wxDC::SetLogicalOrigin( long x
, long y
)
274 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
275 m_logicalOriginY
= y
* m_signY
;
276 ComputeScaleAndOrigin();
279 void wxDC::GetLogicalOrigin( long *x
, long *y
)
281 if (x
) *x
= m_logicalOriginX
;
282 if (y
) *y
= m_logicalOriginY
;
285 void wxDC::SetDeviceOrigin( long x
, long y
)
287 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
290 ComputeScaleAndOrigin();
293 void wxDC::GetDeviceOrigin( long *x
, long *y
)
295 if (x
) *x
= m_deviceOriginX
;
296 if (y
) *y
= m_deviceOriginY
;
299 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
301 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
302 m_signX
= (xLeftRight
? 1 : -1);
303 m_signY
= (yBottomUp
? -1 : 1);
304 ComputeScaleAndOrigin();
307 long wxDC::DeviceToLogicalX(long x
) const
312 long wxDC::DeviceToLogicalY(long y
) const
317 long wxDC::DeviceToLogicalXRel(long x
) const
319 return XDEV2LOGREL(x
);
322 long wxDC::DeviceToLogicalYRel(long y
) const
324 return YDEV2LOGREL(y
);
327 long wxDC::LogicalToDeviceX(long x
) const
332 long wxDC::LogicalToDeviceY(long y
) const
337 long wxDC::LogicalToDeviceXRel(long x
) const
339 return XLOG2DEVREL(x
);
342 long wxDC::LogicalToDeviceYRel(long y
) const
344 return YLOG2DEVREL(y
);
347 void wxDC::CalcBoundingBox( long x
, long y
)
349 if (x
< m_minX
) m_minX
= x
;
350 if (y
< m_minY
) m_minY
= y
;
351 if (x
> m_maxX
) m_maxX
= x
;
352 if (y
> m_maxY
) m_maxY
= y
;
355 void wxDC::ComputeScaleAndOrigin()
357 // CMB: copy scale to see if it changes
358 double origScaleX
= m_scaleX
;
359 double origScaleY
= m_scaleY
;
361 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
362 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
364 // CMB: if scale has changed call SetPen to recalulate the line width
365 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
367 // this is a bit artificial, but we need to force wxDC to think
368 // the pen has changed
369 // It gives an Assert, Robert Roebling