]>
Commit | Line | Data |
---|---|---|
b3c86150 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/dfb/dc.cpp | |
3 | // Purpose: wxDC class | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2006-08-07 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // =========================================================================== | |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | // For compilers that support precompilation, includes "wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/dc.h" | |
28 | #include "wx/log.h" | |
29 | #endif | |
30 | ||
31 | #include "wx/dfb/private.h" | |
32 | ||
071f5576 VS |
33 | // these values are used to initialize newly created DC |
34 | #define DEFAULT_FONT (*wxNORMAL_FONT) | |
35 | #define DEFAULT_PEN (*wxBLACK_PEN) | |
36 | #define DEFAULT_BRUSH (*wxWHITE_BRUSH) | |
37 | ||
b3c86150 VS |
38 | // =========================================================================== |
39 | // implementation | |
40 | // =========================================================================== | |
41 | ||
42 | //----------------------------------------------------------------------------- | |
43 | // wxDC | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) | |
47 | ||
48 | // Default constructor | |
49 | wxDC::wxDC() | |
50 | { | |
51 | m_ok = false; | |
52 | } | |
53 | ||
52c8d32a | 54 | wxDC::wxDC(const wxIDirectFBSurfacePtr& surface) |
b3c86150 VS |
55 | { |
56 | Init(surface); | |
57 | } | |
58 | ||
52c8d32a | 59 | void wxDC::Init(const wxIDirectFBSurfacePtr& surface) |
b3c86150 VS |
60 | { |
61 | m_ok = (surface != NULL); | |
62 | wxCHECK_RET( surface != NULL, _T("invalid surface") ); | |
63 | ||
64 | m_surface = surface; | |
65 | ||
66 | m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / | |
67 | (double)wxGetDisplaySizeMM().GetWidth(); | |
68 | m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / | |
69 | (double)wxGetDisplaySizeMM().GetHeight(); | |
70 | ||
071f5576 VS |
71 | SetFont(DEFAULT_FONT); |
72 | SetPen(DEFAULT_PEN); | |
73 | SetBrush(DEFAULT_BRUSH); | |
b3c86150 VS |
74 | } |
75 | ||
76 | ||
77 | // --------------------------------------------------------------------------- | |
78 | // clipping | |
79 | // --------------------------------------------------------------------------- | |
80 | ||
81 | ||
82 | #define DO_SET_CLIPPING_BOX(rg) \ | |
83 | { \ | |
84 | wxRect rect = rg.GetBox(); \ | |
85 | m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \ | |
86 | m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \ | |
87 | m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \ | |
88 | m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \ | |
89 | } | |
90 | ||
91 | void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) | |
92 | { | |
93 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
94 | ||
95 | DFBRegion r; | |
96 | r.x1 = XLOG2DEV(cx); | |
97 | r.y1 = YLOG2DEV(cy); | |
98 | r.x2 = r.x1 + XLOG2DEVREL(cw) - 1; | |
99 | r.y2 = r.y1 + XLOG2DEVREL(ch) - 1; | |
100 | ||
52c8d32a | 101 | if ( !m_surface->SetClip(&r) ) |
b3c86150 VS |
102 | return; |
103 | ||
104 | m_clipX1 = cx; | |
105 | m_clipY1 = cy; | |
106 | m_clipX2 = cx + cw - 1; | |
107 | m_clipY2 = cy + ch -1; | |
108 | m_clipping = true; | |
109 | } | |
110 | ||
111 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) | |
112 | { | |
113 | // NB: this can be done because wxDFB only supports | |
114 | // rectangular regions | |
115 | SetClippingRegion(region.AsRect()); | |
116 | } | |
117 | ||
118 | void wxDC::DestroyClippingRegion() | |
119 | { | |
120 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
121 | ||
52c8d32a | 122 | m_surface->SetClip(NULL); |
b3c86150 VS |
123 | |
124 | ResetClipping(); | |
125 | } | |
126 | ||
127 | // --------------------------------------------------------------------------- | |
128 | // query capabilities | |
129 | // --------------------------------------------------------------------------- | |
130 | ||
131 | int wxDC::GetDepth() const | |
132 | { | |
133 | return wxDfbGetSurfaceDepth(m_surface); | |
134 | } | |
135 | ||
136 | // --------------------------------------------------------------------------- | |
137 | // drawing | |
138 | // --------------------------------------------------------------------------- | |
139 | ||
140 | void wxDC::Clear() | |
141 | { | |
142 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
143 | ||
144 | if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT ) | |
145 | return; | |
146 | ||
147 | wxColour clr = m_backgroundBrush.GetColour(); | |
52c8d32a | 148 | m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()); |
b3c86150 VS |
149 | } |
150 | ||
151 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
152 | const wxColour & col, int style); | |
153 | ||
154 | bool wxDC::DoFloodFill(wxCoord x, wxCoord y, | |
155 | const wxColour& col, int style) | |
156 | { | |
157 | return wxDoFloodFill(this, x, y, col, style); | |
158 | } | |
159 | ||
160 | bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
161 | { | |
162 | wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel")); | |
163 | ||
164 | wxFAIL_MSG( _T("GetPixel not implemented") ); | |
165 | return false; | |
166 | } | |
167 | ||
168 | void wxDC::DoCrossHair(wxCoord x, wxCoord y) | |
169 | { | |
170 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
171 | ||
172 | wxFAIL_MSG( _T("CrossHair not implemented") ); | |
173 | } | |
174 | ||
175 | void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
176 | { | |
177 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
178 | ||
179 | if ( m_pen.GetStyle() == wxTRANSPARENT ) | |
180 | return; | |
181 | ||
52c8d32a VS |
182 | m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1), |
183 | XLOG2DEV(x2), YLOG2DEV(y2)); | |
b3c86150 VS |
184 | |
185 | CalcBoundingBox(x1, y1); | |
186 | CalcBoundingBox(x2, y2); | |
187 | } | |
188 | ||
189 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
190 | // and ending at (x2, y2) | |
191 | void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, | |
192 | wxCoord x2, wxCoord y2, | |
193 | wxCoord xc, wxCoord yc) | |
194 | { | |
195 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
196 | ||
197 | wxFAIL_MSG( _T("DrawArc not implemented") ); | |
198 | } | |
199 | ||
200 | void wxDC::DoDrawPoint(wxCoord x, wxCoord y) | |
201 | { | |
202 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
203 | ||
204 | wxFAIL_MSG( _T("DrawPoint not implemented") ); | |
205 | } | |
206 | ||
207 | void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle)) | |
208 | { | |
209 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
210 | ||
211 | wxFAIL_MSG( _T("DrawPolygon not implemented") ); | |
212 | } | |
213 | ||
214 | void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
215 | { | |
216 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
217 | ||
218 | // TODO: impl. using DirectDB's DrawLines | |
219 | wxFAIL_MSG( _T("DrawLines not implemented") ); | |
220 | } | |
221 | ||
222 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
223 | { | |
224 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
225 | ||
226 | wxCoord xx = XLOG2DEV(x); | |
227 | wxCoord yy = YLOG2DEV(y); | |
228 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
229 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
230 | ||
231 | if ( ww == 0 || hh == 0 ) return; | |
232 | ||
233 | if ( ww < 0 ) | |
234 | { | |
235 | ww = -ww; | |
236 | xx = xx - ww; | |
237 | } | |
238 | if ( hh < 0 ) | |
239 | { | |
240 | hh = -hh; | |
241 | yy = yy - hh; | |
242 | } | |
243 | ||
244 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
245 | { | |
246 | SelectColour(m_brush.GetColour()); | |
52c8d32a | 247 | m_surface->FillRectangle(xx, yy, ww, hh); |
b3c86150 VS |
248 | // restore pen's colour |
249 | SelectColour(m_pen.GetColour()); | |
250 | } | |
251 | ||
252 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
253 | { | |
52c8d32a | 254 | m_surface->DrawRectangle(xx, yy, ww, hh); |
b3c86150 VS |
255 | } |
256 | ||
257 | CalcBoundingBox(x, y); | |
258 | CalcBoundingBox(x + width, y + height); | |
259 | } | |
260 | ||
261 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
262 | { | |
263 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
264 | ||
265 | wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") ); | |
266 | } | |
267 | ||
268 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
269 | { | |
270 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
271 | ||
272 | wxFAIL_MSG( _T("DrawElipse not implemented") ); | |
273 | } | |
274 | ||
275 | void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
276 | { | |
277 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
278 | ||
279 | wxFAIL_MSG( _T("DrawElipticArc not implemented") ); | |
280 | } | |
281 | ||
282 | void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
283 | { | |
284 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
285 | ||
286 | wxCoord xx = XLOG2DEV(x); | |
287 | wxCoord yy = XLOG2DEV(y); | |
288 | ||
289 | // update the bounding box | |
290 | wxCoord w, h; | |
291 | CalcBoundingBox(x, y); | |
292 | GetTextExtent(text, &w, &h); | |
293 | CalcBoundingBox(x + w, y + h); | |
294 | ||
295 | // if background mode is solid, DrawText must paint text's background: | |
296 | if ( m_backgroundMode == wxSOLID ) | |
297 | { | |
298 | wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") ); | |
299 | ||
300 | SelectColour(m_backgroundBrush.GetColour()); | |
52c8d32a | 301 | m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h)); |
b3c86150 VS |
302 | // restore pen's colour |
303 | SelectColour(m_pen.GetColour()); | |
304 | } | |
305 | ||
306 | // finally draw the text itself: | |
52c8d32a | 307 | m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP); |
b3c86150 VS |
308 | } |
309 | ||
310 | void wxDC::DoDrawRotatedText(const wxString& text, | |
311 | wxCoord x, wxCoord y, | |
312 | double angle) | |
313 | { | |
314 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
315 | ||
316 | wxFAIL_MSG( _T("DrawRotatedText not implemented") ); | |
317 | } | |
318 | ||
319 | // --------------------------------------------------------------------------- | |
320 | // set GDI objects | |
321 | // --------------------------------------------------------------------------- | |
322 | ||
323 | void wxDC::SetPen(const wxPen& pen) | |
324 | { | |
071f5576 | 325 | m_pen = pen.Ok() ? pen : DEFAULT_PEN; |
b3c86150 VS |
326 | |
327 | SelectColour(m_pen.GetColour()); | |
328 | } | |
329 | ||
330 | void wxDC::SetBrush(const wxBrush& brush) | |
331 | { | |
071f5576 | 332 | m_brush = brush.Ok() ? brush : DEFAULT_BRUSH; |
b3c86150 VS |
333 | } |
334 | ||
335 | void wxDC::SelectColour(const wxColour& clr) | |
336 | { | |
52c8d32a | 337 | m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()); |
b3c86150 VS |
338 | #warning "use SetColorIndex?" |
339 | } | |
340 | ||
341 | #if wxUSE_PALETTE | |
342 | void wxDC::SetPalette(const wxPalette& WXUNUSED(palette)) | |
343 | { | |
344 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
345 | ||
346 | wxFAIL_MSG( _T("SetPalette not implemented") ); | |
347 | } | |
348 | #endif // wxUSE_PALETTE | |
349 | ||
350 | void wxDC::SetFont(const wxFont& font) | |
351 | { | |
352 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
353 | ||
071f5576 | 354 | wxFont f(font.Ok() ? font : DEFAULT_FONT); |
b3c86150 | 355 | |
071f5576 | 356 | if ( !m_surface->SetFont(f.GetDirectFBFont()) ) |
b3c86150 VS |
357 | return; |
358 | ||
071f5576 | 359 | m_font = f; |
b3c86150 VS |
360 | } |
361 | ||
362 | void wxDC::SetBackground(const wxBrush& brush) | |
363 | { | |
364 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
365 | ||
366 | if (!brush.Ok()) return; | |
367 | ||
368 | m_backgroundBrush = brush; | |
369 | } | |
370 | ||
371 | void wxDC::SetBackgroundMode(int mode) | |
372 | { | |
373 | m_backgroundMode = mode; | |
374 | } | |
375 | ||
376 | void wxDC::SetLogicalFunction(int function) | |
377 | { | |
378 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
379 | ||
380 | wxFAIL_MSG( _T("SetLogicalFunction not implemented") ); | |
381 | ||
382 | m_logicalFunction = function; | |
383 | } | |
384 | ||
385 | bool wxDC::StartDoc(const wxString& WXUNUSED(message)) | |
386 | { | |
387 | // We might be previewing, so return true to let it continue. | |
388 | return true; | |
389 | } | |
390 | ||
391 | void wxDC::EndDoc() | |
392 | { | |
393 | } | |
394 | ||
395 | void wxDC::StartPage() | |
396 | { | |
397 | } | |
398 | ||
399 | void wxDC::EndPage() | |
400 | { | |
401 | } | |
402 | ||
403 | // --------------------------------------------------------------------------- | |
404 | // text metrics | |
405 | // --------------------------------------------------------------------------- | |
406 | ||
407 | wxCoord wxDC::GetCharHeight() const | |
408 | { | |
409 | wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); | |
410 | wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); | |
411 | ||
412 | int h = -1; | |
52c8d32a | 413 | m_font.GetDirectFBFont()->GetHeight(&h); |
b3c86150 VS |
414 | return YDEV2LOGREL(h); |
415 | } | |
416 | ||
417 | wxCoord wxDC::GetCharWidth() const | |
418 | { | |
419 | wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); | |
420 | wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); | |
421 | ||
422 | int w = -1; | |
52c8d32a | 423 | m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w); |
b3c86150 VS |
424 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are only |
425 | // scaled according to m_scaleY | |
426 | return YDEV2LOGREL(w); | |
427 | } | |
428 | ||
429 | void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, | |
430 | wxCoord *descent, wxCoord *externalLeading, | |
431 | wxFont *theFont) const | |
432 | { | |
433 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
434 | wxCHECK_RET( m_font.Ok(), wxT("no font selected") ); | |
435 | wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") ); | |
436 | ||
437 | wxFont oldFont; | |
438 | if ( theFont != NULL ) | |
439 | { | |
440 | oldFont = m_font; | |
441 | wxConstCast(this, wxDC)->SetFont(*theFont); | |
442 | } | |
443 | ||
444 | wxCoord xx = 0, yy = 0; | |
445 | DFBRectangle rect; | |
52c8d32a | 446 | wxIDirectFBFontPtr f = m_font.GetDirectFBFont(); |
b3c86150 | 447 | |
52c8d32a | 448 | if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) ) |
b3c86150 VS |
449 | { |
450 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are | |
451 | // only scaled according to m_scaleY | |
452 | xx = YDEV2LOGREL(rect.w); | |
453 | yy = YDEV2LOGREL(rect.h); | |
454 | ||
455 | if ( descent ) | |
456 | { | |
457 | int d; | |
52c8d32a | 458 | if ( f->GetDescender(&d) ) |
b3c86150 VS |
459 | *descent = YDEV2LOGREL(-d); |
460 | else | |
461 | *descent = 0; | |
462 | } | |
463 | } | |
464 | ||
465 | if ( x ) *x = xx; | |
466 | if ( y ) *y = yy; | |
467 | if ( externalLeading ) *externalLeading = 0; | |
468 | ||
469 | if ( theFont != NULL ) | |
470 | wxConstCast(this, wxDC)->SetFont(oldFont); | |
471 | } | |
472 | ||
473 | ||
474 | ||
475 | // --------------------------------------------------------------------------- | |
476 | // mapping modes | |
477 | // --------------------------------------------------------------------------- | |
478 | ||
479 | void wxDC::ComputeScaleAndOrigin() | |
480 | { | |
481 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
482 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
483 | ||
484 | // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which | |
485 | // is not currently implemented here; probably makes sense to | |
486 | // switch to Cairo instead of implementing everything for DFB | |
487 | wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0, | |
488 | _T("scaling is not implemented in wxDFB") ); | |
489 | } | |
490 | ||
491 | void wxDC::SetMapMode(int mode) | |
492 | { | |
493 | #warning "move this to common code, it's shared by almost all ports!" | |
494 | switch (mode) | |
495 | { | |
496 | case wxMM_TWIPS: | |
497 | SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); | |
498 | break; | |
499 | case wxMM_POINTS: | |
500 | SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); | |
501 | break; | |
502 | case wxMM_METRIC: | |
503 | SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); | |
504 | break; | |
505 | case wxMM_LOMETRIC: | |
506 | SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); | |
507 | break; | |
508 | default: | |
509 | case wxMM_TEXT: | |
510 | SetLogicalScale(1.0, 1.0); | |
511 | break; | |
512 | } | |
513 | m_mappingMode = mode; | |
514 | } | |
515 | ||
516 | void wxDC::SetUserScale(double x, double y) | |
517 | { | |
518 | #warning "move this to common code?" | |
519 | // allow negative ? -> no | |
520 | m_userScaleX = x; | |
521 | m_userScaleY = y; | |
522 | ComputeScaleAndOrigin(); | |
523 | } | |
524 | ||
525 | void wxDC::SetLogicalScale(double x, double y) | |
526 | { | |
527 | #warning "move this to common code?" | |
528 | // allow negative ? | |
529 | m_logicalScaleX = x; | |
530 | m_logicalScaleY = y; | |
531 | ComputeScaleAndOrigin(); | |
532 | } | |
533 | ||
534 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
535 | { | |
536 | #warning "move this to common code?" | |
537 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
538 | m_logicalOriginY = y * m_signY; | |
539 | ComputeScaleAndOrigin(); | |
540 | } | |
541 | ||
542 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
543 | { | |
544 | #warning "move this to common code?" | |
545 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
546 | m_deviceOriginX = x; | |
547 | m_deviceOriginY = y; | |
548 | ComputeScaleAndOrigin(); | |
549 | } | |
550 | ||
551 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
552 | { | |
553 | #warning "move this to common code?" | |
554 | // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there | |
555 | m_signX = (xLeftRight ? 1 : -1); | |
556 | m_signY = (yBottomUp ? -1 : 1); | |
557 | ComputeScaleAndOrigin(); | |
558 | } | |
559 | ||
560 | // --------------------------------------------------------------------------- | |
561 | // coordinates transformations | |
562 | // --------------------------------------------------------------------------- | |
563 | ||
564 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
565 | { | |
566 | return ((wxDC *)this)->XDEV2LOG(x); | |
567 | } | |
568 | ||
569 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
570 | { | |
571 | return ((wxDC *)this)->YDEV2LOG(y); | |
572 | } | |
573 | ||
574 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
575 | { | |
576 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
577 | } | |
578 | ||
579 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
580 | { | |
581 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
582 | } | |
583 | ||
584 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
585 | { | |
586 | return ((wxDC *)this)->XLOG2DEV(x); | |
587 | } | |
588 | ||
589 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
590 | { | |
591 | return ((wxDC *)this)->YLOG2DEV(y); | |
592 | } | |
593 | ||
594 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
595 | { | |
596 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
597 | } | |
598 | ||
599 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
600 | { | |
601 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
602 | } | |
603 | ||
604 | ||
605 | void wxDC::DoGetSize(int *w, int *h) const | |
606 | { | |
607 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
608 | ||
52c8d32a | 609 | m_surface->GetSize(w, h); |
b3c86150 VS |
610 | } |
611 | ||
612 | void wxDC::DoGetSizeMM(int *width, int *height) const | |
613 | { | |
614 | #warning "move this to common code?" | |
615 | int w = 0; | |
616 | int h = 0; | |
617 | GetSize(&w, &h); | |
618 | if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x)); | |
619 | if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y)); | |
620 | } | |
621 | ||
622 | wxSize wxDC::GetPPI() const | |
623 | { | |
624 | #warning "move this to common code?" | |
625 | return wxSize(int(double(m_mm_to_pix_x) * inches2mm), | |
626 | int(double(m_mm_to_pix_y) * inches2mm)); | |
627 | } | |
628 | ||
629 | ||
630 | // --------------------------------------------------------------------------- | |
631 | // Blitting | |
632 | // --------------------------------------------------------------------------- | |
633 | ||
634 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, | |
635 | wxCoord width, wxCoord height, | |
636 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
637 | int rop, bool useMask, | |
638 | wxCoord xsrcMask, wxCoord ysrcMask) | |
639 | { | |
640 | #warning "FIXME" | |
641 | return false; | |
642 | #if 0 | |
643 | wxCHECK_MSG( Ok(), false, wxT("invalid dc") ); | |
644 | wxCHECK_MSG( source, false, wxT("invalid source dc") ); | |
645 | ||
646 | // transform the source DC coords to the device ones | |
647 | xsrc = source->LogicalToDeviceX(xsrc); | |
648 | ysrc = source->LogicalToDeviceY(ysrc); | |
649 | ||
650 | /* FIXME_MGL: use the mask origin when drawing transparently */ | |
651 | if (xsrcMask == -1 && ysrcMask == -1) | |
652 | { | |
653 | xsrcMask = xsrc; ysrcMask = ysrc; | |
654 | } | |
655 | else | |
656 | { | |
657 | xsrcMask = source->LogicalToDeviceX(xsrcMask); | |
658 | ysrcMask = source->LogicalToDeviceY(ysrcMask); | |
659 | } | |
660 | ||
661 | CalcBoundingBox(xdest, ydest); | |
662 | CalcBoundingBox(xdest + width, ydest + height); | |
663 | ||
664 | /* scale/translate size and position */ | |
665 | wxCoord xx = XLOG2DEV(xdest); | |
666 | wxCoord yy = YLOG2DEV(ydest); | |
667 | wxCoord ww = XLOG2DEVREL(width); | |
668 | wxCoord hh = YLOG2DEVREL(height); | |
669 | ||
670 | if ( source->m_isMemDC ) | |
671 | { | |
672 | wxMemoryDC *memDC = (wxMemoryDC*) source; | |
673 | DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh, | |
674 | xdest, ydest, rop, useMask); | |
675 | } | |
676 | else | |
677 | { | |
678 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
679 | m_MGLDC->bitBlt(*source->GetMGLDC(), | |
680 | xsrc, ysrc, xsrc + ww, ysrc + hh, | |
681 | xx, yy, LogicalFunctionToMGLRop(rop)); | |
682 | } | |
683 | ||
684 | return true; | |
685 | #endif | |
686 | } | |
687 | ||
688 | void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) | |
689 | { | |
690 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
691 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
692 | ||
693 | wxCoord w = bmp.GetWidth(); | |
694 | wxCoord h = bmp.GetHeight(); | |
695 | ||
696 | DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask); | |
697 | } | |
698 | ||
699 | void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
700 | { | |
701 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why | |
702 | DoDrawBitmap((const wxBitmap&)icon, x, y, true); | |
703 | } | |
704 | ||
705 | void wxDC::DoDrawSubBitmap(const wxBitmap &bmp, | |
706 | wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
707 | wxCoord destx, wxCoord desty, int rop, bool useMask) | |
708 | { | |
709 | #if 0 | |
710 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
711 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
712 | ||
713 | CalcBoundingBox(x, y); | |
714 | CalcBoundingBox(x + w, y + h); | |
715 | ||
716 | wxCoord dx = XLOG2DEV(destx); | |
717 | wxCoord dy = YLOG2DEV(desty); | |
718 | wxCoord dw = XLOG2DEVREL(w); | |
719 | wxCoord dh = YLOG2DEVREL(h); | |
720 | ||
721 | m_MGLDC->makeCurrent(); // will go away with MGL6.0 | |
722 | ||
723 | bool useStretching = ((w != dw) || (h != dh)); | |
724 | bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight()); | |
725 | MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop); | |
726 | ||
727 | if ( bmp.GetDepth() == 1 ) | |
728 | { | |
729 | // Mono bitmaps are handled in special way -- all 1s are drawn in | |
730 | // foreground colours, all 0s in background colour. | |
731 | ||
732 | ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour); | |
733 | } | |
734 | ||
735 | if ( useMask && bmp.GetMask() ) | |
736 | { | |
737 | // Since MGL does not support masks directly (in MGL, mask is handled | |
738 | // in same way as in wxImage, i.e. there is one "key" color), we | |
739 | // simulate masked bitblt in 6 steps (same as in MSW): | |
740 | // | |
741 | // 1. Create a temporary bitmap and copy the destination area into it. | |
742 | // 2. Copy the source area into the temporary bitmap using the | |
743 | // specified logical function. | |
744 | // 3. Set the masked area in the temporary bitmap to BLACK by ANDing | |
745 | // the mask bitmap with the temp bitmap with the foreground colour | |
746 | // set to WHITE and the bg colour set to BLACK. | |
747 | // 4. Set the unmasked area in the destination area to BLACK by | |
748 | // ANDing the mask bitmap with the destination area with the | |
749 | // foreground colour set to BLACK and the background colour set | |
750 | // to WHITE. | |
751 | // 5. OR the temporary bitmap with the destination area. | |
752 | // 6. Delete the temporary bitmap. | |
753 | // | |
754 | // This sequence of operations ensures that the source's transparent | |
755 | // area need not be black, and logical functions are supported. | |
756 | ||
757 | wxBitmap *mask = bmp.GetMask()->GetBitmap(); | |
758 | ||
759 | MGLMemoryDC *temp; | |
760 | ||
761 | if ( GetDepth() <= 8 ) | |
762 | { | |
763 | temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL); | |
764 | wxDC tempdc; | |
765 | tempdc.SetMGLDC(temp, false); | |
766 | tempdc.SetPalette(m_palette); | |
767 | } | |
768 | else | |
769 | { | |
770 | pixel_format_t pf; | |
771 | m_MGLDC->getPixelFormat(pf); | |
772 | temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf); | |
773 | } | |
774 | ||
775 | wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") ); | |
776 | ||
777 | temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE); | |
778 | ||
779 | DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop, | |
780 | useStretching, putSection); | |
781 | ||
782 | mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255)); | |
783 | DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC, | |
784 | useStretching, putSection); | |
785 | DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC, | |
786 | useStretching, putSection); | |
787 | ||
788 | m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE); | |
789 | ||
790 | delete temp; | |
791 | } | |
792 | ||
793 | else | |
794 | { | |
795 | DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop, | |
796 | useStretching, putSection); | |
797 | } | |
798 | #endif | |
799 | } |