Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
eventresponder.cpp
Go to the documentation of this file.
1
/*
2
* Vega Strike
3
* Copyright (C) 2003 Mike Byron
4
*
5
* http://vegastrike.sourceforge.net/
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
*/
21
22
#include "
vegastrike.h
"
23
24
#include "
eventresponder.h
"
25
26
#include "
eventmanager.h
"
27
28
//The EventResponder class is a virtual base class that allows objects
29
//to intercept and respond to user events. There are two kinds of
30
//events:
31
//1. Input events. Raw events from input devices that are specific
32
//to the kind of device. Examples: key events, mouse down, etc.
33
//there are specific functions to support each kind of input device.
34
//2. Command events. These are often caused by input events, but are
35
//higher-level. They are identified by a string ID. Examples:
36
//"Cut", "Cockpit::ECM", "Buy Cargo". Input events are usually
37
//translated into command events. Command events usually execute the
38
//operation requested by the user.
39
//This is a virtual base class. The responder functions should be overridden
40
//to handle particular events. All responder functions return true if the
41
//event was handled, false if not. Default implementations generally
42
//return false.
43
//
44
//This class is used in conjunction with the EventManager, which maintains
45
//a chain of EventResponders. Events are passed down the chain to find
46
//something that can execute them.
47
48
//Process a command event.
49
bool
EventResponder::processCommand
(
const
EventCommandId
&command,
Control
*control )
50
{
51
return
m_modal
;
52
}
53
54
//Process a key pressed down.
55
bool
EventResponder::processKeyDown
(
const
InputEvent
&event )
56
{
57
return
m_modal
;
58
}
59
60
//Process a key released.
61
bool
EventResponder::processKeyUp
(
const
InputEvent
&event )
62
{
63
return
m_modal
;
64
}
65
66
//Process a mouse button pressed down.
67
bool
EventResponder::processMouseDown
(
const
InputEvent
&event )
68
{
69
return
m_modal
;
70
}
71
72
//Process a mouse button pressed elsewhere, unfocusing this control.
73
void
EventResponder::processUnfocus
(
const
InputEvent
&event ) {}
74
75
//Process a mouse button released.
76
bool
EventResponder::processMouseUp
(
const
InputEvent
&event )
77
{
78
return
m_modal
;
79
}
80
81
//Process a mouse location change.
82
bool
EventResponder::processMouseMove
(
const
InputEvent
&event )
83
{
84
return
m_modal
;
85
}
86
87
//Process a mouse location change when at least one mouse button is down.
88
bool
EventResponder::processMouseDrag
(
const
InputEvent
&event )
89
{
90
return
m_modal
;
91
}
92
93
//Send a command event into the event chain.
94
void
EventResponder::sendCommand
(
const
EventCommandId
&command,
Control
*control )
95
{
96
if
(
m_commandTarget
!= NULL)
97
if
(
m_commandTarget
->
processCommand
( command, control ) )
98
return
;
99
globalEventManager
().
sendCommand
( command, control );
100
}
101
102
//Set a specified target for commands. Commands aren't forwarded into the
103
//event chain, they are sent to this specific target. This can be used, for
104
//instance, to tie two controls tightly together.
105
//Use NULL to clear the target and forward commands into the event chain.
106
void
EventResponder::setCommandTarget
(
EventResponder
*responder )
107
{
108
m_commandTarget
= responder;
109
}
110
111
//Handle all input events. Don't forward anything down the event chain.
112
void
EventResponder::setModal
(
bool
flag )
113
{
114
m_modal
= flag;
115
}
116
117
//CONSTRUCTION
118
EventResponder::EventResponder
(
void
) :
119
m_modal( false )
120
, m_commandTarget( NULL )
121
{}
122
123
EventResponder::~EventResponder
(
void
)
124
{
125
//Make sure this responder is not in the event chain.
126
if
(
hasGlobalEventManager
() )
127
globalEventManager
().
removeResponder
(
this
);
128
}
129
src
gui
eventresponder.cpp
Generated on Fri May 29 2015 23:07:32 for Vegastrike 0.5.1 rc1 by
1.8.4