Jump to content
Developer Wiki and Function Reference Links ×

Sample VST with Mode Bar Buttons


Recommended Posts

Julian,

   If you find one, I'd love one, too. Please share. Years ago, when I first looked for the same, I believe I was told it was only achievable with the SDK. I have several tools I have made that would benefit immensely from Mode Buttons. I hope you find an example.

 

Raymond

Link to comment

It's possible, but not straightforwards.  You need to flag the tool as event enabled.  AFIK, the only way to do this is with a hex editor.  The instructions for this are somewhere — either in the developer wiki, or possibly VectorDepot or such.

 

The mode bar buttons are generally designed to be part of RunTempTool or TrackObject.  These are generally best run from a menu or PIO button, though.  Tool functionality is primarily why I switched to the SDK.

 

Here's an example.  It's an edited version of an actual plug-in, not a sample, so it won't necessarily work as is.

 

PROCEDURE MyScript;
CONST
	kToolXPropSelectionChange = 1;		{tool wants selection change events.}
	kToolXPropUnsupported = 2;			{not supported}
	kToolXPropWantsMoveSelection2D = 3;	{tool wants kToolMoveSelection2DEvent event with nudge and move 2D commands.}
	k2DToolEnabledInStackedLayerMode = 4;		{2D tool wants to be enabled in Unified View.}
	kToolXPropSetUnrestrictedMode	= 5;		{set unrestricted scaling mode to the 2D selection tool}

	kToolInitGlobals		= 1;
	kToolDisposeGlobals		= 2;
	kToolDoSetup			= 3;
	kToolDoSetDown			= 4;
	kToolGetCursor			= 5;
	kToolDoInterface 		= 6;	{// to be removed}
	kToolDoModeEvent		= 7;
	kToolDoDoubleClick		= 8;
	kToolDoDrawScrMod		= 9;
	kToolDoUndrawScrMod		= 10;
	kToolPointAdded			= 100;
	kToolMouseMove			= 101;
	kToolDrawingDoubleClick	= 102;
	kToolDraw 				= 103;
	kToolHandleComplete 	= 104;
	kToolGetStatus 			= 105;
	kToolPointRemoved		= 106;
	kToolGenericStateChange	= 107;		
	
	{ below can be sent to Tool Definition Procedure (TDP) with Extended Properties.}

	kToolOnInitXProperties		= 108;
	kToolOnSelectionChange		= 109;															
	kToolOnMoveSelection2D		= 110;														
	kToolCustomSubtypeInsert	= 111;		
	kToolOnIdleEvent			= 112;						
	kToolOnCustomBarEvent     	= 113;
	
	kStr_HelpSelectPoint	= 3000 -1 + 1;	{String in PIO.  I would move these to strings file now}
	kStr_HelpSelectOrigin	= 3000 -1 + 2;	

	kMode1Btn1 = 'VWRName/Images/ModeViewBar/NameofImage1.png';
	kMode1Btn2 = 'VWRName/Images/ModeViewBar/NameofImage2.png';
	
	kModeGroupOrigin = 1;
	kModeGroupClick = 2;
	kOriginStore = 9001;
	kTokenCounter = '<count>';

VAR
	pt 			:POINT;		{User click point}
	origin		:POINT;		{User origin}
	outAction     :LONGINT;
	outMessage1   :LONGINT;
	outMessage2   :LONGINT;
	helpText 		:dynarray[] of char;
	result			:BOOLEAN;
	totalPts		:LONGINT;
	firstPt			:REAL;
	modeInt_1		:LONGINT;
	i			:INTEGER;
	startIndex	:INTEGER;
	adjustTotal	:INTEGER;
	
	boo			:boolean;

{---------------------------------------------------------------------}
FUNCTION GetOriginMode : REAL;
	VAR
		mode:REAL;
		boo	:BOOLEAN;
	BEGIN
		vstGetDataLong( kOriginStore, mode, boo );
		IF NOT boo THEN
			mode := 1;
		GetOriginMode := mode;
	END;
{---------------------------------------------------------------------}
BEGIN
	vstGetEventInfo(outAction, outMessage1, outMessage2);
	
	vstGetModeValue(1, modeInt_1);

	CASE outAction OF
		kToolInitGlobals		: BEGIN
		
		END;
		kToolDisposeGlobals		: BEGIN
		
		END;
		kToolDoSetup			: BEGIN
			AddRadioMode( kModeGroupOrigin, 2, kMode1Btn1, kMode1Btn2, '', '', '', '' );
			vstSetPtBehavior(4);
			vstGetModeValue(kModeGroupOrigin, modeInt_1);
			IF modeInt_1 = kModeGroupOrigin THEN
				vstSetHelpString(GetPluginString(kStr_HelpSelectPoint))
			ELSE
				vstSetHelpString(GetPluginString(kStr_HelpSelectOrigin));
			vstSetDataReal(1, 1, result);
		END;
		kToolDoSetDown			: BEGIN
			ReDrawAll;
			vstGetModeValue(kModeGroupOrigin, modeInt_1);
			vstSetDataLong( kOriginStore, modeInt_1, boo );
		END;
		kToolGetCursor			: BEGIN
		
		END;
		kToolDoInterface 		: BEGIN
		
		END;
		kToolDoModeEvent		: BEGIN
			IF modeInt_1 = kModeGroupOrigin THEN
				vstSetHelpString(GetPluginString(kStr_HelpSelectPoint))
			ELSE
				vstSetHelpString(GetPluginString(kStr_HelpSelectOrigin));
		END;
		kToolDoDoubleClick		: BEGIN
		
		END;
		kToolDoDrawScrMod		: BEGIN
		
		END;
		kToolDoUndrawScrMod		: BEGIN
		
		END;
		kToolPointAdded			: BEGIN
			vstNumPts(totalPts);
			vstGetDataReal(1, firstPt, result);
			IF (totalPts=2) & (firstPt=1) THEN BEGIN
				vstSetDataReal(1, 0, result);
				totalPts:=1;
			END;
			IF modeInt_1=kModeGroupOrigin THEN adjustTotal:=0 ELSE adjustTotal:=-1;
			helpText := GetPluginString( kStr_HelpClicks );
			ReplaceStr( helpText, kTokenCounter, Concat( totalPts + 1 + adjustTotal ) );
			vstSetHelpString( helpText );
		END;
		kToolMouseMove			: BEGIN

		END;
		kToolDrawingDoubleClick: BEGIN
		END;
		kToolDraw 				: BEGIN
		
		END;
		kToolHandleComplete 	: BEGIN
			vstNumPts(totalPts);
			IF modeInt_1=kModeGroupOrigin THEN BEGIN	{Drawing origin}
				origin.y:=0;
				startIndex:=1;
			END
			ELSE BEGIN
				vstGetPt2D(0, origin.x, origin.y, result);
				startIndex:=2;
			END;
			FOR i:=startIndex TO totalPts DO BEGIN
				vstGetPt2D(i-1, pt.x, pt.y, result);

			END;

			RefreshAllLSSched;
			vstSetHelpString(GetPluginString(kStr_HelpSelectPoint));
			vstSetDataReal(1, 1, result);
		END;
		kToolGetStatus 			: BEGIN
		
		END;
		kToolPointRemoved		: BEGIN
		
		END;
		kToolGenericStateChange: BEGIN
		
		END;
	END; {CASE}
END;
Run(MyScript);

 

Link to comment

Getting the tool to work is actually not so bad. Figuring out what events are open to VS takes some trial and error, and they are different for event enabled tools, RunTempTool, and TrackObject. 

 

And there still isnt away to get a VS tool to run before the first click. 

Link to comment
  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...