Skip to content

Commit 7913834

Browse files
binstarjs03mmdanggg2
authored andcommitted
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
1 parent 45fa79f commit 7913834

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: src/org/jmc/gui/PreviewPanel.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class PreviewPanel extends JPanel implements MouseMotionListener, MouseWh
6363
/**
6464
* Offset of the map, as set by dragging the map around.
6565
*/
66-
private int shift_x,shift_y;
66+
private float shift_x,shift_y;
6767
/**
6868
* Zoom level of the map.
6969
*/
@@ -449,8 +449,8 @@ public Rectangle getChunkBounds()
449449
{
450450
Rectangle ret=new Rectangle();
451451

452-
ret.x=(-shift_x/64)-1;
453-
ret.y=(-shift_y/64)-1;
452+
ret.x=((int)-shift_x/64)-1;
453+
ret.y=((int)-shift_y/64)-1;
454454
ret.width=(int) Math.ceil((getWidth()/zoom_level)/64.0)+1;
455455
ret.height=(int) Math.ceil((getHeight()/zoom_level)/64.0)+1;
456456

@@ -771,8 +771,8 @@ public void mouseDragged(MouseEvent e) {
771771

772772
if(moving_map)
773773
{
774-
shift_x+=(x-last_x)/zoom_level;
775-
shift_y+=(y-last_y)/zoom_level;
774+
shift_x+=(float)(x-last_x)/zoom_level;
775+
shift_y+=(float)(y-last_y)/zoom_level;
776776

777777
last_x=x;
778778
last_y=y;

0 commit comments

Comments
 (0)