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