This is the base code. Put it in its own source file.
(include "sci.sh")
(use "feature")
(use "obj")
(use "main")
(use "user")
(script 900)
(class LookAtView of View
(properties
parseName 0
)
)
(class LookAtProp of Prop
(properties
parseName 0
)
)
(class LookAtAct of Act
(properties
parseName 0
)
)
(instance onMeCode of Code
(properties)
(method (doit view event)
(var theX, theY, result)
= theX (send event:x())
= theY (send event:y())
= result (>= theX (send view:nsLeft()))
= result (& result (< theX (send view:nsRight())))
= result (& result (>= theY (send view:nsTop())))
= result (& result (< theY (send view:nsBottom())))
(return result)
)
)
(class MouseDownHandler of Script
(properties
defaultVerb 0
modifiers 0
)
(method (handleEvent event)
(var view, parsestr[50])
(if ((== (send event:type()) evMOUSEBUTTON) and
(& (send event:modifiers()) modifiers))
= view (send gCast:firstTrue(#perform onMeCode event))
(if (view and (send view:respondsTo(#parseName)))
(Format(@parsestr "%s %s" defaultVerb
(send view:parseName())))
(Parse(@parsestr event))
(send event:type(evSAID) claimed(FALSE))
(User:said(event))
(return TRUE)
)
(return FALSE)
)
(return FALSE)
)
)
To use it, make an instance of MouseDownHandler, and set its properties as you desire. defaultVerb should contain the text that the mouse button is to emulate, e.g. "look". modifiers should be set to 3 for the right button (emRIGHT_BUTTON) or 4 for the middle button (there is no constant for this, unfortunately). Make sure that the handleEvent method of your instance is called in the global handleEvent (the one in the Template instance). Finally, change all your View/Prop/Act instances to LookAtView etc. and set their parseName appropriately. Note that the handler is backwards compatible, so it can cope with views that don't have a parseName selector (i.e. instances of View etc.).
This approach depends on your own code to perform any actions - variations could easily be made that store the descriptions along wth the views. There are pros and cons to each, but this one requires minimal additional work and is compatible with the Said scheme described in Brian's tutorials.
Lars