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