Skip to content

Commit

Permalink
Merge some slick2d changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Jan 8, 2017
1 parent 41a27fe commit 0867114
Showing 3 changed files with 16 additions and 13 deletions.
12 changes: 7 additions & 5 deletions src/org/newdawn/slick/Input.java
Original file line number Diff line number Diff line change
@@ -633,6 +633,7 @@ public void removeListener(InputListener listener) {
*/
public void removeKeyListener(KeyListener listener) {
keyListeners.remove(listener);
keyListenersToAdd.remove(listener);

if (!mouseListeners.contains(listener) && !controllerListeners.contains(listener)) {
allListeners.remove(listener);
@@ -659,6 +660,7 @@ public void removeControllerListener(ControllerListener listener) {
*/
public void removeMouseListener(MouseListener listener) {
mouseListeners.remove(listener);
mouseListenersToAdd.remove(listener);

if (!controllerListeners.contains(listener) && !keyListeners.contains(listener)) {
allListeners.remove(listener);
@@ -798,7 +800,7 @@ public int getAbsoluteMouseX() {
* @return The absolute y position of the mouse cursor
*/
public int getAbsoluteMouseY() {
return height - Mouse.getY();
return height - Mouse.getY() - 1;
}

/**
@@ -807,7 +809,7 @@ public int getAbsoluteMouseY() {
* @return The x position of the mouse cursor
*/
public int getMouseX() {
return (int) ((Mouse.getX() * scaleX)+xoffset);
return (int) ((getAbsoluteMouseX() * scaleX)+xoffset);
}

/**
@@ -816,7 +818,7 @@ public int getMouseX() {
* @return The y position of the mouse cursor
*/
public int getMouseY() {
return (int) (((height-Mouse.getY()) * scaleY)+yoffset);
return (int) ((getAbsoluteMouseY() * scaleY)+yoffset);
}

/**
@@ -1239,7 +1241,7 @@ public void poll(int width, int height) {
mousePressed[Mouse.getEventButton()] = true;

pressedX = (int) (xoffset + (Mouse.getEventX() * scaleX));
pressedY = (int) (yoffset + ((height-Mouse.getEventY()) * scaleY));
pressedY = (int) (yoffset + ((height-Mouse.getEventY()-1) * scaleY));
lastMouseX = pressedX;
lastMouseY = pressedY;

@@ -1257,7 +1259,7 @@ public void poll(int width, int height) {
mousePressed[Mouse.getEventButton()] = false;

int releasedX = (int) (xoffset + (Mouse.getEventX() * scaleX));
int releasedY = (int) (yoffset + ((height-Mouse.getEventY()) * scaleY));
int releasedY = (int) (yoffset + ((height-Mouse.getEventY()-1) * scaleY));
if ((pressedX != -1) &&
(pressedY != -1) &&
(Math.abs(pressedX - releasedX) < mouseClickTolerance) &&
2 changes: 1 addition & 1 deletion src/org/newdawn/slick/Music.java
Original file line number Diff line number Diff line change
@@ -455,7 +455,7 @@ void update(int delta) {
}
if (fadeTime > 0) {
fadeTime -= delta;
if (fadeTime < 0) {
if (fadeTime <= 0) {
fadeTime = 0;
if (stopAfterFade) {
stop();
15 changes: 8 additions & 7 deletions src/org/newdawn/slick/gui/TextField.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
package org.newdawn.slick.gui;

import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.newdawn.slick.Color;
import org.newdawn.slick.Font;
import org.newdawn.slick.Graphics;
@@ -502,7 +503,13 @@ public void keyPressed(int key, char c) {
if (consume) {
container.getInput().consumeEvent();
}
} else if ((c < 127) && (c > 31) && (value.length() < maxCharacter)) {
} else if (key == Input.KEY_RETURN) {
notifyListeners();
// Nobody more will be notified
if (consume) {
container.getInput().consumeEvent();
}
} else if (c != Keyboard.CHAR_NONE && key != Input.KEY_TAB && value.length() < maxCharacter) {
if (cursorPos < value.length()) {
value = value.substring(0, cursorPos) + c
+ value.substring(cursorPos);
@@ -514,12 +521,6 @@ public void keyPressed(int key, char c) {
if (consume) {
container.getInput().consumeEvent();
}
} else if (key == Input.KEY_RETURN) {
notifyListeners();
// Nobody more will be notified
if (consume) {
container.getInput().consumeEvent();
}
}

}

0 comments on commit 0867114

Please # to comment.