[22 Aug 2009] Question regarding InstallEventHandler()

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
nexus
Posts: 150
Joined: Sun Mar 07, 2010 11:54 am

[22 Aug 2009] Question regarding InstallEventHandler()

Post by nexus »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 22 Aug 2009 13:29:01 +0200

Hi all,

is there a way to *query* an event handler (which was installed by InstallEventHandler()) in order to temporarly replace it?

For example an even on "OnMouseUp" should execute a default action, but at some point in the presenation, a different action should be executed maybe in addition to the default action.

It would be nice to get the eventFunction previously installed with InstallEventHandler and to replace it by a different event handler, which in turn, installs the old event handler again or even *calls* the old eventhandler at the end of its execution.

thanks!

Tom.
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[23 Aug 2009] Re: Question regarding InstallEventHandler()

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 23 Aug 2009 18:44:08 -0000

Hi

I presume you want to overload the standard functionality of your event function in specific circumstances with some different code.

One way to do that without actually changing the event function is to take advantage of LUAs ability to handle functions like variables and pass action to one of multiple alternatives of the same set of functions, each of which covers a particular condition. A small example...

Code: Select all

Function MyKeyEventHandler(msg)
	switch msg.action
	case "OnKeyDown"
		if condition1
			Myaction["DEFAULT_ACTION"]
		if condition2
			Myaction["MYOTHER_ACTION"]
	EndSwitch
EndFunction
You have to decide for yourself what constitutes condition1 and condition1, but they can be used to control which functionality you want active just now.

Code: Select all

// Now create a list of functions called Myaction={}

Myaction["DEFAULT_ACTION"] = function()
	// Do what you need to do when you want the default action for OnKeyDown
EndFunction

Myaction["MYOTHER_ACTION"] = function()
	// Do what you need to do when you want the specific action after the OnKeyDown event.
EndFunction
Of course you then need to activate your event handler (MyKeyEventHander)

This is a simple example. By adding parameters to the function call you can make it more flexible.

One of the tricks you can do is to activate another event type or disable an event. I have used this to create fake windows from layers that can be dragged and dropped by their (equally fake) menu bar as long as you keep the mouse down after clicking in the menu bar, but change functionality once you release the mouse button.

I hope this is useful and that there are no silly errors in my example, as I write this while not in the company of my amiga :-)

regards Jesper
nexus
Posts: 150
Joined: Sun Mar 07, 2010 11:54 am

[24 Aug 2009] Re: Question regarding InstallEventHandler()

Post by nexus »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 24 Aug 2009 09:10:03 +0200

Code: Select all

Function MyKeyEventHandler(msg)
  switch msg.action
  case "OnKeyDown"
      if condition1
          Myaction["DEFAULT_ACTION"]
      if condition2
          Myaction["MYOTHER_ACTION"]
  EndSwitch
EndFunction
Nice idea, but not exactly what I wanted to have. In your example here, you have to know the conditions in advance when your event handling should change. What I have in mind, is, to allow dynamically change the event handling. But for this, it would be necessary to get the current function from "InstallEventHandler()" in order to not only replace it, but also to install it later again.

So, this is another feature request for Hollywood 4.1 from my side ;-)
You have to decide for yourself what constitutes condition1 and condition1, but they can be used to control which functionality you want active just now. This is a simple example. By adding parameters to the function call you can make it more flexible.
if you have full control over the code, this is indeed a nice way to handle it. But if you want to provide a template or library, which otheres could use (and then those users don't have a clue about the code of the library itself), the event handling has to be dynamically changeable such that, users are not too much restricted by your library.
One of the tricks you can do is to activate another event type or disable an event. I have used this to create fake windows from layers that can be dragged and dropped by their (equally fake) menu bar as long as you keep the mouse down after clicking in the menu bar, but change functionality once you release the mouse button.

I hope this is useful and that there are no silly errors in my example, as I write this while not in the company of my amiga :-)
It is useful! Thank you very much. And indeed, as long as the global table "Myaction" is known to everybody, you even can do the things I want to do because a table can be arbitrarily queried and changed. It's just not that convenient as if Hollywood itself allowed to get the currently set event handling function.

kind regards, Tom
User avatar
airsoftsoftwair
Posts: 5834
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[24 Aug 2009] Re: Re: Question regarding InstallEventHandler()

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 24 Aug 2009 13:03:22 +0200
Nice idea, but not exactly what I wanted to have. In your example here, you have to know the conditions in advance when your event handling should change. What I have in mind, is, to allow dynamically change the event handling. But for this, it would be necessary to get the current function from "InstallEventHandler()" in order to not only replace it, but also to install it later again.

So, this is another feature request for Hollywood 4.1 from my side ;-)
Ok, sounds like a good idea. I'll add it to my list :)
User avatar
TheMartian
Posts: 109
Joined: Sun Feb 28, 2010 12:51 pm

[24 Aug 2009] Re: Question regarding InstallEventHandler()

Post by TheMartian »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 24 Aug 2009 19:05:57 -0000

By the way... Have you tried something like:

InstallEventHandler({OnKeyDown=p_MyEventHandler})

and then in response to, say, a mouse event you may have a function that issues a statement like:

InstallEventHandler({OnKeyDown=0}) to disable the first event handler.

As I indicated previously I used this to change the reaction to certain event types while the program was running based on other events.

Unfortunately I can't mail you the code as my old XEA1 seems to finally have given up after 7 years of stellar service. So perhaps it is SAM Flex time for me soon if any are available :-)

regards Jesper
Locked