]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
a7c77998bc209455c7c40d1b49c212d01d1f2c6b
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
;
51 m_logicalScaleX
= 1.0;
52 m_logicalScaleY
= 1.0;
58 m_mappingMode
= MM_TEXT
;
59 m_needComputeScaleX
= FALSE
;
60 m_needComputeScaleY
= FALSE
;
62 m_signX
= 1; // default x-axis left to right
63 m_signY
= 1; // default y-axis top down
65 m_maxX
= m_maxY
= -100000;
66 m_minY
= m_minY
= 100000;
68 m_logicalFunction
= wxCOPY
;
69 // m_textAlignment = wxALIGN_TOP_LEFT;
70 m_backgroundMode
= wxTRANSPARENT
;
72 m_textForegroundColour
= *wxBLACK
;
73 m_textBackgroundColour
= *wxWHITE
;
75 m_font
= *wxNORMAL_FONT
;
76 m_brush
= *wxTRANSPARENT_BRUSH
;
77 m_backgroundBrush
= *wxWHITE_BRUSH
;
79 // m_palette = wxAPP_COLOURMAP;
86 bool wxDC::Ok(void) const
88 wxASSERT_MSG( !ok
, "invalid display context" );
92 void wxDC::DrawArc( long WXUNUSED(x1
), long WXUNUSED(y1
), long WXUNUSED(x2
), long WXUNUSED(y2
),
93 double WXUNUSED(xc
), double WXUNUSED(yc
) )
97 void wxDC::DrawIcon( const wxIcon
&WXUNUSED(icon
), long WXUNUSED(x
), long WXUNUSED(y
), bool WXUNUSED(useMask
) )
101 void wxDC::DrawPoint( wxPoint
& point
)
103 DrawPoint( point
.x
, point
.y
);
106 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
108 int n
= list
->Number();
109 wxPoint
*points
= new wxPoint
[n
];
112 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
114 wxPoint
*point
= (wxPoint
*)node
->Data();
115 points
[i
].x
= point
->x
;
116 points
[i
++].y
= point
->y
;
118 DrawPolygon( n
, points
, xoffset
, yoffset
, fillStyle
);
122 void wxDC::DrawLines( wxList
*list
, long xoffset
, long yoffset
)
124 int n
= list
->Number();
125 wxPoint
*points
= new wxPoint
[n
];
128 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
130 wxPoint
*point
= (wxPoint
*)node
->Data();
131 points
[i
].x
= point
->x
;
132 points
[i
++].y
= point
->y
;
134 DrawLines( n
, points
, xoffset
, yoffset
);
138 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
141 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
142 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
143 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
145 wxNode
*node
= list
.First();
148 wxPoint
*p
= (wxPoint
*)node
->Data();
154 void wxDC::DrawSpline( wxList
*points
)
156 DrawOpenSpline( points
);
159 void wxDC::DrawSpline( int n
, wxPoint points
[] )
162 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
166 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
171 m_clipX2
= x
+ width
;
172 m_clipY2
= y
+ height
;
175 void wxDC::DestroyClippingRegion(void)
180 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
184 if (x
) *x
= m_clipX1
;
185 if (y
) *y
= m_clipY1
;
186 if (width
) *width
= (m_clipX2
- m_clipX1
);
187 if (height
) *height
= (m_clipY2
- m_clipY1
);
190 *x
= *y
= *width
= *height
= 0;
193 void wxDC::GetSize( int* width
, int* height
) const
195 *width
= m_maxX
-m_minX
;
196 *height
= m_maxY
-m_minY
;
199 void wxDC::GetSizeMM( long* width
, long* height
) const
204 *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
205 *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
208 void wxDC::SetTextForeground( const wxColour
&col
)
211 m_textForegroundColour
= col
;
214 void wxDC::SetTextBackground( const wxColour
&col
)
217 m_textBackgroundColour
= col
;
220 void wxDC::SetMapMode( int mode
)
225 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
228 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
231 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
234 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
238 SetLogicalScale( 1.0, 1.0 );
243 m_needComputeScaleX
= TRUE
;
244 m_needComputeScaleY
= TRUE
;
248 void wxDC::SetUserScale( double x
, double y
)
250 // allow negative ? -> no
253 ComputeScaleAndOrigin();
256 void wxDC::GetUserScale( double *x
, double *y
)
258 if (x
) *x
= m_userScaleX
;
259 if (y
) *y
= m_userScaleY
;
262 void wxDC::SetLogicalScale( double x
, double y
)
267 ComputeScaleAndOrigin();
270 void wxDC::GetLogicalScale( double *x
, double *y
)
272 if (x
) *x
= m_logicalScaleX
;
273 if (y
) *y
= m_logicalScaleY
;
276 void wxDC::SetLogicalOrigin( long x
, long y
)
278 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
279 m_logicalOriginY
= y
* m_signY
;
280 ComputeScaleAndOrigin();
283 void wxDC::GetLogicalOrigin( long *x
, long *y
)
285 if (x
) *x
= m_logicalOriginX
;
286 if (y
) *y
= m_logicalOriginY
;
289 void wxDC::SetDeviceOrigin( long x
, long y
)
293 ComputeScaleAndOrigin();
296 void wxDC::GetDeviceOrigin( long *x
, long *y
)
298 if (x
) *x
= m_deviceOriginX
;
299 if (y
) *y
= m_deviceOriginY
;
302 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
304 m_signX
= (xLeftRight
? 1 : -1);
305 m_signY
= (yBottomUp
? -1 : 1);
306 ComputeScaleAndOrigin();
309 long wxDC::DeviceToLogicalX(long x
) const
314 long wxDC::DeviceToLogicalY(long y
) const
319 long wxDC::DeviceToLogicalXRel(long x
) const
321 return XDEV2LOGREL(x
);
324 long wxDC::DeviceToLogicalYRel(long y
) const
326 return YDEV2LOGREL(y
);
329 long wxDC::LogicalToDeviceX(long x
) const
334 long wxDC::LogicalToDeviceY(long y
) const
339 long wxDC::LogicalToDeviceXRel(long x
) const
341 return XLOG2DEVREL(x
);
344 long wxDC::LogicalToDeviceYRel(long y
) const
346 return YLOG2DEVREL(y
);
349 void wxDC::CalcBoundingBox( long x
, long y
)
351 if (x
< m_minX
) m_minX
= x
;
352 if (y
< m_minY
) m_minY
= y
;
353 if (x
> m_maxX
) m_maxX
= x
;
354 if (y
> m_maxY
) m_maxY
= y
;
357 void wxDC::ComputeScaleAndOrigin(void)
359 // CMB: copy scale to see if it changes
360 double origScaleX
= m_scaleX
;
361 double origScaleY
= m_scaleY
;
363 m_scaleX
= m_logicalScaleX
* m_userScaleX
;
364 m_scaleY
= m_logicalScaleY
* m_userScaleY
;
366 // CMB: if scale has changed call SetPen to recalulate the line width
367 if (m_scaleX
!= origScaleX
|| m_scaleY
!= origScaleY
)
369 // this is a bit artificial, but we need to force wxDC to think
370 // the pen has changed
371 wxPen
* pen
= GetPen();