Event.hpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 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 struct Key
00040 {
00041     enum Code
00042     {
00043         A = 'a', Z = 'z', E = 'e', R = 'r', T = 't', Y = 'y', U = 'u', I = 'i', O = 'o', P = 'p',
00044         Q = 'q', S = 's', D = 'd', F = 'f', G = 'g', H = 'h', J = 'j', K = 'k', L = 'l', M = 'm',
00045         W = 'w', X = 'x', C = 'c', V = 'v', B = 'b', N = 'n',
00046         Num0 = '0', Num1 = '1', Num2 = '2', Num3 = '3', Num4 = '4',
00047         Num5 = '5', Num6 = '6', Num7 = '7', Num8 = '8', Num9 = '9', 
00048         Escape = 256,
00049         Space, Return, Back, Tab, PageUp, PageDown, End, Home, Insert, Delete, Add, Subtract, Multiply, Divide,
00050         Left, Right, Up, Down,
00051         Numpad0, Numpad1, Numpad2, Numpad3, Numpad4, Numpad5, Numpad6, Numpad7, Numpad8, Numpad9,
00052         F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15,
00053         Pause,
00054 
00055         Count // For internal use
00056     };
00057 };
00058 
00059 
00063 struct Mouse
00064 {
00065     enum Button
00066     {
00067         Left   = 1 << 1,
00068         Right  = 1 << 2,
00069         Middle = 1 << 3
00070     };
00071 };
00072 
00073 
00077 class Event
00078 {
00079 public :
00080 
00084     enum EventType
00085     {
00086         Close,
00087         Resize,
00088         LostFocus,
00089         GainedFocus,
00090         TextEntered,
00091         KeyPressed,
00092         KeyReleased,
00093         MouseWheelMoved,
00094         MouseButtonPressed,
00095         MouseButtonReleased,
00096         MouseMove,
00097         JoystickButtonPressed,
00098         JoystickButtonReleased,
00099         JoystickMove
00100     };
00101 
00103     // Member data
00105     EventType Type; 
00106 
00107     union
00108     {
00109 
00113         struct
00114         {
00115             Uint16 Unicode;
00116         } Text;
00117 
00121         struct
00122         {
00123             Key::Code Code;
00124             bool      Alt;
00125             bool      Control;
00126             bool      Shift;
00127         } Key;
00128 
00132         struct
00133         {
00134             unsigned int Buttons;
00135             unsigned int X;
00136             unsigned int Y;
00137         } Mouse;
00138 
00142         struct
00143         {
00144             int Delta;
00145         } MouseWheel;
00146 
00150         struct
00151         {
00152             unsigned int JoystickId;
00153             unsigned int Button;
00154             int          X;
00155             int          Y;
00156             int          Z;
00157         } Joystick;
00158 
00162         struct
00163         {
00164             unsigned int Width;
00165             unsigned int Height;
00166         } Size;
00167     };
00168 };
00169 
00170 } // namespace sf
00171 
00172 
00173 #endif // SFML_EVENT_HPP