source: network-game/client/Client/RadioButtonList.cpp@ d998572

Last change on this file since d998572 was 49da01a, checked in by dportnoy <dmp1488@…>, 11 years ago

Add status messages for login and registration and remove the Message class (MessageProcessor includes all that functionality now)

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include "RadioButtonList.h"
2
3#include <string>
4#include <cmath>
5
6using namespace std;
7
8RadioButtonList::RadioButtonList(int x, int y, string strLabel, ALLEGRO_FONT *font) :
9 GuiComponent(x, y, 300, 300, font)
10{
11 this->strLabel = strLabel;
12 this->selectedButton = -1;
13}
14
15
16RadioButtonList::~RadioButtonList(void)
17{
18}
19
20void RadioButtonList::draw(ALLEGRO_DISPLAY *display)
21{
22 al_set_target_bitmap(bitmap);
23 al_clear_to_color(al_map_rgb(0, 0, 0));
24
25 int fontHeight = al_get_font_line_height(font);
26
27 al_draw_text(font, al_map_rgb(0, 255, 0), 0, 0, ALLEGRO_ALIGN_LEFT, this->strLabel.c_str());
28 for(unsigned int i=0; i<this->vctRadioButtons.size(); i++) {
29 al_draw_circle(12, 26+i*20, 8, al_map_rgb(0, 255, 0), 1);
30 if (i == this->selectedButton)
31 al_draw_filled_circle(12, 26+i*20, 6, al_map_rgb(0, 255, 0));
32 al_draw_text(font, al_map_rgb(0, 255, 0), 26, 20+i*20, ALLEGRO_ALIGN_LEFT, this->vctRadioButtons[i].c_str());
33 }
34
35 al_set_target_bitmap(al_get_backbuffer(display));
36 al_draw_bitmap(bitmap, x, y, 0);
37}
38
39bool RadioButtonList::handleEvent(ALLEGRO_EVENT& e)
40{
41 int centerX, centerY;
42 centerX = x+12;
43
44 if (e.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
45 if (e.mouse.button == 1) {
46 for (int i=0; i<this->vctRadioButtons.size(); i++) {
47 centerY = y+26+i*20;
48
49 if (sqrt(pow((float)(e.mouse.x-centerX), 2.0f)+pow((float)(e.mouse.y-centerY), 2.0f))< 8) {
50 this->selectedButton = i;
51 return true;
52 }
53 }
54 }
55 }
56
57 return false;
58}
59
60void RadioButtonList::addRadioButton(string s) {
61 this->vctRadioButtons.push_back(s);
62}
63
64int RadioButtonList::getSelectedButton() {
65 return this->selectedButton;
66}
67
68void RadioButtonList::setSelectedButton(int b) {
69 this->selectedButton = b;
70}
Note: See TracBrowser for help on using the repository browser.