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