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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* Copyright 2011 See AUTHORS file. * Copyright 2011 See AUTHORS file.
* * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -16,11 +16,6 @@
package com.badlogic.gdx.graphics; 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.backends.gwt.GwtFileHandle;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.BufferUtils; 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.CanvasElement;
import com.google.gwt.dom.client.ImageElement; 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 class Pixmap implements Disposable {
public static Map<Integer, Pixmap> pixmaps = new HashMap<Integer, Pixmap>(); public static Map<Integer, Pixmap> pixmaps = new HashMap<Integer, Pixmap>();
static int nextId = 0; static int nextId = 0;
/** Different pixel formats. /**
* Different pixel formats.
* *
* @author mzechner */ * @author mzechner
*/
public enum Format { public enum Format {
Alpha, Intensity, LuminanceAlpha, RGB565, RGBA4444, RGB888, RGBA8888; 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 { public enum Blending {
None, SourceOver 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 { public enum Filter {
NearestNeighbour, BiLinear NearestNeighbour, BiLinear
} }
@ -96,7 +103,8 @@ public class Pixmap implements Disposable {
public Pixmap(FileHandle file) { public Pixmap(FileHandle file) {
this(((GwtFileHandle) file).preloader.images.get(file.path())); 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() { public Context2d getContext() {
@ -139,8 +147,11 @@ public class Pixmap implements Disposable {
return "rgba(" + r2 + "," + g2 + "," + b2 + "," + a2 + ")"; 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) { public static void setBlending(Blending blending) {
Pixmap.blending = blending; Pixmap.blending = blending;
Composite composite = getComposite(); 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() { public static Blending getBlending() {
return blending; 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)}. * {@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) { public static void setFilter(Filter filter) {
} }
@ -218,8 +234,11 @@ public class Pixmap implements Disposable {
return imageElement; 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) { public void setColor(int color) {
ensureCanvasExists(); ensureCanvasExists();
r = (color >>> 24) & 0xff; r = (color >>> 24) & 0xff;
@ -231,12 +250,14 @@ public class Pixmap implements Disposable {
context.setStrokeStyle(this.color); 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 r The red component.
* @param g The green component. * @param g The green component.
* @param b The blue 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) { public void setColor(float r, float g, float b, float a) {
ensureCanvasExists(); ensureCanvasExists();
this.r = (int) (r * 255); this.r = (int) (r * 255);
@ -248,13 +269,18 @@ public class Pixmap implements Disposable {
context.setStrokeStyle(this.color); 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) { public void setColor(Color color) {
setColor(color.r, color.g, color.b, color.a); 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() { public void fill() {
ensureCanvasExists(); ensureCanvasExists();
context.clearRect(0, 0, getWidth(), getHeight()); context.clearRect(0, 0, getWidth(), getHeight());
@ -268,38 +294,45 @@ public class Pixmap implements Disposable {
// */ // */
// public void setStrokeWidth (int width); // 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 x The x-coodinate of the first point
* @param y The y-coordinate of the first point * @param y The y-coordinate of the first point
* @param x2 The x-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) { public void drawLine(int x, int y, int x2, int y2) {
line(x, y, x2, y2, DrawType.STROKE); 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. * using the current color.
* *
* @param x The x coordinate * @param x The x coordinate
* @param y The y coordinate * @param y The y coordinate
* @param width The width in pixels * @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) { public void drawRectangle(int x, int y, int width, int height) {
rectangle(x, y, width, height, DrawType.STROKE); 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 pixmap The other Pixmap
* @param x The target x-coordinate (top left corner) * @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) { public void drawPixmap(Pixmap pixmap, int x, int y) {
CanvasElement image = pixmap.getCanvasElement(); CanvasElement image = pixmap.getCanvasElement();
image(image, 0, 0, image.getWidth(), image.getHeight(), x, y, image.getWidth(), image.getHeight()); 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 pixmap The other Pixmap
* @param x The target x-coordinate (top left corner) * @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 srcx The source x-coordinate (top left corner)
* @param srcy The source y-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 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) { public void drawPixmap(Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) {
CanvasElement image = pixmap.getCanvasElement(); CanvasElement image = pixmap.getCanvasElement();
image(image, srcx, srcy, srcWidth, srcHeight, x, y, srcWidth, srcHeight); 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 * specified target rectangle. Use {@link Pixmap#setFilter(Filter)} to specify the type of filtering to be used (nearest
* neighbour or bilinear). * neighbour or bilinear).
* *
@ -325,58 +360,69 @@ public class Pixmap implements Disposable {
* @param dstx The target x-coordinate (top left corner) * @param dstx The target x-coordinate (top left corner)
* @param dsty The target y-coordinate (top left corner) * @param dsty The target y-coordinate (top left corner)
* @param dstWidth The target width * @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, public void drawPixmap(Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth,
int dstHeight) { int dstHeight) {
image(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, 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. * the current color.
* *
* @param x The x coordinate * @param x The x coordinate
* @param y The y coordinate * @param y The y coordinate
* @param width The width in pixels * @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) { public void fillRectangle(int x, int y, int width, int height) {
rectangle(x, y, width, height, DrawType.FILL); 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 x The x-coordinate of the center
* @param y The y-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) { public void drawCircle(int x, int y, int radius) {
circle(x, y, radius, DrawType.STROKE); 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 x The x-coordinate of the center
* @param y The y-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) { public void fillCircle(int x, int y, int radius) {
circle(x, y, radius, DrawType.FILL); 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 x1 The x-coordinate of vertex 1
* @param y1 The y-coordinate of vertex 1 * @param y1 The y-coordinate of vertex 1
* @param x2 The x-coordinate of vertex 2 * @param x2 The x-coordinate of vertex 2
* @param y2 The y-coordinate of vertex 2 * @param y2 The y-coordinate of vertex 2
* @param x3 The x-coordinate of vertex 3 * @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) { public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) {
triangle(x1, y1, x2, y2, x3, y3, DrawType.FILL); 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 x The x-coordinate
* @param y The y-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) { public int getPixel(int x, int y) {
ensureCanvasExists(); ensureCanvasExists();
if (pixels == null) pixels = context.getImageData(0, 0, width, height).getData(); 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); 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 x the x-coordinate
* @param y the y-coordinate */ * @param y the y-coordinate
*/
public void drawPixel(int x, int y) { public void drawPixel(int x, int y) {
rectangle(x, y, 1, 1, DrawType.FILL); 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 x the x-coordinate
* @param y the y-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) { public void drawPixel(int x, int y, int color) {
setColor(color); setColor(color);
drawPixel(x, y); drawPixel(x, y);