Blender V2.61 - r43446

GPC_KeyboardDevice.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 #include "GPC_KeyboardDevice.h"
00034 
00035 #include <cstdlib>
00036 
00042 void GPC_KeyboardDevice::NextFrame()
00043 {
00044     SCA_IInputDevice::NextFrame();
00045 
00046     // Now convert justpressed key events into regular (active) keyevents
00047     int previousTable = 1-m_currentTable;
00048     for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++)
00049     {
00050         SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent];
00051         if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
00052             oldevent.m_status == SCA_InputEvent::KX_ACTIVE  )
00053         {
00054             m_eventStatusTables[m_currentTable][keyevent] = oldevent;
00055             m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE;
00056             //m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED ;
00057         }
00058     }
00059 }
00060 
00061 
00062 
00067 bool GPC_KeyboardDevice::ConvertEvent(int incode, int val)
00068 {
00069     bool result = false;
00070 
00071     // convert event
00072     KX_EnumInputs kxevent = this->ToNative(incode);
00073 
00074     // only process it, if it's a key
00075     if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY)
00076     {
00077         int previousTable = 1-m_currentTable;
00078 
00079         if (val > 0)
00080         {
00081             if (kxevent == SCA_IInputDevice::KX_ESCKEY && val != 0 && !m_hookesc)
00082                 result = true;
00083 
00084             // todo: convert val ??
00085             m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
00086 
00087             switch (m_eventStatusTables[previousTable][kxevent].m_status)
00088             {
00089             case SCA_InputEvent::KX_JUSTACTIVATED:
00090             case SCA_InputEvent::KX_ACTIVE:
00091                 {
00092                     m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
00093                     break;
00094                 }
00095 
00096             case SCA_InputEvent::KX_NO_INPUTSTATUS:
00097             default:
00098                 {
00099                     m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
00100                 }
00101             }
00102             
00103         } else
00104         {
00105 
00106             switch (m_eventStatusTables[previousTable][kxevent].m_status)
00107             {
00108             case SCA_InputEvent::KX_JUSTACTIVATED:
00109             case SCA_InputEvent::KX_ACTIVE:
00110                 {
00111                     m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
00112                     break;
00113                 }
00114             default:
00115                 {
00116                     m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
00117                 }
00118             }
00119         }
00120     }
00121     return result;
00122 }
00123 
00124 void GPC_KeyboardDevice::HookEscape()
00125 {
00126     m_hookesc = true;
00127 }