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