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