]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcclient.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling, Markus Holzem, Chris Breeze |
b0e0d661 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dcclient.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/dcclient.h" | |
6f65e337 | 15 | #include "wx/dcmemory.h" |
4bc67cc5 | 16 | #include "wx/image.h" |
f5368809 | 17 | #include <math.h> |
c801d85f | 18 | |
83624f79 RR |
19 | #include "gdk/gdk.h" |
20 | #include "gtk/gtk.h" | |
21 | ||
c801d85f KB |
22 | //----------------------------------------------------------------------------- |
23 | // local data | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | #include "bdiag.xbm" | |
27 | #include "fdiag.xbm" | |
28 | #include "cdiag.xbm" | |
29 | #include "horiz.xbm" | |
30 | #include "verti.xbm" | |
31 | #include "cross.xbm" | |
32 | #define num_hatches 6 | |
33 | ||
34 | static GdkPixmap *hatches[num_hatches]; | |
c67daf87 | 35 | static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; |
c801d85f KB |
36 | |
37 | //----------------------------------------------------------------------------- | |
38 | // constants | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | #define RAD2DEG 57.2957795131 | |
42 | ||
6f65e337 JS |
43 | //----------------------------------------------------------------------------- |
44 | // temporary implementation of the missing GDK function | |
45 | //----------------------------------------------------------------------------- | |
b0e0d661 | 46 | |
6f65e337 | 47 | #include "gdk/gdkprivate.h" |
b0e0d661 VZ |
48 | |
49 | void gdk_draw_bitmap (GdkDrawable *drawable, | |
50 | GdkGC *gc, | |
51 | GdkDrawable *src, | |
52 | gint xsrc, | |
53 | gint ysrc, | |
54 | gint xdest, | |
55 | gint ydest, | |
56 | gint width, | |
57 | gint height) | |
6f65e337 | 58 | { |
265898fd RR |
59 | GdkWindowPrivate *drawable_private; |
60 | GdkWindowPrivate *src_private; | |
61 | GdkGCPrivate *gc_private; | |
62 | ||
63 | g_return_if_fail (drawable != NULL); | |
64 | g_return_if_fail (src != NULL); | |
65 | g_return_if_fail (gc != NULL); | |
66 | ||
67 | drawable_private = (GdkWindowPrivate*) drawable; | |
68 | src_private = (GdkWindowPrivate*) src; | |
69 | if (drawable_private->destroyed || src_private->destroyed) | |
70 | return; | |
b0e0d661 | 71 | |
265898fd RR |
72 | gc_private = (GdkGCPrivate*) gc; |
73 | ||
74 | if (width == -1) width = src_private->width; | |
75 | if (height == -1) height = src_private->height; | |
76 | ||
77 | XCopyPlane( drawable_private->xdisplay, | |
b0e0d661 VZ |
78 | src_private->xwindow, |
79 | drawable_private->xwindow, | |
80 | gc_private->xgc, | |
81 | xsrc, ysrc, | |
82 | width, height, | |
83 | xdest, ydest, | |
84 | 1 ); | |
6f65e337 JS |
85 | } |
86 | ||
c801d85f | 87 | //----------------------------------------------------------------------------- |
ec758a20 | 88 | // wxWindowDC |
c801d85f KB |
89 | //----------------------------------------------------------------------------- |
90 | ||
b0e0d661 | 91 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
c801d85f | 92 | |
4bc67cc5 | 93 | wxWindowDC::wxWindowDC() |
c801d85f | 94 | { |
265898fd RR |
95 | m_penGC = (GdkGC *) NULL; |
96 | m_brushGC = (GdkGC *) NULL; | |
97 | m_textGC = (GdkGC *) NULL; | |
98 | m_bgGC = (GdkGC *) NULL; | |
99 | m_cmap = (GdkColormap *) NULL; | |
100 | m_isMemDC = FALSE; | |
bbbbe360 | 101 | m_owner = (wxWindow *)NULL; |
903f689b | 102 | } |
c801d85f | 103 | |
ec758a20 | 104 | wxWindowDC::wxWindowDC( wxWindow *window ) |
c801d85f | 105 | { |
265898fd RR |
106 | m_penGC = (GdkGC *) NULL; |
107 | m_brushGC = (GdkGC *) NULL; | |
108 | m_textGC = (GdkGC *) NULL; | |
109 | m_bgGC = (GdkGC *) NULL; | |
110 | m_cmap = (GdkColormap *) NULL; | |
bbbbe360 | 111 | m_owner = (wxWindow *)NULL; |
6db90681 | 112 | m_isMemDC = FALSE; |
3b245d60 | 113 | m_font = window->GetFont(); |
265898fd | 114 | |
861ccde4 | 115 | wxASSERT_MSG( window, _T("DC needs a window") ); |
1e133b7d | 116 | |
a2053b27 | 117 | GtkWidget *widget = window->m_wxwindow; |
6db90681 | 118 | |
861ccde4 | 119 | wxASSERT_MSG( widget, _T("DC needs a widget") ); |
1e133b7d | 120 | |
265898fd | 121 | m_window = widget->window; |
1e133b7d RR |
122 | |
123 | /* not realized ? */ | |
124 | if (!m_window) | |
125 | { | |
6db90681 RR |
126 | /* don't report problems */ |
127 | m_ok = TRUE; | |
128 | ||
129 | return; | |
1e133b7d RR |
130 | } |
131 | ||
a2053b27 RR |
132 | if (window->m_wxwindow) |
133 | m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); | |
265898fd | 134 | else |
a2053b27 | 135 | m_cmap = gtk_widget_get_colormap( window->m_widget ); |
0180d5da | 136 | |
265898fd | 137 | SetUpDC(); |
bbbbe360 RR |
138 | |
139 | /* this must be done after SetUpDC, bacause SetUpDC calls the | |
140 | repective SetBrush, SetPen, SetBackground etc functions | |
141 | to set up the DC. SetBackground call m_owner->SetBackground | |
142 | and this might not be desired as the standard dc background | |
143 | is white whereas a window might assume gray to be the | |
144 | standard (as e.g. wxStatusBar) */ | |
76ed8f8d | 145 | |
bbbbe360 | 146 | m_owner = window; |
903f689b | 147 | } |
c801d85f | 148 | |
4bc67cc5 | 149 | wxWindowDC::~wxWindowDC() |
c801d85f | 150 | { |
265898fd | 151 | Destroy(); |
903f689b | 152 | } |
c801d85f | 153 | |
b0e0d661 | 154 | void wxWindowDC::DoFloodFill( long WXUNUSED(x), long WXUNUSED(y), |
463c1fa1 | 155 | const wxColour &WXUNUSED(col), int WXUNUSED(style) ) |
c801d85f | 156 | { |
b0e0d661 | 157 | wxFAIL_MSG( _T("wxWindowDC::DoFloodFill not implemented") ); |
903f689b | 158 | } |
c801d85f | 159 | |
b0e0d661 | 160 | bool wxWindowDC::DoGetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const |
c801d85f | 161 | { |
b0e0d661 | 162 | wxFAIL_MSG( _T("wxWindowDC::DoGetPixel not implemented") ); |
265898fd | 163 | return FALSE; |
903f689b | 164 | } |
c801d85f | 165 | |
b0e0d661 | 166 | void wxWindowDC::DoDrawLine( long x1, long y1, long x2, long y2 ) |
c801d85f | 167 | { |
93c5dd39 | 168 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 169 | |
265898fd RR |
170 | if (m_pen.GetStyle() != wxTRANSPARENT) |
171 | { | |
6db90681 RR |
172 | if (m_window) |
173 | gdk_draw_line( m_window, m_penGC, XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); | |
b0e0d661 | 174 | |
ed880dd4 RR |
175 | CalcBoundingBox(x1, y1); |
176 | CalcBoundingBox(x2, y2); | |
265898fd | 177 | } |
903f689b | 178 | } |
c801d85f | 179 | |
b0e0d661 | 180 | void wxWindowDC::DoCrossHair( long x, long y ) |
c801d85f | 181 | { |
93c5dd39 | 182 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 183 | |
265898fd RR |
184 | if (m_pen.GetStyle() != wxTRANSPARENT) |
185 | { | |
186 | int w = 0; | |
187 | int h = 0; | |
188 | GetSize( &w, &h ); | |
189 | long xx = XLOG2DEV(x); | |
190 | long yy = YLOG2DEV(y); | |
6db90681 RR |
191 | if (m_window) |
192 | { | |
193 | gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy ); | |
194 | gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) ); | |
195 | } | |
265898fd | 196 | } |
903f689b | 197 | } |
c801d85f | 198 | |
b0e0d661 VZ |
199 | void wxWindowDC::DoDrawArc( long x1, long y1, long x2, long y2, |
200 | long xc, long yc ) | |
c801d85f | 201 | { |
93c5dd39 | 202 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
265898fd RR |
203 | |
204 | long xx1 = XLOG2DEV(x1); | |
205 | long yy1 = YLOG2DEV(y1); | |
206 | long xx2 = XLOG2DEV(x2); | |
207 | long yy2 = YLOG2DEV(y2); | |
0de9b5b2 RR |
208 | long xxc = XLOG2DEV(xc); |
209 | long yyc = YLOG2DEV(yc); | |
265898fd RR |
210 | double dx = xx1 - xxc; |
211 | double dy = yy1 - yyc; | |
212 | double radius = sqrt(dx*dx+dy*dy); | |
213 | long r = (long)radius; | |
214 | double radius1, radius2; | |
215 | ||
216 | if (xx1 == xx2 && yy1 == yy2) | |
217 | { | |
218 | radius1 = 0.0; | |
219 | radius2 = 360.0; | |
220 | } | |
221 | else | |
222 | if (radius == 0.0) | |
223 | { | |
224 | radius1 = radius2 = 0.0; | |
225 | } | |
226 | else | |
227 | { | |
228 | radius1 = (xx1 - xxc == 0) ? | |
b0e0d661 VZ |
229 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
230 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
265898fd | 231 | radius2 = (xx2 - xxc == 0) ? |
b0e0d661 VZ |
232 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
233 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
265898fd RR |
234 | } |
235 | long alpha1 = long(radius1 * 64.0); | |
236 | long alpha2 = long((radius2 - radius1) * 64.0); | |
237 | while (alpha2 <= 0) alpha2 += 360*64; | |
238 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
239 | ||
6db90681 RR |
240 | if (m_window) |
241 | { | |
242 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
243 | gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); | |
c801d85f | 244 | |
6db90681 RR |
245 | if (m_pen.GetStyle() != wxTRANSPARENT) |
246 | gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); | |
247 | } | |
265898fd RR |
248 | |
249 | CalcBoundingBox (x1, y1); | |
250 | CalcBoundingBox (x2, y2); | |
903f689b | 251 | } |
c801d85f | 252 | |
b0e0d661 | 253 | void wxWindowDC::DoDrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) |
c801d85f | 254 | { |
93c5dd39 | 255 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 256 | |
265898fd RR |
257 | long xx = XLOG2DEV(x); |
258 | long yy = YLOG2DEV(y); | |
259 | long ww = m_signX * XLOG2DEVREL(width); | |
260 | long hh = m_signY * YLOG2DEVREL(height); | |
c801d85f | 261 | |
265898fd RR |
262 | // CMB: handle -ve width and/or height |
263 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
264 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 265 | |
6db90681 RR |
266 | if (m_window) |
267 | { | |
268 | long start = long(sa * 64.0); | |
269 | long end = long(ea * 64.0); | |
270 | ||
271 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
272 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); | |
c801d85f | 273 | |
6db90681 RR |
274 | if (m_pen.GetStyle() != wxTRANSPARENT) |
275 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end ); | |
276 | } | |
b0e0d661 | 277 | |
265898fd RR |
278 | CalcBoundingBox (x, y); |
279 | CalcBoundingBox (x + width, y + height); | |
903f689b | 280 | } |
c801d85f | 281 | |
b0e0d661 | 282 | void wxWindowDC::DoDrawPoint( long x, long y ) |
c801d85f | 283 | { |
93c5dd39 | 284 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 285 | |
6db90681 | 286 | if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window) |
265898fd | 287 | gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); |
b0e0d661 | 288 | |
265898fd | 289 | CalcBoundingBox (x, y); |
903f689b | 290 | } |
c801d85f | 291 | |
b0e0d661 | 292 | void wxWindowDC::DoDrawLines( int n, wxPoint points[], long xoffset, long yoffset ) |
c801d85f | 293 | { |
93c5dd39 | 294 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 295 | |
265898fd RR |
296 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
297 | if (n <= 0) return; | |
c801d85f | 298 | |
265898fd RR |
299 | CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset ); |
300 | ||
301 | for (int i = 0; i < n-1; i++) | |
302 | { | |
303 | long x1 = XLOG2DEV(points[i].x + xoffset); | |
304 | long x2 = XLOG2DEV(points[i+1].x + xoffset); | |
305 | long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste | |
306 | long y2 = YLOG2DEV(points[i+1].y + yoffset); | |
6db90681 RR |
307 | if (m_window) |
308 | gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 ); | |
b0e0d661 | 309 | |
265898fd RR |
310 | CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset ); |
311 | } | |
903f689b | 312 | } |
c801d85f | 313 | |
b0e0d661 | 314 | void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle) ) |
cf7a7e13 | 315 | { |
93c5dd39 | 316 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
cf7a7e13 | 317 | |
4bc67cc5 | 318 | if (n <= 0) return; |
265898fd RR |
319 | |
320 | GdkPoint *gdkpoints = new GdkPoint[n+1]; | |
321 | int i; | |
322 | for (i = 0 ; i < n ; i++) | |
323 | { | |
324 | gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset); | |
325 | gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset); | |
b0e0d661 | 326 | |
265898fd RR |
327 | CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); |
328 | } | |
329 | ||
330 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
331 | gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); | |
332 | ||
333 | // To do: Fillstyle | |
334 | ||
6db90681 RR |
335 | if ((m_pen.GetStyle() != wxTRANSPARENT) && m_window) |
336 | { | |
265898fd | 337 | for (i = 0 ; i < n ; i++) |
b0e0d661 | 338 | { |
265898fd | 339 | gdk_draw_line( m_window, m_penGC, |
b0e0d661 VZ |
340 | gdkpoints[i%n].x, |
341 | gdkpoints[i%n].y, | |
342 | gdkpoints[(i+1)%n].x, | |
343 | gdkpoints[(i+1)%n].y); | |
265898fd | 344 | } |
6db90681 | 345 | } |
b0e0d661 | 346 | |
265898fd | 347 | delete[] gdkpoints; |
903f689b | 348 | } |
c801d85f | 349 | |
b0e0d661 | 350 | void wxWindowDC::DoDrawRectangle( long x, long y, long width, long height ) |
c801d85f | 351 | { |
93c5dd39 | 352 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 353 | |
265898fd RR |
354 | long xx = XLOG2DEV(x); |
355 | long yy = YLOG2DEV(y); | |
356 | long ww = m_signX * XLOG2DEVREL(width); | |
357 | long hh = m_signY * YLOG2DEVREL(height); | |
c801d85f | 358 | |
265898fd RR |
359 | // CMB: draw nothing if transformed w or h is 0 |
360 | if (ww == 0 || hh == 0) return; | |
6f65e337 | 361 | |
265898fd RR |
362 | // CMB: handle -ve width and/or height |
363 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
364 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 365 | |
6db90681 RR |
366 | if (m_window) |
367 | { | |
368 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
369 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); | |
c801d85f | 370 | |
6db90681 RR |
371 | if (m_pen.GetStyle() != wxTRANSPARENT) |
372 | gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); | |
373 | } | |
265898fd RR |
374 | |
375 | CalcBoundingBox( x, y ); | |
376 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 377 | } |
c801d85f | 378 | |
b0e0d661 | 379 | void wxWindowDC::DoDrawRoundedRectangle( long x, long y, long width, long height, double radius ) |
c801d85f | 380 | { |
93c5dd39 | 381 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
265898fd RR |
382 | |
383 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); | |
384 | ||
385 | long xx = XLOG2DEV(x); | |
386 | long yy = YLOG2DEV(y); | |
387 | long ww = m_signX * XLOG2DEVREL(width); | |
388 | long hh = m_signY * YLOG2DEVREL(height); | |
389 | long rr = XLOG2DEVREL((long)radius); | |
390 | ||
391 | // CMB: handle -ve width and/or height | |
392 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
393 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
394 | ||
395 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
396 | // X drawing errors with small radii | |
397 | if (rr == 0) | |
398 | { | |
399 | DrawRectangle( x, y, width, height ); | |
400 | return; | |
401 | } | |
402 | ||
403 | // CMB: draw nothing if transformed w or h is 0 | |
404 | if (ww == 0 || hh == 0) return; | |
405 | ||
406 | // CMB: adjust size if outline is drawn otherwise the result is | |
407 | // 1 pixel too wide and high | |
408 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
409 | { | |
410 | ww--; | |
411 | hh--; | |
412 | } | |
413 | ||
6db90681 | 414 | if (m_window) |
265898fd | 415 | { |
6db90681 RR |
416 | // CMB: ensure dd is not larger than rectangle otherwise we |
417 | // get an hour glass shape | |
418 | long dd = 2 * rr; | |
419 | if (dd > ww) dd = ww; | |
420 | if (dd > hh) dd = hh; | |
421 | rr = dd / 2; | |
422 | ||
423 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
424 | { | |
425 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh ); | |
426 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 ); | |
427 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 ); | |
428 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
429 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
430 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
431 | } | |
265898fd | 432 | |
6db90681 RR |
433 | if (m_pen.GetStyle() != wxTRANSPARENT) |
434 | { | |
435 | gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy ); | |
436 | gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh ); | |
437 | gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr ); | |
438 | gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr ); | |
439 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 ); | |
440 | gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
441 | gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
442 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
443 | } | |
265898fd RR |
444 | } |
445 | ||
446 | // this ignores the radius | |
447 | CalcBoundingBox( x, y ); | |
448 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 449 | } |
c801d85f | 450 | |
b0e0d661 | 451 | void wxWindowDC::DoDrawEllipse( long x, long y, long width, long height ) |
c801d85f | 452 | { |
93c5dd39 | 453 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 454 | |
265898fd RR |
455 | long xx = XLOG2DEV(x); |
456 | long yy = YLOG2DEV(y); | |
457 | long ww = m_signX * XLOG2DEVREL(width); | |
458 | long hh = m_signY * YLOG2DEVREL(height); | |
6f65e337 | 459 | |
265898fd RR |
460 | // CMB: handle -ve width and/or height |
461 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
462 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
c801d85f | 463 | |
6db90681 RR |
464 | if (m_window) |
465 | { | |
466 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
467 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); | |
c801d85f | 468 | |
6db90681 RR |
469 | if (m_pen.GetStyle() != wxTRANSPARENT) |
470 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 ); | |
471 | } | |
b0e0d661 | 472 | |
ed880dd4 | 473 | CalcBoundingBox( x - width, y - height ); |
265898fd | 474 | CalcBoundingBox( x + width, y + height ); |
903f689b | 475 | } |
c801d85f | 476 | |
b0e0d661 | 477 | void wxWindowDC::DoDrawIcon( const wxIcon &icon, long x, long y ) |
c801d85f | 478 | { |
b0e0d661 VZ |
479 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why |
480 | DoDrawBitmap( (const wxBitmap&)icon, x, y, (bool)TRUE ); | |
903f689b | 481 | } |
c801d85f | 482 | |
b0e0d661 VZ |
483 | void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, |
484 | long x, long y, | |
485 | bool useMask ) | |
4bc67cc5 | 486 | { |
93c5dd39 | 487 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 488 | |
b0e0d661 | 489 | wxCHECK_RET( bitmap.Ok(), _T("invalid bitmap") ); |
6e13c196 RR |
490 | |
491 | /* scale/translate size and position */ | |
c801d85f | 492 | |
265898fd RR |
493 | int xx = XLOG2DEV(x); |
494 | int yy = YLOG2DEV(y); | |
c801d85f | 495 | |
4bc67cc5 RR |
496 | int w = bitmap.GetWidth(); |
497 | int h = bitmap.GetHeight(); | |
c801d85f | 498 | |
6453876e RR |
499 | CalcBoundingBox( x, y ); |
500 | CalcBoundingBox( x + w, y + h ); | |
501 | ||
502 | if (!m_window) return; | |
503 | ||
4bc67cc5 RR |
504 | int ww = XLOG2DEVREL(w); |
505 | int hh = YLOG2DEVREL(h); | |
506 | ||
6e13c196 RR |
507 | /* scale bitmap if required */ |
508 | ||
4bc67cc5 RR |
509 | wxBitmap use_bitmap; |
510 | ||
511 | if ((w != ww) || (h != hh)) | |
265898fd | 512 | { |
4bc67cc5 | 513 | wxImage image( bitmap ); |
b0e0d661 VZ |
514 | image = image.Scale( ww, hh ); |
515 | ||
516 | use_bitmap = image.ConvertToBitmap(); | |
265898fd | 517 | } |
4bc67cc5 | 518 | else |
265898fd | 519 | { |
4bc67cc5 | 520 | use_bitmap = bitmap; |
265898fd RR |
521 | } |
522 | ||
6e13c196 RR |
523 | /* apply mask if any */ |
524 | ||
463c1fa1 | 525 | GdkBitmap *mask = (GdkBitmap *) NULL; |
4bc67cc5 | 526 | if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); |
463c1fa1 RR |
527 | |
528 | if (useMask && mask) | |
529 | { | |
530 | gdk_gc_set_clip_mask( m_penGC, mask ); | |
531 | gdk_gc_set_clip_origin( m_penGC, xx, yy ); | |
532 | } | |
533 | ||
6e13c196 RR |
534 | /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ |
535 | ||
4bc67cc5 | 536 | GdkPixmap *pm = use_bitmap.GetPixmap(); |
6e13c196 RR |
537 | if (pm) |
538 | { | |
539 | gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 ); | |
540 | } | |
541 | else | |
542 | { | |
543 | GdkBitmap *bm = use_bitmap.GetBitmap(); | |
544 | if (bm) | |
545 | { | |
546 | gdk_draw_bitmap( m_window, m_penGC, bm, 0, 0, xx, yy, -1, -1 ); | |
b0e0d661 | 547 | } |
6e13c196 RR |
548 | } |
549 | ||
550 | /* remove mask again if any */ | |
551 | ||
463c1fa1 RR |
552 | if (useMask && mask) |
553 | { | |
554 | gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); | |
555 | gdk_gc_set_clip_origin( m_penGC, 0, 0 ); | |
556 | } | |
463c1fa1 RR |
557 | } |
558 | ||
b0e0d661 VZ |
559 | bool wxWindowDC::DoBlit( long xdest, long ydest, long width, long height, |
560 | wxDC *source, long xsrc, long ysrc, | |
561 | int logical_func, bool useMask ) | |
c801d85f | 562 | { |
6e13c196 RR |
563 | /* this is the nth try to get this utterly useless function to |
564 | work. it now completely ignores the scaling or translation | |
565 | of the source dc, but scales correctly on the target dc and | |
566 | knows about possible mask information in a memory dc. */ | |
567 | ||
93c5dd39 | 568 | wxCHECK_MSG( Ok(), FALSE, _T("invalid window dc") ); |
e23d0e95 | 569 | |
93c5dd39 | 570 | wxCHECK_MSG( source, FALSE, _T("invalid source dc") ); |
6e13c196 | 571 | |
6db90681 RR |
572 | if (!m_window) return FALSE; |
573 | ||
6e13c196 RR |
574 | wxClientDC *srcDC = (wxClientDC*)source; |
575 | wxMemoryDC *memDC = (wxMemoryDC*)source; | |
576 | ||
577 | bool use_bitmap_method = FALSE; | |
578 | ||
579 | if (srcDC->m_isMemDC) | |
580 | { | |
b0e0d661 VZ |
581 | if (!memDC->m_selected.Ok()) return FALSE; |
582 | ||
6e13c196 | 583 | /* we use the "XCopyArea" way to copy a memory dc into |
b0e0d661 VZ |
584 | y different window if the memory dc BOTH |
585 | a) doesn't have any mask or its mask isn't used | |
586 | b) it is clipped | |
587 | c) is not 1-bit */ | |
6e13c196 | 588 | |
f234c60c | 589 | if (useMask && (memDC->m_selected.GetMask())) |
b0e0d661 VZ |
590 | { |
591 | /* we HAVE TO use the direct way for memory dcs | |
592 | that have mask since the XCopyArea doesn't know | |
593 | about masks */ | |
594 | use_bitmap_method = TRUE; | |
595 | } | |
596 | else if (memDC->m_selected.GetDepth() == 1) | |
597 | { | |
598 | /* we HAVE TO use the direct way for memory dcs | |
599 | that are bitmaps because XCopyArea doesn't cope | |
600 | with different bit depths */ | |
601 | use_bitmap_method = TRUE; | |
602 | } | |
603 | else if ((xsrc == 0) && (ysrc == 0) && | |
604 | (width == memDC->m_selected.GetWidth()) && | |
605 | (height == memDC->m_selected.GetHeight())) | |
606 | { | |
607 | /* we SHOULD use the direct way if all of the bitmap | |
608 | in the memory dc is copied in which case XCopyArea | |
609 | wouldn't be able able to boost performace by reducing | |
610 | the area to be scaled */ | |
611 | use_bitmap_method = TRUE; | |
612 | } | |
613 | else | |
614 | { | |
615 | use_bitmap_method = FALSE; | |
616 | } | |
6e13c196 RR |
617 | } |
618 | ||
265898fd RR |
619 | CalcBoundingBox( xdest, ydest ); |
620 | CalcBoundingBox( xdest + width, ydest + height ); | |
621 | ||
4bc67cc5 RR |
622 | int old_logical_func = m_logicalFunction; |
623 | SetLogicalFunction( logical_func ); | |
624 | ||
6e13c196 | 625 | if (use_bitmap_method) |
6f65e337 | 626 | { |
6e13c196 RR |
627 | /* scale/translate bitmap size */ |
628 | ||
b0e0d661 VZ |
629 | long bm_width = memDC->m_selected.GetWidth(); |
630 | long bm_height = memDC->m_selected.GetHeight(); | |
631 | ||
632 | long bm_ww = XLOG2DEVREL( bm_width ); | |
633 | long bm_hh = YLOG2DEVREL( bm_height ); | |
634 | ||
6e13c196 RR |
635 | /* scale bitmap if required */ |
636 | ||
637 | wxBitmap use_bitmap; | |
638 | ||
639 | if ((bm_width != bm_ww) || (bm_height != bm_hh)) | |
640 | { | |
641 | wxImage image( memDC->m_selected ); | |
b0e0d661 VZ |
642 | image = image.Scale( bm_ww, bm_hh ); |
643 | ||
644 | use_bitmap = image.ConvertToBitmap(); | |
6e13c196 RR |
645 | } |
646 | else | |
e23d0e95 | 647 | { |
6e13c196 RR |
648 | use_bitmap = memDC->m_selected; |
649 | } | |
b0e0d661 | 650 | |
6e13c196 RR |
651 | /* scale/translate size and position */ |
652 | ||
653 | long xx = XLOG2DEV(xdest); | |
654 | long yy = YLOG2DEV(ydest); | |
b0e0d661 VZ |
655 | |
656 | long ww = XLOG2DEVREL(width); | |
657 | long hh = YLOG2DEVREL(height); | |
658 | ||
6e13c196 | 659 | /* apply mask if any */ |
e23d0e95 | 660 | |
6e13c196 RR |
661 | GdkBitmap *mask = (GdkBitmap *) NULL; |
662 | if (use_bitmap.GetMask()) mask = use_bitmap.GetMask()->GetBitmap(); | |
e23d0e95 | 663 | |
6e13c196 RR |
664 | if (useMask && mask) |
665 | { | |
666 | gdk_gc_set_clip_mask( m_penGC, mask ); | |
667 | gdk_gc_set_clip_origin( m_penGC, xx, yy ); | |
e23d0e95 | 668 | } |
b0e0d661 | 669 | |
6e13c196 RR |
670 | /* draw XPixmap or XBitmap, depending on what the wxBitmap contains */ |
671 | ||
672 | GdkPixmap *pm = use_bitmap.GetPixmap(); | |
673 | if (pm) | |
265898fd | 674 | { |
f234c60c | 675 | gdk_draw_pixmap( m_window, m_penGC, pm, xsrc, ysrc, xx, yy, ww, hh ); |
6e13c196 RR |
676 | } |
677 | else | |
678 | { | |
679 | GdkBitmap *bm = use_bitmap.GetBitmap(); | |
680 | if (bm) | |
681 | { | |
b0e0d661 VZ |
682 | /* we use the textGC here because blitting a bitmap is done |
683 | using the current text colour */ | |
f234c60c | 684 | gdk_draw_bitmap( m_window, m_textGC, bm, xsrc, ysrc, xx, yy, ww, hh ); |
b0e0d661 | 685 | } |
6e13c196 | 686 | } |
df875e59 | 687 | |
6e13c196 | 688 | /* remove mask again if any */ |
df875e59 | 689 | |
6e13c196 RR |
690 | if (useMask && mask) |
691 | { | |
692 | gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); | |
693 | gdk_gc_set_clip_origin( m_penGC, 0, 0 ); | |
265898fd | 694 | } |
6f65e337 | 695 | } |
6e13c196 RR |
696 | else /* use_bitmap_method */ |
697 | { | |
698 | /* scale/translate size and position */ | |
699 | ||
700 | long xx = XLOG2DEV(xdest); | |
701 | long yy = YLOG2DEV(ydest); | |
b0e0d661 VZ |
702 | |
703 | long ww = XLOG2DEVREL(width); | |
704 | long hh = YLOG2DEVREL(height); | |
705 | ||
6e13c196 | 706 | if ((width != ww) || (height != hh)) |
b0e0d661 VZ |
707 | { |
708 | /* draw source window into a bitmap as we cannot scale | |
709 | a window in contrast to a bitmap. this would actually | |
710 | work with memory dcs as well, but we'd lose the mask | |
711 | information and waste one step in this process since | |
712 | a memory already has a bitmap. all this is slightly | |
713 | inefficient as we could take an XImage directly from | |
714 | an X window, but we'd then also have to care that | |
715 | the window is not outside the screen (in which case | |
716 | we'd get a BadMatch or what not). | |
717 | Is a double XGetImage and combined XGetPixel and | |
718 | XPutPixel really faster? I'm not sure. look at wxXt | |
719 | for a different implementation of the same problem. */ | |
6e13c196 | 720 | |
b0e0d661 VZ |
721 | wxBitmap bitmap( width, height ); |
722 | gdk_window_copy_area( bitmap.GetPixmap(), m_penGC, 0, 0, | |
6e13c196 | 723 | srcDC->GetWindow(), |
b0e0d661 VZ |
724 | xsrc, ysrc, width, height ); |
725 | ||
726 | /* scale image */ | |
727 | ||
6e13c196 | 728 | wxImage image( bitmap ); |
b0e0d661 VZ |
729 | image = image.Scale( ww, hh ); |
730 | ||
731 | /* convert to bitmap */ | |
732 | ||
733 | bitmap = image.ConvertToBitmap(); | |
734 | ||
735 | /* draw scaled bitmap */ | |
736 | ||
6e13c196 | 737 | gdk_draw_pixmap( m_window, m_penGC, bitmap.GetPixmap(), 0, 0, xx, yy, -1, -1 ); |
b0e0d661 VZ |
738 | |
739 | } | |
740 | else | |
741 | { | |
742 | /* no scaling and not a memory dc with a mask either */ | |
743 | ||
6e13c196 RR |
744 | gdk_window_copy_area( m_window, m_penGC, xx, yy, |
745 | srcDC->GetWindow(), | |
746 | xsrc, ysrc, width, height ); | |
b0e0d661 | 747 | } |
6e13c196 | 748 | } |
c801d85f | 749 | |
4bc67cc5 RR |
750 | SetLogicalFunction( old_logical_func ); |
751 | return TRUE; | |
903f689b | 752 | } |
c801d85f | 753 | |
b0e0d661 | 754 | void wxWindowDC::DoDrawText( const wxString &text, long x, long y ) |
c801d85f | 755 | { |
93c5dd39 | 756 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
18a2fa37 | 757 | |
6db90681 RR |
758 | if (!m_window) return; |
759 | ||
265898fd | 760 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
6f65e337 | 761 | |
265898fd RR |
762 | x = XLOG2DEV(x); |
763 | y = YLOG2DEV(y); | |
18a2fa37 | 764 | |
bbbbe360 | 765 | /* CMB 21/5/98: draw text background if mode is wxSOLID */ |
265898fd RR |
766 | if (m_backgroundMode == wxSOLID) |
767 | { | |
93c5dd39 | 768 | long width = gdk_string_width( font, text.mbc_str() ); |
265898fd RR |
769 | long height = font->ascent + font->descent; |
770 | gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() ); | |
771 | gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height ); | |
772 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
773 | } | |
93c5dd39 | 774 | gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text.mbc_str() ); |
18a2fa37 | 775 | |
bbbbe360 RR |
776 | /* CMB 17/7/98: simple underline: ignores scaling and underlying |
777 | X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS | |
778 | properties (see wxXt implementation) */ | |
265898fd RR |
779 | if (m_font.GetUnderlined()) |
780 | { | |
93c5dd39 | 781 | long width = gdk_string_width( font, text.mbc_str() ); |
265898fd RR |
782 | long ul_y = y + font->ascent; |
783 | if (font->descent > 0) ul_y++; | |
784 | gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y); | |
785 | } | |
786 | ||
787 | long w, h; | |
788 | GetTextExtent (text, &w, &h); | |
789 | CalcBoundingBox (x + w, y + h); | |
790 | CalcBoundingBox (x, y); | |
903f689b | 791 | } |
c801d85f | 792 | |
ec758a20 | 793 | void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height, |
b0e0d661 VZ |
794 | long *descent, long *externalLeading, |
795 | wxFont *theFont ) const | |
c801d85f | 796 | { |
265898fd RR |
797 | wxFont fontToUse = m_font; |
798 | if (theFont) fontToUse = *theFont; | |
c33c4050 | 799 | |
265898fd | 800 | GdkFont *font = fontToUse.GetInternalFont( m_scaleY ); |
93c5dd39 | 801 | if (width) (*width) = long(gdk_string_width( font, string.mbc_str() ) / m_scaleX); |
265898fd RR |
802 | if (height) (*height) = long((font->ascent + font->descent) / m_scaleY); |
803 | if (descent) (*descent) = long(font->descent / m_scaleY); | |
804 | if (externalLeading) (*externalLeading) = 0; // ?? | |
903f689b | 805 | } |
c801d85f | 806 | |
b0e0d661 | 807 | long wxWindowDC::GetCharWidth() const |
c801d85f | 808 | { |
265898fd RR |
809 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
810 | return long(gdk_string_width( font, "H" ) / m_scaleX); | |
903f689b | 811 | } |
c801d85f | 812 | |
b0e0d661 | 813 | long wxWindowDC::GetCharHeight() const |
c801d85f | 814 | { |
265898fd RR |
815 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
816 | return long((font->ascent + font->descent) / m_scaleY); | |
903f689b | 817 | } |
c801d85f | 818 | |
4bc67cc5 | 819 | void wxWindowDC::Clear() |
c801d85f | 820 | { |
93c5dd39 | 821 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 822 | |
6db90681 RR |
823 | if (!m_window) return; |
824 | ||
f234c60c RR |
825 | /* - we either are a memory dc or have a window as the |
826 | owner. anything else shouldn't happen. | |
827 | - we don't use gdk_window_clear() as we don't set | |
828 | the window's background colour anymore. it is too | |
829 | much pain to keep the DC's and the window's back- | |
830 | ground colour in synch. */ | |
831 | ||
832 | if (m_owner) | |
265898fd | 833 | { |
f234c60c RR |
834 | int width,height; |
835 | m_owner->GetSize( &width, &height ); | |
836 | gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height ); | |
b0e0d661 | 837 | return; |
265898fd | 838 | } |
f234c60c RR |
839 | |
840 | if (m_isMemDC) | |
265898fd RR |
841 | { |
842 | int width,height; | |
843 | GetSize( &width, &height ); | |
844 | gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height ); | |
b0e0d661 | 845 | return; |
265898fd | 846 | } |
903f689b | 847 | } |
c801d85f | 848 | |
ec758a20 | 849 | void wxWindowDC::SetFont( const wxFont &font ) |
c801d85f | 850 | { |
265898fd | 851 | m_font = font; |
903f689b | 852 | } |
c801d85f | 853 | |
ec758a20 | 854 | void wxWindowDC::SetPen( const wxPen &pen ) |
c801d85f | 855 | { |
93c5dd39 | 856 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 857 | |
265898fd RR |
858 | if (m_pen == pen) return; |
859 | ||
860 | m_pen = pen; | |
861 | ||
862 | if (!m_pen.Ok()) return; | |
863 | ||
6db90681 RR |
864 | if (!m_window) return; |
865 | ||
265898fd RR |
866 | gint width = m_pen.GetWidth(); |
867 | // CMB: if width is non-zero scale it with the dc | |
868 | if (width <= 0) | |
869 | { | |
870 | width = 1; | |
871 | } | |
872 | else | |
873 | { | |
874 | // X doesn't allow different width in x and y and so we take | |
875 | // the average | |
876 | double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0; | |
877 | width = (int)w; | |
878 | } | |
879 | ||
880 | GdkLineStyle lineStyle = GDK_LINE_SOLID; | |
881 | switch (m_pen.GetStyle()) | |
882 | { | |
883 | case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; } | |
884 | case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
885 | case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
886 | case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
887 | case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; } | |
888 | } | |
889 | ||
890 | GdkCapStyle capStyle = GDK_CAP_ROUND; | |
891 | switch (m_pen.GetCap()) | |
892 | { | |
893 | case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; } | |
894 | case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; } | |
895 | case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; } | |
896 | } | |
897 | ||
898 | GdkJoinStyle joinStyle = GDK_JOIN_ROUND; | |
899 | switch (m_pen.GetJoin()) | |
900 | { | |
901 | case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; } | |
902 | case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; } | |
903 | case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; } | |
904 | } | |
905 | ||
906 | gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle ); | |
907 | ||
908 | m_pen.GetColour().CalcPixel( m_cmap ); | |
909 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
903f689b | 910 | } |
c801d85f | 911 | |
ec758a20 | 912 | void wxWindowDC::SetBrush( const wxBrush &brush ) |
c801d85f | 913 | { |
93c5dd39 | 914 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 915 | |
265898fd | 916 | if (m_brush == brush) return; |
c801d85f | 917 | |
265898fd | 918 | m_brush = brush; |
c801d85f | 919 | |
265898fd | 920 | if (!m_brush.Ok()) return; |
c801d85f | 921 | |
6db90681 RR |
922 | if (!m_window) return; |
923 | ||
265898fd RR |
924 | m_brush.GetColour().CalcPixel( m_cmap ); |
925 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
c801d85f | 926 | |
265898fd RR |
927 | GdkFill fillStyle = GDK_SOLID; |
928 | switch (m_brush.GetStyle()) | |
929 | { | |
930 | case wxSOLID: | |
931 | case wxTRANSPARENT: | |
932 | break; | |
933 | default: | |
934 | fillStyle = GDK_STIPPLED; | |
935 | } | |
c801d85f | 936 | |
265898fd | 937 | gdk_gc_set_fill( m_brushGC, fillStyle ); |
c801d85f | 938 | |
4fcd73bd | 939 | if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok())) |
265898fd | 940 | { |
4fcd73bd RR |
941 | if (m_brush.GetStipple()->GetPixmap()) |
942 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() ); | |
b0e0d661 | 943 | else |
4fcd73bd | 944 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() ); |
265898fd RR |
945 | } |
946 | ||
947 | if (IS_HATCH(m_brush.GetStyle())) | |
948 | { | |
949 | int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH; | |
950 | gdk_gc_set_stipple( m_brushGC, hatches[num] ); | |
951 | } | |
903f689b | 952 | } |
c801d85f | 953 | |
ec758a20 | 954 | void wxWindowDC::SetBackground( const wxBrush &brush ) |
46dc76ba | 955 | { |
bbbbe360 RR |
956 | /* CMB 21/7/98: Added SetBackground. Sets background brush |
957 | * for Clear() and bg colour for shapes filled with cross-hatch brush */ | |
4bc67cc5 | 958 | |
93c5dd39 | 959 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
46dc76ba | 960 | |
265898fd | 961 | if (m_backgroundBrush == brush) return; |
46dc76ba | 962 | |
265898fd | 963 | m_backgroundBrush = brush; |
46dc76ba | 964 | |
265898fd | 965 | if (!m_backgroundBrush.Ok()) return; |
46dc76ba | 966 | |
6db90681 RR |
967 | if (!m_window) return; |
968 | ||
265898fd RR |
969 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); |
970 | gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() ); | |
a802c3a1 | 971 | gdk_gc_set_background( m_penGC, m_backgroundBrush.GetColour().GetColor() ); |
031b2a7b | 972 | gdk_gc_set_background( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); |
265898fd | 973 | gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); |
46dc76ba | 974 | |
265898fd RR |
975 | GdkFill fillStyle = GDK_SOLID; |
976 | switch (m_backgroundBrush.GetStyle()) | |
977 | { | |
bbbbe360 RR |
978 | case wxSOLID: |
979 | case wxTRANSPARENT: | |
980 | break; | |
981 | default: | |
982 | fillStyle = GDK_STIPPLED; | |
265898fd | 983 | } |
46dc76ba | 984 | |
265898fd | 985 | gdk_gc_set_fill( m_bgGC, fillStyle ); |
46dc76ba | 986 | |
265898fd RR |
987 | if (m_backgroundBrush.GetStyle() == wxSTIPPLE) |
988 | { | |
989 | gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); | |
990 | } | |
46dc76ba | 991 | |
265898fd RR |
992 | if (IS_HATCH(m_backgroundBrush.GetStyle())) |
993 | { | |
994 | int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; | |
995 | gdk_gc_set_stipple( m_bgGC, hatches[num] ); | |
bbbbe360 | 996 | } |
903f689b | 997 | } |
46dc76ba | 998 | |
ec758a20 | 999 | void wxWindowDC::SetLogicalFunction( int function ) |
c801d85f | 1000 | { |
93c5dd39 | 1001 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1002 | |
265898fd | 1003 | if (m_logicalFunction == function) return; |
01eaf507 | 1004 | |
265898fd RR |
1005 | GdkFunction mode = GDK_COPY; |
1006 | switch (function) | |
1007 | { | |
3c679789 RR |
1008 | case wxXOR: mode = GDK_XOR; break; |
1009 | case wxINVERT: mode = GDK_INVERT; break; | |
01eaf507 | 1010 | #if (GTK_MINOR_VERSION > 0) |
3c679789 RR |
1011 | case wxOR_REVERSE: mode = GDK_OR_REVERSE; break; |
1012 | case wxAND_REVERSE: mode = GDK_AND_REVERSE; break; | |
1013 | case wxCLEAR: mode = GDK_CLEAR; break; | |
1014 | case wxSET: mode = GDK_SET; break; | |
1015 | case wxOR_INVERT: mode = GDK_OR_INVERT; break; | |
01eaf507 | 1016 | case wxSRC_AND: |
3c679789 | 1017 | case wxAND: mode = GDK_AND; break; |
01eaf507 | 1018 | case wxSRC_OR: |
3c679789 RR |
1019 | case wxOR: mode = GDK_OR; break; |
1020 | case wxEQUIV: mode = GDK_EQUIV; break; | |
1021 | case wxNAND: mode = GDK_NAND; break; | |
1022 | case wxAND_INVERT: mode = GDK_AND_INVERT; break; | |
01eaf507 RR |
1023 | case wxCOPY: mode = GDK_COPY; break; |
1024 | case wxNO_OP: mode = GDK_NOOP; break; | |
1025 | case wxSRC_INVERT: mode = GDK_COPY_INVERT; break; | |
c96faa7c | 1026 | #endif |
01eaf507 RR |
1027 | default: |
1028 | { | |
861ccde4 | 1029 | wxFAIL_MSG( _T("unsupported logical function") ); |
01eaf507 RR |
1030 | break; |
1031 | } | |
265898fd | 1032 | } |
4bc67cc5 | 1033 | |
265898fd | 1034 | m_logicalFunction = function; |
6db90681 RR |
1035 | |
1036 | if (!m_window) return; | |
1037 | ||
265898fd RR |
1038 | gdk_gc_set_function( m_penGC, mode ); |
1039 | gdk_gc_set_function( m_brushGC, mode ); | |
3bc755fc | 1040 | gdk_gc_set_function( m_textGC, mode ); |
903f689b | 1041 | } |
c801d85f | 1042 | |
ec758a20 | 1043 | void wxWindowDC::SetTextForeground( const wxColour &col ) |
c801d85f | 1044 | { |
93c5dd39 | 1045 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 1046 | |
265898fd | 1047 | if (m_textForegroundColour == col) return; |
c801d85f | 1048 | |
265898fd RR |
1049 | m_textForegroundColour = col; |
1050 | if (!m_textForegroundColour.Ok()) return; | |
c801d85f | 1051 | |
6db90681 RR |
1052 | if (!m_window) return; |
1053 | ||
265898fd RR |
1054 | m_textForegroundColour.CalcPixel( m_cmap ); |
1055 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
903f689b | 1056 | } |
c801d85f | 1057 | |
ec758a20 | 1058 | void wxWindowDC::SetTextBackground( const wxColour &col ) |
c801d85f | 1059 | { |
93c5dd39 | 1060 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
c801d85f | 1061 | |
265898fd | 1062 | if (m_textBackgroundColour == col) return; |
c801d85f | 1063 | |
265898fd RR |
1064 | m_textBackgroundColour = col; |
1065 | if (!m_textBackgroundColour.Ok()) return; | |
c801d85f | 1066 | |
6db90681 RR |
1067 | if (!m_window) return; |
1068 | ||
265898fd RR |
1069 | m_textBackgroundColour.CalcPixel( m_cmap ); |
1070 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
903f689b | 1071 | } |
c801d85f | 1072 | |
ec758a20 | 1073 | void wxWindowDC::SetBackgroundMode( int mode ) |
c801d85f | 1074 | { |
93c5dd39 | 1075 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1076 | |
265898fd | 1077 | m_backgroundMode = mode; |
46dc76ba | 1078 | |
6db90681 RR |
1079 | if (!m_window) return; |
1080 | ||
265898fd RR |
1081 | // CMB 21/7/98: fill style of cross-hatch brushes is affected by |
1082 | // transparent/solid background mode | |
4bc67cc5 | 1083 | |
265898fd RR |
1084 | if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT) |
1085 | { | |
1086 | gdk_gc_set_fill( m_brushGC, | |
1087 | (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED); | |
1088 | } | |
903f689b | 1089 | } |
c801d85f | 1090 | |
ec758a20 | 1091 | void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) ) |
c801d85f | 1092 | { |
93c5dd39 | 1093 | wxFAIL_MSG( _T("wxWindowDC::SetPalette not implemented") ); |
903f689b | 1094 | } |
c801d85f | 1095 | |
b0e0d661 | 1096 | void wxWindowDC::DoSetClippingRegion( long x, long y, long width, long height ) |
c801d85f | 1097 | { |
93c5dd39 | 1098 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1099 | |
089e55d6 | 1100 | wxDC::DoSetClippingRegion( x, y, width, height ); |
c801d85f | 1101 | |
6db90681 RR |
1102 | if (!m_window) return; |
1103 | ||
265898fd RR |
1104 | GdkRectangle rect; |
1105 | rect.x = XLOG2DEV(x); | |
1106 | rect.y = YLOG2DEV(y); | |
1107 | rect.width = XLOG2DEVREL(width); | |
1108 | rect.height = YLOG2DEVREL(height); | |
1109 | gdk_gc_set_clip_rectangle( m_penGC, &rect ); | |
1110 | gdk_gc_set_clip_rectangle( m_brushGC, &rect ); | |
1111 | gdk_gc_set_clip_rectangle( m_textGC, &rect ); | |
1112 | gdk_gc_set_clip_rectangle( m_bgGC, &rect ); | |
903f689b | 1113 | } |
c801d85f | 1114 | |
b0e0d661 | 1115 | void wxWindowDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
463c1fa1 | 1116 | { |
93c5dd39 | 1117 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1118 | |
463c1fa1 RR |
1119 | if (region.Empty()) |
1120 | { | |
1121 | DestroyClippingRegion(); | |
1122 | return; | |
1123 | } | |
1124 | ||
6db90681 RR |
1125 | if (!m_window) return; |
1126 | ||
463c1fa1 RR |
1127 | gdk_gc_set_clip_region( m_penGC, region.GetRegion() ); |
1128 | gdk_gc_set_clip_region( m_brushGC, region.GetRegion() ); | |
1129 | gdk_gc_set_clip_region( m_textGC, region.GetRegion() ); | |
1130 | gdk_gc_set_clip_region( m_bgGC, region.GetRegion() ); | |
1131 | } | |
1132 | ||
4bc67cc5 | 1133 | void wxWindowDC::DestroyClippingRegion() |
c801d85f | 1134 | { |
93c5dd39 | 1135 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1136 | |
265898fd | 1137 | wxDC::DestroyClippingRegion(); |
c801d85f | 1138 | |
6db90681 RR |
1139 | if (!m_window) return; |
1140 | ||
265898fd RR |
1141 | gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL ); |
1142 | gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL ); | |
1143 | gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL ); | |
1144 | gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL ); | |
903f689b | 1145 | } |
c801d85f | 1146 | |
4bc67cc5 | 1147 | void wxWindowDC::SetUpDC() |
c801d85f | 1148 | { |
265898fd RR |
1149 | Destroy(); |
1150 | m_ok = TRUE; | |
1151 | m_logicalFunction = wxCOPY; | |
1152 | m_penGC = gdk_gc_new( m_window ); | |
1153 | m_brushGC = gdk_gc_new( m_window ); | |
1154 | m_textGC = gdk_gc_new( m_window ); | |
1155 | m_bgGC = gdk_gc_new( m_window ); | |
a802c3a1 RR |
1156 | |
1157 | wxColour tmp_col( m_textForegroundColour ); | |
1158 | m_textForegroundColour = wxNullColour; | |
1159 | SetTextForeground( tmp_col ); | |
1160 | tmp_col = m_textBackgroundColour; | |
1161 | m_textBackgroundColour = wxNullColour; | |
1162 | SetTextBackground( tmp_col ); | |
031b2a7b RR |
1163 | |
1164 | wxPen tmp_pen( m_pen ); | |
1165 | m_pen = wxNullPen; | |
1166 | SetPen( tmp_pen ); | |
1167 | ||
1168 | wxFont tmp_font( m_font ); | |
1169 | m_font = wxNullFont; | |
1170 | SetFont( tmp_font ); | |
1171 | ||
1172 | wxBrush tmp_brush( m_brush ); | |
1173 | m_brush = wxNullBrush; | |
1174 | SetBrush( tmp_brush ); | |
1175 | ||
91b8de8d | 1176 | /* |
031b2a7b RR |
1177 | tmp_brush = m_backgroundBrush; |
1178 | m_backgroundBrush = wxNullBrush; | |
1179 | SetBackground( tmp_brush ); | |
91b8de8d RR |
1180 | */ |
1181 | tmp_brush = m_backgroundBrush; | |
1182 | m_backgroundBrush = wxNullBrush; | |
1183 | SetBackground( *wxWHITE_BRUSH ); | |
1184 | m_backgroundBrush = tmp_brush; | |
265898fd | 1185 | |
265898fd RR |
1186 | if (!hatch_bitmap) |
1187 | { | |
1188 | hatch_bitmap = hatches; | |
1189 | hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height ); | |
1190 | hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height ); | |
1191 | hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height ); | |
1192 | hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height ); | |
1193 | hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height ); | |
1194 | hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height ); | |
1195 | } | |
903f689b | 1196 | } |
c801d85f | 1197 | |
4bc67cc5 | 1198 | void wxWindowDC::Destroy() |
dbf858b5 | 1199 | { |
265898fd RR |
1200 | if (m_penGC) gdk_gc_unref( m_penGC ); |
1201 | m_penGC = (GdkGC*) NULL; | |
1202 | if (m_brushGC) gdk_gc_unref( m_brushGC ); | |
1203 | m_brushGC = (GdkGC*) NULL; | |
1204 | if (m_textGC) gdk_gc_unref( m_textGC ); | |
1205 | m_textGC = (GdkGC*) NULL; | |
1206 | if (m_bgGC) gdk_gc_unref( m_bgGC ); | |
1207 | m_bgGC = (GdkGC*) NULL; | |
dbf858b5 RR |
1208 | } |
1209 | ||
238d735d RR |
1210 | void wxWindowDC::ComputeScaleAndOrigin() |
1211 | { | |
1212 | /* CMB: copy scale to see if it changes */ | |
1213 | double origScaleX = m_scaleX; | |
1214 | double origScaleY = m_scaleY; | |
1215 | ||
1216 | wxDC::ComputeScaleAndOrigin(); | |
1217 | ||
1218 | /* CMB: if scale has changed call SetPen to recalulate the line width */ | |
1219 | if ((m_scaleX != origScaleX || m_scaleY != origScaleY) && | |
1220 | (m_pen.Ok())) | |
1221 | { | |
1222 | /* this is a bit artificial, but we need to force wxDC to think | |
1223 | the pen has changed */ | |
1224 | wxPen pen = m_pen; | |
1225 | m_pen = wxNullPen; | |
1226 | SetPen( pen ); | |
1227 | } | |
1228 | } | |
1229 | ||
b0e0d661 VZ |
1230 | // Resolution in pixels per logical inch |
1231 | wxSize wxWindowDC::GetPPI() const | |
1232 | { | |
1233 | return wxSize(100, 100); | |
1234 | } | |
1235 | ||
1236 | int wxWindowDC::GetDepth() const | |
c801d85f | 1237 | { |
b0e0d661 VZ |
1238 | wxFAIL_MSG(_T("not implemented")); |
1239 | ||
1240 | return -1; | |
903f689b | 1241 | } |
c801d85f | 1242 | |
d54e4256 | 1243 | #if wxUSE_SPLINES |
c801d85f KB |
1244 | // ----------------------------------- spline code ---------------------------------------- |
1245 | ||
1246 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, | |
1247 | double a3, double b3, double a4, double b4); | |
4bc67cc5 | 1248 | void wx_clear_stack(); |
c801d85f KB |
1249 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, |
1250 | double *y3, double *x4, double *y4); | |
1251 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, | |
1252 | double x4, double y4); | |
1253 | static bool wx_spline_add_point(double x, double y); | |
1254 | static void wx_spline_draw_point_array(wxDC *dc); | |
1255 | ||
1256 | wxList wx_spline_point_list; | |
1257 | ||
b0e0d661 VZ |
1258 | #define half(z1, z2) ((z1+z2)/2.0) |
1259 | #define THRESHOLD 5 | |
c801d85f KB |
1260 | |
1261 | /* iterative version */ | |
1262 | ||
1263 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, | |
1264 | double b4) | |
1265 | { | |
1266 | register double xmid, ymid; | |
1267 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1268 | ||
1269 | wx_clear_stack(); | |
1270 | wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); | |
1271 | ||
1272 | while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { | |
1273 | xmid = (double)half(x2, x3); | |
1274 | ymid = (double)half(y2, y3); | |
b0e0d661 VZ |
1275 | if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && |
1276 | fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { | |
c801d85f KB |
1277 | wx_spline_add_point( x1, y1 ); |
1278 | wx_spline_add_point( xmid, ymid ); | |
b0e0d661 | 1279 | } else { |
c801d85f KB |
1280 | wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), |
1281 | (double)half(x3, x4), (double)half(y3, y4), x4, y4); | |
1282 | wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), | |
1283 | (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); | |
b0e0d661 | 1284 | } |
c801d85f KB |
1285 | } |
1286 | } | |
1287 | ||
1288 | /* utilities used by spline drawing routines */ | |
1289 | ||
1290 | typedef struct wx_spline_stack_struct { | |
1291 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1292 | } Stack; | |
1293 | ||
1294 | #define SPLINE_STACK_DEPTH 20 | |
1295 | static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; | |
1296 | static Stack *wx_stack_top; | |
1297 | static int wx_stack_count; | |
1298 | ||
4bc67cc5 | 1299 | void wx_clear_stack() |
c801d85f KB |
1300 | { |
1301 | wx_stack_top = wx_spline_stack; | |
1302 | wx_stack_count = 0; | |
1303 | } | |
1304 | ||
1305 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) | |
1306 | { | |
1307 | wx_stack_top->x1 = x1; | |
1308 | wx_stack_top->y1 = y1; | |
1309 | wx_stack_top->x2 = x2; | |
1310 | wx_stack_top->y2 = y2; | |
1311 | wx_stack_top->x3 = x3; | |
1312 | wx_stack_top->y3 = y3; | |
1313 | wx_stack_top->x4 = x4; | |
1314 | wx_stack_top->y4 = y4; | |
1315 | wx_stack_top++; | |
1316 | wx_stack_count++; | |
1317 | } | |
1318 | ||
1319 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, | |
1320 | double *x3, double *y3, double *x4, double *y4) | |
1321 | { | |
1322 | if (wx_stack_count == 0) | |
b0e0d661 | 1323 | return (0); |
c801d85f KB |
1324 | wx_stack_top--; |
1325 | wx_stack_count--; | |
1326 | *x1 = wx_stack_top->x1; | |
1327 | *y1 = wx_stack_top->y1; | |
1328 | *x2 = wx_stack_top->x2; | |
1329 | *y2 = wx_stack_top->y2; | |
1330 | *x3 = wx_stack_top->x3; | |
1331 | *y3 = wx_stack_top->y3; | |
1332 | *x4 = wx_stack_top->x4; | |
1333 | *y4 = wx_stack_top->y4; | |
1334 | return (1); | |
1335 | } | |
1336 | ||
1337 | static bool wx_spline_add_point(double x, double y) | |
1338 | { | |
1339 | wxPoint *point = new wxPoint ; | |
1340 | point->x = (int) x; | |
1341 | point->y = (int) y; | |
1342 | wx_spline_point_list.Append((wxObject*)point); | |
1343 | return TRUE; | |
1344 | } | |
1345 | ||
1346 | static void wx_spline_draw_point_array(wxDC *dc) | |
1347 | { | |
1348 | dc->DrawLines(&wx_spline_point_list, 0, 0 ); | |
1349 | wxNode *node = wx_spline_point_list.First(); | |
1350 | while (node) | |
1351 | { | |
1352 | wxPoint *point = (wxPoint *)node->Data(); | |
1353 | delete point; | |
1354 | delete node; | |
1355 | node = wx_spline_point_list.First(); | |
1356 | } | |
1357 | } | |
1358 | ||
b0e0d661 | 1359 | void wxWindowDC::DoDrawSpline( wxList *points ) |
c801d85f | 1360 | { |
93c5dd39 | 1361 | wxCHECK_RET( Ok(), _T("invalid window dc") ); |
4bc67cc5 | 1362 | |
c801d85f KB |
1363 | wxPoint *p; |
1364 | double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; | |
1365 | double x1, y1, x2, y2; | |
1366 | ||
1367 | wxNode *node = points->First(); | |
1368 | p = (wxPoint *)node->Data(); | |
1369 | ||
1370 | x1 = p->x; | |
1371 | y1 = p->y; | |
1372 | ||
1373 | node = node->Next(); | |
1374 | p = (wxPoint *)node->Data(); | |
1375 | ||
1376 | x2 = p->x; | |
1377 | y2 = p->y; | |
1378 | cx1 = (double)((x1 + x2) / 2); | |
1379 | cy1 = (double)((y1 + y2) / 2); | |
1380 | cx2 = (double)((cx1 + x2) / 2); | |
1381 | cy2 = (double)((cy1 + y2) / 2); | |
1382 | ||
1383 | wx_spline_add_point(x1, y1); | |
1384 | ||
1385 | while ((node = node->Next()) != NULL) | |
1386 | { | |
1387 | p = (wxPoint *)node->Data(); | |
b0e0d661 VZ |
1388 | x1 = x2; |
1389 | y1 = y2; | |
1390 | x2 = p->x; | |
1391 | y2 = p->y; | |
c801d85f KB |
1392 | cx4 = (double)(x1 + x2) / 2; |
1393 | cy4 = (double)(y1 + y2) / 2; | |
1394 | cx3 = (double)(x1 + cx4) / 2; | |
1395 | cy3 = (double)(y1 + cy4) / 2; | |
1396 | ||
1397 | wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); | |
1398 | ||
b0e0d661 VZ |
1399 | cx1 = cx4; |
1400 | cy1 = cy4; | |
c801d85f KB |
1401 | cx2 = (double)(cx1 + x2) / 2; |
1402 | cy2 = (double)(cy1 + y2) / 2; | |
1403 | } | |
1404 | ||
1405 | wx_spline_add_point( cx1, cy1 ); | |
1406 | wx_spline_add_point( x2, y2 ); | |
1407 | ||
1408 | wx_spline_draw_point_array( this ); | |
903f689b | 1409 | } |
ec758a20 | 1410 | |
b0e0d661 | 1411 | #endif // wxUSE_SPLINE |
ec758a20 RR |
1412 | |
1413 | //----------------------------------------------------------------------------- | |
1414 | // wxPaintDC | |
1415 | //----------------------------------------------------------------------------- | |
1416 | ||
1417 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxWindowDC) | |
1418 | ||
4bc67cc5 | 1419 | wxPaintDC::wxPaintDC() |
ec758a20 RR |
1420 | : wxWindowDC() |
1421 | { | |
1422 | } | |
1423 | ||
1424 | wxPaintDC::wxPaintDC( wxWindow *win ) | |
1425 | : wxWindowDC( win ) | |
1426 | { | |
1427 | } | |
1428 | ||
1429 | //----------------------------------------------------------------------------- | |
1430 | // wxClientDC | |
1431 | //----------------------------------------------------------------------------- | |
1432 | ||
1433 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC,wxWindowDC) | |
1434 | ||
4bc67cc5 | 1435 | wxClientDC::wxClientDC() |
ec758a20 RR |
1436 | : wxWindowDC() |
1437 | { | |
1438 | } | |
1439 | ||
1440 | wxClientDC::wxClientDC( wxWindow *win ) | |
1441 | : wxWindowDC( win ) | |
1442 | { | |
1443 | } | |
1444 |