- Timestamp:
- Dec 9, 2012, 8:56:45 PM (12 years ago)
- Branches:
- master
- Children:
- cdb4bec
- Parents:
- 581058c
- Location:
- client/Client
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj
r581058c re607c0f 73 73 </ItemGroup> 74 74 <ItemGroup> 75 <ClInclude Include="..\..\common\Common.h" /> 75 76 <ClInclude Include="..\..\common\Compiler.h" /> 76 77 <ClInclude Include="..\..\common\Message.h" /> -
client/Client/Client.vcxproj.filters
r581058c re607c0f 72 72 <Filter>Header Files\common</Filter> 73 73 </ClInclude> 74 <ClInclude Include="..\..\common\Common.h"> 75 <Filter>Header Files\common</Filter> 76 </ClInclude> 74 77 </ItemGroup> 75 78 </Project> -
client/Client/Textbox.cpp
r581058c re607c0f 10 10 str = ""; 11 11 selected = false; 12 shiftPressed = false; 13 14 // populate the shift map 15 for(int i=0; i<26; i++) 16 shiftMap['a'+i] = 'A'+i; 17 18 shiftMap['1'] = '!'; 19 shiftMap['2'] = '@'; 20 shiftMap['3'] = '#'; 21 shiftMap['4'] = '$'; 22 shiftMap['5'] = '%'; 23 shiftMap['6'] = '^'; 24 shiftMap['7'] = '&'; 25 shiftMap['8'] = '*'; 26 shiftMap['9'] = '('; 27 shiftMap['0'] = ')'; 28 29 shiftMap['`'] = '~'; 30 shiftMap['-'] = '_'; 31 shiftMap['='] = '+'; 32 shiftMap['['] = '{'; 33 shiftMap[']'] = '}'; 34 shiftMap['\\'] = '|'; 35 shiftMap[';'] = ':'; 36 shiftMap['\''] = '\"'; 37 shiftMap[','] = '<'; 38 shiftMap['.'] = '>'; 39 shiftMap['/'] = '?'; 40 shiftMap[' '] = ' '; 12 41 } 13 42 … … 70 99 char newChar = 0; 71 100 72 if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z) {101 if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z) 73 102 newChar = 'a'+e.keyboard.keycode-ALLEGRO_KEY_A; 74 if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))75 newChar -= 32;76 }77 103 else if (ALLEGRO_KEY_0 <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_9) 78 104 newChar = '0'+e.keyboard.keycode-ALLEGRO_KEY_0; 79 else if (e.keyboard.keycode = ALLEGRO_KEY_BACKSPACE && str.size() > 0) 80 str = str.substr(0, str.size()-1); 105 else { 106 switch(e.keyboard.keycode) 107 { 108 case ALLEGRO_KEY_TILDE: 109 newChar = '`'; 110 break; 111 case ALLEGRO_KEY_MINUS: 112 newChar = '-'; 113 break; 114 case ALLEGRO_KEY_EQUALS: 115 newChar = '='; 116 break; 117 case ALLEGRO_KEY_OPENBRACE: 118 newChar = '['; 119 break; 120 case ALLEGRO_KEY_CLOSEBRACE: 121 newChar = ']'; 122 break; 123 case ALLEGRO_KEY_SEMICOLON: 124 newChar = ';'; 125 break; 126 case ALLEGRO_KEY_QUOTE: 127 newChar = '\''; 128 break; 129 case ALLEGRO_KEY_BACKSLASH: 130 newChar = '\\'; 131 break; 132 case ALLEGRO_KEY_COMMA: 133 newChar = ','; 134 break; 135 case ALLEGRO_KEY_FULLSTOP: 136 newChar = '.'; 137 break; 138 case ALLEGRO_KEY_SLASH: 139 newChar = '/'; 140 break; 141 case ALLEGRO_KEY_SPACE: 142 newChar = ' '; 143 break; 144 case ALLEGRO_KEY_BACKSPACE: 145 if (str.size() > 0) 146 { 147 str = str.substr(0, str.size()-1); 148 return true; 149 } 150 else 151 return false; 152 break; 153 case ALLEGRO_KEY_LSHIFT: 154 case ALLEGRO_KEY_RSHIFT: 155 shiftPressed = true; 156 break; 157 default: 158 cout << "unknown keycode: " << e.keyboard.keycode << endl; 159 break; 160 } 161 } 81 162 82 163 if (newChar != 0) { 164 if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT)) 165 newChar = shiftMap[newChar]; 166 83 167 str.append(1, newChar); 84 168 return true; 169 } 170 } 171 else if (e.type == ALLEGRO_EVENT_KEY_UP) { 172 switch(e.keyboard.keycode) 173 { 174 case ALLEGRO_KEY_LSHIFT: 175 case ALLEGRO_KEY_RSHIFT: 176 shiftPressed = false; 177 break; 85 178 } 86 179 } -
client/Client/Textbox.h
r581058c re607c0f 5 5 6 6 #include <string> 7 #include <map> 7 8 8 9 using namespace std; … … 14 15 string str; 15 16 bool selected; 17 bool shiftPressed; 18 map<char, char> shiftMap; 16 19 17 20 public: -
client/Client/main.cpp
r581058c re607c0f 23 23 #include "../../common/Compiler.h" 24 24 #include "../../common/Message.h" 25 #include "../../common/Common.h" 25 26 26 27 #include "Window.h" … … 200 201 error("socket"); 201 202 203 set_nonblock(sock); 204 202 205 server.sin_family = AF_INET; 203 206 hp = gethostbyname(argv[1]); … … 209 212 210 213 al_start_timer(timer); 211 214 212 215 while(!doexit) 213 216 { … … 282 285 } 283 286 } 284 285 if(redraw && al_is_event_queue_empty(event_queue)) { 287 288 if (receiveMessage(&msgFrom, sock, &from) >= 0) 289 { 290 processMessage(msgFrom, state, chatConsole); 291 cout << "state: " << state << endl; 292 } 293 294 if (redraw && al_is_event_queue_empty(event_queue)) 295 { 286 296 redraw = false; 287 297 … … 364 374 case STATE_START: 365 375 { 376 cout << "In STATE_START" << endl; 377 366 378 chatConsole.addLine(response); 367 379 … … 448 460 449 461 sendMessage(&msgTo, sock, &server); 450 receiveMessage(&msgFrom, sock, &from);451 processMessage(msgFrom, state, chatConsole);452 cout << "state: " << state << endl;453 462 } 454 463 … … 468 477 469 478 sendMessage(&msgTo, sock, &server); 470 receiveMessage(&msgFrom, sock, &from);471 processMessage(msgFrom, state, chatConsole);472 cout << "state: " << state << endl;473 479 } 474 480 … … 482 488 483 489 sendMessage(&msgTo, sock, &server); 484 receiveMessage(&msgFrom, sock, &from);485 processMessage(msgFrom, state, chatConsole);486 490 } 487 491 … … 502 506 503 507 sendMessage(&msgTo, sock, &server); 504 receiveMessage(&msgFrom, sock, &from); 505 processMessage(msgFrom, state, chatConsole); 506 } 508 }
Note:
See TracChangeset
for help on using the changeset viewer.