Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Partially documented image.
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyAreAllTheseTaken committed Nov 13, 2019
1 parent 2cb9f0a commit 0a554c1
Showing 1 changed file with 96 additions and 1 deletion.
97 changes: 96 additions & 1 deletion RPGOnline2/src/io/github/tomaso2468/rpgonline/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,80 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import io.github.tomaso2468.rpgonline.render.RenderException;
import io.github.tomaso2468.rpgonline.render.Renderer;

/**
* A representation of a 2D image.
* @author Tomaso2468
*
*/
public class Image implements Cloneable {
/**
* A filter that uses nearest neighbour interpolation.
*/
public static final int FILTER_NEAREST = 0;
/**
* A filter that uses linear interpolation.
*/
public static final int FILTER_LINEAR = 1;


/**
* The renderer for this image.
*/
private Renderer renderer;
/**
* The renderer compatible texture for this image.
*/
private TextureReference texture;
/**
* Texture X coord. This uses OpenGL texture coords.
*/
private float textureX;
/**
* Texture Y coord. This uses OpenGL texture coords.
*/
private float textureY;
/**
* Horizontal texture width.
*/
private float textureWidth;
/**
* Vertical texture height.
*/
private float textureHeight;
/**
* The width of the image.
*/
private float width;
/**
* The height of the image.
*/
private float height;
/**
* The filter this image uses.
*/
private int filter = FILTER_LINEAR;

/**
* Constructs a new blank image.
* @param renderer The renderer to use for image commands.
* @param width The width of the image.
* @param height The height of the image.
* @throws RenderException If an error occurs creating an empty image.
*/
public Image(Renderer renderer, int width, int height) throws RenderException {
this(renderer, renderer.createEmptyTexture(width, height));
}

/**
* Constructs a new Image using texture information.
* @param renderer The renderer to use for image commands.
* @param texture The texture to use for this image.
* @param texture_x The texture X coord using OpenGL texture coords.
* @param texture_y The texture Y coord using OpenGL texture coords.
* @param texture_w The width of the area to use from the texture.
* @param texture_h The height of the area to use from the texture.
* @param width The width of the image.
* @param height The height of the image.
*/
public Image(Renderer renderer, TextureReference texture, float texture_x, float texture_y, float texture_w,
float texture_h, float width, float height) {
super();
Expand All @@ -68,6 +124,11 @@ public Image(Renderer renderer, TextureReference texture, float texture_x, float
this.height = height;
}

/**
* Constructs a new Image using texture information.
* @param renderer The renderer to use for image commands.
* @param texture The texture to use for this image.
*/
public Image(Renderer renderer, TextureReference texture) {
super();
this.renderer = renderer;
Expand All @@ -80,28 +141,62 @@ public Image(Renderer renderer, TextureReference texture) {
this.height = texture.getHeight();
}

/**
* Constructs a new image from an image. This does not create a new copy of the underlying texture.
* @param renderer The renderer to use for image commands.
* @param img The image to copy data from.
*/
public Image(Renderer renderer, Image img) {
this(renderer, img.getTexture(), img.getTextureOffsetX(), img.getTextureOffsetY(), img.getTextureWidth(),
img.getTextureHeight(), img.getWidth(), img.getHeight());
}

/**
* Sets the filter for this image.
* @param filterMode The filter mode.
*
* @see #getFilter()
* @see #FILTER_LINEAR
* @see #FILTER_NEAREST
*/
public void setFilter(int filterMode) {
renderer.setFilter(texture, filterMode);
this.filter = filterMode;
}

/**
* Gets the texture for this image.
* @return A texture reference object compatible with the game's renderer.
*/
public TextureReference getTexture() {
return texture;
}

/**
* Writes an image to a file.
* @param dest The location to write to.
* @param writeAlpha Whether or not the alpha channel should be used when writing this image.
* @throws IOException If an error occurs writing the image.
* @throws RenderException If an error occurs in the renderer.
*/
public void write(String dest, boolean writeAlpha) throws IOException, RenderException {
renderer.writeImage(this, new File(dest), writeAlpha);
}

/**
* Writes an image to a file including the alpha channel.
* @param dest The location to write to.
* @throws IOException If an error occurs writing the image.
* @throws RenderException If an error occurs in the renderer.
*/
public void write(String dest) throws IOException, RenderException {
write(dest, true);
}

/**
* Gets the X position from the source texture.
* @return A float value.
*/
public float getTextureOffsetX() {
return textureX;
}
Expand Down

0 comments on commit 0a554c1

Please sign in to comment.