source: network-game/client/Client/TextLabel.cpp@ 9c18cb7

Last change on this file since 9c18cb7 was 365e156, checked in by dportnoy <dmp1488@…>, 11 years ago

Added a TextLabel gui element and updated the client to show status messages when registering or logging in

  • 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;
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
45bool TextLabel::handleEvent(ALLEGRO_EVENT& e)
46{
47 return false;
48}
49
50void TextLabel::setText(string str) {
51 this->str = str;
52}
Note: See TracBrowser for help on using the repository browser.