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 #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_BlenderMouseDevice.h" 00039 00040 KX_BlenderMouseDevice::KX_BlenderMouseDevice() 00041 { 00042 00043 } 00044 KX_BlenderMouseDevice::~KX_BlenderMouseDevice() 00045 { 00046 00047 } 00048 00053 bool KX_BlenderMouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) 00054 { 00055 const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode]; 00056 bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00057 inevent.m_status == SCA_InputEvent::KX_ACTIVE); 00058 return pressed; 00059 } 00060 /*const SCA_InputEvent& KX_BlenderMouseDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode) 00061 { 00062 return m_eventStatusTables[m_currentTable][inputcode]; 00063 } 00064 */ 00065 00071 void KX_BlenderMouseDevice::NextFrame() 00072 { 00073 SCA_IInputDevice::NextFrame(); 00074 00075 // now convert justpressed keyevents into regular (active) keyevents 00076 int previousTable = 1-m_currentTable; 00077 for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS;mouseevent++) 00078 { 00079 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent]; 00080 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00081 oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) 00082 { 00083 m_eventStatusTables[m_currentTable][mouseevent] = oldevent; 00084 m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE; 00085 } 00086 } 00087 for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE;mousemove++) 00088 { 00089 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove]; 00090 m_eventStatusTables[m_currentTable][mousemove] = oldevent; 00091 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00092 oldevent.m_status == SCA_InputEvent::KX_ACTIVE ) 00093 { 00094 00095 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED; 00096 } else 00097 { 00098 if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED) 00099 { 00100 00101 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS ; 00102 } 00103 } 00104 } 00105 } 00106 00107 00114 bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode,short val) 00115 { 00116 bool result = false; 00117 00118 // convert event 00119 KX_EnumInputs kxevent = this->ToNative(incode); 00120 int previousTable = 1-m_currentTable; 00121 00122 // only process it, if it's a key 00123 if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSEBUTTONS) 00124 { 00125 if (val == KM_PRESS) 00126 { 00127 m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //??? 00128 00129 switch (m_eventStatusTables[previousTable][kxevent].m_status) 00130 { 00131 00132 case SCA_InputEvent::KX_ACTIVE: 00133 case SCA_InputEvent::KX_JUSTACTIVATED: 00134 { 00135 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; 00136 break; 00137 } 00138 case SCA_InputEvent::KX_JUSTRELEASED: 00139 { 00140 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; 00141 break; 00142 } 00143 default: 00144 { 00145 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; 00146 } 00147 } 00148 00149 } else if (val == KM_RELEASE) 00150 { 00151 // blender eventval == 0 00152 switch (m_eventStatusTables[previousTable][kxevent].m_status) 00153 { 00154 case SCA_InputEvent::KX_JUSTACTIVATED: 00155 case SCA_InputEvent::KX_ACTIVE: 00156 { 00157 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; 00158 break; 00159 } 00160 default: 00161 { 00162 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; 00163 } 00164 } 00165 } 00166 } 00167 00168 if (kxevent > KX_ENDMOUSEBUTTONS && kxevent < KX_ENDMOUSE) 00169 { 00170 m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //remember mouse position 00171 00172 switch (m_eventStatusTables[previousTable][kxevent].m_status) 00173 { 00174 00175 case SCA_InputEvent::KX_ACTIVE: 00176 case SCA_InputEvent::KX_JUSTACTIVATED: 00177 { 00178 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; 00179 break; 00180 } 00181 case SCA_InputEvent::KX_JUSTRELEASED: 00182 { 00183 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; 00184 break; 00185 } 00186 default: 00187 { 00188 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; 00189 } 00190 } 00191 } 00192 00193 00194 return result; 00195 }