diff --git a/src/ei/engine/input/Input.java b/src/ei/engine/input/Input.java new file mode 100644 index 0000000..d29dd0d --- /dev/null +++ b/src/ei/engine/input/Input.java @@ -0,0 +1,44 @@ +package ei.engine.input; + + +public abstract class Input{ + // The name of this input + private String name; + // is this input enabled + private boolean enabled; + + public Input(String name){ + this.enabled = true; + InputHandler.getInstance().addInput(this); + } + + /** + * @return The name of the entity + */ + public String getName() { + return name; + } + + /** + * returns if this input is enabled + * + * @return if this input is enabled + */ + public boolean isEnabled(){ + return enabled; + } + + /** + * Set if this input is enabled + * + * @param b if this input is enabled + */ + public void setEnabled(boolean b){ + enabled = b; + } + + + public abstract void update(); + + public abstract void render(); +} diff --git a/src/ei/engine/input/InputHandler.java b/src/ei/engine/input/InputHandler.java new file mode 100644 index 0000000..f894c4a --- /dev/null +++ b/src/ei/engine/input/InputHandler.java @@ -0,0 +1,110 @@ +package ei.engine.input; + +import java.util.ArrayList; + +/** + * This class handels all the input in the engine + * + * @author Ziver + */ + +public class InputHandler { + // The instance of this handler + private static InputHandler instance; + // The array of inputs + private ArrayList input; + + public InputHandler(){ + input = new ArrayList(); + } + + /** + * updates all the inputs + * + */ + public void update(){ + for(int i=0; i= 0 && i < input.size()){ + input.remove(i); + return true; + } + return false; + } + + /** + * Remove a input by name + * + * @param name The name of the input to remove + * @return true if successful else false + */ + public boolean removeInput(String name){ + for(int i=0; i LWJGLGameWindow.getWidth()) { + cursorX = LWJGLGameWindow.getWidth(); + } + if (cursorY < 0) { + cursorY = 0; + } + else if (cursorY > LWJGLGameWindow.getHeight()) { + cursorY = LWJGLGameWindow.getHeight(); + } + mouseMove(cursorX,cursorY); + } + + while ( Mouse.next() ) { + if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == true) { + mouseDown(cursorX, cursorY); + } + if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == false) { + mouseUp(cursorX, cursorY); + } + } + + if(cursor != null){ + cursor.setLocation(new Vector2f(cursorX, cursorY)); + } + } + + /** + * Called by update() when mouse moves + */ + public abstract void mouseMove(int x, int y); + + /** + * Called by update() when mouse button is pressed + */ + public abstract void mouseDown(int x, int y); + + /** + * Called by update() when mouse button is released + */ + public abstract void mouseUp(int x, int y); + +}