]>
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 |
c801d85f KB |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "dcclient.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/dcclient.h" | |
6f65e337 | 15 | #include "wx/dcmemory.h" |
f5368809 | 16 | #include <math.h> |
c801d85f KB |
17 | |
18 | //----------------------------------------------------------------------------- | |
19 | // local data | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | #include "bdiag.xbm" | |
23 | #include "fdiag.xbm" | |
24 | #include "cdiag.xbm" | |
25 | #include "horiz.xbm" | |
26 | #include "verti.xbm" | |
27 | #include "cross.xbm" | |
28 | #define num_hatches 6 | |
29 | ||
30 | static GdkPixmap *hatches[num_hatches]; | |
c67daf87 | 31 | static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; |
c801d85f KB |
32 | |
33 | //----------------------------------------------------------------------------- | |
34 | // constants | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
37 | #define RAD2DEG 57.2957795131 | |
38 | ||
6f65e337 JS |
39 | //----------------------------------------------------------------------------- |
40 | // temporary implementation of the missing GDK function | |
41 | //----------------------------------------------------------------------------- | |
42 | #include "gdk/gdkprivate.h" | |
43 | void gdk_draw_bitmap (GdkDrawable *drawable, | |
44 | GdkGC *gc, | |
45 | GdkDrawable *src, | |
46 | gint xsrc, | |
47 | gint ysrc, | |
48 | gint xdest, | |
49 | gint ydest, | |
50 | gint width, | |
51 | gint height) | |
52 | { | |
265898fd RR |
53 | GdkWindowPrivate *drawable_private; |
54 | GdkWindowPrivate *src_private; | |
55 | GdkGCPrivate *gc_private; | |
56 | ||
57 | g_return_if_fail (drawable != NULL); | |
58 | g_return_if_fail (src != NULL); | |
59 | g_return_if_fail (gc != NULL); | |
60 | ||
61 | drawable_private = (GdkWindowPrivate*) drawable; | |
62 | src_private = (GdkWindowPrivate*) src; | |
63 | if (drawable_private->destroyed || src_private->destroyed) | |
64 | return; | |
65 | ||
66 | gc_private = (GdkGCPrivate*) gc; | |
67 | ||
68 | if (width == -1) width = src_private->width; | |
69 | if (height == -1) height = src_private->height; | |
70 | ||
71 | XCopyPlane( drawable_private->xdisplay, | |
72 | src_private->xwindow, | |
73 | drawable_private->xwindow, | |
74 | gc_private->xgc, | |
75 | xsrc, ysrc, | |
76 | width, height, | |
77 | xdest, ydest, | |
78 | 1 ); | |
6f65e337 JS |
79 | } |
80 | ||
c801d85f KB |
81 | //----------------------------------------------------------------------------- |
82 | // wxPaintDC | |
83 | //----------------------------------------------------------------------------- | |
84 | ||
85 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC,wxDC) | |
86 | ||
87 | wxPaintDC::wxPaintDC(void) | |
88 | { | |
265898fd RR |
89 | m_penGC = (GdkGC *) NULL; |
90 | m_brushGC = (GdkGC *) NULL; | |
91 | m_textGC = (GdkGC *) NULL; | |
92 | m_bgGC = (GdkGC *) NULL; | |
93 | m_cmap = (GdkColormap *) NULL; | |
94 | m_isMemDC = FALSE; | |
903f689b | 95 | } |
c801d85f KB |
96 | |
97 | wxPaintDC::wxPaintDC( wxWindow *window ) | |
98 | { | |
265898fd RR |
99 | m_penGC = (GdkGC *) NULL; |
100 | m_brushGC = (GdkGC *) NULL; | |
101 | m_textGC = (GdkGC *) NULL; | |
102 | m_bgGC = (GdkGC *) NULL; | |
103 | m_cmap = (GdkColormap *) NULL; | |
104 | ||
105 | if (!window) return; | |
106 | GtkWidget *widget = window->m_wxwindow; | |
107 | if (!widget) return; | |
108 | m_window = widget->window; | |
109 | if (!m_window) return; | |
110 | if (window->m_wxwindow) | |
111 | m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); | |
112 | else | |
113 | m_cmap = gtk_widget_get_colormap( window->m_widget ); | |
0180d5da | 114 | |
265898fd | 115 | m_isMemDC = FALSE; |
0180d5da | 116 | |
265898fd | 117 | SetUpDC(); |
903f689b | 118 | } |
c801d85f KB |
119 | |
120 | wxPaintDC::~wxPaintDC(void) | |
121 | { | |
265898fd | 122 | Destroy(); |
903f689b | 123 | } |
c801d85f KB |
124 | |
125 | void wxPaintDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1), | |
265898fd | 126 | wxColour *WXUNUSED(col), int WXUNUSED(style) ) |
c801d85f | 127 | { |
265898fd | 128 | wxFAIL_MSG( "wxPaintDC::FloodFill not implemented" ); |
903f689b | 129 | } |
c801d85f KB |
130 | |
131 | bool wxPaintDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const | |
132 | { | |
265898fd RR |
133 | wxFAIL_MSG( "wxPaintDC::GetPixel not implemented" ); |
134 | return FALSE; | |
903f689b | 135 | } |
c801d85f KB |
136 | |
137 | void wxPaintDC::DrawLine( long x1, long y1, long x2, long y2 ) | |
138 | { | |
265898fd | 139 | if (!Ok()) return; |
c801d85f | 140 | |
265898fd RR |
141 | if (m_pen.GetStyle() != wxTRANSPARENT) |
142 | { | |
143 | gdk_draw_line( m_window, m_penGC, | |
144 | XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2) ); | |
145 | } | |
146 | ||
147 | CalcBoundingBox(x1, y1); | |
148 | CalcBoundingBox(x2, y2); | |
903f689b | 149 | } |
c801d85f KB |
150 | |
151 | void wxPaintDC::CrossHair( long x, long y ) | |
152 | { | |
265898fd | 153 | if (!Ok()) return; |
c801d85f | 154 | |
265898fd RR |
155 | if (m_pen.GetStyle() != wxTRANSPARENT) |
156 | { | |
157 | int w = 0; | |
158 | int h = 0; | |
159 | GetSize( &w, &h ); | |
160 | long xx = XLOG2DEV(x); | |
161 | long yy = YLOG2DEV(y); | |
162 | gdk_draw_line( m_window, m_penGC, 0, yy, XLOG2DEVREL(w), yy ); | |
163 | gdk_draw_line( m_window, m_penGC, xx, 0, xx, YLOG2DEVREL(h) ); | |
164 | } | |
903f689b | 165 | } |
c801d85f KB |
166 | |
167 | void wxPaintDC::DrawArc( long x1, long y1, long x2, long y2, double xc, double yc ) | |
168 | { | |
265898fd RR |
169 | if (!Ok()) return; |
170 | ||
171 | long xx1 = XLOG2DEV(x1); | |
172 | long yy1 = YLOG2DEV(y1); | |
173 | long xx2 = XLOG2DEV(x2); | |
174 | long yy2 = YLOG2DEV(y2); | |
175 | long xxc = XLOG2DEV((long)xc); | |
176 | long yyc = YLOG2DEV((long)yc); | |
177 | double dx = xx1 - xxc; | |
178 | double dy = yy1 - yyc; | |
179 | double radius = sqrt(dx*dx+dy*dy); | |
180 | long r = (long)radius; | |
181 | double radius1, radius2; | |
182 | ||
183 | if (xx1 == xx2 && yy1 == yy2) | |
184 | { | |
185 | radius1 = 0.0; | |
186 | radius2 = 360.0; | |
187 | } | |
188 | else | |
189 | if (radius == 0.0) | |
190 | { | |
191 | radius1 = radius2 = 0.0; | |
192 | } | |
193 | else | |
194 | { | |
195 | radius1 = (xx1 - xxc == 0) ? | |
c801d85f KB |
196 | (yy1 - yyc < 0) ? 90.0 : -90.0 : |
197 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
265898fd | 198 | radius2 = (xx2 - xxc == 0) ? |
c801d85f KB |
199 | (yy2 - yyc < 0) ? 90.0 : -90.0 : |
200 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
265898fd RR |
201 | } |
202 | long alpha1 = long(radius1 * 64.0); | |
203 | long alpha2 = long((radius2 - radius1) * 64.0); | |
204 | while (alpha2 <= 0) alpha2 += 360*64; | |
205 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
206 | ||
207 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
208 | gdk_draw_arc( m_window, m_brushGC, TRUE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); | |
c801d85f | 209 | |
265898fd RR |
210 | if (m_pen.GetStyle() != wxTRANSPARENT) |
211 | gdk_draw_arc( m_window, m_penGC, FALSE, xxc-r, yyc-r, 2*r,2*r, alpha1, alpha2 ); | |
212 | ||
213 | CalcBoundingBox (x1, y1); | |
214 | CalcBoundingBox (x2, y2); | |
903f689b | 215 | } |
c801d85f KB |
216 | |
217 | void wxPaintDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) | |
218 | { | |
265898fd | 219 | if (!Ok()) return; |
c801d85f | 220 | |
265898fd RR |
221 | long xx = XLOG2DEV(x); |
222 | long yy = YLOG2DEV(y); | |
223 | long ww = m_signX * XLOG2DEVREL(width); | |
224 | long hh = m_signY * YLOG2DEVREL(height); | |
c801d85f | 225 | |
265898fd RR |
226 | // CMB: handle -ve width and/or height |
227 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
228 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 229 | |
265898fd RR |
230 | long start = long(sa * 64.0); |
231 | long end = long(ea * 64.0); | |
232 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
233 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, start, end ); | |
c801d85f | 234 | |
265898fd RR |
235 | if (m_pen.GetStyle() != wxTRANSPARENT) |
236 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, start, end ); | |
237 | ||
238 | CalcBoundingBox (x, y); | |
239 | CalcBoundingBox (x + width, y + height); | |
903f689b | 240 | } |
c801d85f KB |
241 | |
242 | void wxPaintDC::DrawPoint( long x, long y ) | |
243 | { | |
265898fd | 244 | if (!Ok()) return; |
c801d85f | 245 | |
265898fd RR |
246 | if (m_pen.GetStyle() != wxTRANSPARENT) |
247 | gdk_draw_point( m_window, m_penGC, XLOG2DEV(x), YLOG2DEV(y) ); | |
248 | ||
249 | CalcBoundingBox (x, y); | |
903f689b | 250 | } |
c801d85f KB |
251 | |
252 | void wxPaintDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset ) | |
253 | { | |
265898fd | 254 | if (!Ok()) return; |
c801d85f | 255 | |
265898fd RR |
256 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
257 | if (n <= 0) return; | |
c801d85f | 258 | |
265898fd RR |
259 | CalcBoundingBox( points[0].x + xoffset, points[0].y + yoffset ); |
260 | ||
261 | for (int i = 0; i < n-1; i++) | |
262 | { | |
263 | long x1 = XLOG2DEV(points[i].x + xoffset); | |
264 | long x2 = XLOG2DEV(points[i+1].x + xoffset); | |
265 | long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste | |
266 | long y2 = YLOG2DEV(points[i+1].y + yoffset); | |
267 | gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 ); | |
268 | ||
269 | CalcBoundingBox( points[i+1].x + xoffset, points[i+1].y + yoffset ); | |
270 | } | |
903f689b | 271 | } |
c801d85f KB |
272 | |
273 | void wxPaintDC::DrawLines( wxList *points, long xoffset, long yoffset ) | |
274 | { | |
265898fd | 275 | if (!Ok()) return; |
c801d85f | 276 | |
265898fd | 277 | if (m_pen.GetStyle() == wxTRANSPARENT) return; |
c801d85f | 278 | |
265898fd RR |
279 | wxNode *node = points->First(); |
280 | if (!node) return; | |
281 | ||
282 | wxPoint *pt = (wxPoint*)node->Data(); | |
283 | CalcBoundingBox( pt->x + xoffset, pt->y + yoffset ); | |
284 | ||
285 | while (node->Next()) | |
286 | { | |
287 | wxPoint *point = (wxPoint*)node->Data(); | |
288 | wxPoint *npoint = (wxPoint*)node->Next()->Data(); | |
289 | long x1 = XLOG2DEV(point->x + xoffset); | |
290 | long x2 = XLOG2DEV(npoint->x + xoffset); | |
291 | long y1 = YLOG2DEV(point->y + yoffset); // and a waste again... | |
292 | long y2 = YLOG2DEV(npoint->y + yoffset); | |
293 | gdk_draw_line( m_window, m_penGC, x1, y1, x2, y2 ); | |
294 | node = node->Next(); | |
295 | ||
296 | CalcBoundingBox( npoint->x + xoffset, npoint->y + yoffset ); | |
297 | } | |
903f689b | 298 | } |
c801d85f | 299 | |
cf7a7e13 RR |
300 | void wxPaintDC::DrawPolygon( int n, wxPoint points[], long xoffset, long yoffset, int WXUNUSED(fillStyle) ) |
301 | { | |
265898fd | 302 | if (!Ok()) return; |
cf7a7e13 | 303 | |
265898fd RR |
304 | if (!n) return; |
305 | ||
306 | GdkPoint *gdkpoints = new GdkPoint[n+1]; | |
307 | int i; | |
308 | for (i = 0 ; i < n ; i++) | |
309 | { | |
310 | gdkpoints[i].x = XLOG2DEV(points[i].x + xoffset); | |
311 | gdkpoints[i].y = YLOG2DEV(points[i].y + yoffset); | |
312 | ||
313 | CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); | |
314 | } | |
315 | ||
316 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
317 | gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); | |
318 | ||
319 | // To do: Fillstyle | |
320 | ||
321 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
322 | for (i = 0 ; i < n ; i++) | |
323 | { | |
324 | gdk_draw_line( m_window, m_penGC, | |
325 | gdkpoints[i%n].x, | |
326 | gdkpoints[i%n].y, | |
327 | gdkpoints[(i+1)%n].x, | |
328 | gdkpoints[(i+1)%n].y); | |
329 | } | |
330 | ||
331 | delete[] gdkpoints; | |
903f689b | 332 | } |
c801d85f | 333 | |
cf7a7e13 RR |
334 | void wxPaintDC::DrawPolygon( wxList *lines, long xoffset, long yoffset, int WXUNUSED(fillStyle)) |
335 | { | |
265898fd RR |
336 | if (!Ok()) return; |
337 | ||
338 | int n = lines->Number(); | |
339 | if (!n) return; | |
340 | ||
341 | GdkPoint *gdkpoints = new GdkPoint[n]; | |
342 | wxNode *node = lines->First(); | |
343 | int cnt = 0; | |
344 | while (node) | |
345 | { | |
346 | wxPoint *p = (wxPoint *) node->Data(); | |
347 | gdkpoints[cnt].x = XLOG2DEV(p->x + xoffset); | |
348 | gdkpoints[cnt].y = YLOG2DEV(p->y + yoffset); | |
349 | node = node->Next(); | |
350 | cnt++; | |
351 | ||
352 | CalcBoundingBox( p->x + xoffset, p->y + yoffset ); | |
353 | } | |
354 | ||
355 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
356 | gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); | |
357 | ||
358 | // To do: Fillstyle | |
359 | ||
360 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
361 | { | |
362 | int i; | |
363 | for (i = 0 ; i < n ; i++) | |
364 | { | |
365 | gdk_draw_line( m_window, m_penGC, | |
366 | gdkpoints[i%n].x, | |
367 | gdkpoints[i%n].y, | |
368 | gdkpoints[(i+1)%n].x, | |
369 | gdkpoints[(i+1)%n].y ); | |
370 | } | |
371 | } | |
372 | delete[] gdkpoints; | |
903f689b | 373 | } |
c801d85f KB |
374 | |
375 | void wxPaintDC::DrawRectangle( long x, long y, long width, long height ) | |
376 | { | |
265898fd | 377 | if (!Ok()) return; |
c801d85f | 378 | |
265898fd RR |
379 | long xx = XLOG2DEV(x); |
380 | long yy = YLOG2DEV(y); | |
381 | long ww = m_signX * XLOG2DEVREL(width); | |
382 | long hh = m_signY * YLOG2DEVREL(height); | |
c801d85f | 383 | |
265898fd RR |
384 | // CMB: draw nothing if transformed w or h is 0 |
385 | if (ww == 0 || hh == 0) return; | |
6f65e337 | 386 | |
265898fd RR |
387 | // CMB: handle -ve width and/or height |
388 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
389 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
6f65e337 | 390 | |
265898fd RR |
391 | if (m_brush.GetStyle() != wxTRANSPARENT) |
392 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); | |
c801d85f | 393 | |
265898fd RR |
394 | if (m_pen.GetStyle() != wxTRANSPARENT) |
395 | gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); | |
396 | ||
397 | CalcBoundingBox( x, y ); | |
398 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 399 | } |
c801d85f KB |
400 | |
401 | void wxPaintDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius ) | |
402 | { | |
265898fd RR |
403 | if (!Ok()) return; |
404 | ||
405 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); | |
406 | ||
407 | long xx = XLOG2DEV(x); | |
408 | long yy = YLOG2DEV(y); | |
409 | long ww = m_signX * XLOG2DEVREL(width); | |
410 | long hh = m_signY * YLOG2DEVREL(height); | |
411 | long rr = XLOG2DEVREL((long)radius); | |
412 | ||
413 | // CMB: handle -ve width and/or height | |
414 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
415 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
416 | ||
417 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
418 | // X drawing errors with small radii | |
419 | if (rr == 0) | |
420 | { | |
421 | DrawRectangle( x, y, width, height ); | |
422 | return; | |
423 | } | |
424 | ||
425 | // CMB: draw nothing if transformed w or h is 0 | |
426 | if (ww == 0 || hh == 0) return; | |
427 | ||
428 | // CMB: adjust size if outline is drawn otherwise the result is | |
429 | // 1 pixel too wide and high | |
430 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
431 | { | |
432 | ww--; | |
433 | hh--; | |
434 | } | |
435 | ||
436 | // CMB: ensure dd is not larger than rectangle otherwise we | |
437 | // get an hour glass shape | |
438 | long dd = 2 * rr; | |
439 | if (dd > ww) dd = ww; | |
440 | if (dd > hh) dd = hh; | |
441 | rr = dd / 2; | |
442 | ||
443 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
444 | { | |
445 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx+rr, yy, ww-dd+1, hh ); | |
446 | gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy+rr, ww, hh-dd+1 ); | |
447 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, dd, dd, 90*64, 90*64 ); | |
448 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
449 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
450 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
451 | } | |
452 | ||
453 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
454 | { | |
455 | gdk_draw_line( m_window, m_penGC, xx+rr, yy, xx+ww-rr, yy ); | |
456 | gdk_draw_line( m_window, m_penGC, xx+rr, yy+hh, xx+ww-rr, yy+hh ); | |
457 | gdk_draw_line( m_window, m_penGC, xx, yy+rr, xx, yy+hh-rr ); | |
458 | gdk_draw_line( m_window, m_penGC, xx+ww, yy+rr, xx+ww, yy+hh-rr ); | |
459 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, dd, dd, 90*64, 90*64 ); | |
460 | gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy, dd, dd, 0, 90*64 ); | |
461 | gdk_draw_arc( m_window, m_penGC, FALSE, xx+ww-dd, yy+hh-dd, dd, dd, 270*64, 90*64 ); | |
462 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy+hh-dd, dd, dd, 180*64, 90*64 ); | |
463 | } | |
464 | ||
465 | // this ignores the radius | |
466 | CalcBoundingBox( x, y ); | |
467 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 468 | } |
c801d85f KB |
469 | |
470 | void wxPaintDC::DrawEllipse( long x, long y, long width, long height ) | |
471 | { | |
265898fd | 472 | if (!Ok()) return; |
c801d85f | 473 | |
265898fd RR |
474 | long xx = XLOG2DEV(x); |
475 | long yy = YLOG2DEV(y); | |
476 | long ww = m_signX * XLOG2DEVREL(width); | |
477 | long hh = m_signY * YLOG2DEVREL(height); | |
6f65e337 | 478 | |
265898fd RR |
479 | // CMB: handle -ve width and/or height |
480 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
481 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
c801d85f | 482 | |
265898fd RR |
483 | if (m_brush.GetStyle() != wxTRANSPARENT) |
484 | gdk_draw_arc( m_window, m_brushGC, TRUE, xx, yy, ww, hh, 0, 360*64 ); | |
c801d85f | 485 | |
265898fd RR |
486 | if (m_pen.GetStyle() != wxTRANSPARENT) |
487 | gdk_draw_arc( m_window, m_penGC, FALSE, xx, yy, ww, hh, 0, 360*64 ); | |
488 | ||
489 | CalcBoundingBox( x, y ); | |
490 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 491 | } |
c801d85f KB |
492 | |
493 | bool wxPaintDC::CanDrawBitmap(void) const | |
494 | { | |
495 | return TRUE; | |
903f689b | 496 | } |
c801d85f KB |
497 | |
498 | void wxPaintDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) | |
499 | { | |
265898fd | 500 | if (!Ok()) return; |
c801d85f | 501 | |
265898fd | 502 | if (!icon.Ok()) return; |
c801d85f | 503 | |
265898fd RR |
504 | int xx = XLOG2DEV(x); |
505 | int yy = YLOG2DEV(y); | |
c801d85f | 506 | |
265898fd RR |
507 | GdkBitmap *mask = (GdkBitmap *) NULL; |
508 | if (icon.GetMask()) mask = icon.GetMask()->GetBitmap(); | |
c801d85f | 509 | |
265898fd RR |
510 | if (useMask && mask) |
511 | { | |
512 | gdk_gc_set_clip_mask( m_penGC, mask ); | |
513 | gdk_gc_set_clip_origin( m_penGC, xx, yy ); | |
514 | } | |
c801d85f | 515 | |
265898fd RR |
516 | GdkPixmap *pm = icon.GetPixmap(); |
517 | gdk_draw_pixmap( m_window, m_penGC, pm, 0, 0, xx, yy, -1, -1 ); | |
c801d85f | 518 | |
265898fd RR |
519 | if (useMask && mask) |
520 | { | |
521 | gdk_gc_set_clip_mask( m_penGC, (GdkBitmap *) NULL ); | |
522 | gdk_gc_set_clip_origin( m_penGC, 0, 0 ); | |
523 | } | |
524 | ||
525 | CalcBoundingBox( x, y ); | |
526 | int width = icon.GetWidth(); | |
527 | int height = icon.GetHeight(); | |
528 | CalcBoundingBox( x + width, y + height ); | |
903f689b | 529 | } |
c801d85f KB |
530 | |
531 | bool wxPaintDC::Blit( long xdest, long ydest, long width, long height, | |
df875e59 | 532 | wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool useMask ) |
c801d85f | 533 | { |
265898fd | 534 | if (!Ok()) return FALSE; |
e23d0e95 | 535 | |
265898fd RR |
536 | CalcBoundingBox( xdest, ydest ); |
537 | CalcBoundingBox( xdest + width, ydest + height ); | |
538 | ||
539 | wxClientDC *csrc = (wxClientDC*)source; | |
f96aa4d9 | 540 | |
265898fd | 541 | if (csrc->m_isMemDC) |
6f65e337 | 542 | { |
265898fd | 543 | wxMemoryDC* srcDC = (wxMemoryDC*)source; |
e23d0e95 RR |
544 | GdkPixmap* pmap = srcDC->m_selected.GetPixmap(); |
545 | if (pmap) | |
546 | { | |
547 | long xx = XLOG2DEV(xdest); | |
548 | long yy = YLOG2DEV(ydest); | |
549 | ||
550 | GdkBitmap *mask = (GdkBitmap *) NULL; | |
551 | if (srcDC->m_selected.GetMask()) mask = srcDC->m_selected.GetMask()->GetBitmap(); | |
552 | ||
553 | if (useMask && mask) | |
554 | { | |
ee5e8025 RR |
555 | gdk_gc_set_clip_mask( m_textGC, mask ); |
556 | gdk_gc_set_clip_origin( m_textGC, xx, yy ); | |
e23d0e95 RR |
557 | } |
558 | ||
ee5e8025 | 559 | gdk_draw_pixmap( m_window, m_textGC, pmap, |
e23d0e95 RR |
560 | source->DeviceToLogicalX(xsrc), |
561 | source->DeviceToLogicalY(ysrc), | |
562 | xx, | |
563 | yy, | |
564 | source->DeviceToLogicalXRel(width), | |
565 | source->DeviceToLogicalYRel(height) ); | |
566 | ||
567 | if (useMask && mask) | |
568 | { | |
ee5e8025 RR |
569 | gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); |
570 | gdk_gc_set_clip_origin( m_textGC, 0, 0 ); | |
e23d0e95 RR |
571 | } |
572 | ||
573 | return TRUE; | |
574 | } | |
575 | ||
576 | GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); | |
265898fd RR |
577 | if (bmap) |
578 | { | |
579 | long xx = XLOG2DEV(xdest); | |
580 | long yy = YLOG2DEV(ydest); | |
df875e59 | 581 | |
265898fd RR |
582 | GdkBitmap *mask = (GdkBitmap *) NULL; |
583 | if (srcDC->m_selected.GetMask()) mask = srcDC->m_selected.GetMask()->GetBitmap(); | |
df875e59 | 584 | |
265898fd RR |
585 | if (useMask && mask) |
586 | { | |
ee5e8025 RR |
587 | gdk_gc_set_clip_mask( m_textGC, mask ); |
588 | gdk_gc_set_clip_origin( m_textGC, xx, yy ); | |
265898fd RR |
589 | } |
590 | ||
ee5e8025 | 591 | gdk_draw_bitmap( m_window, m_textGC, bmap, |
265898fd RR |
592 | source->DeviceToLogicalX(xsrc), |
593 | source->DeviceToLogicalY(ysrc), | |
594 | xx, | |
595 | yy, | |
596 | source->DeviceToLogicalXRel(width), | |
597 | source->DeviceToLogicalYRel(height) ); | |
df875e59 | 598 | |
265898fd RR |
599 | if (useMask && mask) |
600 | { | |
ee5e8025 RR |
601 | gdk_gc_set_clip_mask( m_textGC, (GdkBitmap *) NULL ); |
602 | gdk_gc_set_clip_origin( m_textGC, 0, 0 ); | |
265898fd | 603 | } |
df875e59 | 604 | |
265898fd RR |
605 | return TRUE; |
606 | } | |
6f65e337 | 607 | } |
c801d85f | 608 | |
ee5e8025 | 609 | gdk_window_copy_area ( m_window, m_textGC, |
265898fd RR |
610 | XLOG2DEV(xdest), YLOG2DEV(ydest), |
611 | csrc->GetWindow(), | |
612 | source->DeviceToLogicalX(xsrc), | |
613 | source->DeviceToLogicalY(ysrc), | |
614 | source->DeviceToLogicalXRel(width), | |
615 | source->DeviceToLogicalYRel(height) ); | |
c801d85f KB |
616 | |
617 | /* | |
ee5e8025 | 618 | gdk_window_copy_area ( m_window, m_textGC, |
265898fd RR |
619 | XLOG2DEV(xdest), YLOG2DEV(ydest), |
620 | csrc->GetWindow(), | |
621 | xsrc, ysrc, | |
622 | width, height ); | |
c801d85f KB |
623 | */ |
624 | ||
625 | return TRUE; | |
903f689b | 626 | } |
c801d85f | 627 | |
903f689b | 628 | void wxPaintDC::DrawText( const wxString &text, long x, long y, bool WXUNUSED(use16) ) |
c801d85f | 629 | { |
265898fd | 630 | if (!Ok()) return; |
18a2fa37 | 631 | |
265898fd | 632 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
6f65e337 | 633 | |
265898fd RR |
634 | x = XLOG2DEV(x); |
635 | y = YLOG2DEV(y); | |
18a2fa37 | 636 | |
265898fd RR |
637 | // CMB 21/5/98: draw text background if mode is wxSOLID |
638 | if (m_backgroundMode == wxSOLID) | |
639 | { | |
640 | long width = gdk_string_width( font, text ); | |
641 | long height = font->ascent + font->descent; | |
642 | gdk_gc_set_foreground( m_textGC, m_textBackgroundColour.GetColor() ); | |
643 | gdk_draw_rectangle( m_window, m_textGC, TRUE, x, y, width, height ); | |
644 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
645 | } | |
646 | gdk_draw_string( m_window, font, m_textGC, x, y + font->ascent, text ); | |
18a2fa37 | 647 | |
265898fd RR |
648 | // CMB 17/7/98: simple underline: ignores scaling and underlying |
649 | // X font's XA_UNDERLINE_POSITION and XA_UNDERLINE_THICKNESS | |
650 | // properties (see wxXt implementation) | |
651 | if (m_font.GetUnderlined()) | |
652 | { | |
653 | long width = gdk_string_width( font, text ); | |
654 | long ul_y = y + font->ascent; | |
655 | if (font->descent > 0) ul_y++; | |
656 | gdk_draw_line( m_window, m_textGC, x, ul_y, x + width, ul_y); | |
657 | } | |
658 | ||
659 | long w, h; | |
660 | GetTextExtent (text, &w, &h); | |
661 | CalcBoundingBox (x + w, y + h); | |
662 | CalcBoundingBox (x, y); | |
903f689b | 663 | } |
c801d85f KB |
664 | |
665 | bool wxPaintDC::CanGetTextExtent(void) const | |
666 | { | |
265898fd | 667 | return TRUE; |
903f689b | 668 | } |
c801d85f KB |
669 | |
670 | void wxPaintDC::GetTextExtent( const wxString &string, long *width, long *height, | |
c33c4050 RR |
671 | long *descent, long *externalLeading, |
672 | wxFont *theFont, bool WXUNUSED(use16) ) | |
c801d85f | 673 | { |
265898fd | 674 | if (!Ok()) return; |
c801d85f | 675 | |
265898fd RR |
676 | wxFont fontToUse = m_font; |
677 | if (theFont) fontToUse = *theFont; | |
c33c4050 | 678 | |
265898fd RR |
679 | GdkFont *font = fontToUse.GetInternalFont( m_scaleY ); |
680 | if (width) (*width) = long(gdk_string_width( font, string ) / m_scaleX); | |
681 | if (height) (*height) = long((font->ascent + font->descent) / m_scaleY); | |
682 | if (descent) (*descent) = long(font->descent / m_scaleY); | |
683 | if (externalLeading) (*externalLeading) = 0; // ?? | |
903f689b | 684 | } |
c801d85f KB |
685 | |
686 | long wxPaintDC::GetCharWidth(void) | |
687 | { | |
265898fd | 688 | if (!Ok()) return 0; |
c801d85f | 689 | |
265898fd RR |
690 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
691 | return long(gdk_string_width( font, "H" ) / m_scaleX); | |
903f689b | 692 | } |
c801d85f KB |
693 | |
694 | long wxPaintDC::GetCharHeight(void) | |
695 | { | |
265898fd | 696 | if (!Ok()) return 0; |
c801d85f | 697 | |
265898fd RR |
698 | GdkFont *font = m_font.GetInternalFont( m_scaleY ); |
699 | return long((font->ascent + font->descent) / m_scaleY); | |
903f689b | 700 | } |
c801d85f KB |
701 | |
702 | void wxPaintDC::Clear(void) | |
703 | { | |
265898fd | 704 | if (!Ok()) return; |
c801d85f | 705 | |
265898fd RR |
706 | if (!m_isMemDC) |
707 | { | |
708 | gdk_window_clear( m_window ); | |
709 | } | |
710 | else | |
711 | { | |
712 | int width,height; | |
713 | GetSize( &width, &height ); | |
714 | gdk_draw_rectangle( m_window, m_bgGC, TRUE, 0, 0, width, height ); | |
715 | } | |
903f689b | 716 | } |
c801d85f KB |
717 | |
718 | void wxPaintDC::SetFont( const wxFont &font ) | |
719 | { | |
265898fd | 720 | if (!Ok()) return; |
c801d85f | 721 | |
265898fd | 722 | m_font = font; |
903f689b | 723 | } |
c801d85f KB |
724 | |
725 | void wxPaintDC::SetPen( const wxPen &pen ) | |
726 | { | |
265898fd RR |
727 | if (!Ok()) return; |
728 | ||
729 | if (m_pen == pen) return; | |
730 | ||
731 | m_pen = pen; | |
732 | ||
733 | if (!m_pen.Ok()) return; | |
734 | ||
735 | gint width = m_pen.GetWidth(); | |
736 | // CMB: if width is non-zero scale it with the dc | |
737 | if (width <= 0) | |
738 | { | |
739 | width = 1; | |
740 | } | |
741 | else | |
742 | { | |
743 | // X doesn't allow different width in x and y and so we take | |
744 | // the average | |
745 | double w = 0.5 + (abs(XLOG2DEVREL(width)) + abs(YLOG2DEVREL(width))) / 2.0; | |
746 | width = (int)w; | |
747 | } | |
748 | ||
749 | GdkLineStyle lineStyle = GDK_LINE_SOLID; | |
750 | switch (m_pen.GetStyle()) | |
751 | { | |
752 | case wxSOLID: { lineStyle = GDK_LINE_SOLID; break; } | |
753 | case wxDOT: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
754 | case wxLONG_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
755 | case wxSHORT_DASH: { lineStyle = GDK_LINE_ON_OFF_DASH; break; } | |
756 | case wxDOT_DASH: { lineStyle = GDK_LINE_DOUBLE_DASH; break; } | |
757 | } | |
758 | ||
759 | GdkCapStyle capStyle = GDK_CAP_ROUND; | |
760 | switch (m_pen.GetCap()) | |
761 | { | |
762 | case wxCAP_ROUND: { capStyle = (width <= 1) ? GDK_CAP_NOT_LAST : GDK_CAP_ROUND; break; } | |
763 | case wxCAP_PROJECTING: { capStyle = GDK_CAP_PROJECTING; break; } | |
764 | case wxCAP_BUTT: { capStyle = GDK_CAP_BUTT; break; } | |
765 | } | |
766 | ||
767 | GdkJoinStyle joinStyle = GDK_JOIN_ROUND; | |
768 | switch (m_pen.GetJoin()) | |
769 | { | |
770 | case wxJOIN_BEVEL: { joinStyle = GDK_JOIN_BEVEL; break; } | |
771 | case wxJOIN_ROUND: { joinStyle = GDK_JOIN_ROUND; break; } | |
772 | case wxJOIN_MITER: { joinStyle = GDK_JOIN_MITER; break; } | |
773 | } | |
774 | ||
775 | gdk_gc_set_line_attributes( m_penGC, width, lineStyle, capStyle, joinStyle ); | |
776 | ||
777 | m_pen.GetColour().CalcPixel( m_cmap ); | |
778 | gdk_gc_set_foreground( m_penGC, m_pen.GetColour().GetColor() ); | |
903f689b | 779 | } |
c801d85f KB |
780 | |
781 | void wxPaintDC::SetBrush( const wxBrush &brush ) | |
782 | { | |
265898fd | 783 | if (!Ok()) return; |
c801d85f | 784 | |
265898fd | 785 | if (m_brush == brush) return; |
c801d85f | 786 | |
265898fd | 787 | m_brush = brush; |
c801d85f | 788 | |
265898fd | 789 | if (!m_brush.Ok()) return; |
c801d85f | 790 | |
265898fd RR |
791 | m_brush.GetColour().CalcPixel( m_cmap ); |
792 | gdk_gc_set_foreground( m_brushGC, m_brush.GetColour().GetColor() ); | |
c801d85f | 793 | |
265898fd RR |
794 | GdkFill fillStyle = GDK_SOLID; |
795 | switch (m_brush.GetStyle()) | |
796 | { | |
797 | case wxSOLID: | |
798 | case wxTRANSPARENT: | |
799 | break; | |
800 | default: | |
801 | fillStyle = GDK_STIPPLED; | |
802 | } | |
c801d85f | 803 | |
265898fd | 804 | gdk_gc_set_fill( m_brushGC, fillStyle ); |
c801d85f | 805 | |
265898fd RR |
806 | if (m_brush.GetStyle() == wxSTIPPLE) |
807 | { | |
808 | gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() ); | |
809 | } | |
810 | ||
811 | if (IS_HATCH(m_brush.GetStyle())) | |
812 | { | |
813 | int num = m_brush.GetStyle() - wxBDIAGONAL_HATCH; | |
814 | gdk_gc_set_stipple( m_brushGC, hatches[num] ); | |
815 | } | |
903f689b | 816 | } |
c801d85f | 817 | |
46dc76ba RR |
818 | // CMB 21/7/98: Added SetBackground. Sets background brush |
819 | // for Clear() and bg colour for shapes filled with cross-hatch brush | |
820 | void wxPaintDC::SetBackground( const wxBrush &brush ) | |
821 | { | |
265898fd | 822 | if (!Ok()) return; |
46dc76ba | 823 | |
265898fd | 824 | if (m_backgroundBrush == brush) return; |
46dc76ba | 825 | |
265898fd | 826 | m_backgroundBrush = brush; |
46dc76ba | 827 | |
265898fd | 828 | if (!m_backgroundBrush.Ok()) return; |
46dc76ba | 829 | |
265898fd RR |
830 | m_backgroundBrush.GetColour().CalcPixel( m_cmap ); |
831 | gdk_gc_set_background( m_brushGC, m_backgroundBrush.GetColour().GetColor() ); | |
832 | gdk_gc_set_foreground( m_bgGC, m_backgroundBrush.GetColour().GetColor() ); | |
46dc76ba | 833 | |
265898fd RR |
834 | GdkFill fillStyle = GDK_SOLID; |
835 | switch (m_backgroundBrush.GetStyle()) | |
836 | { | |
837 | case wxSOLID: | |
838 | case wxTRANSPARENT: | |
839 | break; | |
840 | default: | |
841 | fillStyle = GDK_STIPPLED; | |
842 | } | |
46dc76ba | 843 | |
265898fd | 844 | gdk_gc_set_fill( m_bgGC, fillStyle ); |
46dc76ba | 845 | |
265898fd RR |
846 | if (m_backgroundBrush.GetStyle() == wxSTIPPLE) |
847 | { | |
848 | gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); | |
849 | } | |
46dc76ba | 850 | |
265898fd RR |
851 | if (IS_HATCH(m_backgroundBrush.GetStyle())) |
852 | { | |
853 | int num = m_backgroundBrush.GetStyle() - wxBDIAGONAL_HATCH; | |
854 | gdk_gc_set_stipple( m_bgGC, hatches[num] ); | |
855 | } | |
903f689b | 856 | } |
46dc76ba | 857 | |
c801d85f KB |
858 | void wxPaintDC::SetLogicalFunction( int function ) |
859 | { | |
265898fd RR |
860 | if (m_logicalFunction == function) return; |
861 | GdkFunction mode = GDK_COPY; | |
862 | switch (function) | |
863 | { | |
864 | case wxXOR: mode = GDK_INVERT; break; | |
865 | case wxINVERT: mode = GDK_INVERT; break; | |
866 | default: break; | |
867 | } | |
868 | m_logicalFunction = function; | |
869 | gdk_gc_set_function( m_penGC, mode ); | |
870 | gdk_gc_set_function( m_brushGC, mode ); | |
3bc755fc | 871 | gdk_gc_set_function( m_textGC, mode ); |
903f689b | 872 | } |
c801d85f KB |
873 | |
874 | void wxPaintDC::SetTextForeground( const wxColour &col ) | |
875 | { | |
265898fd | 876 | if (!Ok()) return; |
c801d85f | 877 | |
265898fd | 878 | if (m_textForegroundColour == col) return; |
c801d85f | 879 | |
265898fd RR |
880 | m_textForegroundColour = col; |
881 | if (!m_textForegroundColour.Ok()) return; | |
c801d85f | 882 | |
265898fd RR |
883 | m_textForegroundColour.CalcPixel( m_cmap ); |
884 | gdk_gc_set_foreground( m_textGC, m_textForegroundColour.GetColor() ); | |
903f689b | 885 | } |
c801d85f KB |
886 | |
887 | void wxPaintDC::SetTextBackground( const wxColour &col ) | |
888 | { | |
265898fd | 889 | if (!Ok()) return; |
c801d85f | 890 | |
265898fd | 891 | if (m_textBackgroundColour == col) return; |
c801d85f | 892 | |
265898fd RR |
893 | m_textBackgroundColour = col; |
894 | if (!m_textBackgroundColour.Ok()) return; | |
c801d85f | 895 | |
265898fd RR |
896 | m_textBackgroundColour.CalcPixel( m_cmap ); |
897 | gdk_gc_set_background( m_textGC, m_textBackgroundColour.GetColor() ); | |
903f689b | 898 | } |
c801d85f | 899 | |
6f65e337 | 900 | void wxPaintDC::SetBackgroundMode( int mode ) |
c801d85f | 901 | { |
265898fd | 902 | m_backgroundMode = mode; |
46dc76ba | 903 | |
265898fd RR |
904 | // CMB 21/7/98: fill style of cross-hatch brushes is affected by |
905 | // transparent/solid background mode | |
906 | if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT) | |
907 | { | |
908 | gdk_gc_set_fill( m_brushGC, | |
909 | (m_backgroundMode == wxTRANSPARENT) ? GDK_STIPPLED : GDK_OPAQUE_STIPPLED); | |
910 | } | |
903f689b | 911 | } |
c801d85f KB |
912 | |
913 | void wxPaintDC::SetPalette( const wxPalette& WXUNUSED(palette) ) | |
914 | { | |
903f689b | 915 | } |
c801d85f KB |
916 | |
917 | void wxPaintDC::SetClippingRegion( long x, long y, long width, long height ) | |
918 | { | |
265898fd | 919 | wxDC::SetClippingRegion( x, y, width, height ); |
c801d85f | 920 | |
265898fd RR |
921 | GdkRectangle rect; |
922 | rect.x = XLOG2DEV(x); | |
923 | rect.y = YLOG2DEV(y); | |
924 | rect.width = XLOG2DEVREL(width); | |
925 | rect.height = YLOG2DEVREL(height); | |
926 | gdk_gc_set_clip_rectangle( m_penGC, &rect ); | |
927 | gdk_gc_set_clip_rectangle( m_brushGC, &rect ); | |
928 | gdk_gc_set_clip_rectangle( m_textGC, &rect ); | |
929 | gdk_gc_set_clip_rectangle( m_bgGC, &rect ); | |
903f689b | 930 | } |
c801d85f KB |
931 | |
932 | void wxPaintDC::DestroyClippingRegion(void) | |
933 | { | |
265898fd | 934 | wxDC::DestroyClippingRegion(); |
c801d85f | 935 | |
265898fd RR |
936 | gdk_gc_set_clip_rectangle( m_penGC, (GdkRectangle *) NULL ); |
937 | gdk_gc_set_clip_rectangle( m_brushGC, (GdkRectangle *) NULL ); | |
938 | gdk_gc_set_clip_rectangle( m_textGC, (GdkRectangle *) NULL ); | |
939 | gdk_gc_set_clip_rectangle( m_bgGC, (GdkRectangle *) NULL ); | |
903f689b | 940 | } |
c801d85f KB |
941 | |
942 | void wxPaintDC::SetUpDC(void) | |
943 | { | |
265898fd RR |
944 | Destroy(); |
945 | m_ok = TRUE; | |
946 | m_logicalFunction = wxCOPY; | |
947 | m_penGC = gdk_gc_new( m_window ); | |
948 | m_brushGC = gdk_gc_new( m_window ); | |
949 | m_textGC = gdk_gc_new( m_window ); | |
950 | m_bgGC = gdk_gc_new( m_window ); | |
951 | SetTextForeground( m_textForegroundColour ); | |
952 | SetTextBackground( m_textBackgroundColour ); | |
953 | SetPen( m_pen ); | |
954 | SetFont( m_font ); | |
955 | SetBrush( m_brush ); | |
956 | ||
957 | gdk_gc_set_background( m_penGC, wxWHITE->GetColor() ); | |
958 | ||
959 | if (!hatch_bitmap) | |
960 | { | |
961 | hatch_bitmap = hatches; | |
962 | hatch_bitmap[0] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, bdiag_bits, bdiag_width, bdiag_height ); | |
963 | hatch_bitmap[1] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cdiag_bits, cdiag_width, cdiag_height ); | |
964 | hatch_bitmap[2] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, fdiag_bits, fdiag_width, fdiag_height ); | |
965 | hatch_bitmap[3] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, cross_bits, cross_width, cross_height ); | |
966 | hatch_bitmap[4] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, horiz_bits, horiz_width, horiz_height ); | |
967 | hatch_bitmap[5] = gdk_bitmap_create_from_data( (GdkWindow *) NULL, verti_bits, verti_width, verti_height ); | |
968 | } | |
903f689b | 969 | } |
c801d85f | 970 | |
dbf858b5 RR |
971 | void wxPaintDC::Destroy(void) |
972 | { | |
265898fd RR |
973 | if (m_penGC) gdk_gc_unref( m_penGC ); |
974 | m_penGC = (GdkGC*) NULL; | |
975 | if (m_brushGC) gdk_gc_unref( m_brushGC ); | |
976 | m_brushGC = (GdkGC*) NULL; | |
977 | if (m_textGC) gdk_gc_unref( m_textGC ); | |
978 | m_textGC = (GdkGC*) NULL; | |
979 | if (m_bgGC) gdk_gc_unref( m_bgGC ); | |
980 | m_bgGC = (GdkGC*) NULL; | |
dbf858b5 RR |
981 | } |
982 | ||
c801d85f KB |
983 | GdkWindow *wxPaintDC::GetWindow(void) |
984 | { | |
265898fd | 985 | return m_window; |
903f689b | 986 | } |
c801d85f KB |
987 | |
988 | // ----------------------------------- spline code ---------------------------------------- | |
989 | ||
990 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, | |
991 | double a3, double b3, double a4, double b4); | |
992 | void wx_clear_stack(void); | |
993 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, | |
994 | double *y3, double *x4, double *y4); | |
995 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, | |
996 | double x4, double y4); | |
997 | static bool wx_spline_add_point(double x, double y); | |
998 | static void wx_spline_draw_point_array(wxDC *dc); | |
999 | ||
1000 | wxList wx_spline_point_list; | |
1001 | ||
1002 | #define half(z1, z2) ((z1+z2)/2.0) | |
1003 | #define THRESHOLD 5 | |
1004 | ||
1005 | /* iterative version */ | |
1006 | ||
1007 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, | |
1008 | double b4) | |
1009 | { | |
1010 | register double xmid, ymid; | |
1011 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1012 | ||
1013 | wx_clear_stack(); | |
1014 | wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); | |
1015 | ||
1016 | while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { | |
1017 | xmid = (double)half(x2, x3); | |
1018 | ymid = (double)half(y2, y3); | |
1019 | if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && | |
1020 | fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { | |
1021 | wx_spline_add_point( x1, y1 ); | |
1022 | wx_spline_add_point( xmid, ymid ); | |
1023 | } else { | |
1024 | wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), | |
1025 | (double)half(x3, x4), (double)half(y3, y4), x4, y4); | |
1026 | wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), | |
1027 | (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); | |
1028 | } | |
1029 | } | |
1030 | } | |
1031 | ||
1032 | /* utilities used by spline drawing routines */ | |
1033 | ||
1034 | typedef struct wx_spline_stack_struct { | |
1035 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1036 | } Stack; | |
1037 | ||
1038 | #define SPLINE_STACK_DEPTH 20 | |
1039 | static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; | |
1040 | static Stack *wx_stack_top; | |
1041 | static int wx_stack_count; | |
1042 | ||
1043 | void wx_clear_stack(void) | |
1044 | { | |
1045 | wx_stack_top = wx_spline_stack; | |
1046 | wx_stack_count = 0; | |
1047 | } | |
1048 | ||
1049 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) | |
1050 | { | |
1051 | wx_stack_top->x1 = x1; | |
1052 | wx_stack_top->y1 = y1; | |
1053 | wx_stack_top->x2 = x2; | |
1054 | wx_stack_top->y2 = y2; | |
1055 | wx_stack_top->x3 = x3; | |
1056 | wx_stack_top->y3 = y3; | |
1057 | wx_stack_top->x4 = x4; | |
1058 | wx_stack_top->y4 = y4; | |
1059 | wx_stack_top++; | |
1060 | wx_stack_count++; | |
1061 | } | |
1062 | ||
1063 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, | |
1064 | double *x3, double *y3, double *x4, double *y4) | |
1065 | { | |
1066 | if (wx_stack_count == 0) | |
1067 | return (0); | |
1068 | wx_stack_top--; | |
1069 | wx_stack_count--; | |
1070 | *x1 = wx_stack_top->x1; | |
1071 | *y1 = wx_stack_top->y1; | |
1072 | *x2 = wx_stack_top->x2; | |
1073 | *y2 = wx_stack_top->y2; | |
1074 | *x3 = wx_stack_top->x3; | |
1075 | *y3 = wx_stack_top->y3; | |
1076 | *x4 = wx_stack_top->x4; | |
1077 | *y4 = wx_stack_top->y4; | |
1078 | return (1); | |
1079 | } | |
1080 | ||
1081 | static bool wx_spline_add_point(double x, double y) | |
1082 | { | |
1083 | wxPoint *point = new wxPoint ; | |
1084 | point->x = (int) x; | |
1085 | point->y = (int) y; | |
1086 | wx_spline_point_list.Append((wxObject*)point); | |
1087 | return TRUE; | |
1088 | } | |
1089 | ||
1090 | static void wx_spline_draw_point_array(wxDC *dc) | |
1091 | { | |
1092 | dc->DrawLines(&wx_spline_point_list, 0, 0 ); | |
1093 | wxNode *node = wx_spline_point_list.First(); | |
1094 | while (node) | |
1095 | { | |
1096 | wxPoint *point = (wxPoint *)node->Data(); | |
1097 | delete point; | |
1098 | delete node; | |
1099 | node = wx_spline_point_list.First(); | |
1100 | } | |
1101 | } | |
1102 | ||
dfad0599 | 1103 | void wxPaintDC::DrawSpline( wxList *points ) |
c801d85f KB |
1104 | { |
1105 | wxPoint *p; | |
1106 | double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; | |
1107 | double x1, y1, x2, y2; | |
1108 | ||
1109 | wxNode *node = points->First(); | |
1110 | p = (wxPoint *)node->Data(); | |
1111 | ||
1112 | x1 = p->x; | |
1113 | y1 = p->y; | |
1114 | ||
1115 | node = node->Next(); | |
1116 | p = (wxPoint *)node->Data(); | |
1117 | ||
1118 | x2 = p->x; | |
1119 | y2 = p->y; | |
1120 | cx1 = (double)((x1 + x2) / 2); | |
1121 | cy1 = (double)((y1 + y2) / 2); | |
1122 | cx2 = (double)((cx1 + x2) / 2); | |
1123 | cy2 = (double)((cy1 + y2) / 2); | |
1124 | ||
1125 | wx_spline_add_point(x1, y1); | |
1126 | ||
1127 | while ((node = node->Next()) != NULL) | |
1128 | { | |
1129 | p = (wxPoint *)node->Data(); | |
1130 | x1 = x2; | |
1131 | y1 = y2; | |
1132 | x2 = p->x; | |
1133 | y2 = p->y; | |
1134 | cx4 = (double)(x1 + x2) / 2; | |
1135 | cy4 = (double)(y1 + y2) / 2; | |
1136 | cx3 = (double)(x1 + cx4) / 2; | |
1137 | cy3 = (double)(y1 + cy4) / 2; | |
1138 | ||
1139 | wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); | |
1140 | ||
1141 | cx1 = cx4; | |
1142 | cy1 = cy4; | |
1143 | cx2 = (double)(cx1 + x2) / 2; | |
1144 | cy2 = (double)(cy1 + y2) / 2; | |
1145 | } | |
1146 | ||
1147 | wx_spline_add_point( cx1, cy1 ); | |
1148 | wx_spline_add_point( x2, y2 ); | |
1149 | ||
1150 | wx_spline_draw_point_array( this ); | |
903f689b | 1151 | } |