]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mgl/dc.h
1. moved InheritAttributes() from wxControl to wxWindow
[wxWidgets.git] / include / wx / mgl / dc.h
CommitLineData
32b8ec41
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.h
3// Purpose: wxDC class
4// Author: Vaclav Slavik
5// Created: 2001/03/09
6// RCS-ID: $Id$
52750c2e 7// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
32b8ec41
VZ
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_DC_H_
12#define _WX_DC_H_
13
12028905 14#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
32b8ec41
VZ
15 #pragma interface "dc.h"
16#endif
17
18#include "wx/defs.h"
19#include "wx/dc.h"
20#include "wx/region.h"
21
22//-----------------------------------------------------------------------------
23// classes
24//-----------------------------------------------------------------------------
25
26class WXDLLEXPORT wxDC;
27
28//-----------------------------------------------------------------------------
29// constants
30//-----------------------------------------------------------------------------
31
32#define MM_TEXT 0
33#define MM_ISOTROPIC 1
34#define MM_ANISOTROPIC 2
35#define MM_LOMETRIC 3
36#define MM_HIMETRIC 4
37#define MM_TWIPS 5
38#define MM_POINTS 6
39#define MM_METRIC 7
40
41//-----------------------------------------------------------------------------
42// wxDC
43//-----------------------------------------------------------------------------
44
45
46// MGL fwd declarations:
47class MGLDevCtx;
7bdc1879 48class MGLRegion;
32b8ec41
VZ
49struct font_t;
50
51class WXDLLEXPORT wxDC : public wxDCBase
52{
53 DECLARE_DYNAMIC_CLASS(wxDC)
54
55public:
56 wxDC();
57 ~wxDC();
58
59 // implement base class pure virtuals
60 // ----------------------------------
61
62 virtual void Clear();
63
64 virtual bool StartDoc(const wxString& message);
65 virtual void EndDoc();
66
67 virtual void StartPage();
68 virtual void EndPage();
69
70 virtual void SetFont(const wxFont& font);
71 virtual void SetPen(const wxPen& pen);
72 virtual void SetBrush(const wxBrush& brush);
73 virtual void SetBackground(const wxBrush& brush);
74 virtual void SetBackgroundMode(int mode);
75 virtual void SetPalette(const wxPalette& palette);
76
77 virtual void DestroyClippingRegion();
78
79 virtual wxCoord GetCharHeight() const;
80 virtual wxCoord GetCharWidth() const;
81 virtual void DoGetTextExtent(const wxString& string,
82 wxCoord *x, wxCoord *y,
83 wxCoord *descent = NULL,
84 wxCoord *externalLeading = NULL,
85 wxFont *theFont = NULL) const;
86
87 virtual bool CanDrawBitmap() const;
88 virtual bool CanGetTextExtent() const;
89 virtual int GetDepth() const;
90 virtual wxSize GetPPI() const;
91
92 virtual void SetMapMode(int mode);
93 virtual void SetUserScale(double x, double y);
94 virtual void SetLogicalScale(double x, double y);
95 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
96 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
97 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
98 virtual void SetLogicalFunction(int function);
99
100 // implementation from now on
101 // --------------------------
102
103 virtual void ComputeScaleAndOrigin();
104
105 wxCoord XDEV2LOG(wxCoord x) const
106 {
107 wxCoord new_x = x - m_deviceOriginX;
108 if (new_x > 0)
109 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
110 else
111 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
112 }
113 wxCoord XDEV2LOGREL(wxCoord x) const
114 {
115 if (x > 0)
116 return (wxCoord)((double)(x) / m_scaleX + 0.5);
117 else
118 return (wxCoord)((double)(x) / m_scaleX - 0.5);
119 }
120 wxCoord YDEV2LOG(wxCoord y) const
121 {
122 wxCoord new_y = y - m_deviceOriginY;
123 if (new_y > 0)
124 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
125 else
126 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
127 }
128 wxCoord YDEV2LOGREL(wxCoord y) const
129 {
130 if (y > 0)
131 return (wxCoord)((double)(y) / m_scaleY + 0.5);
132 else
133 return (wxCoord)((double)(y) / m_scaleY - 0.5);
134 }
135 wxCoord XLOG2DEV(wxCoord x) const
136 {
137 wxCoord new_x = x - m_logicalOriginX;
138 if (new_x > 0)
139 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
140 else
141 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
142 }
143 wxCoord XLOG2DEVREL(wxCoord x) const
144 {
145 if (x > 0)
146 return (wxCoord)((double)(x) * m_scaleX + 0.5);
147 else
148 return (wxCoord)((double)(x) * m_scaleX - 0.5);
149 }
150 wxCoord YLOG2DEV(wxCoord y) const
151 {
152 wxCoord new_y = y - m_logicalOriginY;
153 if (new_y > 0)
154 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
155 else
156 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
157 }
158 wxCoord YLOG2DEVREL(wxCoord y) const
159 {
160 if (y > 0)
161 return (wxCoord)((double)(y) * m_scaleY + 0.5);
162 else
163 return (wxCoord)((double)(y) * m_scaleY - 0.5);
164 }
165
166 MGLDevCtx *GetMGLDC() const { return m_MGLDC; }
167 void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = FALSE);
168
169protected:
387ebd3e 170 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
32b8ec41
VZ
171 int style = wxFLOOD_SURFACE);
172
173 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
174
175 virtual void DoDrawPoint(wxCoord x, wxCoord y);
176 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
177
178 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
179 wxCoord x2, wxCoord y2,
180 wxCoord xc, wxCoord yc);
181 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
182 double sa, double ea);
183
184 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
185 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
186 wxCoord width, wxCoord height,
187 double radius);
188 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
189
190 virtual void DoCrossHair(wxCoord x, wxCoord y);
191
192 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
193 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
194 bool useMask = FALSE);
195
196 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
197 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
198 double angle);
199
200 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
201 wxDC *source, wxCoord xsrc, wxCoord ysrc,
0cbff120 202 int rop = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
32b8ec41
VZ
203
204 // this is gnarly - we can't even call this function DoSetClippingRegion()
205 // because of virtual function hiding
206 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
207 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
208 wxCoord width, wxCoord height);
209 virtual void DoGetClippingRegion(wxCoord *x, wxCoord *y,
210 wxCoord *width, wxCoord *height)
211 {
212 GetClippingBox(x, y, width, height);
213 }
214
215 virtual void DoGetSize(int *width, int *height) const;
216 virtual void DoGetSizeMM(int* width, int* height) const;
217
218 virtual void DoDrawLines(int n, wxPoint points[],
219 wxCoord xoffset, wxCoord yoffset);
220 virtual void DoDrawPolygon(int n, wxPoint points[],
221 wxCoord xoffset, wxCoord yoffset,
222 int fillStyle = wxODDEVEN_RULE);
223
224 // implementation from now on:
225
226protected:
227 // setup newly attached MGLDevCtx for wxDC's use
228 // (does things like setting RGB blending mode for antialiased texts):
229 void InitializeMGLDC();
230
231 // common part of DoDrawText() and DoDrawRotatedText()
232 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
233
234 // MGL uses pens as both wxPens and wxBrushes, so we have to
235 // switch them as needed:
236 void SelectPen();
237 void SelectBrush();
238 void SelectMGLStipplePen(int style);
239 void SelectMGLFatPen(int style, int flag);
240
241 // Select m_font into m_MGLDC:
242 bool SelectMGLFont();
243
244 // Convert wxWin logical function to MGL rop:
245 int LogicalFunctionToMGLRop(int logFunc) const;
246
247 // Unified implementation of DrawIcon, DrawBitmap and Blit:
248 void DoDrawSubBitmap(const wxBitmap &bmp,
249 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
250 wxCoord destx, wxCoord desty, int rop, bool useMask);
251
252 // MGL DC class we use:
253 MGLDevCtx *m_MGLDC;
254 bool m_OwnsMGLDC:1;
255
256 // helper variables for SelectXXXX():
257 bool m_penSelected;
258 bool m_brushSelected;
259 bool m_downloadedPatterns[2];
260
261 // MGL does not render lines with width>1 with endings centered
262 // at given coords but with top left corner of the pen at them,
263 // these offsets are used to correct it. They are computed by
264 // SelectPen.
265 int m_penOfsX, m_penOfsY;
266
267 double m_mm_to_pix_x, m_mm_to_pix_y;
268
269 wxPalette m_oldPalette;
270
271 wxRegion m_currentClippingRegion;
ef344ff8 272 wxRegion m_globalClippingRegion;
32b8ec41
VZ
273
274 // wxDC::Blit handles memoryDCs as special cases :(
275 bool m_isMemDC;
276
277 font_t *m_mglFont;
278};
279
280#endif
281 // _WX_DC_H_