Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions drawer/src/space/earlygrey/shapedrawer/FilledPolygonDrawer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package space.earlygrey.shapedrawer;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.EarClippingTriangulator;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.ShortArray;
Expand Down Expand Up @@ -72,6 +74,56 @@ void rectangle(float x, float y, float width, float height, float rotation, floa
if (!caching) batchManager.pushToBatch();
}

/** Based on {@link ShapeRenderer#rect(float, float, float, float, float, float, float, float, float, Color, Color, Color, Color)} */
void rectangle(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY,
float degrees, float col1, float col2, float col3, float col4)
{
boolean caching = batchManager.isCachingDraws();
batchManager.ensureSpaceForQuad();

float cos = MathUtils.cosDeg(degrees);
float sin = MathUtils.sinDeg(degrees);
float fx = -originX;
float fy = -originY;
float fx2 = width - originX;
float fy2 = height - originY;

if (scaleX != 1 || scaleY != 1) {
fx *= scaleX;
fy *= scaleY;
fx2 *= scaleX;
fy2 *= scaleY;
}

float worldOriginX = x + originX;
float worldOriginY = y + originY;

float x1 = cos * fx - sin * fy + worldOriginX;
float y1 = sin * fx + cos * fy + worldOriginY;

float x2 = cos * fx2 - sin * fy + worldOriginX;
float y2 = sin * fx2 + cos * fy + worldOriginY;

float x3 = cos * fx2 - sin * fy2 + worldOriginX;
float y3 = sin * fx2 + cos * fy2 + worldOriginY;

float x4 = x1 + (x3 - x2);
float y4 = y3 - (y2 - y1);

x1(x1);
y1(y1);
x2(x2);
y2(y2);
x3(x3);
y3(y3);
x4(x4);
y4(y4);

color(col1, col2, col3, col4);
batchManager.pushQuad();
if (!caching) batchManager.pushToBatch();
}

public void triangle(float x1, float y1, float x2, float y2, float x3, float y3, float color1, float color2, float color3) {
boolean caching = batchManager.isCachingDraws();
vert1(x1, y1);
Expand Down
46 changes: 46 additions & 0 deletions drawer/src/space/earlygrey/shapedrawer/ShapeDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Rectangle;
Expand Down Expand Up @@ -1844,4 +1845,49 @@ public void filledRectangle(float x, float y, float width, float height, float r
filledPolygonDrawer.rectangle(x, y, width, height, rotation, c1, c2, c3, c4);
}

/** Draws a filled rectangle. The x and y specify the lower left corner.
* The originX and originY specify the point about which to rotate the rectangle.
* The rotation is specified in degrees.
*
* @apiNote It have the same usage as {@link ShapeRenderer#rect(float, float, float, float, float, float, float, float, float)} has
*/
public void filledRectangle2(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees)
{
float c = batchManager.floatBits;
filledRectangle2(x, y, originX, originY, width, height, scaleX, scaleY, degrees, c, c, c, c);
}

/** Draws a filled rectangle. The x and y specify the lower left corner.
* The originX and originY specify the point about which to rotate the rectangle.
* The rotation is specified in degrees.
*
* @param col1 The color at (x, y)
* @param col2 The color at (x + width, y)
* @param col3 The color at (x + width, y + height)
* @param col4 The color at (x, y + height)
*
* @apiNote It have the same usage as {@link ShapeRenderer#rect(float, float, float, float, float, float, float, float, float, Color, Color, Color, Color)} has
*/
public void filledRectangle2(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY,
float degrees, Color col1, Color col2, Color col3, Color col4)
{
filledRectangle2(x, y, originX, originY, width, height, scaleX, scaleY, degrees, col1.toFloatBits(), col2.toFloatBits(), col3.toFloatBits(), col4.toFloatBits());
}

/** Draws a filled rectangle. The x and y specify the lower left corner.
* The originX and originY specify the point about which to rotate the rectangle.
* The rotation is specified in degrees.
*
* @param col1 The color at (x, y)
* @param col2 The color at (x + width, y)
* @param col3 The color at (x + width, y + height)
* @param col4 The color at (x, y + height)
*
* @apiNote It have the same usage as {@link ShapeRenderer#rect(float, float, float, float, float, float, float, float, float, Color, Color, Color, Color)} has, but uses {@link Color#toFloatBits()}'ed colors to draw
*/
public void filledRectangle2(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY,
float degrees, float col1, float col2, float col3, float col4)
{
filledPolygonDrawer.rectangle(x, y, originX, originY, width, height, scaleX, scaleY, degrees, col1, col2, col3, col4);
}
}