Blender V2.61 - r43446

KX_BlenderKeyboardDevice.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #if defined(WIN32) && !defined(FREE_WINDOWS)
00034 // annoying warnings about truncated STL debug info
00035 #pragma warning (disable :4786)
00036 #endif 
00037 
00038 #include "KX_BlenderKeyboardDevice.h"
00039 #include "KX_KetsjiEngine.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_KetsjiEngine::GetExitKey() && 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 }