Nebula
Loading...
Searching...
No Matches
inputserverbase.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/refcounted.h"
15#include "input/inputpriority.h"
16#include "input/inputevent.h"
18#include "threading/thread.h"
19
20namespace Input
21{
22 class Mouse;
23 class Keyboard;
24 class GamePad;
25 class InputHandler;
26 class ActionMap;
27}
28
29//------------------------------------------------------------------------------
30namespace Base
31{
33{
35public:
39 virtual ~InputServerBase();
40
46 virtual void Open();
48 virtual void Close();
50 bool IsOpen() const;
52 void SetQuitRequested(bool b);
54 bool IsQuitRequested() const;
56 void Reset();
63
66
70 void RemoveInputHandler(const Ptr<Input::InputHandler>& inputHandler);
72 void AddGamePad(const Ptr<Input::GamePad> pad, IndexT playerIndex);
73
75 virtual void BeginFrame();
77 virtual void OnFrame();
79 void EndFrame();
81 void PutEvent(const Input::InputEvent& ie);
82
84 void ClearMouseCapture();
88 void ClearCapture();
93
95 void ObtainMouseCapture(const Ptr<Input::InputHandler>& inputHandler);
97 void ReleaseMouseCapture(const Ptr<Input::InputHandler>& inputHandler);
99 void ObtainKeyboardCapture(const Ptr<Input::InputHandler>& inputHandler);
101 void ReleaseKeyboardCapture(const Ptr<Input::InputHandler>& inputHandler);
102
104 bool HasFocus() const;
105
106protected:
107 bool isOpen;
120 Threading::CriticalSection critSect;
122};
123
124//------------------------------------------------------------------------------
127inline bool
129{
130 return this->isOpen;
131}
132
133//------------------------------------------------------------------------------
136inline SizeT
141
142//------------------------------------------------------------------------------
145inline void
147{
148 this->isQuitRequested = b;
149}
150
151//------------------------------------------------------------------------------
154inline bool
156{
157 return this->isQuitRequested;
158}
159
160//------------------------------------------------------------------------------
163inline const Ptr<Input::Keyboard>&
165{
166 n_assert2(creatorThreadId == Threading::Thread::GetMyThreadId(), "GetDefaultKeyboard can't be called from any thread but the creator thread!");
167 return this->defaultKeyboard;
168}
169
170//------------------------------------------------------------------------------
173inline const Ptr<Input::Mouse>&
175{
176 n_assert2(creatorThreadId == Threading::Thread::GetMyThreadId(), "GetDefaultMouse can't be called from any thread but the creator thread!");
177 return this->defaultMouse;
178}
179
180//------------------------------------------------------------------------------
183inline const Ptr<Input::ActionMap>&
185{
186 return this->actionMap;
187}
188
189//------------------------------------------------------------------------------
192inline bool
194{
195 return hasFocus;
196}
197
198} // namespace Base
199//------------------------------------------------------------------------------
200
201
202
const Ptr< Input::ActionMap > & GetActionMap() const
returns the action map
Definition inputserverbase.h:184
void ClearMouseCapture()
clear the current mouse capture (if exists)
Definition inputserverbase.cc:398
const Ptr< Input::Keyboard > & GetDefaultKeyboard() const
get the default keyboard input handler
Definition inputserverbase.h:164
bool isOpen
Definition inputserverbase.h:107
void RemoveInputHandler(const Ptr< Input::InputHandler > &inputHandler)
remove an input handler
Definition inputserverbase.cc:154
bool isQuitRequested
Definition inputserverbase.h:109
Ptr< Input::Keyboard > defaultKeyboard
Definition inputserverbase.h:116
SizeT maxNumLocalPlayers
Definition inputserverbase.h:112
void ObtainKeyboardCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: capture keyboard input to the given input handler
Definition inputserverbase.cc:438
Threading::CriticalSection critSect
Definition inputserverbase.h:120
void ReleaseKeyboardCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: release keyboard capture
Definition inputserverbase.cc:455
void PutEvent(const Input::InputEvent &ie)
put an input event into the handler chain
Definition inputserverbase.cc:258
__DeclareClass(InputServerBase)
bool inBeginFrame
Definition inputserverbase.h:108
virtual void OnFrame()
call after processing window events
Definition inputserverbase.cc:204
SizeT GetMaxNumLocalPlayers() const
get the max number of local players
Definition inputserverbase.h:137
void SetMaxNumLocalPlayers(SizeT maxNumLocalPlayers)
set the max number of local players for this application (default is 4)
Definition inputserverbase.cc:55
void ObtainMouseCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: capture mouse input to the given input handler
Definition inputserverbase.cc:358
Ptr< Input::Mouse > defaultMouse
Definition inputserverbase.h:117
void ClearKeyboardCapture()
clear the current keyboard capture (if exists)
Definition inputserverbase.cc:412
Ptr< Input::ActionMap > actionMap
Definition inputserverbase.h:118
void EndFrame()
call at end of frame
Definition inputserverbase.cc:237
Ptr< Input::GamePad > GetDefaultGamePad(IndexT playerIndex) const
get default gamepad handler (playerIndex is valid up to MaxNumLocalPlayers)
Definition inputserverbase.cc:477
void ReleaseMouseCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: release mouse capture
Definition inputserverbase.cc:375
virtual void Open()
open the input server
Definition inputserverbase.cc:66
bool hasFocus
Definition inputserverbase.h:110
void AddGamePad(const Ptr< Input::GamePad > pad, IndexT playerIndex)
Definition inputserverbase.cc:490
bool IsQuitRequested() const
return true if some subsystem has requested to quit the app (e.g. Alt-F4)
Definition inputserverbase.h:155
InputServerBase()
constructor
Definition inputserverbase.cc:24
const Ptr< Input::Mouse > & GetDefaultMouse() const
get the default mouse input handler
Definition inputserverbase.h:174
void Reset()
reset input state
Definition inputserverbase.cc:114
Threading::ThreadId creatorThreadId
Definition inputserverbase.h:121
void ClearCapture()
clear both mouse and keyboard captures
Definition inputserverbase.cc:426
virtual void Close()
close the input server
Definition inputserverbase.cc:82
const Ptr< Input::InputHandler > & GetMouseCaptureHandler() const
return the current mouse capture input handler (return invalid ptr if no capture set)
Definition inputserverbase.cc:388
virtual void BeginFrame()
call before processing window events
Definition inputserverbase.cc:185
const Ptr< Input::InputHandler > & GetKeyboardCaptureHandler() const
return the current keyboard capture input handler (return invalid ptr if no capture set)
Definition inputserverbase.cc:468
Util::FixedArray< Ptr< Input::GamePad > > defaultGamePad
Definition inputserverbase.h:119
int inputHandlersLockCount
Definition inputserverbase.h:111
bool HasFocus() const
return true if the application has focus
Definition inputserverbase.h:193
void SetQuitRequested(bool b)
set the quit requested flag
Definition inputserverbase.h:146
Ptr< Input::InputHandler > keyboardCaptureHandler
Definition inputserverbase.h:115
Util::Array< Util::KeyValuePair< Input::InputPriority::Code, Ptr< Input::InputHandler > > > inputHandlers
Definition inputserverbase.h:113
void AttachInputHandler(Input::InputPriority::Code pri, const Ptr< Input::InputHandler > &inputHandler)
attach an input handler
Definition inputserverbase.cc:133
bool IsOpen() const
return true if open
Definition inputserverbase.h:128
Ptr< Input::InputHandler > mouseCaptureHandler
Definition inputserverbase.h:114
The common base class of Nebula.
Definition refcounted.h:45
An action is a name for something the game asks for, such as "Jump".
Definition actionmap.h:204
The input events of the Input subsystems.
Definition inputevent.h:25
Input handlers receive and process input events.
Definition inputhandler.h:29
Code
Definition inputpriority.h:21
An input handler which represents a mouse for polling.
Definition mouse.h:16
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:61
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
#define n_assert2(exp, msg)
Definition debug.h:59
Definition gamecontentserverbase.cc:10
FIXME!
pthread_t ThreadId
Definition linuxthreadid.h:15
int SizeT
Definition types.h:50
int IndexT
Definition types.h:49