Skip to content

Commit 7b0c010

Browse files
committed
Add rect(x,y,w,h,tl,tr,br,bl) with 4 corner radii
1 parent ab7daf3 commit 7b0c010

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/Processing.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
#if __has_include("stb_truetype.h")
1+
#
2+
void PApplet::rect(float x,float y,float w,float h,float tl,float tr,float br,float bl){
3+
// Draw rect with 4 different corner radii
4+
if(!doFill && !doStroke) return;
5+
float x2=x+w, y2=y+h;
6+
beginShape();
7+
vertex(x+tl,y); vertex(x2-tr,y); // top
8+
if(tr>0){for(int i=0;i<=8;i++){float a=PI+HALF_PI+HALF_PI*i/8.f;vertex(x2-tr+::std::cos(a)*tr,y+tr+::std::sin(a)*tr);}}
9+
vertex(x2,y+tr); vertex(x2,y2-br); // right
10+
if(br>0){for(int i=0;i<=8;i++){float a=0+HALF_PI*i/8.f;vertex(x2-br+::std::cos(a)*br,y2-br+::std::sin(a)*br);}}
11+
vertex(x2-br,y2); vertex(x+bl,y2); // bottom
12+
if(bl>0){for(int i=0;i<=8;i++){float a=HALF_PI+HALF_PI*i/8.f;vertex(x+bl+::std::cos(a)*bl,y2-bl+::std::sin(a)*bl);}}
13+
vertex(x,y2-bl); vertex(x,y+tl); // left
14+
if(tl>0){for(int i=0;i<=8;i++){float a=PI+HALF_PI*i/8.f;vertex(x+tl+::std::cos(a)*tl,y+tl+::std::sin(a)*tl);}}
15+
endShape(CLOSE);
16+
}
17+
if __has_include("stb_truetype.h")
218
# define PROCESSING_HAS_STB_TRUETYPE 1
319
# define STB_TRUETYPE_IMPLEMENTATION
420
# include "stb_truetype.h"

src/Processing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ class PGraphics : public PImage {
930930
void ellipse(float x, float y, float w, float h);
931931
void rect(float x, float y, float w, float h);
932932
void rect(float x, float y, float w, float h, float r);
933+
void rect(float x, float y, float w, float h, float tl, float tr, float br, float bl);
933934
void line(float x1, float y1, float x2, float y2);
934935
void point(float x, float y);
935936
void triangle(float x1,float y1,float x2,float y2,float x3,float y3);
@@ -4107,6 +4108,7 @@ struct PApplet {
41074108
void circle(float cx, float cy, float d);
41084109
void rect(float x, float y, float w, float h);
41094110
void rect(float x, float y, float w, float h, float r);
4111+
void rect(float x, float y, float w, float h, float tl, float tr, float br, float bl);
41104112
void square(float x, float y, float s);
41114113
void triangle(float x1, float y1, float x2, float y2, float x3, float y3);
41124114
void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);

0 commit comments

Comments
 (0)