-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabel.cpp
More file actions
22 lines (20 loc) · 848 Bytes
/
Label.cpp
File metadata and controls
22 lines (20 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <allegro5/allegro_font.h>
#include <memory>
#include "IObject.hpp"
#include "Label.hpp"
#include "Point.hpp"
#include "Resources.hpp"
namespace Engine {
Label::Label(const std::string& text, const std::string& font, int fontSize, float x, float y, unsigned char r, unsigned char g, unsigned char b, unsigned char a, float anchorX, float anchorY) :
IObject(x, y, 0, 0, anchorX, anchorY), font(Resources::GetInstance().GetFont(font, fontSize)), Text(text), Color(al_map_rgba(r, g, b, a)) {
}
void Label::Draw() const {
al_draw_text(font.get(), Color, Position.x - Anchor.x * GetTextWidth(), Position.y - Anchor.y * GetTextHeight(), 0, Text.c_str());
}
int Label::GetTextWidth() const {
return al_get_text_width(font.get(), Text.c_str());
}
int Label::GetTextHeight() const {
return al_get_font_line_height(font.get());
}
}