Nebula
Loading...
Searching...
No Matches
mousebase.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "input/inputhandler.h"
13#include "input/mousebutton.h"
14
15//------------------------------------------------------------------------------
16namespace Base
17{
19{
21public:
23 MouseBase();
25 virtual ~MouseBase();
26
28 virtual void BeginCapture();
30 virtual void EndCapture();
31
37 bool ButtonUp(Input::MouseButton::Code btn) const;
41 bool WheelForward() const;
43 bool WheelBackward() const;
45 const Math::vec2& GetPixelPosition() const;
47 const Math::vec2& GetScreenPosition() const;
49 const Math::vec2& GetMovement() const;
50
52 virtual void LockToPosition(bool locked, Math::vec2& position);
54 bool IsLocked() const;
55
56protected:
58 virtual void OnAttach();
60 virtual void OnBeginFrame();
62 virtual bool OnEvent(const Input::InputEvent& inputEvent);
64 virtual void OnObtainCapture();
66 virtual void OnReleaseCapture();
68 virtual void OnReset();
69
70private:
72 void UpdateMousePositions(const Math::vec2& pixelPos, const Math::vec2& screenPos);
73
75 {
76 public:
78 ButtonState() : pressed(false), down(false), up(false), doubleClicked(false) {};
79
80 bool pressed;
81 bool down;
82 bool up;
84 };
85
98};
99
100//------------------------------------------------------------------------------
103inline bool
105{
106 return this->buttonStates[btn].pressed;
107}
108
109//------------------------------------------------------------------------------
112inline bool
114{
115 return this->buttonStates[btn].down;
116}
117
118//------------------------------------------------------------------------------
121inline bool
123{
124 return this->buttonStates[btn].up;
125}
126
127//------------------------------------------------------------------------------
130inline bool
132{
133 return this->buttonStates[btn].doubleClicked;
134}
135
136//------------------------------------------------------------------------------
139inline const Math::vec2&
141{
142 return this->pixelPosition;
143}
144
145//------------------------------------------------------------------------------
148inline const Math::vec2&
150{
151 return this->screenPosition;
152}
153
154//------------------------------------------------------------------------------
157inline const Math::vec2&
159{
160 return this->movement;
161}
162
163//------------------------------------------------------------------------------
166inline bool
168{
169 return this->wheelForward;
170}
171
172//------------------------------------------------------------------------------
175inline bool
177{
178 return this->wheelBackward;
179}
180
181//------------------------------------------------------------------------------
184inline void
186{
187 mouseLockedPosition = position;
188 mouseLocked = locked;
189 mouseWasLocked = locked;
190}
191
192//------------------------------------------------------------------------------
195inline bool
197{
198 return mouseLocked;
199}
200
201} // namespace Base
202//------------------------------------------------------------------------------
203
An input handler which represents a mouse for polling.
Definition mousebase.h:19
virtual void LockToPosition(bool locked, Math::vec2 &position)
locks the mouse to a screen position (0.0 .. 1.0)
Definition mousebase.h:185
Util::FixedArray< ButtonState > buttonStates
Definition mousebase.h:86
bool WheelForward() const
return true if mouse wheel rotated forward
Definition mousebase.h:167
virtual bool OnEvent(const Input::InputEvent &inputEvent)
called when an input event should be processed
Definition mousebase.cc:114
bool ButtonUp(Input::MouseButton::Code btn) const
return true if button was released at least once in current frame
Definition mousebase.h:122
bool ButtonDoubleClicked(Input::MouseButton::Code btn) const
return true if a button has been double clicked
Definition mousebase.h:131
bool ButtonDown(Input::MouseButton::Code btn) const
return true if button was pushed down at least once in current frame
Definition mousebase.h:113
virtual void OnReleaseCapture()
called when input handler looses capture
Definition mousebase.cc:227
Math::vec2 movement
Definition mousebase.h:91
virtual void BeginCapture()
capture input to this event handler
Definition mousebase.cc:42
const Math::vec2 & GetPixelPosition() const
get current absolute mouse position (in pixels)
Definition mousebase.h:140
MouseBase()
constructor
Definition mousebase.cc:19
bool wheelForward
Definition mousebase.h:93
bool ButtonPressed(Input::MouseButton::Code btn) const
return true if button is currently pressed
Definition mousebase.h:104
const Math::vec2 & GetMovement() const
get mouse movement
Definition mousebase.h:158
bool mouseLocked
Definition mousebase.h:96
virtual ~MouseBase()
destructor
Definition mousebase.cc:33
Math::vec2 pixelPosition
Definition mousebase.h:89
Math::vec2 screenPosition
Definition mousebase.h:90
virtual void EndCapture()
end input capturing to this event handler
Definition mousebase.cc:52
bool WheelBackward() const
return true if mouse wheel rotated backward
Definition mousebase.h:176
__DeclareClass(MouseBase)
const Math::vec2 & GetScreenPosition() const
get current screen space mouse position (0.0 .. 1.0)
Definition mousebase.h:149
bool wheelBackward
Definition mousebase.h:94
void UpdateMousePositions(const Math::vec2 &pixelPos, const Math::vec2 &screenPos)
update mouse position members
Definition mousebase.cc:241
bool IsLocked() const
return true if the mouse is locked
Definition mousebase.h:196
Math::vec2 beginFrameScreenPosition
Definition mousebase.h:88
virtual void OnBeginFrame()
called on InputServer::BeginFrame()
Definition mousebase.cc:82
Math::vec2 mouseLockedPosition
Definition mousebase.h:92
bool initialMouseMovement
Definition mousebase.h:95
virtual void OnAttach()
called when the handler is attached to the input server
Definition mousebase.cc:62
virtual void OnObtainCapture()
called when input handler obtains capture
Definition mousebase.cc:213
virtual void OnReset()
reset the input handler
Definition mousebase.cc:259
bool mouseWasLocked
Definition mousebase.h:97
Math::vec2 beginFramePixelPosition
Definition mousebase.h:87
The input events of the Input subsystems.
Definition inputevent.h:24
Input handlers receive and process input events.
Definition inputhandler.h:29
Code
code enums
Definition mousebutton.h:23
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Definition gamecontentserverbase.cc:10
Definition mousebase.h:75
bool down
Definition mousebase.h:81
ButtonState()
constructor
Definition mousebase.h:78
bool doubleClicked
Definition mousebase.h:83
bool pressed
Definition mousebase.h:80
bool up
Definition mousebase.h:82
A 2-component float vector class.
Definition vec2.h:21