Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
mouse_state.h
1 #pragma once
2 
3 #include "win32/mouse_button.h"
4 #include "util/map.h"
5 
6 #include <DirectXMath.h>
7 
8 namespace blowbox
9 {
18  class MouseState
19  {
20  friend class Window;
21  friend class GLFWManager;
22  friend class ImGuiManager;
23  public:
31  {
32  bool down = false;
33  bool pressed = false;
34  bool released = false;
35  bool modifier_control = false;
36  bool modifier_alt = false;
37  bool modifier_shift = false;
38  };
39 
40  MouseState();
41  ~MouseState();
42 
48  bool GetButton(MouseButton button);
49 
55  bool GetButtonDown(MouseButton button);
56 
62  bool GetButtonPressed(MouseButton button);
63 
69  bool GetButtonReleased(MouseButton button);
70 
72  const DirectX::XMFLOAT2& GetMousePosition() const;
74  const DirectX::XMFLOAT2& GetMousePositionDelta() const;
76  const DirectX::XMFLOAT2& GetScrollDelta() const;
77 
78  protected:
84 
90 
96  void SetMouseButtonModifiers(MouseButton button, int modifiers);
97 
102  void SetMousePosition(const DirectX::XMFLOAT2& new_mouse_position);
103 
108  void SetScrollDelta(const DirectX::XMFLOAT2& delta_scroll);
109 
114  void SetMouseInWindow(bool is_mouse_in_window);
115 
117  void Update();
118 
119  private:
120  DirectX::XMFLOAT2 mouse_position_;
121  DirectX::XMFLOAT2 delta_mouse_position_;
123 
124  DirectX::XMFLOAT2 delta_scroll_;
125  DirectX::XMFLOAT2 delta_scroll_accumulator_;
126 
128 
130  };
131 }
void SetMouseButtonPressed(MouseButton button)
Changes the press-state of a button to true.
Definition: mouse_state.cc:72
MouseButton
All mouse buttons.
Definition: mouse_button.h:10
void SetMouseButtonModifiers(MouseButton button, int modifiers)
Changes the key modifiers of a button to true.
Definition: mouse_state.cc:86
const DirectX::XMFLOAT2 & GetMousePositionDelta() const
Definition: mouse_state.cc:60
DirectX::XMFLOAT2 delta_mouse_position_
The delta of the mouse position over the last frame.
Definition: mouse_state.h:121
Implements all ImGui functionality.
Definition: imgui_manager.h:22
Class for creating windows.
Definition: window.h:30
bool GetButton(MouseButton button)
Find out whether a button is down or not.
Definition: mouse_state.cc:30
void Update()
Updates the MouseState. This makes it so that all accumulators are cleared and mouse states are updat...
Definition: mouse_state.cc:125
bool modifier_control
Whether the control-modifier was pressed together with this key.
Definition: mouse_state.h:35
eastl::map< Key, T > Map
Typedef for wrapping the EASTL map.
Definition: map.h:14
bool GetButtonDown(MouseButton button)
Find out whether a button is down or not.
Definition: mouse_state.cc:36
const DirectX::XMFLOAT2 & GetScrollDelta() const
Definition: mouse_state.cc:66
DirectX::XMFLOAT2 delta_scroll_accumulator_
An accumulator of delta scrolls.
Definition: mouse_state.h:125
void SetMouseButtonReleased(MouseButton button)
Changes the release-state of a button to true.
Definition: mouse_state.cc:79
void SetMousePosition(const DirectX::XMFLOAT2 &new_mouse_position)
Sets the mouse&#39;s position.
Definition: mouse_state.cc:94
bool pressed
Whether the key is currently pressed. (only true for 1 frame!)
Definition: mouse_state.h:33
DirectX::XMFLOAT2 delta_mouse_position_accumulator_
An accumulator of delta mouse positions.
Definition: mouse_state.h:122
const DirectX::XMFLOAT2 & GetMousePosition() const
Definition: mouse_state.cc:54
bool down
Whether the key is currently held down.
Definition: mouse_state.h:32
DirectX::XMFLOAT2 mouse_position_
The current position of the mouse.
Definition: mouse_state.h:120
void SetMouseInWindow(bool is_mouse_in_window)
Sets whether the mouse is in the window or not.
Definition: mouse_state.cc:119
bool GetButtonPressed(MouseButton button)
Find out whether a button is pressed or not.
Definition: mouse_state.cc:42
bool modifier_alt
Whether the alt-modifier was pressed together with this key.
Definition: mouse_state.h:36
bool released
Whether the key is currently released. (only true for 1 frame!)
Definition: mouse_state.h:34
Keeps track of the state of a button on the mouse.
Definition: mouse_state.h:30
bool GetButtonReleased(MouseButton button)
Find out whether a button is released or not.
Definition: mouse_state.cc:48
The main Blowbox namespace.
Definition: image.cc:8
bool modifier_shift
Whether the shift-modifier was pressed together with this key.
Definition: mouse_state.h:37
DirectX::XMFLOAT2 delta_scroll_
The delta scroll of the mouse over the last frame.
Definition: mouse_state.h:124
Manages all GLFW state such as global initialization / termination, event polling, etc.
Definition: glfw_manager.h:16
Keeps track of the state of the mouse.
Definition: mouse_state.h:18
Map< MouseButton, MouseButtonState > mouse_button_states_
All the different mouse states.
Definition: mouse_state.h:129
void SetScrollDelta(const DirectX::XMFLOAT2 &delta_scroll)
Sets the mouse&#39;s scroll delta.
Definition: mouse_state.cc:110
bool is_mouse_in_window_
Whether the mouse is in the window.
Definition: mouse_state.h:127