update libgdx overriden classes

This commit is contained in:
Hannes Janetzek 2013-07-04 06:47:16 +02:00
parent a4bab81cfd
commit d7af6c76a6
3 changed files with 158 additions and 122 deletions

View File

@ -80,7 +80,7 @@ public abstract class GwtApplication implements EntryPoint, Application {
@Override @Override
public void onModuleLoad() { public void onModuleLoad() {
this.agentInfo = computeAgentInfo(); GwtApplication.agentInfo = computeAgentInfo();
this.listener = getApplicationListener(); this.listener = getApplicationListener();
this.config = getConfig(); this.config = getConfig();

View File

@ -25,13 +25,11 @@ import java.nio.ShortBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.GdxRuntimeException;
import com.google.gwt.canvas.client.Canvas;
import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.canvas.dom.client.ImageData;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.typedarrays.client.Uint8ArrayNative; import com.google.gwt.typedarrays.client.Uint8ArrayNative;
import com.google.gwt.typedarrays.shared.Float32Array; import com.google.gwt.typedarrays.shared.Float32Array;
@ -434,19 +432,10 @@ public class GwtGL20 implements GL20, org.oscim.backend.GL20{
Buffer pixels) { Buffer pixels) {
Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer)pixels).get(0)); Pixmap pixmap = Pixmap.pixmaps.get(((IntBuffer)pixels).get(0));
if (pixmap != null){ if (pixmap != null){
System.err.println("load texture "+ target + " "+ width + " " + height + " " + type + " " + format); Gdx.app.log("GwtGL20", "load texture "+ target + " "+ width + " " + height + " " + type + " " + format);
//Canvas canvasTmp = Canvas.createIfSupported();
//Context2d context = canvasTmp.getContext2d();
// canvasTmp.setCoordinateSpaceHeight(height);
// canvasTmp.setCoordinateSpaceWidth(width);
// context.drawImage(pixmap.getCanvasElement(), 0, 0);
// ImageData imageData = context.getImageData(0, 0, width, height);
//gl.texImage2D(target, level, internalformat, format, type, imageData);
gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement()); gl.texImage2D(target, level, internalformat, format, type, pixmap.getCanvasElement());
}else if (format == GL20.GL_ALPHA){ } else if (format == GL20.GL_ALPHA){
System.err.println("load byte texture " + width + " " + height + " " + type + " " + format); Gdx.app.log("GwtGL20", "load byte texture " + width + " " + height + " " + type + " " + format);
int tmp[] = new int[(width * height) >> 2]; int tmp[] = new int[(width * height) >> 2];
((IntBuffer)pixels).get(tmp); ((IntBuffer)pixels).get(tmp);

View File

@ -35,10 +35,12 @@ import com.google.gwt.dom.client.Touch;
import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyCodes;
public class GwtInput implements Input { public class GwtInput implements Input {
boolean touched = false;
int mouseX, mouseY;
int deltaX, deltaY;
boolean justTouched = false; boolean justTouched = false;
private boolean[] touched = new boolean[20];
private int[] touchX = new int[20];
private int[] touchY = new int[20];
private int[] deltaX = new int[20];
private int[] deltaY = new int[20];
Set<Integer> pressedButtons = new HashSet<Integer>(); Set<Integer> pressedButtons = new HashSet<Integer>();
Set<Integer> pressedKeys = new HashSet<Integer>(); Set<Integer> pressedKeys = new HashSet<Integer>();
InputProcessor processor; InputProcessor processor;
@ -70,55 +72,47 @@ public class GwtInput implements Input {
@Override @Override
public int getX() { public int getX() {
return mouseX; return touchX[0];
} }
@Override @Override
public int getX(int pointer) { public int getX(int pointer) {
if (pointer != 0) return touchX[pointer];
return 0;
return mouseX;
} }
@Override @Override
public int getDeltaX() { public int getDeltaX() {
return deltaX; return deltaX[0];
} }
@Override @Override
public int getDeltaX(int pointer) { public int getDeltaX(int pointer) {
if (pointer != 0) return deltaX[pointer];
return 0;
return deltaX;
} }
@Override @Override
public int getY() { public int getY() {
return mouseY; return touchY[0];
} }
@Override @Override
public int getY(int pointer) { public int getY(int pointer) {
if (pointer != 0) return touchY[pointer];
return 0;
return mouseY;
} }
@Override @Override
public int getDeltaY() { public int getDeltaY() {
return deltaY; return deltaY[0];
} }
@Override @Override
public int getDeltaY(int pointer) { public int getDeltaY(int pointer) {
if (pointer != 0) return deltaY[pointer];
return 0;
return deltaY;
} }
@Override @Override
public boolean isTouched() { public boolean isTouched() {
return touched; return touched[0];
} }
@Override @Override
@ -128,14 +122,12 @@ public class GwtInput implements Input {
@Override @Override
public boolean isTouched(int pointer) { public boolean isTouched(int pointer) {
if (pointer != 0) return touched[pointer];
return false;
return touched;
} }
@Override @Override
public boolean isButtonPressed(int button) { public boolean isButtonPressed(int button) {
return button == Buttons.LEFT && touched; return button == Buttons.LEFT && touched[0];
} }
@Override @Override
@ -254,7 +246,7 @@ public class GwtInput implements Input {
if (peripheral == Peripheral.HardwareKeyboard) if (peripheral == Peripheral.HardwareKeyboard)
return true; return true;
if (peripheral == Peripheral.MultitouchScreen) if (peripheral == Peripheral.MultitouchScreen)
return false; return isTouchScreen();
if (peripheral == Peripheral.OnscreenKeyboard) if (peripheral == Peripheral.OnscreenKeyboard)
return false; return false;
if (peripheral == Peripheral.Vibrator) if (peripheral == Peripheral.Vibrator)
@ -356,6 +348,10 @@ public class GwtInput implements Input {
return event.movementY || event.webkitMovementY || 0; return event.movementY || event.webkitMovementY || 0;
}-*/; }-*/;
private static native boolean isTouchScreen() /*-{
return (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
}-*/;
/** /**
* works only for Chrome > Version 18 with enabled Mouse Lock enable in * works only for Chrome > Version 18 with enabled Mouse Lock enable in
* about:flags or start Chrome with the * about:flags or start Chrome with the
@ -453,12 +449,11 @@ public class GwtInput implements Input {
addEventListener(Document.get(), "keydown", this, false); addEventListener(Document.get(), "keydown", this, false);
addEventListener(Document.get(), "keyup", this, false); addEventListener(Document.get(), "keyup", this, false);
addEventListener(Document.get(), "keypress", this, false); addEventListener(Document.get(), "keypress", this, false);
addEventListener(canvas, "touchstart", this, true); addEventListener(canvas, "touchstart", this, true);
addEventListener(Document.get(), "touchstart", this, true);
addEventListener(canvas, "touchend", this, true);
addEventListener(Document.get(), "touchend", this, true);
addEventListener(canvas, "touchmove", this, true); addEventListener(canvas, "touchmove", this, true);
addEventListener(Document.get(), "touchmove", this, true); addEventListener(canvas, "touchcancel", this, true);
addEventListener(canvas, "touchend", this, true);
} }
@ -474,46 +469,8 @@ public class GwtInput implements Input {
private void handleEvent(NativeEvent e) { private void handleEvent(NativeEvent e) {
double r = GwtGraphics.getDevicePixelRatioJSNI(); if (e.getType().equals("mousedown")) {
if (!e.getEventTarget().equals(canvas) || touched[0]) {
if (e.getType().equals("touchstart")) {
this.justTouched = true;
this.deltaX = 0;
this.deltaY = 0;
this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) {
e.preventDefault();
JsArray<Touch> ts = e.getChangedTouches();
for (int i = 0, n = ts.length(); i < n; i++) {
Touch t = ts.get(i);
processor.touchDown((int)(r * t.getClientX()), (int) (r * t.getClientY()), t.getIdentifier(),
Buttons.LEFT);
}
}
} else if (e.getType().equals("touchend")) {
this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) {
e.preventDefault();
JsArray<Touch> ts = e.getChangedTouches();
for (int i = 0, n = ts.length(); i < n; i++) {
Touch t = ts.get(i);
processor.touchUp((int)(r * t.getClientX()), (int) (r * t.getClientY()), t.getIdentifier(),
Buttons.LEFT);
}
}
} else if (e.getType().equals("touchmove")) {
this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) {
e.preventDefault();
JsArray<Touch> ts = e.getChangedTouches();
for (int i = 0, n = ts.length(); i < n; i++) {
Touch t = ts.get(i);
processor.touchDragged((int)(r * t.getClientX()), (int) (r * t.getClientY()), t.getIdentifier());
}
}
} else if (e.getType().equals("mousedown")) {
if (!e.getEventTarget().equals(canvas) || touched) {
float mouseX = (int) getRelativeX(e, canvas); float mouseX = (int) getRelativeX(e, canvas);
float mouseY = (int) getRelativeY(e, canvas); float mouseY = (int) getRelativeY(e, canvas);
if (mouseX < 0 || mouseX > Gdx.graphics.getWidth() || mouseY < 0 if (mouseX < 0 || mouseX > Gdx.graphics.getWidth() || mouseY < 0
@ -524,60 +481,66 @@ public class GwtInput implements Input {
} }
hasFocus = true; hasFocus = true;
this.justTouched = true; this.justTouched = true;
this.touched = true; this.touched[0] = true;
this.pressedButtons.add(getButton(e.getButton())); this.pressedButtons.add(getButton(e.getButton()));
this.deltaX = 0; this.deltaX[0] = 0;
this.deltaY = 0; this.deltaY[0] = 0;
if (isCursorCatched()) { if (isCursorCatched()) {
this.mouseX += getMovementXJSNI(e); this.touchX[0] += getMovementXJSNI(e);
this.mouseY += getMovementYJSNI(e); this.touchY[0] += getMovementYJSNI(e);
} else { } else {
this.mouseX = (int) getRelativeX(e, canvas); this.touchX[0] = (int) getRelativeX(e, canvas);
this.mouseY = (int) getRelativeY(e, canvas); this.touchY[0] = (int) getRelativeY(e, canvas);
} }
this.currentEventTimeStamp = TimeUtils.nanoTime(); this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) if (processor != null)
processor.touchDown(mouseX, mouseY, 0, getButton(e.getButton())); processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton()));
} else if (e.getType().equals("mousemove")) { }
if (e.getType().equals("mousemove")) {
if (isCursorCatched()) { if (isCursorCatched()) {
this.deltaX = (int) getMovementXJSNI(e); this.deltaX[0] = (int) getMovementXJSNI(e);
this.deltaY = (int) getMovementYJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e);
this.mouseX += getMovementXJSNI(e); this.touchX[0] += getMovementXJSNI(e);
this.mouseY += getMovementYJSNI(e); this.touchY[0] += getMovementYJSNI(e);
} else { } else {
this.deltaX = (int) getRelativeX(e, canvas) - mouseX; this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
this.deltaY = (int) getRelativeY(e, canvas) - mouseY; this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
this.mouseX = (int) getRelativeX(e, canvas); this.touchX[0] = (int) getRelativeX(e, canvas);
this.mouseY = (int) getRelativeY(e, canvas); this.touchY[0] = (int) getRelativeY(e, canvas);
} }
this.currentEventTimeStamp = TimeUtils.nanoTime(); this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) { if (processor != null) {
if (touched) if (touched[0])
processor.touchDragged(mouseX, mouseY, 0); processor.touchDragged(touchX[0], touchY[0], 0);
else else
processor.mouseMoved(mouseX, mouseY); processor.mouseMoved(touchX[0], touchY[0]);
} }
} else if (e.getType().equals("mouseup")) { }
if (!touched)
if (e.getType().equals("mouseup")) {
if (!touched[0])
return; return;
this.pressedButtons.remove(getButton(e.getButton())); this.pressedButtons.remove(getButton(e.getButton()));
this.touched = pressedButtons.size() > 0; this.touched[0] = pressedButtons.size() > 0;
if (isCursorCatched()) { if (isCursorCatched()) {
this.deltaX = (int) getMovementXJSNI(e); this.deltaX[0] = (int) getMovementXJSNI(e);
this.deltaY = (int) getMovementYJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e);
this.mouseX += getMovementXJSNI(e); this.touchX[0] += getMovementXJSNI(e);
this.mouseY += getMovementYJSNI(e); this.touchY[0] += getMovementYJSNI(e);
} else { } else {
this.deltaX = (int) getRelativeX(e, canvas) - mouseX; this.deltaX[0] = (int) getRelativeX(e, canvas) - touchX[0];
this.deltaY = (int) getRelativeY(e, canvas) - mouseY; this.deltaY[0] = (int) getRelativeY(e, canvas) - touchY[0];
this.mouseX = (int) getRelativeX(e, canvas); this.touchX[0] = (int) getRelativeX(e, canvas);
this.mouseY = (int) getRelativeY(e, canvas); this.touchY[0] = (int) getRelativeY(e, canvas);
} }
this.currentEventTimeStamp = TimeUtils.nanoTime(); this.currentEventTimeStamp = TimeUtils.nanoTime();
this.touched = false; this.touched[0] = false;
if (processor != null) if (processor != null)
processor.touchUp(mouseX, mouseY, 0, getButton(e.getButton())); processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton()));
} else if (e.getType().equals("keydown") && hasFocus) { }
if (e.getType().equals("keydown") && hasFocus) {
System.out.println("keydown"); System.out.println("keydown");
int code = keyForCode(e.getKeyCode()); int code = keyForCode(e.getKeyCode());
if (code == 67) { if (code == 67) {
@ -591,17 +554,102 @@ public class GwtInput implements Input {
if (processor != null) if (processor != null)
processor.keyDown(code); processor.keyDown(code);
} }
} else if (e.getType().equals("keypress") && hasFocus) { }
if (e.getType().equals("keypress") && hasFocus) {
System.out.println("keypress"); System.out.println("keypress");
char c = (char) e.getCharCode(); char c = (char) e.getCharCode();
if (processor != null) if (processor != null)
processor.keyTyped(c); processor.keyTyped(c);
} else if (e.getType().equals("keyup") && hasFocus) { }
if (e.getType().equals("keyup") && hasFocus) {
System.out.println("keyup"); System.out.println("keyup");
int code = keyForCode(e.getKeyCode()); int code = keyForCode(e.getKeyCode());
this.pressedKeys.remove(code); this.pressedKeys.remove(code);
if (processor != null) if (processor != null)
processor.keyUp(code); processor.keyUp(code);
}
if (e.getType().equals("touchstart")) {
this.justTouched = true;
JsArray<Touch> touches = e.getChangedTouches();
for (int i = 0, j = touches.length(); i < j; i++) {
Touch touch = touches.get(i);
int touchId = touch.getIdentifier();
touched[touchId] = true;
double r = GwtGraphics.getDevicePixelRatioJSNI();
int x = (int) (touch.getRelativeX(canvas) * r);
int y = (int) (touch.getRelativeY(canvas) * r);
touchX[touchId] = x;
touchY[touchId] = y;
deltaX[touchId] = 0;
deltaY[touchId] = 0;
if (processor != null) {
processor.touchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
}
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
e.preventDefault();
}
if (e.getType().equals("touchmove")) {
JsArray<Touch> touches = e.getChangedTouches();
for (int i = 0, j = touches.length(); i < j; i++) {
Touch touch = touches.get(i);
int touchId = touch.getIdentifier();
double r = GwtGraphics.getDevicePixelRatioJSNI();
int x = (int) (touch.getRelativeX(canvas) * r);
int y = (int) (touch.getRelativeY(canvas) * r);
deltaX[touchId] = x - touchX[touchId];
deltaY[touchId] = y - touchY[touchId];
touchX[touchId] = x;
touchY[touchId] = y;
if (processor != null) {
processor.touchDragged(touchX[touchId], touchY[touchId], touchId);
}
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
e.preventDefault();
}
if (e.getType().equals("touchcancel")) {
JsArray<Touch> touches = e.getChangedTouches();
for (int i = 0, j = touches.length(); i < j; i++) {
Touch touch = touches.get(i);
int touchId = touch.getIdentifier();
touched[touchId] = false;
double r = GwtGraphics.getDevicePixelRatioJSNI();
int x = (int) (touch.getRelativeX(canvas) * r);
int y = (int) (touch.getRelativeY(canvas) * r);
deltaX[touchId] = x - touchX[touchId];
deltaY[touchId] = y - touchY[touchId];
touchX[touchId] = x;
touchY[touchId] = y;
if (processor != null) {
processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
}
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
e.preventDefault();
}
if (e.getType().equals("touchend")) {
JsArray<Touch> touches = e.getChangedTouches();
for (int i = 0, j = touches.length(); i < j; i++) {
Touch touch = touches.get(i);
int touchId = touch.getIdentifier();
touched[touchId] = false;
double r = GwtGraphics.getDevicePixelRatioJSNI();
int x = (int) (touch.getRelativeX(canvas) * r);
int y = (int) (touch.getRelativeY(canvas) * r);
deltaX[touchId] = x - touchX[touchId];
deltaY[touchId] = y - touchY[touchId];
touchX[touchId] = x;
touchY[touchId] = y;
if (processor != null) {
processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT);
}
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
e.preventDefault();
} else if (e.getType().equals("mousewheel") || e.getType().equals("DOMMouseScroll")) { } else if (e.getType().equals("mousewheel") || e.getType().equals("DOMMouseScroll")) {
float dir = getMouseWheelVelocity(e); float dir = getMouseWheelVelocity(e);
@ -609,7 +657,6 @@ public class GwtInput implements Input {
processor.scrolled(dir > 0 ? 1 : -1); processor.scrolled(dir > 0 ? 1 : -1);
} }
// if(hasFocus) e.preventDefault(); // if(hasFocus) e.preventDefault();
} }