-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuButton.cpp
53 lines (43 loc) · 1.06 KB
/
MenuButton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "MenuButton.h"
MenuButton::MenuButton() : SDLGameObject(), m_callback(0), m_bReleased(true)
{
}
void MenuButton::draw()
{
SDLGameObject::draw(); // use base class drawing
}
void MenuButton::load(const LoaderParams* pParams)
{
SDLGameObject::load(pParams);
m_callbackID = pParams->getCallbackID();
m_currentFrame = MOUSE_OUT;
}
void MenuButton::update()
{
Vector2D* pMousePos = TheInputHandler::instance()->getMousePosition();
if(pMousePos->getX() < (m_position.getX() + m_width)
&& pMousePos->getX() > m_position.getX()
&& pMousePos->getY() < (m_position.getY() + m_height)
&& pMousePos->getY() > m_position.getY())
{
if(TheInputHandler::instance()->getMouseButtonState(LEFT) && m_bReleased)
{
m_currentFrame = CLICKED;
m_callback(); //call our callback function, passed in via ctor.
m_bReleased = false;
}
else if(!TheInputHandler::instance()->getMouseButtonState(LEFT))
{
m_bReleased = true;
m_currentFrame = MOUSE_OVER;
}
}
else
{
m_currentFrame = MOUSE_OUT;
}
}
void MenuButton::clean()
{
SDLGameObject::clean();
}