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
51 Down(MouseInfo::Impl&, Vec2 objectPos);
52 Down(const Down&) = delete;
53 Down(Down&&) noexcept;
54 Down& operator=(const Down&) = delete;
55 Down& operator=(Down&&) noexcept;
56 ~Down();
57
58 private:
59 MouseInfo::Impl* parent = nullptr;
60 Vec2 startReference;
61 };
62
63 struct Over {
64 Vec2 pos() const;
65
71
72 explicit Over(MouseInfo::Impl&);
73
74 private:
75 MouseInfo::Impl& parent;
76 };
77
80
81private:
82 friend class jngl::Window;
83
84 MouseInfo();
85 ~MouseInfo();
86 void setMousePos(Vec2);
87
89 std::vector<Over> activeCursors;
90};
91
96
97} // 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
std::optional< Down > pressed(Vec2 objectPos)
calling this will result in all future calls of MouseInfo::cursors not returning this cursor