]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dc.cpp
Small modifications
[wxWidgets.git] / src / gtk / dc.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/97
6f65e337 6// RCS-ID: $Id$
c801d85f
KB
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "dc.h"
14#endif
15
16#include "wx/dc.h"
17
18//-----------------------------------------------------------------------------
19// constants
20//-----------------------------------------------------------------------------
21
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
28
29//-----------------------------------------------------------------------------
30// wxDC
31//-----------------------------------------------------------------------------
32
33IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject)
34
35wxDC::wxDC(void)
36{
37 m_ok = FALSE;
38 m_optimize = FALSE;
39 m_autoSetting = FALSE;
40 m_colour = TRUE;
41 m_clipping = FALSE;
42
43 m_mm_to_pix_x = 1.0;
44 m_mm_to_pix_y = 1.0;
45
46 m_logicalOriginX = 0;
47 m_logicalOriginY = 0;
48 m_deviceOriginX = 0;
49 m_deviceOriginY = 0;
50 m_internalDeviceOriginX = 0;
51 m_internalDeviceOriginY = 0;
52 m_externalDeviceOriginX = 0;
53 m_externalDeviceOriginY = 0;
54
55 m_logicalScaleX = 1.0;
56 m_logicalScaleY = 1.0;
57 m_userScaleX = 1.0;
58 m_userScaleY = 1.0;
59 m_scaleX = 1.0;
60 m_scaleY = 1.0;
61
62 m_mappingMode = MM_TEXT;
63 m_needComputeScaleX = FALSE;
64 m_needComputeScaleY = FALSE;
65
66 m_signX = 1; // default x-axis left to right
67 m_signY = 1; // default y-axis top down
68
69 m_maxX = m_maxY = -100000;
70 m_minY = m_minY = 100000;
71
72 m_logicalFunction = wxCOPY;
73// m_textAlignment = wxALIGN_TOP_LEFT;
74 m_backgroundMode = wxTRANSPARENT;
75
76 m_textForegroundColour = *wxBLACK;
77 m_textBackgroundColour = *wxWHITE;
78 m_pen = *wxBLACK_PEN;
79 m_font = *wxNORMAL_FONT;
80 m_brush = *wxTRANSPARENT_BRUSH;
81 m_backgroundBrush = *wxWHITE_BRUSH;
82
83// m_palette = wxAPP_COLOURMAP;
84};
85
86wxDC::~wxDC(void)
87{
88};
89
90void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2),
91 double WXUNUSED(xc), double WXUNUSED(yc) )
92{
93};
94
95void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y), bool WXUNUSED(useMask) )
96{
97};
98
99void wxDC::DrawPoint( wxPoint& point )
100{
101 DrawPoint( point.x, point.y );
102};
103
104void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle )
105{
106 int n = list->Number();
107 wxPoint *points = new wxPoint[n];
108
109 int i = 0;
110 for( wxNode *node = list->First(); node; node = node->Next() )
111 {
112 wxPoint *point = (wxPoint *)node->Data();
113 points[i].x = point->x;
114 points[i++].y = point->y;
115 };
116 DrawPolygon( n, points, xoffset, yoffset, fillStyle );
117 delete[] points;
118};
119
120void wxDC::DrawLines( wxList *list, long xoffset, long yoffset )
121{
122 int n = list->Number();
123 wxPoint *points = new wxPoint[n];
124
125 int i = 0;
126 for( wxNode *node = list->First(); node; node = node->Next() )
127 {
128 wxPoint *point = (wxPoint *)node->Data();
129 points[i].x = point->x;
130 points[i++].y = point->y;
131 };
132 DrawLines( n, points, xoffset, yoffset );
133 delete []points;
134};
135
136void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 )
137{
138 wxList list;
c0392997
RR
139 list.Append( (wxObject*)new wxPoint(x1, y1) );
140 list.Append( (wxObject*)new wxPoint(x2, y2) );
141 list.Append( (wxObject*)new wxPoint(x3, y3) );
c801d85f 142 DrawSpline(&list);
33d0b396
RR
143 wxNode *node = list.First();
144 while (node)
145 {
146 wxPoint *p = (wxPoint*)node->Data();
147 delete p;
148 node = node->Next();
149 };
c801d85f
KB
150};
151
152void wxDC::DrawSpline( wxList *points )
153{
154 DrawOpenSpline( points );
155};
156
157void wxDC::DrawSpline( int n, wxPoint points[] )
158{
159 wxList list;
160 for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] );
161 DrawSpline( &list );
162};
163
164void wxDC::SetClippingRegion( long x, long y, long width, long height )
165{
166 m_clipping = TRUE;
167 m_clipX1 = x;
168 m_clipY1 = y;
169 m_clipX2 = x + width;
170 m_clipY2 = y + height;
171};
172
173void wxDC::DestroyClippingRegion(void)
174{
175 m_clipping = FALSE;
176};
177
178void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const
179{
180 if (m_clipping)
181 {
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);
186 }
187 else
188 *x = *y = *width = *height = 0;
189};
190
191void wxDC::GetSize( int* width, int* height ) const
192{
193 *width = m_maxX-m_minX;
194 *height = m_maxY-m_minY;
195};
196
197void wxDC::GetSizeMM( long* width, long* height ) const
198{
199 int w = 0;
200 int h = 0;
201 GetSize( &w, &h );
202 *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
203 *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
204};
205
206void wxDC::SetTextForeground( const wxColour &col )
207{
208 if (!Ok()) return;
209 m_textForegroundColour = col;
210};
211
212void wxDC::SetTextBackground( const wxColour &col )
213{
214 if (!Ok()) return;
215 m_textBackgroundColour = col;
216};
217
218void wxDC::SetMapMode( int mode )
219{
220 switch (mode)
221 {
222 case MM_TWIPS:
223 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
224 break;
225 case MM_POINTS:
226 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
227 break;
228 case MM_METRIC:
229 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
230 break;
231 case MM_LOMETRIC:
232 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
233 break;
234 default:
235 case MM_TEXT:
236 SetLogicalScale( 1.0, 1.0 );
237 break;
238 };
239 if (mode != MM_TEXT)
240 {
241 m_needComputeScaleX = TRUE;
242 m_needComputeScaleY = TRUE;
243 };
244};
245
246void wxDC::SetUserScale( double x, double y )
247{
248 // allow negative ? -> no
249 m_userScaleX = x;
250 m_userScaleY = y;
251 ComputeScaleAndOrigin();
252};
253
254void wxDC::GetUserScale( double *x, double *y )
255{
256 if (x) *x = m_userScaleX;
257 if (y) *y = m_userScaleY;
258};
259
260void wxDC::SetLogicalScale( double x, double y )
261{
262 // allow negative ?
263 m_logicalScaleX = x;
264 m_logicalScaleY = y;
265 ComputeScaleAndOrigin();
266};
267
268void wxDC::GetLogicalScale( double *x, double *y )
269{
270 if (x) *x = m_logicalScaleX;
271 if (y) *y = m_logicalScaleY;
272};
273
274void wxDC::SetLogicalOrigin( long x, long y )
275{
276 m_logicalOriginX = x * m_signX; // is this still correct ?
277 m_logicalOriginY = y * m_signY;
278 ComputeScaleAndOrigin();
279};
280
281void wxDC::GetLogicalOrigin( long *x, long *y )
282{
283 if (x) *x = m_logicalOriginX;
284 if (y) *y = m_logicalOriginY;
285};
286
287void wxDC::SetDeviceOrigin( long x, long y )
288{
289 m_externalDeviceOriginX = x;
290 m_externalDeviceOriginY = y;
291 ComputeScaleAndOrigin();
292};
293
294void wxDC::GetDeviceOrigin( long *x, long *y )
295{
d4c99d6f
RR
296// if (x) *x = m_externalDeviceOriginX;
297// if (y) *y = m_externalDeviceOriginY;
298 if (x) *x = m_deviceOriginX;
299 if (y) *y = m_deviceOriginY;
c801d85f
KB
300};
301
302void wxDC::SetInternalDeviceOrigin( long x, long y )
303{
304 m_internalDeviceOriginX = x;
305 m_internalDeviceOriginY = y;
306 ComputeScaleAndOrigin();
307};
308
309void wxDC::GetInternalDeviceOrigin( long *x, long *y )
310{
311 if (x) *x = m_internalDeviceOriginX;
312 if (y) *y = m_internalDeviceOriginY;
313};
314
315void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
316{
317 m_signX = (xLeftRight ? 1 : -1);
318 m_signY = (yBottomUp ? -1 : 1);
319 ComputeScaleAndOrigin();
320};
321
322long wxDC::DeviceToLogicalX(long x) const
323{
324 return XDEV2LOG(x);
325};
326
327long wxDC::DeviceToLogicalY(long y) const
328{
329 return YDEV2LOG(y);
330};
331
332long wxDC::DeviceToLogicalXRel(long x) const
333{
334 return XDEV2LOGREL(x);
335};
336
337long wxDC::DeviceToLogicalYRel(long y) const
338{
339 return YDEV2LOGREL(y);
340};
341
342long wxDC::LogicalToDeviceX(long x) const
343{
344 return XLOG2DEV(x);
345};
346
347long wxDC::LogicalToDeviceY(long y) const
348{
349 return YLOG2DEV(y);
350};
351
352long wxDC::LogicalToDeviceXRel(long x) const
353{
354 return XLOG2DEVREL(x);
355};
356
357long wxDC::LogicalToDeviceYRel(long y) const
358{
359 return YLOG2DEVREL(y);
360};
361
362void wxDC::CalcBoundingBox( long x, long y )
363{
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;
368};
369
370void wxDC::ComputeScaleAndOrigin(void)
371{
6f65e337
JS
372 // CMB: copy scale to see if it changes
373 double origScaleX = m_scaleX;
374 double origScaleY = m_scaleY;
375
c801d85f
KB
376 m_scaleX = m_logicalScaleX * m_userScaleX;
377 m_scaleY = m_logicalScaleY * m_userScaleY;
378
379 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
380 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
6f65e337
JS
381
382 // CMB: if scale has changed call SetPen to recalulate the line width
383 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
384 {
385 // this is a bit artificial, but we need to force wxDC to think
386 // the pen has changed
387 wxPen* pen = GetPen();
388 wxPen tempPen;
389 m_pen = tempPen;
390 SetPen(pen);
391 }
c801d85f
KB
392};
393