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