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}
27
28//------------------------------------------------------------------------------
29namespace Base
30{
32{
34public:
38 virtual ~InputServerBase();
39
45 virtual void Open();
47 virtual void Close();
49 bool IsOpen() const;
51 void SetQuitRequested(bool b);
53 bool IsQuitRequested() const;
55 void Reset();
62
66 void RemoveInputHandler(const Ptr<Input::InputHandler>& inputHandler);
68 void AddGamePad(const Ptr<Input::GamePad> pad, IndexT playerIndex);
69
71 virtual void BeginFrame();
73 virtual void OnFrame();
75 void EndFrame();
77 void PutEvent(const Input::InputEvent& ie);
78
80 void ClearMouseCapture();
84 void ClearCapture();
89
91 void ObtainMouseCapture(const Ptr<Input::InputHandler>& inputHandler);
93 void ReleaseMouseCapture(const Ptr<Input::InputHandler>& inputHandler);
95 void ObtainKeyboardCapture(const Ptr<Input::InputHandler>& inputHandler);
97 void ReleaseKeyboardCapture(const Ptr<Input::InputHandler>& inputHandler);
98
100 bool HasFocus() const;
101
102protected:
103 bool isOpen;
117};
118
119//------------------------------------------------------------------------------
122inline bool
124{
125 return this->isOpen;
126}
127
128//------------------------------------------------------------------------------
131inline SizeT
136
137//------------------------------------------------------------------------------
140inline void
142{
143 this->isQuitRequested = b;
144}
145
146//------------------------------------------------------------------------------
149inline bool
151{
152 return this->isQuitRequested;
153}
154
155//------------------------------------------------------------------------------
158inline const Ptr<Input::Keyboard>&
160{
161 n_assert2(creatorThreadId == Threading::Thread::GetMyThreadId(), "GetDefaultKeyboard can't be called from any thread but the creator thread!");
162 return this->defaultKeyboard;
163}
164
165//------------------------------------------------------------------------------
168inline const Ptr<Input::Mouse>&
170{
171 n_assert2(creatorThreadId == Threading::Thread::GetMyThreadId(), "GetDefaultMouse can't be called from any thread but the creator thread!");
172 return this->defaultMouse;
173}
174
175//------------------------------------------------------------------------------
178inline bool
180{
181 return hasFocus;
182}
183
184} // namespace Base
185//------------------------------------------------------------------------------
186
187
188
The InputServer is the central object of the Input subsystem.
Definition inputserverbase.h:32
void ClearMouseCapture()
clear the current mouse capture (if exists)
Definition inputserverbase.cc:358
const Ptr< Input::Keyboard > & GetDefaultKeyboard() const
get the default keyboard input handler
Definition inputserverbase.h:159
bool isOpen
Definition inputserverbase.h:103
void RemoveInputHandler(const Ptr< Input::InputHandler > &inputHandler)
remove an input handler
Definition inputserverbase.cc:143
bool isQuitRequested
Definition inputserverbase.h:105
Ptr< Input::Keyboard > defaultKeyboard
Definition inputserverbase.h:112
SizeT maxNumLocalPlayers
Definition inputserverbase.h:108
void ObtainKeyboardCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: capture keyboard input to the given input handler
Definition inputserverbase.cc:398
Threading::CriticalSection critSect
Definition inputserverbase.h:115
void ReleaseKeyboardCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: release keyboard capture
Definition inputserverbase.cc:415
void PutEvent(const Input::InputEvent &ie)
put an input event into the handler chain
Definition inputserverbase.cc:225
__DeclareClass(InputServerBase)
bool inBeginFrame
Definition inputserverbase.h:104
virtual void OnFrame()
call after processing window events
Definition inputserverbase.cc:193
SizeT GetMaxNumLocalPlayers() const
get the max number of local players
Definition inputserverbase.h:132
void SetMaxNumLocalPlayers(SizeT maxNumLocalPlayers)
set the max number of local players for this application (default is 4)
Definition inputserverbase.cc:54
void ObtainMouseCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: capture mouse input to the given input handler
Definition inputserverbase.cc:318
Ptr< Input::Mouse > defaultMouse
Definition inputserverbase.h:113
void ClearKeyboardCapture()
clear the current keyboard capture (if exists)
Definition inputserverbase.cc:372
void EndFrame()
call at end of frame
Definition inputserverbase.cc:204
Ptr< Input::GamePad > GetDefaultGamePad(IndexT playerIndex) const
get default gamepad handler (playerIndex is valid up to MaxNumLocalPlayers)
Definition inputserverbase.cc:437
void ReleaseMouseCapture(const Ptr< Input::InputHandler > &inputHandler)
only call from InputHandler: release mouse capture
Definition inputserverbase.cc:335
virtual void Open()
open the input server
Definition inputserverbase.cc:65
bool hasFocus
Definition inputserverbase.h:106
void AddGamePad(const Ptr< Input::GamePad > pad, IndexT playerIndex)
Definition inputserverbase.cc:450
bool IsQuitRequested() const
return true if some subsystem has requested to quit the app (e.g. Alt-F4)
Definition inputserverbase.h:150
InputServerBase()
constructor
Definition inputserverbase.cc:23
const Ptr< Input::Mouse > & GetDefaultMouse() const
get the default mouse input handler
Definition inputserverbase.h:169
void Reset()
reset input state
Definition inputserverbase.cc:103
Threading::ThreadId creatorThreadId
Definition inputserverbase.h:116
void ClearCapture()
clear both mouse and keyboard captures
Definition inputserverbase.cc:386
virtual void Close()
close the input server
Definition inputserverbase.cc:77
const Ptr< Input::InputHandler > & GetMouseCaptureHandler() const
return the current mouse capture input handler (return invalid ptr if no capture set)
Definition inputserverbase.cc:348
virtual void BeginFrame()
call before processing window events
Definition inputserverbase.cc:174
const Ptr< Input::InputHandler > & GetKeyboardCaptureHandler() const
return the current keyboard capture input handler (return invalid ptr if no capture set)
Definition inputserverbase.cc:428
Util::FixedArray< Ptr< Input::GamePad > > defaultGamePad
Definition inputserverbase.h:114
int inputHandlersLockCount
Definition inputserverbase.h:107
bool HasFocus() const
return true if the application has focus
Definition inputserverbase.h:179
void SetQuitRequested(bool b)
set the quit requested flag
Definition inputserverbase.h:141
Ptr< Input::InputHandler > keyboardCaptureHandler
Definition inputserverbase.h:111
Util::Array< Util::KeyValuePair< Input::InputPriority::Code, Ptr< Input::InputHandler > > > inputHandlers
Definition inputserverbase.h:109
void AttachInputHandler(Input::InputPriority::Code pri, const Ptr< Input::InputHandler > &inputHandler)
attach an input handler
Definition inputserverbase.cc:122
bool IsOpen() const
return true if open
Definition inputserverbase.h:123
Ptr< Input::InputHandler > mouseCaptureHandler
Definition inputserverbase.h:110
virtual ~InputServerBase()
destructor
Definition inputserverbase.cc:39
The common base class of Nebula.
Definition refcounted.h:38
An input handler which represents a game pad.
The input events of the Input subsystems.
Definition inputevent.h:24
Code
Definition inputpriority.h:21
An input handler which represents a keyboard for polling.
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Critical section objects are used to protect a portion of code from parallel execution.
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
#define n_assert2(exp, msg)
Definition debug.h:51
Definition gamecontentserverbase.cc:10
FIXME!
pthread_t ThreadId
Definition linuxthreadid.h:15
int SizeT
Definition types.h:49
int IndexT
Definition types.h:48