Bevel Factor Mapping
[blender.git] / source / gameengine / GamePlayer / common / GPC_KeyboardDevice.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/GamePlayer/common/GPC_KeyboardDevice.cpp
29  *  \ingroup player
30  */
31
32
33 #include "GPC_KeyboardDevice.h"
34
35 #include <cstdlib>
36
37 /** 
38  * NextFrame toggles currentTable with previousTable,
39  * and copies relevant event information from previous to current table
40  * (pressed keys need to be remembered).
41  */
42 void GPC_KeyboardDevice::NextFrame()
43 {
44         SCA_IInputDevice::NextFrame();
45
46         // Now convert justpressed key events into regular (active) keyevents
47         int previousTable = 1-m_currentTable;
48         for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++)
49         {
50                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent];
51                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
52                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
53                 {
54                         m_eventStatusTables[m_currentTable][keyevent] = oldevent;
55                         m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE;
56                         //m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
57                 }
58         }
59 }
60
61
62
63 /** 
64  * ConvertBPEvent translates Windows keyboard events into ketsji kbd events.
65  * Extra event information is stored, like ramp-mode (just released/pressed)
66  */
67 bool GPC_KeyboardDevice::ConvertEvent(int incode, int val, unsigned int unicode)
68 {
69         bool result = false;
70
71         // convert event
72         KX_EnumInputs kxevent = this->ToNative(incode);
73
74         // only process it, if it's a key
75         if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY)
76         {
77                 int previousTable = 1-m_currentTable;
78
79                 if (val > 0)
80                 {
81                         if (kxevent == SCA_IInputDevice::KX_ESCKEY && val != 0 && !m_hookesc)
82                                 result = true;
83
84                         // todo: convert val ??
85                         m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
86                         m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode ;
87
88                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
89                         {
90                         case SCA_InputEvent::KX_JUSTACTIVATED:
91                         case SCA_InputEvent::KX_ACTIVE:
92                                 {
93                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
94                                         break;
95                                 }
96
97                         case SCA_InputEvent::KX_NO_INPUTSTATUS:
98                         default:
99                                 {
100                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
101                                 }
102                         }
103                         
104                 } else
105                 {
106
107                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
108                         {
109                         case SCA_InputEvent::KX_JUSTACTIVATED:
110                         case SCA_InputEvent::KX_ACTIVE:
111                                 {
112                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
113                                         break;
114                                 }
115                         default:
116                                 {
117                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
118                                 }
119                         }
120                 }
121         }
122         return result;
123 }
124
125 void GPC_KeyboardDevice::HookEscape()
126 {
127         m_hookesc = true;
128 }