1 | #include "TextLabel.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | TextLabel::TextLabel(int x, int y, int width, int height, ALLEGRO_FONT *font, string str, int alignment) :
|
---|
6 | GuiComponent(x, y, width, height, font)
|
---|
7 | {
|
---|
8 | this->str = str;
|
---|
9 | this->alignment = alignment;
|
---|
10 | }
|
---|
11 |
|
---|
12 | TextLabel::~TextLabel(void)
|
---|
13 | {
|
---|
14 | }
|
---|
15 |
|
---|
16 | void TextLabel::draw(ALLEGRO_DISPLAY *display)
|
---|
17 | {
|
---|
18 | al_set_target_bitmap(bitmap);
|
---|
19 | al_clear_to_color(al_map_rgb(0, 0, 0));
|
---|
20 |
|
---|
21 | int fontHeight = al_get_font_line_height(font);
|
---|
22 | int targetX;
|
---|
23 |
|
---|
24 | switch(this->alignment) {
|
---|
25 | case ALLEGRO_ALIGN_LEFT:
|
---|
26 | targetX = 0;
|
---|
27 | break;
|
---|
28 | case ALLEGRO_ALIGN_RIGHT:
|
---|
29 | targetX = this->width;
|
---|
30 | break;
|
---|
31 | case ALLEGRO_ALIGN_CENTRE:
|
---|
32 | targetX = this->width/2;
|
---|
33 | break;
|
---|
34 | default:
|
---|
35 | cout << "Invalid alignment: " << this->alignment << endl;
|
---|
36 | break;
|
---|
37 | }
|
---|
38 |
|
---|
39 | al_draw_text(font, al_map_rgb(0, 255, 0), targetX, (this->height-fontHeight)/2, this->alignment, this->str.c_str());
|
---|
40 |
|
---|
41 | al_set_target_bitmap(al_get_backbuffer(display));
|
---|
42 | al_draw_bitmap(bitmap, x, y, 0);
|
---|
43 | }
|
---|
44 |
|
---|
45 | bool TextLabel::handleEvent(ALLEGRO_EVENT& e)
|
---|
46 | {
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | void TextLabel::setText(string str) {
|
---|
51 | this->str = str;
|
---|
52 | }
|
---|