-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.h
64 lines (56 loc) · 1.96 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <string>
#include <functional>
#include "Math.h"
#include "SDL.h"
class Button
{
public:
// The constructor takes in a name, font,
// callback function and the position/dimension of the button
Button(const std::string& name, class Font* font,
std::function<void()> onClick,
const Vector2& pos, const Vector2& dim);
~Button();
// Set the name of the button and generate the name texture
void SetName(const std::string& name);
// Returns true if the point is within the button's bounds
bool ContainsPoint(const Vector2& pt) const;
// Called when button is clicked
void OnClick();
// Draw the button and associated text
void Draw(SDL_Texture* tex, SDL_Renderer* renderer);
// Getters/Setters
SDL_Texture* GetNameTexture() const { return mNameTexture; }
Font* GetFont() const { return mFont; }
Vector2 GetDimension() const { return mDimension; }
Vector2 GetPosition() const { return mPosition; }
bool GetHighlighted() const { return mHighlighted; }
std::string GetName() const { return mName; }
std::function<void()> GetOnClick() const { return mOnClick; }
void SetNameTexture(SDL_Texture* tex) { mNameTexture = tex; }
void SetFont(Font* font) { mFont = font; }
void SetFontSize(int size) { mFontSize = size; }
void SetPosition(Vector2 pos) { mPosition = pos; }
void SetDimension(Vector2 dim) { mDimension = dim; }
void SetHighlighted(bool highlight) { mHighlighted = highlight; }
void SetSelectionTexts(SDL_Texture* selected, SDL_Texture* unselected) {
mSelectedTexture = selected;
mUnselectedTexture = unselected;
}
SDL_Texture* GetSelected() const { return mSelectedTexture; }
SDL_Texture* GetUnSelected() const { return mUnselectedTexture; }
private:
std::function<void()> mOnClick;
std::string mName;
SDL_Texture* mNameTexture;
SDL_Texture* mSelectedTexture;
SDL_Texture* mUnselectedTexture;
int mNameTexWidth;
int mNameTexHeight;
class Font* mFont;
int mFontSize;
Vector2 mPosition;
Vector2 mDimension;
bool mHighlighted;
};