Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Problem with IsMouseButtonUp which always returns true #3606

Closed
Bigfoot71 opened this issue Dec 6, 2023 · 5 comments · Fixed by #3609
Closed

[core] Problem with IsMouseButtonUp which always returns true #3606

Bigfoot71 opened this issue Dec 6, 2023 · 5 comments · Fixed by #3609

Comments

@Bigfoot71
Copy link
Contributor

Bigfoot71 commented Dec 6, 2023

Issue description

I noticed that the IsMouseButtonUp function always returns true with PLATFORM_DESKTOP on the master branch (984e83c).

Environment

Linux Mint 21.2, 64-bit, Cinnamon

Code Example

#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "Button up test");

    while (!WindowShouldClose())
    {
        BeginDrawing();
        ClearBackground(WHITE);

        if (IsMouseButtonUp(MOUSE_LEFT_BUTTON))
        {
            DrawText("Button is UP", 10, 10, 20, BLACK);
        }
        else
        {
            DrawText("Button is DOWN", 10, 10, 20, BLACK);
        }

        EndDrawing();
    }

    CloseWindow();

    return 0;
}

Edit: Note that doing if (!IsMouseButtonDown(MOUSE_BUTTON_LEFT)) works for me

@orcmid
Copy link
Contributor

orcmid commented Dec 6, 2023

I confirm the same behavior with the 5.0 release as well as the current 5.1-dev. Windows 10, VS 2022 17.8.2 Build Tools.

Nice workaround though :).

@ghost
Copy link

ghost commented Dec 6, 2023

@Bigfoot71 Isn't that exactly how IsMouseButtonUp() (L2913, L1741) is supposed to work? I always assumed it's there report the state of the mouse button on that exact frame (the exact counterpart of IsMouseButtonDown() L2887).

To get a single event, I assume one would use IsMouseButtonReleased() (L2900) instead (the same way IsMouseButtonPressed() L2874), that only happens once in the mouse button cycle and has handling for exactly that.

IMHO, it's working like it's supposed to.

@Bigfoot71
Copy link
Contributor Author

@ubkp Yes, IsMouseButtonUp is supposed to return true continuously as long as the mouse button is not "down" and return false when IsMouseButtonDown is true, and it doesn't do that anymore, it returns true all the time.

Try the example I shared, you will see the problem, sorry if I express myself badly

@ghost
Copy link

ghost commented Dec 6, 2023

@Bigfoot71 You're right, very good catch!

The problem appears to be that if (CORE.Input.Touch.currentTouchState[button] == 0) up = true; overrides the up value because CORE.Input.Touch.currentTouchState[button] is not being assigned anywhere (yet) for rcore_desktop.c.

Not sure if GLFW have a touch API (doc), doesn't appear to have one yet. So I guess the solution for rcore_desktop.c would be mirroring currentButtonState. In a nutshell:

diff --git a/rcore_desktopOLD.c b/rcore_desktopNEW.c
index 0aca731..c1d4b5d 100644
--- a/rcore_desktopOLD.c
+++ b/rcore_desktopNEW.c
@@ -1739,6 +1739,7 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
     // WARNING: GLFW could only return GLFW_PRESS (1) or GLFW_RELEASE (0) for now,
     // but future releases may add more actions (i.e. GLFW_REPEAT)
     CORE.Input.Mouse.currentButtonState[button] = action;
+    CORE.Input.Touch.currentTouchState[button] = action;
 
 #if defined(SUPPORT_GESTURES_SYSTEM) && defined(SUPPORT_MOUSE_GESTURES)
     // Process mouse events as touches to be able to use mouse-gestures

@Bigfoot71 Please send the PR :)

@Minmoose
Copy link
Contributor

Minmoose commented Dec 6, 2023

As is so happens I was also looking into this, and just caught this as well I sent a PR #3609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants