JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
MouseInfo.hpp
Go to the documentation of this file.
1// Copyright 2025-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Vec2.hpp"
8
9#include <optional>
10#include <span>
11#include <vector>
12
13namespace jngl {
14
15class Mat3;
16class Window;
17
18class MouseInfo {
19 struct Impl;
20
21public:
42 void transform(const jngl::Mat3& transformationMatrix);
43
44 struct Down {
46 Vec2 newPos() const;
47 bool released();
48
49 Vec2 startPos() const;
50
53 bool pressedAgain() const;
54
58
59 Down(MouseInfo::Impl&, Vec2 objectPos);
60 Down(const Down&) = delete;
61 Down(Down&&) noexcept;
62 Down& operator=(const Down&) = delete;
63 Down& operator=(Down&&) noexcept;
64 ~Down();
65
66 private:
67 MouseInfo::Impl* parent = nullptr;
68 Vec2 startReference;
69 };
70
71 struct Over {
72 Vec2 pos() const;
73
79
80 explicit Over(MouseInfo::Impl&);
81
82 private:
83 MouseInfo::Impl& parent;
84 };
85
88
89private:
90 friend class jngl::Window;
91
92 MouseInfo();
93 ~MouseInfo();
94 void setMousePos(Vec2);
95
97 std::vector<Over> activeCursors;
98};
99
104
105} // namespace jngl
Contains jngl::Vec2 class.
3x3 matrix
Definition Mat3.hpp:18
std::span< Over > cursors()
Only returns mouse cursors that are currently not over something.
void transform(const jngl::Mat3 &transformationMatrix)
Applies the transformationMatrix on the mouse position.
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
MouseInfo & input()
Returns a reference to the global MouseInfo instance, similar to jngl::modelview()
Vec2 newPos() const
returns nullopt when the mouse has been released
bool pressedAgain() const
if you keep this object alive after released() returned true, this will return true again if the mous...
void blockPressedImmediately()
Calling this will cause pressedAgain() to return false directly, not waiting for the next frame or an...
std::optional< Down > pressed(Vec2 objectPos)
calling this will result in all future calls of MouseInfo::cursors not returning this cursor