Input.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_INPUT_HEADERS
30 #define NOMLIB_SDL2_INPUT_HEADERS
31 
32 #include <iostream>
33 #include <string>
34 #include <memory>
35 
36 #include "SDL.h"
37 
38 #include "nomlib/config.hpp"
39 #include "nomlib/SDL_helpers.hpp"
40 
42 //#define NOM_DEBUG_SDL2_KEYBOARD_INPUT
43 
45 //#define NOM_DEBUG_SDL2_MOUSE_INPUT
46 
48 //#define NOM_DEBUG_SDL2_JOYSTICK_BUTTON_INPUT
49 
51 //#define NOM_DEBUG_SDL2_JOYSTICK_AXIS_INPUT
52 
54 #define NOM_DEBUG_SDL2_DRAG_DROP_INPUT
55 
56 namespace nom {
57 
61 enum PSXAXES
62 {
63  LEFTX = 0,
64  LEFTY = 1,
65  RIGHTX = 2,
66  RIGHTY = 3
67 };
68 
70 enum PSXBUTTON
71 {
72  SELECT = 0,
73  JOYCLICKLEFT = 1,
74  JOYCLICKRIGHT = 2,
75  START = 3,
76  UP = 4,
77  RIGHT = 5,
78  DOWN = 6,
79  LEFT = 7,
80  L2 = 8,
81  R2 = 9,
82  L1 = 10,
83  R1 = 11,
84  TRIANGLE = 12,
85  CIRCLE = 13,
86  CROSS = 14,
87  SQUARE = 15,
88  PSBUTTON = 16
89 };
90 
92 class Input
93 {
94  public:
95  typedef SDL_Event EventType;
96  typedef std::unique_ptr<SDL_Joystick, void (*)(SDL_Joystick*)> JoystickUniquePtr;
97 
98  Input ( void );
99  virtual ~Input ( void );
100 
101  virtual void HandleInput ( SDL_Event* event );
102  protected:
103  virtual void onUserEvent ( uint32 type, int32 code, void* data1, void* data2 );
104 
105  virtual void onQuit ( void );
106  virtual void onResize ( int32 width, int32 height );
107  virtual void onRestore ( void );
108  virtual void onMinimize ( void );
109  virtual void onInputFocus ( void );
110  virtual void onInputBlur ( void );
111  virtual void onMouseFocus ( void );
112  virtual void onMouseBlur ( void );
113  virtual void onExpose ( void );
114 
115  virtual void onKeyDown ( int32 key, int32 mod, uint32 window_id );
116  virtual void onKeyUp ( int32 key, int32 mod, uint32 window_id );
117 
118  virtual void onMouseMotion ( int32 x, int32 y, uint32 window_id );
119  virtual void onMouseWheel ( int32 x, int32 y, uint32 window_id );
120  virtual void onMouseLeftButtonDown ( int32 x, int32 y, uint32 window_id );
121  virtual void onMouseMiddleButtonDown ( int32 x, int32 y, uint32 window_id );
122  virtual void onMouseRightButtonDown ( int32 x, int32 y, uint32 window_id );
123  virtual void onMouseButtonSixDown ( int32 x, int32 y, uint32 window_id );
124  virtual void onMouseButtonSevenDown ( int32 x, int32 y, uint32 window_id );
125 
126  virtual void onMouseLeftButtonUp ( int32 x, int32 y, uint32 window_id );
127  virtual void onMouseMiddleButtonUp ( int32 x, int32 y, uint32 window_id );
128  virtual void onMouseRightButtonUp ( int32 x, int32 y, uint32 window_id );
129  virtual void onMouseButtonSixUp ( int32 x, int32 y, uint32 window_id );
130  virtual void onMouseButtonSevenUp ( int32 x, int32 y, uint32 window_id );
131 
132  virtual void onJoyButtonDown ( int32 which, int32 button );
133  virtual void onJoyButtonUp ( int32 which, int32 button );
134  virtual void onJoyAxis ( int32 which, int32 axis, uint16 value );
135 
142  virtual void onDragDrop ( const std::string& file_path, uint32 timestamp );
143 
144  private:
145  JoystickUniquePtr joystick_;
146  SDL_JoystickID joystick_id_;
147 };
148 
149 
150 } // namespace nom
151 
152 #endif // include guard defined
virtual void onDragDrop(const std::string &file_path, uint32 timestamp)
Definition: Input.cpp:429
SDL Input Events Handling.
Definition: Input.hpp:92