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