]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dc.h
Small cursor improvements
[wxWidgets.git] / include / wx / dc.h
1 #ifndef _WX_DC_H_BASE_
2 #define _WX_DC_H_BASE_
3
4 #ifdef __GNUG__
5 #pragma interface "dcbase.h"
6 #endif
7
8 // ----------------------------------------------------------------------------
9 // headers which we must include here
10 // ----------------------------------------------------------------------------
11
12 #include "wx/object.h" // the base class
13
14 #include "wx/cursor.h" // we have member variables of these classes
15 #include "wx/font.h" // so we can't do without them
16 #include "wx/colour.h"
17 #include "wx/brush.h"
18 #include "wx/pen.h"
19 #include "wx/palette.h"
20
21 #include "wx/list.h" // we use wxList in inline functions
22
23 // ---------------------------------------------------------------------------
24 // types
25 // ---------------------------------------------------------------------------
26
27 // type which should be used (whenever possible, i.e. as long as it doesn't
28 // break compatibility) for screen coordinates
29 typedef int wxCoord;
30
31 // ---------------------------------------------------------------------------
32 // global variables
33 // ---------------------------------------------------------------------------
34
35 WXDLLEXPORT_DATA(extern int) wxPageNumber;
36
37 // ---------------------------------------------------------------------------
38 // wxDC is the device context - object on which any drawing is done
39 // ---------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxDCBase : public wxObject
42 {
43 DECLARE_ABSTRACT_CLASS(wxDCBase)
44
45 public:
46 wxDCBase()
47 {
48 m_clipping = FALSE;
49 m_ok = TRUE;
50
51 m_minX = m_minY = m_maxX = m_maxY = 0;
52
53 m_signX = m_signY = 1;
54
55 m_logicalOriginX = m_logicalOriginY =
56 m_deviceOriginX = m_deviceOriginY = 0;
57
58 m_logicalScaleX = m_logicalScaleY =
59 m_userScaleX = m_userScaleY =
60 m_scaleX = m_scaleY = 1.0;
61
62 m_logicalFunction = -1;
63
64 m_backgroundMode = wxTRANSPARENT;
65
66 m_mappingMode = wxMM_TEXT;
67
68 m_backgroundBrush = *wxWHITE_BRUSH;
69
70 m_textForegroundColour = *wxBLACK;
71 m_textBackgroundColour = *wxWHITE;
72
73 m_colour = wxColourDisplay();
74 }
75
76 ~wxDCBase() { }
77
78 virtual void BeginDrawing() { }
79 virtual void EndDrawing() { }
80
81 // graphic primitives
82 // ------------------
83
84 void FloodFill(long x, long y, const wxColour& col,
85 int style = wxFLOOD_SURFACE)
86 { DoFloodFill(x, y, col, style); }
87 void FloodFill(const wxPoint& pt, const wxColour& col,
88 int style = wxFLOOD_SURFACE)
89 { DoFloodFill(pt.x, pt.y, col, style); }
90
91 bool GetPixel(long x, long y, wxColour *col) const
92 { return DoGetPixel(x, y, col); }
93 bool GetPixel(const wxPoint& pt, wxColour *col) const
94 { return DoGetPixel(pt.x, pt.y, col); }
95
96 void DrawLine(long x1, long y1, long x2, long y2)
97 { DoDrawLine(x1, y1, x2, y2); }
98 void DrawLine(const wxPoint& pt1, const wxPoint& pt2)
99 { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); }
100
101 void CrossHair(long x, long y)
102 { DoCrossHair(x, y); }
103 void CrossHair(const wxPoint& pt)
104 { DoCrossHair(pt.x, pt.y); }
105
106 void DrawArc(long x1, long y1, long x2, long y2, long xc, long yc)
107 { DoDrawArc(x1, y1, x2, y2, xc, yc); }
108 void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
109 { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
110
111 void DrawEllipticArc(long x, long y, long w, long h, double sa, double ea)
112 { DoDrawEllipticArc(x, y, w, h, sa, ea); }
113 void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
114 double sa, double ea)
115 { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); }
116
117 void DrawPoint(long x, long y)
118 { DoDrawPoint(x, y); }
119 void DrawPoint(const wxPoint& pt)
120 { DoDrawPoint(pt.x, pt.y); }
121
122 void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0)
123 { DoDrawLines(n, points, xoffset, yoffset); }
124 void DrawLines(const wxList *list, long xoffset = 0, long yoffset = 0);
125
126 void DrawPolygon(int n, wxPoint points[],
127 long xoffset = 0, long yoffset = 0,
128 int fillStyle = wxODDEVEN_RULE)
129 { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); }
130
131 void DrawPolygon(const wxList *list,
132 long xoffset = 0, long yoffset = 0,
133 int fillStyle = wxODDEVEN_RULE);
134
135 void DrawRectangle(long x, long y, long width, long height)
136 { DoDrawRectangle(x, y, width, height); }
137 void DrawRectangle(const wxPoint& pt, const wxSize& sz)
138 { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); }
139 void DrawRectangle(const wxRect& rect)
140 { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); }
141
142 void DrawRoundedRectangle(long x, long y, long width, long height,
143 double radius)
144 { DoDrawRoundedRectangle(x, y, width, height, radius); }
145 void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
146 double radius)
147 { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); }
148 void DrawRoundedRectangle(const wxRect& r, double radius)
149 { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); }
150
151 void DrawCircle(long x, long y, long radius)
152 { DoDrawEllipse(x - radius, y - radius, 2*radius, 2*radius); }
153 void DrawEllipse(long x, long y, long width, long height)
154 { DoDrawEllipse(x, y, width, height); }
155 void DrawEllipse(const wxPoint& pt, const wxSize& sz)
156 { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); }
157 void DrawEllipse(const wxRect& rect)
158 { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); }
159
160 void DrawIcon(const wxIcon& icon, long x, long y)
161 { DoDrawIcon(icon, x, y); }
162 void DrawIcon(const wxIcon& icon, const wxPoint& pt)
163 { DoDrawIcon(icon, pt.x, pt.y); }
164
165 void DrawBitmap(const wxBitmap &bmp, long x, long y, bool useMask = FALSE)
166 { DoDrawBitmap(bmp, x, y, useMask); }
167 void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
168 bool useMask = FALSE)
169 { DoDrawBitmap(bmp, pt.x, pt.y, useMask); }
170
171 void DrawText(const wxString& text, long x, long y)
172 { DoDrawText(text, x, y); }
173 void DrawText(const wxString& text, const wxPoint& pt)
174 { DoDrawText(text, pt.x, pt.y); }
175
176 bool Blit(long xdest, long ydest, long width, long height,
177 wxDC *source, long xsrc, long ysrc,
178 int rop = wxCOPY, bool useMask = FALSE)
179 {
180 return DoBlit(xdest, ydest, width, height,
181 source, xsrc, ysrc, rop, useMask);
182 }
183 bool Blit(const wxPoint& destPt, const wxSize& sz,
184 wxDC *source, const wxPoint& srcPt,
185 int rop = wxCOPY, bool useMask = FALSE)
186 {
187 return DoBlit(destPt.x, destPt.y, sz.x, sz.y,
188 source, srcPt.x, srcPt.y, rop, useMask);
189 }
190
191 #if wxUSE_SPLINES
192 // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?)
193 void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3);
194 void DrawSpline(int n, wxPoint points[]);
195
196 void DrawSpline(wxList *points) { DoDrawSpline(points); }
197 #endif // wxUSE_SPLINES
198
199 // global DC operations
200 // --------------------
201
202 virtual void Clear() = 0;
203
204 virtual bool StartDoc(const wxString& message) = 0;
205 virtual void EndDoc() = 0;
206
207 virtual void StartPage() = 0;
208 virtual void EndPage() = 0;
209
210 // set objects to use for drawing
211 // ------------------------------
212
213 virtual void SetFont(const wxFont& font) = 0;
214 virtual void SetPen(const wxPen& pen) = 0;
215 virtual void SetBrush(const wxBrush& brush) = 0;
216 virtual void SetBackground(const wxBrush& brush) = 0;
217 virtual void SetBackgroundMode(int mode) = 0;
218 virtual void SetPalette(const wxPalette& palette) = 0;
219
220 // clipping region
221 // ---------------
222
223 void SetClippingRegion(long x, long y, long width, long height)
224 { DoSetClippingRegion(x, y, width, height); }
225 void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
226 { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); }
227 void SetClippingRegion(const wxRect& rect)
228 { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); }
229 void SetClippingRegion(const wxRegion& region)
230 { DoSetClippingRegionAsRegion(region); }
231
232 virtual void DestroyClippingRegion() = 0;
233
234 void GetClippingBox(long *x, long *y, long *w, long *h) const
235 { DoGetClippingBox(x, y, w, h); }
236 void GetClippingBox(wxRect& rect) const
237 { DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); }
238
239 // text extent
240 // -----------
241
242 virtual long GetCharHeight() const = 0;
243 virtual long GetCharWidth() const = 0;
244 virtual void GetTextExtent(const wxString& string,
245 long *x, long *y,
246 long *descent = NULL,
247 long *externalLeading = NULL,
248 wxFont *theFont = NULL) const = 0;
249
250 // size and resolution
251 // -------------------
252
253 // in device units
254 void GetSize(int *width, int *height) const
255 { DoGetSize(width, height); }
256 wxSize GetSize() const
257 {
258 int w, h;
259 DoGetSize(&w, &h);
260
261 return wxSize(w, h);
262 }
263
264 // in mm
265 void GetSizeMM(int* width, int* height) const
266 { DoGetSizeMM(width, height); }
267 wxSize GetSizeMM() const
268 {
269 int w, h;
270 DoGetSizeMM(&w, &h);
271
272 return wxSize(w, h);
273 }
274
275 // coordinates conversions
276 // -----------------------
277
278 // This group of functions does actual conversion of the input, as you'd
279 // expect.
280 long DeviceToLogicalX(long x) const;
281 long DeviceToLogicalY(long y) const;
282 long DeviceToLogicalXRel(long x) const;
283 long DeviceToLogicalYRel(long y) const;
284 long LogicalToDeviceX(long x) const;
285 long LogicalToDeviceY(long y) const;
286 long LogicalToDeviceXRel(long x) const;
287 long LogicalToDeviceYRel(long y) const;
288
289 // query DC capabilities
290 // ---------------------
291
292 virtual bool CanDrawBitmap() const = 0;
293 virtual bool CanGetTextExtent() const = 0;
294
295 // colour depth
296 virtual int GetDepth() const = 0;
297
298 // Resolution in Pixels per inch
299 virtual wxSize GetPPI() const = 0;
300
301 virtual bool Ok() const { return m_ok; }
302
303 // accessors
304 // ---------
305
306 // const...
307 const wxBrush& GetBackground() const { return m_backgroundBrush; }
308 const wxBrush& GetBrush() const { return m_brush; }
309 const wxFont& GetFont() const { return m_font; }
310 const wxPen& GetPen() const { return m_pen; }
311 const wxColour& GetTextBackground() const { return m_textBackgroundColour; }
312 const wxColour& GetTextForeground() const { return m_textForegroundColour; }
313
314 // ... and non const
315 wxBrush& GetBackground() { return m_backgroundBrush; }
316 wxBrush& GetBrush() { return m_brush; }
317 wxFont& GetFont() { return m_font; }
318 wxPen& GetPen() { return m_pen; }
319 wxColour& GetTextBackground() { return m_textBackgroundColour; }
320 wxColour& GetTextForeground() { return m_textForegroundColour; }
321
322 virtual void SetTextForeground(const wxColour& colour)
323 { m_textForegroundColour = colour; }
324 virtual void SetTextBackground(const wxColour& colour)
325 { m_textBackgroundColour = colour; }
326
327 int GetMapMode() const { return m_mappingMode; }
328 virtual void SetMapMode(int mode) = 0;
329
330 virtual void GetUserScale(double *x, double *y) const
331 {
332 if ( x ) *x = m_userScaleX;
333 if ( y ) *y = m_userScaleY;
334 }
335 virtual void SetUserScale(double x, double y) = 0;
336
337 virtual void GetLogicalScale(double *x, double *y)
338 {
339 if ( x ) *x = m_logicalScaleX;
340 if ( y ) *y = m_logicalScaleY;
341 }
342 virtual void SetLogicalScale(double x, double y)
343 {
344 m_logicalScaleX = x;
345 m_logicalScaleY = y;
346 }
347
348 void GetLogicalOrigin(long *x, long *y) const
349 { DoGetLogicalOrigin(x, y); }
350 wxPoint GetLogicalOrigin() const
351 { long x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); }
352 virtual void SetLogicalOrigin(long x, long y) = 0;
353
354 void GetDeviceOrigin(long *x, long *y) const
355 { DoGetDeviceOrigin(x, y); }
356 wxPoint GetDeviceOrigin() const
357 { long x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); }
358 virtual void SetDeviceOrigin(long x, long y) = 0;
359
360 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0;
361
362 int GetLogicalFunction() const { return m_logicalFunction; }
363 virtual void SetLogicalFunction(int function) = 0;
364
365 // Sometimes we need to override optimization, e.g. if other software is
366 // drawing onto our surface and we can't be sure of who's done what.
367 //
368 // FIXME: is this (still) used?
369 virtual void SetOptimization(bool WXUNUSED(opt)) { }
370 virtual bool GetOptimization() { return FALSE; }
371
372 // bounding box
373 // ------------
374
375 virtual void CalcBoundingBox(long x, long y)
376 {
377 if (x < m_minX) m_minX = x;
378 if (y < m_minY) m_minY = y;
379 if (x > m_maxX) m_maxX = x;
380 if (y > m_maxY) m_maxY = y;
381 }
382
383 // Get the final bounding box of the PostScript or Metafile picture.
384 long MinX() const { return m_minX; }
385 long MaxX() const { return m_maxX; }
386 long MinY() const { return m_minY; }
387 long MaxY() const { return m_maxY; }
388
389 // misc old functions
390 // ------------------
391
392 #if WXWIN_COMPATIBILITY
393 virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); }
394 void GetTextExtent(const wxString& string, float *x, float *y,
395 float *descent = NULL, float *externalLeading = NULL,
396 wxFont *theFont = NULL, bool use16bit = FALSE) const ;
397 void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; }
398 void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; }
399 #endif // WXWIN_COMPATIBILITY
400
401 protected:
402 // the pure virtual functions which should be implemented by wxDC
403 virtual void DoFloodFill(long x, long y, const wxColour& col,
404 int style = wxFLOOD_SURFACE) = 0;
405
406 virtual bool DoGetPixel(long x, long y, wxColour *col) const = 0;
407
408 virtual void DoDrawPoint(long x, long y) = 0;
409 virtual void DoDrawLine(long x1, long y1, long x2, long y2) = 0;
410
411 virtual void DoDrawArc(long x1, long y1,
412 long x2, long y2,
413 long xc, long yc) = 0;
414 virtual void DoDrawEllipticArc(long x, long y, long w, long h,
415 double sa, double ea) = 0;
416
417 virtual void DoDrawRectangle(long x, long y, long width, long height) = 0;
418 virtual void DoDrawRoundedRectangle(long x, long y,
419 long width, long height,
420 double radius) = 0;
421 virtual void DoDrawEllipse(long x, long y, long width, long height) = 0;
422
423 virtual void DoCrossHair(long x, long y) = 0;
424
425 virtual void DoDrawIcon(const wxIcon& icon, long x, long y) = 0;
426 virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y,
427 bool useMask = FALSE) = 0;
428
429 virtual void DoDrawText(const wxString& text, long x, long y) = 0;
430
431 virtual bool DoBlit(long xdest, long ydest, long width, long height,
432 wxDC *source, long xsrc, long ysrc,
433 int rop = wxCOPY, bool useMask = FALSE) = 0;
434
435 virtual void DoGetSize(int *width, int *height) const = 0;
436 virtual void DoGetSizeMM(int* width, int* height) const = 0;
437
438 virtual void DoDrawLines(int n, wxPoint points[],
439 long xoffset, long yoffset) = 0;
440 virtual void DoDrawPolygon(int n, wxPoint points[],
441 long xoffset, long yoffset,
442 int fillStyle = wxODDEVEN_RULE) = 0;
443
444 virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0;
445 virtual void DoSetClippingRegion(long x, long y,
446 long width, long height) = 0;
447
448 // FIXME are these functions really different?
449 virtual void DoGetClippingRegion(long *x, long *y,
450 long *w, long *h)
451 { DoGetClippingBox(x, y, w, h); }
452 virtual void DoGetClippingBox(long *x, long *y,
453 long *w, long *h) const
454 {
455 if ( m_clipping )
456 {
457 if ( x ) *x = m_clipX1;
458 if ( y ) *y = m_clipY1;
459 if ( w ) *w = m_clipX2 - m_clipX1;
460 if ( h ) *h = m_clipY2 - m_clipY1;
461 }
462 else
463 {
464 *x = *y = *w = *h = 0;
465 }
466 }
467
468 virtual void DoGetLogicalOrigin(long *x, long *y) const
469 {
470 if ( x ) *x = m_logicalOriginX;
471 if ( y ) *y = m_logicalOriginY;
472 }
473
474 virtual void DoGetDeviceOrigin(long *x, long *y) const
475 {
476 if ( x ) *x = m_deviceOriginX;
477 if ( y ) *y = m_deviceOriginY;
478 }
479
480 #if wxUSE_SPLINES
481 virtual void DoDrawSpline(wxList *points) = 0;
482 #endif
483
484 protected:
485 // flags
486 bool m_colour:1;
487 bool m_ok:1;
488 bool m_clipping:1;
489 bool m_isInteractive:1;
490
491 // coordinate system variables
492
493 // TODO short descriptions of what exactly they are would be nice...
494
495 long m_logicalOriginX, m_logicalOriginY;
496 long m_deviceOriginX, m_deviceOriginY;
497
498 double m_logicalScaleX, m_logicalScaleY;
499 double m_userScaleX, m_userScaleY;
500 double m_scaleX, m_scaleY;
501
502 // Used by SetAxisOrientation() to invert the axes
503 int m_signX, m_signY;
504
505 // bounding and clipping boxes
506 long m_minX, m_minY, m_maxX, m_maxY;
507 long m_clipX1, m_clipY1, m_clipX2, m_clipY2;
508
509 int m_logicalFunction;
510 int m_backgroundMode;
511 int m_mappingMode;
512
513 // GDI objects
514 wxPen m_pen;
515 wxBrush m_brush;
516 wxBrush m_backgroundBrush;
517 wxColour m_textForegroundColour;
518 wxColour m_textBackgroundColour;
519 wxFont m_font;
520 wxPalette m_palette;
521
522 private:
523 DECLARE_NO_COPY_CLASS(wxDCBase);
524 };
525
526 // ----------------------------------------------------------------------------
527 // now include the declaration of wxDC class
528 // ----------------------------------------------------------------------------
529
530 #if defined(__WXMSW__)
531 #include "wx/msw/dc.h"
532 #elif defined(__WXMOTIF__)
533 #include "wx/motif/dc.h"
534 #elif defined(__WXGTK__)
535 #include "wx/gtk/dc.h"
536 #elif defined(__WXQT__)
537 #include "wx/qt/dc.h"
538 #elif defined(__WXMAC__)
539 #include "wx/mac/dc.h"
540 #elif defined(__WXSTUBS__)
541 #include "wx/stubs/dc.h"
542 #endif
543
544 #endif
545 // _WX_DC_H_BASE_