Commit 64a27c19 authored by Cyril Deguet's avatar Cyril Deguet

* all: use command objects in FSM instead of C-style callbacks

parent f6fd8d49
...@@ -37,15 +37,11 @@ CtrlButton::CtrlButton( intf_thread_t *pIntf, const GenericBitmap &rBmpUp, ...@@ -37,15 +37,11 @@ CtrlButton::CtrlButton( intf_thread_t *pIntf, const GenericBitmap &rBmpUp,
VarBool *pVisible ): VarBool *pVisible ):
CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
m_rCommand( rCommand ), m_tooltip( rTooltip ), m_rCommand( rCommand ), m_tooltip( rTooltip ),
m_cmdUpOverDownOver( this, &transUpOverDownOver ), m_cmdUpOverDownOver( pIntf, this ), m_cmdDownOverUpOver( pIntf, this ),
m_cmdDownOverUpOver( this, &transDownOverUpOver ), m_cmdDownOverDown( pIntf, this ), m_cmdDownDownOver( pIntf, this ),
m_cmdDownOverDown( this, &transDownOverDown ), m_cmdUpOverUp( pIntf, this ), m_cmdUpUpOver( pIntf, this ),
m_cmdDownDownOver( this, &transDownDownOver ), m_cmdDownUp( pIntf, this ), m_cmdUpHidden( pIntf, this ),
m_cmdUpOverUp( this, &transUpOverUp ), m_cmdHiddenUp( pIntf, this )
m_cmdUpUpOver( this, &transUpUpOver ),
m_cmdDownUp( this, &transDownUp ),
m_cmdUpHidden( this, &transUpHidden ),
m_cmdHiddenUp( this, &transHiddenUp )
{ {
// Build the images of the button // Build the images of the button
OSFactory *pOsFactory = OSFactory::instance( pIntf ); OSFactory *pOsFactory = OSFactory::instance( pIntf );
...@@ -129,85 +125,76 @@ void CtrlButton::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -129,85 +125,76 @@ void CtrlButton::draw( OSGraphics &rImage, int xDest, int yDest )
} }
void CtrlButton::transUpOverDownOver( SkinObject *pCtrl ) void CtrlButton::CmdUpOverDownOver::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; m_pControl->captureMouse();
pThis->captureMouse(); const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgDown;
pThis->m_pImg = pThis->m_pImgDown; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transDownOverUpOver( SkinObject *pCtrl ) void CtrlButton::CmdDownOverUpOver::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse(); const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgUp;
pThis->m_pImg = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
// Execute the command associated to this button // Execute the command associated to this button
pThis->m_rCommand.execute(); m_pControl->m_rCommand.execute();
} }
void CtrlButton::transDownOverDown( SkinObject *pCtrl ) void CtrlButton::CmdDownOverDown::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgUp;
pThis->m_pImg = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transDownDownOver( SkinObject *pCtrl ) void CtrlButton::CmdDownDownOver::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgDown;
pThis->m_pImg = pThis->m_pImgDown; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transUpUpOver( SkinObject *pCtrl ) void CtrlButton::CmdUpUpOver::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgOver;
pThis->m_pImg = pThis->m_pImgOver; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transUpOverUp( SkinObject *pCtrl ) void CtrlButton::CmdUpOverUp::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgUp;
pThis->m_pImg = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transDownUp( SkinObject *pCtrl ) void CtrlButton::CmdDownUp::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
} }
void CtrlButton::transUpHidden( SkinObject *pCtrl ) void CtrlButton::CmdUpHidden::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = NULL;
pThis->m_pImg = NULL; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
void CtrlButton::transHiddenUp( SkinObject *pCtrl ) void CtrlButton::CmdHiddenUp::execute()
{ {
CtrlButton *pThis = (CtrlButton*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImg;
const OSGraphics *pOldImg = pThis->m_pImg; m_pControl->m_pImg = m_pControl->m_pImgUp;
pThis->m_pImg = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImg );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImg );
} }
...@@ -68,31 +68,21 @@ class CtrlButton: public CtrlGeneric ...@@ -68,31 +68,21 @@ class CtrlButton: public CtrlGeneric
CmdGeneric &m_rCommand; CmdGeneric &m_rCommand;
/// Tooltip text /// Tooltip text
const UString m_tooltip; const UString m_tooltip;
/// Callbacks objects
Callback m_cmdUpOverDownOver;
Callback m_cmdDownOverUpOver;
Callback m_cmdDownOverDown;
Callback m_cmdDownDownOver;
Callback m_cmdUpOverUp;
Callback m_cmdUpUpOver;
Callback m_cmdDownUp;
Callback m_cmdUpHidden;
Callback m_cmdHiddenUp;
/// Images of the button in the different states /// Images of the button in the different states
OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown; OSGraphics *m_pImgUp, *m_pImgOver, *m_pImgDown;
/// Current image /// Current image
OSGraphics *m_pImg; OSGraphics *m_pImg;
/// Callback functions /// Callback objects
static void transUpOverDownOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, UpOverDownOver )
static void transDownOverUpOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, DownOverUpOver )
static void transDownOverDown( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, DownOverDown )
static void transDownDownOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, DownDownOver )
static void transUpOverUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, UpOverUp )
static void transUpUpOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, UpUpOver )
static void transDownUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, DownUp )
static void transUpHidden( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, UpHidden )
static void transHiddenUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlButton, HiddenUp )
}; };
......
...@@ -47,15 +47,11 @@ CtrlCheckbox::CtrlCheckbox( intf_thread_t *pIntf, ...@@ -47,15 +47,11 @@ 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_cmdUpOverDownOver( this, &transUpOverDownOver ), m_cmdUpOverDownOver( pIntf, this ), m_cmdDownOverUpOver( pIntf, this ),
m_cmdDownOverUpOver( this, &transDownOverUpOver ), m_cmdDownOverDown( pIntf, this ), m_cmdDownDownOver( pIntf, this ),
m_cmdDownOverDown( this, &transDownOverDown ), m_cmdUpOverUp( pIntf, this ), m_cmdUpUpOver( pIntf, this ),
m_cmdDownDownOver( this, &transDownDownOver ), m_cmdDownUp( pIntf, this ), m_cmdUpHidden( pIntf, this ),
m_cmdUpOverUp( this, &transUpOverUp ), m_cmdHiddenUp( pIntf, this )
m_cmdUpUpOver( this, &transUpUpOver ),
m_cmdDownUp( this, &transDownUp ),
m_cmdUpHidden( this, &transUpHidden ),
m_cmdHiddenUp( this, &transHiddenUp )
{ {
// Build the images of the checkbox // Build the images of the checkbox
OSFactory *pOsFactory = OSFactory::instance( pIntf ); OSFactory *pOsFactory = OSFactory::instance( pIntf );
...@@ -173,89 +169,80 @@ void CtrlCheckbox::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -173,89 +169,80 @@ void CtrlCheckbox::draw( OSGraphics &rImage, int xDest, int yDest )
} }
void CtrlCheckbox::transUpOverDownOver( SkinObject *pCtrl ) void CtrlCheckbox::CmdUpOverDownOver::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; m_pControl->captureMouse();
pThis->captureMouse(); const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgDown;
pThis->m_pImgCurrent = pThis->m_pImgDown; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transDownOverUpOver( SkinObject *pCtrl ) void CtrlCheckbox::CmdDownOverUpOver::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
// Invert the state variable // Invert the state variable
const OSGraphics *pOldImg = pThis->m_pImgCurrent; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
pThis->m_pImgCurrent = pThis->m_pImgUp; m_pControl->m_pImgCurrent = m_pControl->m_pImgUp;
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent ); m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
// Execute the command // Execute the command
pThis->m_pCommand->execute(); m_pControl->m_pCommand->execute();
} }
void CtrlCheckbox::transDownOverDown( SkinObject *pCtrl ) void CtrlCheckbox::CmdDownOverDown::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgUp;
pThis->m_pImgCurrent = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transDownDownOver( SkinObject *pCtrl ) void CtrlCheckbox::CmdDownDownOver::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgDown;
pThis->m_pImgCurrent = pThis->m_pImgDown; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transUpUpOver( SkinObject *pCtrl ) void CtrlCheckbox::CmdUpUpOver::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgOver;
pThis->m_pImgCurrent = pThis->m_pImgOver; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transUpOverUp( SkinObject *pCtrl ) void CtrlCheckbox::CmdUpOverUp::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgUp;
pThis->m_pImgCurrent = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transDownUp( SkinObject *pCtrl ) void CtrlCheckbox::CmdDownUp::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
} }
void CtrlCheckbox::transUpHidden( SkinObject *pCtrl ) void CtrlCheckbox::CmdUpHidden::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = NULL;
pThis->m_pImgCurrent = NULL; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
void CtrlCheckbox::transHiddenUp( SkinObject *pCtrl ) void CtrlCheckbox::CmdHiddenUp::execute()
{ {
CtrlCheckbox *pThis = (CtrlCheckbox*)pCtrl; const OSGraphics *pOldImg = m_pControl->m_pImgCurrent;
const OSGraphics *pOldImg = pThis->m_pImgCurrent; m_pControl->m_pImgCurrent = m_pControl->m_pImgUp;
pThis->m_pImgCurrent = pThis->m_pImgUp; m_pControl->notifyLayoutMaxSize( pOldImg, m_pControl->m_pImgCurrent );
pThis->notifyLayoutMaxSize( pOldImg, pThis->m_pImgCurrent );
} }
...@@ -292,4 +279,3 @@ void CtrlCheckbox::changeButton() ...@@ -292,4 +279,3 @@ void CtrlCheckbox::changeButton()
// Refresh // Refresh
notifyLayout(); notifyLayout();
} }
...@@ -81,16 +81,6 @@ class CtrlCheckbox: public CtrlGeneric ...@@ -81,16 +81,6 @@ class CtrlCheckbox: public CtrlGeneric
const UString m_tooltip1, m_tooltip2; const UString m_tooltip1, m_tooltip2;
/// Current tooltip /// Current tooltip
const UString *m_pTooltip; const UString *m_pTooltip;
/// Callbacks objects
Callback m_cmdUpOverDownOver;
Callback m_cmdDownOverUpOver;
Callback m_cmdDownOverDown;
Callback m_cmdDownDownOver;
Callback m_cmdUpOverUp;
Callback m_cmdUpUpOver;
Callback m_cmdDownUp;
Callback m_cmdUpHidden;
Callback m_cmdHiddenUp;
/// Images of the checkbox in the different states /// Images of the checkbox in the different states
OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1; OSGraphics *m_pImgUp1, *m_pImgOver1, *m_pImgDown1;
OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2; OSGraphics *m_pImgUp2, *m_pImgOver2, *m_pImgDown2;
...@@ -103,16 +93,16 @@ class CtrlCheckbox: public CtrlGeneric ...@@ -103,16 +93,16 @@ class CtrlCheckbox: public CtrlGeneric
/// Current image /// Current image
OSGraphics *m_pImgCurrent; OSGraphics *m_pImgCurrent;
/// Callback functions /// Callback objects
static void transUpOverDownOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, UpOverDownOver )
static void transDownOverUpOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, DownOverUpOver )
static void transDownOverDown( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, DownOverDown )
static void transDownDownOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, DownDownOver )
static void transUpOverUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, UpOverUp )
static void transUpUpOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, UpUpOver )
static void transDownUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, DownUp )
static void transUpHidden( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, UpHidden )
static void transHiddenUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlCheckbox, HiddenUp )
/// 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 );
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "../utils/fsm.hpp" #include "../utils/fsm.hpp"
#include "../utils/ustring.hpp" #include "../utils/ustring.hpp"
#include "../utils/observer.hpp" #include "../utils/observer.hpp"
#include "../commands/cmd_generic.hpp"
class EvtGeneric; class EvtGeneric;
class OSGraphics; class OSGraphics;
...@@ -133,4 +134,21 @@ class CtrlGeneric: public SkinObject, public Observer<VarBool> ...@@ -133,4 +134,21 @@ class CtrlGeneric: public SkinObject, public Observer<VarBool>
typedef CountedPtr<CtrlGeneric> CtrlGenericPtr; typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;
// Macro to define a control action command
#define DEFINE_CALLBACK( control, action ) \
class Cmd##action: public CmdGeneric \
{ \
public: \
Cmd##action( intf_thread_t *pIntf, control *pControl ): \
CmdGeneric( pIntf ), m_pControl( pControl) {} \
virtual ~Cmd##action() {} \
virtual void execute(); \
virtual string getType() const { return "Cmd" #control #action; } \
private: \
control *m_pControl; \
\
} m_cmd##action; \
friend class Cmd##action;
#endif #endif
...@@ -37,9 +37,9 @@ CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager, ...@@ -37,9 +37,9 @@ CtrlMove::CtrlMove( intf_thread_t *pIntf, WindowManager &rWindowManager,
CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
m_rWindowManager( rWindowManager ), m_rWindowManager( rWindowManager ),
m_rCtrl( rCtrl ), m_rWindow( rWindow ), m_rCtrl( rCtrl ), m_rWindow( rWindow ),
m_cmdMovingMoving( this, &transMovingMoving ), m_cmdMovingMoving( pIntf, this ),
m_cmdStillMoving( this, &transStillMoving ), m_cmdStillMoving( pIntf, this ),
m_cmdMovingStill( this, &transMovingStill ) m_cmdMovingStill( pIntf, this )
{ {
m_pEvt = NULL; m_pEvt = NULL;
m_xPos = 0; m_xPos = 0;
...@@ -96,39 +96,35 @@ void CtrlMove::handleEvent( EvtGeneric &rEvent ) ...@@ -96,39 +96,35 @@ void CtrlMove::handleEvent( EvtGeneric &rEvent )
} }
void CtrlMove::transStillMoving( SkinObject *pCtrl ) void CtrlMove::CmdStillMoving::execute()
{ {
CtrlMove *pThis = (CtrlMove*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
pThis->m_xPos = pEvtMouse->getXPos(); m_pControl->m_xPos = pEvtMouse->getXPos();
pThis->m_yPos = pEvtMouse->getYPos(); m_pControl->m_yPos = pEvtMouse->getYPos();
pThis->captureMouse(); m_pControl->captureMouse();
pThis->m_rWindowManager.startMove( pThis->m_rWindow ); m_pControl->m_rWindowManager.startMove( m_pControl->m_rWindow );
} }
void CtrlMove::transMovingMoving( SkinObject *pCtrl ) void CtrlMove::CmdMovingMoving::execute()
{ {
CtrlMove *pThis = (CtrlMove*)pCtrl; EvtMotion *pEvtMotion = (EvtMotion*)m_pControl->m_pEvt;
EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
int xNewLeft = pEvtMotion->getXPos() - pThis->m_xPos + int xNewLeft = pEvtMotion->getXPos() - m_pControl->m_xPos +
pThis->m_rWindow.getLeft(); m_pControl->m_rWindow.getLeft();
int yNewTop = pEvtMotion->getYPos() - pThis->m_yPos + int yNewTop = pEvtMotion->getYPos() - m_pControl->m_yPos +
pThis->m_rWindow.getTop(); m_pControl->m_rWindow.getTop();
pThis->m_rWindowManager.move( pThis->m_rWindow, xNewLeft, yNewTop ); m_pControl->m_rWindowManager.move( m_pControl->m_rWindow, xNewLeft, yNewTop );
} }
void CtrlMove::transMovingStill( SkinObject *pCtrl ) void CtrlMove::CmdMovingStill::execute()
{ {
CtrlMove *pThis = (CtrlMove*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse(); m_pControl->m_rWindowManager.stopMove();
pThis->m_rWindowManager.stopMove();
} }
...@@ -58,10 +58,6 @@ class CtrlMove: public CtrlFlat ...@@ -58,10 +58,6 @@ class CtrlMove: public CtrlFlat
/// Get the position of the decorated control in the layout, if any /// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const; virtual const Position *getPosition() const;
static void transMovingMoving( SkinObject *pCtrl );
static void transStillMoving( SkinObject *pCtrl );
static void transMovingStill( SkinObject *pCtrl );
/// Get the type of control (custom RTTI) /// Get the type of control (custom RTTI)
virtual string getType() const { return m_rCtrl.getType(); } virtual string getType() const { return m_rCtrl.getType(); }
...@@ -77,10 +73,11 @@ class CtrlMove: public CtrlFlat ...@@ -77,10 +73,11 @@ class CtrlMove: public CtrlFlat
EvtGeneric *m_pEvt; EvtGeneric *m_pEvt;
/// Position of the click that started the move /// Position of the click that started the move
int m_xPos, m_yPos; int m_xPos, m_yPos;
/// Callbacks
Callback m_cmdMovingMoving; /// Callback objects
Callback m_cmdStillMoving; DEFINE_CALLBACK( CtrlMove, MovingMoving )
Callback m_cmdMovingStill; DEFINE_CALLBACK( CtrlMove, StillMoving )
}; DEFINE_CALLBACK( CtrlMove, MovingStill )
};
#endif #endif
...@@ -40,8 +40,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf, ...@@ -40,8 +40,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf,
VarBool *pVisible ): VarBool *pVisible ):
CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_numImg( numImg ), CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_numImg( numImg ),
m_rVariable( rVariable ), m_minAngle( minAngle ), m_maxAngle( maxAngle ), m_rVariable( rVariable ), m_minAngle( minAngle ), m_maxAngle( maxAngle ),
m_cmdUpDown( this, &transUpDown ), m_cmdDownUp( this, &transDownUp ), m_cmdUpDown( pIntf, this ), m_cmdDownUp( pIntf, this ),
m_cmdMove( this, &transMove ), m_position( 0 ), m_lastPos( 0 ) m_cmdMove( pIntf, this )
{ {
// Build the images of the sequence // Build the images of the sequence
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); OSFactory *pOsFactory = OSFactory::instance( getIntf() );
...@@ -105,35 +105,29 @@ void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable ) ...@@ -105,35 +105,29 @@ void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable )
} }
void CtrlRadialSlider::transUpDown( SkinObject *pCtrl ) void CtrlRadialSlider::CmdUpDown::execute()
{ {
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Change the position of the cursor, in non-blocking mode // Change the position of the cursor, in non-blocking mode
pThis->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), false ); m_pControl->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), false );
pThis->captureMouse(); m_pControl->captureMouse();
} }
void CtrlRadialSlider::transDownUp( SkinObject *pCtrl ) void CtrlRadialSlider::CmdDownUp::execute()
{ {
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
} }
void CtrlRadialSlider::transMove( SkinObject *pCtrl ) void CtrlRadialSlider::CmdMove::execute()
{ {
CtrlRadialSlider *pThis = (CtrlRadialSlider*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Change the position of the cursor, in blocking mode // Change the position of the cursor, in blocking mode
pThis->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true ); m_pControl->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true );
} }
......
...@@ -69,10 +69,6 @@ class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent> ...@@ -69,10 +69,6 @@ class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent>
VarPercent &m_rVariable; VarPercent &m_rVariable;
/// Min and max angles of the button /// Min and max angles of the button
float m_minAngle, m_maxAngle; float m_minAngle, m_maxAngle;
/// Callbacks objects
Callback m_cmdUpDown;
Callback m_cmdDownUp;
Callback m_cmdMove;
/// Position of the cursor /// Position of the cursor
int m_position; int m_position;
/// Size of an image /// Size of an image
...@@ -84,10 +80,10 @@ class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent> ...@@ -84,10 +80,10 @@ class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent>
/// Last saved position /// Last saved position
int m_lastPos; int m_lastPos;
/// Callback functions /// Callback objects
static void transUpDown( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlRadialSlider, UpDown )
static void transDownUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlRadialSlider, DownUp )
static void transMove( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlRadialSlider, Move )
/// Method called when the observed variable is modified /// Method called when the observed variable is modified
virtual void onUpdate( Subject<VarPercent> &rVariable ); virtual void onUpdate( Subject<VarPercent> &rVariable );
......
...@@ -37,12 +37,12 @@ CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl, ...@@ -37,12 +37,12 @@ CtrlResize::CtrlResize( intf_thread_t *pIntf, CtrlFlat &rCtrl,
GenericLayout &rLayout, const UString &rHelp, GenericLayout &rLayout, const UString &rHelp,
VarBool *pVisible ): VarBool *pVisible ):
CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ), CtrlFlat( pIntf, rHelp, pVisible ), m_fsm( pIntf ), m_rCtrl( rCtrl ),
m_rLayout( rLayout ), m_cmdOutStill( this, &transOutStill ), m_rLayout( rLayout ), m_cmdOutStill( pIntf, this ),
m_cmdStillOut( this, &transStillOut ), m_cmdStillOut( pIntf, this ),
m_cmdStillStill( this, &transStillStill ), m_cmdStillStill( pIntf, this ),
m_cmdStillResize( this, &transStillResize ), m_cmdStillResize( pIntf, this ),
m_cmdResizeStill( this, &transResizeStill ), m_cmdResizeStill( pIntf, this ),
m_cmdResizeResize( this, &transResizeResize ) m_cmdResizeResize( pIntf, this )
{ {
m_pEvt = NULL; m_pEvt = NULL;
m_xPos = 0; m_xPos = 0;
...@@ -103,96 +103,89 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent ) ...@@ -103,96 +103,89 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent )
} }
void CtrlResize::transOutStill( SkinObject *pCtrl ) void CtrlResize::CmdOutStill::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl; OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); pOsFactory->changeCursor( OSFactory::kResizeNWSE );
} }
void CtrlResize::transStillOut( SkinObject *pCtrl ) void CtrlResize::CmdStillOut::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl; OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
pOsFactory->changeCursor( OSFactory::kDefaultArrow ); pOsFactory->changeCursor( OSFactory::kDefaultArrow );
} }
void CtrlResize::transStillStill( SkinObject *pCtrl ) void CtrlResize::CmdStillStill::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl; OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() );
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); pOsFactory->changeCursor( OSFactory::kResizeNWSE );
} }
void CtrlResize::transStillResize( SkinObject *pCtrl ) void CtrlResize::CmdStillResize::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Set the cursor // Set the cursor
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() ); OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); pOsFactory->changeCursor( OSFactory::kResizeNWSE );
pThis->m_xPos = pEvtMouse->getXPos(); m_pControl->m_xPos = pEvtMouse->getXPos();
pThis->m_yPos = pEvtMouse->getYPos(); m_pControl->m_yPos = pEvtMouse->getYPos();
pThis->captureMouse(); m_pControl->captureMouse();
pThis->m_width = pThis->m_rLayout.getWidth(); m_pControl->m_width = m_pControl->m_rLayout.getWidth();
pThis->m_height = pThis->m_rLayout.getHeight(); m_pControl->m_height = m_pControl->m_rLayout.getHeight();
} }
void CtrlResize::transResizeStill( SkinObject *pCtrl ) void CtrlResize::CmdResizeStill::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl;
// Set the cursor // Set the cursor
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() ); OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); pOsFactory->changeCursor( OSFactory::kResizeNWSE );
pThis->releaseMouse(); m_pControl->releaseMouse();
} }
void CtrlResize::transResizeResize( SkinObject *pCtrl ) void CtrlResize::CmdResizeResize::execute()
{ {
CtrlResize *pThis = (CtrlResize*)pCtrl; EvtMotion *pEvtMotion = (EvtMotion*)m_pControl->m_pEvt;
EvtMotion *pEvtMotion = (EvtMotion*)pThis->m_pEvt;
// Set the cursor // Set the cursor
OSFactory *pOsFactory = OSFactory::instance( pThis->getIntf() ); OSFactory *pOsFactory = OSFactory::instance( m_pControl->getIntf() );
pOsFactory->changeCursor( OSFactory::kResizeNWSE ); pOsFactory->changeCursor( OSFactory::kResizeNWSE );
int newWidth = pEvtMotion->getXPos() - pThis->m_xPos + pThis->m_width; int newWidth = pEvtMotion->getXPos() - m_pControl->m_xPos + m_pControl->m_width;
int newHeight = pEvtMotion->getYPos() - pThis->m_yPos + pThis->m_height; int newHeight = pEvtMotion->getYPos() - m_pControl->m_yPos + m_pControl->m_height;
// Check boundaries // Check boundaries
if( newWidth < pThis->m_rLayout.getMinWidth() ) if( newWidth < m_pControl->m_rLayout.getMinWidth() )
{ {
newWidth = pThis->m_rLayout.getMinWidth(); newWidth = m_pControl->m_rLayout.getMinWidth();
} }
if( newWidth > pThis->m_rLayout.getMaxWidth() ) if( newWidth > m_pControl->m_rLayout.getMaxWidth() )
{ {
newWidth = pThis->m_rLayout.getMaxWidth(); newWidth = m_pControl->m_rLayout.getMaxWidth();
} }
if( newHeight < pThis->m_rLayout.getMinHeight() ) if( newHeight < m_pControl->m_rLayout.getMinHeight() )
{ {
newHeight = pThis->m_rLayout.getMinHeight(); newHeight = m_pControl->m_rLayout.getMinHeight();
} }
if( newHeight > pThis->m_rLayout.getMaxHeight() ) if( newHeight > m_pControl->m_rLayout.getMaxHeight() )
{ {
newHeight = pThis->m_rLayout.getMaxHeight(); newHeight = m_pControl->m_rLayout.getMaxHeight();
} }
// Create a resize command // Create a resize command
CmdGeneric *pCmd = new CmdResize( pThis->getIntf(), pThis->m_rLayout, CmdGeneric *pCmd = new CmdResize( m_pControl->getIntf(), m_pControl->m_rLayout,
newWidth, newHeight ); newWidth, newHeight );
// Push the command in the asynchronous command queue // Push the command in the asynchronous command queue
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() ); AsyncQueue *pQueue = AsyncQueue::instance( m_pControl->getIntf() );
pQueue->remove( "resize" ); pQueue->remove( "resize" );
pQueue->push( CmdGenericPtr( pCmd ) ); pQueue->push( CmdGenericPtr( pCmd ) );
} }
...@@ -57,13 +57,6 @@ class CtrlResize: public CtrlFlat ...@@ -57,13 +57,6 @@ class CtrlResize: public CtrlFlat
/// Get the position of the decorated control in the layout, if any /// Get the position of the decorated control in the layout, if any
virtual const Position *getPosition() const; virtual const Position *getPosition() const;
static void transOutStill( SkinObject *pCtrl );
static void transStillOut( SkinObject *pCtrl );
static void transStillStill( SkinObject *pCtrl );
static void transStillResize( SkinObject *pCtrl );
static void transResizeStill( SkinObject *pCtrl );
static void transResizeResize( SkinObject *pCtrl );
/// Get the type of control (custom RTTI) /// Get the type of control (custom RTTI)
virtual string getType() const { return m_rCtrl.getType(); } virtual string getType() const { return m_rCtrl.getType(); }
...@@ -77,13 +70,14 @@ class CtrlResize: public CtrlFlat ...@@ -77,13 +70,14 @@ class CtrlResize: public CtrlFlat
EvtGeneric *m_pEvt; EvtGeneric *m_pEvt;
/// Position of the click that started the resizing /// Position of the click that started the resizing
int m_xPos, m_yPos; int m_xPos, m_yPos;
/// Callbacks
Callback m_cmdOutStill; /// Callback objects
Callback m_cmdStillOut; DEFINE_CALLBACK( CtrlResize, OutStill )
Callback m_cmdStillStill; DEFINE_CALLBACK( CtrlResize, StillOut )
Callback m_cmdStillResize; DEFINE_CALLBACK( CtrlResize, StillStill )
Callback m_cmdResizeStill; DEFINE_CALLBACK( CtrlResize, StillResize )
Callback m_cmdResizeResize; DEFINE_CALLBACK( CtrlResize, ResizeStill )
DEFINE_CALLBACK( CtrlResize, ResizeResize )
// Size of the layout, before resizing // Size of the layout, before resizing
int m_width, m_height; int m_width, m_height;
......
...@@ -50,10 +50,10 @@ CtrlSliderCursor::CtrlSliderCursor( intf_thread_t *pIntf, ...@@ -50,10 +50,10 @@ CtrlSliderCursor::CtrlSliderCursor( intf_thread_t *pIntf,
CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
m_rVariable( rVariable ), m_tooltip( rTooltip ), m_rVariable( rVariable ), m_tooltip( rTooltip ),
m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ), m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ),
m_cmdOverDown( this, &transOverDown ), m_cmdOverDown( pIntf, this ), m_cmdDownOver( pIntf, this ),
m_cmdDownOver( this, &transDownOver ), m_cmdOverUp( this, &transOverUp ), m_cmdOverUp( pIntf, this ), m_cmdUpOver( pIntf, this ),
m_cmdUpOver( this, &transUpOver ), m_cmdMove( this, &transMove ), m_cmdMove( pIntf, this ), m_cmdScroll( pIntf, this ),
m_cmdScroll( this, &transScroll ),
m_lastPercentage( 0 ), m_xOffset( 0 ), m_yOffset( 0 ), m_lastPercentage( 0 ), m_xOffset( 0 ), m_yOffset( 0 ),
m_pEvt( NULL ), m_rCurve( rCurve ) m_pEvt( NULL ), m_rCurve( rCurve )
{ {
...@@ -175,139 +175,130 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable ) ...@@ -175,139 +175,130 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable )
} }
void CtrlSliderCursor::transOverDown( SkinObject *pCtrl ) void CtrlSliderCursor::CmdOverDown::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Compute the resize factors // Compute the resize factors
float factorX, factorY; float factorX, factorY;
pThis->getResizeFactors( factorX, factorY ); m_pControl->getResizeFactors( factorX, factorY );
// Get the position of the control // Get the position of the control
const Position *pPos = pThis->getPosition(); const Position *pPos = m_pControl->getPosition();
// Compute the offset // Compute the offset
int tempX, tempY; int tempX, tempY;
pThis->m_rCurve.getPoint( pThis->m_rVariable.get(), tempX, tempY ); m_pControl->m_rCurve.getPoint( m_pControl->m_rVariable.get(), tempX, tempY );
pThis->m_xOffset = pEvtMouse->getXPos() - pPos->getLeft() m_pControl->m_xOffset = pEvtMouse->getXPos() - pPos->getLeft()
- (int)(tempX * factorX); - (int)(tempX * factorX);
pThis->m_yOffset = pEvtMouse->getYPos() - pPos->getTop() m_pControl->m_yOffset = pEvtMouse->getYPos() - pPos->getTop()
- (int)(tempY * factorY); - (int)(tempY * factorY);
pThis->captureMouse(); m_pControl->captureMouse();
pThis->m_pImg = pThis->m_pImgDown; m_pControl->m_pImg = m_pControl->m_pImgDown;
if( pThis->m_pImg ) if( m_pControl->m_pImg )
{ {
pThis->notifyLayout( m_pControl->notifyLayout(
pThis->m_rCurve.getWidth() + pThis->m_pImg->getWidth(), m_pControl->m_rCurve.getWidth() + m_pControl->m_pImg->getWidth(),
pThis->m_rCurve.getHeight() + pThis->m_pImg->getHeight(), m_pControl->m_rCurve.getHeight() + m_pControl->m_pImg->getHeight(),
- pThis->m_pImg->getWidth() / 2, - m_pControl->m_pImg->getWidth() / 2,
- pThis->m_pImg->getHeight() / 2 ); - m_pControl->m_pImg->getHeight() / 2 );
} }
else else
pThis->notifyLayout(); m_pControl->notifyLayout();
} }
void CtrlSliderCursor::transDownOver( SkinObject *pCtrl ) void CtrlSliderCursor::CmdDownOver::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl;
// Save the position // Save the position
pThis->m_lastPercentage = pThis->m_rVariable.get(); m_pControl->m_lastPercentage = m_pControl->m_rVariable.get();
pThis->releaseMouse(); m_pControl->releaseMouse();
pThis->m_pImg = pThis->m_pImgUp; m_pControl->m_pImg = m_pControl->m_pImgUp;
if( pThis->m_pImg ) if( m_pControl->m_pImg )
{ {
pThis->notifyLayout( m_pControl->notifyLayout(
pThis->m_rCurve.getWidth() + pThis->m_pImg->getWidth(), m_pControl->m_rCurve.getWidth() + m_pControl->m_pImg->getWidth(),
pThis->m_rCurve.getHeight() + pThis->m_pImg->getHeight(), m_pControl->m_rCurve.getHeight() + m_pControl->m_pImg->getHeight(),
- pThis->m_pImg->getWidth() / 2, - m_pControl->m_pImg->getWidth() / 2,
- pThis->m_pImg->getHeight() / 2 ); - m_pControl->m_pImg->getHeight() / 2 );
} }
else else
pThis->notifyLayout(); m_pControl->notifyLayout();
} }
void CtrlSliderCursor::transUpOver( SkinObject *pCtrl ) void CtrlSliderCursor::CmdUpOver::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; m_pControl->m_pImg = m_pControl->m_pImgOver;
if( m_pControl->m_pImg )
pThis->m_pImg = pThis->m_pImgOver;
if( pThis->m_pImg )
{ {
pThis->notifyLayout( m_pControl->notifyLayout(
pThis->m_rCurve.getWidth() + pThis->m_pImg->getWidth(), m_pControl->m_rCurve.getWidth() + m_pControl->m_pImg->getWidth(),
pThis->m_rCurve.getHeight() + pThis->m_pImg->getHeight(), m_pControl->m_rCurve.getHeight() + m_pControl->m_pImg->getHeight(),
- pThis->m_pImg->getWidth() / 2, - m_pControl->m_pImg->getWidth() / 2,
- pThis->m_pImg->getHeight() / 2 ); - m_pControl->m_pImg->getHeight() / 2 );
} }
else else
pThis->notifyLayout(); m_pControl->notifyLayout();
} }
void CtrlSliderCursor::transOverUp( SkinObject *pCtrl ) void CtrlSliderCursor::CmdOverUp::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; m_pControl->m_pImg = m_pControl->m_pImgUp;
if( m_pControl->m_pImg )
pThis->m_pImg = pThis->m_pImgUp;
if( pThis->m_pImg )
{ {
pThis->notifyLayout( m_pControl->notifyLayout(
pThis->m_rCurve.getWidth() + pThis->m_pImg->getWidth(), m_pControl->m_rCurve.getWidth() + m_pControl->m_pImg->getWidth(),
pThis->m_rCurve.getHeight() + pThis->m_pImg->getHeight(), m_pControl->m_rCurve.getHeight() + m_pControl->m_pImg->getHeight(),
- pThis->m_pImg->getWidth() / 2, - m_pControl->m_pImg->getWidth() / 2,
- pThis->m_pImg->getHeight() / 2 ); - m_pControl->m_pImg->getHeight() / 2 );
} }
else else
pThis->notifyLayout(); m_pControl->notifyLayout();
} }
void CtrlSliderCursor::transMove( SkinObject *pCtrl ) void CtrlSliderCursor::CmdMove::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Get the position of the control // Get the position of the control
const Position *pPos = pThis->getPosition(); const Position *pPos = m_pControl->getPosition();
// Compute the resize factors // Compute the resize factors
float factorX, factorY; float factorX, factorY;
pThis->getResizeFactors( factorX, factorY ); m_pControl->getResizeFactors( factorX, factorY );
// Compute the relative position of the centre of the cursor // Compute the relative position of the centre of the cursor
float relX = pEvtMouse->getXPos() - pPos->getLeft() - pThis->m_xOffset; float relX = pEvtMouse->getXPos() - pPos->getLeft() - m_pControl->m_xOffset;
float relY = pEvtMouse->getYPos() - pPos->getTop() - pThis->m_yOffset; float relY = pEvtMouse->getYPos() - pPos->getTop() - m_pControl->m_yOffset;
// Ponderate with the resize factors // Ponderate with the resize factors
int relXPond = (int)(relX / factorX); int relXPond = (int)(relX / factorX);
int relYPond = (int)(relY / factorY); int relYPond = (int)(relY / factorY);
// Update the position // Update the position
if( pThis->m_rCurve.getMinDist( relXPond, relYPond ) < RANGE ) if( m_pControl->m_rCurve.getMinDist( relXPond, relYPond ) < RANGE )
{ {
float percentage = pThis->m_rCurve.getNearestPercent( relXPond, float percentage = m_pControl->m_rCurve.getNearestPercent( relXPond,
relYPond ); relYPond );
pThis->m_rVariable.set( percentage ); m_pControl->m_rVariable.set( percentage );
} }
else else
{ {
pThis->m_rVariable.set( pThis->m_lastPercentage ); m_pControl->m_rVariable.set( m_pControl->m_lastPercentage );
} }
} }
void CtrlSliderCursor::transScroll( SkinObject *pCtrl ) void CtrlSliderCursor::CmdScroll::execute()
{ {
CtrlSliderCursor *pThis = (CtrlSliderCursor*)pCtrl; EvtScroll *pEvtScroll = (EvtScroll*)m_pControl->m_pEvt;
EvtScroll *pEvtScroll = (EvtScroll*)pThis->m_pEvt;
int direction = pEvtScroll->getDirection(); int direction = pEvtScroll->getDirection();
float percentage = pThis->m_rVariable.get(); float percentage = m_pControl->m_rVariable.get();
if( direction == EvtScroll::kUp ) if( direction == EvtScroll::kUp )
{ {
percentage += SCROLL_STEP; percentage += SCROLL_STEP;
...@@ -317,7 +308,7 @@ void CtrlSliderCursor::transScroll( SkinObject *pCtrl ) ...@@ -317,7 +308,7 @@ void CtrlSliderCursor::transScroll( SkinObject *pCtrl )
percentage -= SCROLL_STEP; percentage -= SCROLL_STEP;
} }
pThis->m_rVariable.set( percentage ); m_pControl->m_rVariable.set( percentage );
} }
......
...@@ -75,13 +75,6 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent> ...@@ -75,13 +75,6 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
const UString m_tooltip; const UString m_tooltip;
/// Initial size of the control /// Initial size of the control
int m_width, m_height; int m_width, m_height;
/// Callback objects
Callback m_cmdOverDown;
Callback m_cmdDownOver;
Callback m_cmdOverUp;
Callback m_cmdUpOver;
Callback m_cmdMove;
Callback m_cmdScroll;
/// Position of the cursor /// Position of the cursor
int m_xPosition, m_yPosition; int m_xPosition, m_yPosition;
/// Last saved position of the cursor (stored as a percentage) /// Last saved position of the cursor (stored as a percentage)
...@@ -97,13 +90,13 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent> ...@@ -97,13 +90,13 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
/// Bezier curve of the slider /// Bezier curve of the slider
const Bezier &m_rCurve; const Bezier &m_rCurve;
/// Callback functions /// Callback objects
static void transOverDown( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, OverDown )
static void transDownOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, DownOver )
static void transOverUp( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, OverUp )
static void transUpOver( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, UpOver )
static void transMove( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, Move )
static void transScroll( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlSliderCursor, Scroll )
/// Method called when the position variable is modified /// Method called when the position variable is modified
virtual void onUpdate( Subject<VarPercent> &rVariable ); virtual void onUpdate( Subject<VarPercent> &rVariable );
......
...@@ -44,13 +44,11 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable, ...@@ -44,13 +44,11 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp, const GenericFont &rFont, const UString &rHelp,
uint32_t color, VarBool *pVisible ): uint32_t color, VarBool *pVisible ):
CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ), CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
m_rVariable( rVariable ), m_cmdToManual( this, &transToManual ), m_rVariable( rVariable ), m_cmdToManual( pIntf, this ),
m_cmdManualMoving( this, &transManualMoving ), m_cmdManualMoving( pIntf, this ), m_cmdManualStill( pIntf, this ),
m_cmdManualStill( this, &transManualStill ), m_cmdMove( pIntf, this ), m_pEvt( NULL ), m_rFont( rFont ),
m_cmdMove( this, &transMove ), m_color( color ), m_pImg( NULL ), m_pImgDouble( NULL ),
m_pEvt( NULL ), m_rFont( rFont ), m_color( color ), m_pCurrImg( NULL ), m_xPos( 0 ), m_xOffset( 0 )
m_pImg( NULL ), m_pImgDouble( NULL ), m_pCurrImg( NULL ),
m_xPos( 0 ), m_xOffset( 0 )
{ {
m_pTimer = OSFactory::instance( getIntf() )->createOSTimer( m_pTimer = OSFactory::instance( getIntf() )->createOSTimer(
Callback( this, &updateText ) ); Callback( this, &updateText ) );
...@@ -254,78 +252,74 @@ void CtrlText::onChangePosition() ...@@ -254,78 +252,74 @@ void CtrlText::onChangePosition()
} }
void CtrlText::transToManual( SkinObject *pCtrl ) void CtrlText::CmdToManual::execute()
{ {
CtrlText *pThis = (CtrlText*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Compute the offset // Compute the offset
pThis->m_xOffset = pEvtMouse->getXPos() - pThis->m_xPos; m_pControl->m_xOffset = pEvtMouse->getXPos() - m_pControl->m_xPos;
pThis->m_pTimer->stop(); m_pControl->m_pTimer->stop();
pThis->captureMouse(); m_pControl->captureMouse();
} }
void CtrlText::transManualMoving( SkinObject *pCtrl ) void CtrlText::CmdManualMoving::execute()
{ {
CtrlText *pThis = (CtrlText*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
// Start the automatic movement, but only if the text is wider than the // Start the automatic movement, but only if the text is wider than the
// control // control
if( pThis->m_pImg && if( m_pControl->m_pImg &&
pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() ) m_pControl->m_pImg->getWidth() >= m_pControl->getPosition()->getWidth() )
{ {
// The current image may have been set incorrectly in displayText(), so // The current image may have been set incorrectly in displayText(), so
// set the correct value // set the correct value
pThis->m_pCurrImg = pThis->m_pImgDouble; m_pControl->m_pCurrImg = m_pControl->m_pImgDouble;
pThis->m_pTimer->start( MOVING_TEXT_DELAY, false ); m_pControl->m_pTimer->start( MOVING_TEXT_DELAY, false );
} }
} }
void CtrlText::transManualStill( SkinObject *pCtrl ) void CtrlText::CmdManualStill::execute()
{ {
CtrlText *pThis = (CtrlText*)pCtrl; m_pControl->releaseMouse();
pThis->releaseMouse();
} }
void CtrlText::transMove( SkinObject *pCtrl ) void CtrlText::CmdMove::execute()
{ {
CtrlText *pThis = (CtrlText*)pCtrl; EvtMouse *pEvtMouse = (EvtMouse*)m_pControl->m_pEvt;
EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
// Do nothing if the text fits in the control // Do nothing if the text fits in the control
if( pThis->m_pImg && if( m_pControl->m_pImg &&
pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() ) m_pControl->m_pImg->getWidth() >= m_pControl->getPosition()->getWidth() )
{ {
// The current image may have been set incorrectly in displayText(), so // The current image may have been set incorrectly in displayText(), so
// we set the correct value // we set the correct value
pThis->m_pCurrImg = pThis->m_pImgDouble; m_pControl->m_pCurrImg = m_pControl->m_pImgDouble;
// Compute the new position of the left side, and make sure it is // Compute the new position of the left side, and make sure it is
// in the correct range // in the correct range
pThis->m_xPos = (pEvtMouse->getXPos() - pThis->m_xOffset); m_pControl->m_xPos = (pEvtMouse->getXPos() - m_pControl->m_xOffset);
pThis->adjust( pThis->m_xPos ); m_pControl->adjust( m_pControl->m_xPos );
pThis->notifyLayout( pThis->getPosition()->getWidth(), m_pControl->notifyLayout( m_pControl->getPosition()->getWidth(),
pThis->getPosition()->getHeight() ); m_pControl->getPosition()->getHeight() );
} }
} }
void CtrlText::updateText( SkinObject *pCtrl ) void CtrlText::updateText( SkinObject *pCtrl )
{ {
CtrlText *pThis = (CtrlText*)pCtrl; CtrlText *m_pControl = (CtrlText*)pCtrl;
pThis->m_xPos -= MOVING_TEXT_STEP; m_pControl->m_xPos -= MOVING_TEXT_STEP;
pThis->adjust( pThis->m_xPos ); m_pControl->adjust( m_pControl->m_xPos );
pThis->notifyLayout( pThis->getPosition()->getWidth(), m_pControl->notifyLayout( m_pControl->getPosition()->getWidth(),
pThis->getPosition()->getHeight() ); m_pControl->getPosition()->getHeight() );
} }
......
...@@ -68,11 +68,6 @@ class CtrlText: public CtrlGeneric, public Observer<VarText> ...@@ -68,11 +68,6 @@ class CtrlText: public CtrlGeneric, public Observer<VarText>
FSM m_fsm; FSM m_fsm;
/// Variable associated to the control /// Variable associated to the control
VarText &m_rVariable; VarText &m_rVariable;
/// Callback objects
Callback m_cmdToManual;
Callback m_cmdManualMoving;
Callback m_cmdManualStill;
Callback m_cmdMove;
/// The last received event /// The last received event
EvtGeneric *m_pEvt; EvtGeneric *m_pEvt;
/// Font used to render the text /// Font used to render the text
...@@ -94,11 +89,12 @@ class CtrlText: public CtrlGeneric, public Observer<VarText> ...@@ -94,11 +89,12 @@ class CtrlText: public CtrlGeneric, public Observer<VarText>
/// Timer to move the text /// Timer to move the text
OSTimer *m_pTimer; OSTimer *m_pTimer;
/// Callback functions /// Callback objects
static void transToManual( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlText, ToManual )
static void transManualMoving( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlText, ManualMoving )
static void transManualStill( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlText, ManualStill )
static void transMove( SkinObject *pCtrl ); DEFINE_CALLBACK( CtrlText, Move )
/// Callback for the timer /// Callback for the timer
static void updateText( SkinObject *pCtrl ); static void updateText( SkinObject *pCtrl );
......
...@@ -33,7 +33,7 @@ void FSM::addState( const string &state ) ...@@ -33,7 +33,7 @@ void FSM::addState( const string &state )
void FSM::addTransition( const string &state1, const string &event, void FSM::addTransition( const string &state1, const string &event,
const string &state2, Callback *pCmd ) const string &state2, CmdGeneric *pCmd )
{ {
// Check that we already know the states // Check that we already know the states
if( m_states.find( state1 ) == m_states.end() || if( m_states.find( state1 ) == m_states.end() ||
...@@ -100,9 +100,9 @@ void FSM::handleTransition( const string &event ) ...@@ -100,9 +100,9 @@ void FSM::handleTransition( const string &event )
m_currentState = (*it).second.first; m_currentState = (*it).second.first;
// Call the callback, if any // Call the callback, if any
Callback *pCmd = (*it).second.second; CmdGeneric *pCmd = (*it).second.second;
if( pCmd != NULL ) if( pCmd != NULL )
{ {
(*(pCmd->getFunc()))( pCmd->getObj() ); pCmd->execute();
} }
} }
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <set> #include <set>
class EvtGeneric; class EvtGeneric;
class CmdGeneric;
/// This class implements a Finite State Machine (FSM) /// This class implements a Finite State Machine (FSM)
...@@ -46,7 +47,7 @@ class FSM: public SkinObject ...@@ -46,7 +47,7 @@ class FSM: public SkinObject
/// Add a transition to the machine /// Add a transition to the machine
void addTransition( const string &state1, const string &event, void addTransition( const string &state1, const string &event,
const string &state2, const string &state2,
Callback *pCmd = NULL ); CmdGeneric *pCmd = NULL );
/// Retrieve the current state /// Retrieve the current state
const string &getState() const { return m_currentState; } const string &getState() const { return m_currentState; }
...@@ -65,7 +66,7 @@ class FSM: public SkinObject ...@@ -65,7 +66,7 @@ class FSM: public SkinObject
/// A Data_t contains the final state of a transition, and a callback /// A Data_t contains the final state of a transition, and a callback
/// to execute when the transition is applied /// to execute when the transition is applied
typedef pair<string, Callback*> Data_t; typedef pair<string, CmdGeneric*> Data_t;
/// Current state of the machine /// Current state of the machine
string m_currentState; string m_currentState;
......
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