From 4d830b1623c295892e9b73217f17fcfab11125a3 Mon Sep 17 00:00:00 2001 From: Bintang Jakasurya <93080026+binstarjs03@users.noreply.github.com> Date: Sun, 13 Nov 2022 11:54:08 +0700 Subject: [PATCH] Fix preview panel dragging experience Preview panel dragging is clunky if zoom level above 1. The higher the zoom level, the worser it is. This issue fixed by changing datatype that shifting the chunk position in preview panel from int to float. This happens probably rounding error and such --- src/org/jmc/gui/PreviewPanel.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/jmc/gui/PreviewPanel.java b/src/org/jmc/gui/PreviewPanel.java index 02ebccc..518d54a 100644 --- a/src/org/jmc/gui/PreviewPanel.java +++ b/src/org/jmc/gui/PreviewPanel.java @@ -63,7 +63,7 @@ public class PreviewPanel extends JPanel implements MouseMotionListener, MouseWh /** * Offset of the map, as set by dragging the map around. */ - private int shift_x,shift_y; + private float shift_x,shift_y; /** * Zoom level of the map. */ @@ -449,8 +449,8 @@ public Rectangle getChunkBounds() { Rectangle ret=new Rectangle(); - ret.x=(-shift_x/64)-1; - ret.y=(-shift_y/64)-1; + ret.x=((int)-shift_x/64)-1; + ret.y=((int)-shift_y/64)-1; ret.width=(int) Math.ceil((getWidth()/zoom_level)/64.0)+1; ret.height=(int) Math.ceil((getHeight()/zoom_level)/64.0)+1; @@ -771,8 +771,8 @@ public void mouseDragged(MouseEvent e) { if(moving_map) { - shift_x+=(x-last_x)/zoom_level; - shift_y+=(y-last_y)/zoom_level; + shift_x+=(float)(x-last_x)/zoom_level; + shift_y+=(float)(y-last_y)/zoom_level; last_x=x; last_y=y;