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