gui: refactoring complete, everything works (including instanciating a gui through...
[fail.git] / gui / game / Button.cpp
blob65cec3ab3282f39b898a6c469e0bf997dcbdf738
1 #include "Button.h"
2 #include "ButtonDecorator.h"
3 #include "EventManager.h"
5 using namespace awful;
6 using namespace awful::gui::game;
8 Button::Button( Container* pParent_, const std::string& Label_ ) :
9 Widget( pParent_ ),
10 m_State( s_Idle ),
11 m_bDepressCheck( false )
13 m_Label = Label_;
14 m_pDecorator = getTheme()->newButtonDecorator( this );
17 void Button::setLabel( const std::string& Label_ )
19 m_Label = Label_;
20 reLayout();
23 void Button::mouseEnter( const math::Vector2f& pos )
25 m_State = s_Hilighted;
26 m_pDecorator->updateState();
29 void Button::mouseExit()
31 m_State = s_Idle;
32 m_pDecorator->updateState();
35 bool Button::mouseMotionEvent( const math::Vector2f& pos, const math::Vector2f& rel )
37 EventManager* pEventManager = EventManager::GetInstance();
39 if( m_bDepressCheck )
41 // we are currently waiting to see if the user will depress the button,
42 // update the idle/pressed state according to mouse position
43 m_State = isInside( pos ) ? s_Pressed : s_Idle;
44 m_pDecorator->updateState();
47 return false;
50 bool Button::mouseButtonEvent( const math::Vector2f& pos, e_MouseButton Button, bool bPressed )
52 if( Button != mb_Left )
53 return false;
55 EventManager* pEventManager = EventManager::GetInstance();
57 if( bPressed )
59 m_State = s_Pressed;
60 m_bDepressCheck = true;
61 pEventManager->setCurrentMouseMotionHandler( this );
62 pEventManager->setCurrentMouseButtonHandler( this );
63 setWantMouseMotion( true );
65 else if( m_bDepressCheck )
67 m_bDepressCheck = false;
68 pEventManager->setCurrentMouseButtonHandler( 0 );
69 pEventManager->setCurrentMouseMotionHandler( 0 );
70 setWantMouseMotion( false );
72 if( isInside( pos ) )
74 // The user released the mouse button inside the button:
75 // go to hilighted state and trigger the Depressed signal
76 m_State = s_Hilighted;
77 m_Depressed();
79 else
80 // Otherwise, turn back to idle state and do nothing
81 m_State = s_Idle;
84 m_pDecorator->updateState();
85 return false;
88 void Button::buildSceneGraph()
90 m_pDecorator->buildSceneGraph( m_pFrame, m_pRenderable );
93 void Button::calcMinMax()
95 m_pDecorator->calcMinMax();
98 void Button::layout()
100 m_pDecorator->layout();