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,
m_rVariable( rVariable ),
m_rCommand1( rCommand1 ), m_rCommand2( rCommand2 ),
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_cmdDownOverDown( this ), m_cmdDownDownOver( this ),
m_cmdUpOverUp( this ), m_cmdUpUpOver( this ),
m_cmdDownUp( this ), m_cmdUpHidden( 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
m_fsm.addState( "up" );
m_fsm.addState( "down" );
......@@ -109,18 +90,18 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
m_fsm.setState( "up" );
if( !m_rVariable.get() )
{
m_pImgUp = m_pImgUp1;
m_pImgOver = m_pImgOver1;
m_pImgDown = m_pImgDown1;
m_pImgUp = &m_imgUp1;
m_pImgOver = &m_imgOver1;
m_pImgDown = &m_imgDown1;
m_pImgCurrent = m_pImgUp;
m_pCommand = &m_rCommand1;
m_pTooltip = &m_tooltip1;
}
else
{
m_pImgUp = m_pImgUp2;
m_pImgOver = m_pImgOver2;
m_pImgDown = m_pImgDown2;
m_pImgUp = &m_imgUp2;
m_pImgOver = &m_imgOver2;
m_pImgDown = &m_imgDown2;
m_pImgCurrent = m_pImgDown;
m_pCommand = &m_rCommand2;
m_pTooltip = &m_tooltip2;
......@@ -131,12 +112,6 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf,
CtrlCheckbox::~CtrlCheckbox()
{
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 )
if( m_pImgCurrent )
{
// 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()
{
m_pParent->captureMouse();
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgDown;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgDown );
}
......@@ -194,12 +188,10 @@ void CtrlCheckbox::CmdDownOverUpOver::execute()
// from an object variable).
// Invert the state variable
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
if( m_pParent->m_pImgUp == m_pParent->m_pImgUp1 )
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp2;
if( m_pParent->m_pImgUp == &m_pParent->m_imgUp1 )
m_pParent->setImage( &m_pParent->m_imgUp2 );
else
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp1;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( &m_pParent->m_imgUp1 );
// Execute the command
m_pParent->m_pCommand->execute();
......@@ -208,33 +200,25 @@ void CtrlCheckbox::CmdDownOverUpOver::execute()
void CtrlCheckbox::CmdDownOverDown::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgUp );
}
void CtrlCheckbox::CmdDownDownOver::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgDown;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgDown );
}
void CtrlCheckbox::CmdUpUpOver::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgOver;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgOver );
}
void CtrlCheckbox::CmdUpOverUp::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgUp );
}
......@@ -246,17 +230,13 @@ void CtrlCheckbox::CmdDownUp::execute()
void CtrlCheckbox::CmdUpHidden::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = NULL;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( NULL );
}
void CtrlCheckbox::CmdHiddenUp::execute()
{
const OSGraphics *pOldImg = m_pParent->m_pImgCurrent;
m_pParent->m_pImgCurrent = m_pParent->m_pImgUp;
m_pParent->notifyLayoutMaxSize( pOldImg, m_pParent->m_pImgCurrent );
m_pParent->setImage( m_pParent->m_pImgUp );
}
......@@ -266,30 +246,37 @@ void CtrlCheckbox::onVarBoolUpdate( VarBool &rVariable )
}
void CtrlCheckbox::onUpdate( Subject<AnimBitmap, void*> &rBitmap, void *arg )
{
notifyLayout();
}
void CtrlCheckbox::changeButton()
{
// 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_pImgOver = m_pImgOver2;
m_pImgDown = m_pImgDown2;
m_pImgUp = &m_imgUp2;
m_pImgOver = &m_imgOver2;
m_pImgDown = &m_imgDown2;
m_pTooltip = &m_tooltip2;
m_pCommand = &m_rCommand2;
}
else
{
m_pImgUp = m_pImgUp1;
m_pImgOver = m_pImgOver1;
m_pImgDown = m_pImgDown1;
m_pImgUp = &m_imgUp1;
m_pImgOver = &m_imgOver1;
m_pImgDown = &m_imgDown1;
m_pTooltip = &m_tooltip1;
m_pCommand = &m_rCommand1;
}
// XXX: We assume that the checkbox is up
m_pImgCurrent = m_pImgUp;
setImage( m_pImgUp );
// Notify the window the tooltip has changed
notifyTooltipChange();
// Refresh
notifyLayout();
}
......@@ -28,6 +28,7 @@
#include "ctrl_generic.hpp"
#include "../utils/fsm.hpp"
#include "../utils/observer.hpp"
#include "../src/anim_bitmap.hpp"
class GenericBitmap;
class OSGraphics;
......@@ -35,7 +36,7 @@ class CmdGeneric;
/// Base class for checkbox controls
class CtrlCheckbox: public CtrlGeneric
class CtrlCheckbox: public CtrlGeneric, public Observer<AnimBitmap, void*>
{
public:
/// Create a checkbox with 6 images
......@@ -82,16 +83,16 @@ class CtrlCheckbox: public CtrlGeneric
/// Current tooltip
const UString *m_pTooltip;
/// Images of the checkbox in the different states
OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1;
OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2;
AnimBitmap m_imgUp1, m_imgOver1, m_imgDown1;
AnimBitmap m_imgUp2, m_imgOver2, m_imgDown2;
/// Current set of images (pointing to 1 or 2)
/// 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
/// callbacks (and it could be extended easily to support 3 buttons or
/// more...)
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
AnimBitmap *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image
OSGraphics *m_pImgCurrent;
AnimBitmap *m_pImgCurrent;
/// Callback objects
DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
......@@ -107,6 +108,12 @@ class CtrlCheckbox: public CtrlGeneric
/// Method called when the observed variable is modified
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
void changeButton();
};
......
......@@ -543,27 +543,27 @@ void Builder::addImage( const BuilderData::Image &rData )
{
CtrlMove *pMove = new CtrlMove( getIntf(), m_pTheme->getWindowManager(),
*pImage, *pWindow, UString( getIntf(), rData.m_help.c_str() ),
NULL);
pVisible );
pLayout->addControl( pMove, pos, rData.m_layer );
}
else if( rData.m_actionId == "resizeS" )
{
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 );
pLayout->addControl( pResize, pos, rData.m_layer );
}
else if( rData.m_actionId == "resizeE" )
{
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 );
pLayout->addControl( pResize, pos, rData.m_layer );
}
else if( rData.m_actionId == "resizeSE" )
{
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 );
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