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