Skip to content

Commit 1af5c5a

Browse files
committed
Add MouseInfo::Down::blockPressedImmediately()
1 parent 9e906b8 commit 1af5c5a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/jngl/MouseInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ struct MouseInfo::Impl {
1313
bool down = false;
1414
Vec2 mousePos;
1515
VirtualMouseCursor* virtualCursor = nullptr;
16+
bool pressedBlocked = false;
1617

1718
bool getPressed() const {
19+
if (pressedBlocked) {
20+
return false;
21+
}
1822
if (virtualCursor) {
1923
return virtualCursor->pressed();
2024
}
@@ -43,13 +47,15 @@ void MouseInfo::setMousePos(Vec2 mousePos) {
4347
impls.resize(1);
4448
}
4549
impls[0].enabled = true;
50+
impls[0].pressedBlocked = false;
4651
impls[0].mousePos = mousePos;
4752

4853
if (auto virtualCursor = getJob<VirtualMouseCursor>()) {
4954
if (impls.size() < 2) {
5055
impls.resize(2);
5156
}
5257
impls[1].enabled = true;
58+
impls[1].pressedBlocked = false;
5359
impls[1].mousePos = virtualCursor->getPosition();
5460
impls[1].virtualCursor = virtualCursor.get();
5561
}
@@ -71,6 +77,10 @@ bool MouseInfo::Down::pressedAgain() const {
7177
return parent->getPressed();
7278
}
7379

80+
void MouseInfo::Down::blockPressedImmediately() {
81+
parent->pressedBlocked = true;
82+
}
83+
7484
MouseInfo::Down::Down(MouseInfo::Impl& parent, Vec2 objectPos)
7585
: parent(&parent), startReference(parent.mousePos - objectPos) {
7686
parent.down = true;

src/jngl/MouseInfo.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class MouseInfo {
5252
/// again if the mouse is pressed again
5353
bool pressedAgain() const;
5454

55+
/// Calling this will cause pressedAgain() to return false directly, not waiting for the
56+
/// next frame or anything:
57+
void blockPressedImmediately();
58+
5559
Down(MouseInfo::Impl&, Vec2 objectPos);
5660
Down(const Down&) = delete;
5761
Down(Down&&) noexcept;

0 commit comments

Comments
 (0)