]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
44fe792814d64d4d95e4331081e6a7534cd778d9
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "dc.h"
17 //-----------------------------------------------------------------------------
19 //-----------------------------------------------------------------------------
21 #define mm2inches 0.0393700787402
22 #define inches2mm 25.4
23 #define mm2twips 56.6929133859
24 #define twips2mm 0.0176388888889
25 #define mm2pt 2.83464566929
26 #define pt2mm 0.352777777778
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 IMPLEMENT_ABSTRACT_CLASS(wxDC
,wxObject
)
38 m_autoSetting
= FALSE
;
50 m_logicalScaleX
= 1.0;
51 m_logicalScaleY
= 1.0;
57 m_mappingMode
= MM_TEXT
;
58 m_needComputeScaleX
= FALSE
;
59 m_needComputeScaleY
= FALSE
;
61 m_signX
= 1; // default x-axis left to right
62 m_signY
= 1; // default y-axis top down
64 m_maxX
= m_maxY
= -100000;
65 m_minY
= m_minY
= 100000;
67 m_logicalFunction
= wxCOPY
;
68 // m_textAlignment = wxALIGN_TOP_LEFT;
69 m_backgroundMode
= wxTRANSPARENT
;
71 m_textForegroundColour
= *wxBLACK
;
72 m_textBackgroundColour
= *wxWHITE
;
74 m_font
= *wxNORMAL_FONT
;
75 m_brush
= *wxTRANSPARENT_BRUSH
;
76 m_backgroundBrush
= *wxWHITE_BRUSH
;
78 // 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::DrawPoint( wxPoint
& point
)
97 DrawPoint( point
.x
, point
.y
);
100 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
102 int n
= list
->Number();
103 wxPoint
*points
= new wxPoint
[n
];
106 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
108 wxPoint
*point
= (wxPoint
*)node
->Data();
109 points
[i
].x
= point
->x
;
110 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
;
130 DrawLines( n
, points
, xoffset
, yoffset
);
134 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
137 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
138 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
139 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
141 wxNode
*node
= list
.First();
144 wxPoint
*p
= (wxPoint
*)node
->Data();
150 void wxDC::DrawSpline( int n
, wxPoint points
[] )
153 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
157 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
162 m_clipX2
= x
+ width
;
163 m_clipY2
= y
+ height
;
166 void wxDC::DestroyClippingRegion()
171 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
175 if (x
) *x
= m_clipX1
;
176 if (y
) *y
= m_clipY1
;
177 if (width
) *width
= (m_clipX2
- m_clipX1
);
178 if (height
) *height
= (m_clipY2
- m_clipY1
);
182 *x
= *y
= *width
= *height
= 0;
186 void wxDC::GetSize( int* width
, int* height
) const
188 if (width
) *width
= m_maxX
-m_minX
;
189 if (height
) *height
= m_maxY
-m_minY
;
192 void wxDC::GetSizeMM( long* width
, long* height
) const
197 if (width
) *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
198 if (height
) *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
201 void wxDC::SetTextForeground( const wxColour
&col
)
203 m_textForegroundColour
= col
;
206 void wxDC::SetTextBackground( const wxColour
&col
)
208 m_textBackgroundColour
= col
;
211 void wxDC::SetMapMode( int mode
)
216 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
219 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
222 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
225 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
229 SetLogicalScale( 1.0, 1.0 );
232 /* we don't do this mega optimisation
235 m_needComputeScaleX = TRUE;
236 m_needComputeScaleY = TRUE;
241 void wxDC::SetUserScale( double x
, double y
)
243 // allow negative ? -> no
246 ComputeScaleAndOrigin();
249 void wxDC::GetUserScale( double *x
, double *y
)
251 if (x
) *x
= m_userScaleX
;
252 if (y
) *y
= m_userScaleY
;
255 void wxDC::SetLogicalScale( double x
, double y
)
260 ComputeScaleAndOrigin();
263 void wxDC::GetLogicalScale( double *x
, double *y
)
265 if (x
) *x
= m_logicalScaleX
;
266 if (y
) *y
= m_logicalScaleY
;
269 void wxDC::SetLogicalOrigin( long x
, long y
)
271 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
272 m_logicalOriginY
= y
* m_signY
;
273 ComputeScaleAndOrigin();
276 void wxDC::GetLogicalOrigin( long *x
, long *y
)
278 if (x
) *x
= m_logicalOriginX
;
279 if (y
) *y
= m_logicalOriginY
;
282 void wxDC::SetDeviceOrigin( long x
, long y
)
284 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
287 ComputeScaleAndOrigin();
290 void wxDC::GetDeviceOrigin( long *x
, long *y
)
292 if (x
) *x
= m_deviceOriginX
;
293 if (y
) *y
= m_deviceOriginY
;
296 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
298 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
299 m_signX
= (xLeftRight
? 1 : -1);
300 m_signY
= (yBottomUp
? -1 : 1);
301 ComputeScaleAndOrigin();
304 long wxDC::DeviceToLogicalX(long x
) const
309 long wxDC::DeviceToLogicalY(long y
) const
314 long wxDC::DeviceToLogicalXRel(long x
) const
316 return XDEV2LOGREL(x
);
319 long wxDC::DeviceToLogicalYRel(long y
) const
321 return YDEV2LOGREL(y
);
324 long wxDC::LogicalToDeviceX(long x
) const
329 long wxDC::LogicalToDeviceY(long y
) const
334 long wxDC::LogicalToDeviceXRel(long x
) const
336 return XLOG2DEVREL(x
);
339 long wxDC::LogicalToDeviceYRel(long y
) const
341 return YLOG2DEVREL(y
);
344 void wxDC::CalcBoundingBox( long x
, long y
)
346 if (x
< m_minX
) m_minX
= x
;
347 if (y
< m_minY
) m_minY
= y
;
348 if (x
> m_maxX
) m_maxX
= x
;
349 if (y
> m_maxY
) m_maxY
= y
;
352 void wxDC::ComputeScaleAndOrigin()
354 // CMB: copy scale to see if it changes
355 double origScaleX
= m_scaleX
;
356 double origScaleY
= m_scaleY
;
358 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
359 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
361 // CMB: if scale has changed call SetPen to recalulate the line width
362 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
364 // this is a bit artificial, but we need to force wxDC to think
365 // the pen has changed
366 // It gives an Assert, Robert Roebling