]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/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
= wxMM_TEXT
;
61 m_needComputeScaleX
= FALSE
; /* not used yet */
62 m_needComputeScaleY
= FALSE
; /* not used yet */
64 m_signX
= 1; /* default x-axis left to right */
65 m_signY
= 1; /* default y-axis top down. -1 in postscript. */
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; /* I'll learn to handle palettes later in my life */
95 void wxDC::DrawArc( long WXUNUSED(x1
), long WXUNUSED(y1
), long WXUNUSED(x2
), long WXUNUSED(y2
),
96 double WXUNUSED(xc
), double WXUNUSED(yc
) )
100 void wxDC::DrawPoint( wxPoint
& point
)
102 DrawPoint( point
.x
, point
.y
);
105 void wxDC::DrawPolygon( wxList
*list
, long xoffset
, long yoffset
, int fillStyle
)
107 int n
= list
->Number();
108 wxPoint
*points
= new wxPoint
[n
];
111 for( wxNode
*node
= list
->First(); node
; node
= node
->Next() )
113 wxPoint
*point
= (wxPoint
*)node
->Data();
114 points
[i
].x
= point
->x
;
115 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
;
135 DrawLines( n
, points
, xoffset
, yoffset
);
139 void wxDC::DrawSpline( long x1
, long y1
, long x2
, long y2
, long x3
, long y3
)
142 list
.Append( (wxObject
*)new wxPoint(x1
, y1
) );
143 list
.Append( (wxObject
*)new wxPoint(x2
, y2
) );
144 list
.Append( (wxObject
*)new wxPoint(x3
, y3
) );
146 wxNode
*node
= list
.First();
149 wxPoint
*p
= (wxPoint
*)node
->Data();
155 void wxDC::DrawSpline( int n
, wxPoint points
[] )
158 for (int i
= 0; i
< n
; i
++) list
.Append( (wxObject
*)&points
[i
] );
162 void wxDC::SetClippingRegion( long x
, long y
, long width
, long height
)
167 m_clipX2
= x
+ width
;
168 m_clipY2
= y
+ height
;
171 void wxDC::DestroyClippingRegion()
176 void wxDC::GetClippingBox( long *x
, long *y
, long *width
, long *height
) const
180 if (x
) *x
= m_clipX1
;
181 if (y
) *y
= m_clipY1
;
182 if (width
) *width
= (m_clipX2
- m_clipX1
);
183 if (height
) *height
= (m_clipY2
- m_clipY1
);
187 *x
= *y
= *width
= *height
= 0;
191 void wxDC::GetSize( int* width
, int* height
) const
193 if (width
) *width
= m_maxX
-m_minX
;
194 if (height
) *height
= m_maxY
-m_minY
;
197 void wxDC::GetSizeMM( long* width
, long* height
) const
202 if (width
) *width
= long( double(w
) / (m_scaleX
*m_mm_to_pix_x
) );
203 if (height
) *height
= long( double(h
) / (m_scaleY
*m_mm_to_pix_y
) );
206 void wxDC::SetTextForeground( const wxColour
&col
)
208 m_textForegroundColour
= col
;
211 void wxDC::SetTextBackground( const wxColour
&col
)
213 m_textBackgroundColour
= col
;
216 void wxDC::SetMapMode( int mode
)
221 SetLogicalScale( twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
224 SetLogicalScale( pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
227 SetLogicalScale( m_mm_to_pix_x
, m_mm_to_pix_y
);
230 SetLogicalScale( m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0 );
234 SetLogicalScale( 1.0, 1.0 );
237 /* we don't do this mega optimisation
238 if (mode != wxMM_TEXT)
240 m_needComputeScaleX = TRUE;
241 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 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
292 ComputeScaleAndOrigin();
295 void wxDC::GetDeviceOrigin( long *x
, long *y
)
297 if (x
) *x
= m_deviceOriginX
;
298 if (y
) *y
= m_deviceOriginY
;
301 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
303 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
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()
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 // It gives an Assert, Robert Roebling