-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_drawable.cpp
More file actions
37 lines (30 loc) · 1.01 KB
/
ui_drawable.cpp
File metadata and controls
37 lines (30 loc) · 1.01 KB
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
#include "ui_drawable.hpp"
UIDrawable::UIDrawable(std::string filename, float screenX, float screenY) : filename(filename), screenX(screenX), screenY(screenY) {
loadSprite(filename);
}
void UIDrawable::render(sf::RenderTarget* screen) {
sf::Vector2f screen_center = screen->getView().getCenter();
sf::Vector2f screen_size = screen->getView().getSize();
spr.setPosition(screenX + screen_center.x - screen_size.x/2, screenY + screen_center.y - screen_size.y/2);
screen->draw(spr);
}
void UIDrawable::update(float dt) {
}
void UIDrawable::onClick() {
}
bool UIDrawable::isClicked(float x, float y) {
return x >= screenX &&
x <= screenX + width &&
y >= screenY &&
y <= screenY + height;
}
void UIDrawable::loadSprite(std::string filename) {
if (filename != "EMPTY" && !tex.loadFromFile(filename)) {
DEBUG_OUTPUT << "ERROR: Could not load " << filename << std::endl;
return;
};
width = (int) tex.getSize().x * X_SCALE;
height = (int) tex.getSize().y * Y_SCALE;
spr.setTexture(tex);
spr.setScale(X_SCALE, Y_SCALE);
}