[go: up one dir, main page]

File: SoEvent.cpp

package info (click to toggle)
coin3 3.1.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 48,344 kB
  • ctags: 70,042
  • sloc: cpp: 314,328; ansic: 15,927; sh: 13,635; makefile: 8,780; perl: 2,149; lex: 1,302; lisp: 1,247; yacc: 184; xml: 175; sed: 68
file content (300 lines) | stat: -rw-r--r-- 7,777 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
/**************************************************************************\
 *
 *  This file is part of the Coin 3D visualization library.
 *  Copyright (C) by Kongsberg Oil & Gas Technologies.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  ("GPL") version 2 as published by the Free Software Foundation.
 *  See the file LICENSE.GPL at the root directory of this source
 *  distribution for additional information about the GNU GPL.
 *
 *  For using Coin with software that can not be combined with the GNU
 *  GPL, and for taking advantage of the additional benefits of our
 *  support services, please contact Kongsberg Oil & Gas Technologies
 *  about acquiring a Coin Professional Edition License.
 *
 *  See http://www.coin3d.org/ for more information.
 *
 *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
 *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
 *
\**************************************************************************/

/*!
  \class SoEvent SoEvent.h Inventor/events/SoEvent.h
  \brief The SoEvent class is the base class for all Coin events.
  \ingroup events

  Coin contains its own set of event classes, independent of the underlying
  window system.

  Upon system specific events, a translation is done by the window
  specific device classes into one of the Coin event object classes
  listed below. The event is then typically sent by the render area
  to an SoSceneManager which will apply it to the scenegraph through
  an SoHandleEventAction.

  Events may be caught by the user by attaching an SoEventCallback
  node to the scenegraph, or it can automatically be handled by a
  dragger or manipulator in the graph.

  \sa SoButtonEvent, SoKeyboardEvent, SoLocation2Event, SoMotion3Event
  \sa SoMouseButtonEvent, SoSpaceballButtonEvent
  \sa SoEventCallback, SoHandleEventAction */

#include <Inventor/events/SoEvent.h>

#include <cassert>

#include <Inventor/events/SoMouseButtonEvent.h>
#include <Inventor/events/SoKeyboardEvent.h>
#include <Inventor/events/SoSpaceballButtonEvent.h>
#include <Inventor/events/SoLocation2Event.h>
#include <Inventor/events/SoMotion3Event.h>
#include <Inventor/SbViewportRegion.h>
#include <Inventor/SbName.h>

#include "tidbitsp.h"

SO_EVENT_SOURCE(SoEvent);

/*!
  \fn SoType SoEvent::getClassTypeId(void)

  This static method returns the SoType object associated with objects
  of this class.
 */


// FIXME: grab better version of getTypeId() doc from SoBase, SoAction
// and / or SoDetail. 20010913 mortene.
/*!
  \fn SoType SoEvent::getTypeId(void) const

  Returns the actual type id of an instantiated object.
*/


/*!
  Initialize SoEvent and all it's known subclasses (i.e. all subclasses
  which are part of the standard classes in the Coin library).

  This method is called from SoDB::init(), so it's very unlikely that
  you will have to call it explicitly.
 */
void
SoEvent::initClass(void)
{
  // Make sure we only initialize once.
  assert(SoEvent::classTypeId == SoType::badType());

  SoEvent::classTypeId = SoType::createType(SoType::badType(), "SoEvent");
  coin_atexit(reinterpret_cast<coin_atexit_f *>(cleanupClass), CC_ATEXIT_NORMAL);

  SoEvent::initEvents();
}

void
SoEvent::cleanupClass(void)
{
  SoEvent::classTypeId STATIC_SOTYPE_INIT;
}

/*!
  \COININTERNAL

  Initialize all known subclasses.
 */
void
SoEvent::initEvents(void)
{
  SoButtonEvent::initClass();
    SoMouseButtonEvent::initClass();
    SoKeyboardEvent::initClass();
    SoSpaceballButtonEvent::initClass();
  SoLocation2Event::initClass();
  SoMotion3Event::initClass();
}

/*!
  Constructor, will set all modifiers to "off" state.
*/
SoEvent::SoEvent(void)
{
  this->modifiers.shiftdown = 0;
  this->modifiers.ctrldown = 0;
  this->modifiers.altdown = 0;
}

/*!
  Destructor.
 */
SoEvent::~SoEvent()
{
}

