Hi, I want to play a sound as soon as a button is pressed, but when using Event/Select the sound always plays when the button is release with the mouse. Any ideas...?
Playsound when button pressed not released?
BlitzMax Forums/BlitzMax GUI Programming/Playsound when button pressed not released? Perhaps use an active panel or a canvas instead and play on the mouse click itself, after you've checked the mouse is indeed inside the correct rect.
- David
- David
when using Event/Select the sound always plays when the button is release with the mouse.
Ah yes, that's because MaxGUI Buttons don't have a "mouse down" event on Win32/Mac. Tis a shame really, as those platforms are just as capable as GTK in supporting more events.
You may have to resort to what David says above, unfortunately.
hmm, a bit of a pain. Brucey does your new GUI module allow this?
It does now ;-)
Gadgets/Widgets by default only support a small set of events - like a button tends only to be interested in button-clicks.
However, it is possible to tell a widget that it is interested in all kinds of events, and then all you need to do is sub-class it, and Connect the new events to the instance of the widget.
I've just added support for this with wxButton, so an example I knocked together would look like this :
We extend wxButton, and connect a Left-mouse-button Down event to it. Now, when you press the button, it first fires off the event.
"event.Skip()" forwards the mouse event onwards to the button proper - otherwise the button would never know you clicked!
It has potential... but still has a way to go until it's finished... getting there :-)
Gadgets/Widgets by default only support a small set of events - like a button tends only to be interested in button-clicks.
However, it is possible to tell a widget that it is interested in all kinds of events, and then all you need to do is sub-class it, and Connect the new events to the instance of the widget.
I've just added support for this with wxButton, so an example I knocked together would look like this :
SuperStrict Framework wx.wxApp Import wx.wxPanel Import wx.wxFrame Import wx.wxButton Import wx.wxMouseEvent New MyApp.run() Type MyApp Extends wxApp Field frame:MyFrame Method OnInit:Int() frame = MyFrame(New MyFrame.Create(Null, -1, "Button Event Test", 200, 200)) SetTopWindow(frame) frame.show() Return True End Method End Type Type MyFrame Extends wxFrame Const BUTTON1:Int = 101 Method OnInit() ' a panel Local panel:wxPanel = wxPanel.CreatePanel(Self) ' add buttons to the panel New MyButton.Create(panel, BUTTON1, "Button &1", 50, 30, 100, 30) End Method End Type Type MyButton Extends wxButton Method OnInit() ConnectAny(wxEVT_LEFT_DOWN, OnMouseDown) End Method Function OnMouseDown(event:wxEvent) DebugLog "down!" event.Skip() End Function End Type
We extend wxButton, and connect a Left-mouse-button Down event to it. Now, when you press the button, it first fires off the event.
"event.Skip()" forwards the mouse event onwards to the button proper - otherwise the button would never know you clicked!
It has potential... but still has a way to go until it's finished... getting there :-)
Thats, great thanks allot.