Makebutton "OnAnyEvent" = func

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Makebutton "OnAnyEvent" = func

Post 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.
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Makebutton "OnAnyEvent" = func

Post 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 :)
Bugala
Posts: 1178
Joined: Sun Feb 14, 2010 7:11 pm

Re: Makebutton "OnAnyEvent" = func

Post by Bugala »

Funny how simplest of solutions sometimes just dont come to mind. Thanks from that solution, will help keep the code cleaner.
Post Reply