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