You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently fiddling with the Event module.
When using a MouseMotion event, you can know if a button is pressed with the state masks but you can't check if no button are pressed.
Of course, you could just do something like
if event.state == 0:
#Do something
But it's less clear than having a mask I think.
So my suggestion would be to have a mask for this.
What do you think ?
The text was updated successfully, but these errors were encountered:
Python conventions would recommend doing this for your example:
ifnotevent.state:
...
The above code and your example are unambiguous, but you could add a comment if you needed it to be more verbose.
Realistically, the else clause could be used after checking for a state.
ifevent.state&tcod.event.BUTTON_LMASK: # Left button held.
...
else: # Left button not held.
...
Bit masks are meant to be used with bit-wise operators, so there isn't much reason to include a named zero. Make sure that you're using & and not == to check if a button is held.
The current names are derived directly from the SDL2 API, and probably won't change very much.
I like the not event.state, I didn't thought about it.
The else clause is not useful in my case because I need to check specifically if there is no button pressed.
It's related to focus behaviour : an object will gain/lose focus when the mouse move and no button is pressed and is treated before any other event handling basically.
It's related to focus behaviour : an object will gain/lose focus when the mouse move and no button is pressed and is treated before any other event handling basically.
I'd still try to limit that behavior to only the buttons which will interact with those elements:
ifnotevent.state& (tcod.event.BUTTON_LMASK|tcod.event.BUTTON_RMASK):
... # Left and right buttons not held.
Hey there,
I'm currently fiddling with the Event module.
When using a MouseMotion event, you can know if a button is pressed with the
state
masks but you can't check if no button are pressed.Of course, you could just do something like
But it's less clear than having a mask I think.
So my suggestion would be to have a mask for this.
What do you think ?
The text was updated successfully, but these errors were encountered: