1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/overlay.cpp
3 // Purpose: wxOverlay implementation for wxDFB
4 // Author: Vaclav Slavik
5 // Created: 2006-10-20
6 // Copyright: (c) wxWidgets team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
20
21
22 #ifndef WX_PRECOMP
23 #include "wx/window.h"
24 #include "wx/dcclient.h"
25 #endif
26
27 #include "wx/private/overlay.h"
28 #include "wx/dfb/dcclient.h"
29 #include "wx/dfb/private.h"
30
31 // ============================================================================
32 // implementation
33 // ============================================================================
34
35 // ----------------------------------------------------------------------------
36 // wxOverlay
37 // ----------------------------------------------------------------------------
38
wxOverlayImpl()39 wxOverlayImpl::wxOverlayImpl()
40 {
41 m_window = NULL;
42 m_isEmpty = true;
43 }
44
~wxOverlayImpl()45 wxOverlayImpl::~wxOverlayImpl()
46 {
47 Reset();
48 }
49
IsOk()50 bool wxOverlayImpl::IsOk()
51 {
52 return m_window != NULL;
53 }
54
Init(wxDC * dc,int x,int y,int width,int height)55 void wxOverlayImpl::Init(wxDC *dc, int x, int y, int width, int height)
56 {
57 wxCHECK_RET( dc, "NULL dc pointer" );
58 wxASSERT_MSG( !IsOk() , "You cannot Init an overlay twice" );
59
60 wxDFBDCImpl * const dcimpl = wxDynamicCast(dc->GetImpl(), wxDFBDCImpl);
61 wxCHECK_RET( dcimpl, "must have a DFB wxDC" );
62
63 m_window = dc->GetWindow();
64
65 m_rect = wxRect(x, y, width, height);
66 if ( wxDynamicCast(dc, wxClientDC) )
67 m_rect.Offset(m_window->GetClientAreaOrigin());
68
69 // FIXME: create surface with transparency or key color (?)
70 m_surface = dcimpl->GetDirectFBSurface()->CreateCompatible
71 (
72 m_rect.GetSize(),
73 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
74 );
75
76 m_window->AddOverlay(this);
77 }
78
BeginDrawing(wxDC * dc)79 void wxOverlayImpl::BeginDrawing(wxDC *dc)
80 {
81 wxCHECK_RET( dc, "NULL dc pointer" );
82
83 wxWindowDCImpl * const
84 dcimpl = static_cast<wxWindowDCImpl *>(dc->GetImpl());
85
86 wxPoint origin(m_rect.GetPosition());
87 if ( wxDynamicCast(dc, wxClientDC) )
88 origin -= m_window->GetClientAreaOrigin();
89
90 // drawing on overlay "hijacks" existing wxWindowDC rather then using
91 // another DC, so we have to change the DC to draw on the overlay's surface.
92 // Setting m_shouldFlip is done to avoid flipping and drawing of overlays
93 // in ~wxWindowDC (we do it EndDrawing).
94 dcimpl->DFBInit(m_surface);
95 dcimpl->m_shouldFlip = false;
96 dc->SetDeviceOrigin(-origin.x, -origin.y);
97
98 m_isEmpty = false;
99 }
100
EndDrawing(wxDC * WXUNUSED (dc))101 void wxOverlayImpl::EndDrawing(wxDC *WXUNUSED(dc))
102 {
103 m_window->RefreshWindowRect(m_rect);
104 }
105
Clear(wxDC * WXUNUSED (dc))106 void wxOverlayImpl::Clear(wxDC *WXUNUSED(dc))
107 {
108 wxASSERT_MSG( IsOk(),
109 "You cannot Clear an overlay that is not initialized" );
110
111 m_isEmpty = true;
112 }
113
Reset()114 void wxOverlayImpl::Reset()
115 {
116 if ( m_window )
117 {
118 m_window->RemoveOverlay(this);
119 m_window = NULL;
120 m_surface.Reset();
121 }
122 }
123