1 | #include "chat.h"
|
---|
2 |
|
---|
3 | chat::chat(void)
|
---|
4 | {
|
---|
5 | }
|
---|
6 |
|
---|
7 | chat::~chat(void)
|
---|
8 | {
|
---|
9 | }
|
---|
10 |
|
---|
11 | string chat::getInput()
|
---|
12 | {
|
---|
13 | string temp = strEnteredInput;
|
---|
14 | strEnteredInput.clear();
|
---|
15 | return temp;
|
---|
16 | }
|
---|
17 |
|
---|
18 | void chat::draw(ALLEGRO_FONT *font, ALLEGRO_COLOR color)
|
---|
19 | {
|
---|
20 | for(unsigned int x=0; x<vctChat.size(); x++)
|
---|
21 | al_draw_text(font, color, 5, 100+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
|
---|
22 |
|
---|
23 | // I think this might never be used
|
---|
24 | al_draw_text(font, color, 5, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
|
---|
25 | }
|
---|
26 |
|
---|
27 | void chat::addLine(string s)
|
---|
28 | {
|
---|
29 | vctChat.push_back(s);
|
---|
30 | }
|
---|
31 |
|
---|
32 | // returns true if the event was consumed, false if it should be passed on
|
---|
33 | bool chat::handleEvent(ALLEGRO_EVENT e)
|
---|
34 | {
|
---|
35 | ALLEGRO_KEYBOARD_STATE keys;
|
---|
36 | al_get_keyboard_state(&keys);
|
---|
37 |
|
---|
38 | if (e.type == ALLEGRO_EVENT_KEY_DOWN) {
|
---|
39 | char newChar = 0;
|
---|
40 |
|
---|
41 | if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z) {
|
---|
42 | newChar = 'a'+e.keyboard.keycode-ALLEGRO_KEY_A;
|
---|
43 | if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
|
---|
44 | newChar -= 32;
|
---|
45 | }
|
---|
46 | if (ALLEGRO_KEY_0 <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_9)
|
---|
47 | newChar = '0'+e.keyboard.keycode-ALLEGRO_KEY_0;
|
---|
48 |
|
---|
49 | if (newChar != 0) {
|
---|
50 | strPrompt.append(1, newChar);
|
---|
51 | return true;
|
---|
52 | }
|
---|
53 |
|
---|
54 | if (e.keyboard.keycode == ALLEGRO_KEY_ENTER) {
|
---|
55 | strEnteredInput = strPrompt;
|
---|
56 | strPrompt.clear();
|
---|
57 | return true;
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | return false;
|
---|
62 | }
|
---|