]>
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 VS |
560 | |
561 | // VS: MGLDC::rect() does not render rectangles that have width | |
562 | // or height equal to 1, so we have to use MGLDC::line() | |
563 | // instead... | |
564 | if ( hh == 1 || ww == 1 ) | |
565 | m_MGLDC->line(xx + m_penOfsX, yy + m_penOfsY, | |
566 | xx + ww-1 + m_penOfsX, yy + hh-1 + m_penOfsY); | |
567 | else | |
568 | m_MGLDC->rect(xx + m_penOfsX, yy + m_penOfsY, | |
569 | xx + ww + m_penOfsX, yy + hh + m_penOfsY); | |
32b8ec41 VZ |
570 | } |
571 | ||
572 | CalcBoundingBox(x, y); | |
573 | CalcBoundingBox(x + width, y + height); | |
574 | } | |
575 | ||
576 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
577 | { | |
578 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
579 | ||
580 | if ( radius < 0.0 ) | |
581 | radius = -radius * ((width < height) ? width : height); | |
582 | ||
583 | wxCoord xx = XLOG2DEV(x); | |
584 | wxCoord yy = YLOG2DEV(y); | |
585 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
586 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
587 | wxCoord rr = XLOG2DEVREL((wxCoord)radius); | |
588 | ||
589 | // CMB: handle -ve width and/or height | |
590 | if ( ww < 0 ) | |
591 | { | |
592 | ww = -ww; | |
593 | xx = xx - ww; | |
594 | } | |
595 | if ( hh < 0 ) | |
596 | { | |
597 | hh = -hh; | |
598 | yy = yy - hh; | |
599 | } | |
600 | ||
601 | // CMB: if radius is zero use DrawRectangle() instead to avoid | |
602 | // X drawing errors with small radii | |
603 | if ( rr == 0 ) | |
604 | { | |
605 | DrawRectangle(x, y, width, height); | |
606 | return; | |
607 | } | |
608 | ||
609 | // CMB: draw nothing if transformed w or h is 0 | |
610 | if ( ww == 0 || hh == 0 ) return; | |
611 | ||
612 | // CMB: ensure dd is not larger than rectangle otherwise we | |
613 | // get an hour glass shape | |
614 | wxCoord dd = 2 * rr; | |
615 | if ( dd > ww ) dd = ww; | |
616 | if ( dd > hh ) dd = hh; | |
617 | rr = dd / 2; | |
618 | ||
619 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
620 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
621 | { | |
622 | if (!m_brushSelected) | |
623 | SelectBrush(); | |
624 | m_MGLDC->fillRect(xx+rr, yy, xx+ww-rr, yy+hh); | |
625 | m_MGLDC->fillRect(xx, yy+rr, xx+ww, yy+hh-rr); | |
626 | m_MGLDC->fillEllipseArc(xx+rr, yy+rr, rr, rr, 90, 180); | |
627 | m_MGLDC->fillEllipseArc(xx+ww-rr, yy+rr, rr, rr, 0, 90); | |
628 | m_MGLDC->fillEllipseArc(xx+rr, yy+hh-rr, rr, rr, 180, 270); | |
629 | m_MGLDC->fillEllipseArc(xx+ww-rr, yy+hh-rr, rr, rr, 270, 0); | |
630 | } | |
631 | ||
632 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
633 | { | |
634 | if ( !m_penSelected ) | |
635 | SelectPen(); | |
636 | xx += m_penOfsX; | |
637 | yy += m_penOfsY; | |
638 | m_MGLDC->line(xx+rr+1, yy, xx+ww-rr, yy); | |
639 | m_MGLDC->ellipseArc(xx+ww-rr, yy+rr, rr, rr, 0, 90); | |
640 | m_MGLDC->line(xx+ww, yy+rr+1, xx+ww, yy+hh-rr); | |
641 | m_MGLDC->ellipseArc(xx+ww-rr, yy+hh-rr, rr, rr, 270, 0); | |
642 | m_MGLDC->line(xx+ww-rr, yy+hh, xx+rr+1, yy+hh); | |
643 | m_MGLDC->ellipseArc(xx+rr, yy+hh-rr, rr, rr, 180, 270); | |
644 | m_MGLDC->line(xx, yy+hh-rr, xx, yy+rr+1); | |
645 | m_MGLDC->ellipseArc(xx+rr, yy+rr, rr, rr, 90, 180); | |
646 | } | |
647 | ||
648 | CalcBoundingBox(x, y); | |
649 | CalcBoundingBox(x + width, y + height); | |
650 | } | |
651 | ||
652 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
653 | { | |
654 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
655 | ||
656 | wxCoord x2 = (x+width); | |
657 | wxCoord y2 = (y+height); | |
658 | ||
659 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
660 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
661 | { | |
662 | if ( !m_brushSelected ) | |
663 | SelectBrush(); | |
664 | MGLRect rect(XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
665 | m_MGLDC->fillEllipse(rect); | |
666 | } | |
667 | ||
668 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
669 | { | |
670 | if ( !m_penSelected ) | |
671 | SelectPen(); | |
672 | MGLRect rect(XLOG2DEV(x) + m_penOfsX, YLOG2DEV(y) + m_penOfsY, | |
673 | XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY); | |
674 | m_MGLDC->ellipse(rect); | |
675 | } | |
676 | ||
677 | CalcBoundingBox(x, y); | |
678 | CalcBoundingBox(x2, y2); | |
679 | } | |
680 | ||
681 | void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
682 | { | |
683 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
684 | ||
685 | wxCoord x2 = (x+w); | |
686 | wxCoord y2 = (y+h); | |
687 | ||
688 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
689 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
690 | { | |
691 | if (!m_brushSelected) SelectBrush(); | |
692 | MGLRect rect(XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); | |
693 | m_MGLDC->fillEllipseArc(rect, (int)sa, (int)ea); | |
694 | } | |
695 | ||
696 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
697 | { | |
698 | if ( !m_penSelected ) | |
699 | SelectPen(); | |
700 | MGLRect rect(XLOG2DEV(x) + m_penOfsX, YLOG2DEV(y) + m_penOfsY, | |
701 | XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY); | |
702 | m_MGLDC->ellipseArc(rect, (int)sa, (int)ea); | |
703 | } | |
704 | ||
705 | CalcBoundingBox(x, y); | |
706 | CalcBoundingBox(x2, y2); | |
707 | } | |
708 | ||
709 | void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
710 | { | |
32b8ec41 VZ |
711 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 |
712 | DrawAnyText(text, x, y); | |
713 | ||
714 | // update the bounding box | |
715 | wxCoord w, h; | |
716 | CalcBoundingBox(x, y); | |
717 | GetTextExtent(text, &w, &h); | |
718 | CalcBoundingBox(x + w, y + h); | |
719 | } | |
720 | ||
721 | bool wxDC::SelectMGLFont() | |
722 | { | |
723 | if ( m_mglFont == NULL ) | |
724 | { | |
725 | float scale = m_scaleY; | |
726 | bool antialiased = (GetDepth() > 8); | |
727 | ||
728 | m_mglFont = m_font.GetMGLfont_t(scale, antialiased); | |
729 | wxCHECK_MSG( m_mglFont, FALSE, wxT("invalid font") ); | |
730 | ||
731 | m_MGLDC->useFont(m_mglFont); | |
732 | wxLogTrace("mgl_font", "useFont(%p)", m_mglFont); | |
733 | ||
734 | #if !wxUSE_UNICODE | |
735 | wxNativeEncodingInfo nativeEnc; | |
736 | wxFontEncoding encoding = m_font.GetEncoding(); | |
737 | if ( !wxGetNativeFontEncoding(encoding, &nativeEnc) || | |
738 | !wxTestFontEncoding(nativeEnc) ) | |
739 | { | |
740 | #if wxUSE_FONTMAP | |
741 | if ( !wxTheFontMapper->GetAltForEncoding(encoding, &nativeEnc) ) | |
742 | #endif | |
743 | { | |
744 | nativeEnc.mglEncoding = MGL_ENCODING_ASCII; | |
745 | } | |
746 | } | |
747 | m_MGLDC->setTextEncoding(nativeEnc.mglEncoding); | |
748 | #endif | |
749 | } | |
750 | return TRUE; | |
751 | } | |
752 | ||
753 | void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) | |
754 | { | |
755 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
756 | ||
757 | SelectMGLFont(); | |
758 | ||
32b8ec41 VZ |
759 | // Render the text: |
760 | wxCoord xx = XLOG2DEV(x); | |
761 | wxCoord yy = YLOG2DEV(y); | |
21a700f3 | 762 | |
32b8ec41 VZ |
763 | m_MGLDC->setLineStyle(MGL_LINE_STIPPLE); |
764 | m_MGLDC->setLineStipple(0xFFFF); | |
765 | m_MGLDC->setPenSize(1, 1); | |
766 | m_MGLDC->setPenStyle(MGL_BITMAP_SOLID); | |
21a700f3 | 767 | |
32b8ec41 VZ |
768 | #if wxUSE_UNICODE |
769 | const wchar_t *c_text = text.c_str(); | |
770 | #else | |
771 | const char *c_text = text.c_str(); | |
772 | #endif | |
21a700f3 VS |
773 | |
774 | #if 1 | |
775 | // FIXME_MGL - this is a temporary hack in absence of proper | |
776 | // implementation of solid text background in MGL. Once | |
777 | // the bug in MGL is fixed, this code should be nuked | |
778 | // immediately. Note that the code is not 100% correct; | |
779 | // it only works with wxCOPY logical function | |
780 | if ( m_backgroundMode == wxSOLID ) | |
781 | { | |
782 | int w = m_MGLDC->textWidth(c_text); | |
783 | int h = m_MGLDC->textHeight(); | |
784 | m_MGLDC->setColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), | |
785 | m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); | |
786 | m_MGLDC->fillRect(xx, yy, xx+w, yy+h); | |
787 | } | |
788 | #endif | |
789 | ||
790 | m_MGLDC->setColor(m_MGLDC->packColorFast(m_textForegroundColour.Red(), | |
791 | m_textForegroundColour.Green(), m_textForegroundColour.Blue())); | |
792 | m_MGLDC->setBackColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), | |
793 | m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); | |
794 | ||
32b8ec41 VZ |
795 | m_MGLDC->drawStr(xx, yy, c_text); |
796 | ||
797 | // Render underline: | |
798 | if ( m_font.GetUnderlined() ) | |
799 | { | |
800 | int x1 = xx, y1 = yy; | |
a4bbc9f7 | 801 | int x2 = 0 , y2 = 0; |
32b8ec41 VZ |
802 | int w = m_MGLDC->textWidth(c_text); |
803 | m_MGLDC->underScoreLocation(x1, y1, c_text); | |
804 | switch (m_MGLDC->getTextDirection()) | |
805 | { | |
806 | case MGL_RIGHT_DIR: x2 = x1 + w, y2 = y1; break; | |
807 | case MGL_LEFT_DIR: x2 = x1 - w, y2 = y1; break; | |
808 | case MGL_UP_DIR: x2 = x1, y2 = y1 - w; break; | |
809 | case MGL_DOWN_DIR: x2 = x1, y2 = y1 + w; break; | |
810 | } | |
811 | m_MGLDC->line(x1, y1, x2, y2); | |
812 | } | |
813 | ||
814 | m_penSelected = m_brushSelected = FALSE; | |
815 | } | |
816 | ||
817 | void wxDC::DoDrawRotatedText(const wxString& text, | |
818 | wxCoord x, wxCoord y, | |
819 | double angle) | |
820 | { | |
32b8ec41 VZ |
821 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 |
822 | ||
823 | if ( angle == 0 ) | |
824 | { | |
825 | DoDrawText(text, x, y); | |
826 | return; | |
827 | } | |
828 | else if ( angle == 90.0 ) | |
829 | m_MGLDC->setTextDirection(MGL_UP_DIR); | |
830 | else if ( angle == 180.0 ) | |
831 | m_MGLDC->setTextDirection(MGL_LEFT_DIR); | |
832 | else if ( angle == 270.0 ) | |
833 | m_MGLDC->setTextDirection(MGL_DOWN_DIR); | |
834 | else | |
835 | { | |
836 | // FIXME_MGL -- implement once MGL supports it | |
837 | wxFAIL_MSG(wxT("wxMGL only supports rotated text with angle 0,90,180 or 270")); | |
838 | return; | |
839 | } | |
840 | ||
841 | DrawAnyText(text, x, y); | |
842 | ||
843 | // Restore default: | |
844 | m_MGLDC->setTextDirection(MGL_RIGHT_DIR); | |
845 | } | |
846 | ||
847 | // --------------------------------------------------------------------------- | |
848 | // set GDI objects | |
849 | // --------------------------------------------------------------------------- | |
850 | ||
851 | void wxDC::SelectMGLStipplePen(int style) | |
852 | { | |
853 | ushort stipple; | |
854 | ||
855 | switch (style) | |
856 | { | |
857 | case wxDOT: stipple = STIPPLE_wxDOT; break; | |
858 | case wxLONG_DASH: stipple = STIPPLE_wxLONG_DASH; break; | |
859 | case wxSHORT_DASH: stipple = STIPPLE_wxSHORT_DASH; break; | |
860 | case wxDOT_DASH: stipple = STIPPLE_wxDOT_DASH; break; | |
861 | default: stipple = STIPPLE_wxSOLID; break; | |
862 | } | |
863 | ||
864 | m_MGLDC->setLineStyle(MGL_LINE_STIPPLE); | |
865 | m_MGLDC->setLineStipple(stipple); | |
866 | m_MGLDC->setPenSize(1, 1); | |
867 | m_MGLDC->setPenStyle(MGL_BITMAP_SOLID); | |
868 | m_penOfsY = m_penOfsX = 0; | |
869 | } | |
870 | ||
871 | // Accepted valus of SelectMGLFatPen's 2nd argument | |
872 | enum { | |
873 | wxMGL_SELECT_FROM_PEN, | |
874 | wxMGL_SELECT_FROM_BRUSH | |
875 | }; | |
876 | ||
877 | void wxDC::SelectMGLFatPen(int style, int flag) | |
878 | { | |
879 | MGL_penStyleType penstyle; | |
880 | const pattern_t *pattern = NULL; | |
881 | pixpattern24_t *pixPattern = NULL; | |
882 | int wx, wy; | |
883 | int slot; | |
884 | ||
885 | // Since MGL pens may be created from wxBrush or wxPen and we often | |
886 | // switch between pens and brushes, we take advantage of MGL's ability | |
887 | // to have multiple (pix)pattern_t's loaded. We always download pen | |
888 | // to 0th slot and brush to 1st slot. | |
889 | if ( flag == wxMGL_SELECT_FROM_PEN ) | |
890 | slot = 0; | |
891 | else | |
892 | slot = 1; | |
893 | ||
894 | // compute pen's width: | |
895 | if ( m_pen.GetWidth() <= 1 ) | |
896 | { | |
897 | wx = wy = 1; | |
898 | m_penOfsX = m_penOfsY = 0; | |
899 | } | |
900 | else | |
901 | { | |
902 | wx = (int)(0.5 + fabs((double) XLOG2DEVREL(m_pen.GetWidth()))); | |
903 | wy = (int)(0.5 + fabs((double) YLOG2DEVREL(m_pen.GetWidth()))); | |
904 | m_penOfsX = -wx/2; | |
905 | m_penOfsY = -wy/2; | |
906 | } | |
907 | ||
908 | // find pen's type: | |
909 | penstyle = MGL_BITMAP_TRANSPARENT; | |
910 | switch (style) | |
911 | { | |
912 | case wxBDIAGONAL_HATCH: pattern = &PATTERN_wxBDIAGONAL_HATCH; | |
913 | penstyle = MGL_BITMAP_TRANSPARENT; | |
914 | break; | |
915 | case wxCROSSDIAG_HATCH: pattern = &PATTERN_wxCROSSDIAG_HATCH; | |
916 | penstyle = MGL_BITMAP_TRANSPARENT; | |
917 | break; | |
918 | case wxFDIAGONAL_HATCH: pattern = &PATTERN_wxFDIAGONAL_HATCH; | |
919 | penstyle = MGL_BITMAP_TRANSPARENT; | |
920 | break; | |
921 | case wxCROSS_HATCH: pattern = &PATTERN_wxCROSS_HATCH; | |
922 | penstyle = MGL_BITMAP_TRANSPARENT; | |
923 | break; | |
924 | case wxHORIZONTAL_HATCH: pattern = &PATTERN_wxHORIZONTAL_HATCH; | |
925 | penstyle = MGL_BITMAP_TRANSPARENT; | |
926 | break; | |
927 | case wxVERTICAL_HATCH: pattern = &PATTERN_wxVERTICAL_HATCH; | |
928 | penstyle = MGL_BITMAP_TRANSPARENT; | |
929 | break; | |
930 | ||
931 | case wxSTIPPLE: | |
932 | if ( flag == wxMGL_SELECT_FROM_PEN ) | |
933 | pixPattern = (pixpattern24_t*) m_pen.GetPixPattern(); | |
934 | else | |
935 | pixPattern = (pixpattern24_t*) m_brush.GetPixPattern(); | |
936 | penstyle = MGL_PIXMAP; | |
937 | break; | |
938 | ||
939 | case wxSTIPPLE_MASK_OPAQUE: | |
940 | pattern = (pattern_t*) m_brush.GetMaskPattern(); | |
941 | penstyle = MGL_BITMAP_OPAQUE; | |
942 | break; | |
943 | ||
944 | case wxSOLID: | |
945 | default: | |
946 | penstyle = MGL_BITMAP_SOLID; break; | |
947 | } | |
948 | ||
949 | // ...and finally, pass the pen to MGL: | |
950 | ||
951 | if ( pattern ) | |
952 | { | |
953 | if ( !m_downloadedPatterns[slot] ) | |
954 | { | |
955 | m_MGLDC->setPenBitmapPattern(slot, pattern); | |
956 | m_downloadedPatterns[slot] = TRUE; | |
957 | } | |
958 | m_MGLDC->usePenBitmapPattern(slot); | |
959 | } | |
960 | ||
961 | if ( pixPattern ) | |
962 | { | |
963 | if ( !m_downloadedPatterns[slot] ) | |
964 | { | |
965 | pixpattern_t pix; | |
966 | int x, y, c; | |
967 | ||
968 | switch (GetDepth()) | |
969 | { | |
970 | case 8: | |
971 | for (y = 0; y < 8; y++) | |
972 | for (x = 0; x < 8; x++) | |
973 | pix.b8.p[x][y] = m_MGLDC->packColorFast( | |
974 | pixPattern->p[x][y][0], | |
975 | pixPattern->p[x][y][1], | |
976 | pixPattern->p[x][y][2]); | |
977 | break; | |
978 | case 15: | |
979 | case 16: | |
980 | for (y = 0; y < 8; y++) | |
981 | for (x = 0; x < 8; x++) | |
982 | pix.b16.p[x][y] = m_MGLDC->packColorFast( | |
983 | pixPattern->p[x][y][0], | |
984 | pixPattern->p[x][y][1], | |
985 | pixPattern->p[x][y][2]); | |
986 | break; | |
987 | case 24: | |
988 | for (y = 0; y < 8; y++) | |
989 | for (x = 0; x < 8; x++) | |
990 | for (c = 0; c < 3; c++) | |
991 | pix.b24.p[x][y][c] = pixPattern->p[x][y][c]; | |
992 | break; | |
993 | case 32: | |
994 | for (y = 0; y < 8; y++) | |
995 | for (x = 0; x < 8; x++) | |
996 | pix.b32.p[x][y] = m_MGLDC->packColorFast( | |
997 | pixPattern->p[x][y][0], | |
998 | pixPattern->p[x][y][1], | |
999 | pixPattern->p[x][y][2]); | |
1000 | break; | |
1001 | default: | |
1002 | wxFAIL_MSG(_T("invalid DC depth")); | |
1003 | break; | |
1004 | } | |
1005 | m_MGLDC->setPenPixmapPattern(slot, &pix); | |
1006 | m_downloadedPatterns[slot] = TRUE; | |
1007 | } | |
1008 | m_MGLDC->usePenPixmapPattern(slot); | |
1009 | } | |
1010 | ||
1011 | m_MGLDC->setLineStyle(MGL_LINE_PENSTYLE); | |
1012 | m_MGLDC->setPenStyle(penstyle); | |
1013 | m_MGLDC->setPenSize(wy, wx); | |
1014 | } | |
1015 | ||
1016 | void wxDC::SelectPen() | |
1017 | { | |
1018 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1019 | ||
1020 | wxColour& clr = m_pen.GetColour(); | |
1021 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1022 | m_MGLDC->setColorRGB(clr.Red(), clr.Green(), clr.Blue()); | |
1023 | ||
1024 | switch (m_pen.GetStyle()) | |
1025 | { | |
1026 | case wxTRANSPARENT: | |
1027 | break; | |
1028 | ||
1029 | case wxDOT: | |
1030 | case wxLONG_DASH: | |
1031 | case wxSHORT_DASH: | |
1032 | case wxDOT_DASH: | |
1033 | SelectMGLStipplePen(m_pen.GetStyle()); | |
1034 | break; | |
1035 | ||
1036 | case wxBDIAGONAL_HATCH: | |
1037 | case wxCROSSDIAG_HATCH: | |
1038 | case wxFDIAGONAL_HATCH: | |
1039 | case wxCROSS_HATCH: | |
1040 | case wxHORIZONTAL_HATCH: | |
1041 | case wxVERTICAL_HATCH: | |
1042 | SelectMGLFatPen(m_pen.GetStyle(), wxMGL_SELECT_FROM_PEN); | |
1043 | break; | |
1044 | ||
1045 | case wxSTIPPLE: | |
1046 | SelectMGLFatPen(m_pen.GetStyle(), wxMGL_SELECT_FROM_PEN); | |
1047 | break; | |
1048 | ||
1049 | case wxSOLID: | |
1050 | case wxUSER_DASH: | |
1051 | default: | |
1052 | if ( m_pen.GetWidth() <= 1 ) | |
1053 | SelectMGLStipplePen(wxSOLID); | |
1054 | else | |
1055 | SelectMGLFatPen(wxSOLID, wxMGL_SELECT_FROM_PEN); | |
1056 | break; | |
1057 | } | |
1058 | m_penSelected = TRUE; | |
1059 | m_brushSelected = FALSE; | |
1060 | } | |
1061 | ||
1062 | void wxDC::SelectBrush() | |
1063 | { | |
1064 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1065 | ||
1066 | wxColour fg, bg; | |
1067 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1068 | ||
1069 | if ( m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) | |
1070 | { | |
1071 | fg = m_textForegroundColour; | |
1072 | bg = m_textBackgroundColour; | |
1073 | } | |
1074 | else | |
1075 | { | |
1076 | fg = m_brush.GetColour(); | |
1077 | bg = m_backgroundBrush.GetColour(); | |
1078 | } | |
1079 | ||
1080 | m_MGLDC->setColorRGB(fg.Red(), fg.Green(), fg.Blue()); | |
1081 | m_MGLDC->setBackColor(m_MGLDC->packColorFast(bg.Red(), bg.Green(), bg.Blue())); | |
1082 | m_penSelected = FALSE; | |
1083 | m_brushSelected = TRUE; | |
1084 | ||
1085 | SelectMGLFatPen(m_brush.GetStyle(), wxMGL_SELECT_FROM_BRUSH); | |
1086 | } | |
1087 | ||
1088 | void wxDC::SetPen(const wxPen& pen) | |
1089 | { | |
1090 | if ( !pen.Ok() ) return; | |
1091 | if ( m_pen == pen ) return; | |
1092 | m_pen = pen; | |
1093 | m_penSelected = FALSE; | |
1094 | m_downloadedPatterns[0] = FALSE; | |
1095 | } | |
1096 | ||
1097 | void wxDC::SetBrush(const wxBrush& brush) | |
1098 | { | |
1099 | if ( !brush.Ok() ) return; | |
1100 | if ( m_brush == brush ) return; | |
1101 | m_brush = brush; | |
1102 | m_brushSelected = FALSE; | |
1103 | m_downloadedPatterns[1] = FALSE; | |
1104 | } | |
1105 | ||
1106 | void wxDC::SetPalette(const wxPalette& palette) | |
1107 | { | |
1108 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1109 | ||
1110 | if ( palette == wxNullPalette ) | |
1111 | { | |
ac4de069 VS |
1112 | if ( m_oldPalette.Ok() ) |
1113 | SetPalette(m_oldPalette); | |
32b8ec41 VZ |
1114 | return; |
1115 | } | |
1116 | ||
1117 | if ( !palette.Ok() ) return; | |
1118 | if ( m_palette == palette ) return; | |
1119 | m_oldPalette = m_palette; | |
1120 | m_palette = palette; | |
1121 | ||
1122 | int cnt = m_palette.GetColoursCount(); | |
1123 | palette_t *pal = m_palette.GetMGLpalette_t(); | |
1124 | m_MGLDC->setPalette(pal, cnt, 0); | |
1125 | m_MGLDC->realizePalette(cnt, 0, TRUE); | |
1126 | } | |
1127 | ||
1128 | void wxDC::SetFont(const wxFont& font) | |
1129 | { | |
31e39e3c VS |
1130 | if ( font.Ok() ) |
1131 | { | |
1132 | m_font = font; | |
1133 | m_mglFont = NULL; | |
1134 | } | |
32b8ec41 VZ |
1135 | } |
1136 | ||
1137 | void wxDC::SetBackground(const wxBrush& brush) | |
1138 | { | |
1139 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1140 | ||
1141 | if (!m_backgroundBrush.Ok()) return; | |
1142 | ||
1143 | m_backgroundBrush = brush; | |
1144 | wxColour &clr = m_backgroundBrush.GetColour(); | |
1145 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1146 | m_MGLDC->setBackColor( | |
1147 | m_MGLDC->packColorFast(clr.Red(), clr.Green(), clr.Blue())); | |
1148 | } | |
1149 | ||
1150 | void wxDC::SetBackgroundMode(int mode) | |
1151 | { | |
1152 | m_backgroundMode = mode; | |
1153 | if ( mode == wxSOLID ) | |
1154 | m_MGLDC->setBackMode(MGL_OPAQUE_BACKGROUND); | |
1155 | else | |
1156 | m_MGLDC->setBackMode(MGL_TRANSPARENT_BACKGROUND); | |
1157 | } | |
1158 | ||
1159 | void wxDC::SetLogicalFunction(int function) | |
1160 | { | |
1161 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1162 | ||
1163 | m_logicalFunction = function; | |
1164 | ||
1165 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1166 | m_MGLDC->setWriteMode(LogicalFunctionToMGLRop(m_logicalFunction)); | |
1167 | } | |
1168 | ||
1169 | int wxDC::LogicalFunctionToMGLRop(int logFunc) const | |
1170 | { | |
1171 | MGL_writeModeType rop; | |
1172 | ||
1173 | switch (logFunc) | |
1174 | { | |
1175 | case wxCLEAR: rop = MGL_R2_BLACK; break; | |
1176 | case wxXOR: rop = MGL_R2_XORSRC; break; | |
1177 | case wxINVERT: rop = MGL_R2_NOT; break; | |
1178 | case wxOR_REVERSE: rop = MGL_R2_MERGESRCNOT; break; | |
1179 | case wxAND_REVERSE: rop = MGL_R2_MASKSRCNOT; break; | |
1180 | case wxCOPY: rop = MGL_R2_COPYSRC; break; | |
1181 | case wxAND: rop = MGL_R2_MASKSRC; break; | |
1182 | case wxAND_INVERT: rop = MGL_R2_MASKNOTSRC; break; | |
1183 | case wxNO_OP: rop = MGL_R2_NOP; break; | |
1184 | case wxNOR: rop = MGL_R2_NOTMERGESRC; break; | |
1185 | case wxEQUIV: rop = MGL_R2_NOTXORSRC; break; | |
1186 | case wxSRC_INVERT: rop = MGL_R2_NOTCOPYSRC; break; | |
1187 | case wxOR_INVERT: rop = MGL_R2_MERGENOTSRC; break; | |
1188 | case wxNAND: rop = MGL_R2_NOTMASKSRC; break; | |
1189 | case wxOR: rop = MGL_R2_MERGESRC; break; | |
1190 | case wxSET: rop = MGL_R2_WHITE; break; | |
1191 | default: | |
1192 | wxFAIL_MSG( wxT("unsupported logical function") ); | |
1193 | return MGL_REPLACE_MODE; | |
1194 | } | |
1195 | return (int)rop; | |
1196 | } | |
1197 | ||
1198 | bool wxDC::StartDoc(const wxString& message) | |
1199 | { | |
1200 | // We might be previewing, so return TRUE to let it continue. | |
1201 | return TRUE; | |
1202 | } | |
1203 | ||
1204 | void wxDC::EndDoc() | |
1205 | { | |
1206 | } | |
1207 | ||
1208 | void wxDC::StartPage() | |
1209 | { | |
1210 | } | |
1211 | ||
1212 | void wxDC::EndPage() | |
1213 | { | |
1214 | } | |
1215 | ||
1216 | // --------------------------------------------------------------------------- | |
1217 | // text metrics | |
1218 | // --------------------------------------------------------------------------- | |
1219 | ||
1220 | wxCoord wxDC::GetCharHeight() const | |
1221 | { | |
1222 | wxCurrentDCSwitcher switcher(m_MGLDC); | |
1223 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return -1; | |
1224 | return YDEV2LOGREL(m_mglFont->fontHeight); | |
1225 | } | |
1226 | ||
1227 | wxCoord wxDC::GetCharWidth() const | |
1228 | { | |
1229 | wxCurrentDCSwitcher switcher(m_MGLDC); | |
1230 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return -1; | |
1231 | // VS: wxT() is intentional, charWidth() has both char and wchar_t version | |
1232 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are only | |
1233 | // scaled according to m_scaleY | |
1234 | return YDEV2LOGREL(m_mglFont->fontWidth); | |
1235 | } | |
1236 | ||
1237 | void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, | |
1238 | wxCoord *descent, wxCoord *externalLeading, | |
1239 | wxFont *theFont) const | |
1240 | { | |
1241 | wxFont oldFont; | |
1242 | ||
1243 | if ( theFont != NULL ) | |
1244 | { | |
1245 | oldFont = m_font; | |
1246 | wxConstCast(this, wxDC)->SetFont(*theFont); | |
1247 | } | |
1248 | ||
1249 | wxCurrentDCSwitcher switcher(m_MGLDC); | |
1250 | if ( !wxConstCast(this, wxDC)->SelectMGLFont() ) return; | |
1251 | ||
1252 | if ( x ) | |
1253 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are | |
1254 | // only scaled according to m_scaleY | |
1255 | *x = YDEV2LOGREL(m_MGLDC->textWidth(string.c_str())); | |
1256 | if ( y ) | |
1257 | *y = YDEV2LOGREL(m_MGLDC->textHeight()); | |
1258 | if ( descent ) | |
1259 | *descent = YDEV2LOGREL(m_mglFont->descent); | |
1260 | if ( externalLeading ) | |
1261 | *externalLeading = YDEV2LOGREL(m_mglFont->leading); | |
a46935cb | 1262 | |
32b8ec41 VZ |
1263 | if ( theFont != NULL ) |
1264 | wxConstCast(this, wxDC)->SetFont(oldFont); | |
1265 | } | |
1266 | ||
1267 | ||
1268 | ||
1269 | // --------------------------------------------------------------------------- | |
1270 | // mapping modes | |
1271 | // --------------------------------------------------------------------------- | |
1272 | ||
1273 | void wxDC::ComputeScaleAndOrigin() | |
1274 | { | |
1275 | double newX = m_logicalScaleX * m_userScaleX; | |
1276 | double newY = m_logicalScaleY * m_userScaleY; | |
1277 | ||
1278 | // make sure font will be reloaded before drawing: | |
1279 | if ( newY != m_scaleY ) | |
1280 | m_mglFont = NULL; | |
1281 | // make sure m_penOfs{X,Y} will be reevaluated before drawing: | |
1282 | if ( newY != m_scaleY || newX != m_scaleX ) | |
1283 | m_penSelected = FALSE; | |
1284 | ||
1285 | m_scaleX = newX, m_scaleY = newY; | |
1286 | } | |
1287 | ||
1288 | void wxDC::SetMapMode(int mode) | |
1289 | { | |
1290 | switch (mode) | |
1291 | { | |
1292 | case wxMM_TWIPS: | |
1293 | SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); | |
1294 | break; | |
1295 | case wxMM_POINTS: | |
1296 | SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); | |
1297 | break; | |
1298 | case wxMM_METRIC: | |
1299 | SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); | |
1300 | break; | |
1301 | case wxMM_LOMETRIC: | |
1302 | SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); | |
1303 | break; | |
1304 | default: | |
1305 | case wxMM_TEXT: | |
1306 | SetLogicalScale(1.0, 1.0); | |
1307 | break; | |
1308 | } | |
1309 | m_mappingMode = mode; | |
1310 | } | |
1311 | ||
1312 | void wxDC::SetUserScale( double x, double y ) | |
1313 | { | |
1314 | // allow negative ? -> no | |
1315 | m_userScaleX = x; | |
1316 | m_userScaleY = y; | |
1317 | ComputeScaleAndOrigin(); | |
1318 | } | |
1319 | ||
1320 | void wxDC::SetLogicalScale( double x, double y ) | |
1321 | { | |
1322 | // allow negative ? | |
1323 | m_logicalScaleX = x; | |
1324 | m_logicalScaleY = y; | |
1325 | ComputeScaleAndOrigin(); | |
1326 | } | |
1327 | ||
1328 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
1329 | { | |
1330 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
1331 | m_logicalOriginY = y * m_signY; | |
1332 | ComputeScaleAndOrigin(); | |
1333 | } | |
1334 | ||
1335 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
1336 | { | |
1337 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
1338 | m_deviceOriginX = x; | |
1339 | m_deviceOriginY = y; | |
1340 | ComputeScaleAndOrigin(); | |
1341 | } | |
1342 | ||
1343 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
1344 | { | |
1345 | // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there | |
1346 | m_signX = (xLeftRight ? 1 : -1); | |
1347 | m_signY = (yBottomUp ? -1 : 1); | |
1348 | ComputeScaleAndOrigin(); | |
1349 | } | |
1350 | ||
1351 | // --------------------------------------------------------------------------- | |
1352 | // coordinates transformations | |
1353 | // --------------------------------------------------------------------------- | |
1354 | ||
1355 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
1356 | { | |
1357 | return ((wxDC *)this)->XDEV2LOG(x); | |
1358 | } | |
1359 | ||
1360 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
1361 | { | |
1362 | return ((wxDC *)this)->YDEV2LOG(y); | |
1363 | } | |
1364 | ||
1365 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
1366 | { | |
1367 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
1368 | } | |
1369 | ||
1370 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
1371 | { | |
1372 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
1373 | } | |
1374 | ||
1375 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
1376 | { | |
1377 | return ((wxDC *)this)->XLOG2DEV(x); | |
1378 | } | |
1379 | ||
1380 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
1381 | { | |
1382 | return ((wxDC *)this)->YLOG2DEV(y); | |
1383 | } | |
1384 | ||
1385 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
1386 | { | |
1387 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
1388 | } | |
1389 | ||
1390 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
1391 | { | |
1392 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
1393 | } | |
1394 | ||
1395 | ||
1396 | void wxDC::DoGetSize(int *w, int *h) const | |
1397 | { | |
b8c0528d VS |
1398 | if (w) *w = m_MGLDC->sizex()+1; |
1399 | if (h) *h = m_MGLDC->sizey()+1; | |
32b8ec41 VZ |
1400 | } |
1401 | ||
1402 | void wxDC::DoGetSizeMM(int *width, int *height) const | |
1403 | { | |
1404 | int w = 0; | |
1405 | int h = 0; | |
1406 | GetSize(&w, &h); | |
1407 | if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x)); | |
1408 | if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y)); | |
1409 | } | |
1410 | ||
1411 | wxSize wxDC::GetPPI() const | |
1412 | { | |
1413 | return wxSize(int(double(m_mm_to_pix_x) * inches2mm), | |
1414 | int(double(m_mm_to_pix_y) * inches2mm)); | |
1415 | } | |
1416 | ||
1417 | ||
1418 | // --------------------------------------------------------------------------- | |
1419 | // Blitting | |
1420 | // --------------------------------------------------------------------------- | |
1421 | ||
1422 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, | |
1423 | wxCoord width, wxCoord height, | |
1424 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
0cbff120 JS |
1425 | int rop, bool useMask, |
1426 | wxCoord xsrcMask, wxCoord ysrcMask) | |
32b8ec41 VZ |
1427 | { |
1428 | wxCHECK_MSG( Ok(), FALSE, wxT("invalid dc") ); | |
1429 | wxCHECK_MSG( source, FALSE, wxT("invalid source dc") ); | |
1430 | ||
1431 | // transform the source DC coords to the device ones | |
1432 | xsrc = source->LogicalToDeviceX(xsrc); | |
1433 | ysrc = source->LogicalToDeviceY(ysrc); | |
1434 | ||
a4bbc9f7 | 1435 | /* FIXME_MGL: use the mask origin when drawing transparently */ |
0cbff120 JS |
1436 | if (xsrcMask == -1 && ysrcMask == -1) |
1437 | { | |
1438 | xsrcMask = xsrc; ysrcMask = ysrc; | |
1439 | } | |
1440 | else | |
1441 | { | |
1442 | xsrcMask = source->LogicalToDeviceX(xsrcMask); | |
1443 | ysrcMask = source->LogicalToDeviceY(ysrcMask); | |
1444 | } | |
1445 | ||
32b8ec41 VZ |
1446 | CalcBoundingBox(xdest, ydest); |
1447 | CalcBoundingBox(xdest + width, ydest + height); | |
1448 | ||
1449 | /* scale/translate size and position */ | |
1450 | wxCoord xx = XLOG2DEV(xdest); | |
1451 | wxCoord yy = YLOG2DEV(ydest); | |
1452 | wxCoord ww = XLOG2DEVREL(width); | |
1453 | wxCoord hh = YLOG2DEVREL(height); | |
1454 | ||
1455 | if ( source->m_isMemDC ) | |
1456 | { | |
1457 | wxMemoryDC *memDC = (wxMemoryDC*) source; | |
1458 | DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh, | |
1459 | xdest, ydest, rop, useMask); | |
1460 | } | |
1461 | else | |
1462 | { | |
1463 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1464 | m_MGLDC->bitBlt(*source->GetMGLDC(), | |
1465 | xsrc, ysrc, xsrc + ww, ysrc + hh, | |
1466 | xx, yy, LogicalFunctionToMGLRop(rop)); | |
1467 | } | |
1468 | ||
1469 | return TRUE; | |
1470 | } | |
1471 | ||
1472 | void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) | |
1473 | { | |
1474 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1475 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
1476 | ||
1477 | wxCoord w = bmp.GetWidth(); | |
1478 | wxCoord h = bmp.GetHeight(); | |
1479 | ||
1480 | DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask); | |
1481 | } | |
1482 | ||
1483 | void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
1484 | { | |
1485 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why | |
1486 | DoDrawBitmap((const wxBitmap&)icon, x, y, (bool)TRUE); | |
1487 | } | |
1488 | ||
1489 | ||
1490 | static inline void DoBitBlt(const wxBitmap& src, MGLDevCtx *dst, | |
1491 | int sx, int sy, int sw, int sh, | |
1492 | int dx, int dy, int dw, int dh, | |
1493 | int rop, bool useStretching, bool putSection) | |
1494 | { | |
1495 | bitmap_t *bmp = src.GetMGLbitmap_t(); | |
1496 | if (!useStretching) | |
1497 | { | |
1498 | if (!putSection) | |
1499 | dst->putBitmap(dx, dy, bmp, rop); | |
1500 | else | |
1501 | dst->putBitmapSection(sx, sy, sx + sw, sy + sh, dx, dy, bmp, rop); | |
1502 | } | |
1503 | else | |
1504 | { | |
1505 | if (!putSection) | |
1506 | dst->stretchBitmap(dx, dy, dx + dw, dy + dh, bmp, rop); | |
1507 | else | |
1508 | dst->stretchBitmapSection(sx, sy, sx + sw, sy + sh, | |
1509 | dx, dy, dx + dw, dy + dh, bmp, rop); | |
1510 | } | |
1511 | } | |
1512 | ||
1513 | void wxDC::DoDrawSubBitmap(const wxBitmap &bmp, | |
1514 | wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
1515 | wxCoord destx, wxCoord desty, int rop, bool useMask) | |
1516 | { | |
1517 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
1518 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
1519 | ||
1520 | CalcBoundingBox(x, y); | |
1521 | CalcBoundingBox(x + w, y + h); | |
1522 | ||
1523 | wxCoord dx = XLOG2DEV(destx); | |
1524 | wxCoord dy = YLOG2DEV(desty); | |
1525 | wxCoord dw = XLOG2DEVREL(w); | |
1526 | wxCoord dh = YLOG2DEVREL(h); | |
1527 | ||
1528 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
1529 | ||
1530 | bool useStretching = ((w != dw) || (h != dh)); | |
1531 | bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight()); | |
1532 | MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop); | |
1533 | ||
1534 | if ( bmp.GetDepth() == 1 ) | |
1535 | { | |
1536 | // Mono bitmaps are handled in special way -- all 1s are drawn in | |
1537 | // foreground colours, all 0s in background colour. | |
1538 | ||
1539 | ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour); | |
1540 | } | |
1541 | ||
1542 | if ( useMask && bmp.GetMask() ) | |
1543 | { | |
1544 | // Since MGL does not support masks directly (in MGL, mask is handled | |
1545 | // in same way as in wxImage, i.e. there is one "key" color), we | |
1546 | // simulate masked bitblt in 6 steps (same as in MSW): | |
1547 | // | |
1548 | // 1. Create a temporary bitmap and copy the destination area into it. | |
1549 | // 2. Copy the source area into the temporary bitmap using the | |
1550 | // specified logical function. | |
1551 | // 3. Set the masked area in the temporary bitmap to BLACK by ANDing | |
1552 | // the mask bitmap with the temp bitmap with the foreground colour | |
1553 | // set to WHITE and the bg colour set to BLACK. | |
1554 | // 4. Set the unmasked area in the destination area to BLACK by | |
1555 | // ANDing the mask bitmap with the destination area with the | |
1556 | // foreground colour set to BLACK and the background colour set | |
1557 | // to WHITE. | |
1558 | // 5. OR the temporary bitmap with the destination area. | |
1559 | // 6. Delete the temporary bitmap. | |
1560 | // | |
1561 | // This sequence of operations ensures that the source's transparent | |
1562 | // area need not be black, and logical functions are supported. | |
1563 | ||
1564 | wxBitmap *mask = bmp.GetMask()->GetBitmap(); | |
1565 | ||
1566 | MGLMemoryDC *temp; | |
1567 | ||
1568 | if ( GetDepth() <= 8 ) | |
1569 | { | |
1570 | temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL); | |
1571 | wxDC tempdc; | |
1572 | tempdc.SetMGLDC(temp, FALSE); | |
1573 | tempdc.SetPalette(m_palette); | |
1574 | } | |
1575 | else | |
1576 | { | |
1577 | pixel_format_t pf; | |
1578 | m_MGLDC->getPixelFormat(pf); | |
1579 | temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf); | |
1580 | } | |
1581 | ||
1582 | wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") ); | |
1583 | ||
1584 | temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE); | |
1585 | ||
1586 | DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop, | |
1587 | useStretching, putSection); | |
1588 | ||
1589 | mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255)); | |
1590 | DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC, | |
1591 | useStretching, putSection); | |
1592 | DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC, | |
1593 | useStretching, putSection); | |
1594 | ||
1595 | m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE); | |
1596 | ||
1597 | delete temp; | |
1598 | } | |
1599 | ||
1600 | else | |
1601 | { | |
1602 | DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop, | |
1603 | useStretching, putSection); | |
1604 | } | |
1605 | } |