usata-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Usata-commits] Changes to usata2/src/sdl/input.cpp


From: David Lau
Subject: [Usata-commits] Changes to usata2/src/sdl/input.cpp
Date: Tue, 25 Jan 2005 14:26:39 -0500

Index: usata2/src/sdl/input.cpp
diff -u usata2/src/sdl/input.cpp:1.1 usata2/src/sdl/input.cpp:1.2
--- usata2/src/sdl/input.cpp:1.1        Tue Jan 25 08:28:27 2005
+++ usata2/src/sdl/input.cpp    Tue Jan 25 19:26:33 2005
@@ -10,16 +10,52 @@
 // included in the software distribution, or visit
 // http://www.fsf.org/licenses/gpl.html.
 //
-// $Id: input.cpp,v 1.1 2005/01/25 08:28:27 skunix Exp $
+// $Id: input.cpp,v 1.2 2005/01/25 19:26:33 skunix Exp $
 
 #include "../input-system.hpp"
 #include <SDL.h>
 #include <vector>
 
+#include "../log.hpp"
+
 namespace usata { namespace input{
 namespace {
 
-using namespace input;
+//using namespace input;
+struct SDL2Usata
+{
+       SDLKey s;
+       int u;
+};
+
+SDL2Usata key_conversion[]=
+{
+       {SDLK_LEFT, Key::LEFT},
+       {SDLK_RIGHT, Key::RIGHT},
+       {SDLK_ESCAPE, Key::ESCAPE},
+       {SDLK_RETURN, Key::ENTER}
+
+};
+
+size_t key_conversion_len = sizeof(key_conversion)/sizeof(SDL2Usata);
+
+int key_convert(SDLKey sk)
+{
+       SDL2Usata *conv3rt = &key_conversion[0];
+       int retval(Key::UNKNOWN);
+
+       for (size_t cnt=0; cnt < key_conversion_len; cnt++)
+       {
+               if (conv3rt->s == sk)
+               {
+                       retval = conv3rt->u;
+                       break;
+               }
+               ++conv3rt;
+       }
+       return retval;
+};
+
 
 class SDLDriver: public input::Driver
 {
@@ -30,6 +66,8 @@
 
        SDL_Event mSDL_ev;
 
+               Event* key_process();
+
        public:
                SDLDriver();
                virtual void update(){}
@@ -47,7 +85,9 @@
        mMouseEnabled(true),
        mJoystickEnabled(true)
 {
-       
+       log::BufferedStream lb;
+
+       lb << "size of conv: " << sizeof(key_conversion)/sizeof(SDL2Usata) << 
log::commit;
 
 }
 
@@ -89,7 +129,8 @@
        {
                case SDL_KEYDOWN:
                case SDL_KEYUP:
-       
+                       return key_process();
+                       break;
                case SDL_QUIT:
                        return new SystemEvent(SystemEvent::QUIT);      
                        break;
@@ -101,6 +142,21 @@
 }
 
 Event*
+SDLDriver::key_process()
+{
+       Event*retval;
+       bool state=false;
+       if (mSDL_ev.type == SDL_KEYDOWN)
+               state=true;
+
+       int key = key_convert(mSDL_ev.key.keysym.sym);          
+
+       retval = new KeyEvent(key, state);
+
+       return retval;
+};
+
+Event*
 SDLDriver::next()
 {
        Event*retval(0);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]