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