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