[SOLVED] Vision Animation using system.gui.moveComponent

After reading the literature I was under the impression the following code:

rect = event.source.parent.getComponent("template_Instruction1")
system.gui.moveComponent(rect, rect.x, rect.y)

tied to a button would move the component ‘template_Instrution1’ to the SAME position. However, at run time the component moves closer to the top right of the screen.

What gives here?

moveComponent is deprecated - use system.gui.transform, and pay attention to the ‘coordinate space’ parameter.

1 Like

Far easier than what I had planned to do. Thank you.

https://docs.inductiveautomation.com/display/DOC80/system.gui.transform

1 Like
#GET COMPONENT
component1 = event.source.parent.getComponent('Rectangle1')

#SET PARAMETERS TO PASS INTO system.gui.transform()
t_X = 			component1.relX
t_Y = 			component1.relY
t_Width = 		component1.relWidth
t_Height = 		component1.relHeight
t_Duration = 	1000
t_Callback = 	None
t_FPS = 		60
t_Accel = 		system.gui.ACCL_CONSTANT
t_Coord = 		system.gui.COORD_DESIGNER

system.gui.transform(
    	component = component1,
    	newX = t_X,
    	newY = t_Y,
    	newWidth = t_Width,
        newHeight = t_Height,
    	duration = t_Duration,
    	callback = None,
    	framesPerSecond = t_FPS,
    	acceleration = t_Accel
        coordSpace = t_Coord
)

I believe the above code should keep Rectangle1 at the same X,Y coordinates but it moves still with my button that triggers the code… I think this is because I have a docked window in my project on the left side. The size of the docked window is 200x1080. The size of the window running the animation is 1720x1080. The total size of the project should be 1920x1080.

Thoughts on this?

EDIT: UPDATED WITH SOLUTION

You’re not passing the t_Coord parameter in - you’ve tried both ways?

1 Like

Ahhhh im blind.

That was the solution thanks. I’ll update the code above to include the t-coord.

1 Like

What is the difference between these two?

rectX = 		rectangle[temp[x]].relX
rectY = 		rectangle[temp[x]].relY
rectWidth = 	rectangle[temp[x]].relWidth
rectHeight = 	rectangle[temp[x]].relHeight

and…

rectX = 		rectangle[temp[x]].getX()
rectY = 		rectangle[temp[x]].getY()
rectWidth = 	rectangle[temp[x]].getWidth()
rectHeight = 	rectangle[temp[x]].getHeight()

Because the “relX” from the first block doesn’t exist for templates on the screen. But when I use “getX()” from the second block to transform a template it doesn’t quite move to the correct location. I’m assuming “getX()” is calling the position relative to the Root container?

Welcome to the wonderful world of relative coordinate systems :slight_smile:
The rel<X/Y/width/height> options are only present on shapes, because of…reasons.
An X position of a component should be relative to its container - which may or may not be the root container; for templates it almost certainly isn’t.
You could try importing and using SwingUtilities.convertPoint - move from the given coordinate system to the actual root container’s coordinate system.

This is slightly above my current coding abilities. Care to post an example?

My alternate solution I've been working on is having invisible rectangles on the screen that I can send the templates too.

All this to create a scrolling like menu for the user :sweat_smile:
Simple example: I have rectangle 1, 2, 3 and template 1, 2, 3. Template 1 moves to rectangle 3. Template 2 moves to rectangle 1. And Template 3 moves to rectangle 2.

Would be something like this - rectangle is the input component, rectangle.parent would have to be adjusted to be a reference to the root container.

from javax.swing import SwingUtilities
adjusted = SwingUtilities.convertPoint(rectangle, rectangle.X, rectangle.Y, rectangle.parent)
#use adjusted.X, adjusted.Y
1 Like
from javax.swing import SwingUtilities

#Button constants.
t_Duration = 	1000
t_Callback = 	None
t_FPS = 		60
t_Accel = 		system.gui.ACCL_CONSTANT
t_Coord = 		system.gui.COORD_DESIGNER

#Initialize arrays of anchor points and templates on screen.
template = 	[0 for x in range(3)]

rectangle = event.source.parent

#Retrieve templates on screen.
template[0] = event.source.parent.getComponent('Template0')
template[1] = event.source.parent.getComponent('Template1')
template[2] = event.source.parent.getComponent('Template2')

adjusted0 = SwingUtilities.convertPoint(template[0], template[0].x, template[0].y, rectangle)
adjusted1 = SwingUtilities.convertPoint(template[1], template[1].x, template[1].y, rectangle)
adjusted2 = SwingUtilities.convertPoint(template[2], template[2].x, template[2].y, rectangle)

Animation.transformThis(template[1], adjusted1.x, adjusted1.y, template[1].width, template[1].height, t_Duration, t_Callback, t_FPS, t_Accel, t_Coord)

Well I assumed the above would keep the template[1] in the exact same location but it moved it slightly… Thoughts? If I figure this out I promise to leave you in peace for a week :smile:

If it’s only moving it slightly, it might be coordinates rounding down from floating point to integer, and there might not be a lot you can do about that - I think convertPoint only works with integer values.

1 Like

:sweat: :sob:

Back to the alternative method I guess. Hope the team includes more coordinates support in version 9…