Commit 80f538b8 authored by Cyril Deguet's avatar Cyril Deguet

* builder.cpp: the "visible" attribute is now taken into account for all images

* ctrl_checkbox.cpp: animated bitmaps are now supported in checkbox controls
parent e56193e8
...@@ -47,34 +47,15 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf, ...@@ -47,34 +47,15 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
m_rVariable( rVariable ), m_rVariable( rVariable ),
m_rCommand1( rCommand1 ), m_rCommand2( rCommand2 ), m_rCommand1( rCommand1 ), m_rCommand2( rCommand2 ),
m_tooltip1( rTooltip1 ), m_tooltip2( rTooltip2 ), m_tooltip1( rTooltip1 ), m_tooltip2( rTooltip2 ),
m_imgUp1( pIntf, rBmpUp1 ), m_imgOver1( pIntf, rBmpOver1 ),
m_imgDown1( pIntf, rBmpDown1 ), m_imgUp2( pIntf, rBmpUp2 ),
m_imgOver2( pIntf, rBmpOver2 ), m_imgDown2( pIntf, rBmpDown2 ),
m_cmdUpOverDownOver( this ), m_cmdDownOverUpOver( this ), m_cmdUpOverDownOver( this ), m_cmdDownOverUpOver( this ),
m_cmdDownOverDown( this ), m_cmdDownDownOver( this ), m_cmdDownOverDown( this ), m_cmdDownDownOver( this ),
m_cmdUpOverUp( this ), m_cmdUpUpOver( this ), m_cmdUpOverUp( this ), m_cmdUpUpOver( this ),
m_cmdDownUp( this ), m_cmdUpHidden( this ), m_cmdDownUp( this ), m_cmdUpHidden( this ),
m_cmdHiddenUp( this ) m_cmdHiddenUp( this )
{ {
// Build the images of the checkbox
OSFactory *pOsFactory = OSFactory::instance( pIntf );
m_pImgUp1 = pOsFactory->createOSGraphics( rBmpUp1.getWidth(),
rBmpUp1.getHeight() );
m_pImgUp1->drawBitmap( rBmpUp1, 0, 0 );
m_pImgDown1 = pOsFactory->createOSGraphics( rBmpDown1.getWidth(),
rBmpDown1.getHeight() );
m_pImgDown1->drawBitmap( rBmpDown1, 0, 0 );
m_pImgOver1 = pOsFactory->createOSGraphics( rBmpOver1.getWidth(),
rBmpOver1.getHeight() );
m_pImgOver1->drawBitmap( rBmpOver1, 0, 0 );
m_pImgUp2 = pOsFactory->createOSGraphics( rBmpUp2.getWidth(),
rBmpUp2.getHeight() );
m_pImgUp2->drawBitmap( rBmpUp2, 0, 0 );
m_pImgDown2 = pOsFactory->createOSGraphics( rBmpDown2.getWidth(),
rBmpDown2.getHeight() );
m_pImgDown2->drawBitmap( rBmpDown2, 0, 0 );
m_pImgOver2 = pOsFactory->createOSGraphics( rBmpOver2.getWidth(),
rBmpOver2.getHeight() );
m_pImgOver2->drawBitmap( rBmpOver2, 0, 0 );
// States // States
m_fsm.addState( "up" ); m_fsm.addState( "up" );
m_fsm.addState( "down" ); m_fsm.addState( "down" );
...@@ -109,18 +90,18 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf, ...@@ -109,18 +90,18 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
m_fsm.setState( "up" ); m_fsm.setState( "up" );
if( !m_rVariable.get() ) if( !m_rVariable.get() )
{ {
m_pImgUp = m_pImgUp1; m_pImgUp = &m_imgUp1;
m_pImgOver = m_pImgOver1; m_pImgOver = &m_imgOver1;
m_pImgDown = m_pImgDown1; m_pImgDown = &m_imgDown1;
m_pImgCurrent = m_pImgUp; m_pImgCurrent = m_pImgUp;
m_pCommand = &m_rCommand1; m_pCommand = &m_rCommand1;
m_pTooltip = &m_tooltip1; m_pTooltip = &m_tooltip1;
} }
else else
{ {
m_pImgUp = m_pImgUp2; m_pImgUp = &m_imgUp2;
m_pImgOver = m_pImgOver2; m_pImgOver = &m_imgOver2;
m_pImgDown = m_pImgDown2; m_pImgDown = &m_imgDown2;
m_pImgCurrent = m_pImgDown; m_pImgCurrent = m_pImgDown;
m_pCommand = &m_rCommand2; m_pCommand = &m_rCommand2;
m_pTooltip = &m_tooltip2; m_pTooltip = &m_tooltip2;
...@@ -131,12 +112,6 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf, ...@@ -131,12 +112,6 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
CtrlCheckbox::~CtrlCheckbox() CtrlCheckbox::~CtrlCheckbox()
{ {
m_rVariable.delObserver( this ); m_rVariable.delObserver( this );
SKINS_DELETE( m_pImgUp1 );
SKINS_DELETE( m_pImgDown1 );
SKINS_DELETE( m_pImgOver1 );
SKINS_DELETE( m_pImgUp2 );
SKINS_DELETE( m_pImgDown2 );
SKINS_DELETE( m_pImgOver2 );
} }
...@@ -164,17 +139,36 @@ void CtrlCheckbox::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -164,17 +139,36 @@ void CtrlCheckbox::draw( OSGraphics &rImage, int xDest, int yDest )
if( m_pImgCurrent ) if( m_pImgCurrent )
{ {
// Draw the current image // Draw the current image
rImage.drawGraphics( *m_pImgCurrent, 0, 0, xDest, yDest ); m_pImgCurrent->draw( rImage, xDest, yDest );
}
}
void CtrlCheckbox::setImage( AnimBitmap *pImg )
{
AnimBitmap *pOldImg = m_pImgCurrent;
m_pImgCurrent = pImg;
if( pOldImg )
{
pOldImg->stopAnim();
pOldImg->delObserver( this );
}
if( pImg )
{
pImg->startAnim();
pImg->addObserver( this );
} }
notifyLayoutMaxSize( pOldImg, pImg );
} }
void CtrlCheckbox::CmdUpOverDownOver::execute() void CtrlCheckbox::CmdUpOverDownOver::execute()
{ {
m_pParent->captureMouse(); m_pParent->captureMouse();
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgDown );
m_pParent->m_pImgCurrent = m_pParent->m_pImgDown;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
...@@ -194,12 +188,10 @@ void CtrlCheckbox::CmdDownOverUpOver::execute() ...@@ -194,12 +188,10 @@ void CtrlCheckbox::CmdDownOverUpOver::execute()
// from an object variable). // from an object variable).
// Invert the state variable // Invert the state variable
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; if( m_pParent->m_pImgUp == &m_pParent->m_imgUp1 )
if( m_pParent->m_pImgUp == m_pParent->m_pImgUp1 ) m_pParent->setImage( &m_pParent->m_imgUp2 );
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp2;
else else
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp1; m_pParent->setImage( &m_pParent->m_imgUp1 );
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
// Execute the command // Execute the command
m_pParent->m_pCommand->execute(); m_pParent->m_pCommand->execute();
...@@ -208,33 +200,25 @@ void CtrlCheckbox::CmdDownOverUpOver::execute() ...@@ -208,33 +200,25 @@ void CtrlCheckbox::CmdDownOverUpOver::execute()
void CtrlCheckbox::CmdDownOverDown::execute() void CtrlCheckbox::CmdDownOverDown::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgUp );
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
void CtrlCheckbox::CmdDownDownOver::execute() void CtrlCheckbox::CmdDownDownOver::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgDown );
m_pParent->m_pImgCurrent = m_pParent->m_pImgDown;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
void CtrlCheckbox::CmdUpUpOver::execute() void CtrlCheckbox::CmdUpUpOver::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgOver );
m_pParent->m_pImgCurrent = m_pParent->m_pImgOver;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
void CtrlCheckbox::CmdUpOverUp::execute() void CtrlCheckbox::CmdUpOverUp::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgUp );
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
...@@ -246,17 +230,13 @@ void CtrlCheckbox::CmdDownUp::execute() ...@@ -246,17 +230,13 @@ void CtrlCheckbox::CmdDownUp::execute()
void CtrlCheckbox::CmdUpHidden::execute() void CtrlCheckbox::CmdUpHidden::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( NULL );
m_pParent->m_pImgCurrent = NULL;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
void CtrlCheckbox::CmdHiddenUp::execute() void CtrlCheckbox::CmdHiddenUp::execute()
{ {
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent; m_pParent->setImage( m_pParent->m_pImgUp );
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
} }
...@@ -266,30 +246,37 @@ void CtrlCheckbox::onVarBoolUpdate( VarBool &rVariable ) ...@@ -266,30 +246,37 @@ void CtrlCheckbox::onVarBoolUpdate( VarBool &rVariable )
} }
void CtrlCheckbox::onUpdate( Subject<AnimBitmap, void*> &rBitmap, void *arg )
{
notifyLayout();
}
void CtrlCheckbox::changeButton() void CtrlCheckbox::changeButton()
{ {
// Are we using the first set of images or the second one? // Are we using the first set of images or the second one?
if( m_pImgUp == m_pImgUp1 ) if( m_pImgUp == &m_imgUp1 )
{ {
m_pImgUp = m_pImgUp2; m_pImgUp = &m_imgUp2;
m_pImgOver = m_pImgOver2; m_pImgOver = &m_imgOver2;
m_pImgDown = m_pImgDown2; m_pImgDown = &m_imgDown2;
m_pTooltip = &m_tooltip2; m_pTooltip = &m_tooltip2;
m_pCommand = &m_rCommand2; m_pCommand = &m_rCommand2;
} }
else else
{ {
m_pImgUp = m_pImgUp1; m_pImgUp = &m_imgUp1;
m_pImgOver = m_pImgOver1; m_pImgOver = &m_imgOver1;
m_pImgDown = m_pImgDown1; m_pImgDown = &m_imgDown1;
m_pTooltip = &m_tooltip1; m_pTooltip = &m_tooltip1;
m_pCommand = &m_rCommand1; m_pCommand = &m_rCommand1;
} }
// XXX: We assume that the checkbox is up // XXX: We assume that the checkbox is up
m_pImgCurrent = m_pImgUp; setImage( m_pImgUp );
// Notify the window the tooltip has changed // Notify the window the tooltip has changed
notifyTooltipChange(); notifyTooltipChange();
// Refresh // Refresh
notifyLayout(); notifyLayout();
} }
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ctrl_generic.hpp" #include "ctrl_generic.hpp"
#include "../utils/fsm.hpp" #include "../utils/fsm.hpp"
#include "../utils/observer.hpp" #include "../utils/observer.hpp"
#include "../src/anim_bitmap.hpp"
class GenericBitmap; class GenericBitmap;
class OSGraphics; class OSGraphics;
...@@ -35,7 +36,7 @@ class CmdGeneric; ...@@ -35,7 +36,7 @@ class CmdGeneric;
/// Base class for checkbox controls /// Base class for checkbox controls
class CtrlCheckbox: public CtrlGeneric class CtrlCheckbox: public CtrlGeneric, public Observer<AnimBitmap, void*>
{ {
public: public:
/// Create a checkbox with 6 images /// Create a checkbox with 6 images
...@@ -82,16 +83,16 @@ class CtrlCheckbox: public CtrlGeneric ...@@ -82,16 +83,16 @@ class CtrlCheckbox: public CtrlGeneric
/// Current tooltip /// Current tooltip
const UString *m_pTooltip; const UString *m_pTooltip;
/// Images of the checkbox in the different states /// Images of the checkbox in the different states
OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1; AnimBitmap m_imgUp1, m_imgOver1, m_imgDown1;
OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2; AnimBitmap m_imgUp2, m_imgOver2, m_imgDown2;
/// Current set of images (pointing to 1 or 2) /// Current set of images (pointing to 1 or 2)
/// In fact, we consider here that a checkbox acts like 2 buttons, in a /// In fact, we consider here that a checkbox acts like 2 buttons, in a
/// symetric way; this is a small trick to avoid multiplicating the /// symetric way; this is a small trick to avoid multiplicating the
/// callbacks (and it could be extended easily to support 3 buttons or /// callbacks (and it could be extended easily to support 3 buttons or
/// more...) /// more...)
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown; AnimBitmap *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image /// Current image
OSGraphics *m_pImgCurrent; AnimBitmap *m_pImgCurrent;
/// Callback objects /// Callback objects
DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver ) DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
...@@ -107,6 +108,12 @@ class CtrlCheckbox: public CtrlGeneric ...@@ -107,6 +108,12 @@ class CtrlCheckbox: public CtrlGeneric
/// Method called when the observed variable is modified /// Method called when the observed variable is modified
virtual void onVarBoolUpdate( VarBool &rVariable ); virtual void onVarBoolUpdate( VarBool &rVariable );
/// Method called when an animated bitmap changes
virtual void onUpdate( Subject<AnimBitmap, void*> &rBitmap, void* );
/// Change the current image
void setImage( AnimBitmap *pImg );
/// Helper function to update the current state of images /// Helper function to update the current state of images
void changeButton(); void changeButton();
}; };
......
...@@ -543,27 +543,27 @@ void Builder::addImage( const BuilderData::Image &rData ) ...@@ -543,27 +543,27 @@ void Builder::addImage( const BuilderData::Image &rData )
{ {
CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(), CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
*pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ), *pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
NULL); pVisible );
pLayout->addControl( pMove, pos, rData.m_layer ); pLayout->addControl( pMove, pos, rData.m_layer );
} }
else if( rData.m_actionId == "resizeS" ) else if( rData.m_actionId == "resizeS" )
{ {
CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout, CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
UString( getIntf(), rData.m_help.c_str() ), NULL, UString( getIntf(), rData.m_help.c_str() ), pVisible,
CtrlResize::kResizeS ); CtrlResize::kResizeS );
pLayout->addControl( pResize, pos, rData.m_layer ); pLayout->addControl( pResize, pos, rData.m_layer );
} }
else if( rData.m_actionId == "resizeE" ) else if( rData.m_actionId == "resizeE" )
{ {
CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout, CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
UString( getIntf(), rData.m_help.c_str() ), NULL, UString( getIntf(), rData.m_help.c_str() ), pVisible,
CtrlResize::kResizeE ); CtrlResize::kResizeE );
pLayout->addControl( pResize, pos, rData.m_layer ); pLayout->addControl( pResize, pos, rData.m_layer );
} }
else if( rData.m_actionId == "resizeSE" ) else if( rData.m_actionId == "resizeSE" )
{ {
CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout, CtrlResize *pResize = new CtrlResize( getIntf(), *pImage, *pLayout,
UString( getIntf(), rData.m_help.c_str() ), NULL, UString( getIntf(), rData.m_help.c_str() ), pVisible,
CtrlResize::kResizeSE ); CtrlResize::kResizeSE );
pLayout->addControl( pResize, pos, rData.m_layer ); pLayout->addControl( pResize, pos, rData.m_layer );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment