]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/overlay.cpp
Applied patch from Bo, WIP
[wxWidgets.git] / src / dfb / overlay.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/overlay.cpp
3 // Purpose: wxOverlay implementation for wxDFB
4 // Author: Vaclav Slavik
5 // Created: 2006-10-20
6 // RCS-ID: $Id$
7 // Copyright: (c) wxWidgets team
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/window.h"
28 #include "wx/dcclient.h"
29 #endif
30
31 #include "wx/private/overlay.h"
32 #include "wx/dfb/private.h"
33
34 // ============================================================================
35 // implementation
36 // ============================================================================
37
38 // ----------------------------------------------------------------------------
39 // wxOverlay
40 // ----------------------------------------------------------------------------
41
42 wxOverlayImpl::wxOverlayImpl()
43 {
44 m_window = NULL;
45 m_isEmpty = true;
46 }
47
48 wxOverlayImpl::~wxOverlayImpl()
49 {
50 Reset();
51 }
52
53 bool wxOverlayImpl::IsOk()
54 {
55 return m_window != NULL;
56 }
57
58 void wxOverlayImpl::Init(wxWindowDC *dc, int x, int y, int width, int height)
59 {
60 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
61
62 m_window = dc->GetWindow();
63
64 m_rect = wxRect(x, y, width, height);
65 if ( wxDynamicCast(dc, wxClientDC) )
66 m_rect.Offset(m_window->GetClientAreaOrigin());
67
68 // FIXME: create surface with transparency or key color (?)
69 m_surface =
70 dc->GetDirectFBSurface()->CreateCompatible
71 (
72 m_rect.GetSize(),
73 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
74 );
75
76 m_window->AddOverlay(this);
77 }
78
79 void wxOverlayImpl::BeginDrawing(wxWindowDC *dc)
80 {
81 wxPoint origin(m_rect.GetPosition());
82 if ( wxDynamicCast(dc, wxClientDC) )
83 origin -= m_window->GetClientAreaOrigin();
84
85 // drawing on overlay "hijacks" existing wxWindowDC rather then using
86 // another DC, so we have to change the DC to draw on the overlay's surface.
87 // Setting m_shouldFlip is done to avoid flipping and drawing of overlays
88 // in ~wxWindowDC (we do it EndDrawing).
89 dc->DFBInit(m_surface);
90 dc->SetDeviceOrigin(-origin.x, -origin.y);
91 dc->m_shouldFlip = false;
92
93 m_isEmpty = false;
94 }
95
96 void wxOverlayImpl::EndDrawing(wxWindowDC *dc)
97 {
98 m_window->RefreshWindowRect(m_rect);
99 }
100
101 void wxOverlayImpl::Clear(wxWindowDC *dc)
102 {
103 wxASSERT_MSG( IsOk(),
104 "You cannot Clear an overlay that is not initialized" );
105
106 m_isEmpty = true;
107 }
108
109 void wxOverlayImpl::Reset()
110 {
111 if ( m_window )
112 {
113 m_window->RemoveOverlay(this);
114 m_window = NULL;
115 m_surface.Reset();
116 }
117 }