]>
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 | ||
b3c86150 VS |
81 | void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) |
82 | { | |
83 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
84 | ||
564b429f VS |
85 | wxSize size(GetSize()); |
86 | ||
f87d0500 VS |
87 | wxASSERT_MSG( !m_clipping, |
88 | _T("narrowing clipping region not implemented yet") ); | |
89 | ||
564b429f VS |
90 | // NB: We intersect the clipping rectangle with surface's area here because |
91 | // DirectFB will return an error if you try to set clipping rectangle | |
92 | // that is partially outside of the surface. | |
b3c86150 | 93 | DFBRegion r; |
564b429f VS |
94 | r.x1 = wxMax(0, XLOG2DEV(cx)); |
95 | r.y1 = wxMax(0, YLOG2DEV(cy)); | |
96 | r.x2 = wxMin(r.x1 + XLOG2DEVREL(cw), size.x) - 1; | |
97 | r.y2 = wxMin(r.y1 + YLOG2DEVREL(ch), size.y) - 1; | |
b3c86150 | 98 | |
52c8d32a | 99 | if ( !m_surface->SetClip(&r) ) |
b3c86150 VS |
100 | return; |
101 | ||
102 | m_clipX1 = cx; | |
103 | m_clipY1 = cy; | |
104 | m_clipX2 = cx + cw - 1; | |
105 | m_clipY2 = cy + ch -1; | |
106 | m_clipping = true; | |
107 | } | |
108 | ||
109 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) | |
110 | { | |
f87d0500 | 111 | // NB: this can be done because wxDFB only supports rectangular regions |
b3c86150 VS |
112 | SetClippingRegion(region.AsRect()); |
113 | } | |
114 | ||
115 | void wxDC::DestroyClippingRegion() | |
116 | { | |
117 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
118 | ||
52c8d32a | 119 | m_surface->SetClip(NULL); |
b3c86150 VS |
120 | |
121 | ResetClipping(); | |
122 | } | |
123 | ||
124 | // --------------------------------------------------------------------------- | |
125 | // query capabilities | |
126 | // --------------------------------------------------------------------------- | |
127 | ||
128 | int wxDC::GetDepth() const | |
129 | { | |
a5b31f4e | 130 | return m_surface->GetDepth(); |
b3c86150 VS |
131 | } |
132 | ||
133 | // --------------------------------------------------------------------------- | |
134 | // drawing | |
135 | // --------------------------------------------------------------------------- | |
136 | ||
137 | void wxDC::Clear() | |
138 | { | |
139 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
140 | ||
141 | if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT ) | |
142 | return; | |
143 | ||
144 | wxColour clr = m_backgroundBrush.GetColour(); | |
52c8d32a | 145 | m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()); |
20671963 VS |
146 | |
147 | wxSize size(GetSize()); | |
148 | CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0)); | |
149 | CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y)); | |
b3c86150 VS |
150 | } |
151 | ||
152 | extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, | |
153 | const wxColour & col, int style); | |
154 | ||
155 | bool wxDC::DoFloodFill(wxCoord x, wxCoord y, | |
156 | const wxColour& col, int style) | |
157 | { | |
158 | return wxDoFloodFill(this, x, y, col, style); | |
159 | } | |
160 | ||
161 | bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const | |
162 | { | |
163 | wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel")); | |
164 | ||
165 | wxFAIL_MSG( _T("GetPixel not implemented") ); | |
166 | return false; | |
167 | } | |
168 | ||
169 | void wxDC::DoCrossHair(wxCoord x, wxCoord y) | |
170 | { | |
171 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
172 | ||
173 | wxFAIL_MSG( _T("CrossHair not implemented") ); | |
174 | } | |
175 | ||
176 | void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) | |
177 | { | |
178 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
179 | ||
180 | if ( m_pen.GetStyle() == wxTRANSPARENT ) | |
181 | return; | |
182 | ||
52c8d32a VS |
183 | m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1), |
184 | XLOG2DEV(x2), YLOG2DEV(y2)); | |
b3c86150 VS |
185 | |
186 | CalcBoundingBox(x1, y1); | |
187 | CalcBoundingBox(x2, y2); | |
188 | } | |
189 | ||
190 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
191 | // and ending at (x2, y2) | |
192 | void wxDC::DoDrawArc(wxCoord x1, wxCoord y1, | |
193 | wxCoord x2, wxCoord y2, | |
194 | wxCoord xc, wxCoord yc) | |
195 | { | |
196 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
197 | ||
198 | wxFAIL_MSG( _T("DrawArc not implemented") ); | |
199 | } | |
200 | ||
201 | void wxDC::DoDrawPoint(wxCoord x, wxCoord y) | |
202 | { | |
203 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
204 | ||
3af4da32 VS |
205 | // NB: DirectFB API doesn't provide a function for drawing points, so |
206 | // implement it as 1px long line. This is inefficient, but then, so is | |
207 | // using DrawPoint() for drawing more than a few points. | |
208 | DoDrawLine(x, y, x, y); | |
209 | ||
210 | // FIXME_DFB: implement special cases for common formats (RGB24,RGBA/RGB32) | |
b3c86150 VS |
211 | } |
212 | ||
213 | void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle)) | |
214 | { | |
215 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
216 | ||
217 | wxFAIL_MSG( _T("DrawPolygon not implemented") ); | |
218 | } | |
219 | ||
220 | void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) | |
221 | { | |
222 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
223 | ||
224 | // TODO: impl. using DirectDB's DrawLines | |
225 | wxFAIL_MSG( _T("DrawLines not implemented") ); | |
226 | } | |
227 | ||
228 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
229 | { | |
230 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
231 | ||
232 | wxCoord xx = XLOG2DEV(x); | |
233 | wxCoord yy = YLOG2DEV(y); | |
234 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
235 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
236 | ||
237 | if ( ww == 0 || hh == 0 ) return; | |
238 | ||
239 | if ( ww < 0 ) | |
240 | { | |
241 | ww = -ww; | |
242 | xx = xx - ww; | |
243 | } | |
244 | if ( hh < 0 ) | |
245 | { | |
246 | hh = -hh; | |
247 | yy = yy - hh; | |
248 | } | |
249 | ||
250 | if ( m_brush.GetStyle() != wxTRANSPARENT ) | |
251 | { | |
252 | SelectColour(m_brush.GetColour()); | |
52c8d32a | 253 | m_surface->FillRectangle(xx, yy, ww, hh); |
3dcc2231 VS |
254 | // restore pen's colour, because other drawing functions expect the |
255 | // colour to be set to the pen: | |
b3c86150 VS |
256 | SelectColour(m_pen.GetColour()); |
257 | } | |
258 | ||
259 | if ( m_pen.GetStyle() != wxTRANSPARENT ) | |
260 | { | |
52c8d32a | 261 | m_surface->DrawRectangle(xx, yy, ww, hh); |
b3c86150 VS |
262 | } |
263 | ||
264 | CalcBoundingBox(x, y); | |
265 | CalcBoundingBox(x + width, y + height); | |
266 | } | |
267 | ||
268 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) | |
269 | { | |
270 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
271 | ||
272 | wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") ); | |
273 | } | |
274 | ||
275 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) | |
276 | { | |
277 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
278 | ||
279 | wxFAIL_MSG( _T("DrawElipse not implemented") ); | |
280 | } | |
281 | ||
282 | void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea) | |
283 | { | |
284 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
285 | ||
286 | wxFAIL_MSG( _T("DrawElipticArc not implemented") ); | |
287 | } | |
288 | ||
289 | void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) | |
290 | { | |
291 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
292 | ||
293 | wxCoord xx = XLOG2DEV(x); | |
5034c9db | 294 | wxCoord yy = YLOG2DEV(y); |
b3c86150 VS |
295 | |
296 | // update the bounding box | |
297 | wxCoord w, h; | |
298 | CalcBoundingBox(x, y); | |
299 | GetTextExtent(text, &w, &h); | |
300 | CalcBoundingBox(x + w, y + h); | |
301 | ||
302 | // if background mode is solid, DrawText must paint text's background: | |
303 | if ( m_backgroundMode == wxSOLID ) | |
304 | { | |
3dcc2231 VS |
305 | wxCHECK_RET( m_textBackgroundColour.Ok(), |
306 | wxT("invalid background color") ); | |
b3c86150 | 307 | |
3dcc2231 | 308 | SelectColour(m_textBackgroundColour); |
52c8d32a | 309 | m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h)); |
b3c86150 VS |
310 | } |
311 | ||
312 | // finally draw the text itself: | |
3dcc2231 VS |
313 | wxCHECK_RET( m_textForegroundColour.Ok(), |
314 | wxT("invalid foreground color") ); | |
315 | SelectColour(m_textForegroundColour); | |
52c8d32a | 316 | m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP); |
3dcc2231 VS |
317 | |
318 | // restore pen's colour, because other drawing functions expect the colour | |
319 | // to be set to the pen: | |
320 | SelectColour(m_pen.GetColour()); | |
b3c86150 VS |
321 | } |
322 | ||
323 | void wxDC::DoDrawRotatedText(const wxString& text, | |
324 | wxCoord x, wxCoord y, | |
325 | double angle) | |
326 | { | |
327 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
328 | ||
329 | wxFAIL_MSG( _T("DrawRotatedText not implemented") ); | |
330 | } | |
331 | ||
332 | // --------------------------------------------------------------------------- | |
333 | // set GDI objects | |
334 | // --------------------------------------------------------------------------- | |
335 | ||
336 | void wxDC::SetPen(const wxPen& pen) | |
337 | { | |
071f5576 | 338 | m_pen = pen.Ok() ? pen : DEFAULT_PEN; |
b3c86150 VS |
339 | |
340 | SelectColour(m_pen.GetColour()); | |
341 | } | |
342 | ||
343 | void wxDC::SetBrush(const wxBrush& brush) | |
344 | { | |
071f5576 | 345 | m_brush = brush.Ok() ? brush : DEFAULT_BRUSH; |
b3c86150 VS |
346 | } |
347 | ||
348 | void wxDC::SelectColour(const wxColour& clr) | |
349 | { | |
52c8d32a | 350 | m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()); |
b3c86150 VS |
351 | #warning "use SetColorIndex?" |
352 | } | |
353 | ||
354 | #if wxUSE_PALETTE | |
355 | void wxDC::SetPalette(const wxPalette& WXUNUSED(palette)) | |
356 | { | |
357 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
358 | ||
359 | wxFAIL_MSG( _T("SetPalette not implemented") ); | |
360 | } | |
361 | #endif // wxUSE_PALETTE | |
362 | ||
363 | void wxDC::SetFont(const wxFont& font) | |
364 | { | |
365 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
366 | ||
071f5576 | 367 | wxFont f(font.Ok() ? font : DEFAULT_FONT); |
b3c86150 | 368 | |
071f5576 | 369 | if ( !m_surface->SetFont(f.GetDirectFBFont()) ) |
b3c86150 VS |
370 | return; |
371 | ||
071f5576 | 372 | m_font = f; |
b3c86150 VS |
373 | } |
374 | ||
375 | void wxDC::SetBackground(const wxBrush& brush) | |
376 | { | |
377 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
378 | ||
379 | if (!brush.Ok()) return; | |
380 | ||
381 | m_backgroundBrush = brush; | |
382 | } | |
383 | ||
384 | void wxDC::SetBackgroundMode(int mode) | |
385 | { | |
386 | m_backgroundMode = mode; | |
387 | } | |
388 | ||
389 | void wxDC::SetLogicalFunction(int function) | |
390 | { | |
391 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
392 | ||
5942996c VS |
393 | // NB: we could also support XOR, but for blitting only (via DSBLIT_XOR); |
394 | // and possibly others via SetSrc/DstBlendFunction() | |
395 | wxASSERT_MSG( function == wxCOPY, | |
396 | _T("only wxCOPY logical function supported") ); | |
b3c86150 VS |
397 | |
398 | m_logicalFunction = function; | |
399 | } | |
400 | ||
401 | bool wxDC::StartDoc(const wxString& WXUNUSED(message)) | |
402 | { | |
403 | // We might be previewing, so return true to let it continue. | |
404 | return true; | |
405 | } | |
406 | ||
407 | void wxDC::EndDoc() | |
408 | { | |
409 | } | |
410 | ||
411 | void wxDC::StartPage() | |
412 | { | |
413 | } | |
414 | ||
415 | void wxDC::EndPage() | |
416 | { | |
417 | } | |
418 | ||
419 | // --------------------------------------------------------------------------- | |
420 | // text metrics | |
421 | // --------------------------------------------------------------------------- | |
422 | ||
423 | wxCoord wxDC::GetCharHeight() const | |
424 | { | |
425 | wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); | |
426 | wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); | |
427 | ||
428 | int h = -1; | |
52c8d32a | 429 | m_font.GetDirectFBFont()->GetHeight(&h); |
b3c86150 VS |
430 | return YDEV2LOGREL(h); |
431 | } | |
432 | ||
433 | wxCoord wxDC::GetCharWidth() const | |
434 | { | |
435 | wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); | |
436 | wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); | |
437 | ||
438 | int w = -1; | |
52c8d32a | 439 | m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w); |
b3c86150 VS |
440 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are only |
441 | // scaled according to m_scaleY | |
442 | return YDEV2LOGREL(w); | |
443 | } | |
444 | ||
445 | void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, | |
446 | wxCoord *descent, wxCoord *externalLeading, | |
447 | wxFont *theFont) const | |
448 | { | |
449 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
450 | wxCHECK_RET( m_font.Ok(), wxT("no font selected") ); | |
451 | wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") ); | |
452 | ||
453 | wxFont oldFont; | |
454 | if ( theFont != NULL ) | |
455 | { | |
456 | oldFont = m_font; | |
457 | wxConstCast(this, wxDC)->SetFont(*theFont); | |
458 | } | |
459 | ||
460 | wxCoord xx = 0, yy = 0; | |
461 | DFBRectangle rect; | |
52c8d32a | 462 | wxIDirectFBFontPtr f = m_font.GetDirectFBFont(); |
b3c86150 | 463 | |
52c8d32a | 464 | if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) ) |
b3c86150 VS |
465 | { |
466 | // VS: YDEV is corrent, it should *not* be XDEV, because font's are | |
467 | // only scaled according to m_scaleY | |
468 | xx = YDEV2LOGREL(rect.w); | |
469 | yy = YDEV2LOGREL(rect.h); | |
470 | ||
471 | if ( descent ) | |
472 | { | |
473 | int d; | |
52c8d32a | 474 | if ( f->GetDescender(&d) ) |
b3c86150 VS |
475 | *descent = YDEV2LOGREL(-d); |
476 | else | |
477 | *descent = 0; | |
478 | } | |
479 | } | |
480 | ||
481 | if ( x ) *x = xx; | |
482 | if ( y ) *y = yy; | |
483 | if ( externalLeading ) *externalLeading = 0; | |
484 | ||
485 | if ( theFont != NULL ) | |
486 | wxConstCast(this, wxDC)->SetFont(oldFont); | |
487 | } | |
488 | ||
489 | ||
490 | ||
491 | // --------------------------------------------------------------------------- | |
492 | // mapping modes | |
493 | // --------------------------------------------------------------------------- | |
494 | ||
495 | void wxDC::ComputeScaleAndOrigin() | |
496 | { | |
497 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
498 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
499 | ||
500 | // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which | |
501 | // is not currently implemented here; probably makes sense to | |
502 | // switch to Cairo instead of implementing everything for DFB | |
503 | wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0, | |
504 | _T("scaling is not implemented in wxDFB") ); | |
505 | } | |
506 | ||
507 | void wxDC::SetMapMode(int mode) | |
508 | { | |
509 | #warning "move this to common code, it's shared by almost all ports!" | |
510 | switch (mode) | |
511 | { | |
512 | case wxMM_TWIPS: | |
513 | SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); | |
514 | break; | |
515 | case wxMM_POINTS: | |
516 | SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); | |
517 | break; | |
518 | case wxMM_METRIC: | |
519 | SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); | |
520 | break; | |
521 | case wxMM_LOMETRIC: | |
522 | SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); | |
523 | break; | |
524 | default: | |
525 | case wxMM_TEXT: | |
526 | SetLogicalScale(1.0, 1.0); | |
527 | break; | |
528 | } | |
529 | m_mappingMode = mode; | |
530 | } | |
531 | ||
532 | void wxDC::SetUserScale(double x, double y) | |
533 | { | |
534 | #warning "move this to common code?" | |
535 | // allow negative ? -> no | |
536 | m_userScaleX = x; | |
537 | m_userScaleY = y; | |
538 | ComputeScaleAndOrigin(); | |
539 | } | |
540 | ||
541 | void wxDC::SetLogicalScale(double x, double y) | |
542 | { | |
543 | #warning "move this to common code?" | |
544 | // allow negative ? | |
545 | m_logicalScaleX = x; | |
546 | m_logicalScaleY = y; | |
547 | ComputeScaleAndOrigin(); | |
548 | } | |
549 | ||
550 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) | |
551 | { | |
552 | #warning "move this to common code?" | |
553 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
554 | m_logicalOriginY = y * m_signY; | |
555 | ComputeScaleAndOrigin(); | |
556 | } | |
557 | ||
558 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) | |
559 | { | |
560 | #warning "move this to common code?" | |
561 | // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there | |
562 | m_deviceOriginX = x; | |
563 | m_deviceOriginY = y; | |
564 | ComputeScaleAndOrigin(); | |
565 | } | |
566 | ||
567 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
568 | { | |
569 | #warning "move this to common code?" | |
570 | // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there | |
571 | m_signX = (xLeftRight ? 1 : -1); | |
572 | m_signY = (yBottomUp ? -1 : 1); | |
573 | ComputeScaleAndOrigin(); | |
574 | } | |
575 | ||
576 | // --------------------------------------------------------------------------- | |
577 | // coordinates transformations | |
578 | // --------------------------------------------------------------------------- | |
579 | ||
580 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
581 | { | |
582 | return ((wxDC *)this)->XDEV2LOG(x); | |
583 | } | |
584 | ||
585 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
586 | { | |
587 | return ((wxDC *)this)->YDEV2LOG(y); | |
588 | } | |
589 | ||
590 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
591 | { | |
592 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
593 | } | |
594 | ||
595 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
596 | { | |
597 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
598 | } | |
599 | ||
600 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
601 | { | |
602 | return ((wxDC *)this)->XLOG2DEV(x); | |
603 | } | |
604 | ||
605 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
606 | { | |
607 | return ((wxDC *)this)->YLOG2DEV(y); | |
608 | } | |
609 | ||
610 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
611 | { | |
612 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
613 | } | |
614 | ||
615 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
616 | { | |
617 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
618 | } | |
619 | ||
620 | ||
621 | void wxDC::DoGetSize(int *w, int *h) const | |
622 | { | |
623 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
624 | ||
52c8d32a | 625 | m_surface->GetSize(w, h); |
b3c86150 VS |
626 | } |
627 | ||
628 | void wxDC::DoGetSizeMM(int *width, int *height) const | |
629 | { | |
630 | #warning "move this to common code?" | |
631 | int w = 0; | |
632 | int h = 0; | |
633 | GetSize(&w, &h); | |
634 | if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x)); | |
635 | if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y)); | |
636 | } | |
637 | ||
638 | wxSize wxDC::GetPPI() const | |
639 | { | |
640 | #warning "move this to common code?" | |
641 | return wxSize(int(double(m_mm_to_pix_x) * inches2mm), | |
642 | int(double(m_mm_to_pix_y) * inches2mm)); | |
643 | } | |
644 | ||
645 | ||
646 | // --------------------------------------------------------------------------- | |
647 | // Blitting | |
648 | // --------------------------------------------------------------------------- | |
649 | ||
650 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, | |
651 | wxCoord width, wxCoord height, | |
652 | wxDC *source, wxCoord xsrc, wxCoord ysrc, | |
653 | int rop, bool useMask, | |
654 | wxCoord xsrcMask, wxCoord ysrcMask) | |
655 | { | |
5942996c VS |
656 | wxCHECK_MSG( Ok(), false, _T("invalid dc") ); |
657 | wxCHECK_MSG( source, false, _T("invalid source dc") ); | |
658 | ||
659 | // NB: we could also support XOR here (via DSBLIT_XOR) | |
660 | // and possibly others via SetSrc/DstBlendFunction() | |
661 | wxCHECK_MSG( rop == wxCOPY, false, _T("only wxCOPY function supported") ); | |
b3c86150 VS |
662 | |
663 | // transform the source DC coords to the device ones | |
664 | xsrc = source->LogicalToDeviceX(xsrc); | |
665 | ysrc = source->LogicalToDeviceY(ysrc); | |
666 | ||
5942996c VS |
667 | // FIXME_DFB: use the mask origin when drawing transparently |
668 | wxASSERT_MSG( xsrcMask == -1 && ysrcMask == -1, | |
669 | _T("non-default source mask offset not implemented") ); | |
670 | #if 0 | |
b3c86150 VS |
671 | if (xsrcMask == -1 && ysrcMask == -1) |
672 | { | |
673 | xsrcMask = xsrc; ysrcMask = ysrc; | |
674 | } | |
675 | else | |
676 | { | |
677 | xsrcMask = source->LogicalToDeviceX(xsrcMask); | |
678 | ysrcMask = source->LogicalToDeviceY(ysrcMask); | |
679 | } | |
5942996c | 680 | #endif |
b3c86150 | 681 | |
5942996c VS |
682 | wxMemoryDC *sourceAsMemDC = wxDynamicCast(source, wxMemoryDC); |
683 | if ( sourceAsMemDC ) | |
b3c86150 | 684 | { |
5942996c VS |
685 | DoDrawSubBitmap(sourceAsMemDC->GetSelectedObject(), |
686 | xsrc, ysrc, | |
687 | width, height, | |
688 | xdest, ydest, | |
689 | rop, | |
690 | useMask); | |
b3c86150 VS |
691 | } |
692 | else | |
693 | { | |
5942996c VS |
694 | return DoBlitFromSurface(source->GetDirectFBSurface(), |
695 | xsrc, ysrc, | |
696 | width, height, | |
697 | xdest, ydest); | |
b3c86150 VS |
698 | } |
699 | ||
700 | return true; | |
b3c86150 VS |
701 | } |
702 | ||
703 | void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask) | |
704 | { | |
705 | wxCHECK_RET( Ok(), wxT("invalid dc") ); | |
706 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
707 | ||
5942996c VS |
708 | DoDrawSubBitmap(bmp, |
709 | 0, 0, bmp.GetWidth(), bmp.GetHeight(), | |
710 | x, y, | |
711 | m_logicalFunction, useMask); | |
b3c86150 VS |
712 | } |
713 | ||
714 | void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) | |
715 | { | |
716 | // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why | |
717 | DoDrawBitmap((const wxBitmap&)icon, x, y, true); | |
718 | } | |
719 | ||
720 | void wxDC::DoDrawSubBitmap(const wxBitmap &bmp, | |
721 | wxCoord x, wxCoord y, wxCoord w, wxCoord h, | |
722 | wxCoord destx, wxCoord desty, int rop, bool useMask) | |
723 | { | |
b3c86150 VS |
724 | wxCHECK_RET( Ok(), wxT("invalid dc") ); |
725 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
726 | ||
5942996c VS |
727 | // NB: we could also support XOR here (via DSBLIT_XOR) |
728 | // and possibly others via SetSrc/DstBlendFunction() | |
729 | wxCHECK_RET( rop == wxCOPY, _T("only wxCOPY function supported") ); | |
b3c86150 VS |
730 | |
731 | if ( bmp.GetDepth() == 1 ) | |
732 | { | |
733 | // Mono bitmaps are handled in special way -- all 1s are drawn in | |
734 | // foreground colours, all 0s in background colour. | |
5942996c VS |
735 | wxFAIL_MSG( _T("drawing mono bitmaps not implemented") ); |
736 | return; | |
b3c86150 VS |
737 | } |
738 | ||
739 | if ( useMask && bmp.GetMask() ) | |
740 | { | |
5942996c VS |
741 | // FIXME_DFB: see MGL sources for a way to do it, but it's not directly |
742 | // applicable because DirectFB doesn't implement ROPs; OTOH, | |
743 | // it has blitting modes that can be useful; finally, see | |
744 | // DFB's SetSrcBlendFunction() and SetSrcColorKey() | |
745 | wxFAIL_MSG( _T("drawing bitmaps with masks not implemented") ); | |
746 | return; | |
747 | } | |
b3c86150 | 748 | |
5942996c VS |
749 | DoBlitFromSurface(bmp.GetDirectFBSurface(), |
750 | x, y, | |
751 | w, h, | |
752 | destx, desty); | |
753 | } | |
b3c86150 | 754 | |
5942996c VS |
755 | bool wxDC::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src, |
756 | wxCoord srcx, wxCoord srcy, | |
757 | wxCoord w, wxCoord h, | |
758 | wxCoord dstx, wxCoord dsty) | |
759 | { | |
760 | CalcBoundingBox(dstx, dsty); | |
761 | CalcBoundingBox(dstx + w, dsty + h); | |
b3c86150 | 762 | |
5942996c VS |
763 | DFBRectangle srcRect = { srcx, srcy, w, h }; |
764 | DFBRectangle dstRect = { XLOG2DEV(dstx), YLOG2DEV(dsty), | |
765 | XLOG2DEVREL(w), YLOG2DEVREL(h) }; | |
b3c86150 | 766 | |
5942996c | 767 | wxIDirectFBSurfacePtr dst(m_surface); |
b3c86150 | 768 | |
5942996c VS |
769 | // FIXME: this will have to be different in useMask case, see above |
770 | if ( !dst->SetBlittingFlags(DSBLIT_NOFX) ) | |
771 | return false; | |
b3c86150 | 772 | |
5942996c VS |
773 | if ( srcRect.w != dstRect.w || srcRect.h != dstRect.h ) |
774 | { | |
775 | // the bitmap is drawn stretched: | |
776 | dst->StretchBlit(src, &srcRect, &dstRect); | |
b3c86150 | 777 | } |
b3c86150 VS |
778 | else |
779 | { | |
5942996c VS |
780 | // no stretching, size is preserved: |
781 | dst->Blit(src, &srcRect, dstRect.x, dstRect.y); | |
b3c86150 | 782 | } |
5942996c VS |
783 | |
784 | return true; | |
b3c86150 | 785 | } |