SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLInputManager Class Reference

SLInputManager. manages system input and custom input devices. More...

#include <SLInputManager.h>

Public Member Functions

 SLInputManager ()
 
SLbool pollAndProcessEvents (SLSceneView *sv)
 
void queueEvent (const SLInputEvent *e)
 
SLVInputDevicedevices ()
 

Private Member Functions

SLbool processQueuedEvents (SLSceneView *sv)
 

Private Attributes

SLQInputEvent _systemEvents
 queue for known system events More...
 
SLVInputDevice _devices
 list of activated SLInputDevices More...
 

Friends

class SLInputDevice
 

Detailed Description

SLInputManager. manages system input and custom input devices.

One static instance of SLInputManager is used in AppCommon. Every user input has to go through the SLInputManager. System event's like touch, mouse, character input will be encapsulated in SLInputEvent subclasses and will be queued up before being sent to the relevant SLSceneView. Custom SLInputDevices can also be created. The SLInputDevices are guaranteed to receive a call to their poll() function whenever the SLInputManager requires them to send out new events. The method pollAndProcessEvents is called every frame in SLScene::onUpdate.

Definition at line 22 of file SLInputManager.h.

Constructor & Destructor Documentation

◆ SLInputManager()

SLInputManager::SLInputManager ( )
inline

Definition at line 27 of file SLInputManager.h.

27 { ; }

Member Function Documentation

◆ devices()

SLVInputDevice& SLInputManager::devices ( )
inline

Definition at line 31 of file SLInputManager.h.

31 { return _devices; }
SLVInputDevice _devices
list of activated SLInputDevices

◆ pollAndProcessEvents()

SLbool SLInputManager::pollAndProcessEvents ( SLSceneView sv)

Sends any queued up system event's to their correct receiver and polls all activated SLInputDevices.

Note
The event queue is similar to how Qt manages it's events. The main difference is, that we don't use the SLInputEvent class outside of the SLInputManager. The SLInputManager calls the correct SLSceneView input handler functions directly. Also we don't allow for custom SLInputEvents. This is the other main difference to the Qt event system. The decision to go this route is simplicity for now. It is totally sufficient for our use cases to provide the user with the SLInputDevice interface to realize custom input. However it has to be considered, that Qt also has many GUI related events like MouseEnter, MouseLeave, Drag etc. For a sophisticated GUI implementation the whole input management in SL would have to be reviewed.

Definition at line 29 of file SLInputManager.cpp.

30 {
31  // process system events first
32  SLbool consumedEvents = processQueuedEvents(sv);
33 
34  // process custom input devices
35  for (auto device : _devices)
36  consumedEvents |= device->poll();
37 
38  return consumedEvents;
39 }
bool SLbool
Definition: SL.h:175
SLbool processQueuedEvents(SLSceneView *sv)
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69

◆ processQueuedEvents()

SLbool SLInputManager::processQueuedEvents ( SLSceneView sv)
private

Work off any queued up input event's and notify the correct receiver.

Note
this is similar to the Qt QObject::event function.

Definition at line 52 of file SLInputManager.cpp.

