java - JavaFX pannable GridPane -
for current project, need large grid transparent background 1 can zoom , pan across. tried use scrollpane
setpannable(true)
, discovered scrollpane background remain opague when call setstyle("-fx-background-color: transparent")
or setstyle("-fx-background: transparent")
. easy option eliminated, need make gridpane in question directly pannable.
i've tried several things already, including trying bind mouse position gridpane
's translate property(which quite didn't work), , failed more promising alternative work properly:
gridpane gridview = new gridpane(); int x; int y; gridview.setondragentered( (event) -> { x = event.getx(); y = event.gety(); }); gridview.setondragdetected( (event) -> { gridview.settranslatex(x - event.getx()); gridview.settranslatey(y - event.gety()); });
however, makes map jump , left, rather make pan mouse intended.
managed figure out. 1 remaining problem gridpane
rather jittery when panned, it's @ acceptable level now.
int x = 0; int y = 0; gridview.setonmousedragged((event) -> { if(x != 0){ //prevent panning before values initialized gridview.settranslatex( gridview.gettranslatex() + limit(event.getx() - x, 25)); gridview.settranslatey( gridview.gettranslatey() + limit(event.gety() - y, 25)); } x = (int)event.getx(); y = (int)event.gety(); });
where limit(double num, double limit)
method limits input num range [-limit, limit]. reducing limit decreases jitter, @ expense of decreasing responsiveness well.
Comments
Post a Comment