]> git.saurik.com Git - wxWidgets.git/blame - src/common/overlaycmn.cpp
simplify code so it always returns the same object
[wxWidgets.git] / src / common / overlaycmn.cpp
CommitLineData
30c841c8
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/overlaycmn.cpp
3// Purpose: common wxOverlay code
4// Author: Stefan Csomor
5// Modified by:
6// Created: 2006-10-20
7// RCS-ID: $Id$
8// Copyright: (c) wxWidgets team
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#include "wx/overlay.h"
28#include "wx/private/overlay.h"
29#include "wx/dcclient.h"
30#include "wx/dcmemory.h"
31
32// ============================================================================
33// implementation
34// ============================================================================
35
36// ----------------------------------------------------------------------------
37// wxOverlay
38// ----------------------------------------------------------------------------
39
40wxOverlay::wxOverlay()
41{
42 m_impl = new wxOverlayImpl();
43 m_inDrawing = false;
44}
45
46wxOverlay::~wxOverlay()
47{
78ce938e 48 delete m_impl;
30c841c8
VS
49}
50
51bool wxOverlay::IsOk()
52{
53 return m_impl->IsOk();
54}
55
156310e2 56void wxOverlay::Init( wxDC* dc, int x , int y , int width , int height )
30c841c8
VS
57{
58 m_impl->Init(dc, x, y, width, height);
59}
60
156310e2 61void wxOverlay::BeginDrawing( wxDC* dc)
30c841c8
VS
62{
63 m_impl->BeginDrawing(dc);
64 m_inDrawing = true ;
65}
66
156310e2 67void wxOverlay::EndDrawing( wxDC* dc)
30c841c8
VS
68{
69 m_impl->EndDrawing(dc);
70 m_inDrawing = false ;
71}
72
156310e2 73void wxOverlay::Clear( wxDC* dc)
30c841c8
VS
74{
75 m_impl->Clear(dc);
76}
77
78void wxOverlay::Reset()
79{
80 wxASSERT_MSG(m_inDrawing==false,wxT("cannot reset overlay during drawing"));
81 m_impl->Reset();
82}
83
84
85// ----------------------------------------------------------------------------
86// wxDCOverlay
87// ----------------------------------------------------------------------------
88
156310e2 89wxDCOverlay::wxDCOverlay(wxOverlay &overlay, wxDC *dc, int x , int y , int width , int height) :
30c841c8
VS
90 m_overlay(overlay)
91{
92 Init(dc, x, y, width, height);
93}
94
156310e2 95wxDCOverlay::wxDCOverlay(wxOverlay &overlay, wxDC *dc) :
30c841c8
VS
96 m_overlay(overlay)
97{
98 int width;
99 int height;
100 dc->GetSize(&width,&height);
101 Init(dc, 0, 0, width, height);
102}
103
104wxDCOverlay::~wxDCOverlay()
105{
106 m_overlay.EndDrawing(m_dc);
107}
108
156310e2 109void wxDCOverlay::Init(wxDC *dc, int x , int y , int width , int height )
30c841c8
VS
110{
111 m_dc = dc ;
112 if ( !m_overlay.IsOk() )
113 {
114 m_overlay.Init(dc,x,y,width,height);
115 }
116 m_overlay.BeginDrawing(dc);
117}
118
5abbb704 119void wxDCOverlay::Clear()
30c841c8
VS
120{
121 m_overlay.Clear(m_dc);
122}
123
124// ----------------------------------------------------------------------------
125// generic implementation of wxOverlayImpl
126// ----------------------------------------------------------------------------
127
69a5bc23 128#ifndef wxHAS_NATIVE_OVERLAY
30c841c8
VS
129
130wxOverlayImpl::wxOverlayImpl()
131{
30c841c8 132 m_window = NULL ;
30c841c8
VS
133 m_x = m_y = m_width = m_height = 0 ;
134}
135
136wxOverlayImpl::~wxOverlayImpl()
137{
138}
139
5abbb704 140bool wxOverlayImpl::IsOk()
30c841c8 141{
a1b806b9 142 return m_bmpSaved.IsOk() ;
30c841c8
VS
143}
144
156310e2 145void wxOverlayImpl::Init( wxDC* dc, int x , int y , int width , int height )
30c841c8 146{
30c841c8 147 m_window = dc->GetWindow();
30c841c8
VS
148 wxMemoryDC dcMem ;
149 m_bmpSaved.Create( width, height );
150 dcMem.SelectObject( m_bmpSaved );
151 m_x = x ;
152 m_y = y ;
153 m_width = width ;
154 m_height = height ;
30c841c8
VS
155 dcMem.Blit(0, 0, m_width, m_height,
156 dc, x, y);
157 dcMem.SelectObject( wxNullBitmap );
158}
159
156310e2 160void wxOverlayImpl::Clear(wxDC* dc)
30c841c8
VS
161{
162 wxMemoryDC dcMem ;
163 dcMem.SelectObject( m_bmpSaved );
164 dc->Blit( m_x, m_y, m_width, m_height , &dcMem , 0 , 0 );
165 dcMem.SelectObject( wxNullBitmap );
166}
167
168void wxOverlayImpl::Reset()
169{
170 m_bmpSaved = wxBitmap();
171}
172
156310e2 173void wxOverlayImpl::BeginDrawing(wxDC* WXUNUSED(dc))
30c841c8
VS
174{
175}
176
156310e2 177void wxOverlayImpl::EndDrawing(wxDC* WXUNUSED(dc))
30c841c8
VS
178{
179}
180
181#endif // !wxHAS_NATIVE_OVERLAY
182
183