Improve code / xml formatting #54

This commit is contained in:
Emux 2016-11-20 19:26:38 +02:00
parent 308497ffa6
commit 3388e1401f
4 changed files with 521 additions and 435 deletions

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -55,10 +55,13 @@ import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
/** Implementation of an {@link Application} based on GWT. Clients have to override {@link #getConfig()} and
/**
* Implementation of an {@link Application} based on GWT. Clients have to override {@link #getConfig()} and
* {@link #createApplicationListener()}. Clients can override the default loading screen via
* {@link #getPreloaderCallback()} and implement any loading screen drawing via GWT widgets.
* @author mzechner */
*
* @author mzechner
*/
public abstract class GwtApplication implements EntryPoint, Application {
private ApplicationListener listener;
GwtApplicationConfiguration config;
@ -79,12 +82,13 @@ public abstract class GwtApplication implements EntryPoint, Application {
private Clipboard clipboard;
LoadingListener loadingListener;
/** @return the configuration for the {@link GwtApplication}. */
/**
* @return the configuration for the {@link GwtApplication}.
*/
public abstract GwtApplicationConfiguration getConfig();
public String getPreloaderBaseURL()
{
public String getPreloaderBaseURL() {
return GWT.getHostPageBaseURL() + "assets/";
}
@ -455,13 +459,17 @@ public abstract class GwtApplication implements EntryPoint, Application {
public void exit() {
}
/** Contains precomputed information on the user-agent. Useful for dealing with browser and OS behavioral differences. Kindly
* borrowed from PlayN */
/**
* Contains precomputed information on the user-agent. Useful for dealing with browser and OS behavioral differences. Kindly
* borrowed from PlayN
*/
public static AgentInfo agentInfo() {
return agentInfo;
}
/** kindly borrowed from PlayN **/
/**
* kindly borrowed from PlayN
**/
private static native AgentInfo computeAgentInfo() /*-{
var userAgent = navigator.userAgent.toLowerCase();
return {
@ -478,7 +486,9 @@ public abstract class GwtApplication implements EntryPoint, Application {
};
}-*/;
/** Returned by {@link #agentInfo}. Kindly borrowed from PlayN. */
/**
* Returned by {@link #agentInfo}. Kindly borrowed from PlayN.
*/
public static class AgentInfo extends JavaScriptObject {
public final native boolean isFirefox() /*-{
return this.isFirefox;

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -296,8 +296,11 @@ public class GwtInput implements Input {
return Orientation.Landscape;
}
/** from https://github.com/toji/game-shim/blob/master/game-shim.js
* @return is Cursor catched */
/**
* from https://github.com/toji/game-shim/blob/master/game-shim.js
*
* @return is Cursor catched
*/
private native boolean isCursorCatchedJSNI() /*-{
if (!navigator.pointer) {
navigator.pointer = navigator.webkitPointer || navigator.mozPointer;
@ -317,8 +320,11 @@ public class GwtInput implements Input {
return false;
}-*/;
/** from https://github.com/toji/game-shim/blob/master/game-shim.js
* @param element Canvas */
/**
* from https://github.com/toji/game-shim/blob/master/game-shim.js
*
* @param element Canvas
*/
private native void setCursorCatchedJSNI(CanvasElement element) /*-{
// Navigator pointer is not the right interface according to spec.
// Here for backwards compatibility only
@ -339,7 +345,9 @@ public class GwtInput implements Input {
element.requestPointerLock();
}-*/;
/** from https://github.com/toji/game-shim/blob/master/game-shim.js */
/**
* from https://github.com/toji/game-shim/blob/master/game-shim.js
*/
private native void exitCursorCatchedJSNI() /*-{
if (!$doc.exitPointerLock) {
$doc.exitPointerLock = (function() {
@ -354,16 +362,22 @@ public class GwtInput implements Input {
}
}-*/;
/** from https://github.com/toji/game-shim/blob/master/game-shim.js
/**
* from https://github.com/toji/game-shim/blob/master/game-shim.js
*
* @param event JavaScript Mouse Event
* @return movement in x direction */
* @return movement in x direction
*/
private native float getMovementXJSNI(NativeEvent event) /*-{
return event.movementX || event.webkitMovementX || 0;
}-*/;
/** from https://github.com/toji/game-shim/blob/master/game-shim.js
/**
* from https://github.com/toji/game-shim/blob/master/game-shim.js
*
* @param event JavaScript Mouse Event
* @return movement in y direction */
* @return movement in y direction
*/
private native float getMovementYJSNI(NativeEvent event) /*-{
return event.movementY || event.webkitMovementY || 0;
}-*/;
@ -372,8 +386,10 @@ public class GwtInput implements Input {
return (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0));
}-*/;
/** works only for Chrome > Version 18 with enabled Mouse Lock enable in about:flags or start Chrome with the
* --enable-pointer-lock flag */
/**
* works only for Chrome > Version 18 with enabled Mouse Lock enable in about:flags or start Chrome with the
* --enable-pointer-lock flag
*/
@Override
public void setCursorCatched(boolean catched) {
if (catched)
@ -433,7 +449,9 @@ public class GwtInput implements Input {
return delta;
}-*/;
/** Kindly borrowed from PlayN. **/
/**
* Kindly borrowed from PlayN.
**/
protected static native String getMouseWheelEvent() /*-{
if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
return "DOMMouseScroll";
@ -442,14 +460,18 @@ public class GwtInput implements Input {
}
}-*/;
/** Kindly borrowed from PlayN. **/
/**
* Kindly borrowed from PlayN.
**/
protected int getRelativeX(NativeEvent e, CanvasElement target) {
float xScaleRatio = target.getWidth() * 1f / target.getClientWidth(); // Correct for canvas CSS scaling
return Math.round(xScaleRatio
* (e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() + target.getOwnerDocument().getScrollLeft()));
}
/** Kindly borrowed from PlayN. **/
/**
* Kindly borrowed from PlayN.
**/
protected int getRelativeY(NativeEvent e, CanvasElement target) {
float yScaleRatio = target.getHeight() * 1f / target.getClientHeight(); // Correct for canvas CSS scaling
return Math.round(yScaleRatio
@ -519,7 +541,8 @@ public class GwtInput implements Input {
this.touchY[0] = getRelativeY(e, canvas);
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
if (processor != null) processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton()));
if (processor != null)
processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton()));
}
if (e.getType().equals("mousemove")) {
@ -560,7 +583,8 @@ public class GwtInput implements Input {
}
this.currentEventTimeStamp = TimeUtils.nanoTime();
this.touched[0] = false;
if (processor != null) processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton()));
if (processor != null)
processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton()));
}
if (e.getType().equals(getMouseWheelEvent())) {
if (processor != null) {
@ -694,7 +718,9 @@ public class GwtInput implements Input {
return -1;
}
/** borrowed from PlayN, thanks guys **/
/**
* borrowed from PlayN, thanks guys
**/
private static int keyForCode(int keyCode) {
switch (keyCode) {
case KeyCodes.KEY_ALT:

View File

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,11 +16,6 @@
package com.badlogic.gdx.graphics;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;
import com.badlogic.gdx.backends.gwt.GwtFileHandle;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.BufferUtils;
@ -33,13 +28,20 @@ import com.google.gwt.canvas.dom.client.Context2d.Composite;
import com.google.gwt.dom.client.CanvasElement;
import com.google.gwt.dom.client.ImageElement;
import java.nio.Buffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;
public class Pixmap implements Disposable {
public static Map<Integer, Pixmap> pixmaps = new HashMap<Integer, Pixmap>();
static int nextId = 0;
/** Different pixel formats.
/**
* Different pixel formats.
*
* @author mzechner */
* @author mzechner
*/
public enum Format {
Alpha, Intensity, LuminanceAlpha, RGB565, RGBA4444, RGB888, RGBA8888;
@ -66,15 +68,20 @@ public class Pixmap implements Disposable {
}
}
/** Blending functions to be set with {@link Pixmap#setBlending}.
* @author mzechner */
/**
* Blending functions to be set with {@link Pixmap#setBlending}.
*
* @author mzechner
*/
public enum Blending {
None, SourceOver
}
/** Filters to be used with {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
/**
* Filters to be used with {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
*
* @author mzechner */
* @author mzechner
*/
public enum Filter {
NearestNeighbour, BiLinear
}
@ -96,7 +103,8 @@ public class Pixmap implements Disposable {
public Pixmap(FileHandle file) {
this(((GwtFileHandle) file).preloader.images.get(file.path()));
if (imageElement == null) throw new GdxRuntimeException("Couldn't load image '" + file.path() + "', file does not exist");
if (imageElement == null)
throw new GdxRuntimeException("Couldn't load image '" + file.path() + "', file does not exist");
}
public Context2d getContext() {
@ -139,8 +147,11 @@ public class Pixmap implements Disposable {
return "rgba(" + r2 + "," + g2 + "," + b2 + "," + a2 + ")";
}
/** Sets the type of {@link Blending} to be used for all operations. Default is {@link Blending#SourceOver}.
* @param blending the blending type */
/**
* Sets the type of {@link Blending} to be used for all operations. Default is {@link Blending#SourceOver}.
*
* @param blending the blending type
*/
public static void setBlending(Blending blending) {
Pixmap.blending = blending;
Composite composite = getComposite();
@ -150,14 +161,19 @@ public class Pixmap implements Disposable {
}
}
/** @return the currently set {@link Blending} */
/**
* @return the currently set {@link Blending}
*/
public static Blending getBlending() {
return blending;
}
/** Sets the type of interpolation {@link Filter} to be used in conjunction with
/**
* Sets the type of interpolation {@link Filter} to be used in conjunction with
* {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
* @param filter the filter. */
*
* @param filter the filter.
*/
public static void setFilter(Filter filter) {
}
@ -218,8 +234,11 @@ public class Pixmap implements Disposable {
return imageElement;
}
/** Sets the color for the following drawing operations
* @param color the color, encoded as RGBA8888 */
/**
* Sets the color for the following drawing operations
*
* @param color the color, encoded as RGBA8888
*/
public void setColor(int color) {
ensureCanvasExists();
r = (color >>> 24) & 0xff;
@ -231,12 +250,14 @@ public class Pixmap implements Disposable {
context.setStrokeStyle(this.color);
}
/** Sets the color for the following drawing operations.
/**
* Sets the color for the following drawing operations.
*
* @param r The red component.
* @param g The green component.
* @param b The blue component.
* @param a The alpha component. */
* @param a The alpha component.
*/
public void setColor(float r, float g, float b, float a) {
ensureCanvasExists();
this.r = (int) (r * 255);
@ -248,13 +269,18 @@ public class Pixmap implements Disposable {
context.setStrokeStyle(this.color);
}
/** Sets the color for the following drawing operations.
* @param color The color. */
/**
* Sets the color for the following drawing operations.
*
* @param color The color.
*/
public void setColor(Color color) {
setColor(color.r, color.g, color.b, color.a);
}
/** Fills the complete bitmap with the currently set color. */
/**
* Fills the complete bitmap with the currently set color.
*/
public void fill() {
ensureCanvasExists();
context.clearRect(0, 0, getWidth(), getHeight());
@ -268,38 +294,45 @@ public class Pixmap implements Disposable {
// */
// public void setStrokeWidth (int width);
/** Draws a line between the given coordinates using the currently set color.
/**
* Draws a line between the given coordinates using the currently set color.
*
* @param x The x-coodinate of the first point
* @param y The y-coordinate of the first point
* @param x2 The x-coordinate of the first point
* @param y2 The y-coordinate of the first point */
* @param y2 The y-coordinate of the first point
*/
public void drawLine(int x, int y, int x2, int y2) {
line(x, y, x2, y2, DrawType.STROKE);
}
/** Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards)
/**
* Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards)
* using the current color.
*
* @param x The x coordinate
* @param y The y coordinate
* @param width The width in pixels
* @param height The height in pixels */
* @param height The height in pixels
*/
public void drawRectangle(int x, int y, int width, int height) {
rectangle(x, y, width, height, DrawType.STROKE);
}
/** Draws an area form another Pixmap to this Pixmap.
/**
* Draws an area form another Pixmap to this Pixmap.
*
* @param pixmap The other Pixmap
* @param x The target x-coordinate (top left corner)
* @param y The target y-coordinate (top left corner) */
* @param y The target y-coordinate (top left corner)
*/
public void drawPixmap(Pixmap pixmap, int x, int y) {
CanvasElement image = pixmap.getCanvasElement();
image(image, 0, 0, image.getWidth(), image.getHeight(), x, y, image.getWidth(), image.getHeight());
}
/** Draws an area form another Pixmap to this Pixmap.
/**
* Draws an area form another Pixmap to this Pixmap.
*
* @param pixmap The other Pixmap
* @param x The target x-coordinate (top left corner)
@ -307,13 +340,15 @@ public class Pixmap implements Disposable {
* @param srcx The source x-coordinate (top left corner)
* @param srcy The source y-coordinate (top left corner);
* @param srcWidth The width of the area form the other Pixmap in pixels
* @param srcHeight The height of the area form the other Pixmap in pixles */
* @param srcHeight The height of the area form the other Pixmap in pixles
*/
public void drawPixmap(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) {
CanvasElement image = pixmap.getCanvasElement();
image(image, srcx, srcy, srcWidth, srcHeight, x, y, srcWidth, srcHeight);
}
/** Draws an area form another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the
/**
* Draws an area form another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the
* specified target rectangle. Use {@link Pixmap#setFilter(Filter)} to specify the type of filtering to be used (nearest
* neighbour or bilinear).
*
@ -325,58 +360,69 @@ public class Pixmap implements Disposable {
* @param dstx The target x-coordinate (top left corner)
* @param dsty The target y-coordinate (top left corner)
* @param dstWidth The target width
* @param dstHeight the target height */
* @param dstHeight the target height
*/
public void drawPixmap(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth,
int dstHeight) {
image(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
}
/** Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using
/**
* Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using
* the current color.
*
* @param x The x coordinate
* @param y The y coordinate
* @param width The width in pixels
* @param height The height in pixels */
* @param height The height in pixels
*/
public void fillRectangle(int x, int y, int width, int height) {
rectangle(x, y, width, height, DrawType.FILL);
}
/** Draws a circle outline with the center at x,y and a radius using the current color and stroke width.
/**
* Draws a circle outline with the center at x,y and a radius using the current color and stroke width.
*
* @param x The x-coordinate of the center
* @param y The y-coordinate of the center
* @param radius The radius in pixels */
* @param radius The radius in pixels
*/
public void drawCircle(int x, int y, int radius) {
circle(x, y, radius, DrawType.STROKE);
}
/** Fills a circle with the center at x,y and a radius using the current color.
/**
* Fills a circle with the center at x,y and a radius using the current color.
*
* @param x The x-coordinate of the center
* @param y The y-coordinate of the center
* @param radius The radius in pixels */
* @param radius The radius in pixels
*/
public void fillCircle(int x, int y, int radius) {
circle(x, y, radius, DrawType.FILL);
}
/** Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.
/**
* Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.
*
* @param x1 The x-coordinate of vertex 1
* @param y1 The y-coordinate of vertex 1
* @param x2 The x-coordinate of vertex 2
* @param y2 The y-coordinate of vertex 2
* @param x3 The x-coordinate of vertex 3
* @param y3 The y-coordinate of vertex 3 */
* @param y3 The y-coordinate of vertex 3
*/
public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
triangle(x1, y1, x2, y2, x3, y3, DrawType.FILL);
}
/** Returns the 32-bit RGBA8888 value of the pixel at x, y. For Alpha formats the RGB components will be one.
/**
* Returns the 32-bit RGBA8888 value of the pixel at x, y. For Alpha formats the RGB components will be one.
*
* @param x The x-coordinate
* @param y The y-coordinate
* @return The pixel color in RGBA8888 format. */
* @return The pixel color in RGBA8888 format.
*/
public int getPixel(int x, int y) {
ensureCanvasExists();
if (pixels == null) pixels = context.getImageData(0, 0, width, height).getData();
@ -388,19 +434,23 @@ public class Pixmap implements Disposable {
return (r << 24) | (g << 16) | (b << 8) | (a);
}
/** Draws a pixel at the given location with the current color.
/**
* Draws a pixel at the given location with the current color.
*
* @param x the x-coordinate
* @param y the y-coordinate */
* @param y the y-coordinate
*/
public void drawPixel(int x, int y) {
rectangle(x, y, 1, 1, DrawType.FILL);
}
/** Draws a pixel at the given location with the given color.
/**
* Draws a pixel at the given location with the given color.
*
* @param x the x-coordinate
* @param y the y-coordinate
* @param color the color in RGBA8888 format. */
* @param color the color in RGBA8888 format.
*/
public void drawPixel(int x, int y, int color) {
setColor(color);
drawPixel(x, y);