Leviathan  0.8.0.0
Leviathan game engine
Leviathan::InputController Class Reference

Manages registering multiple InputReceiver objects to a window to easily control where input is sent. More...

#include <InputController.h>

+ Inheritance diagram for Leviathan::InputController:

Public Member Functions

DLLEXPORT InputController ()
 
DLLEXPORT ~InputController ()
 
DLLEXPORT void LinkReceiver (std::shared_ptr< InputReceiver > object)
 
virtual DLLEXPORT void StartInputGather ()
 
virtual DLLEXPORT void OnInputGet (int32_t key, int specialmodifiers, bool down)
 Called when the GUI didn't eat the whole keypress (it only ate half of the A-press) More...
 
virtual DLLEXPORT void OnBlockedInput (int32_t key, int specialmodifiers, bool down)
 This is called when input is not received. More...
 
virtual DLLEXPORT void OnScroll (int x, int y, int modifiers)
 
virtual DLLEXPORT void SendMouseMovement (int xmoved, int ymoved)
 When the mouse input is captured it is passed here. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

Protected Member Functions

virtual DLLEXPORT void _OnChildUnlink (Lock &guard, InputReceiver *child)
 Called by input controllers if they unlink. More...
 

Protected Attributes

std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Detailed Description

Manages registering multiple InputReceiver objects to a window to easily control where input is sent.

Definition at line 58 of file InputController.h.

Constructor & Destructor Documentation

◆ InputController()

DLLEXPORT InputController::InputController ( )

Definition at line 6 of file InputController.cpp.

6 {}

◆ ~InputController()

DLLEXPORT InputController::~InputController ( )

Definition at line 8 of file InputController.cpp.

9 {
10  // Unlink all children //
11  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
12  // Call disconnect function first //
13  ConnectedReceivers[i]->_OnDisconnect(this);
14  }
15 
16  ConnectedReceivers.clear();
17 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers

Member Function Documentation

◆ _OnChildUnlink()

DLLEXPORT void InputController::_OnChildUnlink ( Lock guard,
InputReceiver child 
)
protectedvirtual

Called by input controllers if they unlink.

Definition at line 99 of file InputController.cpp.

100 {
101  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
102  if(ConnectedReceivers[i].get() == child) {
103  // call disconnect function first //
104  ConnectedReceivers[i]->_OnDisconnect(this);
105  ConnectedReceivers.erase(ConnectedReceivers.begin() + i);
106  return;
107  }
108  }
109 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers

◆ LinkReceiver()

DLLEXPORT void InputController::LinkReceiver ( std::shared_ptr< InputReceiver object)

Definition at line 88 of file InputController.cpp.

89 {
90 
91  GUARD_LOCK();
92 
93  // Just add to list and call link function //
94  object->_OnConnected(this);
95 
96  ConnectedReceivers.push_back(object);
97 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ OnBlockedInput()

DLLEXPORT void InputController::OnBlockedInput ( int32_t  key,
int  specialmodifiers,
bool  down 
)
virtual

This is called when input is not received.

Definition at line 51 of file InputController.cpp.

52 {
53  GUARD_LOCK();
54 
55  // call on all //
56  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
57 
58  ConnectedReceivers[i]->ReceiveBlockedInput(key, specialmodifiers, down);
59  }
60 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ OnInputGet()

DLLEXPORT void InputController::OnInputGet ( int32_t  key,
int  specialmodifiers,
bool  down 
)
virtual

Called when the GUI didn't eat the whole keypress (it only ate half of the A-press)

Definition at line 31 of file InputController.cpp.

32 {
33  // Call on first that wants it //
34  bool received = false;
35 
36  GUARD_LOCK();
37 
38  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
39 
40  if(received) {
41 
42  ConnectedReceivers[i]->ReceiveBlockedInput(key, specialmodifiers, down);
43  continue;
44  }
45 
46  if(ConnectedReceivers[i]->ReceiveInput(key, specialmodifiers, down))
47  received = true;
48  }
49 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ OnScroll()

DLLEXPORT void InputController::OnScroll ( int  x,
int  y,
int  modifiers 
)
virtual

Called the scroll wheel is used and the GUI didn't take the scroll input

Parameters
xThe x side scroll. NOTE: this is the side to side scrolling
yThe y direction scroll amount. This is the usual scroll direction

Definition at line 62 of file InputController.cpp.

63 {
64  // Call on first that wants it //
65  GUARD_LOCK();
66 
67  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
68 
69  if(ConnectedReceivers[i]->OnScroll(x, y, modifiers))
70  return;
71  }
72 }
virtual DLLEXPORT void OnScroll(int x, int y, int modifiers)
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ SendMouseMovement()

DLLEXPORT void InputController::SendMouseMovement ( int  xmoved,
int  ymoved 
)
virtual

When the mouse input is captured it is passed here.

Definition at line 75 of file InputController.cpp.

76 {
77 
78  GUARD_LOCK();
79 
80  // call on first that gets it //
81  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
82 
83  if(ConnectedReceivers[i]->OnMouseMove(xmoved, ymoved))
84  return;
85  }
86 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ StartInputGather()

DLLEXPORT void InputController::StartInputGather ( )
virtual

Definition at line 19 of file InputController.cpp.

20 {
21  GUARD_LOCK();
22  // reset internal state //
23 
24  // tell listeners that new frame begins //
25  for(size_t i = 0; i < ConnectedReceivers.size(); i++) {
26 
27  ConnectedReceivers[i]->BeginNewReceiveQueue();
28  }
29 }
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

Member Data Documentation

◆ ConnectedReceivers

std::vector<std::shared_ptr<InputReceiver> > Leviathan::InputController::ConnectedReceivers
protected

Definition at line 87 of file InputController.h.


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