-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.cpp
56 lines (52 loc) · 1.3 KB
/
Button.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
54
55
56
/*
Button.cpp
Written by Ronan Murphy circa Aug-Sep 2013.
*/
#include "Button.h"
/*
Name: Constructor
Desc: Constructor for Button
Args: p_texture, the texture used for the button
p_buttonSize, the size of the button
p_buttonPos, the position of the button
p_nonHoverRect, the part of the texture used when not hovering on the button
p_hoverRect, the part of the texture used when hovering on the button
Rtrn: None
*/
Button::Button(const sf::Texture &p_texture, const sf::Vector2f &p_buttonSize, const sf::Vector2f &p_buttonPos, sf::IntRect p_nonHoverRect, sf::IntRect p_hoverRect) :
m_button(p_texture, p_nonHoverRect),
m_hoverRect(p_hoverRect),
m_nonHoverRect(p_nonHoverRect)
{
m_button.setPosition(p_buttonPos);
}
/*
Name: getSprite
Desc: getter for the sprite of the button
Args: None
Rtrn: m_button
*/
sf::Sprite& Button::getSprite()
{
return m_button;
}
/*
Name: startHover
Desc: sets the button to use the part of the texture needed for when the button is being hovered on
Args: None
Rtrn: None
*/
void Button::startHover()
{
m_button.setTextureRect(m_hoverRect);
}
/*
Name: endHover
Desc: resets the button to used the part of the texture needed when nothing is hovering on the button
Args: None
Rtrn: None
*/
void Button::endHover()
{
m_button.setTextureRect(m_nonHoverRect);
}