From 4f9de9527f8301e024fe81a42f0b9dfc50bae1a6 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 30 Sep 2017 00:46:31 +0200 Subject: Review gradient rectangle drawing Added: DrawRectangleGradientV() Added: DrawRectangleGradientH() --- src/shapes.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/shapes.c') diff --git a/src/shapes.c b/src/shapes.c index 8c7f2419..8197735f 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -274,22 +274,22 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color rlDisableTexture(); } -// Draw a gradient-filled rectangle +// Draw a vertical-gradient-filled rectangle // NOTE: Gradient goes from bottom (color1) to top (color2) -void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2) +void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2) { - rlBegin(RL_TRIANGLES); - rlColor4ub(color1.r, color1.g, color1.b, color1.a); rlVertex2i(posX, posY); - rlColor4ub(color2.r, color2.g, color2.b, color2.a); rlVertex2i(posX, posY + height); - rlColor4ub(color2.r, color2.g, color2.b, color2.a); rlVertex2i(posX + width, posY + height); + DrawRectangleGradientEx((Rectangle){ posX, posY, width, height }, color1, color2, color2, color1); +} - rlColor4ub(color1.r, color1.g, color1.b, color1.a); rlVertex2i(posX, posY); - rlColor4ub(color2.r, color2.g, color2.b, color2.a); rlVertex2i(posX + width, posY + height); - rlColor4ub(color1.r, color1.g, color1.b, color1.a); rlVertex2i(posX + width, posY); - rlEnd(); +// Draw a horizontal-gradient-filled rectangle +// NOTE: Gradient goes from bottom (color1) to top (color2) +void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2) +{ + DrawRectangleGradientEx((Rectangle){ posX, posY, width, height }, color1, color1, color2, color2); } // Draw a gradient-filled rectangle +// NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4) { rlEnableTexture(GetTextureDefault().id); // Default white texture -- cgit v1.2.3 From cd6d752217c9ee2af52f55daf1fea73c0da09a84 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 12 Oct 2017 19:51:21 +0200 Subject: Fix warning about unsequenced modification of variable Variable t was read and modified without interleaving sequence points, technically undefined behavior. Report by Clang's -Wunsequenced --- src/shapes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/shapes.c') diff --git a/src/shapes.c b/src/shapes.c index 8197735f..63993469 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -683,5 +683,5 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) static float EaseCubicInOut(float t, float b, float c, float d) { if ((t/=d/2) < 1) return (c/2*t*t*t + b); - return (c/2*((t-=2)*t*t + 2) + b); -} \ No newline at end of file + return (c/2*((t-2)*t*t + 2) + b); +} -- cgit v1.2.3 From 107294f3e64c0b1c5722f736097adb808aa3a83c Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Fri, 13 Oct 2017 13:55:01 +0200 Subject: Fix bug, add some whitespace --- src/shapes.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/shapes.c') diff --git a/src/shapes.c b/src/shapes.c index 63993469..0b34f921 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -682,6 +682,8 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2) // NOTE: Required for DrawLineBezier() static float EaseCubicInOut(float t, float b, float c, float d) { - if ((t/=d/2) < 1) return (c/2*t*t*t + b); - return (c/2*((t-2)*t*t + 2) + b); + if ((t /= 0.5*d) < 1) + return 0.5*c*t*t*t + b; + t -= 2; + return 0.5*c*(t*t*t + 2) + b; } -- cgit v1.2.3