style cleanup: comment format
[blender.git] / source / gameengine / BlenderRoutines / KX_BlenderMouseDevice.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
29  *  \ingroup blroutines
30  */
31
32 #ifdef _MSC_VER
33    /* annoying warnings about truncated STL debug info */
34 #  pragma warning (disable:4786)
35 #endif 
36
37 #include "KX_BlenderMouseDevice.h"
38
39 KX_BlenderMouseDevice::KX_BlenderMouseDevice()
40 {
41
42 }
43 KX_BlenderMouseDevice::~KX_BlenderMouseDevice()
44 {
45
46 }
47
48 /**
49  * IsPressed gives boolean information about mouse status, true if pressed, false if not
50  */
51
52 bool KX_BlenderMouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
53 {
54         const SCA_InputEvent & inevent =  m_eventStatusTables[m_currentTable][inputcode];
55         bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 
56                 inevent.m_status == SCA_InputEvent::KX_ACTIVE);
57         return pressed;
58 }
59 /*const SCA_InputEvent& KX_BlenderMouseDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
60 {
61         return m_eventStatusTables[m_currentTable][inputcode];
62 }
63 */
64
65 /**
66  * NextFrame toggles currentTable with previousTable,
67  * and copy relevant event information from previous to current
68  * (pressed keys need to be remembered)
69  */
70 void    KX_BlenderMouseDevice::NextFrame()
71 {
72         SCA_IInputDevice::NextFrame();
73         
74         // now convert justpressed keyevents into regular (active) keyevents
75         int previousTable = 1-m_currentTable;
76         for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS;mouseevent++)
77         {
78                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent];
79                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
80                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
81                 {
82                         m_eventStatusTables[m_currentTable][mouseevent] = oldevent;
83                         m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE;
84                 }
85         }
86         for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE;mousemove++)
87         {
88                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove];
89                 m_eventStatusTables[m_currentTable][mousemove] = oldevent;
90                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
91                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
92                 {
93                         
94                         m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED;
95                 } else
96                 {
97                         if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED)
98                         {
99                                 
100                                 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
101                         }
102                 }
103         }
104 }
105
106
107 /**
108  * ConvertBlenderEvent translates blender mouse events into ketsji kbd events
109  * extra event information is stored, like ramp-mode (just released/pressed)
110  */
111 bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode, short val)
112 {
113         bool result = false;
114         
115         // convert event
116         KX_EnumInputs kxevent = this->ToNative(incode);
117         int previousTable = 1-m_currentTable;
118
119         // only process it, if it's a key
120         if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSEBUTTONS)
121         {
122                 if (val == KM_PRESS || val == KM_DBL_CLICK)
123                 {
124                         m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
125
126                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
127                         {
128                         
129                         case SCA_InputEvent::KX_ACTIVE:
130                         case SCA_InputEvent::KX_JUSTACTIVATED:
131                                 {
132                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
133                                         break;
134                                 }
135                         case SCA_InputEvent::KX_JUSTRELEASED:
136                                 {
137                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
138                                         break;
139                                 }
140                         default:
141                                 {
142                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
143                                 }
144                         }
145                         
146                 } else if (val == KM_RELEASE)
147                 {
148                         // blender eventval == 0
149                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
150                         {
151                         case SCA_InputEvent::KX_JUSTACTIVATED:
152                         case SCA_InputEvent::KX_ACTIVE:
153                                 {
154                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
155                                         break;
156                                 }
157                         default:
158                                 {
159                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
160                                 }
161                         }
162                 }
163         }
164
165         if (kxevent > KX_ENDMOUSEBUTTONS && kxevent < KX_ENDMOUSE)
166         {
167                 m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //remember mouse position
168
169                 switch (m_eventStatusTables[previousTable][kxevent].m_status)
170                 {
171                         
172                 case SCA_InputEvent::KX_ACTIVE:
173                 case SCA_InputEvent::KX_JUSTACTIVATED:
174                         {
175                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
176                                 break;
177                         }
178                 case SCA_InputEvent::KX_JUSTRELEASED:
179                         {
180                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
181                                 break;
182                         }
183                 default:
184                         {
185                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
186                         }
187                 }
188         }
189
190
191         return result;
192 }