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 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
11namespace jngl {
12
13class MouseInfo {
14public:
15 void setMousePos(Vec2);
16
17 struct Down {
19 Vec2 newPos() const;
20 bool released();
21
22 Vec2 startPos() const;
23
24 Down(MouseInfo&, Vec2 objectPos);
25 Down(const Down&) = delete;
26 Down(Down&&) noexcept;
27 Down& operator=(const Down&) = delete;
28 Down& operator=(Down&&) noexcept;
29 ~Down();
30
31 private:
32 MouseInfo* parent = nullptr;
33 Vec2 startReference;
34 };
35
36 struct Over {
37 Vec2 pos() const;
38
43
44 explicit Over(MouseInfo&);
45
46 private:
47 MouseInfo& parent;
48 };
49
52
53private:
54 bool enabled = true;
55 bool down = false;
56 Vec2 mousePos;
57};
58
59} // namespace jngl
Contains jngl::Vec2 class.
std::optional< Over > pos()
will return nullopt if the mouse is already over another object
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
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::pos returning nullopt