Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

input.h

Go to the documentation of this file.
00001 #ifndef __INPUT_H
00002 #define __INPUT_H
00003 
00004 #include <SDL/SDL_events.h>
00005 #include <SDL/SDL_mouse.h>
00006 #include <SDL/SDL_keyboard.h>
00007 #include <SDL/SDL_keysym.h>
00008 
00009 typedef SDL_Event Event; 
00010 
00011 class Input {
00012 public:
00013         enum MouseButton {
00014                 MOUSE_BUTTON1 = 0x01
00015         };
00016         
00017         enum Key {
00018                 UNKNOWN = 0,
00019                 CANCEL,
00020                 FAST_QUIT,
00021                 FULLSCREEN_TOGGLE,
00022                 LOCKMOUSE_TOGGLE,
00023                 WALK_WEST,
00024                 WALK_EAST,
00025                 WALK_NORTH,
00026                 WALK_SOUTH,
00027                 ADD_UFO,
00028                 MUSIC_TOGGLE,
00029                 RAPID_FIRE,
00030                 SWITCH_MUSIC,
00031                 ROT_UP,
00032                 ROT_DOWN,
00033                 KLAST
00034         };
00035                 
00036         Input();
00037         ~Input();
00038 
00039         void init();
00040                 
00041         // Returns a bitmask OR'd of button presses.
00042         int GetMouse (int &x, int &y);
00043         
00044         // Clears the state of the mouse
00045         bool ResetMouse (unsigned int mask = (unsigned int)-1);
00046         bool ResetMouseButton(unsigned int mask);
00047 
00048         // If argument is true, confines the mouse to our window.
00049         bool LockMouse(bool);
00050         
00051         // Return true if a certain key is pressed
00052         bool IsPressed(Key);
00053 
00054         // Return true if shift is pressed
00055         bool IsShift() { return ((SDL_GetModState() & (KMOD_LSHIFT|KMOD_RSHIFT)) != 0); }
00056         
00057         // Clear the keypress
00058         bool ResetKey(Key);
00059         
00060         // Handles the Event calls, returns true if handled properly
00061         bool Update(Event &);
00062         
00063         // Maps an SDL key to an input key.
00064         void Map(int sdlkey, Key inputkey);
00065 private:
00066         void HandleKeyDown(int sdlkeysym);
00067         void HandleKeyUp(int sdlkeysym);
00068         void HandleMouseMotion(int x, int y);
00069         void HandleMouseButtonDown(int button);
00070         void HandleMouseButtonUp(int button);
00071         
00072         Key mapping[SDLK_LAST];
00073         bool presses[KLAST];
00074         int mouse_press;
00075         int mouse_x, mouse_y;
00076 };
00077 
00078 
00079 #endif

Generated on Sun Dec 8 12:02:19 2002 for nnc by doxygen1.3-rc1