source: network-game/client/Client/TextLabel.cpp@ 7f9b01c

Last change on this file since 7f9b01c was 3ea1839, checked in by Dmitry Portnoy <dportnoy@…>, 10 years ago

Fix Mac compiler warnings

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[365e156]1#include "TextLabel.h"
2
3#include <iostream>
4
5TextLabel::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
12TextLabel::~TextLabel(void)
13{
14}
15
16void 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
46bool TextLabel::handleEvent(ALLEGRO_EVENT& e)
47{
48 return false;
49}
50
51void TextLabel::setText(string str) {
52 this->str = str;
[3ea1839]53}
Note: See TracBrowser for help on using the repository browser.