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