package com.fundynamic.d2tm.game.event;


import com.fundynamic.d2tm.game.drawing.Viewport;
import com.fundynamic.d2tm.game.math.Vector2D;

public class ViewportMovementListener extends AbstractMouseListener {

    public static final int PIXELS_NEAR_BORDER = 2;

    private final Viewport viewport;
    private final Vector2D screenResolution;

    public ViewportMovementListener(Viewport viewport, Vector2D screenResolution) {
        this.screenResolution = screenResolution;
        this.viewport = viewport;
    }

    @Override
    public void mouseWheelMoved(int change) {

    }

    @Override
    public void mouseClicked(int button, int x, int y, int clickCount) {

    }

    @Override
    public void mousePressed(int button, int x, int y) {

    }

    @Override
    public void mouseReleased(int button, int x, int y) {

    }

    @Override
    public void mouseMoved(int oldx, int oldy, int newx, int newy) {
        if (newx <= PIXELS_NEAR_BORDER) {
            viewport.moveLeft();
        } else if (newx >= screenResolution.getX() - PIXELS_NEAR_BORDER) {
            viewport.moveRight();
        } else {
            viewport.stopMovingHorizontally();
        }

        if (newy <= PIXELS_NEAR_BORDER) {
            viewport.moveUp();
        } else if (newy >= screenResolution.getY() - PIXELS_NEAR_BORDER) {
            viewport.moveDown();
        } else {
            viewport.stopMovingVertically();
        }
    }

    @Override
    public void mouseDragged(int oldx, int oldy, int newx, int newy) {

    }
}

@@ -321,32 +321,34 @@
 ector2D 
-screenResolut
+viewportDimens
 ion
+s
 ;%0A%0A    p
@@ -406,32 +406,34 @@
 ector2D 
-screenResolut
+viewportDimens
 ion
+s
 ) %7B%0A    
@@ -445,43 +445,47 @@
 his.
-screenResolut
+viewportDimens
 ion
+s
  = 
-screenResolut
+viewportDimens
 ion
+s
 ;%0A  
@@ -924,24 +924,79 @@
 int newy) %7B%0A
+        // Stefan: I think screenresolution should go%0A%0A
         if (
@@ -1085,32 +1085,34 @@
 newx %3E= 
-screenResolut
+viewportDimens
 ion
+s
 .getX() 
@@ -1348,24 +1348,26 @@
  %3E= 
-screenResolut
+viewportDimens
 ion
+s
 .get

rename to viewportDimensions because screenResolution happened to be the size of the viewport, but does not have to be.