Skip to content

Commit 28e8a68

Browse files
committed
Add rect(x,y,w,h,tl,tr,br,bl) with 4 corner radii
1 parent a259fce commit 28e8a68

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

src/Processing.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
#
2-
void PApplet::rect(float x,float y,float w,float h,float tl,float tr,float br,float bl){
3-
if(!doFill && !doStroke) return;
4-
float x2=x+w, y2=y+h;
5-
beginShape();
6-
vertex(x+tl,y); vertex(x2-tr,y);
7-
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);}}
8-
vertex(x2,y+tr); vertex(x2,y2-br);
9-
if(br>0){for(int i=0;i<=8;i++){float a=HALF_PI*i/8.f;vertex(x2-br+::std::cos(a)*br,y2-br+::std::sin(a)*br);}}
10-
vertex(x2-br,y2); vertex(x+bl,y2);
11-
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);}}
12-
vertex(x,y2-bl); vertex(x,y+tl);
13-
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);}}
14-
endShape(CLOSE);
15-
}
16-
if __has_include("stb_truetype.h")
1+
#if __has_include("stb_truetype.h")
172
# define PROCESSING_HAS_STB_TRUETYPE 1
183
# define STB_TRUETYPE_IMPLEMENTATION
194
# include "stb_truetype.h"
@@ -1153,6 +1138,21 @@ void PApplet::rect(float x, float y, float w, float h, float r) {
11531138
glEnd();
11541139
}
11551140
}
1141+
void PApplet::rect(float x,float y,float w,float h,float tl,float tr,float br,float bl){
1142+
if(!doFill && !doStroke) return;
1143+
float x2=x+w, y2=y+h;
1144+
beginShape();
1145+
vertex(x+tl,y); vertex(x2-tr,y);
1146+
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);}}
1147+
vertex(x2,y+tr); vertex(x2,y2-br);
1148+
if(br>0){for(int i=0;i<=8;i++){float a=HALF_PI*i/8.f;vertex(x2-br+::std::cos(a)*br,y2-br+::std::sin(a)*br);}}
1149+
vertex(x2-br,y2); vertex(x+bl,y2);
1150+
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);}}
1151+
vertex(x,y2-bl); vertex(x,y+tl);
1152+
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);}}
1153+
endShape(CLOSE);
1154+
}
1155+
11561156
void PApplet::square(float x,float y,float s){rect(x,y,s,s);}
11571157
void PApplet::triangle(float x1, float y1, float x2, float y2, float x3, float y3) {
11581158
if (doFill) {

0 commit comments

Comments
 (0)