]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
fd3f686c | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a23fd0e1 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
a23fd0e1 | 21 | #pragma implementation "dc.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
a23fd0e1 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
a23fd0e1 VZ |
32 | #include "wx/frame.h" |
33 | #include "wx/dc.h" | |
34 | #include "wx/utils.h" | |
35 | #include "wx/dialog.h" | |
36 | #include "wx/app.h" | |
37 | #include "wx/bitmap.h" | |
38 | #include "wx/dcmemory.h" | |
2bda0e17 KB |
39 | #endif |
40 | ||
41 | #include "wx/dcprint.h" | |
42 | #include "wx/msw/private.h" | |
43 | ||
44 | #include <string.h> | |
45 | #include <math.h> | |
2bda0e17 | 46 | |
47d67540 | 47 | #if wxUSE_COMMON_DIALOGS |
a23fd0e1 | 48 | #include <commdlg.h> |
2bda0e17 KB |
49 | #endif |
50 | ||
51 | #ifndef __WIN32__ | |
a23fd0e1 | 52 | #include <print.h> |
2bda0e17 KB |
53 | #endif |
54 | ||
2bda0e17 | 55 | #if !USE_SHARED_LIBRARY |
a23fd0e1 | 56 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
2bda0e17 KB |
57 | #endif |
58 | ||
a23fd0e1 VZ |
59 | // --------------------------------------------------------------------------- |
60 | // constants | |
61 | // --------------------------------------------------------------------------- | |
62 | ||
42e69d6b VZ |
63 | static const int VIEWPORT_EXTENT = 1000; |
64 | ||
65 | static const int MM_POINTS = 9; | |
66 | static const int MM_METRIC = 10; | |
a23fd0e1 VZ |
67 | |
68 | // --------------------------------------------------------------------------- | |
69 | // macros | |
70 | // --------------------------------------------------------------------------- | |
2bda0e17 | 71 | |
42e69d6b VZ |
72 | // Logical to device |
73 | // Absolute | |
74 | #define XLOG2DEV(x) (x) | |
75 | #define YLOG2DEV(y) (y) | |
76 | ||
77 | // Relative | |
78 | #define XLOG2DEVREL(x) (x) | |
79 | #define YLOG2DEVREL(y) (y) | |
80 | ||
81 | // Device to logical | |
82 | // Absolute | |
83 | #define XDEV2LOG(x) (x) | |
84 | ||
85 | #define YDEV2LOG(y) (y) | |
86 | ||
87 | // Relative | |
88 | #define XDEV2LOGREL(x) (x) | |
89 | #define YDEV2LOGREL(y) (y) | |
90 | ||
91 | /* | |
92 | * Have the same macros as for XView but not for every operation: | |
93 | * just for calculating window/viewport extent (a better way of scaling). | |
94 | */ | |
95 | ||
96 | // Logical to device | |
97 | // Absolute | |
98 | #define MS_XLOG2DEV(x) LogicalToDevice(x) | |
99 | ||
100 | #define MS_YLOG2DEV(y) LogicalToDevice(y) | |
101 | ||
102 | // Relative | |
103 | #define MS_XLOG2DEVREL(x) LogicalToDeviceXRel(x) | |
104 | #define MS_YLOG2DEVREL(y) LogicalToDeviceYRel(y) | |
105 | ||
106 | // Device to logical | |
107 | // Absolute | |
108 | #define MS_XDEV2LOG(x) DeviceToLogicalX(x) | |
109 | ||
110 | #define MS_YDEV2LOG(y) DeviceToLogicalY(y) | |
111 | ||
112 | // Relative | |
113 | #define MS_XDEV2LOGREL(x) DeviceToLogicalXRel(x) | |
114 | #define MS_YDEV2LOGREL(y) DeviceToLogicalYRel(y) | |
115 | ||
2bda0e17 KB |
116 | #define YSCALE(y) (yorigin - (y)) |
117 | ||
42e69d6b VZ |
118 | #define wx_round(a) (int)((a)+.5) |
119 | ||
a23fd0e1 VZ |
120 | // =========================================================================== |
121 | // implementation | |
122 | // =========================================================================== | |
123 | ||
124 | // --------------------------------------------------------------------------- | |
125 | // wxDC | |
126 | // --------------------------------------------------------------------------- | |
2bda0e17 KB |
127 | |
128 | // Default constructor | |
a23fd0e1 | 129 | wxDC::wxDC() |
2bda0e17 | 130 | { |
7bcb11d3 | 131 | m_canvas = NULL; |
a23fd0e1 | 132 | |
7bcb11d3 JS |
133 | m_oldBitmap = 0; |
134 | m_oldPen = 0; | |
135 | m_oldBrush = 0; | |
136 | m_oldFont = 0; | |
137 | m_oldPalette = 0; | |
a23fd0e1 | 138 | |
7bcb11d3 JS |
139 | m_bOwnsDC = FALSE; |
140 | m_hDC = 0; | |
a23fd0e1 | 141 | |
7bcb11d3 JS |
142 | m_windowExtX = VIEWPORT_EXTENT; |
143 | m_windowExtY = VIEWPORT_EXTENT; | |
a23fd0e1 | 144 | |
7bcb11d3 | 145 | m_hDCCount = 0; |
2bda0e17 KB |
146 | } |
147 | ||
148 | ||
a23fd0e1 | 149 | wxDC::~wxDC() |
2bda0e17 | 150 | { |
7bcb11d3 JS |
151 | if ( m_hDC != 0 ) { |
152 | SelectOldObjects(m_hDC); | |
153 | if ( m_bOwnsDC ) { | |
154 | if ( m_canvas == NULL ) | |
a23fd0e1 | 155 | ::DeleteDC(GetHdc()); |
7bcb11d3 | 156 | else |
a23fd0e1 | 157 | ::ReleaseDC((HWND)m_canvas->GetHWND(), GetHdc()); |
7bcb11d3 | 158 | } |
2bda0e17 | 159 | } |
a23fd0e1 | 160 | |
2bda0e17 KB |
161 | } |
162 | ||
163 | // This will select current objects out of the DC, | |
164 | // which is what you have to do before deleting the | |
165 | // DC. | |
166 | void wxDC::SelectOldObjects(WXHDC dc) | |
167 | { | |
7bcb11d3 | 168 | if (dc) |
2bda0e17 | 169 | { |
7bcb11d3 JS |
170 | if (m_oldBitmap) |
171 | { | |
172 | ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); | |
173 | if (m_selectedBitmap.Ok()) | |
174 | { | |
175 | m_selectedBitmap.SetSelectedInto(NULL); | |
176 | } | |
177 | } | |
a23fd0e1 | 178 | m_oldBitmap = 0; |
7bcb11d3 JS |
179 | if (m_oldPen) |
180 | { | |
181 | ::SelectObject((HDC) dc, (HPEN) m_oldPen); | |
182 | } | |
a23fd0e1 | 183 | m_oldPen = 0; |
7bcb11d3 JS |
184 | if (m_oldBrush) |
185 | { | |
186 | ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); | |
187 | } | |
a23fd0e1 | 188 | m_oldBrush = 0; |
7bcb11d3 JS |
189 | if (m_oldFont) |
190 | { | |
191 | ::SelectObject((HDC) dc, (HFONT) m_oldFont); | |
192 | } | |
a23fd0e1 | 193 | m_oldFont = 0; |
7bcb11d3 JS |
194 | if (m_oldPalette) |
195 | { | |
196 | ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); | |
197 | } | |
a23fd0e1 | 198 | m_oldPalette = 0; |
2bda0e17 | 199 | } |
a23fd0e1 VZ |
200 | |
201 | m_brush = wxNullBrush; | |
7bcb11d3 JS |
202 | m_pen = wxNullPen; |
203 | m_palette = wxNullPalette; | |
204 | m_font = wxNullFont; | |
205 | m_backgroundBrush = wxNullBrush; | |
206 | m_selectedBitmap = wxNullBitmap; | |
2bda0e17 KB |
207 | } |
208 | ||
a23fd0e1 VZ |
209 | // --------------------------------------------------------------------------- |
210 | // clipping | |
211 | // --------------------------------------------------------------------------- | |
212 | ||
213 | void wxDC::DoSetClippingRegion(long cx, long cy, long cw, long ch) | |
2bda0e17 | 214 | { |
7bcb11d3 JS |
215 | m_clipping = TRUE; |
216 | m_clipX1 = (int)cx; | |
217 | m_clipY1 = (int)cy; | |
218 | m_clipX2 = (int)(cx + cw); | |
219 | m_clipY2 = (int)(cy + ch); | |
a23fd0e1 | 220 | |
7bcb11d3 | 221 | DoClipping((WXHDC) m_hDC); |
2bda0e17 KB |
222 | } |
223 | ||
a23fd0e1 | 224 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) |
a724d789 | 225 | { |
a23fd0e1 VZ |
226 | wxCHECK_RET( region.GetHRGN(), _T("invalid clipping region") ); |
227 | ||
7bcb11d3 | 228 | wxRect box = region.GetBox(); |
a23fd0e1 | 229 | |
7bcb11d3 JS |
230 | m_clipping = TRUE; |
231 | m_clipX1 = box.x; | |
232 | m_clipY1 = box.y; | |
233 | m_clipX2 = box.x + box.width; | |
234 | m_clipY2 = box.y + box.height; | |
a23fd0e1 | 235 | |
1e6d9499 | 236 | #ifdef __WIN16__ |
a23fd0e1 | 237 | SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN()); |
1e6d9499 | 238 | #else |
a23fd0e1 | 239 | ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND); |
1e6d9499 | 240 | #endif |
a724d789 JS |
241 | } |
242 | ||
2bda0e17 KB |
243 | void wxDC::DoClipping(WXHDC dc) |
244 | { | |
7bcb11d3 JS |
245 | if (m_clipping && dc) |
246 | { | |
247 | IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), | |
a23fd0e1 | 248 | XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); |
7bcb11d3 | 249 | } |
2bda0e17 KB |
250 | } |
251 | ||
a23fd0e1 | 252 | void wxDC::DestroyClippingRegion() |
2bda0e17 | 253 | { |
7bcb11d3 JS |
254 | if (m_clipping && m_hDC) |
255 | { | |
256 | // TODO: this should restore the previous clipping region, | |
257 | // so that OnPaint processing works correctly, and the update clipping region | |
258 | // doesn't get destroyed after the first DestroyClippingRegion. | |
259 | HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); | |
a23fd0e1 | 260 | SelectClipRgn(GetHdc(), rgn); |
7bcb11d3 JS |
261 | DeleteObject(rgn); |
262 | } | |
263 | m_clipping = FALSE; | |
2bda0e17 KB |
264 | } |
265 | ||
a23fd0e1 VZ |
266 | // --------------------------------------------------------------------------- |
267 | // query capabilities | |
268 | // --------------------------------------------------------------------------- | |
269 | ||
270 | bool wxDC::CanDrawBitmap() const | |
2bda0e17 | 271 | { |
7bcb11d3 | 272 | return TRUE; |
2bda0e17 KB |
273 | } |
274 | ||
a23fd0e1 | 275 | bool wxDC::CanGetTextExtent() const |
2bda0e17 | 276 | { |
7bcb11d3 | 277 | // What sort of display is it? |
a23fd0e1 VZ |
278 | int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY); |
279 | ||
280 | return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER); | |
2bda0e17 KB |
281 | } |
282 | ||
a23fd0e1 | 283 | int wxDC::GetDepth() const |
2bda0e17 | 284 | { |
a23fd0e1 | 285 | return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); |
2bda0e17 KB |
286 | } |
287 | ||
a23fd0e1 VZ |
288 | // --------------------------------------------------------------------------- |
289 | // drawing | |
290 | // --------------------------------------------------------------------------- | |
291 | ||
292 | void wxDC::Clear() | |
2bda0e17 | 293 | { |
7bcb11d3 JS |
294 | RECT rect; |
295 | if (m_canvas) | |
296 | GetClientRect((HWND) m_canvas->GetHWND(), &rect); | |
297 | else if (m_selectedBitmap.Ok()) | |
298 | { | |
299 | rect.left = 0; rect.top = 0; | |
300 | rect.right = m_selectedBitmap.GetWidth(); | |
301 | rect.bottom = m_selectedBitmap.GetHeight(); | |
302 | } | |
a23fd0e1 VZ |
303 | (void) ::SetMapMode(GetHdc(), MM_TEXT); |
304 | ||
305 | DWORD colour = GetBkColor(GetHdc()); | |
7bcb11d3 | 306 | HBRUSH brush = CreateSolidBrush(colour); |
a23fd0e1 | 307 | FillRect(GetHdc(), &rect, brush); |
7bcb11d3 | 308 | DeleteObject(brush); |
a23fd0e1 VZ |
309 | |
310 | ::SetMapMode(GetHdc(), MM_ANISOTROPIC); | |
311 | ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); | |
312 | ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL); | |
313 | ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); | |
314 | ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
315 | } | |
316 | ||
317 | void wxDC::DoFloodFill(long x, long y, const wxColour& col, int style) | |
318 | { | |
319 | (void)ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), | |
320 | col.GetPixel(), | |
321 | style == wxFLOOD_SURFACE ? FLOODFILLSURFACE | |
322 | : FLOODFILLBORDER); | |
323 | ||
7bcb11d3 | 324 | CalcBoundingBox(x, y); |
2bda0e17 KB |
325 | } |
326 | ||
a23fd0e1 | 327 | bool wxDC::DoGetPixel(long x, long y, wxColour *col) const |
2bda0e17 | 328 | { |
7bcb11d3 JS |
329 | // added by steve 29.12.94 (copied from DrawPoint) |
330 | // returns TRUE for pixels in the color of the current pen | |
331 | // and FALSE for all other pixels colors | |
332 | // if col is non-NULL return the color of the pixel | |
a23fd0e1 | 333 | |
7bcb11d3 | 334 | // get the color of the pixel |
a23fd0e1 | 335 | COLORREF pixelcolor = ::GetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)); |
7bcb11d3 JS |
336 | // get the color of the pen |
337 | COLORREF pencolor = 0x00ffffff; | |
338 | if (m_pen.Ok()) | |
339 | { | |
a23fd0e1 | 340 | pencolor = m_pen.GetColour().GetPixel(); |
7bcb11d3 | 341 | } |
a23fd0e1 | 342 | |
7bcb11d3 JS |
343 | // return the color of the pixel |
344 | if(col) | |
345 | col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor)); | |
a23fd0e1 | 346 | |
7bcb11d3 JS |
347 | // check, if color of the pixels is the same as the color |
348 | // of the current pen | |
349 | return(pixelcolor==pencolor); | |
2bda0e17 KB |
350 | } |
351 | ||
a23fd0e1 VZ |
352 | void wxDC::DoCrossHair(long x, long y) |
353 | { | |
354 | long x1 = x-VIEWPORT_EXTENT; | |
355 | long y1 = y-VIEWPORT_EXTENT; | |
356 | long x2 = x+VIEWPORT_EXTENT; | |
357 | long y2 = y+VIEWPORT_EXTENT; | |
358 | ||
359 | (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y), NULL); | |
360 | (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y)); | |
361 | ||
362 | (void)MoveToEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y1), NULL); | |
363 | (void)LineTo(GetHdc(), XLOG2DEV(x), YLOG2DEV(y2)); | |
364 | ||
7bcb11d3 JS |
365 | CalcBoundingBox(x1, y1); |
366 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
367 | } |
368 | ||
a23fd0e1 | 369 | void wxDC::DoDrawLine(long x1, long y1, long x2, long y2) |
2bda0e17 | 370 | { |
a23fd0e1 VZ |
371 | (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); |
372 | (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); | |
373 | ||
7bcb11d3 | 374 | /* MATTHEW: [6] New normalization */ |
2bda0e17 | 375 | #if WX_STANDARD_GRAPHICS |
a23fd0e1 | 376 | (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2)); |
2bda0e17 | 377 | #endif |
a23fd0e1 | 378 | |
7bcb11d3 JS |
379 | CalcBoundingBox(x1, y1); |
380 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
381 | } |
382 | ||
a23fd0e1 | 383 | void wxDC::DoDrawArc(long x1,long y1,long x2,long y2, long xc, long yc) |
2bda0e17 | 384 | { |
a23fd0e1 VZ |
385 | double dx = xc-x1; |
386 | double dy = yc-y1; | |
7bcb11d3 JS |
387 | double radius = (double)sqrt(dx*dx+dy*dy) ;; |
388 | if (x1==x2 && x2==y2) | |
389 | { | |
a23fd0e1 VZ |
390 | DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)); |
391 | return; | |
7bcb11d3 | 392 | } |
a23fd0e1 VZ |
393 | |
394 | long xx1 = XLOG2DEV(x1); | |
395 | long yy1 = YLOG2DEV(y1); | |
396 | long xx2 = XLOG2DEV(x2); | |
397 | long yy2 = YLOG2DEV(y2); | |
398 | long xxc = XLOG2DEV(xc); | |
399 | long yyc = YLOG2DEV(yc); | |
400 | long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))); | |
401 | ||
402 | (void)MoveToEx(GetHdc(), (int) xx1, (int) yy1, NULL); | |
7bcb11d3 JS |
403 | long xxx1 = (long) (xxc-ray); |
404 | long yyy1 = (long) (yyc-ray); | |
405 | long xxx2 = (long) (xxc+ray); | |
406 | long yyy2 = (long) (yyc+ray); | |
407 | if (m_brush.Ok() && m_brush.GetStyle() !=wxTRANSPARENT) | |
408 | { | |
409 | // Have to add 1 to bottom-right corner of rectangle | |
410 | // to make semi-circles look right (crooked line otherwise). | |
411 | // Unfortunately this is not a reliable method, depends | |
412 | // on the size of shape. | |
413 | // TODO: figure out why this happens! | |
a23fd0e1 VZ |
414 | Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1, |
415 | xx1,yy1,xx2,yy2); | |
7bcb11d3 JS |
416 | } |
417 | else | |
a23fd0e1 VZ |
418 | Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2, |
419 | xx1,yy1,xx2,yy2); | |
420 | ||
7bcb11d3 JS |
421 | CalcBoundingBox((xc-radius), (yc-radius)); |
422 | CalcBoundingBox((xc+radius), (yc+radius)); | |
2bda0e17 KB |
423 | } |
424 | ||
a23fd0e1 | 425 | void wxDC::DoDrawPoint(long x, long y) |
2bda0e17 | 426 | { |
7bcb11d3 JS |
427 | COLORREF color = 0x00ffffff; |
428 | if (m_pen.Ok()) | |
429 | { | |
a23fd0e1 | 430 | color = m_pen.GetColour().GetPixel(); |
7bcb11d3 | 431 | } |
a23fd0e1 VZ |
432 | |
433 | SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color); | |
434 | ||
7bcb11d3 | 435 | CalcBoundingBox(x, y); |
2bda0e17 KB |
436 | } |
437 | ||
a23fd0e1 | 438 | void wxDC::DoDrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle) |
2bda0e17 | 439 | { |
7bcb11d3 JS |
440 | // Do things less efficiently if we have offsets |
441 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 442 | { |
7bcb11d3 JS |
443 | POINT *cpoints = new POINT[n]; |
444 | int i; | |
445 | for (i = 0; i < n; i++) | |
446 | { | |
447 | cpoints[i].x = (int)(points[i].x + xoffset); | |
448 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 449 | |
7bcb11d3 JS |
450 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
451 | } | |
a23fd0e1 VZ |
452 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); |
453 | (void)Polygon(GetHdc(), cpoints, n); | |
454 | SetPolyFillMode(GetHdc(),prev); | |
7bcb11d3 JS |
455 | delete[] cpoints; |
456 | } | |
457 | else | |
458 | { | |
459 | int i; | |
460 | for (i = 0; i < n; i++) | |
461 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
462 | |
463 | int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); | |
464 | (void)Polygon(GetHdc(), (POINT*) points, n); | |
465 | SetPolyFillMode(GetHdc(),prev); | |
6a6c0a8b | 466 | } |
2bda0e17 KB |
467 | } |
468 | ||
a23fd0e1 | 469 | void wxDC::DoDrawLines(int n, wxPoint points[], long xoffset, long yoffset) |
2bda0e17 | 470 | { |
7bcb11d3 JS |
471 | // Do things less efficiently if we have offsets |
472 | if (xoffset != 0 || yoffset != 0) | |
6a6c0a8b | 473 | { |
7bcb11d3 JS |
474 | POINT *cpoints = new POINT[n]; |
475 | int i; | |
476 | for (i = 0; i < n; i++) | |
477 | { | |
478 | cpoints[i].x = (int)(points[i].x + xoffset); | |
479 | cpoints[i].y = (int)(points[i].y + yoffset); | |
a23fd0e1 | 480 | |
7bcb11d3 JS |
481 | CalcBoundingBox(cpoints[i].x, cpoints[i].y); |
482 | } | |
a23fd0e1 | 483 | (void)Polyline(GetHdc(), cpoints, n); |
7bcb11d3 JS |
484 | delete[] cpoints; |
485 | } | |
486 | else | |
487 | { | |
488 | int i; | |
489 | for (i = 0; i < n; i++) | |
490 | CalcBoundingBox(points[i].x, points[i].y); | |
a23fd0e1 VZ |
491 | |
492 | (void)Polyline(GetHdc(), (POINT*) points, n); | |
6a6c0a8b | 493 | } |
2bda0e17 KB |
494 | } |
495 | ||
a23fd0e1 | 496 | void wxDC::DoDrawRectangle(long x, long y, long width, long height) |
2bda0e17 | 497 | { |
7bcb11d3 JS |
498 | long x2 = x + width; |
499 | long y2 = y + height; | |
a23fd0e1 | 500 | |
7bcb11d3 | 501 | /* MATTHEW: [6] new normalization */ |
2bda0e17 | 502 | #if WX_STANDARD_GRAPHICS |
7bcb11d3 | 503 | bool do_brush, do_pen; |
a23fd0e1 | 504 | |
7bcb11d3 JS |
505 | do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT; |
506 | do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT; | |
a23fd0e1 | 507 | |
7bcb11d3 JS |
508 | if (do_brush) { |
509 | HPEN orig_pen = NULL; | |
a23fd0e1 | 510 | |
7bcb11d3 | 511 | if (do_pen || !m_pen.Ok()) |
a23fd0e1 VZ |
512 | orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN)); |
513 | ||
514 | (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), | |
7bcb11d3 | 515 | XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1); |
a23fd0e1 | 516 | |
7bcb11d3 | 517 | if (do_pen || !m_pen.Ok()) |
a23fd0e1 | 518 | ::SelectObject(GetHdc() , orig_pen); |
7bcb11d3 JS |
519 | } |
520 | if (do_pen) { | |
521 | HBRUSH orig_brush = NULL; | |
a23fd0e1 | 522 | |
7bcb11d3 | 523 | if (do_brush || !m_brush.Ok()) |
a23fd0e1 VZ |
524 | orig_brush = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH) ::GetStockObject(NULL_BRUSH)); |
525 | ||
526 | (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), | |
7bcb11d3 | 527 | XLOG2DEV(x2), YLOG2DEV(y2)); |
a23fd0e1 | 528 | |
7bcb11d3 | 529 | if (do_brush || !m_brush.Ok()) |
a23fd0e1 | 530 | ::SelectObject(GetHdc(), orig_brush); |
7bcb11d3 | 531 | } |
2bda0e17 | 532 | #else |
a23fd0e1 | 533 | (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); |
2bda0e17 | 534 | #endif |
a23fd0e1 | 535 | |
7bcb11d3 JS |
536 | CalcBoundingBox(x, y); |
537 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
538 | } |
539 | ||
a23fd0e1 | 540 | void wxDC::DoDrawRoundedRectangle(long x, long y, long width, long height, double radius) |
2bda0e17 | 541 | { |
7bcb11d3 JS |
542 | // Now, a negative radius value is interpreted to mean |
543 | // 'the proportion of the smallest X or Y dimension' | |
a23fd0e1 | 544 | |
7bcb11d3 JS |
545 | if (radius < 0.0) |
546 | { | |
547 | double smallest = 0.0; | |
548 | if (width < height) | |
549 | smallest = width; | |
550 | else | |
551 | smallest = height; | |
552 | radius = (- radius * smallest); | |
553 | } | |
a23fd0e1 | 554 | |
7bcb11d3 JS |
555 | long x2 = (x+width); |
556 | long y2 = (y+height); | |
a23fd0e1 VZ |
557 | |
558 | (void)RoundRect(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), | |
7bcb11d3 | 559 | YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius)); |
a23fd0e1 | 560 | |
7bcb11d3 JS |
561 | CalcBoundingBox(x, y); |
562 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
563 | } |
564 | ||
a23fd0e1 | 565 | void wxDC::DoDrawEllipse(long x, long y, long width, long height) |
2bda0e17 | 566 | { |
7bcb11d3 JS |
567 | long x2 = (x+width); |
568 | long y2 = (y+height); | |
a23fd0e1 VZ |
569 | |
570 | (void)Ellipse(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
571 | ||
7bcb11d3 JS |
572 | CalcBoundingBox(x, y); |
573 | CalcBoundingBox(x2, y2); | |
2bda0e17 KB |
574 | } |
575 | ||
6f65e337 | 576 | // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows |
a23fd0e1 | 577 | void wxDC::DoDrawEllipticArc(long x,long y,long w,long h,double sa,double ea) |
6f65e337 | 578 | { |
7bcb11d3 JS |
579 | long x2 = (x+w); |
580 | long y2 = (y+h); | |
a23fd0e1 | 581 | |
7bcb11d3 JS |
582 | const double deg2rad = 3.14159265359 / 180.0; |
583 | int rx1 = XLOG2DEV(x+w/2); | |
584 | int ry1 = YLOG2DEV(y+h/2); | |
585 | int rx2 = rx1; | |
586 | int ry2 = ry1; | |
587 | rx1 += (int)(100.0 * abs(w) * cos(sa * deg2rad)); | |
588 | ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); | |
589 | rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); | |
590 | ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); | |
a23fd0e1 | 591 | |
7bcb11d3 JS |
592 | // draw pie with NULL_PEN first and then outline otherwise a line is |
593 | // drawn from the start and end points to the centre | |
a23fd0e1 | 594 | HPEN orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN)); |
7bcb11d3 JS |
595 | if (m_signY > 0) |
596 | { | |
a23fd0e1 | 597 | (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, |
7bcb11d3 JS |
598 | rx1, ry1, rx2, ry2); |
599 | } | |
600 | else | |
601 | { | |
a23fd0e1 | 602 | (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), |
7bcb11d3 JS |
603 | rx1, ry1-1, rx2, ry2-1); |
604 | } | |
a23fd0e1 VZ |
605 | ::SelectObject(GetHdc(), orig_pen); |
606 | (void)Arc(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), | |
fd3f686c | 607 | rx1, ry1, rx2, ry2); |
a23fd0e1 | 608 | |
7bcb11d3 JS |
609 | CalcBoundingBox(x, y); |
610 | CalcBoundingBox(x2, y2); | |
6f65e337 JS |
611 | } |
612 | ||
a23fd0e1 | 613 | void wxDC::DoDrawIcon(const wxIcon& icon, long x, long y) |
2bda0e17 | 614 | { |
57c208c5 | 615 | #if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__) |
a23fd0e1 | 616 | ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), |
7bcb11d3 | 617 | icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL); |
f60d0f94 | 618 | #else |
a23fd0e1 | 619 | ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); |
f60d0f94 | 620 | #endif |
a23fd0e1 | 621 | |
7bcb11d3 JS |
622 | CalcBoundingBox(x, y); |
623 | CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); | |
2bda0e17 KB |
624 | } |
625 | ||
a23fd0e1 | 626 | void wxDC::DoDrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) |
f5419957 JS |
627 | { |
628 | if (!bmp.Ok()) | |
629 | return; | |
a23fd0e1 | 630 | |
f5419957 JS |
631 | // If we're not drawing transparently, and not drawing to a printer, |
632 | // optimize this function to use Windows functions. | |
633 | if (!useMask && !IsKindOf(CLASSINFO(wxPrinterDC))) | |
634 | { | |
a23fd0e1 | 635 | HDC cdc = GetHdc(); |
f5419957 JS |
636 | HDC memdc = ::CreateCompatibleDC( cdc ); |
637 | HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( ); | |
638 | ::SelectObject( memdc, hbitmap ); | |
639 | ::BitBlt( cdc, x, y, bmp.GetWidth(), bmp.GetHeight(), memdc, 0, 0, SRCCOPY); | |
640 | ::SelectObject( memdc, 0 ); | |
641 | ::DeleteDC( memdc ); | |
642 | } | |
643 | else | |
644 | { | |
645 | // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level | |
646 | wxMemoryDC memDC; | |
647 | memDC.SelectObject(bmp); | |
a23fd0e1 | 648 | |
f5419957 | 649 | /* Not sure if we need this. The mask should leave the |
7bcb11d3 JS |
650 | * masked areas as per the original background of this DC. |
651 | */ | |
652 | /* | |
f5419957 JS |
653 | // There might be transparent areas, so make these |
654 | // the same colour as this DC | |
655 | memDC.SetBackground(* GetBackground()); | |
656 | memDC.Clear(); | |
7bcb11d3 | 657 | */ |
a23fd0e1 | 658 | |
f5419957 | 659 | Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask); |
a23fd0e1 | 660 | |
f5419957 JS |
661 | memDC.SelectObject(wxNullBitmap); |
662 | } | |
663 | } | |
664 | ||
a23fd0e1 VZ |
665 | void wxDC::DoDrawText(const wxString& text, long x, long y) |
666 | { | |
667 | if (m_textForegroundColour.Ok()) | |
668 | SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() ); | |
669 | ||
670 | DWORD old_background = 0; | |
671 | if (m_textBackgroundColour.Ok()) | |
672 | { | |
673 | old_background = SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() ); | |
674 | } | |
675 | ||
676 | if (m_backgroundMode == wxTRANSPARENT) | |
677 | SetBkMode(GetHdc(), TRANSPARENT); | |
678 | else | |
679 | SetBkMode(GetHdc(), OPAQUE); | |
680 | ||
681 | (void)TextOut(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); | |
682 | ||
683 | if (m_textBackgroundColour.Ok()) | |
684 | (void)SetBkColor(GetHdc(), old_background); | |
685 | ||
686 | CalcBoundingBox(x, y); | |
687 | ||
688 | long w, h; | |
689 | GetTextExtent(text, &w, &h); | |
690 | CalcBoundingBox((x + w), (y + h)); | |
691 | } | |
692 | ||
693 | // --------------------------------------------------------------------------- | |
694 | // set GDI objects | |
695 | // --------------------------------------------------------------------------- | |
696 | ||
697 | void wxDC::SetPalette(const wxPalette& palette) | |
698 | { | |
699 | // Set the old object temporarily, in case the assignment deletes an object | |
700 | // that's not yet selected out. | |
701 | if (m_oldPalette) | |
702 | { | |
703 | ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); | |
704 | m_oldPalette = 0; | |
705 | } | |
706 | ||
707 | m_palette = palette; | |
708 | ||
709 | if (!m_palette.Ok()) | |
710 | { | |
711 | // Setting a NULL colourmap is a way of restoring | |
712 | // the original colourmap | |
713 | if (m_oldPalette) | |
714 | { | |
715 | ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); | |
716 | m_oldPalette = 0; | |
717 | } | |
718 | ||
719 | return; | |
720 | } | |
721 | ||
722 | if (m_palette.Ok() && m_palette.GetHPALETTE()) | |
723 | { | |
724 | HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), TRUE); | |
725 | if (!m_oldPalette) | |
726 | m_oldPalette = (WXHPALETTE) oldPal; | |
727 | ||
728 | ::RealizePalette(GetHdc()); | |
729 | } | |
730 | } | |
731 | ||
2bda0e17 KB |
732 | void wxDC::SetFont(const wxFont& the_font) |
733 | { | |
7bcb11d3 JS |
734 | // Set the old object temporarily, in case the assignment deletes an object |
735 | // that's not yet selected out. | |
2bda0e17 | 736 | if (m_oldFont) |
34da0970 | 737 | { |
a23fd0e1 | 738 | ::SelectObject(GetHdc(), (HFONT) m_oldFont); |
7bcb11d3 JS |
739 | m_oldFont = 0; |
740 | } | |
a23fd0e1 | 741 | |
7bcb11d3 | 742 | m_font = the_font; |
a23fd0e1 | 743 | |
7bcb11d3 JS |
744 | if (!the_font.Ok()) |
745 | { | |
746 | if (m_oldFont) | |
a23fd0e1 VZ |
747 | ::SelectObject(GetHdc(), (HFONT) m_oldFont); |
748 | m_oldFont = 0; | |
7bcb11d3 | 749 | } |
a23fd0e1 | 750 | |
7bcb11d3 JS |
751 | if (m_font.Ok() && m_font.GetResourceHandle()) |
752 | { | |
a23fd0e1 | 753 | HFONT f = (HFONT) ::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); |
7bcb11d3 JS |
754 | if (f == (HFONT) NULL) |
755 | { | |
a23fd0e1 | 756 | wxLogDebug("::SelectObject failed in wxDC::SetFont."); |
7bcb11d3 JS |
757 | } |
758 | if (!m_oldFont) | |
759 | m_oldFont = (WXHFONT) f; | |
34da0970 | 760 | } |
2bda0e17 KB |
761 | } |
762 | ||
763 | void wxDC::SetPen(const wxPen& pen) | |
764 | { | |
7bcb11d3 JS |
765 | // Set the old object temporarily, in case the assignment deletes an object |
766 | // that's not yet selected out. | |
2bda0e17 | 767 | if (m_oldPen) |
2bda0e17 | 768 | { |
a23fd0e1 | 769 | ::SelectObject(GetHdc(), (HPEN) m_oldPen); |
7bcb11d3 JS |
770 | m_oldPen = 0; |
771 | } | |
a23fd0e1 | 772 | |
7bcb11d3 | 773 | m_pen = pen; |
a23fd0e1 | 774 | |
7bcb11d3 JS |
775 | if (!m_pen.Ok()) |
776 | { | |
777 | if (m_oldPen) | |
a23fd0e1 VZ |
778 | ::SelectObject(GetHdc(), (HPEN) m_oldPen); |
779 | m_oldPen = 0; | |
7bcb11d3 | 780 | } |
a23fd0e1 | 781 | |
7bcb11d3 JS |
782 | if (m_pen.Ok()) |
783 | { | |
784 | if (m_pen.GetResourceHandle()) | |
785 | { | |
a23fd0e1 | 786 | HPEN p = (HPEN) ::SelectObject(GetHdc(), (HPEN)m_pen.GetResourceHandle()); |
7bcb11d3 JS |
787 | if (!m_oldPen) |
788 | m_oldPen = (WXHPEN) p; | |
789 | } | |
2bda0e17 | 790 | } |
2bda0e17 KB |
791 | } |
792 | ||
793 | void wxDC::SetBrush(const wxBrush& brush) | |
794 | { | |
7bcb11d3 JS |
795 | // Set the old object temporarily, in case the assignment deletes an object |
796 | // that's not yet selected out. | |
2bda0e17 | 797 | if (m_oldBrush) |
2bda0e17 | 798 | { |
a23fd0e1 | 799 | ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush); |
7bcb11d3 JS |
800 | m_oldBrush = 0; |
801 | } | |
a23fd0e1 | 802 | |
7bcb11d3 | 803 | m_brush = brush; |
a23fd0e1 | 804 | |
7bcb11d3 JS |
805 | if (!m_brush.Ok()) |
806 | { | |
807 | if (m_oldBrush) | |
a23fd0e1 VZ |
808 | ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush); |
809 | m_oldBrush = 0; | |
7bcb11d3 | 810 | } |
a23fd0e1 | 811 | |
7bcb11d3 JS |
812 | if (m_brush.Ok()) |
813 | { | |
814 | if (m_brush.GetResourceHandle()) | |
815 | { | |
816 | HBRUSH b = 0; | |
a23fd0e1 | 817 | b = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH)m_brush.GetResourceHandle()); |
7bcb11d3 JS |
818 | if (!m_oldBrush) |
819 | m_oldBrush = (WXHBRUSH) b; | |
820 | } | |
2bda0e17 | 821 | } |
2bda0e17 KB |
822 | } |
823 | ||
2bda0e17 KB |
824 | void wxDC::SetBackground(const wxBrush& brush) |
825 | { | |
7bcb11d3 | 826 | m_backgroundBrush = brush; |
a23fd0e1 | 827 | |
7bcb11d3 JS |
828 | if (!m_backgroundBrush.Ok()) |
829 | return; | |
a23fd0e1 | 830 | |
7bcb11d3 | 831 | if (m_canvas) |
2bda0e17 | 832 | { |
7bcb11d3 JS |
833 | bool customColours = TRUE; |
834 | // If we haven't specified wxUSER_COLOURS, don't allow the panel/dialog box to | |
835 | // change background colours from the control-panel specified colours. | |
836 | if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) | |
837 | customColours = FALSE; | |
a23fd0e1 | 838 | |
7bcb11d3 JS |
839 | if (customColours) |
840 | { | |
841 | if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) | |
842 | { | |
cc2b7472 | 843 | m_canvas->SetTransparent(TRUE); |
7bcb11d3 JS |
844 | } |
845 | else | |
846 | { | |
847 | // New behaviour, 10/2/99: setting the background brush of a DC | |
848 | // doesn't affect the window background colour. However, | |
849 | // I'm leaving in the transparency setting because it's needed by | |
850 | // various controls (e.g. wxStaticText) to determine whether to draw | |
851 | // transparently or not. TODO: maybe this should be a new function | |
852 | // wxWindow::SetTransparency(). Should that apply to the child itself, or the | |
853 | // parent? | |
854 | // m_canvas->SetBackgroundColour(m_backgroundBrush.GetColour()); | |
cc2b7472 | 855 | m_canvas->SetTransparent(FALSE); |
7bcb11d3 JS |
856 | } |
857 | } | |
858 | } | |
a23fd0e1 | 859 | COLORREF new_color = m_backgroundBrush.GetColour().GetPixel(); |
7bcb11d3 | 860 | { |
a23fd0e1 | 861 | (void)SetBkColor(GetHdc(), new_color); |
2bda0e17 | 862 | } |
2bda0e17 KB |
863 | } |
864 | ||
865 | void wxDC::SetBackgroundMode(int mode) | |
866 | { | |
7bcb11d3 | 867 | m_backgroundMode = mode; |
a23fd0e1 | 868 | |
7bcb11d3 | 869 | if (m_backgroundMode == wxTRANSPARENT) |
a23fd0e1 | 870 | ::SetBkMode(GetHdc(), TRANSPARENT); |
7bcb11d3 | 871 | else |
a23fd0e1 | 872 | ::SetBkMode(GetHdc(), OPAQUE); |
2bda0e17 KB |
873 | } |
874 | ||
875 | void wxDC::SetLogicalFunction(int function) | |
876 | { | |
7bcb11d3 | 877 | m_logicalFunction = function; |
a23fd0e1 | 878 | |
7bcb11d3 | 879 | SetRop((WXHDC) m_hDC); |
2bda0e17 KB |
880 | } |
881 | ||
882 | void wxDC::SetRop(WXHDC dc) | |
883 | { | |
7bcb11d3 JS |
884 | if (!dc || m_logicalFunction < 0) |
885 | return; | |
a23fd0e1 | 886 | |
7bcb11d3 JS |
887 | int c_rop; |
888 | // These may be wrong | |
889 | switch (m_logicalFunction) | |
890 | { | |
891 | // case wxXOR: c_rop = R2_XORPEN; break; | |
2bda0e17 KB |
892 | case wxXOR: c_rop = R2_NOTXORPEN; break; |
893 | case wxINVERT: c_rop = R2_NOT; break; | |
894 | case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break; | |
895 | case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break; | |
896 | case wxCLEAR: c_rop = R2_WHITE; break; | |
897 | case wxSET: c_rop = R2_BLACK; break; | |
898 | case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break; | |
899 | case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break; | |
900 | case wxAND: c_rop = R2_MASKPEN; break; | |
901 | case wxOR: c_rop = R2_MERGEPEN; break; | |
902 | case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break; | |
903 | case wxEQUIV: | |
904 | case wxNAND: | |
905 | case wxCOPY: | |
906 | default: | |
7bcb11d3 JS |
907 | c_rop = R2_COPYPEN; break; |
908 | } | |
909 | SetROP2((HDC) dc, c_rop); | |
2bda0e17 KB |
910 | } |
911 | ||
912 | bool wxDC::StartDoc(const wxString& message) | |
913 | { | |
7bcb11d3 | 914 | // We might be previewing, so return TRUE to let it continue. |
2bda0e17 | 915 | return TRUE; |
2bda0e17 KB |
916 | } |
917 | ||
a23fd0e1 | 918 | void wxDC::EndDoc() |
2bda0e17 | 919 | { |
2bda0e17 KB |
920 | } |
921 | ||
a23fd0e1 | 922 | void wxDC::StartPage() |
2bda0e17 | 923 | { |
2bda0e17 KB |
924 | } |
925 | ||
a23fd0e1 | 926 | void wxDC::EndPage() |
2bda0e17 | 927 | { |
2bda0e17 KB |
928 | } |
929 | ||
a23fd0e1 VZ |
930 | // --------------------------------------------------------------------------- |
931 | // text metrics | |
932 | // --------------------------------------------------------------------------- | |
933 | ||
934 | long wxDC::GetCharHeight() const | |
2bda0e17 | 935 | { |
7bcb11d3 | 936 | TEXTMETRIC lpTextMetric; |
a23fd0e1 VZ |
937 | |
938 | GetTextMetrics(GetHdc(), &lpTextMetric); | |
939 | ||
7bcb11d3 | 940 | return YDEV2LOGREL(lpTextMetric.tmHeight); |
2bda0e17 KB |
941 | } |
942 | ||
a23fd0e1 | 943 | long wxDC::GetCharWidth() const |
2bda0e17 | 944 | { |
7bcb11d3 | 945 | TEXTMETRIC lpTextMetric; |
a23fd0e1 VZ |
946 | |
947 | GetTextMetrics(GetHdc(), &lpTextMetric); | |
948 | ||
7bcb11d3 | 949 | return XDEV2LOGREL(lpTextMetric.tmAveCharWidth); |
2bda0e17 KB |
950 | } |
951 | ||
952 | void wxDC::GetTextExtent(const wxString& string, long *x, long *y, | |
a23fd0e1 VZ |
953 | long *descent, long *externalLeading, |
954 | wxFont *theFont) const | |
2bda0e17 | 955 | { |
7bcb11d3 JS |
956 | wxFont *fontToUse = (wxFont*) theFont; |
957 | if (!fontToUse) | |
958 | fontToUse = (wxFont*) &m_font; | |
a23fd0e1 | 959 | |
7bcb11d3 JS |
960 | SIZE sizeRect; |
961 | TEXTMETRIC tm; | |
a23fd0e1 VZ |
962 | |
963 | GetTextExtentPoint(GetHdc(), (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); | |
964 | GetTextMetrics(GetHdc(), &tm); | |
965 | ||
7bcb11d3 JS |
966 | if (x) *x = XDEV2LOGREL(sizeRect.cx); |
967 | if (y) *y = YDEV2LOGREL(sizeRect.cy); | |
968 | if (descent) *descent = tm.tmDescent; | |
969 | if (externalLeading) *externalLeading = tm.tmExternalLeading; | |
2bda0e17 KB |
970 | } |
971 | ||
972 | void wxDC::SetMapMode(int mode) | |
973 | { | |
7bcb11d3 | 974 | m_mappingMode = mode; |
a23fd0e1 | 975 | |
7bcb11d3 JS |
976 | int pixel_width = 0; |
977 | int pixel_height = 0; | |
978 | int mm_width = 0; | |
979 | int mm_height = 0; | |
a23fd0e1 VZ |
980 | |
981 | pixel_width = GetDeviceCaps(GetHdc(), HORZRES); | |
982 | pixel_height = GetDeviceCaps(GetHdc(), VERTRES); | |
983 | mm_width = GetDeviceCaps(GetHdc(), HORZSIZE); | |
984 | mm_height = GetDeviceCaps(GetHdc(), VERTSIZE); | |
985 | ||
7bcb11d3 | 986 | if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0)) |
2bda0e17 | 987 | { |
7bcb11d3 | 988 | return; |
2bda0e17 | 989 | } |
a23fd0e1 | 990 | |
7bcb11d3 JS |
991 | double mm2pixelsX = pixel_width/mm_width; |
992 | double mm2pixelsY = pixel_height/mm_height; | |
a23fd0e1 | 993 | |
7bcb11d3 | 994 | switch (mode) |
2bda0e17 | 995 | { |
7bcb11d3 JS |
996 | case wxMM_TWIPS: |
997 | { | |
998 | m_logicalScaleX = (twips2mm * mm2pixelsX); | |
999 | m_logicalScaleY = (twips2mm * mm2pixelsY); | |
1000 | break; | |
1001 | } | |
1002 | case wxMM_POINTS: | |
1003 | { | |
1004 | m_logicalScaleX = (pt2mm * mm2pixelsX); | |
1005 | m_logicalScaleY = (pt2mm * mm2pixelsY); | |
1006 | break; | |
1007 | } | |
e3065973 | 1008 | case wxMM_METRIC: |
7bcb11d3 JS |
1009 | { |
1010 | m_logicalScaleX = mm2pixelsX; | |
1011 | m_logicalScaleY = mm2pixelsY; | |
1012 | break; | |
1013 | } | |
e3065973 | 1014 | case wxMM_LOMETRIC: |
7bcb11d3 JS |
1015 | { |
1016 | m_logicalScaleX = (mm2pixelsX/10.0); | |
1017 | m_logicalScaleY = (mm2pixelsY/10.0); | |
1018 | break; | |
1019 | } | |
2bda0e17 | 1020 | default: |
e3065973 | 1021 | case wxMM_TEXT: |
7bcb11d3 JS |
1022 | { |
1023 | m_logicalScaleX = 1.0; | |
1024 | m_logicalScaleY = 1.0; | |
1025 | break; | |
1026 | } | |
2bda0e17 | 1027 | } |
a23fd0e1 VZ |
1028 | |
1029 | if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC) | |
1030 | ::SetMapMode(GetHdc(), MM_ANISOTROPIC); | |
1031 | ||
1032 | SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); | |
7bcb11d3 JS |
1033 | m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT); |
1034 | m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT); | |
a23fd0e1 VZ |
1035 | ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL); |
1036 | ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); | |
1037 | ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
2bda0e17 KB |
1038 | } |
1039 | ||
1040 | void wxDC::SetUserScale(double x, double y) | |
1041 | { | |
7bcb11d3 JS |
1042 | m_userScaleX = x; |
1043 | m_userScaleY = y; | |
a23fd0e1 | 1044 | |
7bcb11d3 | 1045 | SetMapMode(m_mappingMode); |
2bda0e17 KB |
1046 | } |
1047 | ||
6f65e337 JS |
1048 | void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) |
1049 | { | |
7bcb11d3 JS |
1050 | m_signX = xLeftRight ? 1 : -1; |
1051 | m_signY = yBottomUp ? -1 : 1; | |
a23fd0e1 | 1052 | |
7bcb11d3 | 1053 | SetMapMode(m_mappingMode); |
6f65e337 JS |
1054 | } |
1055 | ||
2bda0e17 KB |
1056 | void wxDC::SetSystemScale(double x, double y) |
1057 | { | |
a23fd0e1 VZ |
1058 | m_scaleX = x; |
1059 | m_scaleY = y; | |
1060 | ||
7bcb11d3 | 1061 | SetMapMode(m_mappingMode); |
2bda0e17 KB |
1062 | } |
1063 | ||
1064 | void wxDC::SetLogicalOrigin(long x, long y) | |
1065 | { | |
7bcb11d3 JS |
1066 | m_logicalOriginX = x; |
1067 | m_logicalOriginY = y; | |
a23fd0e1 VZ |
1068 | |
1069 | ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); | |
2bda0e17 KB |
1070 | } |
1071 | ||
1072 | void wxDC::SetDeviceOrigin(long x, long y) | |
1073 | { | |
7bcb11d3 JS |
1074 | m_deviceOriginX = x; |
1075 | m_deviceOriginY = y; | |
2bda0e17 | 1076 | |
a23fd0e1 | 1077 | ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); |
2bda0e17 KB |
1078 | } |
1079 | ||
a23fd0e1 VZ |
1080 | // --------------------------------------------------------------------------- |
1081 | // coordinates transformations | |
1082 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1083 | |
a23fd0e1 | 1084 | long wxDCBase::DeviceToLogicalX(long x) const |
2bda0e17 | 1085 | { |
a23fd0e1 | 1086 | return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); |
2bda0e17 KB |
1087 | } |
1088 | ||
a23fd0e1 | 1089 | long wxDCBase::DeviceToLogicalXRel(long x) const |
2bda0e17 | 1090 | { |
a23fd0e1 | 1091 | return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX)); |
2bda0e17 KB |
1092 | } |
1093 | ||
a23fd0e1 | 1094 | long wxDCBase::DeviceToLogicalY(long y) const |
2bda0e17 | 1095 | { |
a23fd0e1 | 1096 | return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); |
2bda0e17 KB |
1097 | } |
1098 | ||
a23fd0e1 | 1099 | long wxDCBase::DeviceToLogicalYRel(long y) const |
2bda0e17 | 1100 | { |
a23fd0e1 | 1101 | return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY)); |
2bda0e17 KB |
1102 | } |
1103 | ||
a23fd0e1 | 1104 | long wxDCBase::LogicalToDeviceX(long x) const |
2bda0e17 | 1105 | { |
a23fd0e1 | 1106 | return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); |
2bda0e17 KB |
1107 | } |
1108 | ||
a23fd0e1 | 1109 | long wxDCBase::LogicalToDeviceXRel(long x) const |
2bda0e17 | 1110 | { |
a23fd0e1 | 1111 | return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX); |
2bda0e17 KB |
1112 | } |
1113 | ||
a23fd0e1 | 1114 | long wxDCBase::LogicalToDeviceY(long y) const |
2bda0e17 | 1115 | { |
a23fd0e1 | 1116 | return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); |
2bda0e17 KB |
1117 | } |
1118 | ||
a23fd0e1 | 1119 | long wxDCBase::LogicalToDeviceYRel(long y) const |
2bda0e17 | 1120 | { |
a23fd0e1 | 1121 | return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY); |
2bda0e17 KB |
1122 | } |
1123 | ||
a23fd0e1 VZ |
1124 | // --------------------------------------------------------------------------- |
1125 | // bit blit | |
1126 | // --------------------------------------------------------------------------- | |
1127 | bool wxDC::DoBlit(long xdest, long ydest, long width, long height, | |
1128 | wxDC *source, long xsrc, long ysrc, int rop, bool useMask) | |
2bda0e17 | 1129 | { |
7bcb11d3 JS |
1130 | long xdest1 = xdest; |
1131 | long ydest1 = ydest; | |
1132 | long xsrc1 = xsrc; | |
1133 | long ysrc1 = ysrc; | |
a23fd0e1 | 1134 | |
7bcb11d3 JS |
1135 | // Chris Breeze 18/5/98: use text foreground/background colours |
1136 | // when blitting from 1-bit bitmaps | |
a23fd0e1 VZ |
1137 | COLORREF old_textground = ::GetTextColor(GetHdc()); |
1138 | COLORREF old_background = ::GetBkColor(GetHdc()); | |
7bcb11d3 JS |
1139 | if (m_textForegroundColour.Ok()) |
1140 | { | |
a23fd0e1 | 1141 | ::SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() ); |
7bcb11d3 JS |
1142 | } |
1143 | if (m_textBackgroundColour.Ok()) | |
1144 | { | |
a23fd0e1 | 1145 | ::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() ); |
7bcb11d3 | 1146 | } |
a23fd0e1 | 1147 | |
7bcb11d3 JS |
1148 | DWORD dwRop = rop == wxCOPY ? SRCCOPY : |
1149 | rop == wxCLEAR ? WHITENESS : | |
1150 | rop == wxSET ? BLACKNESS : | |
1151 | rop == wxINVERT ? DSTINVERT : | |
1152 | rop == wxAND ? MERGECOPY : | |
1153 | rop == wxOR ? MERGEPAINT : | |
1154 | rop == wxSRC_INVERT ? NOTSRCCOPY : | |
1155 | rop == wxXOR ? SRCINVERT : | |
1156 | rop == wxOR_REVERSE ? MERGEPAINT : | |
1157 | rop == wxAND_REVERSE ? SRCERASE : | |
1158 | rop == wxSRC_OR ? SRCPAINT : | |
1159 | rop == wxSRC_AND ? SRCAND : | |
1160 | SRCCOPY; | |
a23fd0e1 | 1161 | |
7bcb11d3 JS |
1162 | bool success = TRUE; |
1163 | if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask()) | |
1164 | { | |
a23fd0e1 | 1165 | |
2bda0e17 | 1166 | #if 0 // __WIN32__ |
7bcb11d3 | 1167 | // Not implemented under Win95 (or maybe a specific device?) |
a23fd0e1 | 1168 | if (MaskBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, |
2bda0e17 KB |
1169 | (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(), |
1170 | 0, 0, 0xAACC0020)) | |
7bcb11d3 JS |
1171 | { |
1172 | // Success | |
1173 | } | |
1174 | else | |
2bda0e17 | 1175 | #endif |
7bcb11d3 JS |
1176 | { |
1177 | // Old code | |
2bda0e17 | 1178 | #if 0 |
7bcb11d3 JS |
1179 | HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC); |
1180 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); | |
a23fd0e1 | 1181 | success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, |
7bcb11d3 | 1182 | dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0); |
a23fd0e1 | 1183 | success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, |
7bcb11d3 JS |
1184 | (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0); |
1185 | ::SelectObject(dc_mask, 0); | |
1186 | ::DeleteDC(dc_mask); | |
2bda0e17 | 1187 | #endif |
7bcb11d3 JS |
1188 | // New code from Chris Breeze, 15/7/98 |
1189 | // Blit bitmap with mask | |
a23fd0e1 | 1190 | |
7bcb11d3 JS |
1191 | if (IsKindOf(CLASSINFO(wxPrinterDC))) |
1192 | { | |
1193 | // If we are printing source colours are screen colours | |
1194 | // not printer colours and so we need copy the bitmap | |
1195 | // pixel by pixel. | |
1196 | RECT rect; | |
1197 | HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); | |
1198 | HDC dc_src = (HDC) source->m_hDC; | |
a23fd0e1 | 1199 | |
7bcb11d3 JS |
1200 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); |
1201 | for (int x = 0; x < width; x++) | |
1202 | { | |
1203 | for (int y = 0; y < height; y++) | |
1204 | { | |
1205 | COLORREF cref = ::GetPixel(dc_mask, x, y); | |
1206 | if (cref) | |
1207 | { | |
1208 | HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); | |
1209 | rect.left = xdest1 + x; rect.right = rect.left + 1; | |
1210 | rect.top = ydest1 + y; rect.bottom = rect.top + 1; | |
a23fd0e1 | 1211 | ::FillRect(GetHdc(), &rect, brush); |
7bcb11d3 JS |
1212 | ::DeleteObject(brush); |
1213 | } | |
1214 | } | |
1215 | } | |
1216 | ::SelectObject(dc_mask, 0); | |
1217 | ::DeleteDC(dc_mask); | |
1218 | } | |
1219 | else | |
1220 | { | |
1221 | // create a temp buffer bitmap and DCs to access it and the mask | |
1222 | HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); | |
a23fd0e1 VZ |
1223 | HDC dc_buffer = ::CreateCompatibleDC(GetHdc()); |
1224 | HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height); | |
7bcb11d3 JS |
1225 | ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); |
1226 | ::SelectObject(dc_buffer, buffer_bmap); | |
a23fd0e1 | 1227 | |
7bcb11d3 JS |
1228 | // copy dest to buffer |
1229 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, | |
a23fd0e1 VZ |
1230 | GetHdc(), xdest1, ydest1, SRCCOPY); |
1231 | ||
7bcb11d3 JS |
1232 | // copy src to buffer using selected raster op |
1233 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, | |
1234 | (HDC) source->m_hDC, xsrc1, ysrc1, dwRop); | |
a23fd0e1 | 1235 | |
7bcb11d3 | 1236 | // set masked area in buffer to BLACK (pixel value 0) |
a23fd0e1 VZ |
1237 | COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255)); |
1238 | COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0)); | |
7bcb11d3 JS |
1239 | ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, |
1240 | dc_mask, xsrc1, ysrc1, SRCAND); | |
a23fd0e1 | 1241 | |
7bcb11d3 | 1242 | // set unmasked area in dest to BLACK |
a23fd0e1 VZ |
1243 | ::SetBkColor(GetHdc(), RGB(0, 0, 0)); |
1244 | ::SetTextColor(GetHdc(), RGB(255, 255, 255)); | |
1245 | ::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, | |
7bcb11d3 | 1246 | dc_mask, xsrc1, ysrc1, SRCAND); |
a23fd0e1 VZ |
1247 | ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values |
1248 | ::SetTextColor(GetHdc(), prevCol); | |
1249 | ||
7bcb11d3 | 1250 | // OR buffer to dest |
a23fd0e1 | 1251 | success = (::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, |
7bcb11d3 | 1252 | dc_buffer, 0, 0, SRCPAINT) != 0); |
a23fd0e1 | 1253 | |
7bcb11d3 JS |
1254 | // tidy up temporary DCs and bitmap |
1255 | ::SelectObject(dc_mask, 0); | |
1256 | ::DeleteDC(dc_mask); | |
1257 | ::SelectObject(dc_buffer, 0); | |
1258 | ::DeleteDC(dc_buffer); | |
1259 | ::DeleteObject(buffer_bmap); | |
1260 | } | |
1261 | } | |
1262 | } | |
1263 | else | |
1264 | { | |
fd3f686c VZ |
1265 | if (IsKindOf(CLASSINFO(wxPrinterDC))) |
1266 | { | |
7bcb11d3 | 1267 | // If we are printing, source colours are screen colours |
fd3f686c VZ |
1268 | // not printer colours and so we need copy the bitmap |
1269 | // pixel by pixel. | |
fd3f686c | 1270 | HDC dc_src = (HDC) source->m_hDC; |
7bcb11d3 | 1271 | RECT rect; |
fd3f686c VZ |
1272 | for (int x = 0; x < width; x++) |
1273 | { | |
1274 | for (int y = 0; y < height; y++) | |
1275 | { | |
7bcb11d3 JS |
1276 | HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); |
1277 | rect.left = xdest1 + x; rect.right = rect.left + 1; | |
1278 | rect.top = ydest1 + y; rect.bottom = rect.top + 1; | |
a23fd0e1 | 1279 | ::FillRect(GetHdc(), &rect, brush); |
7bcb11d3 | 1280 | ::DeleteObject(brush); |
fd3f686c VZ |
1281 | } |
1282 | } | |
fd3f686c VZ |
1283 | } |
1284 | else | |
1285 | { | |
a23fd0e1 | 1286 | success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, |
7bcb11d3 | 1287 | xsrc1, ysrc1, dwRop) != 0); |
fd3f686c | 1288 | } |
400735a8 | 1289 | } |
a23fd0e1 VZ |
1290 | ::SetTextColor(GetHdc(), old_textground); |
1291 | ::SetBkColor(GetHdc(), old_background); | |
2bda0e17 | 1292 | |
a23fd0e1 | 1293 | return success; |
2bda0e17 KB |
1294 | } |
1295 | ||
a23fd0e1 | 1296 | void wxDC::DoGetSize(int *w, int *h) const |
2bda0e17 | 1297 | { |
a23fd0e1 VZ |
1298 | if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES); |
1299 | if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES); | |
2bda0e17 KB |
1300 | } |
1301 | ||
a23fd0e1 | 1302 | void wxDC::DoGetSizeMM(int *w, int *h) const |
2bda0e17 | 1303 | { |
a23fd0e1 VZ |
1304 | if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); |
1305 | if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); | |
7bcb11d3 | 1306 | } |
2bda0e17 | 1307 | |
a23fd0e1 | 1308 | wxSize wxDC::GetPPI() const |
7bcb11d3 | 1309 | { |
a23fd0e1 VZ |
1310 | int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); |
1311 | int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); | |
2bda0e17 | 1312 | |
a23fd0e1 | 1313 | return wxSize(x, y); |
2bda0e17 KB |
1314 | } |
1315 | ||
2bda0e17 KB |
1316 | // For use by wxWindows only, unless custom units are required. |
1317 | void wxDC::SetLogicalScale(double x, double y) | |
1318 | { | |
7bcb11d3 JS |
1319 | m_logicalScaleX = x; |
1320 | m_logicalScaleY = y; | |
2bda0e17 KB |
1321 | } |
1322 | ||
2bda0e17 | 1323 | #if WXWIN_COMPATIBILITY |
a23fd0e1 | 1324 | void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, |
7bcb11d3 JS |
1325 | float *descent, float *externalLeading, |
1326 | wxFont *theFont, bool use16bit) const | |
2bda0e17 KB |
1327 | { |
1328 | long x1, y1, descent1, externalLeading1; | |
fd3f686c VZ |
1329 | GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); |
1330 | *x = x1; *y = y1; | |
2bda0e17 KB |
1331 | if (descent) |
1332 | *descent = descent1; | |
1333 | if (externalLeading) | |
1334 | *externalLeading = externalLeading1; | |
1335 | } | |
1336 | #endif | |
8b9518ee | 1337 | |
a23fd0e1 VZ |
1338 | // --------------------------------------------------------------------------- |
1339 | // spline drawing code | |
1340 | // --------------------------------------------------------------------------- | |
7b46ecac | 1341 | |
dfad0599 JS |
1342 | #if wxUSE_SPLINES |
1343 | ||
dfad0599 JS |
1344 | class wxSpline: public wxObject |
1345 | { | |
7bcb11d3 JS |
1346 | public: |
1347 | int type; | |
1348 | wxList *points; | |
a23fd0e1 | 1349 | |
7bcb11d3 | 1350 | wxSpline(wxList *list); |
a23fd0e1 VZ |
1351 | void DeletePoints(); |
1352 | ||
7bcb11d3 | 1353 | // Doesn't delete points |
a23fd0e1 | 1354 | ~wxSpline(); |
dfad0599 JS |
1355 | }; |
1356 | ||
dfad0599 JS |
1357 | void wx_draw_open_spline(wxDC *dc, wxSpline *spline); |
1358 | ||
1359 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, | |
1360 | double a3, double b3, double a4, double b4); | |
a23fd0e1 | 1361 | void wx_clear_stack(); |
dfad0599 | 1362 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, |
7bcb11d3 | 1363 | double *y3, double *x4, double *y4); |
dfad0599 | 1364 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, |
7bcb11d3 | 1365 | double x4, double y4); |
dfad0599 JS |
1366 | static bool wx_spline_add_point(double x, double y); |
1367 | static void wx_spline_draw_point_array(wxDC *dc); | |
1368 | wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3); | |
1369 | ||
a23fd0e1 | 1370 | void wxDC::DoDrawSpline(wxList *list) |
dfad0599 | 1371 | { |
7bcb11d3 | 1372 | wxSpline spline(list); |
a23fd0e1 | 1373 | |
7bcb11d3 | 1374 | wx_draw_open_spline(this, &spline); |
dfad0599 JS |
1375 | } |
1376 | ||
dfad0599 JS |
1377 | wxList wx_spline_point_list; |
1378 | ||
1379 | void wx_draw_open_spline(wxDC *dc, wxSpline *spline) | |
1380 | { | |
1381 | wxPoint *p; | |
1382 | double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; | |
1383 | double x1, y1, x2, y2; | |
a23fd0e1 | 1384 | |
dfad0599 JS |
1385 | wxNode *node = spline->points->First(); |
1386 | p = (wxPoint *)node->Data(); | |
a23fd0e1 | 1387 | |
dfad0599 JS |
1388 | x1 = p->x; |
1389 | y1 = p->y; | |
a23fd0e1 | 1390 | |
dfad0599 JS |
1391 | node = node->Next(); |
1392 | p = (wxPoint *)node->Data(); | |
a23fd0e1 | 1393 | |
dfad0599 JS |
1394 | x2 = p->x; |
1395 | y2 = p->y; | |
1396 | cx1 = (double)((x1 + x2) / 2); | |
1397 | cy1 = (double)((y1 + y2) / 2); | |
1398 | cx2 = (double)((cx1 + x2) / 2); | |
1399 | cy2 = (double)((cy1 + y2) / 2); | |
a23fd0e1 | 1400 | |
dfad0599 | 1401 | wx_spline_add_point(x1, y1); |
a23fd0e1 | 1402 | |
dfad0599 JS |
1403 | while ((node = node->Next()) != NULL) |
1404 | { | |
1405 | p = (wxPoint *)node->Data(); | |
7bcb11d3 JS |
1406 | x1 = x2; |
1407 | y1 = y2; | |
1408 | x2 = p->x; | |
1409 | y2 = p->y; | |
dfad0599 JS |
1410 | cx4 = (double)(x1 + x2) / 2; |
1411 | cy4 = (double)(y1 + y2) / 2; | |
1412 | cx3 = (double)(x1 + cx4) / 2; | |
1413 | cy3 = (double)(y1 + cy4) / 2; | |
a23fd0e1 | 1414 | |
dfad0599 | 1415 | wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); |
a23fd0e1 | 1416 | |
7bcb11d3 JS |
1417 | cx1 = cx4; |
1418 | cy1 = cy4; | |
dfad0599 JS |
1419 | cx2 = (double)(cx1 + x2) / 2; |
1420 | cy2 = (double)(cy1 + y2) / 2; | |
1421 | } | |
a23fd0e1 | 1422 | |
dfad0599 JS |
1423 | wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1)); |
1424 | wx_spline_add_point(x2, y2); | |
a23fd0e1 | 1425 | |
dfad0599 | 1426 | wx_spline_draw_point_array(dc); |
a23fd0e1 | 1427 | |
dfad0599 JS |
1428 | } |
1429 | ||
1430 | /********************* CURVES FOR SPLINES ***************************** | |
1431 | ||
7bcb11d3 | 1432 | The following spline drawing routine is from |
a23fd0e1 | 1433 | |
fd3f686c VZ |
1434 | "An Algorithm for High-Speed Curve Generation" |
1435 | by George Merrill Chaikin, | |
1436 | Computer Graphics and Image Processing, 3, Academic Press, | |
1437 | 1974, 346-349. | |
a23fd0e1 | 1438 | |
7bcb11d3 | 1439 | and |
a23fd0e1 | 1440 | |
7bcb11d3 JS |
1441 | "On Chaikin's Algorithm" by R. F. Riesenfeld, |
1442 | Computer Graphics and Image Processing, 4, Academic Press, | |
1443 | 1975, 304-310. | |
a23fd0e1 | 1444 | |
dfad0599 JS |
1445 | ***********************************************************************/ |
1446 | ||
fd3f686c VZ |
1447 | #define half(z1, z2) ((z1+z2)/2.0) |
1448 | #define THRESHOLD 5 | |
dfad0599 JS |
1449 | |
1450 | /* iterative version */ | |
1451 | ||
1452 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, | |
7bcb11d3 | 1453 | double b4) |
dfad0599 JS |
1454 | { |
1455 | register double xmid, ymid; | |
1456 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
a23fd0e1 | 1457 | |
dfad0599 JS |
1458 | wx_clear_stack(); |
1459 | wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); | |
a23fd0e1 | 1460 | |
dfad0599 JS |
1461 | while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { |
1462 | xmid = (double)half(x2, x3); | |
1463 | ymid = (double)half(y2, y3); | |
7bcb11d3 JS |
1464 | if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && |
1465 | fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { | |
dfad0599 JS |
1466 | wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1)); |
1467 | wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid)); | |
7bcb11d3 | 1468 | } else { |
dfad0599 | 1469 | wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), |
7bcb11d3 | 1470 | (double)half(x3, x4), (double)half(y3, y4), x4, y4); |
dfad0599 | 1471 | wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), |
7bcb11d3 JS |
1472 | (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); |
1473 | } | |
dfad0599 JS |
1474 | } |
1475 | } | |
1476 | ||
1477 | ||
1478 | /* utilities used by spline drawing routines */ | |
1479 | ||
1480 | ||
1481 | typedef struct wx_spline_stack_struct { | |
1482 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1483 | } | |
7bcb11d3 | 1484 | Stack; |
dfad0599 JS |
1485 | |
1486 | #define SPLINE_STACK_DEPTH 20 | |
1487 | static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; | |
1488 | static Stack *wx_stack_top; | |
1489 | static int wx_stack_count; | |
1490 | ||
a23fd0e1 | 1491 | void wx_clear_stack() |
dfad0599 JS |
1492 | { |
1493 | wx_stack_top = wx_spline_stack; | |
1494 | wx_stack_count = 0; | |
1495 | } | |
1496 | ||
1497 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) | |
1498 | { | |
1499 | wx_stack_top->x1 = x1; | |
1500 | wx_stack_top->y1 = y1; | |
1501 | wx_stack_top->x2 = x2; | |
1502 | wx_stack_top->y2 = y2; | |
1503 | wx_stack_top->x3 = x3; | |
1504 | wx_stack_top->y3 = y3; | |
1505 | wx_stack_top->x4 = x4; | |
1506 | wx_stack_top->y4 = y4; | |
1507 | wx_stack_top++; | |
1508 | wx_stack_count++; | |
1509 | } | |
1510 | ||
1511 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, | |
1512 | double *x3, double *y3, double *x4, double *y4) | |
1513 | { | |
1514 | if (wx_stack_count == 0) | |
7bcb11d3 | 1515 | return (0); |
dfad0599 JS |
1516 | wx_stack_top--; |
1517 | wx_stack_count--; | |
1518 | *x1 = wx_stack_top->x1; | |
1519 | *y1 = wx_stack_top->y1; | |
1520 | *x2 = wx_stack_top->x2; | |
1521 | *y2 = wx_stack_top->y2; | |
1522 | *x3 = wx_stack_top->x3; | |
1523 | *y3 = wx_stack_top->y3; | |
1524 | *x4 = wx_stack_top->x4; | |
1525 | *y4 = wx_stack_top->y4; | |
1526 | return (1); | |
1527 | } | |
1528 | ||
1529 | static bool wx_spline_add_point(double x, double y) | |
1530 | { | |
a23fd0e1 | 1531 | wxPoint *point = new wxPoint; |
7bcb11d3 JS |
1532 | point->x = (int) x; |
1533 | point->y = (int) y; | |
1534 | wx_spline_point_list.Append((wxObject*)point); | |
1535 | return TRUE; | |
dfad0599 JS |
1536 | } |
1537 | ||
1538 | static void wx_spline_draw_point_array(wxDC *dc) | |
1539 | { | |
7bcb11d3 JS |
1540 | dc->DrawLines(&wx_spline_point_list, 0, 0); |
1541 | wxNode *node = wx_spline_point_list.First(); | |
1542 | while (node) | |
1543 | { | |
1544 | wxPoint *point = (wxPoint *)node->Data(); | |
1545 | delete point; | |
1546 | delete node; | |
1547 | node = wx_spline_point_list.First(); | |
1548 | } | |
dfad0599 JS |
1549 | } |
1550 | ||
1551 | wxSpline::wxSpline(wxList *list) | |
1552 | { | |
7bcb11d3 | 1553 | points = list; |
dfad0599 JS |
1554 | } |
1555 | ||
a23fd0e1 | 1556 | wxSpline::~wxSpline() |
dfad0599 JS |
1557 | { |
1558 | } | |
1559 | ||
a23fd0e1 | 1560 | void wxSpline::DeletePoints() |
dfad0599 | 1561 | { |
7bcb11d3 JS |
1562 | for(wxNode *node = points->First(); node; node = points->First()) |
1563 | { | |
1564 | wxPoint *point = (wxPoint *)node->Data(); | |
1565 | delete point; | |
1566 | delete node; | |
1567 | } | |
1568 | delete points; | |
dfad0599 JS |
1569 | } |
1570 | ||
1571 | ||
1572 | #endif // wxUSE_SPLINES | |
7b46ecac | 1573 |