Home » Eclipse Projects » GEF » Problem with hover feedback geometry with GEF4.0.0RC2
|
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733127 is a reply to message #1733118] |
Tue, 24 May 2016 08:49 |
|
As GeometryNode is now based on Region, its layout bounds are fixed to (0, 0, width, height). We interpret the position information within its Geometry as its layoutX, layoutY values, so literally speaking the geometry reflects the boundsInParent of the GeometryNode. The translation within NodeUtils has been added to compensate this (as it should retrieve a geometry within the local coordinate system of the given node, not its parent). It seems as if a translation (localToParent/parentToLocal) is missing in some place. How do you position your nodes?
|
|
|
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733154 is a reply to message #1733118] |
Tue, 24 May 2016 13:02 |
|
Xavier, to illustrate this take a look at the following test code:
// Shape
javafx.scene.shape.Rectangle shape = new javafx.scene.shape.Rectangle(5, 10, 30, 40);
shape.setStroke(Color.RED);
shape.setStrokeWidth(3);
shape.setStrokeType(StrokeType.OUTSIDE);
shape.relocate(30, 40);
IGeometry geometricOutline = NodeUtils.getGeometricOutline(shape);
assertTrue(geometricOutline instanceof Rectangle);
// the geometry is returned in the local coordinates of the Shape (the
// stroke is outside), thus the X and Y values are preserved
assertEquals(new Rectangle(5, 10, 30, 40), geometricOutline);
// translating it into parent coordinates returns the relocate values
// including the stroke offset
assertEquals(new Rectangle(33, 43, 30, 40), NodeUtils.localToParent(shape, geometricOutline).getBounds());
// GeometryNode
GeometryNode<Rectangle> geometryNode = new GeometryNode<>();
geometryNode.setStroke(Color.RED);
geometryNode.setStrokeWidth(3);
geometryNode.setStrokeType(StrokeType.OUTSIDE);
geometryNode.setGeometry(new Rectangle(0, 0, 30, 40));
geometryNode.relocate(30, 40);
geometricOutline = NodeUtils.getGeometricOutline(geometryNode);
assertTrue(geometricOutline instanceof Rectangle);
// the geometric is returned in the local coordinates of the
// GeometryNode (as the stroke is outside the geometry but inside the
// GeometryNode the geometry is translated by the stroke offset)
assertEquals(new Rectangle(3, 3, 30, 40), geometricOutline);
// translating it into parent coordinates should provide the same values
// as in the Shape case, i.e. the relocate values including the stroke
// offset
assertEquals(new Rectangle(33, 43, 30, 40), NodeUtils.localToParent(geometryNode, geometricOutline).getBounds());
Prior to our change, the Geometry included its X and Y values in its layout bounds (similar to Shape). Now, as it extends Region, the layout bounds are fixed by (0,0). In parent coordinates nothing should have changed, but if a respective translation is missing, the layoutX, layoutY offset should be noticeable.
|
|
|
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733388 is a reply to message #1733118] |
Thu, 26 May 2016 23:56 |
|
Hi Xavier,
supplementary to Alexander's replies, you can check what geometry provider is used for hover feedback and how the hover feedback part factory transforms the provided geometry. In the Logo example, the GeometricOutlineProvider is used and the FXDefaultFeedbackPartFactory transforms the provided geometry from the local coordinate system of the target node into the coordinate system of the scene. Possibly, in your case, either the geometry provider does not return the geometry in local coordinates of the target node, or the transformation from local to scene coordinates within the factory is incorrect.
For debuggin purposes, you can output the target node and its local-to-scene-transformation within the factory, and you can output the provided geometry within FXHoverFeedbackPart#doRefreshVisual(), which should be in parent coordinates, as well as the feedback part visual's local-to-scene-transformation, which should reflect the translation.
Best regards,
Matthias
|
|
| | |
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733499 is a reply to message #1733440] |
Sat, 28 May 2016 20:45 |
|
I have a pretty similar situation. I have around 40 different parts, most of which use a GeometryNode as the visual, but a handful use Group instead. The ones that use Group add an invisible GeometryNode with the model object's outline geometry, which is used by the geometry provider. After picking up these changes, I also had to add the localToParent conversion as Alexander says. Here is my geometry provider:
public IGeometry get() {
IVisualPart<Node, ? extends Node> adaptable = getAdaptable();
if (adaptable instanceof TerrainPart<?, ?>) {
TerrainPart<?, ?> part = (TerrainPart<?, ?>) adaptable;
IGeometry outline = NodeUtils.getGeometricOutline(part.getGeometryOutline());
if (part.isLocalGeometry()) {
return outline;
} else {
return NodeUtils.localToParent(part.getGeometryOutline(), outline);
}
}
return NodeUtils.getGeometricOutline(adaptable.getVisual());
}
TerrainPart is the base class for all my different parts. The method getGeometryOutline() returns the GeometryNode to use for the outline - in the base base it is the part's visual, in the classes using group it is the invisible child. The isLocalGeometry() method is overridden in the Group parts to return false, so it does the conversion to parent coordinates. That all works nicely.
Colin Sharples
CTG Games Ltd
Wellington, New Zealand
|
|
|
Re: Problem with hover feedback geometry with GEF4.0.0RC2 [message #1733506 is a reply to message #1733499] |
Sat, 28 May 2016 23:18 |
|
Incidentally, this change also affects how you interpret mouse events in the part geometry. Previously, in my IFXOnClickPolicy and IFXOnDragPolicy classes, I was just using Node.sceneToLocal() to convert the mouse event sceneX() and sceneY() to a point that I could use in model coordinates. However, that will now always return a point in reference to the (0, 0) origin of the Region, so you need to do a two-step transform to get the point back into the parent coordinates of the GeometyNode. I added a method to my base TerrainPart, again using the getGeometryOutline() method to get the model's geometry, as follows:
public Point sceneToLocal(double sceneX, double sceneY) {
GeometryNode<?> outline = getGeometryOutline();
Point local = NodeUtils.sceneToLocal(outline, new Point(sceneX, sceneY));
return NodeUtils.localToParent(outline, local);
}
Here's an example of this being used. This is an IFXOnDragPolicy that rotates a part, so I want to calculate the new angle of rotation from the current position of the mouse relative to the current location of the model object. Geometry.getAngleFrom() is a utility method of mine that returns the angle (as a clockwise rotation from the X-axis) from point A to point B. Obviously, those two points both need to refer to the same coordinate space for it to compute the angle correctly.
public void drag(MouseEvent e, Dimension delta) {
Point reference = targetPart.sceneToLocal(e.getSceneX(), e.getSceneY());
Angle newAngle = Geometry.getAngleFrom(targetPart.getTerrain().getLocation(), reference);
// update transaction policy with the new angle
}
Colin Sharples
CTG Games Ltd
Wellington, New Zealand
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 10:23:29 GMT 2024
Powered by FUDForum. Page generated in 0.05932 seconds
|