]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
127eab18 | 2 | // Name: src/mgl/dc.cpp |
32b8ec41 VZ |
3 | // Purpose: wxDC class |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2001/03/09 | |
6 | // RCS-ID: $Id$ | |
c41c20a5 | 7 | // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 8 | // Licence: wxWindows licence |
32b8ec41 VZ |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // =========================================================================== | |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
32b8ec41 VZ |
19 | // For compilers that support precompilation, includes "wx.h". |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/dc.h" | |
28 | #include "wx/dcmemory.h" | |
e4db172a | 29 | #include "wx/log.h" |
32b8ec41 VZ |
30 | #endif |
31 | ||
32 | #include "wx/fontutil.h" | |
3af1a9f8 | 33 | #include "wx/encinfo.h" |
32b8ec41 VZ |
34 | #include "wx/fontmap.h" |
35 | #include "wx/mgl/private.h" | |
32b8ec41 VZ |
36 | |
37 | #include <string.h> | |
32b8ec41 VZ |
38 | #include <mgraph.hpp> |
39 | ||
40 | ||
41 | ||
42 | //----------------------------------------------------------------------------- | |
43 | // constants | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
32b8ec41 VZ |
46 | const double RAD2DEG = 180.0 / M_PI; |
47 | ||
48 | ||
49 | //----------------------------------------------------------------------------- | |
50 | // pens data: | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | const ushort STIPPLE_wxDOT = 0x5555/* - - - - - - - -*/; | |
54 | const ushort STIPPLE_wxLONG_DASH = 0xF0F0/* ---- ----*/; | |
55 | const ushort STIPPLE_wxSHORT_DASH = 0xCCCC/*-- -- -- -- */; | |
d16b634f VZ |
56 | const ushort STIPPLE_wxDOT_DASH = 0x3939/* --- - --- -*/; |
57 | const ushort STIPPLE_wxSOLID = 0xFFFF/*----------------*/; | |
32b8ec41 VZ |
58 | |
59 | #define PATTERN_ROW(b7,b6,b5,b4,b3,b2,b1,b0) \ | |
60 | ((b7 << 7) | (b6 << 6) | (b5 << 5) | (b4 << 4) | \ | |
61 | (b3 << 3) | (b2 << 2) | (b1 << 1) | b0) | |
62 | ||
63 | static pattern_t PATTERN_wxFDIAGONAL_HATCH = {{ | |
64 | PATTERN_ROW(1,0,0,0,0,0,0,0), | |
65 | PATTERN_ROW(0,1,0,0,0,0,0,0), | |
66 | PATTERN_ROW(0,0,1,0,0,0,0,0), | |
67 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
68 | PATTERN_ROW(0,0,0,0,1,0,0,0), | |
69 | PATTERN_ROW(0,0,0,0,0,1,0,0), | |
70 | PATTERN_ROW(0,0,0,0,0,0,1,0), | |
71 | PATTERN_ROW(0,0,0,0,0,0,0,1), | |
72 | }}; | |
73 | ||
74 | static pattern_t PATTERN_wxCROSSDIAG_HATCH = {{ | |
75 | PATTERN_ROW(1,0,0,0,0,0,0,1), | |
76 | PATTERN_ROW(0,1,0,0,0,0,1,0), | |
77 | PATTERN_ROW(0,0,1,0,0,1,0,0), | |
78 | PATTERN_ROW(0,0,0,1,1,0,0,0), | |
79 | PATTERN_ROW(0,0,0,1,1,0,0,0), | |
80 | PATTERN_ROW(0,0,1,0,0,1,0,0), | |
81 | PATTERN_ROW(0,1,0,0,0,0,1,0), | |
82 | PATTERN_ROW(1,0,0,0,0,0,0,1), | |
83 | }}; | |
84 | ||
85 | static pattern_t PATTERN_wxBDIAGONAL_HATCH = {{ | |
86 | PATTERN_ROW(0,0,0,0,0,0,0,1), | |
87 | PATTERN_ROW(0,0,0,0,0,0,1,0), | |
88 | PATTERN_ROW(0,0,0,0,0,1,0,0), | |
89 | PATTERN_ROW(0,0,0,0,1,0,0,0), | |
90 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
91 | PATTERN_ROW(0,0,1,0,0,0,0,0), | |
92 | PATTERN_ROW(0,1,0,0,0,0,0,0), | |
93 | PATTERN_ROW(1,0,0,0,0,0,0,0), | |
94 | }}; | |
95 | ||
96 | static pattern_t PATTERN_wxCROSS_HATCH = {{ | |
97 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
98 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
99 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
100 | PATTERN_ROW(1,1,1,1,1,1,1,1), | |
101 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
102 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
103 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
104 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
105 | }}; | |
106 | ||
107 | static pattern_t PATTERN_wxHORIZONTAL_HATCH = {{ | |
108 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
109 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
110 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
111 | PATTERN_ROW(1,1,1,1,1,1,1,1), | |
112 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
113 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
114 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
115 | PATTERN_ROW(0,0,0,0,0,0,0,0), | |
116 | }}; | |
117 | ||
118 | static pattern_t PATTERN_wxVERTICAL_HATCH = {{ | |
119 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
120 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
121 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
122 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
123 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
124 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
125 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
126 | PATTERN_ROW(0,0,0,1,0,0,0,0), | |
127 | }}; | |
128 | ||
129 | #undef PATTERN_ROW | |
130 | ||
131 | //----------------------------------------------------------------------------- | |
132 | // wxDC | |
133 | //----------------------------------------------------------------------------- | |
134 | ||
135 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) | |
136 | ||
137 | // Default constructor | |
138 | wxDC::wxDC() | |
139 | { | |
127eab18 | 140 | m_isMemDC = false; |
32b8ec41 | 141 | m_MGLDC = NULL; |
127eab18 WS |
142 | m_OwnsMGLDC = false; |
143 | m_ok = false; // must call SetMGLDevCtx() before using it | |
32b8ec41 | 144 | |
32b8ec41 VZ |
145 | m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / |
146 | (double)wxGetDisplaySizeMM().GetWidth(); | |
147 | m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / | |
148 | (double)wxGetDisplaySizeMM().GetHeight(); | |
32b8ec41 VZ |
149 | |
150 | m_pen = *wxBLACK_PEN; | |
151 | m_font = *wxNORMAL_FONT; | |
152 | m_brush = *wxWHITE_BRUSH; | |
153 | m_penOfsX = m_penOfsY = 0; | |
154 | ||
127eab18 WS |
155 | m_penSelected = m_brushSelected = false; |
156 | m_downloadedPatterns[0] = m_downloadedPatterns[1] = false; | |
d16b634f | 157 | |
32b8ec41 VZ |
158 | m_mglFont = NULL; |
159 | } | |
160 | ||
161 | ||
162 | wxDC::~wxDC() | |
163 | { | |
d16b634f | 164 | if (m_OwnsMGLDC) |
32b8ec41 VZ |
165 | delete m_MGLDC; |
166 | } | |
167 | ||
168 | void wxDC::SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC) | |
169 | { | |
170 | if ( m_OwnsMGLDC && m_MGLDC ) | |
171 | delete m_MGLDC; | |
172 | m_MGLDC = mgldc; | |
173 | m_OwnsMGLDC = OwnsMGLDC; | |
127eab18 | 174 | m_ok = true; |
b8c0528d VS |
175 | |
176 | if ( !m_globalClippingRegion.IsNull() ) | |
177 | SetClippingRegion(m_globalClippingRegion); | |
d16b634f | 178 | |
32b8ec41 VZ |
179 | InitializeMGLDC(); |
180 | } | |
181 | ||
182 | void wxDC::InitializeMGLDC() | |
183 | { | |
184 | if ( GetDepth() > 8 ) | |
185 | { | |
186 | wxCurrentDCSwitcher switcher(m_MGLDC); // will go away with MGL6 | |
187 | m_MGLDC->setFontBlendMode(MGL_AA_RGBBLEND); | |
188 | } | |
189 | } | |
190 | ||
191 | ||
192 | // --------------------------------------------------------------------------- | |
193 | // clipping | |
194 | // --------------------------------------------------------------------------- | |
195 | ||
196 | ||
197 | #define DO_SET_CLIPPING_BOX(rg) \ | |
198 | { \ | |
199 | wxRect rect = rg.GetBox(); \ | |
200 | m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \ | |
201 | m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \ | |
202 | m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \ | |
203 | m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \ | |
204 | } | |
205 | ||
206 | void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) | |
207 | { | |
208 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
209 | ||
210 | wxRect rect(XLOG2DEV(cx), YLOG2DEV(cy), XLOG2DEVREL(cw), YLOG2DEVREL(ch)); | |
211 | ||
212 | if ( !m_currentClippingRegion.IsNull() ) | |
213 | m_currentClippingRegion.Intersect(rect); | |
214 | else | |
215 | m_currentClippingRegion.Union(rect); | |
216 | ||
ef344ff8 | 217 | m_MGLDC->setClipRegion(m_currentClippingRegion.GetMGLRegion()); |
32b8ec41 | 218 | |
127eab18 | 219 | m_clipping = true; |
32b8ec41 VZ |
220 | DO_SET_CLIPPING_BOX(m_currentClippingRegion) |
221 | } | |
222 | ||
223 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) | |
224 | { | |
225 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
226 | ||
ef344ff8 | 227 | if ( region.IsEmpty() ) |
32b8ec41 VZ |
228 | { |
229 | DestroyClippingRegion(); | |
230 | return; | |
231 | } | |
d16b634f | 232 | |
32b8ec41 | 233 | wxRegion rg(region); |
d16b634f | 234 | |
32b8ec41 VZ |
235 | // check if the DC is scaled or moved, and if yes, then |
236 | // convert rg to device coordinates: | |
237 | if ( m_deviceOriginX != 0 || m_deviceOriginY != 0 || | |
999c13cc | 238 | m_logicalOriginX != 0 || m_logicalOriginY != 0 || |
32b8ec41 VZ |
239 | XLOG2DEVREL(500) != 500 || YLOG2DEVREL(500) != 500 ) |
240 | { | |
241 | region_t *mrg = rg.GetMGLRegion().rgnPointer(); | |
d16b634f VZ |
242 | span_t *s; |
243 | segment_t *p; | |
244 | for (s = mrg->spans; s; s = s->next) | |
32b8ec41 | 245 | { |
d16b634f VZ |
246 | s->y = YLOG2DEV(s->y); |
247 | for (p = s->seg; p; p = p->next) | |
248 | p->x = XLOG2DEV(p->x); | |
32b8ec41 VZ |
249 | } |
250 | } | |
d16b634f | 251 | |
32b8ec41 VZ |
252 | if ( !m_currentClippingRegion.IsNull() ) |
253 | m_currentClippingRegion.Intersect(rg); | |
254 | else | |
255 | m_currentClippingRegion.Union(rg); | |
256 | ||
ef344ff8 | 257 | m_MGLDC->setClipRegion(m_currentClippingRegion.GetMGLRegion()); |
32b8ec41 | 258 | |
127eab18 | 259 | m_clipping = true; |
32b8ec41 VZ |
260 | DO_SET_CLIPPING_BOX(m_currentClippingRegion) |
261 | } | |
262 | ||
263 | void wxDC::DestroyClippingRegion() | |
264 | { | |
265 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
d16b634f | 266 | |
ef344ff8 VS |
267 | if ( !m_globalClippingRegion.IsNull() ) |
268 | { | |
269 | m_MGLDC->setClipRegion(m_globalClippingRegion.GetMGLRegion()); | |
270 | m_currentClippingRegion = m_globalClippingRegion; | |
127eab18 | 271 | m_clipping = true; |
ef344ff8 | 272 | } |
7bdc1879 | 273 | else |
ef344ff8 | 274 | { |
b8c0528d | 275 | m_MGLDC->setClipRect(MGLRect(0, 0, m_MGLDC->sizex()+1, m_MGLDC->sizey()+1)); |
d16b634f | 276 | ResetClipping(); |
ef344ff8 VS |
277 | m_currentClippingRegion.Clear(); |
278 | } | |
32b8ec41 VZ |
279 | } |
280 | ||
281 | // --------------------------------------------------------------------------- | |
282 | // query capabilities | |
283 | // --------------------------------------------------------------------------- | |
284 | ||
285 | bool wxDC::CanDrawBitmap() const | |
286 | { | |
127eab18 | 287 | return true; |
32b8ec41 VZ |
288 | } |
289 | ||
290 | bool wxDC::CanGetTextExtent() const | |
291 | { | |
127eab18 | 292 | return true; |
32b8ec41 VZ |
293 | } |
294 | ||
295 | int wxDC::GetDepth() const | |
296 | { | |
297 | return m_MGLDC->getBitsPerPixel(); | |
298 | } | |
299 | ||
300 | // --------------------------------------------------------------------------- | |
301 | // drawing | |
302 | // --------------------------------------------------------------------------- | |
303 | ||
304 | void wxDC::Clear() | |
305 | { | |
306 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
307 | ||
308 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
fd495ab3 | 309 | if ( m_backgroundBrush.GetStyle() != wxTRANSPARENT ) |
32b8ec41 VZ |
310 | { |
311 | int w, h; | |
312 | wxBrush oldb = m_brush; | |
313 | SetBrush(m_backgroundBrush); | |
314 | SelectBrush(); | |
315 | GetSize(&w, &h); | |
fa7cdd7f | 316 | m_MGLDC->fillRect(0, 0, w, h); |
32b8ec41 VZ |
317 | SetBrush(oldb); |
318 | } | |
319 | } | |
320 | ||
d16b634f | 321 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, |
3a0a5ada | 322 | const wxColour & col, int style); |
b1699cd3 | 323 | |
387ebd3e | 324 | bool wxDC::DoFloodFill(wxCoord x, wxCoord y, |
3a0a5ada VS |
325 | const wxColour& col, int style) |
326 | { | |
387ebd3e | 327 | return wxDoFloodFill(this, x, y, col, style); |
32b8ec41 VZ |
328 | } |
329 | ||
330 | bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
331 | { | |
127eab18 | 332 | wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel")); |
32b8ec41 VZ |
333 | |
334 | uchar r, g, b; | |
d16b634f | 335 | m_MGLDC->unpackColorFast(m_MGLDC->getPixel(XLOG2DEV(x), YLOG2DEV(y)), |
32b8ec41 VZ |
336 | r, g, b); |
337 | col->Set(r, g, b); | |
127eab18 | 338 | return true; |
32b8ec41 VZ |
339 | } |
340 | ||
341 | void wxDC::DoCrossHair(wxCoord x, wxCoord y) | |
342 | { | |
343 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
344 | ||
345 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
346 | { | |
347 | int w = 0; | |
348 | int h = 0; | |
349 | GetSize(&w, &h); | |
350 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 351 | if ( !m_penSelected ) |
32b8ec41 VZ |
352 | SelectPen(); |
353 | wxCoord xx = XLOG2DEV(x); | |
354 | wxCoord yy = YLOG2DEV(y); | |
355 | m_MGLDC->line(m_penOfsX, yy + m_penOfsY, w-1 + m_penOfsX, yy + m_penOfsY); | |
356 | m_MGLDC->line(xx + m_penOfsX, m_penOfsY, x + m_penOfsX, h-1 + m_penOfsY); | |
357 | CalcBoundingBox(0, 0); | |
358 | CalcBoundingBox(w, h); | |
359 | } | |
360 | } | |
361 | ||
362 | void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
363 | { | |
364 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
365 | ||
366 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
367 | { | |
368 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 369 | if ( !m_penSelected ) |
32b8ec41 | 370 | SelectPen(); |
d16b634f | 371 | m_MGLDC->lineExt(XLOG2DEV(x1) + m_penOfsX, YLOG2DEV(y1) + m_penOfsY, |
88f2a771 | 372 | XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY,FALSE); |
32b8ec41 VZ |
373 | CalcBoundingBox(x1, y1); |
374 | CalcBoundingBox(x2, y2); | |
375 | } | |
376 | } | |
377 | ||
378 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
379 | // and ending at (x2, y2) | |
380 | void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, | |
381 | wxCoord x2, wxCoord y2, | |
382 | wxCoord xc, wxCoord yc) | |
383 | { | |
384 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
385 | ||
386 | wxCoord xx1 = XLOG2DEV(x1); | |
387 | wxCoord yy1 = YLOG2DEV(y1); | |
388 | wxCoord xx2 = XLOG2DEV(x2); | |
389 | wxCoord yy2 = YLOG2DEV(y2); | |
390 | wxCoord xxc = XLOG2DEV(xc); | |
391 | wxCoord yyc = YLOG2DEV(yc); | |
392 | double dx = xx1 - xxc; | |
393 | double dy = yy1 - yyc; | |
394 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
395 | wxCoord r = (wxCoord)radius; | |
396 | double radius1, radius2; | |
397 | ||
398 | ||
399 | if (xx1 == xx2 && yy1 == yy2) | |
400 | { | |
401 | radius1 = 0.0; | |
402 | radius2 = 360.0; | |
403 | } | |
404 | else if (radius == 0.0) | |
405 | { | |
406 | radius1 = radius2 = 0.0; | |
407 | } | |
408 | else | |
409 | { | |
410 | radius1 = (xx1 - xxc == 0) ? | |
411 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
412 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
413 | radius2 = (xx2 - xxc == 0) ? | |
414 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
415 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
416 | } | |
417 | wxCoord alpha1 = wxCoord(radius1); | |
418 | wxCoord alpha2 = alpha1 + wxCoord(radius2 - radius1); | |
419 | while (alpha2 <= 0) alpha2 += 360; | |
420 | while (alpha1 > 360) alpha1 -= 360; | |
421 | ||
422 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
423 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
424 | { | |
d16b634f | 425 | if ( !m_brushSelected ) |
32b8ec41 VZ |
426 | SelectBrush(); |
427 | m_MGLDC->fillEllipseArc(xxc, yyc, r, r, alpha1, alpha2); | |
d16b634f | 428 | } |
32b8ec41 VZ |
429 | |
430 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
431 | { | |
d16b634f | 432 | if ( !m_penSelected ) |
32b8ec41 VZ |
433 | SelectPen(); |
434 | m_MGLDC->ellipseArc(xxc + m_penOfsX, yyc + m_penOfsY, r, r, alpha1, alpha2); | |
d16b634f | 435 | } |
32b8ec41 VZ |
436 | |
437 | CalcBoundingBox(xc - r, yc - r); | |
438 | CalcBoundingBox(xc + r, yc + r); | |
439 | } | |
440 | ||
441 | void wxDC::DoDrawPoint(wxCoord x, wxCoord y) | |
442 | { | |
443 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
444 | ||
445 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
446 | { | |
447 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 448 | if ( !m_penSelected ) |
32b8ec41 VZ |
449 | SelectPen(); |
450 | m_MGLDC->pixel(XLOG2DEV(x), YLOG2DEV(y)); | |
451 | CalcBoundingBox(x, y); | |
452 | } | |
453 | } | |
454 | ||
127eab18 | 455 | void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle)) |
32b8ec41 VZ |
456 | { |
457 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
458 | ||
d16b634f | 459 | wxCoord xxoffset = XLOG2DEVREL(xoffset), |
32b8ec41 | 460 | yyoffset = YLOG2DEVREL(yoffset); |
d16b634f | 461 | MGLPoint *cpoints = new MGLPoint[n+1]; |
32b8ec41 VZ |
462 | for (int i = 0; i < n; i++) |
463 | { | |
464 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); | |
465 | cpoints[i].x = (int)(XLOG2DEV(points[i].x)); | |
466 | cpoints[i].y = (int)(YLOG2DEV(points[i].y)); | |
467 | } | |
468 | cpoints[n] = cpoints[0]; | |
469 | ||
470 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
471 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
472 | { | |
473 | if ( !m_brushSelected ) | |
474 | SelectBrush(); | |
475 | m_MGLDC->fillPolygon(n, cpoints, xxoffset, yyoffset); | |
476 | } | |
477 | ||
478 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
479 | { | |
d16b634f | 480 | if ( !m_penSelected ) |
32b8ec41 VZ |
481 | SelectPen(); |
482 | if (m_penOfsX != 0 || m_penOfsY != 0) | |
483 | { | |
484 | for (int i = 0; i <= n; i++) | |
485 | { | |
486 | cpoints[i].x += m_penOfsX; | |
487 | cpoints[i].y += m_penOfsY; | |
488 | } | |
489 | } | |
490 | m_MGLDC->polyLine(n+1, cpoints); | |
491 | } | |
492 | ||
493 | delete[] cpoints; | |
494 | } | |
495 | ||
496 | void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
497 | { | |
498 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
499 | ||
500 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
501 | { | |
502 | MGLPoint *cpoints = new MGLPoint[n]; | |
503 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 504 | if ( !m_penSelected ) |
32b8ec41 VZ |
505 | SelectPen(); |
506 | for (int i = 0; i < n; i++) | |
507 | { | |
508 | CalcBoundingBox(points[i].x + xoffset, points[i].y + yoffset); | |
509 | cpoints[i].x = (int)(XLOG2DEV(points[i].x + xoffset) /*+ m_penOfsX*/); | |
510 | cpoints[i].y = (int)(YLOG2DEV(points[i].y + yoffset) /*+ m_penOfsY*/); | |
511 | } | |
512 | m_MGLDC->polyLine(n, cpoints); | |
513 | delete[] cpoints; | |
514 | } | |
515 | } | |
516 | ||
517 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
518 | { | |
519 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
520 | ||
521 | wxCoord xx = XLOG2DEV(x); | |
522 | wxCoord yy = YLOG2DEV(y); | |
523 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
524 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
525 | ||
526 | if ( ww == 0 || hh == 0 ) return; | |
527 | ||
d16b634f | 528 | if ( ww < 0 ) |
32b8ec41 | 529 | { |
d16b634f | 530 | ww = -ww; |
32b8ec41 VZ |
531 | xx = xx - ww; |
532 | } | |
d16b634f | 533 | if ( hh < 0 ) |
32b8ec41 | 534 | { |
d16b634f VZ |
535 | hh = -hh; |
536 | yy = yy - hh; | |
32b8ec41 VZ |
537 | } |
538 | ||
539 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
540 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
541 | { | |
d16b634f | 542 | if ( !m_brushSelected ) |
32b8ec41 VZ |
543 | SelectBrush(); |
544 | m_MGLDC->fillRect(xx, yy, xx + ww, yy + hh); | |
d16b634f | 545 | } |
32b8ec41 VZ |
546 | |
547 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
548 | { | |
d16b634f | 549 | if ( !m_penSelected ) |
32b8ec41 | 550 | SelectPen(); |
497b78df | 551 | |
d16b634f | 552 | m_MGLDC->rect(xx + m_penOfsX, yy + m_penOfsY, |
186954b0 | 553 | xx + ww + m_penOfsX, yy + hh + m_penOfsY); |
d16b634f | 554 | } |
32b8ec41 VZ |
555 | |
556 | CalcBoundingBox(x, y); | |
557 | CalcBoundingBox(x + width, y + height); | |
558 | } | |
559 | ||
560 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
561 | { | |
562 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
563 | ||
d16b634f | 564 | if ( radius < 0.0 ) |
32b8ec41 VZ |
565 | radius = -radius * ((width < height) ? width : height); |
566 | ||
567 | wxCoord xx = XLOG2DEV(x); | |
568 | wxCoord yy = YLOG2DEV(y); | |
569 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
570 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
571 | wxCoord rr = XLOG2DEVREL((wxCoord)radius); | |
572 | ||
573 | // CMB: handle -ve width and/or height | |
d16b634f | 574 | if ( ww < 0 ) |
32b8ec41 | 575 | { |
d16b634f VZ |
576 | ww = -ww; |
577 | xx = xx - ww; | |
32b8ec41 | 578 | } |
d16b634f VZ |
579 | if ( hh < 0 ) |
580 | { | |
581 | hh = -hh; | |
582 | yy = yy - hh; | |
32b8ec41 VZ |
583 | } |
584 | ||
585 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
586 | // X drawing errors with small radii | |
587 | if ( rr == 0 ) | |
588 | { | |
589 | DrawRectangle(x, y, width, height); | |
590 | return; | |
591 | } | |
592 | ||
593 | // CMB: draw nothing if transformed w or h is 0 | |
594 | if ( ww == 0 || hh == 0 ) return; | |
595 | ||
596 | // CMB: ensure dd is not larger than rectangle otherwise we | |
597 | // get an hour glass shape | |
598 | wxCoord dd = 2 * rr; | |
599 | if ( dd > ww ) dd = ww; | |
600 | if ( dd > hh ) dd = hh; | |
601 | rr = dd / 2; | |
602 | ||
603 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
604 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
605 | { | |
d16b634f | 606 | if (!m_brushSelected) |
32b8ec41 VZ |
607 | SelectBrush(); |
608 | m_MGLDC->fillRect(xx+rr, yy, xx+ww-rr, yy+hh); | |
609 | m_MGLDC->fillRect(xx, yy+rr, xx+ww, yy+hh-rr); | |
610 | m_MGLDC->fillEllipseArc(xx+rr, yy+rr, rr, rr, 90, 180); | |
611 | m_MGLDC->fillEllipseArc(xx+ww-rr, yy+rr, rr, rr, 0, 90); | |
612 | m_MGLDC->fillEllipseArc(xx+rr, yy+hh-rr, rr, rr, 180, 270); | |
613 | m_MGLDC->fillEllipseArc(xx+ww-rr, yy+hh-rr, rr, rr, 270, 0); | |
d16b634f | 614 | } |
32b8ec41 VZ |
615 | |
616 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
617 | { | |
d16b634f | 618 | if ( !m_penSelected ) |
32b8ec41 VZ |
619 | SelectPen(); |
620 | xx += m_penOfsX; | |
621 | yy += m_penOfsY; | |
d16b634f | 622 | m_MGLDC->line(xx+rr+1, yy, xx+ww-rr, yy); |
32b8ec41 VZ |
623 | m_MGLDC->ellipseArc(xx+ww-rr, yy+rr, rr, rr, 0, 90); |
624 | m_MGLDC->line(xx+ww, yy+rr+1, xx+ww, yy+hh-rr); | |
625 | m_MGLDC->ellipseArc(xx+ww-rr, yy+hh-rr, rr, rr, 270, 0); | |
626 | m_MGLDC->line(xx+ww-rr, yy+hh, xx+rr+1, yy+hh); | |
d16b634f | 627 | m_MGLDC->ellipseArc(xx+rr, yy+hh-rr, rr, rr, 180, 270); |
32b8ec41 VZ |
628 | m_MGLDC->line(xx, yy+hh-rr, xx, yy+rr+1); |
629 | m_MGLDC->ellipseArc(xx+rr, yy+rr, rr, rr, 90, 180); | |
630 | } | |
631 | ||
632 | CalcBoundingBox(x, y); | |
633 | CalcBoundingBox(x + width, y + height); | |
634 | } | |
635 | ||
636 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
637 | { | |
638 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
639 | ||
640 | wxCoord x2 = (x+width); | |
641 | wxCoord y2 = (y+height); | |
642 | ||
643 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
644 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
645 | { | |
646 | if ( !m_brushSelected ) | |
647 | SelectBrush(); | |
648 | MGLRect rect(XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
649 | m_MGLDC->fillEllipse(rect); | |
d16b634f | 650 | } |
32b8ec41 VZ |
651 | |
652 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
653 | { | |
d16b634f | 654 | if ( !m_penSelected ) |
32b8ec41 | 655 | SelectPen(); |
d16b634f | 656 | MGLRect rect(XLOG2DEV(x) + m_penOfsX, YLOG2DEV(y) + m_penOfsY, |
32b8ec41 VZ |
657 | XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY); |
658 | m_MGLDC->ellipse(rect); | |
659 | } | |
660 | ||
661 | CalcBoundingBox(x, y); | |
662 | CalcBoundingBox(x2, y2); | |
663 | } | |
664 | ||
665 | void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
666 | { | |
667 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
668 | ||
669 | wxCoord x2 = (x+w); | |
670 | wxCoord y2 = (y+h); | |
671 | ||
672 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
673 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
674 | { | |
675 | if (!m_brushSelected) SelectBrush(); | |
676 | MGLRect rect(XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
677 | m_MGLDC->fillEllipseArc(rect, (int)sa, (int)ea); | |
d16b634f | 678 | } |
32b8ec41 VZ |
679 | |
680 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
681 | { | |
d16b634f | 682 | if ( !m_penSelected ) |
32b8ec41 | 683 | SelectPen(); |
d16b634f | 684 | MGLRect rect(XLOG2DEV(x) + m_penOfsX, YLOG2DEV(y) + m_penOfsY, |
32b8ec41 VZ |
685 | XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY); |
686 | m_MGLDC->ellipseArc(rect, (int)sa, (int)ea); | |
d16b634f | 687 | } |
32b8ec41 VZ |
688 | |
689 | CalcBoundingBox(x, y); | |
690 | CalcBoundingBox(x2, y2); | |
691 | } | |
692 | ||
693 | void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
694 | { | |
32b8ec41 VZ |
695 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 |
696 | DrawAnyText(text, x, y); | |
697 | ||
698 | // update the bounding box | |
699 | wxCoord w, h; | |
700 | CalcBoundingBox(x, y); | |
701 | GetTextExtent(text, &w, &h); | |
702 | CalcBoundingBox(x + w, y + h); | |
703 | } | |
704 | ||
705 | bool wxDC::SelectMGLFont() | |
706 | { | |
707 | if ( m_mglFont == NULL ) | |
708 | { | |
709 | float scale = m_scaleY; | |
710 | bool antialiased = (GetDepth() > 8); | |
711 | ||
712 | m_mglFont = m_font.GetMGLfont_t(scale, antialiased); | |
127eab18 | 713 | wxCHECK_MSG( m_mglFont, false, wxT("invalid font") ); |
d16b634f | 714 | |
32b8ec41 VZ |
715 | m_MGLDC->useFont(m_mglFont); |
716 | wxLogTrace("mgl_font", "useFont(%p)", m_mglFont); | |
717 | ||
718 | #if !wxUSE_UNICODE | |
719 | wxNativeEncodingInfo nativeEnc; | |
720 | wxFontEncoding encoding = m_font.GetEncoding(); | |
721 | if ( !wxGetNativeFontEncoding(encoding, &nativeEnc) || | |
722 | !wxTestFontEncoding(nativeEnc) ) | |
723 | { | |
724 | #if wxUSE_FONTMAP | |
142b3bc2 | 725 | if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &nativeEnc) ) |
32b8ec41 VZ |
726 | #endif |
727 | { | |
728 | nativeEnc.mglEncoding = MGL_ENCODING_ASCII; | |
729 | } | |
730 | } | |
731 | m_MGLDC->setTextEncoding(nativeEnc.mglEncoding); | |
732 | #endif | |
733 | } | |
127eab18 | 734 | return true; |
32b8ec41 VZ |
735 | } |
736 | ||
737 | void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) | |
738 | { | |
739 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
740 | ||
741 | SelectMGLFont(); | |
742 | ||
32b8ec41 VZ |
743 | // Render the text: |
744 | wxCoord xx = XLOG2DEV(x); | |
745 | wxCoord yy = YLOG2DEV(y); | |
d16b634f | 746 | |
32b8ec41 VZ |
747 | m_MGLDC->setLineStyle(MGL_LINE_STIPPLE); |
748 | m_MGLDC->setLineStipple(0xFFFF); | |
749 | m_MGLDC->setPenSize(1, 1); | |
750 | m_MGLDC->setPenStyle(MGL_BITMAP_SOLID); | |
21a700f3 | 751 | |
32b8ec41 VZ |
752 | #if wxUSE_UNICODE |
753 | const wchar_t *c_text = text.c_str(); | |
754 | #else | |
755 | const char *c_text = text.c_str(); | |
756 | #endif | |
21a700f3 | 757 | |
d16b634f VZ |
758 | #if 1 |
759 | // FIXME_MGL - this is a temporary hack in absence of proper | |
760 | // implementation of solid text background in MGL. Once | |
21a700f3 VS |
761 | // the bug in MGL is fixed, this code should be nuked |
762 | // immediately. Note that the code is not 100% correct; | |
763 | // it only works with wxCOPY logical function | |
764 | if ( m_backgroundMode == wxSOLID ) | |
765 | { | |
766 | int w = m_MGLDC->textWidth(c_text); | |
767 | int h = m_MGLDC->textHeight(); | |
768 | m_MGLDC->setColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), | |
769 | m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); | |
770 | m_MGLDC->fillRect(xx, yy, xx+w, yy+h); | |
771 | } | |
772 | #endif | |
773 | ||
774 | m_MGLDC->setColor(m_MGLDC->packColorFast(m_textForegroundColour.Red(), | |
775 | m_textForegroundColour.Green(), m_textForegroundColour.Blue())); | |
776 | m_MGLDC->setBackColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), | |
777 | m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); | |
d16b634f | 778 | |
32b8ec41 | 779 | m_MGLDC->drawStr(xx, yy, c_text); |
d16b634f | 780 | |
32b8ec41 VZ |
781 | // Render underline: |
782 | if ( m_font.GetUnderlined() ) | |
783 | { | |
784 | int x1 = xx, y1 = yy; | |
a4bbc9f7 | 785 | int x2 = 0 , y2 = 0; |
32b8ec41 VZ |
786 | int w = m_MGLDC->textWidth(c_text); |
787 | m_MGLDC->underScoreLocation(x1, y1, c_text); | |
788 | switch (m_MGLDC->getTextDirection()) | |
789 | { | |
790 | case MGL_RIGHT_DIR: x2 = x1 + w, y2 = y1; break; | |
791 | case MGL_LEFT_DIR: x2 = x1 - w, y2 = y1; break; | |
792 | case MGL_UP_DIR: x2 = x1, y2 = y1 - w; break; | |
793 | case MGL_DOWN_DIR: x2 = x1, y2 = y1 + w; break; | |
794 | } | |
795 | m_MGLDC->line(x1, y1, x2, y2); | |
796 | } | |
797 | ||
127eab18 | 798 | m_penSelected = m_brushSelected = false; |
32b8ec41 VZ |
799 | } |
800 | ||
801 | void wxDC::DoDrawRotatedText(const wxString& text, | |
802 | wxCoord x, wxCoord y, | |
803 | double angle) | |
804 | { | |
32b8ec41 | 805 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 |
d16b634f | 806 | |
32b8ec41 VZ |
807 | if ( angle == 0 ) |
808 | { | |
809 | DoDrawText(text, x, y); | |
810 | return; | |
811 | } | |
812 | else if ( angle == 90.0 ) | |
813 | m_MGLDC->setTextDirection(MGL_UP_DIR); | |
814 | else if ( angle == 180.0 ) | |
815 | m_MGLDC->setTextDirection(MGL_LEFT_DIR); | |
816 | else if ( angle == 270.0 ) | |
817 | m_MGLDC->setTextDirection(MGL_DOWN_DIR); | |
818 | else | |
819 | { | |
820 | // FIXME_MGL -- implement once MGL supports it | |
821 | wxFAIL_MSG(wxT("wxMGL only supports rotated text with angle 0,90,180 or 270")); | |
822 | return; | |
823 | } | |
d16b634f | 824 | |
32b8ec41 | 825 | DrawAnyText(text, x, y); |
d16b634f | 826 | |
32b8ec41 VZ |
827 | // Restore default: |
828 | m_MGLDC->setTextDirection(MGL_RIGHT_DIR); | |
829 | } | |
830 | ||
831 | // --------------------------------------------------------------------------- | |
832 | // set GDI objects | |
833 | // --------------------------------------------------------------------------- | |
834 | ||
835 | void wxDC::SelectMGLStipplePen(int style) | |
836 | { | |
837 | ushort stipple; | |
838 | ||
839 | switch (style) | |
840 | { | |
841 | case wxDOT: stipple = STIPPLE_wxDOT; break; | |
842 | case wxLONG_DASH: stipple = STIPPLE_wxLONG_DASH; break; | |
843 | case wxSHORT_DASH: stipple = STIPPLE_wxSHORT_DASH; break; | |
844 | case wxDOT_DASH: stipple = STIPPLE_wxDOT_DASH; break; | |
845 | default: stipple = STIPPLE_wxSOLID; break; | |
846 | } | |
847 | ||
848 | m_MGLDC->setLineStyle(MGL_LINE_STIPPLE); | |
849 | m_MGLDC->setLineStipple(stipple); | |
850 | m_MGLDC->setPenSize(1, 1); | |
851 | m_MGLDC->setPenStyle(MGL_BITMAP_SOLID); | |
852 | m_penOfsY = m_penOfsX = 0; | |
853 | } | |
854 | ||
855 | // Accepted valus of SelectMGLFatPen's 2nd argument | |
856 | enum { | |
857 | wxMGL_SELECT_FROM_PEN, | |
858 | wxMGL_SELECT_FROM_BRUSH | |
859 | }; | |
860 | ||
861 | void wxDC::SelectMGLFatPen(int style, int flag) | |
862 | { | |
863 | MGL_penStyleType penstyle; | |
864 | const pattern_t *pattern = NULL; | |
865 | pixpattern24_t *pixPattern = NULL; | |
866 | int wx, wy; | |
867 | int slot; | |
868 | ||
869 | // Since MGL pens may be created from wxBrush or wxPen and we often | |
870 | // switch between pens and brushes, we take advantage of MGL's ability | |
871 | // to have multiple (pix)pattern_t's loaded. We always download pen | |
872 | // to 0th slot and brush to 1st slot. | |
d16b634f | 873 | if ( flag == wxMGL_SELECT_FROM_PEN ) |
32b8ec41 VZ |
874 | slot = 0; |
875 | else | |
876 | slot = 1; | |
877 | ||
d16b634f | 878 | // compute pen's width: |
32b8ec41 VZ |
879 | if ( m_pen.GetWidth() <= 1 ) |
880 | { | |
881 | wx = wy = 1; | |
882 | m_penOfsX = m_penOfsY = 0; | |
883 | } | |
884 | else | |
d16b634f | 885 | { |
32b8ec41 VZ |
886 | wx = (int)(0.5 + fabs((double) XLOG2DEVREL(m_pen.GetWidth()))); |
887 | wy = (int)(0.5 + fabs((double) YLOG2DEVREL(m_pen.GetWidth()))); | |
888 | m_penOfsX = -wx/2; | |
889 | m_penOfsY = -wy/2; | |
890 | } | |
d16b634f | 891 | |
32b8ec41 VZ |
892 | // find pen's type: |
893 | penstyle = MGL_BITMAP_TRANSPARENT; | |
894 | switch (style) | |
895 | { | |
d16b634f VZ |
896 | case wxBDIAGONAL_HATCH: pattern = &PATTERN_wxBDIAGONAL_HATCH; |
897 | penstyle = MGL_BITMAP_TRANSPARENT; | |
32b8ec41 | 898 | break; |
d16b634f VZ |
899 | case wxCROSSDIAG_HATCH: pattern = &PATTERN_wxCROSSDIAG_HATCH; |
900 | penstyle = MGL_BITMAP_TRANSPARENT; | |
32b8ec41 VZ |
901 | break; |
902 | case wxFDIAGONAL_HATCH: pattern = &PATTERN_wxFDIAGONAL_HATCH; | |
d16b634f | 903 | penstyle = MGL_BITMAP_TRANSPARENT; |
32b8ec41 VZ |
904 | break; |
905 | case wxCROSS_HATCH: pattern = &PATTERN_wxCROSS_HATCH; | |
d16b634f | 906 | penstyle = MGL_BITMAP_TRANSPARENT; |
32b8ec41 VZ |
907 | break; |
908 | case wxHORIZONTAL_HATCH: pattern = &PATTERN_wxHORIZONTAL_HATCH; | |
d16b634f | 909 | penstyle = MGL_BITMAP_TRANSPARENT; |
32b8ec41 VZ |
910 | break; |
911 | case wxVERTICAL_HATCH: pattern = &PATTERN_wxVERTICAL_HATCH; | |
d16b634f | 912 | penstyle = MGL_BITMAP_TRANSPARENT; |
32b8ec41 | 913 | break; |
d16b634f | 914 | |
32b8ec41 | 915 | case wxSTIPPLE: |
d16b634f | 916 | if ( flag == wxMGL_SELECT_FROM_PEN ) |
32b8ec41 VZ |
917 | pixPattern = (pixpattern24_t*) m_pen.GetPixPattern(); |
918 | else | |
919 | pixPattern = (pixpattern24_t*) m_brush.GetPixPattern(); | |
920 | penstyle = MGL_PIXMAP; | |
921 | break; | |
d16b634f | 922 | |
32b8ec41 VZ |
923 | case wxSTIPPLE_MASK_OPAQUE: |
924 | pattern = (pattern_t*) m_brush.GetMaskPattern(); | |
925 | penstyle = MGL_BITMAP_OPAQUE; | |
926 | break; | |
d16b634f | 927 | |
32b8ec41 VZ |
928 | case wxSOLID: |
929 | default: | |
930 | penstyle = MGL_BITMAP_SOLID; break; | |
931 | } | |
932 | ||
933 | // ...and finally, pass the pen to MGL: | |
934 | ||
935 | if ( pattern ) | |
936 | { | |
937 | if ( !m_downloadedPatterns[slot] ) | |
938 | { | |
939 | m_MGLDC->setPenBitmapPattern(slot, pattern); | |
127eab18 | 940 | m_downloadedPatterns[slot] = true; |
32b8ec41 VZ |
941 | } |
942 | m_MGLDC->usePenBitmapPattern(slot); | |
943 | } | |
d16b634f | 944 | |
32b8ec41 VZ |
945 | if ( pixPattern ) |
946 | { | |
947 | if ( !m_downloadedPatterns[slot] ) | |
948 | { | |
949 | pixpattern_t pix; | |
950 | int x, y, c; | |
d16b634f | 951 | |
32b8ec41 VZ |
952 | switch (GetDepth()) |
953 | { | |
954 | case 8: | |
955 | for (y = 0; y < 8; y++) | |
956 | for (x = 0; x < 8; x++) | |
127eab18 | 957 | pix.b8.p[x][y] = (uchar)m_MGLDC->packColorFast( |
32b8ec41 VZ |
958 | pixPattern->p[x][y][0], |
959 | pixPattern->p[x][y][1], | |
960 | pixPattern->p[x][y][2]); | |
961 | break; | |
962 | case 15: | |
963 | case 16: | |
964 | for (y = 0; y < 8; y++) | |
965 | for (x = 0; x < 8; x++) | |
127eab18 | 966 | pix.b16.p[x][y] = (M_uint16)m_MGLDC->packColorFast( |
32b8ec41 VZ |
967 | pixPattern->p[x][y][0], |
968 | pixPattern->p[x][y][1], | |
969 | pixPattern->p[x][y][2]); | |
970 | break; | |
971 | case 24: | |
972 | for (y = 0; y < 8; y++) | |
973 | for (x = 0; x < 8; x++) | |
974 | for (c = 0; c < 3; c++) | |
975 | pix.b24.p[x][y][c] = pixPattern->p[x][y][c]; | |
976 | break; | |
977 | case 32: | |
978 | for (y = 0; y < 8; y++) | |
979 | for (x = 0; x < 8; x++) | |
980 | pix.b32.p[x][y] = m_MGLDC->packColorFast( | |
981 | pixPattern->p[x][y][0], | |
982 | pixPattern->p[x][y][1], | |
983 | pixPattern->p[x][y][2]); | |
984 | break; | |
985 | default: | |
986 | wxFAIL_MSG(_T("invalid DC depth")); | |
987 | break; | |
988 | } | |
989 | m_MGLDC->setPenPixmapPattern(slot, &pix); | |
127eab18 | 990 | m_downloadedPatterns[slot] = true; |
32b8ec41 VZ |
991 | } |
992 | m_MGLDC->usePenPixmapPattern(slot); | |
993 | } | |
d16b634f | 994 | |
32b8ec41 VZ |
995 | m_MGLDC->setLineStyle(MGL_LINE_PENSTYLE); |
996 | m_MGLDC->setPenStyle(penstyle); | |
997 | m_MGLDC->setPenSize(wy, wx); | |
998 | } | |
999 | ||
1000 | void wxDC::SelectPen() | |
1001 | { | |
1002 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1003 | ||
1004 | wxColour& clr = m_pen.GetColour(); | |
1005 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1006 | m_MGLDC->setColorRGB(clr.Red(), clr.Green(), clr.Blue()); | |
1007 | ||
1008 | switch (m_pen.GetStyle()) | |
1009 | { | |
1010 | case wxTRANSPARENT: | |
1011 | break; | |
1012 | ||
1013 | case wxDOT: | |
1014 | case wxLONG_DASH: | |
1015 | case wxSHORT_DASH: | |
1016 | case wxDOT_DASH: | |
1017 | SelectMGLStipplePen(m_pen.GetStyle()); | |
1018 | break; | |
d16b634f | 1019 | |
32b8ec41 VZ |
1020 | case wxBDIAGONAL_HATCH: |
1021 | case wxCROSSDIAG_HATCH: | |
1022 | case wxFDIAGONAL_HATCH: | |
1023 | case wxCROSS_HATCH: | |
1024 | case wxHORIZONTAL_HATCH: | |
1025 | case wxVERTICAL_HATCH: | |
1026 | SelectMGLFatPen(m_pen.GetStyle(), wxMGL_SELECT_FROM_PEN); | |
1027 | break; | |
1028 | ||
1029 | case wxSTIPPLE: | |
1030 | SelectMGLFatPen(m_pen.GetStyle(), wxMGL_SELECT_FROM_PEN); | |
1031 | break; | |
1032 | ||
1033 | case wxSOLID: | |
1034 | case wxUSER_DASH: | |
1035 | default: | |
1036 | if ( m_pen.GetWidth() <= 1 ) | |
1037 | SelectMGLStipplePen(wxSOLID); | |
1038 | else | |
1039 | SelectMGLFatPen(wxSOLID, wxMGL_SELECT_FROM_PEN); | |
1040 | break; | |
1041 | } | |
127eab18 WS |
1042 | m_penSelected = true; |
1043 | m_brushSelected = false; | |
32b8ec41 VZ |
1044 | } |
1045 | ||
1046 | void wxDC::SelectBrush() | |
1047 | { | |
1048 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1049 | ||
1050 | wxColour fg, bg; | |
1051 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 1052 | |
32b8ec41 VZ |
1053 | if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) |
1054 | { | |
1055 | fg = m_textForegroundColour; | |
1056 | bg = m_textBackgroundColour; | |
1057 | } | |
1058 | else | |
1059 | { | |
1060 | fg = m_brush.GetColour(); | |
1061 | bg = m_backgroundBrush.GetColour(); | |
1062 | } | |
1063 | ||
1064 | m_MGLDC->setColorRGB(fg.Red(), fg.Green(), fg.Blue()); | |
1065 | m_MGLDC->setBackColor(m_MGLDC->packColorFast(bg.Red(), bg.Green(), bg.Blue())); | |
127eab18 WS |
1066 | m_penSelected = false; |
1067 | m_brushSelected = true; | |
32b8ec41 VZ |
1068 | |
1069 | SelectMGLFatPen(m_brush.GetStyle(), wxMGL_SELECT_FROM_BRUSH); | |
1070 | } | |
1071 | ||
1072 | void wxDC::SetPen(const wxPen& pen) | |
1073 | { | |
1074 | if ( !pen.Ok() ) return; | |
1075 | if ( m_pen == pen ) return; | |
1076 | m_pen = pen; | |
127eab18 WS |
1077 | m_penSelected = false; |
1078 | m_downloadedPatterns[0] = false; | |
32b8ec41 VZ |
1079 | } |
1080 | ||
1081 | void wxDC::SetBrush(const wxBrush& brush) | |
1082 | { | |
1083 | if ( !brush.Ok() ) return; | |
1084 | if ( m_brush == brush ) return; | |
1085 | m_brush = brush; | |
127eab18 WS |
1086 | m_brushSelected = false; |
1087 | m_downloadedPatterns[1] = false; | |
32b8ec41 VZ |
1088 | } |
1089 | ||
1090 | void wxDC::SetPalette(const wxPalette& palette) | |
1091 | { | |
1092 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
d16b634f | 1093 | |
32b8ec41 VZ |
1094 | if ( palette == wxNullPalette ) |
1095 | { | |
ac4de069 VS |
1096 | if ( m_oldPalette.Ok() ) |
1097 | SetPalette(m_oldPalette); | |
32b8ec41 VZ |
1098 | return; |
1099 | } | |
1100 | ||
1101 | if ( !palette.Ok() ) return; | |
1102 | if ( m_palette == palette ) return; | |
1103 | m_oldPalette = m_palette; | |
1104 | m_palette = palette; | |
1105 | ||
1106 | int cnt = m_palette.GetColoursCount(); | |
d16b634f | 1107 | palette_t *pal = m_palette.GetMGLpalette_t(); |
32b8ec41 VZ |
1108 | m_MGLDC->setPalette(pal, cnt, 0); |
1109 | m_MGLDC->realizePalette(cnt, 0, TRUE); | |
1110 | } | |
1111 | ||
1112 | void wxDC::SetFont(const wxFont& font) | |
1113 | { | |
31e39e3c VS |
1114 | if ( font.Ok() ) |
1115 | { | |
1116 | m_font = font; | |
1117 | m_mglFont = NULL; | |
1118 | } | |
32b8ec41 VZ |
1119 | } |
1120 | ||
1121 | void wxDC::SetBackground(const wxBrush& brush) | |
1122 | { | |
1123 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1124 | ||
1125 | if (!m_backgroundBrush.Ok()) return; | |
1126 | ||
1127 | m_backgroundBrush = brush; | |
1128 | wxColour &clr = m_backgroundBrush.GetColour(); | |
1129 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1130 | m_MGLDC->setBackColor( | |
1131 | m_MGLDC->packColorFast(clr.Red(), clr.Green(), clr.Blue())); | |
1132 | } | |
1133 | ||
1134 | void wxDC::SetBackgroundMode(int mode) | |
1135 | { | |
1136 | m_backgroundMode = mode; | |
1137 | if ( mode == wxSOLID ) | |
1138 | m_MGLDC->setBackMode(MGL_OPAQUE_BACKGROUND); | |
1139 | else | |
1140 | m_MGLDC->setBackMode(MGL_TRANSPARENT_BACKGROUND); | |
1141 | } | |
1142 | ||
1143 | void wxDC::SetLogicalFunction(int function) | |
1144 | { | |
1145 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1146 | ||
1147 | m_logicalFunction = function; | |
1148 | ||
1149 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1150 | m_MGLDC->setWriteMode(LogicalFunctionToMGLRop(m_logicalFunction)); | |
1151 | } | |
1152 | ||
1153 | int wxDC::LogicalFunctionToMGLRop(int logFunc) const | |
1154 | { | |
1155 | MGL_writeModeType rop; | |
1156 | ||
1157 | switch (logFunc) | |
1158 | { | |
1159 | case wxCLEAR: rop = MGL_R2_BLACK; break; | |
1160 | case wxXOR: rop = MGL_R2_XORSRC; break; | |
1161 | case wxINVERT: rop = MGL_R2_NOT; break; | |
1162 | case wxOR_REVERSE: rop = MGL_R2_MERGESRCNOT; break; | |
1163 | case wxAND_REVERSE: rop = MGL_R2_MASKSRCNOT; break; | |
1164 | case wxCOPY: rop = MGL_R2_COPYSRC; break; | |
1165 | case wxAND: rop = MGL_R2_MASKSRC; break; | |
1166 | case wxAND_INVERT: rop = MGL_R2_MASKNOTSRC; break; | |
1167 | case wxNO_OP: rop = MGL_R2_NOP; break; | |
1168 | case wxNOR: rop = MGL_R2_NOTMERGESRC; break; | |
1169 | case wxEQUIV: rop = MGL_R2_NOTXORSRC; break; | |
1170 | case wxSRC_INVERT: rop = MGL_R2_NOTCOPYSRC; break; | |
1171 | case wxOR_INVERT: rop = MGL_R2_MERGENOTSRC; break; | |
1172 | case wxNAND: rop = MGL_R2_NOTMASKSRC; break; | |
1173 | case wxOR: rop = MGL_R2_MERGESRC; break; | |
1174 | case wxSET: rop = MGL_R2_WHITE; break; | |
1175 | default: | |
1176 | wxFAIL_MSG( wxT("unsupported logical function") ); | |
1177 | return MGL_REPLACE_MODE; | |
1178 | } | |
1179 | return (int)rop; | |
1180 | } | |
1181 | ||
127eab18 | 1182 | bool wxDC::StartDoc(const wxString& WXUNUSED(message)) |
32b8ec41 | 1183 | { |
127eab18 WS |
1184 | // We might be previewing, so return true to let it continue. |
1185 | return true; | |
32b8ec41 VZ |
1186 | } |
1187 | ||
1188 | void wxDC::EndDoc() | |
1189 | { | |
1190 | } | |
1191 | ||
1192 | void wxDC::StartPage() | |
1193 | { | |
1194 | } | |
1195 | ||
1196 | void wxDC::EndPage() | |
1197 | { | |
1198 | } | |
1199 | ||
1200 | // --------------------------------------------------------------------------- | |
1201 | // text metrics | |
1202 | // --------------------------------------------------------------------------- | |
1203 | ||
1204 | wxCoord wxDC::GetCharHeight() const | |
1205 | { | |
1206 | wxCurrentDCSwitcher switcher(m_MGLDC); | |
1207 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return -1; | |
1208 | return YDEV2LOGREL(m_mglFont->fontHeight); | |
1209 | } | |
1210 | ||
1211 | wxCoord wxDC::GetCharWidth() const | |
1212 | { | |
1213 | wxCurrentDCSwitcher switcher(m_MGLDC); | |
1214 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return -1; | |
1215 | // VS: wxT() is intentional, charWidth() has both char and wchar_t version | |
1216 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are only | |
1217 | // scaled according to m_scaleY | |
1218 | return YDEV2LOGREL(m_mglFont->fontWidth); | |
1219 | } | |
1220 | ||
1221 | void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, | |
1222 | wxCoord *descent, wxCoord *externalLeading, | |
1223 | wxFont *theFont) const | |
1224 | { | |
1225 | wxFont oldFont; | |
d16b634f | 1226 | |
32b8ec41 VZ |
1227 | if ( theFont != NULL ) |
1228 | { | |
1229 | oldFont = m_font; | |
1230 | wxConstCast(this, wxDC)->SetFont(*theFont); | |
1231 | } | |
d16b634f | 1232 | |
32b8ec41 VZ |
1233 | wxCurrentDCSwitcher switcher(m_MGLDC); |
1234 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return; | |
1235 | ||
1236 | if ( x ) | |
d16b634f | 1237 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are |
32b8ec41 VZ |
1238 | // only scaled according to m_scaleY |
1239 | *x = YDEV2LOGREL(m_MGLDC->textWidth(string.c_str())); | |
1240 | if ( y ) | |
1241 | *y = YDEV2LOGREL(m_MGLDC->textHeight()); | |
1242 | if ( descent ) | |
1243 | *descent = YDEV2LOGREL(m_mglFont->descent); | |
1244 | if ( externalLeading ) | |
1245 | *externalLeading = YDEV2LOGREL(m_mglFont->leading); | |
a46935cb | 1246 | |
32b8ec41 VZ |
1247 | if ( theFont != NULL ) |
1248 | wxConstCast(this, wxDC)->SetFont(oldFont); | |
1249 | } | |
1250 | ||
1251 | ||
1252 | ||
1253 | // --------------------------------------------------------------------------- | |
1254 | // mapping modes | |
1255 | // --------------------------------------------------------------------------- | |
1256 | ||
1257 | void wxDC::ComputeScaleAndOrigin() | |
1258 | { | |
1259 | double newX = m_logicalScaleX * m_userScaleX; | |
1260 | double newY = m_logicalScaleY * m_userScaleY; | |
d16b634f | 1261 | |
32b8ec41 VZ |
1262 | // make sure font will be reloaded before drawing: |
1263 | if ( newY != m_scaleY ) | |
1264 | m_mglFont = NULL; | |
1265 | // make sure m_penOfs{X,Y} will be reevaluated before drawing: | |
1266 | if ( newY != m_scaleY || newX != m_scaleX ) | |
127eab18 | 1267 | m_penSelected = false; |
d16b634f | 1268 | |
32b8ec41 VZ |
1269 | m_scaleX = newX, m_scaleY = newY; |
1270 | } | |
1271 | ||
1272 | void wxDC::SetMapMode(int mode) | |
1273 | { | |
1274 | switch (mode) | |
1275 | { | |
1276 | case wxMM_TWIPS: | |
1277 | SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); | |
1278 | break; | |
1279 | case wxMM_POINTS: | |
1280 | SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); | |
1281 | break; | |
1282 | case wxMM_METRIC: | |
1283 | SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); | |
1284 | break; | |
1285 | case wxMM_LOMETRIC: | |
1286 | SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); | |
1287 | break; | |
1288 | default: | |
1289 | case wxMM_TEXT: | |
1290 | SetLogicalScale(1.0, 1.0); | |
1291 | break; | |
1292 | } | |
1293 | m_mappingMode = mode; | |
1294 | } | |
1295 | ||
1296 | void wxDC::SetUserScale( double x, double y ) | |
1297 | { | |
1298 | // allow negative ? -> no | |
1299 | m_userScaleX = x; | |
1300 | m_userScaleY = y; | |
1301 | ComputeScaleAndOrigin(); | |
1302 | } | |
1303 | ||
1304 | void wxDC::SetLogicalScale( double x, double y ) | |
1305 | { | |
1306 | // allow negative ? | |
1307 | m_logicalScaleX = x; | |
1308 | m_logicalScaleY = y; | |
1309 | ComputeScaleAndOrigin(); | |
1310 | } | |
1311 | ||
1312 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
1313 | { | |
1314 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
1315 | m_logicalOriginY = y * m_signY; | |
1316 | ComputeScaleAndOrigin(); | |
1317 | } | |
1318 | ||
1319 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1320 | { | |
1321 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
1322 | m_deviceOriginX = x; | |
1323 | m_deviceOriginY = y; | |
1324 | ComputeScaleAndOrigin(); | |
1325 | } | |
1326 | ||
1327 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1328 | { | |
1329 | // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there | |
1330 | m_signX = (xLeftRight ? 1 : -1); | |
1331 | m_signY = (yBottomUp ? -1 : 1); | |
1332 | ComputeScaleAndOrigin(); | |
1333 | } | |
1334 | ||
1335 | // --------------------------------------------------------------------------- | |
1336 | // coordinates transformations | |
1337 | // --------------------------------------------------------------------------- | |
1338 | ||
1339 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
1340 | { | |
1341 | return ((wxDC *)this)->XDEV2LOG(x); | |
1342 | } | |
1343 | ||
1344 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
1345 | { | |
1346 | return ((wxDC *)this)->YDEV2LOG(y); | |
1347 | } | |
1348 | ||
1349 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
1350 | { | |
1351 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
1352 | } | |
1353 | ||
1354 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
1355 | { | |
1356 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
1357 | } | |
1358 | ||
1359 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
1360 | { | |
1361 | return ((wxDC *)this)->XLOG2DEV(x); | |
1362 | } | |
1363 | ||
1364 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
1365 | { | |
1366 | return ((wxDC *)this)->YLOG2DEV(y); | |
1367 | } | |
1368 | ||
1369 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
1370 | { | |
1371 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
1372 | } | |
1373 | ||
1374 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
1375 | { | |
1376 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
1377 | } | |
1378 | ||
1379 | ||
1380 | void wxDC::DoGetSize(int *w, int *h) const | |
1381 | { | |
b8c0528d VS |
1382 | if (w) *w = m_MGLDC->sizex()+1; |
1383 | if (h) *h = m_MGLDC->sizey()+1; | |
32b8ec41 VZ |
1384 | } |
1385 | ||
1386 | void wxDC::DoGetSizeMM(int *width, int *height) const | |
1387 | { | |
1388 | int w = 0; | |
1389 | int h = 0; | |
1390 | GetSize(&w, &h); | |
1391 | if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x)); | |
1392 | if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y)); | |
1393 | } | |
1394 | ||
1395 | wxSize wxDC::GetPPI() const | |
1396 | { | |
d16b634f | 1397 | return wxSize(int(double(m_mm_to_pix_x) * inches2mm), |
32b8ec41 VZ |
1398 | int(double(m_mm_to_pix_y) * inches2mm)); |
1399 | } | |
1400 | ||
1401 | ||
1402 | // --------------------------------------------------------------------------- | |
1403 | // Blitting | |
1404 | // --------------------------------------------------------------------------- | |
1405 | ||
1406 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, | |
1407 | wxCoord width, wxCoord height, | |
1408 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 JS |
1409 | int rop, bool useMask, |
1410 | wxCoord xsrcMask, wxCoord ysrcMask) | |
32b8ec41 | 1411 | { |
127eab18 WS |
1412 | wxCHECK_MSG( Ok(), false, wxT("invalid dc") ); |
1413 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); | |
d16b634f | 1414 | |
32b8ec41 VZ |
1415 | // transform the source DC coords to the device ones |
1416 | xsrc = source->LogicalToDeviceX(xsrc); | |
1417 | ysrc = source->LogicalToDeviceY(ysrc); | |
1418 | ||
a4bbc9f7 | 1419 | /* FIXME_MGL: use the mask origin when drawing transparently */ |
0cbff120 JS |
1420 | if (xsrcMask == -1 && ysrcMask == -1) |
1421 | { | |
1422 | xsrcMask = xsrc; ysrcMask = ysrc; | |
1423 | } | |
1424 | else | |
1425 | { | |
1426 | xsrcMask = source->LogicalToDeviceX(xsrcMask); | |
1427 | ysrcMask = source->LogicalToDeviceY(ysrcMask); | |
1428 | } | |
1429 | ||
32b8ec41 VZ |
1430 | CalcBoundingBox(xdest, ydest); |
1431 | CalcBoundingBox(xdest + width, ydest + height); | |
1432 | ||
1433 | /* scale/translate size and position */ | |
1434 | wxCoord xx = XLOG2DEV(xdest); | |
1435 | wxCoord yy = YLOG2DEV(ydest); | |
1436 | wxCoord ww = XLOG2DEVREL(width); | |
1437 | wxCoord hh = YLOG2DEVREL(height); | |
1438 | ||
1439 | if ( source->m_isMemDC ) | |
1440 | { | |
1441 | wxMemoryDC *memDC = (wxMemoryDC*) source; | |
1442 | DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh, | |
1443 | xdest, ydest, rop, useMask); | |
1444 | } | |
1445 | else | |
1446 | { | |
1447 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
d16b634f | 1448 | m_MGLDC->bitBlt(*source->GetMGLDC(), |
32b8ec41 VZ |
1449 | xsrc, ysrc, xsrc + ww, ysrc + hh, |
1450 | xx, yy, LogicalFunctionToMGLRop(rop)); | |
1451 | } | |
1452 | ||
127eab18 | 1453 | return true; |
32b8ec41 VZ |
1454 | } |
1455 | ||
1456 | void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) | |
1457 | { | |
1458 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1459 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
1460 | ||
1461 | wxCoord w = bmp.GetWidth(); | |
1462 | wxCoord h = bmp.GetHeight(); | |
1463 | ||
1464 | DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask); | |
1465 | } | |
1466 | ||
1467 | void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
1468 | { | |
1469 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why | |
127eab18 | 1470 | DoDrawBitmap((const wxBitmap&)icon, x, y, true); |
32b8ec41 VZ |
1471 | } |
1472 | ||
1473 | ||
1474 | static inline void DoBitBlt(const wxBitmap& src, MGLDevCtx *dst, | |
d16b634f VZ |
1475 | int sx, int sy, int sw, int sh, |
1476 | int dx, int dy, int dw, int dh, | |
32b8ec41 VZ |
1477 | int rop, bool useStretching, bool putSection) |
1478 | { | |
1479 | bitmap_t *bmp = src.GetMGLbitmap_t(); | |
1480 | if (!useStretching) | |
1481 | { | |
1482 | if (!putSection) | |
1483 | dst->putBitmap(dx, dy, bmp, rop); | |
1484 | else | |
1485 | dst->putBitmapSection(sx, sy, sx + sw, sy + sh, dx, dy, bmp, rop); | |
1486 | } | |
1487 | else | |
1488 | { | |
1489 | if (!putSection) | |
1490 | dst->stretchBitmap(dx, dy, dx + dw, dy + dh, bmp, rop); | |
1491 | else | |
d16b634f | 1492 | dst->stretchBitmapSection(sx, sy, sx + sw, sy + sh, |
32b8ec41 VZ |
1493 | dx, dy, dx + dw, dy + dh, bmp, rop); |
1494 | } | |
1495 | } | |
1496 | ||
d16b634f | 1497 | void wxDC::DoDrawSubBitmap(const wxBitmap &bmp, |
32b8ec41 VZ |
1498 | wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
1499 | wxCoord destx, wxCoord desty, int rop, bool useMask) | |
1500 | { | |
1501 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1502 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
1503 | ||
1504 | CalcBoundingBox(x, y); | |
1505 | CalcBoundingBox(x + w, y + h); | |
1506 | ||
1507 | wxCoord dx = XLOG2DEV(destx); | |
1508 | wxCoord dy = YLOG2DEV(desty); | |
1509 | wxCoord dw = XLOG2DEVREL(w); | |
1510 | wxCoord dh = YLOG2DEVREL(h); | |
d16b634f | 1511 | |
32b8ec41 | 1512 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 |
d16b634f | 1513 | |
32b8ec41 VZ |
1514 | bool useStretching = ((w != dw) || (h != dh)); |
1515 | bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight()); | |
1516 | MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop); | |
1517 | ||
1518 | if ( bmp.GetDepth() == 1 ) | |
1519 | { | |
1520 | // Mono bitmaps are handled in special way -- all 1s are drawn in | |
1521 | // foreground colours, all 0s in background colour. | |
1522 | ||
1523 | ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour); | |
1524 | } | |
1525 | ||
1526 | if ( useMask && bmp.GetMask() ) | |
1527 | { | |
1528 | // Since MGL does not support masks directly (in MGL, mask is handled | |
d16b634f | 1529 | // in same way as in wxImage, i.e. there is one "key" color), we |
32b8ec41 VZ |
1530 | // simulate masked bitblt in 6 steps (same as in MSW): |
1531 | // | |
d16b634f VZ |
1532 | // 1. Create a temporary bitmap and copy the destination area into it. |
1533 | // 2. Copy the source area into the temporary bitmap using the | |
32b8ec41 | 1534 | // specified logical function. |
d16b634f VZ |
1535 | // 3. Set the masked area in the temporary bitmap to BLACK by ANDing |
1536 | // the mask bitmap with the temp bitmap with the foreground colour | |
32b8ec41 VZ |
1537 | // set to WHITE and the bg colour set to BLACK. |
1538 | // 4. Set the unmasked area in the destination area to BLACK by | |
d16b634f | 1539 | // ANDing the mask bitmap with the destination area with the |
32b8ec41 | 1540 | // foreground colour set to BLACK and the background colour set |
d16b634f VZ |
1541 | // to WHITE. |
1542 | // 5. OR the temporary bitmap with the destination area. | |
1543 | // 6. Delete the temporary bitmap. | |
1544 | // | |
1545 | // This sequence of operations ensures that the source's transparent | |
32b8ec41 VZ |
1546 | // area need not be black, and logical functions are supported. |
1547 | ||
1548 | wxBitmap *mask = bmp.GetMask()->GetBitmap(); | |
1549 | ||
1550 | MGLMemoryDC *temp; | |
d16b634f | 1551 | |
32b8ec41 VZ |
1552 | if ( GetDepth() <= 8 ) |
1553 | { | |
1554 | temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL); | |
1555 | wxDC tempdc; | |
127eab18 | 1556 | tempdc.SetMGLDC(temp, false); |
32b8ec41 VZ |
1557 | tempdc.SetPalette(m_palette); |
1558 | } | |
1559 | else | |
1560 | { | |
1561 | pixel_format_t pf; | |
1562 | m_MGLDC->getPixelFormat(pf); | |
1563 | temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf); | |
1564 | } | |
d16b634f | 1565 | |
32b8ec41 | 1566 | wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") ); |
d16b634f | 1567 | |
32b8ec41 VZ |
1568 | temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE); |
1569 | ||
d16b634f | 1570 | DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop, |
32b8ec41 VZ |
1571 | useStretching, putSection); |
1572 | ||
1573 | mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255)); | |
d16b634f | 1574 | DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC, |
32b8ec41 | 1575 | useStretching, putSection); |
d16b634f | 1576 | DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC, |
32b8ec41 VZ |
1577 | useStretching, putSection); |
1578 | ||
1579 | m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE); | |
d16b634f | 1580 | |
32b8ec41 VZ |
1581 | delete temp; |
1582 | } | |
d16b634f | 1583 | |
32b8ec41 VZ |
1584 | else |
1585 | { | |
d16b634f | 1586 | DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop, |
32b8ec41 VZ |
1587 | useStretching, putSection); |
1588 | } | |
1589 | } |