D:/Development/Projects/X-Clone/X-Clone/trunk/Input.cpp

Go to the documentation of this file.
00001 #include "Input.h"
00002 #include "XClone.h"
00003 #include "Chat.h"
00004 
00005 Input::Input()
00006 {
00007     _mode = command;
00008     _str = "";
00009     SDL_EnableUNICODE( SDL_ENABLE );
00010 }
00011 
00012 void Input::processSDLEvent(SDL_Event& event) 
00013 {
00014     if (event.type == SDL_QUIT) 
00015     {
00016        XClone::instance().quit();
00017     }
00018     else if ( event.type == SDL_KEYDOWN )
00019     {
00020        if (_mode == command) 
00021        {
00022           switch ( event.key.keysym.sym )
00023           {
00024              case SDLK_ESCAPE:
00025                 XClone::instance().quit();
00026                 break;
00027              case SDLK_RETURN:
00028                 if ( _mode == command )
00029                    _mode = chat;
00030                 break;
00031              default:
00032                 XClone::instance().processSDLEvent(event);
00033                 break;
00034           }
00035        }
00036        else if (_mode == chat)
00037        {
00038           if( _str.length() <= 64 )
00039           {
00040              //if( event.key.keysym.unicode == (Uint16)' ' )
00041              //    _str += (char)event.key.keysym.unicode;    
00042              if( event.key.keysym.unicode == SDLK_SPACE )
00043                 _str += "_";
00044              if( ( event.key.keysym.unicode >= (Uint16)'0' ) && ( event.key.keysym.unicode <= (Uint16)'9' ) )
00045                 _str += (char)event.key.keysym.unicode;
00046              else if( ( event.key.keysym.unicode >= (Uint16)'A' ) && ( event.key.keysym.unicode <= (Uint16)'Z' ) )
00047                 _str += (char)event.key.keysym.unicode;
00048              else if( ( event.key.keysym.unicode >= (Uint16)'a' ) && ( event.key.keysym.unicode <= (Uint16)'z' ) )
00049                 _str += (char)event.key.keysym.unicode;
00050           }
00051           if( ( event.key.keysym.sym == SDLK_BACKSPACE ) && ( _str.length() != 0 ) )
00052              _str.erase( _str.length() - 1 );
00053           if( ( event.key.keysym.sym == SDLK_ESCAPE ) )
00054           {
00055              _str = "";
00056              _mode = command;
00057              return;
00058           }
00059           if( ( event.key.keysym.sym == SDLK_RETURN ) && ( _str.length() != 0 ) )
00060           {
00061              Chat::instance().sendMessage( _str );
00062              _mode = command;
00063              _str = "";
00064           }
00065           Chat::instance().inputMessage( _str );
00066           return;
00067        }
00068     }
00069     else {
00070        XClone::instance().processSDLEvent(event);
00071     }
00072 }
00073 
00074 Point Input::getMousePosition() const
00075 {
00076     Point p;
00077     SDL_GetMouseState(&p.x, &p.y);
00078     return p;
00079 }
00080 

Generated on Fri Sep 22 06:00:26 2006 for X-CLONE by  doxygen 1.4.7