forked from SaConway/Super-Red
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Button.h
39 lines (31 loc) · 1.31 KB
/
Button.h
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
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <functional>
//-----------------------------------------------------------------------------
using namespace sf;
using namespace std;
//-----------------------------------------------------------------------------
const int BUTTONS_SIZE = 128;
//-----------------------------------------------------------------------------
class Button
{
public:
Button(Vector2f&, Vector2i &, Vector2i&, function<void()>);
Button(const Texture & ,Vector2f&, Vector2i&, Vector2i&, function<void()>);
Button(const SoundBuffer & , Vector2f&, Vector2i&, Vector2i&, function<void()>);
bool checkIfPressed(Vector2f & mouse_loc) const { return m_button.getGlobalBounds().contains(mouse_loc); };
void setPosition(Vector2f & pos) { m_button.setPosition(pos); }
void setScale(Vector2f scale) { m_button.setScale(scale); };
void setOrigin(Vector2f origin) { m_button.setOrigin(origin); };
const Vector2f & getPosition() const { return m_button.getPosition(); }
void Hilight(Vector2f &);
void handlePress();
void playClickSound() { m_clickSound.play(); }
void draw(RenderWindow & window) const { window.draw(m_button); }
private:
void initButton(Vector2f & , Vector2i & , Vector2i & , function<void()>);
Sound m_clickSound;
Sprite m_button;
function<void()> m_func;
};