Bookshelf Contents Previous Next Glossary Index Search

Momentary Functions and Continuous Functions

There are two kinds of functions that can be invoked from the Alias menu: momentary functions and continuous functions.

Momentary Functions

A momentary function is essentially a single event: a function that takes no arguments and has no return value. It is simply a jump point in memory. Alias transfers control to this point when the menu item is invoked, the function executes, and control is returned to Alias. An example of a momentary function is `delete all'.

The simplest way to define a momentary function is through the AlMomentaryFunction class. Calling one of the create methods on an instance of that class will generate a new momentary function in Alias.

One can also define a momentary function in Scheme using the ui-function-define-momentary primitive. This primitive takes two arguments - the name of the momentary function to define, and a piece of executable Scheme code. This can be the name of another function or a lambda closure. Once the momentary function is defined, it can be referenced like any other and added to menus. For instance, to create a menu item that invokes the unix command `xcalc', one could add the following to Alias.scm:

	(ui-function-define-momentary "InvokeXcalc" 
		(lambda () (unix-system "xcalc &")))
	(ui-string "xcalc.str" "Invoke xcalc")
	(ui-function "invoke_xcalc"
		(list 'command "InvokeXCalc")
		(list 'label_string 'xcalc.str)
	)
	(ui-menu-add-entry "al_goto" 'invoke_xcalc)

Note that the lambda expression attached to the momentary function uses the unix-system primitive, which executes its argument as a unix command.

Continuous Functions

A continuous function is more complicated than a momentary function. It is event driven: it must respond to user interaction through the mouse, keyboard, and user defined devices. As a result, continuous functions do not actually take over control of Alias when they execute. Rather, they define a context under which UI events are interpreted. Alias reads these events and transfers them to a group of event handlers defined by the continuous function. Thus a continuous function is a set of five callback functions: init, down, move, up and cleanup.

In addition, a continuous function is allowed to define pre-init and post-cleanup functions. The reason for these is that there are two ways to enter and leave the context of a continuous function. The function can be preempted temporarily by selecting some momentary function, or terminated more permanently by switching contexts to some other continuous function (or quitting Alias, of course). The pre-init and post-cleanup functions allow you to define actions that get invoked when Alias truly changes contexts and does not merely preempt your continuous function.

Init

"Init" is executed when the context of a continuous function is entered. This occurs when the function is first invoked, or after returning from a momentary function which pre-empted the function, or after reselecting this continuous function after completing some other continuous function.

Down

"Down" is called on every mouse down event. Use this function to detect the start of a click-drag type of operation.

Move

"Move" corresponds to the sequence of mouse movement events that occur between a mouse down and a mouse up. A move event will be generated for each significant mouse movement while a button is being held down. Further, "move" will be called in the case that the enter key is pressed on the keyboard. Therefore, it is in the move function that keyboard input should be detected.

Up

"Up" is called on mouse up events. Use this function to do things like commit transforms or create geometry corresponding to some sequence of mouse drags.

Cleanup

"Cleanup" is called when the context of this function is left to perform some other action. For example, if the user is in the context of your continuous plug-in, and invokes some other momentary function, the cleanup function will be called, followed by the momentary function, followed by the "init" function when Alias returns to the context of the original continuous function.



Bookshelf Contents Previous Next Glossary Index Search

[email protected]
Copyright © 1998, Alias|Wavefront, a division of Silicon Graphics Limited. All rights reserved.