/*!
  Returns TRUE if this object either has the same type as the given
  \c type parameter, or if \c type belongs to a superclass of ourselves.
*/
SbBool
SoEvent::isOfType(SoType type) const
{
  const SoType myType = this->getTypeId();
  if (myType == type) return TRUE;
  if (myType.isDerivedFrom(type)) return TRUE;
  return FALSE;
}

/*!
  From a system specific device object, set the time the event occurred.

  \sa getTime()
 */
void
SoEvent::setTime(const SbTime t)
{
  this->timeofevent = t;
}

/*!
  Returns the time the event occurred.

  \sa getPosition(), wasShiftDown(), wasCtrlDown(), wasAltDown()
 */
SbTime
SoEvent::getTime(void) const
{
  return this->timeofevent;
}

/*!
  From a system specific device object, set the mouse pointer position
  when the event occurred.

  \sa getPosition(), getNormalizedPosition()
 */
void
SoEvent::setPosition(const SbVec2s & p)
{
  this->positionofevent = p;
}

// FIXME: "window" below is ambiguous, replace with something less
// generic, like e.g. "the rendering canvas" or some such. Should also
// scan API docs for other references to "window" (and "widget"?) and
// do likewise. 20040728 mortene.
/*!
  Returns the mouse pointer position when the event occurred. The
  coordinates are given relative to the window coordinates.

  \sa getNormalizedPosition(), getTime(), wasShiftDown(), wasCtrlDown(),
  \sa wasAltDown()
 */
const SbVec2s &
SoEvent::getPosition(void) const
{
  return this->positionofevent;
}

/*!
  Returns the mouse pointer position when the event occurred. The
  coordinates are given relative to the viewport coordinates.

  \sa getNormalizedPosition(), getTime(), wasShiftDown(), wasCtrlDown(),
  \sa wasAltDown()
 */
const SbVec2s
SoEvent::getPosition(const SbViewportRegion & vpRgn) const
{
  return SbVec2s(this->positionofevent - vpRgn.getViewportOriginPixels());
}

/*!
  Returns the mouse pointer position when the event occurred. The
  coordinates are given relative to the viewport coordinates,
  normalized according to the size of the viewport.

  \sa getPosition(), getTime(), wasShiftDown(), wasCtrlDown(), wasAltDown()
 */
const SbVec2f
SoEvent::getNormalizedPosition(const SbViewportRegion & vpRgn) const
{
  SbVec2s p = this->positionofevent - vpRgn.getViewportOriginPixels();
  SbVec2s s = vpRgn.getViewportSizePixels();

  return SbVec2f(
               static_cast<float>(p[0])/static_cast<float>(s[0]),
               static_cast<float>(p[1])/static_cast<float>(s[1])
               );
}

/*!
  From a system specific device object, set the state of the Shift key(s)
  when the event occurred.

  \sa wasShiftDown(), setCtrlDown(), setAltDown()
 */
void
SoEvent::setShiftDown(SbBool isDown)
{
  this->modifiers.shiftdown = isDown ? TRUE : FALSE;
}

/*!
  Returns state of Shift key(s) when the event occurred.

  \sa wasCtrlDown(), wasAltDown(), getPosition(), getTime()
 */
SbBool
SoEvent::wasShiftDown(void) const
{
  return this->modifiers.shiftdown;
}

/*!
  From a system specific device object, set the state of the Ctrl key(s)
  when the event occurred.

  \sa wasCtrlDown(), setShiftDown(), setAltDown()
 */
void
SoEvent::setCtrlDown(SbBool isDown)
{
  this->modifiers.ctrldown = isDown ? TRUE : FALSE;
}

/*!
  Returns state of Ctrl key(s) when the event occurred.

  \sa wasShiftDown(), wasAltDown(), getPosition(), getTime()
 */
SbBool
SoEvent::wasCtrlDown(void) const
{
  return this->modifiers.ctrldown;
}

/*!
  From a system specific device object, set the state of the Alt key(s)
  when the event occurred.

  \sa wasAltDown(), setCtrlDown(), setShiftDown()
 */
void
SoEvent::setAltDown(SbBool isDown)
{
  this->modifiers.altdown = isDown ? TRUE : FALSE;
}

/*!
  Returns state of Alt key(s) when the event occurred.

  \sa wasShiftDown(), wasCtrlDown(), getPosition(), getTime()
 */
SbBool
SoEvent::wasAltDown(void) const
{
  return this->modifiers.altdown;
}