PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
input.h
1#pragma once
2
3#include "pixelbullet/input/key_codes.h"
4#include "pixelbullet/input/mouse_codes.h"
5
6#include <bitset>
7#include <cstddef>
8#include <glm/glm.hpp>
9
10namespace pixelbullet::glfw_window_internal
11{
12class CallbackAdapter;
13} // namespace pixelbullet::glfw_window_internal
14
15namespace pixelbullet
16{
17namespace input
18{
20{
21public:
22 [[nodiscard]] bool IsKeyDown(KeyCode key) const;
23 [[nodiscard]] bool IsMouseButtonDown(MouseCode button) const;
24 [[nodiscard]] glm::vec2 GetMousePosition() const noexcept
25 {
26 return mouse_position_;
27 }
28 [[nodiscard]] float GetMouseX() const noexcept
29 {
30 return mouse_position_.x;
31 }
32 [[nodiscard]] float GetMouseY() const noexcept
33 {
34 return mouse_position_.y;
35 }
36
37private:
38 static constexpr std::size_t kMaxTrackedKeys = 512;
39 static constexpr std::size_t kMaxTrackedMouseButtons = 8;
40
41 void SetKeyDown(KeyCode key, bool is_down);
42 void SetMouseButtonDown(MouseCode button, bool is_down);
43 void SetMousePosition(glm::vec2 mouse_position) noexcept
44 {
45 mouse_position_ = mouse_position;
46 }
47 void ClearPressedInputs() noexcept
48 {
49 key_down_.reset();
50 mouse_button_down_.reset();
51 }
52
54
55 std::bitset<kMaxTrackedKeys> key_down_;
56 std::bitset<kMaxTrackedMouseButtons> mouse_button_down_;
57 glm::vec2 mouse_position_ = glm::vec2(0.0f);
58};
59} // namespace input
60} // namespace pixelbullet
Definition input.h:20