mouse and key release events are supported in later SVN versions of 2.48a, and it is included in 2.49, so get the release candidate or wait for 2.49.
Blender.eventValue == 1 when mouse is down, and Blender.eventValue == 0 when mouse goes up.
Blender.event would == Draw.RIGHTMOUSE or Draw.LEFTMOUSE, or Draw.MIDDLEMOUSE, etc etc etc
if you want to intercept the Blender event so that you can execute your own code and not let it do it’s normal action, set Blender.event = None in your code.
i believe there’s also Window.GetMouseButtons() if need an OR’d status of the mouse buttons state.
In your event handler function, look at the ‘value’ (second argument to the function) value. It triggers a 1 when the mouse button is pressed and a 0 when its released. Based off that you can set a variable to tell you what state the mouse is in (you know if you saw a 1, but did not see a 0, then the button is still pressed), and you can do whatever you need based off that.
For drag operations you need to monitor the mouse position as well and once its moved a certain distance and is still pressed you would enter a “drag state” where you monitor the mouse movement until the mouse button is released (or you press escape).
Its probably easiest to think of it as an FSM (at least that’s how I think of it).
Basically, your UI would have states like normal, move, drag, etc. In normal mode it operates normally. In drag mode/state you “disable” buttons (you can’t actually do that without creating your own custom buttons, though) and allow things to move.
So you need to store state information, like how far the mouse has moved, etc. So you could do something like (in rough pseudocode):
MouseState = {'Left': 0, 'Right': 0, 'x': 0, 'y': 0, 'dragdx' : 0, 'dragdy': 0}
DRAGTHRESH = 5
UIState = 'Normal'
def gui():
if MouseState['Left'] and MouseState['dragdx'] >= DRAGTHRESH:
UIState = 'Drag'
Draw.Redraw()
elif UIState == 'Drag':
# do your drag state stuff
else:
# do your normal state stuff
def event(evt, val):
if evt == Draw.LEFTMOUSE:
MouseState['Left'] = val
if not val:
MouseState['dragdx'] = 0
# Check for right mouse maybe?
elif evt == Draw.MOUSEX:
if MouseState['Left']: # for drag
MouseState['dragdx'] += val - MouseState['x']
MouseState['x'] = val
# Check for Y movement
So that’s a little rougher than I expected :eek:, but the concept should still hopefully come across. Basically, you have a “state” variable and based off that you decide which actions to take. Its mainly a matter of keeping track of inputs accurately and dealing with some occasional quirks in the Blender draw cycle.
Thanks for the code. This is basically what I was after.
if evt == Draw.LEFTMOUSE:
if not val:
DrawProgressBar (0.0, "L-UP")
else:
DrawProgressBar (0.0, "L-DOWN")
if evt == Draw.RIGHTMOUSE:
if not val:
DrawProgressBar (0.0, "R-UP")
else:
DrawProgressBar (0.0, "R-DOWN")
if evt == Draw.MIDDLEMOUSE:
if not val:
DrawProgressBar (0.0, "M-UP")
else:
DrawProgressBar (0.0, "M-DOWN")