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(int x=0; x<vctChat.size(); x++)
|
---|
21 | al_draw_text(font, color, 10, 10+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
|
---|
22 |
|
---|
23 | al_draw_text(font, color, 10, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
|
---|
24 | }
|
---|
25 |
|
---|
26 | void chat::addLine(string s)
|
---|
27 | {
|
---|
28 | vctChat.push_back(s);
|
---|
29 | }
|
---|
30 |
|
---|
31 | // returns true if the event was consumed, false if it should be passed on
|
---|
32 | bool chat::processEvent(ALLEGRO_EVENT ev)
|
---|
33 | {
|
---|
34 | ALLEGRO_KEYBOARD_STATE keys;
|
---|
35 | al_get_keyboard_state(&keys);
|
---|
36 |
|
---|
37 | if (ev.type == ALLEGRO_EVENT_KEY_DOWN) {
|
---|
38 | char newChar = 0;
|
---|
39 |
|
---|
40 | if (ALLEGRO_KEY_A <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_Z) {
|
---|
41 | newChar = 'a'+ev.keyboard.keycode-ALLEGRO_KEY_A;
|
---|
42 | if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
|
---|
43 | newChar -= 32;
|
---|
44 | }
|
---|
45 | if (ALLEGRO_KEY_0 <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_9)
|
---|
46 | newChar = '0'+ev.keyboard.keycode-ALLEGRO_KEY_0;
|
---|
47 |
|
---|
48 | if (newChar != 0) {
|
---|
49 | strPrompt.append(1, newChar);
|
---|
50 | return true;
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (ev.keyboard.keycode == ALLEGRO_KEY_ENTER) {
|
---|
54 | strEnteredInput = strPrompt;
|
---|
55 | strPrompt.clear();
|
---|
56 | return true;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | return false;
|
---|
61 | }
|
---|