Is there anything built in that can give me the bounds of the currently visible window?
For example, the visible bounds for the below screenshot should be:
[x=20, y=20, width=312, height=140]
Is there anything built in that can give me the bounds of the currently visible window?
For example, the visible bounds for the below screenshot should be:
[x=20, y=20, width=312, height=140]
From a reference to the WindowWorkspace
; from there you can call getSelectedDesignPanel
(or use some other method to retrieve a DesignPanel
), which is the outer JScrollPane
that contains the 'rulers'; from there you should be able to retrieve underlying Swing bounds fairly easily.
I'm interested in what you want this information for, but purely out of curiosity.
Thanks Paul, I'll check that out.
The reason I need this information is that when I use the setClip()
method, Ignition wants to draw my components on top of the rulers and scroll bars.
I want to try to fix this by limiting the clip to the visible bounds.
Probably easier then to just SwingUtilities.getAncestorOfClass(TopLevelContainer.class)
, to get the 'root' window or template your component is on (in designer or client scope).
That returns the FPMIWindow
, from which I can use getVisibleRect()
, but that doesn't give me what I'm looking for.
I was able to get the DesignPanel
via SwingUtilities.getAncestorOfClass(ScrollPaneConstants.class,this)
. But how do I get the visible bounds from here? The .getVisibleRect()
method does not give me what I need.
I think you want topLevelContainer.getVisibleRect()
, you just also need to adjust your rectangle coordinate system, e.g. javax.swing.SwingUtilities#convertRectangle
.
I see now that it works good when the window is scaled at 100%. Still can't figure out though how to get proper values on any other scale
Can you take a step back and describe what you're actually trying to do?
Is there a reason you can't just have your component(s) paint within their own bounds? You get the clipping for free, then.
My components are built by extending AbstractVisionShape
, which uses the window's bounds as its own bounds, and then has another property boundingRect
, which is the actual bounds of the component.
Can you extend com.inductiveautomation.vision.api.client.components.shapes.PathBasedVisionShape
instead? I would essentially have to see your code and then reverse engineer AbstractVisionShape
to give you specific advice on what to do, but my guess is that if you extend PathBasedVisionShape
you'll basically get the right behavior "for free".