Skip to content

Commit 77680ac

Browse files
committed
Add createShape(kind,x,y,w,h) overload and PShape.params field
1 parent 45d29fe commit 77680ac

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/Processing.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,6 +4263,20 @@ bool PApplet::saveTable(const ::std::string& path,const Table& t,const ::std::st
42634263
// =============================================================================
42644264
void PApplet::shapeMode(int mode){ shapeDrawMode=mode; }
42654265
PShape PApplet::createShape(int kind){ return PShape(kind); }
4266+
PShape PApplet::createShape(int kind, float a, float b, float c, float d){
4267+
// createShape(RECT/ELLIPSE/LINE/POINT, x, y, w, h)
4268+
PShape s(kind);
4269+
s.beginShape();
4270+
if(kind==ELLIPSE||kind==RECT) {
4271+
s.params = {a,b,c,d};
4272+
} else if(kind==LINE) {
4273+
s.vertex(a,b); s.vertex(c,d);
4274+
} else if(kind==POINT) {
4275+
s.vertex(a,b);
4276+
}
4277+
s.endShape();
4278+
return s;
4279+
}
42664280

42674281
// ── Minimal SVG loader ────────────────────────────────────────────────────────
42684282
// Parses basic SVG shapes (path, rect, circle, ellipse, polygon, polyline, line)

src/Processing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,6 +3437,7 @@ class PShape {
34373437

34383438
void beginShape(int k=-1) { kind=k; verts.clear(); }
34393439
void endShape(bool close=false) { closed=close; }
3440+
::std::vector<float> params; // for primitive shapes (ELLIPSE, RECT, etc.)
34403441
void vertex(float x,float y,float z=0,float u=0,float v=0) { verts.push_back({x,y,z,u,v}); }
34413442
void addChild(const PShape& s) { children.push_back(s); }
34423443
void addChild(const PShape* s) { if (s) addChild(*s); }
@@ -4662,6 +4663,7 @@ struct PApplet {
46624663
// ── PShape ───────────────────────────────────────────────────────────────
46634664
PShape createShape(int kind=-1);
46644665
PShape* loadShape(const ::std::string& path);
4666+
PShape createShape(int kind, float a, float b, float c, float d);
46654667
void shape(const PShape& s, float x=0, float y=0);
46664668
void shape(const PShape& s, float x, float y, float w, float h);
46674669
void shape(const PShape* s, float x=0, float y=0) { if(s) shape(*s,x,y); }

0 commit comments

Comments
 (0)