Event.hpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00025 #ifndef SFML_EVENT_HPP
00026 #define SFML_EVENT_HPP
00027 
00029 // Headers
00031 #include <SFML/Config.hpp>
00032 
00033 
00034 namespace sf
00035 {
00039 namespace Key
00040 {
00041     enum Code
00042     {
00043         A = 'a',
00044         B = 'b',
00045         C = 'c',
00046         D = 'd',
00047         E = 'e',
00048         F = 'f',
00049         G = 'g',
00050         H = 'h',
00051         I = 'i',
00052         J = 'j',
00053         K = 'k',
00054         L = 'l',
00055         M = 'm',
00056         N = 'n',
00057         O = 'o',
00058         P = 'p',
00059         Q = 'q',
00060         R = 'r',
00061         S = 's',
00062         T = 't',
00063         U = 'u',
00064         V = 'v',
00065         W = 'w',
00066         X = 'x',
00067         Y = 'y',
00068         Z = 'z',
00069         Num0 = '0',
00070         Num1 = '1',
00071         Num2 = '2',
00072         Num3 = '3',
00073         Num4 = '4',
00074         Num5 = '5',
00075         Num6 = '6',
00076         Num7 = '7',
00077         Num8 = '8',
00078         Num9 = '9', 
00079         Escape = 256,
00080         LControl,
00081         LShift,
00082         LAlt,
00083         LSystem,      
00084         RControl,
00085         RShift,
00086         RAlt,
00087         RSystem,      
00088         Menu,
00089         LBracket,     
00090         RBracket,     
00091         SemiColon,    
00092         Comma,        
00093         Period,       
00094         Quote,        
00095         Slash,        
00096         BackSlash,
00097         Tilde,        
00098         Equal,        
00099         Dash,         
00100         Space,
00101         Return,
00102         Back,
00103         Tab,
00104         PageUp,
00105         PageDown,
00106         End,
00107         Home,
00108         Insert,
00109         Delete,
00110         Add,          
00111         Subtract,     
00112         Multiply,     
00113         Divide,       
00114         Left,         
00115         Right,        
00116         Up,           
00117         Down,         
00118         Numpad0,
00119         Numpad1,
00120         Numpad2,
00121         Numpad3,
00122         Numpad4,
00123         Numpad5,
00124         Numpad6,
00125         Numpad7,
00126         Numpad8,
00127         Numpad9,
00128         F1,
00129         F2,
00130         F3,
00131         F4,
00132         F5,
00133         F6,
00134         F7,
00135         F8,
00136         F9,
00137         F10,
00138         F11,
00139         F12,
00140         F13,
00141         F14,
00142         F15,
00143         Pause,
00144 
00145         Count // For internal use
00146     };
00147 }
00148 
00149 
00153 namespace Mouse
00154 {
00155     enum Button
00156     {
00157         Left,
00158         Right,
00159         Middle,
00160         XButton1,
00161         XButton2,
00162 
00163         Count // For internal use
00164     };
00165 }
00166 
00167 
00171 namespace Joy
00172 {
00173     enum Axis
00174     {
00175         AxisX,
00176         AxisY,
00177         AxisZ,
00178         AxisR,
00179         AxisU,
00180         AxisV,
00181         AxisPOV,
00182 
00183         Count // For internal use
00184     };
00185 }
00186 
00187 
00191 class Event
00192 {
00193 public :
00194 
00198     struct KeyEvent
00199     {
00200         Key::Code Code;
00201         bool      Alt;
00202         bool      Control;
00203         bool      Shift;
00204     };
00205 
00209     struct TextEvent
00210     {
00211         Uint16 Unicode;
00212     };
00213 
00217     struct MouseMoveEvent
00218     {
00219         unsigned int X;
00220         unsigned int Y;
00221     };
00222 
00226     struct MouseButtonEvent
00227     {
00228         Mouse::Button Button;
00229     };
00230 
00234     struct MouseWheelEvent
00235     {
00236         int Delta;
00237     };
00238 
00242     struct JoyMoveEvent
00243     {
00244         unsigned int JoystickId;
00245         Joy::Axis    Axis;
00246         float        Position;
00247     };
00248 
00252     struct JoyButtonEvent
00253     {
00254         unsigned int JoystickId;
00255         unsigned int Button;
00256     };
00257 
00261     struct SizeEvent
00262     {
00263         unsigned int Width;
00264         unsigned int Height;
00265     };
00266 
00270     enum EventType
00271     {
00272         Closed,
00273         Resized,
00274         LostFocus,
00275         GainedFocus,
00276         TextEntered,
00277         KeyPressed,
00278         KeyReleased,
00279         MouseWheelMoved,
00280         MouseButtonPressed,
00281         MouseButtonReleased,
00282         MouseMoved,
00283         JoyButtonPressed,
00284         JoyButtonReleased,
00285         JoyMoved
00286     };
00287 
00289     // Member data
00291     EventType Type; 
00292 
00293     union
00294     {
00295         KeyEvent         Key;
00296         TextEvent        Text;
00297         MouseMoveEvent   MouseMove;
00298         MouseButtonEvent MouseButton;
00299         MouseWheelEvent  MouseWheel;
00300         JoyMoveEvent     JoyMove;
00301         JoyButtonEvent   JoyButton;
00302         SizeEvent        Size;
00303     };
00304 };
00305 
00306 } // namespace sf
00307 
00308 
00309 #endif // SFML_EVENT_HPP