~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/SCA_MouseManager.cpp

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Manager for mouse events
 
3
 *
 
4
 *
 
5
 * $Id: SCA_MouseManager.cpp 15884 2008-07-30 17:41:47Z ben2610 $
 
6
 *
 
7
 * ***** BEGIN GPL LICENSE BLOCK *****
 
8
 *
 
9
 * This program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU General Public License
 
11
 * as published by the Free Software Foundation; either version 2
 
12
 * of the License, or (at your option) any later version.
 
13
 *
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License
 
20
 * along with this program; if not, write to the Free Software Foundation,
 
21
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
 *
 
23
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
24
 * All rights reserved.
 
25
 *
 
26
 * The Original Code is: all of this file.
 
27
 *
 
28
 * Contributor(s): none yet.
 
29
 *
 
30
 * ***** END GPL LICENSE BLOCK *****
 
31
 */
 
32
 
 
33
#ifdef HAVE_CONFIG_H
 
34
#include <config.h>
 
35
#endif
 
36
 
 
37
#ifdef WIN32
 
38
// This warning tells us about truncation of __long__ stl-generated names.
 
39
// It can occasionally cause DevStudio to have internal compiler warnings.
 
40
#pragma warning( disable : 4786 )     
 
41
#endif
 
42
 
 
43
#include "BoolValue.h"
 
44
#include "SCA_MouseManager.h"
 
45
#include "SCA_MouseSensor.h"
 
46
#include "IntValue.h"
 
47
 
 
48
 
 
49
SCA_MouseManager::SCA_MouseManager(SCA_LogicManager* logicmgr,
 
50
                                                                   SCA_IInputDevice* mousedev)
 
51
        :       SCA_EventManager(MOUSE_EVENTMGR),
 
52
                m_mousedevice (mousedev),
 
53
                m_logicmanager(logicmgr)
 
54
{
 
55
        m_xpos = 0;
 
56
        m_ypos = 0;
 
57
}
 
58
 
 
59
 
 
60
 
 
61
SCA_MouseManager::~SCA_MouseManager()
 
62
{
 
63
}
 
64
 
 
65
 
 
66
 
 
67
SCA_IInputDevice* SCA_MouseManager::GetInputDevice()
 
68
{
 
69
        return m_mousedevice;
 
70
}
 
71
 
 
72
 
 
73
 
 
74
void SCA_MouseManager::NextFrame()
 
75
{
 
76
        if (m_mousedevice)
 
77
        {
 
78
                set<SCA_ISensor*>::iterator it;
 
79
                for (it=m_sensors.begin(); it!=m_sensors.end(); it++)
 
80
                {
 
81
                        SCA_MouseSensor* mousesensor = (SCA_MouseSensor*)(*it);
 
82
                        // (0,0) is the Upper Left corner in our local window
 
83
                        // coordinates
 
84
                        if (!mousesensor->IsSuspended())
 
85
                        {
 
86
                                const SCA_InputEvent& event = 
 
87
                                        m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
 
88
                                int mx = event.m_eventval;
 
89
                                const SCA_InputEvent& event2 = 
 
90
                                        m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
 
91
                                int my = event2.m_eventval;
 
92
                                
 
93
                                mousesensor->setX(mx);
 
94
                                mousesensor->setY(my);
 
95
                                
 
96
                                mousesensor->Activate(m_logicmanager,NULL);
 
97
                        }
 
98
                }
 
99
        }
 
100
}
 
101
 
 
102
bool SCA_MouseManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
 
103
{
 
104
        /* We should guard for non-mouse events maybe? A rather silly side       */
 
105
        /* effect here is that position-change events are considered presses as  */
 
106
        /* well.                                                                 */
 
107
        
 
108
        return m_mousedevice->IsPressed(inputcode);
 
109
}