1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/overlay.cpp
3 // Purpose: wxOverlay implementation for wxDFB
4 // Author: Vaclav Slavik
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/window.h"
28 #include "wx/dcclient.h"
31 #include "wx/private/overlay.h"
32 #include "wx/dfb/dcclient.h"
33 #include "wx/dfb/private.h"
35 // ============================================================================
37 // ============================================================================
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 wxOverlayImpl::wxOverlayImpl()
49 wxOverlayImpl::~wxOverlayImpl()
54 bool wxOverlayImpl::IsOk()
56 return m_window
!= NULL
;
59 void wxOverlayImpl::Init(wxDC
*dc
, int x
, int y
, int width
, int height
)
61 wxCHECK_RET( dc
, "NULL dc pointer" );
62 wxASSERT_MSG( !IsOk() , _("You cannot Init an overlay twice") );
64 wxDFBDCImpl
* const dcimpl
= wxDynamicCast(dc
->GetImpl(), wxDFBDCImpl
);
65 wxCHECK_RET( dcimpl
, "must have a DFB wxDC" );
67 m_window
= dc
->GetWindow();
69 m_rect
= wxRect(x
, y
, width
, height
);
70 if ( wxDynamicCast(dc
, wxClientDC
) )
71 m_rect
.Offset(m_window
->GetClientAreaOrigin());
73 // FIXME: create surface with transparency or key color (?)
74 m_surface
= dcimpl
->GetDirectFBSurface()->CreateCompatible
77 wxIDirectFBSurface::CreateCompatible_NoBackBuffer
80 m_window
->AddOverlay(this);
83 void wxOverlayImpl::BeginDrawing(wxDC
*dc
)
85 wxCHECK_RET( dc
, "NULL dc pointer" );
87 wxWindowDCImpl
* const
88 dcimpl
= static_cast<wxWindowDCImpl
*>(dc
->GetImpl());
90 wxPoint
origin(m_rect
.GetPosition());
91 if ( wxDynamicCast(dc
, wxClientDC
) )
92 origin
-= m_window
->GetClientAreaOrigin();
94 // drawing on overlay "hijacks" existing wxWindowDC rather then using
95 // another DC, so we have to change the DC to draw on the overlay's surface.
96 // Setting m_shouldFlip is done to avoid flipping and drawing of overlays
97 // in ~wxWindowDC (we do it EndDrawing).
98 dcimpl
->DFBInit(m_surface
);
99 dcimpl
->m_shouldFlip
= false;
100 dc
->SetDeviceOrigin(-origin
.x
, -origin
.y
);
105 void wxOverlayImpl::EndDrawing(wxDC
*WXUNUSED(dc
))
107 m_window
->RefreshWindowRect(m_rect
);
110 void wxOverlayImpl::Clear(wxDC
*WXUNUSED(dc
))
112 wxASSERT_MSG( IsOk(),
113 "You cannot Clear an overlay that is not initialized" );
118 void wxOverlayImpl::Reset()
122 m_window
->RemoveOverlay(this);