/[usata]/usata2/src/sdl/input.cpp
ViewVC logotype

Diff of /usata2/src/sdl/input.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by skunix, Tue Jan 25 19:26:33 2005 UTC revision 1.3 by skunix, Fri Feb 25 19:50:48 2005 UTC
# Line 12  Line 12 
12  //  //
13  // $Id$  // $Id$
14    
15    #include <queue>
16    
17  #include "../input-system.hpp"  #include "../input-system.hpp"
18  #include <SDL.h>  #include <SDL.h>
19  #include <vector>  #include <vector>
   
20  #include "../log.hpp"  #include "../log.hpp"
21    
22    
23  namespace usata { namespace input{  namespace usata { namespace input{
24  namespace {  namespace {
25    
# Line 56  int key_convert(SDLKey sk) Line 58  int key_convert(SDLKey sk)
58          return retval;          return retval;
59  };  };
60    
61    class SDLDriver : public input::Driver
 class SDLDriver: public input::Driver  
62  {  {
63            std::queue<input::Event*> mEventQueue;
         bool mKbEnabled,  
                  mMouseEnabled,  
                  mJoystickEnabled;  
   
         SDL_Event mSDL_ev;  
   
                 Event* key_process();  
   
64          public:          public:
65                  SDLDriver();                  SDLDriver();
66                  virtual void update(){}                  virtual ~SDLDriver();
                 virtual void configure ();  
                 virtual bool supports(DeviceType type);  
                 virtual bool enable(DeviceType type, bool);      
                 Event* process();  
67                  virtual Event* next();                  virtual Event* next();
68                    Event* process(SDL_Event&);
69                    virtual void update();
70  };  };
71    
72  SDLDriver::SDLDriver()  SDLDriver::SDLDriver()
73  :       input::Driver("sdl"),  : input::Driver("SDL")
         mKbEnabled(true),  
         mMouseEnabled(true),  
         mJoystickEnabled(true)  
74  {  {
         log::BufferedStream lb;  
   
         lb << "size of conv: " << sizeof(key_conversion)/sizeof(SDL2Usata) << log::commit;  
75    
76  }  }
77    
78  bool  SDLDriver::~SDLDriver()
 SDLDriver::supports(DeviceType dt)  
79  {  {
         return true;  
 };  
 bool  
 SDLDriver::enable(DeviceType type, bool e)  
 {  
         bool retval = false;  
         switch (type)  
         {  
                 case KEYBOARD:  
                 case JOYSTICK:  
                 case MOUSE:              
                         break;  
                 default:  
                         break;  
         }  
         return retval;  
   
80  }  }
81    
82  void  Event*
83  SDLDriver::configure()  SDLDriver::next()
84  {  {
85            Event*retval=0;
86            if (mEventQueue.empty())
87          return;                  return retval;
88            retval = mEventQueue.front();
89            mEventQueue.pop();              
90            return retval;
91  }  }
92    
93  Event*  Event*
94  SDLDriver::process()  SDLDriver::process(SDL_Event&ev)
95  {  {
96                    
97          switch (mSDL_ev.type)          switch (ev.type)
98          {          {
99                  case SDL_KEYDOWN:                  case SDL_KEYDOWN:
100                  case SDL_KEYUP:                  case SDL_KEYUP:
101                          return key_process();  //                      return key_process();
102                          break;                          break;
103                  case SDL_QUIT:                  case SDL_QUIT:
104                          return new SystemEvent(SystemEvent::QUIT);                                return new SystemEvent(SystemEvent::QUIT);      
105                          break;                          break;
106    
107          };          };
           
   
108          return 0;          return 0;
109  }  }
110    
111  Event*  void
112  SDLDriver::key_process()  SDLDriver::update()
 {  
         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()  
113  {  {
114          Event*retval(0);          SDL_Event ev;
115                    
116          while (1)          while (SDL_PollEvent(&ev))
117          {          {
118                  if (!SDL_PollEvent(&mSDL_ev))                  Event* uev= process(ev);
119                          break;                  if (uev)
120                            mEventQueue.push(uev);
121                  retval = process();          }
                 if (retval)  
                         break;  
         }        
   
122    
123          return retval;          return;
124  }  }
   
   
   
   
125  }  }
   
126  Driver * default_driver()  Driver * default_driver()
127  {  {
128    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26