|
Blender
V2.59
|
00001 /* 00002 * $Id: SCA_IInputDevice.cpp 35169 2011-02-25 13:32:11Z 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 #include <assert.h> 00035 #include "SCA_IInputDevice.h" 00036 00037 SCA_IInputDevice::SCA_IInputDevice() 00038 : 00039 m_currentTable(0) 00040 { 00041 ClearStatusTable(0); 00042 ClearStatusTable(1); 00043 } 00044 00045 00046 00047 SCA_IInputDevice::~SCA_IInputDevice() 00048 { 00049 } 00050 00051 void SCA_IInputDevice::HookEscape() 00052 { 00053 assert(false && "This device does not support hooking escape."); 00054 } 00055 00056 void SCA_IInputDevice::ClearStatusTable(int tableid) 00057 { 00058 for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++) 00059 m_eventStatusTables[tableid][i]=SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS,0); 00060 } 00061 00062 00063 00064 const SCA_InputEvent& SCA_IInputDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode) 00065 { 00066 // cerr << "SCA_IInputDevice::GetEventValue" << endl; 00067 return m_eventStatusTables[m_currentTable][inputcode]; 00068 } 00069 00070 00071 00072 int SCA_IInputDevice::GetNumActiveEvents() 00073 { 00074 int num = 0; 00075 00076 // cerr << "SCA_IInputDevice::GetNumActiveEvents" << endl; 00077 00078 for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++) 00079 { 00080 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i]; 00081 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED) 00082 || (event.m_status == SCA_InputEvent::KX_ACTIVE)) 00083 num++; 00084 } 00085 00086 return num; 00087 } 00088 00089 00090 00091 int SCA_IInputDevice::GetNumJustEvents() 00092 { 00093 int num = 0; 00094 00095 // cerr << "SCA_IInputDevice::GetNumJustEvents" << endl; 00096 00097 for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++) 00098 { 00099 const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i]; 00100 if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED) 00101 || (event.m_status == SCA_InputEvent::KX_JUSTRELEASED)) 00102 num++; 00103 } 00104 00105 return num; 00106 } 00107 00108 00109 00110 void SCA_IInputDevice::NextFrame() 00111 { 00112 m_currentTable = 1 - m_currentTable; 00113 00114 // cerr << "SCA_IInputDevice::NextFrame " << GetNumActiveEvents() << endl; 00115 00116 for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++) 00117 { 00118 switch (m_eventStatusTables[1 - m_currentTable][i].m_status) 00119 { 00120 case SCA_InputEvent::KX_NO_INPUTSTATUS: 00121 m_eventStatusTables[m_currentTable][i] 00122 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1); 00123 break; 00124 case SCA_InputEvent::KX_JUSTACTIVATED: 00125 m_eventStatusTables[m_currentTable][i] 00126 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1); 00127 break; 00128 case SCA_InputEvent::KX_ACTIVE: 00129 m_eventStatusTables[m_currentTable][i] 00130 = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1); 00131 break; 00132 case SCA_InputEvent::KX_JUSTRELEASED: 00133 m_eventStatusTables[m_currentTable][i] 00134 = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1); 00135 break; 00136 default: 00137 ; /* error */ 00138 } 00139 } 00140 }