PIcking needs to take into account effects that alter the geometry of an object, such as the perspective effect. The following test program draws a black, filled rectangle that has a perspective effect applied. The red stroked rectangle shows the local bounds and the green stroked rectangle shows the original layout bounds. Both are correct. Picking is currently done on the original, unaltered geometry, which is not what an application would expect.
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.shape.*;
import javafx.scene.input.*;
import javafx.scene.paint.*;
import java.lang.Math;
var width = 200;
var height = 200;
var radius = width/2;
var back = height/10;
var t = 3.14 / 8;;
var rect = Rectangle {
x:10 y:10 width:100 height:100
effect: PerspectiveTransform {
ulx: radius - Math.sin(t)*radius uly: 0 - Math.cos(t)*back
urx: radius + Math.sin(t)*radius ury: 0 + Math.cos(t)*back
lrx: radius + Math.sin(t)*radius lry: height - Math.cos(t)*back
llx: radius - Math.sin(t)*radius lly: height + Math.cos(t)*back
}
onMouseMoved:function(e:MouseEvent):Void {
println(e);
}
onMousePressed:function(e:MouseEvent):Void {
println(e);
}
}
var localBounds = Rectangle {
x: bind rect.boundsInLocal.minX
y: bind rect.boundsInLocal.minY
width: bind rect.boundsInLocal.width
height: bind rect.boundsInLocal.height
fill: null
stroke: Color.RED
strokeWidth: 3
}
var layoutBounds = Rectangle {
x: bind rect.layoutBounds.minX
y: bind rect.layoutBounds.minY
width: bind rect.layoutBounds.width
height: bind rect.layoutBounds.height
fill: null
stroke: Color.GREEN
strokeWidth: 3
}
Scene {
width: 600
height: 450
content: [ rect, localBounds, layoutBounds ]
}
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.shape.*;
import javafx.scene.input.*;
import javafx.scene.paint.*;
import java.lang.Math;
var width = 200;
var height = 200;
var radius = width/2;
var back = height/10;
var t = 3.14 / 8;;
var rect = Rectangle {
x:10 y:10 width:100 height:100
effect: PerspectiveTransform {
ulx: radius - Math.sin(t)*radius uly: 0 - Math.cos(t)*back
urx: radius + Math.sin(t)*radius ury: 0 + Math.cos(t)*back
lrx: radius + Math.sin(t)*radius lry: height - Math.cos(t)*back
llx: radius - Math.sin(t)*radius lly: height + Math.cos(t)*back
}
onMouseMoved:function(e:MouseEvent):Void {
println(e);
}
onMousePressed:function(e:MouseEvent):Void {
println(e);
}
}
var localBounds = Rectangle {
x: bind rect.boundsInLocal.minX
y: bind rect.boundsInLocal.minY
width: bind rect.boundsInLocal.width
height: bind rect.boundsInLocal.height
fill: null
stroke: Color.RED
strokeWidth: 3
}
var layoutBounds = Rectangle {
x: bind rect.layoutBounds.minX
y: bind rect.layoutBounds.minY
width: bind rect.layoutBounds.width
height: bind rect.layoutBounds.height
fill: null
stroke: Color.GREEN
strokeWidth: 3
}
Scene {
width: 600
height: 450
content: [ rect, localBounds, layoutBounds ]
}
- relates to
-
JDK-8107324 coordinate translation methods such as Node's parentToLocal, sceneToLocal, localToParent, localToScene need to take geometry altering effects into account.
-
- Resolved
-
-
JDK-8105112 The bounding box of the text whose effect is a perspective transform returns a rect( x/y=0.0/0.0, w/h=0.0/0.0) during the animation
-
- Closed
-