java - JavaFX center view on cursor position -


i created first javafx app displays images. want zoom image full size on mouse down (centered on cursor position) , refit image on mouse up.

all working fine don't know how center on cursor position. zoom method looks @ moment:

private void zoom100(double cursorx, double cursory){     double centery = imageview.getlayoutbounds().getheight()/2;     double centerx = imageview.getlayoutbounds().getwidth()/2;     imageview.setfitheight(-1); //zooms height 100%     imageview.setfitwidth(-1); //zooms width 100%     imageview.settranslatex(centerx-cursorx); //moves x      imageview.settranslatey(centery-cursory); //moves y } 

my idea set offset translate. not sure if translate correct approach. if correct approach how calculate correct values? (centerx-cursorx) wrong!

i uploaded code here: https://github.com/dermoritz/fastimageviewer (it working - see answer)

i didn't test think order wrong. calculate center before set fit size. setting fit size image view change it's preferred size. therefore center point won't match anymore.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -