]>
git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/src/antiflickpl.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas (@Lithuania)
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "antiflickpl.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
28 #include "antiflickpl.h"
30 /***** Implementation for class cbAntiflickerPlugin *****/
32 IMPLEMENT_DYNAMIC_CLASS( cbAntiflickerPlugin
, cbPluginBase
)
34 BEGIN_EVENT_TABLE( cbAntiflickerPlugin
, cbPluginBase
)
36 EVT_PL_START_DRAW_IN_AREA ( cbAntiflickerPlugin::OnStartDrawInArea
)
37 EVT_PL_FINISH_DRAW_IN_AREA ( cbAntiflickerPlugin::OnFinishDrawInArea
)
41 // initialization of static members
43 int cbAntiflickerPlugin::mRefCount
= 0;
45 wxBitmap
* cbAntiflickerPlugin::mpVertBuf
= 0;
46 wxBitmap
* cbAntiflickerPlugin::mpHorizBuf
= 0;
47 wxMemoryDC
* cbAntiflickerPlugin::mpVertBufDc
= 0;
48 wxMemoryDC
* cbAntiflickerPlugin::mpHorizBufDc
= 0;
52 cbAntiflickerPlugin::cbAntiflickerPlugin(void)
53 : mpLRUBufDc ( NULL
),
54 mLRUArea ( -1,-1, -1,-1 )
59 cbAntiflickerPlugin::cbAntiflickerPlugin( wxFrameLayout
* pPanel
, int paneMask
)
61 : cbPluginBase( pPanel
, paneMask
),
63 mLRUArea ( -1,-1, -1,-1 )
68 cbAntiflickerPlugin::~cbAntiflickerPlugin()
70 if ( --mRefCount
== 0 )
74 mpHorizBufDc
->SelectObject( wxNullBitmap
);
83 mpVertBufDc
->SelectObject( wxNullBitmap
);
92 wxDC
* cbAntiflickerPlugin::FindSuitableBuffer( const wxRect
& forArea
)
96 if ( mpVertBuf
->GetHeight() >= forArea
.height
&&
97 mpVertBuf
->GetWidth() >= forArea
.width
)
104 if ( mpHorizBuf
->GetHeight() >= forArea
.height
&&
105 mpHorizBuf
->GetWidth() >= forArea
.width
)
113 wxDC
* cbAntiflickerPlugin::AllocNewBuffer( const wxRect
& forArea
)
115 // TBD:: preallocate bit larger bitmap at once, to avoid
116 // excessive realocations later
118 // check whether the given area is oriented horizontally
119 // or verticallya and choose correspoinding bitmap to create or
124 if ( forArea
.height
> forArea
.width
)
126 wxSize
prevDim( 0,0 );
130 prevDim
.x
= mpVertBuf
->GetWidth();
131 prevDim
.y
= mpVertBuf
->GetHeight();
133 mpVertBufDc
->SelectObject( wxNullBitmap
);
137 mpVertBufDc
= new wxMemoryDC();
139 mpVertBuf
= new wxBitmap( int( wxMax(forArea
.width
, prevDim
.x
) ),
140 int( wxMax(forArea
.height
, prevDim
.y
) )
143 mpVertBufDc
->SelectObject( *mpVertBuf
);
149 wxSize
prevDim( 0,0 );
153 prevDim
.x
= mpHorizBuf
->GetWidth();
154 prevDim
.y
= mpHorizBuf
->GetHeight();
156 mpHorizBufDc
->SelectObject( wxNullBitmap
);
160 mpHorizBufDc
= new wxMemoryDC();
162 mpHorizBuf
= new wxBitmap( int( wxMax(forArea
.width
, prevDim
.x
) ),
163 int( wxMax(forArea
.height
, prevDim
.y
) )
166 mpHorizBufDc
->SelectObject( *mpHorizBuf
);
172 void cbAntiflickerPlugin::OnStartDrawInArea( cbStartDrawInAreaEvent
& event
)
174 wxASSERT( mpLRUBufDc
== NULL
); // DBG:: see comments in OnFinishDrawInArea(..) method
177 wxRect
& area
= event
.mArea
;
179 if ( event
.mArea
.width
< 0 ||
180 event
.mArea
.height
< 0 ) return;
182 // memorize given area
185 mLRUArea
.width
= area
.width
;
186 mLRUArea
.height
= area
.height
;
188 wxDC
* pBufDc
= FindSuitableBuffer( area
);
192 pBufDc
= AllocNewBuffer( area
);
194 pBufDc
->SetDeviceOrigin( -area
.x
, -area
.y
);
196 pBufDc
->SetClippingRegion( area
.x
, area
.y
,
197 area
.width
, area
.height
);
199 wxClientDC
clntDc( &mpLayout
->GetParentFrame() );
201 (*event
.mppDc
) = pBufDc
;
203 mpLRUBufDc
= pBufDc
; // memorize buffer, which will be flushed to screen
204 // upon "commiting" the drawing
208 mpLRUBufDc->Blit( pos.x, pos.y, size.x, size.y,
209 &clntDc, pos.x, pos.y, wxCOPY );
213 void cbAntiflickerPlugin::OnFinishDrawInArea( cbFinishDrawInAreaEvent
& event
)
215 wxRect
& area
= event
.mArea
;
217 if ( event
.mArea
.width
< 0 ||
218 event
.mArea
.height
< 0 ) return;
220 wxASSERT( mpLRUBufDc
); // DBG:: OnStartDrawInArea should be called first
222 // FOR NOW:: OnStartDrawInArea(..) should be immediatelly followed
223 // by OnFinishDrawInArea(..) for the same area
225 wxASSERT( mLRUArea
.x
== area
.x
);
226 wxASSERT( mLRUArea
.y
== area
.y
);
227 wxASSERT( mLRUArea
.width
== area
.width
);
228 wxASSERT( mLRUArea
.height
== area
.height
);
230 wxClientDC
clntDc( &mpLayout
->GetParentFrame() );
232 // "commit" drawings in one-shot
233 clntDc
.Blit( area
.x
, area
.y
, area
.width
, area
.height
,
234 mpLRUBufDc
, area
.x
, area
.y
, wxCOPY
);
236 mpLRUBufDc
->DestroyClippingRegion();