53 {
55 
56  // flag if an event has been consumed by a receiver
57  SLbool eventConsumed = false;
58 
59  while (!q.empty())
60  {
61  const SLInputEvent* e;
62  {
63  e = q.front();
64  q.pop();
65  }
66 
67  if (sv)
68  {
69  switch (e->type)
70  {
72  {
73  const SLMouseEvent* me = (const SLMouseEvent*)e;
74  eventConsumed |= sv->onMouseMove(me->x, me->y);
75  }
76  break;
78  {
79  const SLMouseEvent* me = (const SLMouseEvent*)e;
80  eventConsumed |= sv->onMouseDown(me->button, me->x, me->y, me->modifier);
81  }
82  break;
84  {
85  const SLMouseEvent* me = (const SLMouseEvent*)e;
86  eventConsumed |= sv->onMouseUp(me->button, me->x, me->y, me->modifier);
87  }
88  break;
90  {
91  const SLMouseEvent* me = (const SLMouseEvent*)e;
92  eventConsumed |= sv->onDoubleClick(me->button, me->x, me->y, me->modifier);
93  }
94  break;
96  {
97  const SLMouseEvent* me = (const SLMouseEvent*)e;
98  eventConsumed |= sv->onMouseWheel(me->y, me->modifier);
99  }
100  break;
101 
103  {
104  const SLTouchEvent* te = (const SLTouchEvent*)e;
105  eventConsumed |= sv->onTouch2Move(te->x1, te->y1, te->x2, te->y2);
106  }
107  break;
109  {
110  const SLTouchEvent* te = (const SLTouchEvent*)e;
111  eventConsumed |= sv->onTouch2Down(te->x1, te->y1, te->x2, te->y2);
112  }
113  break;
115  {
116  const SLTouchEvent* te = (const SLTouchEvent*)e;
117  eventConsumed |= sv->onTouch2Up(te->x1, te->y1, te->x2, te->y2);
118  }
119  break;
120 
122  {
123  const SLKeyEvent* ke = (const SLKeyEvent*)e;
124  eventConsumed |= sv->onKeyPress(ke->key, ke->modifier);
125  }
126  break;
127  case SLInputEvent::KeyUp:
128  {
129  const SLKeyEvent* ke = (const SLKeyEvent*)e;
130  eventConsumed |= sv->onKeyRelease(ke->key, ke->modifier);
131  }
132  break;
134  {
135  const SLCharInputEvent* ce = (const SLCharInputEvent*)e;
136  eventConsumed |= sv->onCharInput(ce->character);
137  }
138  break;
139 
141  {
142  const SLResizeEvent* re = (const SLResizeEvent*)e;
143  sv->onResize(re->width, re->height);
144  }
145  break;
146 
148  {
150  SLstring path = re->path;
151 
152  if (!Utils::dirExists(path))
153  Utils::makeDirRecurse(path);
154  SLstring filename = "Screenshot_" + Utils::getDateTime2String() + ".png";
155  SLstring pathFilename = path + filename;
156  sv->saveFrameBufferAsImage(pathFilename, cv::Size(sv->scrW(), sv->scrH()));
157  }
158  break;
159 
160  default: break;
161  }
162  }
163 
164  delete e;
165  }
166 
167  return eventConsumed;
168 }
string SLstring
Definition: SL.h:158
std::queue< const SLInputEvent * > SLQInputEvent
Definition: SLInputEvent.h:134
Specialized SLInput class for unicode character input.
Definition: SLInputEvent.h:116
Baseclass for all system input events.
Definition: SLInputEvent.h:25
enum SLInputEvent::Type type
concrete type of the event
SLQInputEvent _systemEvents
queue for known system events
Specialized SLInput class for all keypress related input events.
Definition: SLInputEvent.h:67
SLKey modifier
Definition: SLInputEvent.h:70
Specialized SLInput class for all mouse related input events.
Definition: SLInputEvent.h:54
SLKey modifier
Definition: SLInputEvent.h:59
SLMouseButton button
Definition: SLInputEvent.h:58
Specialized SLInput class for window resize events.
Definition: SLInputEvent.h:101
virtual SLbool onDoubleClick(SLMouseButton button, SLint x, SLint y, SLKey mod)
virtual SLbool onCharInput(SLuint c)
void onResize(SLint width, SLint height)
virtual SLbool onMouseMove(SLint x, SLint y)
virtual SLbool onKeyRelease(SLKey key, SLKey mod)
void saveFrameBufferAsImage(SLstring pathFilename, cv::Size targetSize=cv::Size(-1, -1))
Saves after n wait frames the front frame buffer as a PNG image.
virtual SLbool onMouseWheel(SLint delta, SLKey mod)
virtual SLbool onTouch2Move(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
virtual SLbool onMouseUp(SLMouseButton button, SLint scrX, SLint scrY, SLKey mod)
virtual SLbool onKeyPress(SLKey key, SLKey mod)
virtual SLbool onMouseDown(SLMouseButton button, SLint scrX, SLint scrY, SLKey mod)
void scrW(SLint scrW)
Definition: SLSceneView.h:147
virtual SLbool onTouch2Up(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
void scrH(SLint scrH)
Definition: SLSceneView.h:148
virtual SLbool onTouch2Down(SLint scrX1, SLint scrY1, SLint scrX2, SLint scrY2)
Specialized SLInput class to trigger a screen capture.
Definition: SLInputEvent.h:126
Specialized SLInput class for touch related input events.
Definition: SLInputEvent.h:78
string getDateTime2String()
Returns local time as string like "20190213-154611".
Definition: Utils.cpp:289
bool dirExists(const string &path)
Returns true if a directory exists.
Definition: Utils.cpp:790
bool makeDirRecurse(std::string path)
Definition: Utils.cpp:826

◆ queueEvent()

void SLInputManager::queueEvent ( const SLInputEvent e)

Add a new SLInputEvent to the event queue. The queue will be emtied when a call to SLInputManager::pollEvents is made. The passed in SLInputEvents have to be dynamically allocated by the user, the deallocation is handled by the SLInputManager

Definition at line 45 of file SLInputManager.cpp.

46 {
47  _systemEvents.push(e);
48 }

Friends And Related Function Documentation

◆ SLInputDevice

friend class SLInputDevice
friend

Definition at line 24 of file SLInputManager.h.

Member Data Documentation

◆ _devices

SLVInputDevice SLInputManager::_devices
private

list of activated SLInputDevices

Definition at line 35 of file SLInputManager.h.

◆ _systemEvents

SLQInputEvent SLInputManager::_systemEvents
private

queue for known system events

Definition at line 34 of file SLInputManager.h.


The documentation for this class was generated from the following files: