Continuous plug-in example
 
 
 

This example is a skeleton for continuous plug-ins. It echoes all user interaction to stdout.

continuousFuncExample.cpp

// cont.plugin 
// 
// This file implements a simple continuous function plugin, a plugin 
// that gets events from Alias and can interact with the user.  It can  
// be used as a skeleton from which to construct other, more complicated 
// continuous functions if desired. 
//  
#include <AlLiveData.h> 
#include <AlFunction.h> 
#include <AlFunctionHandle.h>  
#include <AlUniverse.h> 
#include <AlDagNode.h> 
#include <AlPickList.h> 
#include <AlPickable.h> 
#include <AlWindow.h>  
#include <AlTM.h>
char inbuf[ 256 ]; 
char text_buf[ 100 ]; 
const char * my_prompt = "Enter some text: %s";   
void go_button_pressed( void ) { 
	AlPrintf( kStdout, "Go button pressed!\n" ); 
	AlContinuousFunction::createGoButton( go_button_pressed ); 
}  
static void init_func( void ) { 
	AlPrintf( kStdout, "Now entering continuous plugin.\n" ); 
	AlContinuousFunction::createGoButton( go_button_pressed ); 
}  
static void down_func( int input, Screencoord x, Screencoord y ) 
{ 
	int button; 
	double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1; 
	AlWindow * w;  
	switch( AlContinuousFunction::translateInput( input, button ) ) { 
	case kInputButton: 
		w = AlUniverse::currentWindow(); 
		w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez ); 
		AlPrintf( kStdout, "Mousedown at %d,%d [%lf,%lf,%lf %lf,%lf,%lf].  Button %d.\n", 
			x,y, dx,dy,dz, ex,ey,ez, button ); 
		delete w; 
		break; 
	} 
} 
	 static void move_func( int input, Screencoord x, Screencoord y ) 
{ 
	int button; 
	double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1; 
	AlWindow * w;  
	switch( AlContinuousFunction::translateInput( input, button ) ) { 
	case kInputButton: 
		w = AlUniverse::currentWindow(); 
		w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez ); 
		AlPrintf( kStdout, "Mousemove at %d,%d [%lf,%lf,%lf %lf,%lf,%lf].  Button %d.\n", 
			x,y, dx,dy,dz, ex,ey,ez, button ); 
		delete w; 
		break; 
	case kInputKeyboard: 
		sscanf( inbuf, "%s", text_buf ); 
		AlPrintf( kStdout, "Text input: %s [%s]\n", text_buf, inbuf ); 
		break; 
	} 
}  
static void up_func( int input, Screencoord x, Screencoord y ) 
{ 
	int button; 
	double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1; 
	AlWindow * w;  
	switch( AlContinuousFunction::translateInput( input, button ) ) { 
	case kInputButton: 
		w = AlUniverse::currentWindow(); 
		w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez ); 
		AlPrintf( kStdout, "Mouseup at %d,%d [%lf,%lf,%lf %lf,%lf,%lf].  Button %d.\n", 
			x,y, dx,dy,dz, ex,ey,ez, button ); 
		delete w; 
		break; 
	} 
}  
static void cleanup_func() { 
	AlPrintf( kStdout, "Now leaving continuous plugin.\n" ); 
	AlContinuousFunction::clearGoButton( TRUE ); 
}  
AlFunctionHandle h; 
AlContinuousFunction hFunc;  
extern "C" 
PLUGINAPI_DECL int plugin_init( char *dirName )
{
	AlUniverse::initialize();  
	hFunc.create( "Continuous", init_func, down_func, move_func,  
								up_func, cleanup_func, TRUE ); 
	hFunc.setPrompt( my_prompt, inbuf, kFilterNone ); 
	h.create( "Cont Test", &hFunc ); 
	h.setAttributeString( "cont" ); 
	h.setIconPath( makeAltPath( dirName, NULL ) ); 
	h.addToMenu( "mp_objtools" );  
	AlPrintf( kPrompt, "Continuous example installed on Palette 'Object Edit."); 
	return 0; 
}  
extern "C" 
PLUGINAPI_DECL int plugin_exit( void ) 
{ 
	h.removeFromMenu(); 
	h.deleteObject(); 
	hFunc.deleteObject();  
	return 0; 
}