Blender V2.61 - r43446
|
00001 /* 00002 * Manager for mouse events 00003 * 00004 * 00005 * 00006 * ***** BEGIN GPL LICENSE BLOCK ***** 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software Foundation, 00020 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00021 * 00022 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00023 * All rights reserved. 00024 * 00025 * The Original Code is: all of this file. 00026 * 00027 * Contributor(s): none yet. 00028 * 00029 * ***** END GPL LICENSE BLOCK ***** 00030 */ 00031 00037 #if defined(WIN32) && !defined(FREE_WINDOWS) 00038 // This warning tells us about truncation of __long__ stl-generated names. 00039 // It can occasionally cause DevStudio to have internal compiler warnings. 00040 #pragma warning( disable : 4786 ) 00041 #endif 00042 00043 #include "BoolValue.h" 00044 #include "SCA_MouseManager.h" 00045 #include "SCA_MouseSensor.h" 00046 #include "IntValue.h" 00047 #include "RAS_ICanvas.h" 00048 00049 00050 SCA_MouseManager::SCA_MouseManager(SCA_LogicManager* logicmgr, 00051 SCA_IInputDevice* mousedev, 00052 RAS_ICanvas* canvas) 00053 : SCA_EventManager(logicmgr, MOUSE_EVENTMGR), 00054 m_mousedevice (mousedev), 00055 m_canvas(canvas) 00056 { 00057 m_xpos = 0; 00058 m_ypos = 0; 00059 } 00060 00061 00062 00063 SCA_MouseManager::~SCA_MouseManager() 00064 { 00065 } 00066 00067 00068 00069 SCA_IInputDevice* SCA_MouseManager::GetInputDevice() 00070 { 00071 return m_mousedevice; 00072 } 00073 00074 00075 00076 void SCA_MouseManager::NextFrame() 00077 { 00078 if (m_mousedevice) 00079 { 00080 SG_DList::iterator<SCA_ISensor> it(m_sensors); 00081 for (it.begin();!it.end();++it) 00082 { 00083 SCA_MouseSensor* mousesensor = (SCA_MouseSensor*)(*it); 00084 // (0,0) is the Upper Left corner in our local window 00085 // coordinates 00086 if (!mousesensor->IsSuspended()) 00087 { 00088 const SCA_InputEvent& event1 = 00089 m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEX); 00090 const SCA_InputEvent& event2 = 00091 m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEY); 00092 00093 int mx = this->m_canvas->GetMouseX(event1.m_eventval); 00094 int my = this->m_canvas->GetMouseY(event2.m_eventval); 00095 00096 mousesensor->setX(mx); 00097 mousesensor->setY(my); 00098 00099 mousesensor->Activate(m_logicmgr); 00100 } 00101 } 00102 } 00103 } 00104 00105 bool SCA_MouseManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode) 00106 { 00107 /* We should guard for non-mouse events maybe? A rather silly side */ 00108 /* effect here is that position-change events are considered presses as */ 00109 /* well. */ 00110 00111 return m_mousedevice->IsPressed(inputcode); 00112 }