Description of the problem: I can’t get to make isPressedIn work. It never returns True, no matter the object I’m checking the position against.
This is the code part that checks for it (in Each Frame tab of code_4):
def update_bounding_box_position(mouse,box):
buttons=mouse.getPressed()
if buttons[0]==1:
mouse_pos = mouse.getPos()
if mouse.isPressedIn(confirm_button_prova):
confirm_button_prova.fillColor = [-1,0.04,-1]
box.pos = mouse_pos
Hi,
I only pasted the part of the code that deals with it. I call the function in the same Each Frame tab. The rest of the code functions, but isPressedIn keeps not returning True.
def update_bounding_box_position(mouse,box):
if mouse.isPressedIn(trial_confirm_button_box):
confirm_button_prova.fillColor = [-1,0.04,-1]
buttons=mouse.getPressed()
if buttons[0]==1:
mouse_pos = mouse.getPos()
box.pos = mouse_pos
…
update_bounding_box_position(Prova_mouse, Prova_bounding_box)
I also implemented your crib sheet color suggestion
So box and trial_confirm_button_box are different polygons (rectangles), I want to move “box” where I click with the mouse (and it works fine), but also change the color of the confirm_button_box to green once I press on it (and that doens’t work). I implemented the green button after the box moving feature, I admit putting both of them in the same function is not the clearest way to do it. I also tried to check for the button press outside the function, but with no results.
Precisely! I think I found the culprit. I had to manually set the window units as “pixels”, but the button box units were in height (0.26, 0.13). This caused the box the get correctly drawn in the right position, but isPressedIn was checking as if [0.26,0.13] were the dimensions in pixels. I tested it by setting the button size to [100,100] (height) and it turned green only if I pressed in the middle of the screen. I can remove the window units settings, but now the mouse position on click gets set to the center (I think due to the same problem) at every click.
Update: I solved it by multiplying the mouse coordinates by the window height, now everything works!
Please could you post the code where you do this? I’m not sure how this might work and the code you posted didn’t involve coordinates for the “isPressedIn” section.
To be clear, multiplying the mouse coordinates by window height solved the fact that the mouse position on click would be moved only to the center. The original problem was solved by removing an old line “win.units=‘pix’”
Here is the final function:
def update_bounding_box_position(mouse,box, button):
if mouse.isPressedIn(button):
button.setFillColor(green)
confirmed_position=True
elif mouse.getPressed()[0]:
mouse_pos=mouse.getPos()
mouse_x=mouse_pos[0]*win.size[1]
mouse_y=mouse_pos[1]*win.size[1]
mouse_new=[mouse_x,mouse_y]
box.pos = mouse_new