1 //==============================================================================
2 // This program is free software; you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation; either version 2 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Library General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 //==============================================================================
16
17 //==============================================================================
18 // File: cActionMapper.cpp
19 // Project: Shooting Star
20 // Author:
21 // Copyrights (c) 2003 2ndPoint ry (www.2ndpoint.fi)
22 //------------------------------------------------------------------------------
23 // Revision history
24 //==============================================================================
25
26 //==============================================================================
27 // Includes
28 #include "cActionMapper.hpp"
29 #include "Debug.hpp"
30 //------------------------------------------------------------------------------
31 // Namespaces
32 using namespace ShootingStar;
33 //==============================================================================
34
35
36 //! Constructor
cActionMapper(void)37 cActionMapper::cActionMapper (void)
38 {
39 // Empty
40 };
41
42 //! Destructor
~cActionMapper(void)43 cActionMapper::~cActionMapper (void)
44 {
45 // Empty
46 };
47
48 //! Register keyboard action
49 void
RegisterKeyboardAction(SDLKey key,Uint8 state,const cAction & action)50 cActionMapper::RegisterKeyboardAction (SDLKey key, Uint8 state, const cAction &action)
51 {
52 switch ( state )
53 {
54 case SDL_PRESSED:
55 mKeyDownActions[key] = action;
56 break;
57 case SDL_RELEASED:
58 mKeyUpActions[key] = action;
59 break;
60 default:
61 dbgError () << "RegisterKeyboardAction: Invalid state\n";
62 dbg::sentinel (DBG_HERE);
63 break;
64 }
65 }
66
67 void
RegisterMouseAction(Uint8 button,Uint8 state,const cAction & action)68 cActionMapper::RegisterMouseAction (Uint8 button, Uint8 state, const cAction &action)
69 {
70 switch ( state )
71 {
72 case SDL_PRESSED:
73 mButtonDownActions[button] = action;
74 break;
75 case SDL_RELEASED:
76 mButtonUpActions[button] = action;
77 break;
78 default:
79 dbgError () << "RegisterMouseAction: Invalid state\n";
80 dbg::sentinel (DBG_HERE);
81 break;
82 }
83 }
84
85 //! Map keyboard event to action
86 const cAction &
MapKeyboardEvent(const SDL_KeyboardEvent * pEvent)87 cActionMapper::MapKeyboardEvent (const SDL_KeyboardEvent *pEvent)
88 {
89 switch ( pEvent->state )
90 {
91 case SDL_PRESSED:
92 return mKeyDownActions[pEvent->keysym.sym];
93 case SDL_RELEASED:
94 return mKeyUpActions[pEvent->keysym.sym];
95 default:
96 dbg::sentinel (DBG_HERE);
97 break;
98 }
99
100 static cAction emptyAction;
101 return emptyAction;
102 }
103
104 const cAction &
MapMouseEvent(const SDL_MouseButtonEvent * pEvent)105 cActionMapper::MapMouseEvent (const SDL_MouseButtonEvent *pEvent)
106 {
107 switch ( pEvent->state )
108 {
109 case SDL_PRESSED:
110 return mButtonDownActions[pEvent->button];
111 case SDL_RELEASED:
112 return mButtonUpActions[pEvent->button];
113 default:
114 dbg::sentinel (DBG_HERE);
115 break;
116 }
117
118 static cAction emptyAction;
119 return emptyAction;
120 }
121
122 //==============================================================================
123 // EOF
124 //==============================================================================
125