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

Inconsistency between mouse_is_pressed boolean and mouse_clicked function #441

Closed
swirly opened this issue Sep 18, 2023 · 1 comment · Fixed by #458
Closed

Inconsistency between mouse_is_pressed boolean and mouse_clicked function #441

swirly opened this issue Sep 18, 2023 · 1 comment · Fixed by #458

Comments

@swirly
Copy link

swirly commented Sep 18, 2023

Describe the bug
the mouse_button does not behave correctly when using mouse_clicked

code to reproduce :

from p5 import *

def setup():
   size(100, 100)
   fill(0)

def draw():
    background(204)
    if mouse_is_pressed:
       colorize()
    rect((25, 25), 50, 50)

def colorize():
    if mouse_button == "LEFT":
      fill(0)
    elif mouse_button == "RIGHT":
      fill(255)
    else:
      fill(126)

if __name__ == '__main__':
   run()

works correctly. Left click => black, right click => white, central click => gray

from p5 import *

def setup():
   size(100, 100)
   fill(0)

def draw():
    background(204)
    rect((25, 25), 50, 50)

def mouse_clicked():
    if mouse_button == "LEFT":
      fill(0)
    elif mouse_button == "RIGHT":
      fill(255)
    else:
      fill(126)

if __name__ == '__main__':
   run()

Does not work. Mouse_button seems undefined in mouse_clicked function and only gray is selected, whatever the click button is.

To Reproduce
Just use the code above

Expected behavior
The two code should behave the same

System information:

  • p5 release (version number or latest commit): latest pip version
  • Python version: 3.9
  • Operating system: Mac OS X
@tushar5526
Copy link
Member

tushar5526 commented Dec 4, 2023

Hi @swirly, this was rather a quick fix. Fixed it for both "skia" and "vispy" renderers. Please use the master branch to install p5. pip install git+https://github.com/p5py/p5.git

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.

2 participants