[365e156] | 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;
|
---|
[3ea1839] | 36 | targetX = 0;
|
---|
[365e156] | 37 | break;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | al_draw_text(font, al_map_rgb(0, 255, 0), targetX, (this->height-fontHeight)/2, this->alignment, this->str.c_str());
|
---|
| 41 |
|
---|
| 42 | al_set_target_bitmap(al_get_backbuffer(display));
|
---|
| 43 | al_draw_bitmap(bitmap, x, y, 0);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | bool TextLabel::handleEvent(ALLEGRO_EVENT& e)
|
---|
| 47 | {
|
---|
| 48 | return false;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void TextLabel::setText(string str) {
|
---|
| 52 | this->str = str;
|
---|
[3ea1839] | 53 | }
|
---|