Skip to content
Open
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
24 changes: 18 additions & 6 deletions Sources/kha/graphics2/GraphicsExtension.hx
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,44 @@ class GraphicsExtension {
/**
* Draws a convex polygon.
*/
public static function drawPolygon(g2: Graphics, x: Float, y: Float, vertices: Array<Vector2>, strength: Float = 1) {
public static function drawPolygon(g2: Graphics, x: Float, y: Float, vertices: Array<Vector2>, strength: Float = 1, ?worldSpace: Bool = false) {
var iterator = vertices.iterator();
var v0 = iterator.next();
var v1 = v0;

while (iterator.hasNext()) {
var v2 = iterator.next();
g2.drawLine(v1.x + x, v1.y + y, v2.x + x, v2.y + y, strength);
if (worldSpace)
g2.drawLine(v1.x, v1.y, v2.x, v2.y, strength);
else
g2.drawLine(v1.x + x, v1.y + y, v2.x + x, v2.y + y, strength);
v1 = v2;
}
g2.drawLine(v1.x + x, v1.y + y, v0.x + x, v0.y + y, strength);
if (worldSpace)
g2.drawLine(v1.x, v1.y, v0.x, v0.y, strength);
else
g2.drawLine(v1.x + x, v1.y + y, v0.x + x, v0.y + y, strength);
}

/**
* Draws a filled convex polygon.
*/
public static function fillPolygon(g2: Graphics, x: Float, y: Float, vertices: Array<Vector2>) {
public static function fillPolygon(g2: Graphics, x: Float, y: Float, vertices: Array<Vector2>, ?worldSpace: Bool = false) {
var iterator = vertices.iterator();
var v0 = iterator.next();
var v1 = v0;

while (iterator.hasNext()) {
var v2 = iterator.next();
g2.fillTriangle(v1.x + x, v1.y + y, v2.x + x, v2.y + y, x, y);
if (worldSpace)
g2.fillTriangle(v1.x, v1.y, v2.x, v2.y, x, y);
else
g2.fillTriangle(v1.x + x, v1.y + y, v2.x + x, v2.y + y, x, y);
v1 = v2;
}
g2.fillTriangle(v1.x + x, v1.y + y, v0.x + x, v0.y + y, x, y);
if (worldSpace)
g2.fillTriangle(v1.x, v1.y, v0.x, v0.y, x, y);
else
g2.fillTriangle(v1.x + x, v1.y + y, v0.x + x, v0.y + y, x, y);
}
}