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