Blender  V2.59
KX_BlenderKeyboardDevice.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_BlenderKeyboardDevice.cpp 35166 2011-02-25 13:29:48Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #if defined(WIN32) && !defined(FREE_WINDOWS)
00035 // annoying warnings about truncated STL debug info
00036 #pragma warning (disable :4786)
00037 #endif 
00038 
00039 #include "KX_BlenderKeyboardDevice.h"
00040 
00041 KX_BlenderKeyboardDevice::KX_BlenderKeyboardDevice()
00042         : m_hookesc(false)
00043 {
00044 
00045 }
00046 KX_BlenderKeyboardDevice::~KX_BlenderKeyboardDevice()
00047 {
00048 
00049 }
00050 
00055 bool KX_BlenderKeyboardDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
00056 {
00057         const SCA_InputEvent & inevent =  m_eventStatusTables[m_currentTable][inputcode];
00058         bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 
00059                 inevent.m_status == SCA_InputEvent::KX_ACTIVE);
00060         return pressed;
00061 }
00062 /*const SCA_InputEvent& KX_BlenderKeyboardDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
00063 {
00064         return m_eventStatusTables[m_currentTable][inputcode];
00065 }
00066 */
00072 void    KX_BlenderKeyboardDevice::NextFrame()
00073 {
00074         SCA_IInputDevice::NextFrame();
00075         
00076         // now convert justpressed keyevents into regular (active) keyevents
00077         int previousTable = 1-m_currentTable;
00078         for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++)
00079         {
00080                 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent];
00081                 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00082                         oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
00083                 {
00084                         m_eventStatusTables[m_currentTable][keyevent] = oldevent;
00085                         m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE;
00086                 }
00087         }
00088 }
00089 
00096 bool    KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode,short val)
00097 {
00098         bool result = false;
00099         
00100         // convert event
00101         KX_EnumInputs kxevent = this->ToNative(incode);
00102 
00103         // only process it, if it's a key
00104         if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY)
00105         {
00106                 int previousTable = 1-m_currentTable;
00107 
00108                 if (val == KM_PRESS)
00109                 {
00110                         if (kxevent == KX_ESCKEY && val != 0 && !m_hookesc)
00111                                 result = true;
00112                         if (kxevent == KX_PAUSEKEY && val && (IsPressed(KX_LEFTCTRLKEY) || IsPressed(KX_RIGHTCTRLKEY)))
00113                                 result = true;
00114 
00115                         // todo: convert val ??
00116                         m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
00117 
00118                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
00119                         {
00120                         case SCA_InputEvent::KX_JUSTACTIVATED:
00121                                 {
00122                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
00123                                         break;
00124                                 }
00125                         case SCA_InputEvent::KX_ACTIVE:
00126                         
00127                                 {
00128                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
00129                                         break;
00130                                 }
00131                         case SCA_InputEvent::KX_NO_INPUTSTATUS:
00132                                 {
00133                                                 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
00134                                                 break;
00135                                 }
00136                         default:
00137                                 {
00138                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
00139                                 }
00140                         }
00141                         
00142                 } else if (val == KM_RELEASE)
00143                 {
00144                         // blender eventval == 0
00145                         switch (m_eventStatusTables[previousTable][kxevent].m_status)
00146                         {
00147                         case SCA_InputEvent::KX_JUSTACTIVATED:
00148                                 {
00149                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
00150                                         break;
00151                                 }
00152                         case SCA_InputEvent::KX_ACTIVE:
00153                                 {
00154                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
00155                                         break;
00156                                 }
00157                         default:
00158                                 {
00159                                         m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
00160                                 }
00161                         }
00162                 }
00163         }
00164         return result;
00165 }
00166 
00167 void KX_BlenderKeyboardDevice::HookEscape()
00168 {
00169         m_hookesc = true;
00170 }