00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "OSDLBackBufferedWidget.h"
00028
00029
00030 #include "OSDLSurface.h"
00031 #include "OSDLPoint2D.h"
00032
00033
00034 #ifdef OSDL_USES_CONFIG_H
00035 #include <OSDLConfig.h>
00036 #endif // OSDL_USES_CONFIG_H
00037
00038
00039
00040
00041 using namespace Ceylan::Log ;
00042
00043 using namespace OSDL::Video ;
00044 using namespace OSDL::Video::TwoDimensional ;
00045
00046 using std::string ;
00047
00048
00049
00050
00051 BackBufferedWidget::BackBufferedWidget(
00052 Surface & container,
00053 const Point2D & relativePosition,
00054 Length width,
00055 Length height,
00056 BaseColorMode baseColorMode,
00057 Pixels::ColorDefinition baseColor,
00058 const string & title,
00059 bool minMaximizable,
00060 bool draggable,
00061 bool wrappable,
00062 bool closable ) :
00063 Widget(
00064 container,
00065 relativePosition,
00066 width,
00067 height,
00068 baseColorMode,
00069 baseColor,
00070 title,
00071 minMaximizable,
00072 draggable,
00073 wrappable,
00074 closable ),
00075 _overallSurface( 0 ),
00076 _needsBackBufferRedraw( true )
00077 {
00078
00079 #if OSDL_DEBUG_WIDGET
00080
00081 LogPlug::trace( "Back-buffered widget constructor" ) ;
00082
00083 #endif // OSDL_DEBUG_WIDGET
00084
00085
00086
00087
00088
00089
00090 _overallSurface = new Surface(
00091 container.getFlags(),
00092 width,
00093 height,
00094 container.getBitsPerPixel(),
00095 container.getPixelFormat().Rmask,
00096 container.getPixelFormat().Gmask,
00097 container.getPixelFormat().Bmask,
00098 container.getPixelFormat().Amask
00099 ) ;
00100
00101
00102
00103
00104
00105
00106
00107 _overallSurface->convertToDisplay(
00108 ( getFlags() & Surface::AlphaBlendingBlit ) != 0 ) ;
00109
00110 }
00111
00112
00113
00114 BackBufferedWidget::~BackBufferedWidget() throw()
00115 {
00116
00117 #if OSDL_DEBUG_WIDGET
00118
00119 LogPlug::trace( "Back-buffered widget destructor" ) ;
00120
00121 #endif // OSDL_DEBUG_WIDGET
00122
00123 delete _overallSurface ;
00124
00125 }
00126
00127
00128
00129 void BackBufferedWidget::resize( Length newWidth, Length newHeight,
00130 bool ignored )
00131 {
00132
00133
00134 Widget::resize( newWidth, newHeight ) ;
00135
00136 _overallSurface->resize( newWidth, newHeight ) ;
00137
00138 setBackBufferRedrawState( true ) ;
00139
00140 }
00141
00142
00143
00144 void BackBufferedWidget::setBaseColorMode( BaseColorMode newBaseColorMode,
00145 Pixels::ColorDefinition newBaseColor )
00146 {
00147
00148
00149
00150
00151
00152
00153
00154 bool mustUpdateColor = ( ( _baseColorMode == NotInitialized )
00155 && ( newBaseColorMode != NotInitialized ) )
00156 || ( ! Pixels::areEqual( newBaseColor, _baseColor ) ) ;
00157
00158 bool mustUpdateColorKey = false ;
00159
00160
00161 if ( newBaseColorMode != _baseColorMode )
00162 {
00163
00164
00165
00166
00167 if ( _baseColorMode == Colorkey )
00168 {
00169
00170
00171
00172 setColorKey( 0,
00173 _actualBaseColor ) ;
00174
00175 _overallSurface->setColorKey( 0,
00176 _actualBaseColor ) ;
00177
00178 }
00179 else
00180 {
00181
00182 if ( newBaseColorMode == Colorkey )
00183 mustUpdateColorKey = true ;
00184 }
00185
00186 _baseColorMode = newBaseColorMode ;
00187
00188 }
00189 else
00190 {
00191
00192
00193 if ( ( _baseColorMode == Colorkey ) && mustUpdateColor )
00194 mustUpdateColorKey = true ;
00195 }
00196
00197 if ( mustUpdateColor )
00198 {
00199
00200 _baseColor = newBaseColor ;
00201 _actualBaseColor = Pixels::convertColorDefinitionToPixelColor(
00202 getPixelFormat(), _baseColor ) ;
00203
00204
00205 setBackBufferRedrawState( true ) ;
00206
00207 }
00208
00209
00210 if ( mustUpdateColorKey )
00211 {
00212
00213
00214
00215
00216
00217
00218 setColorKey( ColorkeyBlit | RLEColorkeyBlit, _actualBaseColor ) ;
00219
00220 _overallSurface->setColorKey( ColorkeyBlit | RLEColorkeyBlit,
00221 _actualBaseColor ) ;
00222
00223
00224 setBackBufferRedrawState( true ) ;
00225
00226 }
00227
00228
00229 }
00230
00231
00232
00233 void BackBufferedWidget::redraw()
00234 {
00235
00236 #if OSDL_DEBUG_WIDGET
00237
00238 LogPlug::trace( "BackBufferedWidget::redraw: needs redraw attribute is "
00239 + Ceylan::toString( getRedrawState() ) + "." ) ;
00240
00241 #endif // OSDL_DEBUG_WIDGET
00242
00243
00244
00245
00246
00247
00248 Surface::redraw() ;
00249
00250
00251 try
00252 {
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 _overallSurface->blitTo( getContainer().getWidgetRenderTarget(),
00265 _upperLeftCorner ) ;
00266 }
00267 catch( const VideoException & e )
00268 {
00269 LogPlug::error(
00270 "BackBufferedWidget::redraw: blit to container failed: "
00271 + e.toString() ) ;
00272 }
00273
00274 }
00275
00276
00277
00278 void BackBufferedWidget::redrawInternal()
00279 {
00280
00281 #if OSDL_DEBUG_WIDGET
00282
00283 LogPlug::trace( "BackBufferedWidget::redrawInternal: "
00284 "needs back-buffer redraw attribute is "
00285 + Ceylan::toString( getBackBufferRedrawState() ) + "." ) ;
00286
00287 #endif // OSDL_DEBUG_WIDGET
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 if ( getBackBufferRedrawState() )
00299 {
00300
00301
00302
00303
00304
00305
00306 redrawBackBuffer() ;
00307
00308 }
00309 else
00310 {
00311
00312 #if OSDL_DEBUG_WIDGET
00313
00314 LogPlug::trace( "BackBufferedWidget::redrawInternal:"
00315 " back-buffer already available." ) ;
00316
00317 #endif // OSDL_DEBUG_WIDGET
00318
00319 }
00320
00321
00322 #if OSDL_DEBUG_WIDGET
00323
00324 LogPlug::trace( "BackBufferedWidget::redrawInternal: "
00325 "blitting back-buffer to front buffer." ) ;
00326
00327 #endif // OSDL_DEBUG_WIDGET
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 if ( getBaseColorMode() == Colorkey )
00339 _overallSurface->fill( _baseColor ) ;
00340
00341 blitTo( *_overallSurface ) ;
00342
00343 setRedrawState( false ) ;
00344
00345 }
00346
00347
00348
00349 void BackBufferedWidget::redrawBackBuffer()
00350 {
00351
00352 #if OSDL_DEBUG_WIDGET
00353
00354 LogPlug::trace( "BackBufferedWidget::redrawBackBuffer" ) ;
00355
00356 #endif // OSDL_DEBUG_WIDGET
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 setBackBufferRedrawState( false ) ;
00370
00371 }
00372
00373
00374
00375 Surface & BackBufferedWidget::getWidgetRenderTarget()
00376 {
00377
00378
00379 return *_overallSurface ;
00380
00381 }
00382
00383
00384
00385 const string BackBufferedWidget::toString( Ceylan::VerbosityLevels level ) const
00386 {
00387
00388 string res ;
00389
00390 if ( getBackBufferRedrawState() )
00391 res += "needs to be redrawn. " ;
00392 else
00393 res += "does not need to be redrawn. " ;
00394
00395 res += "Overall surface is: " + _overallSurface->toString( level ) ;
00396
00397 return "Back-buffered widget description whose back-buffer "
00398 + res + Widget::toString( level ) ;
00399
00400 }
00401
00402
00403
00404 void BackBufferedWidget::setBackBufferRedrawState( bool needsToBeRedrawn )
00405 {
00406
00407
00408
00409
00410
00411
00412
00413 if ( ( getBackBufferRedrawState() == false ) && needsToBeRedrawn )
00414 {
00415 _needsBackBufferRedraw = true ;
00416 setRedrawState( true ) ;
00417 }
00418
00419 }
00420
00421
00422
00423 bool BackBufferedWidget::getBackBufferRedrawState() const
00424 {
00425
00426 return _needsBackBufferRedraw ;
00427
00428 }
00429