Page 1 of 1

Makebutton "OnAnyEvent" = func

Posted: Sun Aug 27, 2017 4:14 pm
by Bugala
Now that I am changing functions activated by button calls on the fly, I am currently thinking the cleanest way to do this is:

Code: Select all

function MyButtonActionFunction(msg)
switch msg.action
           case "OnMouseDown":
                      MyLeftMouseDownFunc()
           case "OnRightMouseDown":
                      MyRightMouseDownFunc()
...
endswitch
endfunction
And this is what i basically use on any button, that regardless what event triggered, it is always going to that one and same function dedicated for that buttons action events so it can call the appropriate function that i can change on the fly.


Therefore, it would be nice to have on that Makebuttons event part "OnAnyEvent" possibility, for now that I am always calling the same function, it is slightly annoying to:

Code: Select all

MakeButton(NIL, #SIMPLEBUTTON, 100, 100, 200, 200 {OnMouseDown = samefunc, OnRightMouseDown = samefunc, OnMiddleMouseDown = samefunc, OnMouseUp = samefunc, OnRightMouseUp = samefunc...})
when it could be done:

Code: Select all

MakeButton(NIL, #SIMPLEBUTTON, 100, 100, 200, 200 {OnAnyEvent = samefunc})
Although the drawback is that this MyActionButtonFunc would be called on every possible event, I dont think that is such a big deal, since if all my Function does is to check which action it is and then switch to corresponding action to execute corresponding function meant for it, I dont think it would really take that much resources even it would everytime come and execute that even when unnecessary.

Re: Makebutton "OnAnyEvent" = func

Posted: Wed Nov 01, 2017 7:03 pm
by Allanon
If you need such feature you can write your custom MakeButton code, for example :

Code: Select all

Function MakeButton2(id, type, x, y, w, h, callback)
  Local id = MakeButton(id, type, x, y, w, h, {OnMouseDown = callback, OnRightMouseDown = callback, OnMiddleMouseDown = callback, OnMouseUp = callback, OnRightMouseUp = callback...})
  Return(id)
EndFunction
And you are done :)

Re: Makebutton "OnAnyEvent" = func

Posted: Wed Nov 01, 2017 9:55 pm
by Bugala
Funny how simplest of solutions sometimes just dont come to mind. Thanks from that solution, will help keep the code cleaner.