Leviathan  0.8.0.0
Leviathan game engine
InputController.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 #include "Common/ThreadSafe.h"
7 
8 #include <vector>
9 
10 namespace Leviathan {
11 
12 class InputController;
13 
16  friend InputController;
17 
18 public:
20  DLLEXPORT virtual ~InputReceiver();
21 
25  DLLEXPORT virtual void BeginNewReceiveQueue();
26 
28  DLLEXPORT virtual bool ReceiveInput(int32_t key, int modifiers, bool down) = 0;
29 
33  DLLEXPORT virtual void ReceiveBlockedInput(int32_t key, int modifiers, bool down) = 0;
34 
38  DLLEXPORT virtual bool OnScroll(int x, int y, int modifiers);
39 
41  DLLEXPORT virtual bool OnMouseMove(int xmove, int ymove) = 0;
42 
44  DLLEXPORT void _UnConnectParent(Lock& ownerlock);
45 
46 protected:
47  // called by input controller when certain events happen //
48  void _OnConnected(InputController* owner);
49  void _OnDisconnect(InputController* owner);
50 
51 protected:
53 };
54 
55 
58 class InputController : public ThreadSafe {
59  friend InputReceiver;
60 
61 public:
64 
65 
66  DLLEXPORT void LinkReceiver(std::shared_ptr<InputReceiver> object);
67 
68  DLLEXPORT virtual void StartInputGather();
69 
71  DLLEXPORT virtual void OnInputGet(int32_t key, int specialmodifiers, bool down);
72 
74  DLLEXPORT virtual void OnBlockedInput(int32_t key, int specialmodifiers, bool down);
75 
77  DLLEXPORT virtual void OnScroll(int x, int y, int modifiers);
78 
80  DLLEXPORT virtual void SendMouseMovement(int xmoved, int ymoved);
81 
82 protected:
84  DLLEXPORT virtual void _OnChildUnlink(Lock& guard, InputReceiver* child);
85 
86 protected:
87  std::vector<std::shared_ptr<InputReceiver>> ConnectedReceivers;
88 };
89 
90 } // namespace Leviathan
virtual DLLEXPORT void ReceiveBlockedInput(int32_t key, int modifiers, bool down)=0
This is called when input is not received.
Allows the inherited object to be locked.
Definition: ThreadSafe.h:137
DLLEXPORT void LinkReceiver(std::shared_ptr< InputReceiver > object)
Manages registering multiple InputReceiver objects to a window to easily control where input is sent.
virtual DLLEXPORT void _OnChildUnlink(Lock &guard, InputReceiver *child)
Called by input controllers if they unlink.
class to derive from when wanting to connect to input
virtual DLLEXPORT bool OnMouseMove(int xmove, int ymove)=0
when mouse is captured and is moved (relative movement is passed)
virtual DLLEXPORT ~InputReceiver()
virtual DLLEXPORT void BeginNewReceiveQueue()
virtual DLLEXPORT void OnBlockedInput(int32_t key, int specialmodifiers, bool down)
This is called when input is not received.
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)
virtual DLLEXPORT bool ReceiveInput(int32_t key, int modifiers, bool down)=0
Called when the object receives a key press, return true when consumed.
#define DLLEXPORT
Definition: Include.h:84
virtual DLLEXPORT void OnScroll(int x, int y, int modifiers)
InputController * ConnectedTo
virtual DLLEXPORT bool OnScroll(int x, int y, int modifiers)
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
void _OnDisconnect(InputController *owner)
void _OnConnected(InputController *owner)
DLLEXPORT void _UnConnectParent(Lock &ownerlock)
If ConnectedTo is not NULL notifies it that we are no longer valid.
std::vector< std::shared_ptr< InputReceiver > > ConnectedReceivers
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:18
virtual DLLEXPORT void SendMouseMovement(int xmoved, int ymoved)
When the mouse input is captured it is passed here.