diff --git a/src/sig/JavaProjectTemplate.java b/src/sig/JavaProjectTemplate.java index 5dc2096..b282d8e 100644 --- a/src/sig/JavaProjectTemplate.java +++ b/src/sig/JavaProjectTemplate.java @@ -5,6 +5,7 @@ import sig.engine.Color; import sig.engine.Font; import sig.engine.Key; import sig.engine.Mouse; +import sig.engine.MouseScrollValue; import sig.engine.Panel; import sig.engine.Point; import sig.engine.Sprite; @@ -58,6 +59,13 @@ public class JavaProjectTemplate { if (Mouse.isPressed(2)) { //If middle click is pressed, reset the player position. pl.x=pl.y=200; } + + if (Mouse.mouseWheel==MouseScrollValue.UP) { + System.out.println("Scroll up!"); + } + if (Mouse.mouseWheel==MouseScrollValue.DOWN) { + System.out.println("Scroll down!"); + } } public void drawGame() { diff --git a/src/sig/engine/Mouse.java b/src/sig/engine/Mouse.java index baaf780..c81cba2 100644 --- a/src/sig/engine/Mouse.java +++ b/src/sig/engine/Mouse.java @@ -9,6 +9,7 @@ public class Mouse { public static HashMap pressMap=new HashMap<>(); public static HashMap releaseMap=new HashMap<>(); public static Point mousePosition = new Point(0,0); + public static MouseScrollValue mouseWheel = MouseScrollValue.NONE; public static Point GetPos(){ return new Point(x,y); } diff --git a/src/sig/engine/MouseScrollValue.java b/src/sig/engine/MouseScrollValue.java index 0ecb90e..82721aa 100644 --- a/src/sig/engine/MouseScrollValue.java +++ b/src/sig/engine/MouseScrollValue.java @@ -1,8 +1,9 @@ package sig.engine; public enum MouseScrollValue { - UP(), //-1 is up - DOWN() /*1 is down*/; + UP, //-1 is up + DOWN, /*1 is down*/ + NONE /*Means no scrolling occurring.*/; public static MouseScrollValue getValue(int value) { return value==-1?UP:DOWN; diff --git a/src/sig/engine/Panel.java b/src/sig/engine/Panel.java index 276abc5..0714eab 100644 --- a/src/sig/engine/Panel.java +++ b/src/sig/engine/Panel.java @@ -49,7 +49,6 @@ public class Panel extends JPanel implements Runnable,KeyListener { public double nanaX = 0; public double nanaY = 0; public int button = 0; - private MouseScrollValue scrollWheel=null; public static final int UPDATE_LOOP_FRAMERATE = 244; public static final long UPDATE_LOOP_NANOTIME = (long)((1d/UPDATE_LOOP_FRAMERATE)*1000000000l); public static final double UPDATE_MULT = 1d / UPDATE_LOOP_FRAMERATE; @@ -101,6 +100,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { Mouse.releaseMap.clear(); Key.KEYS_PRESS.clear(); Key.KEYS_RELEASE.clear(); + Mouse.mouseWheel=MouseScrollValue.NONE; dt -= UPDATE_LOOP_NANOTIME; TIME += UPDATE_LOOP_NANOTIME; } @@ -181,7 +181,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { //-1 is UP, 1 is DOWN @Override public void mouseWheelMoved(MouseWheelEvent e) { - scrollWheel=MouseScrollValue.getValue(e.getWheelRotation()); + Mouse.mouseWheel=MouseScrollValue.getValue(e.getWheelRotation()); } }); }