Choose Language Hide Translation Bar
Highlighted
gob0b
Level I

Custom Graph Background Image Drag Reset

Hi,

  Given a custom graph box with background image and handle script, is there a way to prevent the user from accidentally dragging the background image when they miss the handle?  The problem I have is that frequently when trying to drag the handle I or another user will miss click and wind up dragging the background image instead.  There's no easy way to undo this, Ctrl+Z just rescales the image to its original size (not to the size of the graph box).  My question is this: Is there a way to force a background image in a graph box to be un-draggable?  Or, failing that, is there a way to capture Ctrl+Z to undo this mis-click?  Worst case scenario I can add a button, but its UI clutter I don't want.

 

Example

img = New Image( "$SAMPLE_IMAGES/tile.jpg" );
scale_factor = 0.5;
curimg_scaled = img;
curimg_scaled << Scale( scale_factor );
{scaled_width, scaled_height} = curimg_scaled << Size;
XX=scaled_width/2;
YY=scaled_height/2;
gb = Graph Box(
	<<Add Image(
		Image( New Image( curimg_scaled ) ),
		Bounds( Left( 0 ), Right( scaled_width ), Top( 0 ), Bottom( scaled_height ) )
	),
	XName( "X_scaled" ),
	XAxis( Min( 0 ), Max( scaled_width ), Increment( 100 ), Show Minor Grid( 0 ), Show Major Grid( 0 ) ),
	YName( "Y_scaled" ),
	YAxis( Min( scaled_height ), Max( 0 ), Increment( 100 ), Show Minor Grid( 0 ), Show Major Grid( 0 ) ),
	Marker Size( 6 ),
	Handle(
		XX,
		YY, 
	//dragscript -- update position
		XX = If(x>scaled_width,scaled_width,x<1,1,x);
		YY = If(y>scaled_height,scaled_height,y<1,1,y);, 
	//mouseupscript -- update profile plots
		XX = Round( XX );
		YY = Round( YY );
		// DO STUFF
		txt = Eval Insert( "(X,Y)=(^XX^,^YY^)" );
		Print(txt);
		tb_xy << Set Text( txt );
	);
	H Line( YY );
	V Line( XX );
);
New Window("Test",V List Box(gb,tb_xy=Text Box("")));

 

Robert Maltby
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: Custom Graph Background Image Drag Reset

You can lock the image.

 

img = New Image( "$SAMPLE_IMAGES/tile.jpg" );
scale_factor = 0.5;
curimg_scaled = img;
curimg_scaled << Scale( scale_factor );
{scaled_width, scaled_height} = curimg_scaled << Size;
XX = scaled_width / 2;
YY = scaled_height / 2;
gb = Graph Box(
	<<Add Image(
		Image( New Image( curimg_scaled ) ),
		Bounds( Left( 0 ), Right( scaled_width ), Top( 0 ), Bottom( scaled_height ) ), 
		//
		//
		Lock( 1 ) // lock the image so it can't be moved or rescaled
		//
		//
	),
	XName( "X_scaled" ),
	XAxis(
		Min( 0 ),
		Max( scaled_width ),
		Increment( 100 ),
		Show Minor Grid( 0 ),
		Show Major Grid( 0 )
	),
	YName( "Y_scaled" ),
	YAxis(
		Min( scaled_height ),
		Max( 0 ),
		Increment( 100 ),
		Show Minor Grid( 0 ),
		Show Major Grid( 0 )
	),
	Marker Size( 6 ),
	Handle(
		XX,
		YY, 
	//dragscript -- update position
		XX = If(
			x > scaled_width, scaled_width,
			x < 1, 1,
			x
		);
		YY = If(
			y > scaled_height, scaled_height,
			y < 1, 1,
			y
		);, 
	//mouseupscript -- update profile plots
		XX = Round( XX );
		YY = Round( YY );
		// DO STUFF
		txt = Eval Insert( "(X,Y)=(^XX^,^YY^)" );
		Print( txt );
		tb_xy << Set Text( txt );
	);
	H Line( YY );
	V Line( XX );
);
New Window( "Test", V List Box( gb, tb_xy = Text Box( "" ) ) );
-Jeff

View solution in original post

3 REPLIES 3
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: Custom Graph Background Image Drag Reset

You can lock the image.

 

img = New Image( "$SAMPLE_IMAGES/tile.jpg" );
scale_factor = 0.5;
curimg_scaled = img;
curimg_scaled << Scale( scale_factor );
{scaled_width, scaled_height} = curimg_scaled << Size;
XX = scaled_width / 2;
YY = scaled_height / 2;
gb = Graph Box(
	<<Add Image(
		Image( New Image( curimg_scaled ) ),
		Bounds( Left( 0 ), Right( scaled_width ), Top( 0 ), Bottom( scaled_height ) ), 
		//
		//
		Lock( 1 ) // lock the image so it can't be moved or rescaled
		//
		//
	),
	XName( "X_scaled" ),
	XAxis(
		Min( 0 ),
		Max( scaled_width ),
		Increment( 100 ),
		Show Minor Grid( 0 ),
		Show Major Grid( 0 )
	),
	YName( "Y_scaled" ),
	YAxis(
		Min( scaled_height ),
		Max( 0 ),
		Increment( 100 ),
		Show Minor Grid( 0 ),
		Show Major Grid( 0 )
	),
	Marker Size( 6 ),
	Handle(
		XX,
		YY, 
	//dragscript -- update position
		XX = If(
			x > scaled_width, scaled_width,
			x < 1, 1,
			x
		);
		YY = If(
			y > scaled_height, scaled_height,
			y < 1, 1,
			y
		);, 
	//mouseupscript -- update profile plots
		XX = Round( XX );
		YY = Round( YY );
		// DO STUFF
		txt = Eval Insert( "(X,Y)=(^XX^,^YY^)" );
		Print( txt );
		tb_xy << Set Text( txt );
	);
	H Line( YY );
	V Line( XX );
);
New Window( "Test", V List Box( gb, tb_xy = Text Box( "" ) ) );
-Jeff

View solution in original post

Highlighted
gob0b
Level I

Re: Custom Graph Background Image Drag Reset

Thanks a bunch Jeff! Is that option to the image message documented? I must’ve missed it.
Robert Maltby
Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: Custom Graph Background Image Drag Reset

I started by right clicking on the image to see if there was a Lock option there.

 

2020-09-02_09-20-59.539.png

Then I searched the Scripting Index (Help->Scripting Index) for Lock, and I found it on the PictSeg object. 

 

2020-09-02_09-17-05.895.png

I then experimented to see if I could use it on the Add Image() message directly as I showed you above.

-Jeff
Article Labels