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 "GPC_MouseDevice.h" 00034 00035 GPC_MouseDevice::GPC_MouseDevice() 00036 { 00037 00038 } 00039 GPC_MouseDevice::~GPC_MouseDevice() 00040 { 00041 00042 } 00043 00047 bool GPC_MouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) 00048 { 00049 const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode]; 00050 bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00051 inevent.m_status == SCA_InputEvent::KX_ACTIVE); 00052 return pressed; 00053 } 00054 00055 00061 void GPC_MouseDevice::NextFrame() 00062 { 00063 SCA_IInputDevice::NextFrame(); 00064 00065 // Convert just pressed events into regular (active) events 00066 int previousTable = 1-m_currentTable; 00067 for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS; mouseevent++) { 00068 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent]; 00069 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00070 oldevent.m_status == SCA_InputEvent::KX_ACTIVE) { 00071 m_eventStatusTables[m_currentTable][mouseevent] = oldevent; 00072 m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE; 00073 } 00074 } 00075 for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE; mousemove++) { 00076 SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove]; 00077 m_eventStatusTables[m_currentTable][mousemove] = oldevent; 00078 if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || 00079 oldevent.m_status == SCA_InputEvent::KX_ACTIVE) { 00080 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED; 00081 } 00082 else { 00083 if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED) { 00084 m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS ; 00085 } 00086 } 00087 } 00088 } 00089 00090 00091 bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown) 00092 { 00093 bool result = false; 00094 00095 switch (button) 00096 { 00097 case buttonLeft: 00098 result = ConvertEvent(KX_LEFTMOUSE, isDown); 00099 break; 00100 case buttonMiddle: 00101 result = ConvertEvent(KX_MIDDLEMOUSE, isDown); 00102 break; 00103 case buttonRight: 00104 result = ConvertEvent(KX_RIGHTMOUSE, isDown); 00105 break; 00106 case buttonWheelUp: 00107 result = ConvertEvent(KX_WHEELUPMOUSE, isDown); 00108 break; 00109 case buttonWheelDown: 00110 result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown); 00111 break; 00112 default: 00113 // Should not happen! 00114 break; 00115 } 00116 00117 return result; 00118 } 00119 00124 bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown, int x, int y) 00125 { 00126 // First update state tables for cursor move. 00127 bool result = ConvertMoveEvent(x, y); 00128 00129 // Now update for button state. 00130 if (result) { 00131 result = ConvertButtonEvent(button, isDown); 00132 } 00133 00134 return result; 00135 } 00136 00140 bool GPC_MouseDevice::ConvertMoveEvent(int x, int y) 00141 { 00142 bool result; 00143 00144 // Convert to local coordinates? 00145 result = ConvertEvent(KX_MOUSEX, x); 00146 if (result) { 00147 result = ConvertEvent(KX_MOUSEY, y); 00148 } 00149 00150 return result; 00151 } 00152 00153 00154 bool GPC_MouseDevice::ConvertEvent(KX_EnumInputs kxevent, int eventval) 00155 { 00156 bool result = true; 00157 00158 // Only process it, if it's a mouse event 00159 if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSE) { 00160 int previousTable = 1-m_currentTable; 00161 00162 if (eventval > 0) { 00163 m_eventStatusTables[m_currentTable][kxevent].m_eventval = eventval; 00164 00165 switch (m_eventStatusTables[previousTable][kxevent].m_status) 00166 { 00167 case SCA_InputEvent::KX_ACTIVE: 00168 case SCA_InputEvent::KX_JUSTACTIVATED: 00169 { 00170 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; 00171 break; 00172 } 00173 case SCA_InputEvent::KX_JUSTRELEASED: 00174 { 00175 if ( kxevent > KX_BEGINMOUSEBUTTONS && kxevent < KX_ENDMOUSEBUTTONS) 00176 { 00177 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; 00178 } else 00179 { 00180 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE; 00181 00182 } 00183 break; 00184 } 00185 default: 00186 { 00187 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED; 00188 } 00189 } 00190 00191 } 00192 else { 00193 switch (m_eventStatusTables[previousTable][kxevent].m_status) 00194 { 00195 case SCA_InputEvent::KX_JUSTACTIVATED: 00196 case SCA_InputEvent::KX_ACTIVE: 00197 { 00198 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED; 00199 break; 00200 } 00201 default: 00202 { 00203 m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS; 00204 } 00205 } 00206 } 00207 } 00208 else { 00209 result = false; 00210 } 00211 return result; 00212 }