]>
Commit | Line | Data |
---|---|---|
93cf77c0 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcclient.cpp | |
3 | // Purpose: wxClientDC class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dcclient.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dcclient.h" | |
17 | #include "wx/dcmemory.h" | |
18 | #include <math.h> | |
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | // constants | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | #define RAD2DEG 57.2957795131 | |
25 | ||
26 | //----------------------------------------------------------------------------- | |
27 | // wxPaintDC | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | #if !USE_SHARED_LIBRARY | |
e6460682 JS |
31 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
32 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
33 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
93cf77c0 JS |
34 | #endif |
35 | ||
e6460682 JS |
36 | /* |
37 | * wxWindowDC | |
38 | */ | |
93cf77c0 | 39 | |
e6460682 | 40 | wxWindowDC::wxWindowDC(void) |
93cf77c0 JS |
41 | { |
42 | }; | |
43 | ||
e6460682 | 44 | wxWindowDC::wxWindowDC( wxWindow *window ) |
93cf77c0 JS |
45 | { |
46 | }; | |
47 | ||
e6460682 | 48 | wxWindowDC::~wxWindowDC(void) |
93cf77c0 JS |
49 | { |
50 | }; | |
51 | ||
e6460682 | 52 | void wxWindowDC::FloodFill( long WXUNUSED(x1), long WXUNUSED(y1), |
34138703 | 53 | wxColour* WXUNUSED(col), int WXUNUSED(style) ) |
93cf77c0 JS |
54 | { |
55 | }; | |
56 | ||
e6460682 | 57 | bool wxWindowDC::GetPixel( long WXUNUSED(x1), long WXUNUSED(y1), wxColour *WXUNUSED(col) ) const |
93cf77c0 JS |
58 | { |
59 | return FALSE; | |
60 | }; | |
61 | ||
e6460682 | 62 | void wxWindowDC::DrawLine( long x1, long y1, long x2, long y2 ) |
93cf77c0 JS |
63 | { |
64 | if (!Ok()) return; | |
65 | ||
66 | }; | |
67 | ||
e6460682 | 68 | void wxWindowDC::CrossHair( long x, long y ) |
93cf77c0 JS |
69 | { |
70 | if (!Ok()) return; | |
71 | ||
72 | }; | |
73 | ||
e6460682 | 74 | void wxWindowDC::DrawArc( long x1, long y1, long x2, long y2, long xc, long yc ) |
93cf77c0 JS |
75 | { |
76 | if (!Ok()) return; | |
77 | ||
78 | long xx1 = XLOG2DEV(x1); | |
79 | long yy1 = YLOG2DEV(y1); | |
80 | long xx2 = XLOG2DEV(x2); | |
81 | long yy2 = YLOG2DEV(y2); | |
82 | long xxc = XLOG2DEV((long)xc); | |
83 | long yyc = YLOG2DEV((long)yc); | |
84 | double dx = xx1 - xxc; | |
85 | double dy = yy1 - yyc; | |
86 | double radius = sqrt(dx*dx+dy*dy); | |
87 | long r = (long)radius; | |
88 | double radius1, radius2; | |
89 | ||
90 | if (xx1 == xx2 && yy1 == yy2) | |
91 | { | |
92 | radius1 = 0.0; | |
93 | radius2 = 360.0; | |
94 | } | |
95 | else | |
96 | if (radius == 0.0) | |
97 | { | |
98 | radius1 = radius2 = 0.0; | |
99 | } | |
100 | else | |
101 | { | |
102 | radius1 = (xx1 - xxc == 0) ? | |
103 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
104 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
105 | radius2 = (xx2 - xxc == 0) ? | |
106 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
107 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
108 | }; | |
109 | long alpha1 = long(radius1 * 64.0); | |
110 | long alpha2 = long((radius2 - radius1) * 64.0); | |
111 | while (alpha2 <= 0) alpha2 += 360*64; | |
112 | while (alpha1 > 360*64) alpha1 -= 360*64; | |
113 | ||
114 | if (m_brush.GetStyle() != wxTRANSPARENT) {}; | |
115 | ||
116 | if (m_pen.GetStyle() != wxTRANSPARENT) {}; | |
117 | ||
118 | }; | |
119 | ||
e6460682 | 120 | void wxWindowDC::DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) |
93cf77c0 JS |
121 | { |
122 | if (!Ok()) return; | |
123 | ||
124 | long xx = XLOG2DEV(x); | |
125 | long yy = YLOG2DEV(y); | |
126 | long ww = m_signX * XLOG2DEVREL(width); | |
127 | long hh = m_signY * YLOG2DEVREL(height); | |
128 | ||
129 | // CMB: handle -ve width and/or height | |
130 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
131 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
132 | ||
133 | long start = long(sa * 64.0); | |
134 | long end = long(ea * 64.0); | |
135 | if (m_brush.GetStyle() != wxTRANSPARENT) {}; | |
136 | ||
137 | if (m_pen.GetStyle() != wxTRANSPARENT) {}; | |
138 | }; | |
139 | ||
e6460682 | 140 | void wxWindowDC::DrawPoint( long x, long y ) |
93cf77c0 JS |
141 | { |
142 | if (!Ok()) return; | |
143 | ||
144 | if (m_pen.GetStyle() != wxTRANSPARENT) {}; | |
145 | }; | |
146 | ||
e6460682 | 147 | void wxWindowDC::DrawLines( int n, wxPoint points[], long xoffset, long yoffset ) |
93cf77c0 JS |
148 | { |
149 | if (!Ok()) return; | |
150 | ||
151 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
152 | ||
153 | for (int i = 0; i < n-1; i++) | |
154 | { | |
155 | long x1 = XLOG2DEV(points[i].x + xoffset); | |
156 | long x2 = XLOG2DEV(points[i+1].x + xoffset); | |
157 | long y1 = YLOG2DEV(points[i].y + yoffset); // oh, what a waste | |
158 | long y2 = YLOG2DEV(points[i+1].y + yoffset); | |
159 | }; | |
160 | }; | |
161 | ||
e6460682 | 162 | void wxWindowDC::DrawLines( wxList *points, long xoffset, long yoffset ) |
93cf77c0 JS |
163 | { |
164 | if (!Ok()) return; | |
165 | ||
166 | if (m_pen.GetStyle() == wxTRANSPARENT) return; | |
167 | ||
168 | wxNode *node = points->First(); | |
169 | while (node->Next()) | |
170 | { | |
171 | wxPoint *point = (wxPoint*)node->Data(); | |
172 | wxPoint *npoint = (wxPoint*)node->Next()->Data(); | |
173 | long x1 = XLOG2DEV(point->x + xoffset); | |
174 | long x2 = XLOG2DEV(npoint->x + xoffset); | |
175 | long y1 = YLOG2DEV(point->y + yoffset); // and again... | |
176 | long y2 = YLOG2DEV(npoint->y + yoffset); | |
177 | node = node->Next(); | |
178 | }; | |
179 | }; | |
180 | ||
e6460682 | 181 | void wxWindowDC::DrawPolygon( int WXUNUSED(n), wxPoint WXUNUSED(points)[], |
93cf77c0 JS |
182 | long WXUNUSED(xoffset), long WXUNUSED(yoffset), int WXUNUSED(fillStyle) ) |
183 | { | |
184 | if (!Ok()) return; | |
185 | }; | |
186 | ||
e6460682 | 187 | void wxWindowDC::DrawPolygon( wxList *WXUNUSED(lines), long WXUNUSED(xoffset), |
93cf77c0 JS |
188 | long WXUNUSED(yoffset), int WXUNUSED(fillStyle) ) |
189 | { | |
190 | if (!Ok()) return; | |
191 | }; | |
192 | ||
e6460682 | 193 | void wxWindowDC::DrawRectangle( long x, long y, long width, long height ) |
93cf77c0 JS |
194 | { |
195 | if (!Ok()) return; | |
196 | ||
197 | long xx = XLOG2DEV(x); | |
198 | long yy = YLOG2DEV(y); | |
199 | long ww = m_signX * XLOG2DEVREL(width); | |
200 | long hh = m_signY * YLOG2DEVREL(height); | |
201 | ||
202 | // CMB: draw nothing if transformed w or h is 0 | |
203 | if (ww == 0 || hh == 0) return; | |
204 | ||
205 | // CMB: handle -ve width and/or height | |
206 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
207 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
208 | ||
209 | if (m_brush.GetStyle() != wxTRANSPARENT) {}; | |
210 | ||
211 | if (m_pen.GetStyle() != wxTRANSPARENT) {}; | |
212 | }; | |
213 | ||
e6460682 | 214 | void wxWindowDC::DrawRoundedRectangle( long x, long y, long width, long height, double radius ) |
93cf77c0 JS |
215 | { |
216 | if (!Ok()) return; | |
217 | ||
218 | if (radius < 0.0) radius = - radius * ((width < height) ? width : height); | |
219 | ||
220 | long xx = XLOG2DEV(x); | |
221 | long yy = YLOG2DEV(y); | |
222 | long ww = m_signX * XLOG2DEVREL(width); | |
223 | long hh = m_signY * YLOG2DEVREL(height); | |
224 | long rr = XLOG2DEVREL((long)radius); | |
225 | ||
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; } | |
229 | ||
230 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
231 | // X drawing errors with small radii | |
232 | if (rr == 0) | |
233 | { | |
234 | DrawRectangle( x, y, width, height ); | |
235 | return; | |
236 | } | |
237 | ||
238 | // CMB: draw nothing if transformed w or h is 0 | |
239 | if (ww == 0 || hh == 0) return; | |
240 | ||
241 | // CMB: adjust size if outline is drawn otherwise the result is | |
242 | // 1 pixel too wide and high | |
243 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
244 | { | |
245 | ww--; | |
246 | hh--; | |
247 | } | |
248 | ||
249 | // CMB: ensure dd is not larger than rectangle otherwise we | |
250 | // get an hour glass shape | |
251 | long dd = 2 * rr; | |
252 | if (dd > ww) dd = ww; | |
253 | if (dd > hh) dd = hh; | |
254 | rr = dd / 2; | |
255 | ||
256 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
257 | { | |
258 | }; | |
259 | ||
260 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
261 | { | |
262 | }; | |
263 | }; | |
264 | ||
e6460682 | 265 | void wxWindowDC::DrawEllipse( long x, long y, long width, long height ) |
93cf77c0 JS |
266 | { |
267 | if (!Ok()) return; | |
268 | ||
269 | long xx = XLOG2DEV(x); | |
270 | long yy = YLOG2DEV(y); | |
271 | long ww = m_signX * XLOG2DEVREL(width); | |
272 | long hh = m_signY * YLOG2DEVREL(height); | |
273 | ||
274 | // CMB: handle -ve width and/or height | |
275 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
276 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
277 | ||
278 | if (m_brush.GetStyle() != wxTRANSPARENT) {}; | |
279 | ||
280 | if (m_pen.GetStyle() != wxTRANSPARENT) {}; | |
281 | }; | |
282 | ||
e6460682 | 283 | bool wxWindowDC::CanDrawBitmap(void) const |
93cf77c0 JS |
284 | { |
285 | return TRUE; | |
286 | }; | |
287 | ||
e6460682 | 288 | void wxWindowDC::DrawIcon( const wxIcon &icon, long x, long y, bool useMask ) |
93cf77c0 JS |
289 | { |
290 | if (!Ok()) return; | |
291 | ||
292 | if (!icon.Ok()) return; | |
293 | ||
294 | int xx = XLOG2DEV(x); | |
295 | int yy = YLOG2DEV(y); | |
296 | ||
297 | }; | |
298 | ||
e6460682 | 299 | bool wxWindowDC::Blit( long xdest, long ydest, long width, long height, |
93cf77c0 JS |
300 | wxDC *source, long xsrc, long ysrc, int WXUNUSED(logical_func), bool WXUNUSED(useMask) ) |
301 | { | |
302 | if (!Ok()) return FALSE; | |
303 | ||
304 | // CMB 20/5/98: add blitting of bitmaps | |
305 | if (source->IsKindOf(CLASSINFO(wxMemoryDC))) | |
306 | { | |
307 | wxMemoryDC* srcDC = (wxMemoryDC*)source; | |
308 | /* | |
309 | GdkBitmap* bmap = srcDC->m_selected.GetBitmap(); | |
310 | if (bmap) | |
311 | { | |
312 | gdk_draw_bitmap ( | |
313 | m_window, | |
314 | m_textGC, | |
315 | bmap, | |
316 | source->DeviceToLogicalX(xsrc), source->DeviceToLogicalY(ysrc), | |
317 | XLOG2DEV(xdest), YLOG2DEV(ydest), | |
318 | source->DeviceToLogicalXRel(width), source->DeviceToLogicalYRel(height) | |
319 | ); | |
320 | return TRUE; | |
321 | } | |
322 | */ | |
323 | } | |
324 | ||
325 | return TRUE; | |
326 | }; | |
327 | ||
e6460682 | 328 | void wxWindowDC::DrawText( const wxString &text, long x, long y, bool |
93cf77c0 JS |
329 | WXUNUSED(use16) ) |
330 | { | |
331 | if (!Ok()) return; | |
332 | ||
333 | }; | |
334 | ||
335 | ||
336 | ||
e6460682 | 337 | bool wxWindowDC::CanGetTextExtent(void) const |
93cf77c0 JS |
338 | { |
339 | return TRUE; | |
340 | }; | |
341 | ||
e6460682 | 342 | void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *height, |
93cf77c0 JS |
343 | long *WXUNUSED(descent), long *WXUNUSED(externalLeading), |
344 | wxFont *WXUNUSED(theFont), bool WXUNUSED(use16) ) | |
345 | { | |
346 | if (!Ok()) return; | |
347 | ||
348 | }; | |
349 | ||
e6460682 | 350 | long wxWindowDC::GetCharWidth(void) |
93cf77c0 JS |
351 | { |
352 | if (!Ok()) return 0; | |
34138703 | 353 | return 0; |
93cf77c0 JS |
354 | }; |
355 | ||
e6460682 | 356 | long wxWindowDC::GetCharHeight(void) |
93cf77c0 JS |
357 | { |
358 | if (!Ok()) return 0; | |
34138703 | 359 | return 0; |
93cf77c0 JS |
360 | }; |
361 | ||
e6460682 | 362 | void wxWindowDC::Clear(void) |
93cf77c0 JS |
363 | { |
364 | if (!Ok()) return; | |
365 | ||
366 | }; | |
367 | ||
e6460682 | 368 | void wxWindowDC::SetFont( const wxFont &font ) |
93cf77c0 JS |
369 | { |
370 | if (!Ok()) return; | |
371 | ||
372 | m_font = font; | |
373 | }; | |
374 | ||
e6460682 | 375 | void wxWindowDC::SetPen( const wxPen &pen ) |
93cf77c0 JS |
376 | { |
377 | if (!Ok()) return; | |
378 | ||
379 | if (m_pen == pen) return; | |
380 | ||
381 | m_pen = pen; | |
382 | ||
383 | if (!m_pen.Ok()) return; | |
384 | }; | |
385 | ||
e6460682 | 386 | void wxWindowDC::SetBrush( const wxBrush &brush ) |
93cf77c0 JS |
387 | { |
388 | if (!Ok()) return; | |
389 | ||
390 | if (m_brush == brush) return; | |
391 | ||
392 | m_brush = brush; | |
393 | ||
394 | if (!m_brush.Ok()) return; | |
395 | ||
396 | }; | |
397 | ||
e6460682 | 398 | void wxWindowDC::SetBackground( const wxBrush &brush ) |
93cf77c0 JS |
399 | { |
400 | if (!Ok()) return; | |
401 | ||
402 | if (m_backgroundBrush == brush) return; | |
403 | ||
404 | m_backgroundBrush = brush; | |
405 | ||
406 | if (!m_backgroundBrush.Ok()) return; | |
407 | ||
408 | }; | |
409 | ||
e6460682 | 410 | void wxWindowDC::SetLogicalFunction( int function ) |
93cf77c0 JS |
411 | { |
412 | if (m_logicalFunction == function) return; | |
413 | }; | |
414 | ||
e6460682 | 415 | void wxWindowDC::SetTextForeground( const wxColour &col ) |
93cf77c0 JS |
416 | { |
417 | if (!Ok()) return; | |
418 | ||
419 | if (m_textForegroundColour == col) return; | |
420 | ||
421 | m_textForegroundColour = col; | |
422 | if (!m_textForegroundColour.Ok()) return; | |
423 | }; | |
424 | ||
e6460682 | 425 | void wxWindowDC::SetTextBackground( const wxColour &col ) |
93cf77c0 JS |
426 | { |
427 | if (!Ok()) return; | |
428 | ||
429 | if (m_textBackgroundColour == col) return; | |
430 | ||
431 | m_textBackgroundColour = col; | |
432 | if (!m_textBackgroundColour.Ok()) return; | |
433 | }; | |
434 | ||
e6460682 | 435 | void wxWindowDC::SetBackgroundMode( int mode ) |
93cf77c0 JS |
436 | { |
437 | m_backgroundMode = mode; | |
438 | ||
439 | if (m_brush.GetStyle() != wxSOLID && m_brush.GetStyle() != wxTRANSPARENT) | |
440 | { | |
441 | } | |
442 | }; | |
443 | ||
e6460682 | 444 | void wxWindowDC::SetPalette( const wxPalette& WXUNUSED(palette) ) |
93cf77c0 JS |
445 | { |
446 | }; | |
447 | ||
e6460682 | 448 | void wxWindowDC::SetClippingRegion( long x, long y, long width, long height ) |
93cf77c0 JS |
449 | { |
450 | wxDC::SetClippingRegion( x, y, width, height ); | |
451 | ||
452 | }; | |
453 | ||
e6460682 | 454 | void wxWindowDC::DestroyClippingRegion(void) |
93cf77c0 JS |
455 | { |
456 | wxDC::DestroyClippingRegion(); | |
457 | ||
458 | }; | |
459 | ||
460 | // ----------------------------------- spline code ---------------------------------------- | |
461 | ||
462 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, | |
463 | double a3, double b3, double a4, double b4); | |
464 | void wx_clear_stack(void); | |
465 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, | |
466 | double *y3, double *x4, double *y4); | |
467 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, | |
468 | double x4, double y4); | |
469 | static bool wx_spline_add_point(double x, double y); | |
470 | static void wx_spline_draw_point_array(wxDC *dc); | |
471 | ||
472 | wxList wx_spline_point_list; | |
473 | ||
474 | #define half(z1, z2) ((z1+z2)/2.0) | |
475 | #define THRESHOLD 5 | |
476 | ||
477 | /* iterative version */ | |
478 | ||
479 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, | |
480 | double b4) | |
481 | { | |
482 | register double xmid, ymid; | |
483 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
484 | ||
485 | wx_clear_stack(); | |
486 | wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); | |
487 | ||
488 | while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { | |
489 | xmid = (double)half(x2, x3); | |
490 | ymid = (double)half(y2, y3); | |
491 | if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && | |
492 | fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { | |
493 | wx_spline_add_point( x1, y1 ); | |
494 | wx_spline_add_point( xmid, ymid ); | |
495 | } else { | |
496 | wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), | |
497 | (double)half(x3, x4), (double)half(y3, y4), x4, y4); | |
498 | wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), | |
499 | (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); | |
500 | } | |
501 | } | |
502 | } | |
503 | ||
504 | /* utilities used by spline drawing routines */ | |
505 | ||
506 | typedef struct wx_spline_stack_struct { | |
507 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
508 | } Stack; | |
509 | ||
510 | #define SPLINE_STACK_DEPTH 20 | |
511 | static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; | |
512 | static Stack *wx_stack_top; | |
513 | static int wx_stack_count; | |
514 | ||
515 | void wx_clear_stack(void) | |
516 | { | |
517 | wx_stack_top = wx_spline_stack; | |
518 | wx_stack_count = 0; | |
519 | } | |
520 | ||
521 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) | |
522 | { | |
523 | wx_stack_top->x1 = x1; | |
524 | wx_stack_top->y1 = y1; | |
525 | wx_stack_top->x2 = x2; | |
526 | wx_stack_top->y2 = y2; | |
527 | wx_stack_top->x3 = x3; | |
528 | wx_stack_top->y3 = y3; | |
529 | wx_stack_top->x4 = x4; | |
530 | wx_stack_top->y4 = y4; | |
531 | wx_stack_top++; | |
532 | wx_stack_count++; | |
533 | } | |
534 | ||
535 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, | |
536 | double *x3, double *y3, double *x4, double *y4) | |
537 | { | |
538 | if (wx_stack_count == 0) | |
539 | return (0); | |
540 | wx_stack_top--; | |
541 | wx_stack_count--; | |
542 | *x1 = wx_stack_top->x1; | |
543 | *y1 = wx_stack_top->y1; | |
544 | *x2 = wx_stack_top->x2; | |
545 | *y2 = wx_stack_top->y2; | |
546 | *x3 = wx_stack_top->x3; | |
547 | *y3 = wx_stack_top->y3; | |
548 | *x4 = wx_stack_top->x4; | |
549 | *y4 = wx_stack_top->y4; | |
550 | return (1); | |
551 | } | |
552 | ||
553 | static bool wx_spline_add_point(double x, double y) | |
554 | { | |
555 | wxPoint *point = new wxPoint ; | |
556 | point->x = (int) x; | |
557 | point->y = (int) y; | |
558 | wx_spline_point_list.Append((wxObject*)point); | |
559 | return TRUE; | |
560 | } | |
561 | ||
562 | static void wx_spline_draw_point_array(wxDC *dc) | |
563 | { | |
564 | dc->DrawLines(&wx_spline_point_list, 0, 0 ); | |
565 | wxNode *node = wx_spline_point_list.First(); | |
566 | while (node) | |
567 | { | |
568 | wxPoint *point = (wxPoint *)node->Data(); | |
569 | delete point; | |
570 | delete node; | |
571 | node = wx_spline_point_list.First(); | |
572 | } | |
573 | } | |
574 | ||
e6460682 | 575 | void wxWindowDC::DrawSpline( wxList *points ) |
93cf77c0 JS |
576 | { |
577 | wxPoint *p; | |
578 | double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; | |
579 | double x1, y1, x2, y2; | |
580 | ||
581 | wxNode *node = points->First(); | |
582 | p = (wxPoint *)node->Data(); | |
583 | ||
584 | x1 = p->x; | |
585 | y1 = p->y; | |
586 | ||
587 | node = node->Next(); | |
588 | p = (wxPoint *)node->Data(); | |
589 | ||
590 | x2 = p->x; | |
591 | y2 = p->y; | |
592 | cx1 = (double)((x1 + x2) / 2); | |
593 | cy1 = (double)((y1 + y2) / 2); | |
594 | cx2 = (double)((cx1 + x2) / 2); | |
595 | cy2 = (double)((cy1 + y2) / 2); | |
596 | ||
597 | wx_spline_add_point(x1, y1); | |
598 | ||
599 | while ((node = node->Next()) != NULL) | |
600 | { | |
601 | p = (wxPoint *)node->Data(); | |
602 | x1 = x2; | |
603 | y1 = y2; | |
604 | x2 = p->x; | |
605 | y2 = p->y; | |
606 | cx4 = (double)(x1 + x2) / 2; | |
607 | cy4 = (double)(y1 + y2) / 2; | |
608 | cx3 = (double)(x1 + cx4) / 2; | |
609 | cy3 = (double)(y1 + cy4) / 2; | |
610 | ||
611 | wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); | |
612 | ||
613 | cx1 = cx4; | |
614 | cy1 = cy4; | |
615 | cx2 = (double)(cx1 + x2) / 2; | |
616 | cy2 = (double)(cy1 + y2) / 2; | |
617 | } | |
618 | ||
619 | wx_spline_add_point( cx1, cy1 ); | |
620 | wx_spline_add_point( x2, y2 ); | |
621 | ||
622 | wx_spline_draw_point_array( this ); | |
623 | }; |