Watch
2
0
Fork
You've already forked raylib-cs
0

chore: clean up linter warnings

This commit is contained in:
tiger tiger tiger 2026-07-29 19:58:47 +02:00
commit dfc34997bc
No known key found for this signature in database
217 changed files with 1863 additions and 1077 deletions

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
namespace Examples.Shapes;
@ -146,7 +143,10 @@ public partial class BallPhysics : IExample
{
for (int i = 0; i < ballCount; i++)
{
if (!balls[i].grabbed) balls[i].speed = Vector2Add(balls[i].speed, Vector2Scale(windowPositionDelta, 10.0f));
if (!balls[i].grabbed)
{
balls[i].speed = Vector2Add(balls[i].speed, Vector2Scale(windowPositionDelta, 10.0f));
}
}
}
@ -155,7 +155,10 @@ public partial class BallPhysics : IExample
{
for (int i = 0; i < ballCount; i++)
{
if (!balls[i].grabbed) balls[i].speed = new Vector2(GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000));
if (!balls[i].grabbed)
{
balls[i].speed = new Vector2(GetRandomValue(-2000, 2000), GetRandomValue(-2000, 2000));
}
}
}

View file

@ -13,9 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class BasicShapes : IExample

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class BouncingBall : IExample

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class BulletHell : IExample
@ -167,13 +163,40 @@ public partial class BulletHell : IExample
}
// Input logic
if ((IsKeyPressed(KeyboardKey.Right) || IsKeyPressed(KeyboardKey.D)) && (bulletRows < 359)) bulletRows++;
if ((IsKeyPressed(KeyboardKey.Left) || IsKeyPressed(KeyboardKey.A)) && (bulletRows > 1)) bulletRows--;
if (IsKeyPressed(KeyboardKey.Up) || IsKeyPressed(KeyboardKey.W)) bulletSpeed += 0.25f;
if ((IsKeyPressed(KeyboardKey.Down) || IsKeyPressed(KeyboardKey.S)) && (bulletSpeed > 0.50f)) bulletSpeed -= 0.25f;
if (IsKeyPressed(KeyboardKey.Z) && (spawnCooldown > 1)) spawnCooldown--;
if (IsKeyPressed(KeyboardKey.X)) spawnCooldown++;
if (IsKeyPressed(KeyboardKey.Enter)) drawInPerformanceMode = !drawInPerformanceMode;
if ((IsKeyPressed(KeyboardKey.Right) || IsKeyPressed(KeyboardKey.D)) && (bulletRows < 359))
{
bulletRows++;
}
if ((IsKeyPressed(KeyboardKey.Left) || IsKeyPressed(KeyboardKey.A)) && (bulletRows > 1))
{
bulletRows--;
}
if (IsKeyPressed(KeyboardKey.Up) || IsKeyPressed(KeyboardKey.W))
{
bulletSpeed += 0.25f;
}
if ((IsKeyPressed(KeyboardKey.Down) || IsKeyPressed(KeyboardKey.S)) && (bulletSpeed > 0.50f))
{
bulletSpeed -= 0.25f;
}
if (IsKeyPressed(KeyboardKey.Z) && (spawnCooldown > 1))
{
spawnCooldown--;
}
if (IsKeyPressed(KeyboardKey.X))
{
spawnCooldown++;
}
if (IsKeyPressed(KeyboardKey.Enter))
{
drawInPerformanceMode = !drawInPerformanceMode;
}
if (IsKeyDown(KeyboardKey.Space))
{
@ -244,10 +267,16 @@ public partial class BulletHell : IExample
DrawText("- C: Clear bullets", 40, 140, 10, Color.LightGray);
DrawRectangle(610, 10, 170, 30, new Color(0, 0, 0, 200));
if (drawInPerformanceMode) DrawText("Draw method: DrawTexture(*)", 620, 20, 10, Color.Green);
else DrawText("Draw method: DrawCircle(*)", 620, 20, 10, Color.Red);
if (drawInPerformanceMode)
{
DrawText("Draw method: DrawTexture(*)", 620, 20, 10, Color.Green);
}
else
{
DrawText("Draw method: DrawCircle(*)", 620, 20, 10, Color.Red);
}
DrawRectangle(135, 410, 530, 30, new Color(0, 0, 0, 200));
DrawRectangle(135, 410, 530, 30, new Color(0, 0, 0, 200));
DrawText($"[ FPS: {GetFPS()}, Bullets: {bulletCount - bulletDisabledCount}, Rows: {bulletRows}, Bullet speed: {bulletSpeed:F2}, Angle increment per frame: {angleIncrement}, Cooldown: {spawnCooldown:F0} ]",
155, 420, 10, Color.Green);

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath; // Required for: Lerp(), Clamp()
namespace Examples.Shapes;
@ -113,9 +110,20 @@ public partial class ClockOfClocks : IExample
dstAngles[digit, cell] = digitAngles[clockDigits[digit] - '0', cell];
// Quick exception for 12h mode
if ((digit == 0) && (hourMode == 12) && (clockDigits[0] == '0')) dstAngles[digit, cell] = ZZ;
if (srcAngles[digit, cell].X > dstAngles[digit, cell].X) srcAngles[digit, cell].X -= 360.0f;
if (srcAngles[digit, cell].Y > dstAngles[digit, cell].Y) srcAngles[digit, cell].Y -= 360.0f;
if ((digit == 0) && (hourMode == 12) && (clockDigits[0] == '0'))
{
dstAngles[digit, cell] = ZZ;
}
if (srcAngles[digit, cell].X > dstAngles[digit, cell].X)
{
srcAngles[digit, cell].X -= 360.0f;
}
if (srcAngles[digit, cell].Y > dstAngles[digit, cell].Y)
{
srcAngles[digit, cell].Y -= 360.0f;
}
}
}
@ -146,7 +154,10 @@ public partial class ClockOfClocks : IExample
}
// Handle input
if (IsKeyPressed(KeyboardKey.Space)) hourMode = 36 - hourMode; // Toggle between 12 and 24 hour mode with space
if (IsKeyPressed(KeyboardKey.Space))
{
hourMode = 36 - hourMode; // Toggle between 12 and 24 hour mode with space
}
//----------------------------------------------------------------------------------
// Draw

View file

@ -13,8 +13,6 @@
*
********************************************************************************************/
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class CollisionArea : IExample

View file

@ -13,9 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class ColorsPalette : IExample

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DashedLine : IExample
@ -59,15 +56,32 @@ public partial class DashedLine : IExample
lineEndPosition = GetMousePosition(); // Line endpoint follows the mouse
// Change Dash Length (UP/DOWN arrows)
if (IsKeyDown(KeyboardKey.Up)) dashLength += 1.0f;
if (IsKeyDown(KeyboardKey.Down) && dashLength > 1.0f) dashLength -= 1.0f;
if (IsKeyDown(KeyboardKey.Up))
{
dashLength += 1.0f;
}
if (IsKeyDown(KeyboardKey.Down) && dashLength > 1.0f)
{
dashLength -= 1.0f;
}
// Change Space Length (LEFT/RIGHT arrows)
if (IsKeyDown(KeyboardKey.Right)) blankLength += 1.0f;
if (IsKeyDown(KeyboardKey.Left) && blankLength > 1.0f) blankLength -= 1.0f;
if (IsKeyDown(KeyboardKey.Right))
{
blankLength += 1.0f;
}
if (IsKeyDown(KeyboardKey.Left) && blankLength > 1.0f)
{
blankLength -= 1.0f;
}
// Cycle through colors ('C' key)
if (IsKeyPressed(KeyboardKey.C)) colorIndex = (colorIndex + 1)%lineColors.Length;
if (IsKeyPressed(KeyboardKey.C))
{
colorIndex = (colorIndex + 1)%lineColors.Length;
}
//----------------------------------------------------------------------------------
// Draw

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DigitalClock : IExample
@ -92,8 +88,14 @@ public partial class DigitalClock : IExample
if (IsKeyPressed(KeyboardKey.Space))
{
// Toggle clock mode
if (clockMode == CLOCK_DIGITAL) clockMode = CLOCK_ANALOG;
else if (clockMode == CLOCK_ANALOG) clockMode = CLOCK_DIGITAL;
if (clockMode == CLOCK_DIGITAL)
{
clockMode = CLOCK_ANALOG;
}
else if (clockMode == CLOCK_ANALOG)
{
clockMode = CLOCK_DIGITAL;
}
}
UpdateClock(); // Update clock required data: value and angle
@ -106,7 +108,10 @@ public partial class DigitalClock : IExample
ClearBackground(Color.RayWhite);
// Draw clock in selected mode
if (clockMode == CLOCK_ANALOG) DrawClockAnalog(clock, new Vector2(400, 240));
if (clockMode == CLOCK_ANALOG)
{
DrawClockAnalog(clock, new Vector2(400, 240));
}
else if (clockMode == CLOCK_DIGITAL)
{
DrawClockDigital(clock, new Vector2(30, 60));

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DoublePendulum : IExample

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DrawCircleSector : IExample
@ -106,16 +102,30 @@ public partial class DrawCircleSector : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -15,8 +15,6 @@
*
********************************************************************************************/
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DrawRectangleRounded : IExample
@ -119,27 +117,51 @@ public partial class DrawRectangleRounded : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiCheckBox(Rectangle bounds, string text, ref bool active)
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class DrawRing : IExample
@ -149,27 +145,51 @@ public partial class DrawRing : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiCheckBox(Rectangle bounds, string text, ref bool active)
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -13,7 +13,6 @@
*
********************************************************************************************/
using static Raylib_cs.Raylib;
using Examples.Shared;
namespace Examples.Shapes;

View file

@ -13,8 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using Examples.Shared;
namespace Examples.Shapes;

View file

@ -16,8 +16,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using Examples.Shared;
namespace Examples.Shapes;

View file

@ -15,10 +15,7 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using Examples.Shared;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
@ -112,19 +109,31 @@ public partial class EasingsTestbed : IExample
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KeyboardKey.T)) boundedT = !boundedT;
if (IsKeyPressed(KeyboardKey.T))
{
boundedT = !boundedT;
}
// Choose easing for the X axis
if (IsKeyPressed(KeyboardKey.Right))
{
easingX++;
if (easingX > EASING_NONE) easingX = 0;
if (easingX > EASING_NONE)
{
easingX = 0;
}
}
else if (IsKeyPressed(KeyboardKey.Left))
{
if (easingX == 0) easingX = EASING_NONE;
else easingX--;
if (easingX == 0)
{
easingX = EASING_NONE;
}
else
{
easingX--;
}
}
// Choose easing for the Y axis
@ -132,20 +141,41 @@ public partial class EasingsTestbed : IExample
{
easingY++;
if (easingY > EASING_NONE) easingY = 0;
if (easingY > EASING_NONE)
{
easingY = 0;
}
}
else if (IsKeyPressed(KeyboardKey.Up))
{
if (easingY == 0) easingY = EASING_NONE;
else easingY--;
if (easingY == 0)
{
easingY = EASING_NONE;
}
else
{
easingY--;
}
}
// Change d (duration) value
if (IsKeyPressed(KeyboardKey.W) && (d < D_MAX - D_STEP)) d += D_STEP;
else if (IsKeyPressed(KeyboardKey.Q) && (d > D_MIN + D_STEP)) d -= D_STEP;
if (IsKeyPressed(KeyboardKey.W) && (d < D_MAX - D_STEP))
{
d += D_STEP;
}
else if (IsKeyPressed(KeyboardKey.Q) && (d > D_MIN + D_STEP))
{
d -= D_STEP;
}
if (IsKeyDown(KeyboardKey.S) && (d < D_MAX - D_STEP_FINE)) d += D_STEP_FINE;
else if (IsKeyDown(KeyboardKey.A) && (d > D_MIN + D_STEP_FINE)) d -= D_STEP_FINE;
if (IsKeyDown(KeyboardKey.S) && (d < D_MAX - D_STEP_FINE))
{
d += D_STEP_FINE;
}
else if (IsKeyDown(KeyboardKey.A) && (d > D_MIN + D_STEP_FINE))
{
d -= D_STEP_FINE;
}
// Play, pause and restart controls
if (IsKeyPressed(KeyboardKey.Space) || IsKeyPressed(KeyboardKey.T) ||
@ -161,7 +191,10 @@ public partial class EasingsTestbed : IExample
paused = true;
}
if (IsKeyPressed(KeyboardKey.Enter)) paused = !paused;
if (IsKeyPressed(KeyboardKey.Enter))
{
paused = !paused;
}
// Movement computation
if (!paused && ((boundedT && t < d) || !boundedT))

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class EllipseCollision : IExample

View file

@ -13,11 +13,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using Raylib_cs;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class FollowingEyes : IExample

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class HilbertCurve : IExample
@ -64,8 +61,14 @@ public partial class HilbertCurve : IExample
{
hilbertPath = LoadHilbertPath(order, size, out strokeCount);
if (animate) counter = 0;
else counter = strokeCount;
if (animate)
{
counter = 0;
}
else
{
counter = strokeCount;
}
prevOrder = order;
prevSize = (int)size;
@ -190,11 +193,21 @@ public partial class HilbertCurve : IExample
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiSpinner(Rectangle bounds, string text, ref int value, int minValue, int maxValue)
@ -204,8 +217,15 @@ public partial class HilbertCurve : IExample
Rectangle right = new Rectangle(bounds.X + bounds.Width - bounds.Height, bounds.Y, bounds.Height, bounds.Height);
Rectangle mid = new Rectangle(bounds.X + bounds.Height, bounds.Y, bounds.Width - 2 * bounds.Height, bounds.Height);
if (CheckCollisionPointRec(mouse, left) && IsMouseButtonPressed(MouseButton.Left) && value > minValue) value--;
if (CheckCollisionPointRec(mouse, right) && IsMouseButtonPressed(MouseButton.Left) && value < maxValue) value++;
if (CheckCollisionPointRec(mouse, left) && IsMouseButtonPressed(MouseButton.Left) && value > minValue)
{
value--;
}
if (CheckCollisionPointRec(mouse, right) && IsMouseButtonPressed(MouseButton.Left) && value < maxValue)
{
value++;
}
DrawRectangleRec(mid, Color.RayWhite);
DrawRectangleLinesEx(mid, 1, Color.Gray);
@ -217,7 +237,10 @@ public partial class HilbertCurve : IExample
DrawText("+", (int)(right.X + right.Width / 2 - 3), (int)(right.Y + right.Height / 2 - 5), 10, Color.DarkGray);
string vs = value.ToString();
DrawText(vs, (int)(mid.X + mid.Width / 2 - MeasureText(vs, 10) / 2), (int)(mid.Y + mid.Height / 2 - 5), 10, Color.DarkGray);
if (text != null) DrawText(text, (int)bounds.X - MeasureText(text, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (text != null)
{
DrawText(text, (int)bounds.X - MeasureText(text, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiSlider(Rectangle bounds, string textLeft, string textRight, ref float value, float minValue, float maxValue)
@ -227,8 +250,15 @@ public partial class HilbertCurve : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
@ -236,8 +266,15 @@ public partial class HilbertCurve : IExample
float handleX = bounds.X + pct * bounds.Width;
DrawRectangle((int)(handleX - 5), (int)bounds.Y, 10, (int)bounds.Height, Color.DarkGray);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (textLeft != null) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (textRight != null) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (textLeft != null)
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (textRight != null)
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
namespace Examples.Shapes;

View file

@ -13,9 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class LinesBezier : IExample

View file

@ -15,8 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
namespace Examples.Shapes;
@ -71,7 +69,10 @@ public partial class LinesDrawing : IExample
// Update
//----------------------------------------------------------------------------------
// Disable the hint text once the user clicks
if (IsMouseButtonPressed(MouseButton.Left) && startText) startText = false;
if (IsMouseButtonPressed(MouseButton.Left) && startText)
{
startText = false;
}
// Clear the canvas when the user middle-clicks
if (IsMouseButtonPressed(MouseButton.Middle))
@ -97,12 +98,18 @@ public partial class LinesDrawing : IExample
// While the hue is >=360, subtract it to bring it down into the range 0-360
// This is more visually accurate than resetting to zero
while (lineHue >= 360.0f) lineHue -= 360.0f;
while (lineHue >= 360.0f)
{
lineHue -= 360.0f;
}
// Create the final color
drawColor = ColorFromHSV(lineHue, 1.0f, 1.0f);
}
else if (rightButtonDown) drawColor = Color.RayWhite; // Use the background color as an "eraser"
else if (rightButtonDown)
{
drawColor = Color.RayWhite; // Use the background color as an "eraser"
}
// Draw the line onto the canvas
BeginTextureMode(canvas);
@ -129,10 +136,16 @@ public partial class LinesDrawing : IExample
DrawTextureRec(canvas.Texture, new Rectangle(0.0f, 0.0f, (float)canvas.Texture.Width, (float)-canvas.Texture.Height), Vector2Zero(), Color.White);
// Draw the preview circle
if (!leftButtonDown) DrawCircleLinesV(GetMousePosition(), lineThickness/2.0f, new Color(127, 127, 127, 127));
if (!leftButtonDown)
{
DrawCircleLinesV(GetMousePosition(), lineThickness/2.0f, new Color(127, 127, 127, 127));
}
// Draw the hint text
if (startText) DrawText("try clicking and dragging!", 275, 215, 20, Color.LightGray);
// Draw the hint text
if (startText)
{
DrawText("try clicking and dragging!", 275, 215, 20, Color.LightGray);
}
EndDrawing();
//----------------------------------------------------------------------------------

View file

@ -13,8 +13,6 @@
*
********************************************************************************************/
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class LogoRaylibAnim : IExample

View file

@ -13,8 +13,6 @@
*
********************************************************************************************/
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class LogoRaylibShape : IExample

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class MathAngleRotation : IExample
@ -59,7 +55,10 @@ public partial class MathAngleRotation : IExample
// Update
//----------------------------------------------------------------------------------
totalAngle += 1.0f; // degrees per frame
if (totalAngle >= 360.0f) totalAngle -= 360.0f;
if (totalAngle >= 360.0f)
{
totalAngle -= 360.0f;
}
//----------------------------------------------------------------------------------
// Draw

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
namespace Examples.Shapes;
@ -122,14 +119,20 @@ public partial class MathSineCosine : IExample
DrawLineDashed(new Vector2(point.X, center.Y), new Vector2(point.X, point.Y), 10, 4, Color.Red);
DrawText($"Sine {sinRad:0.00}", 640, 190, 6, Color.Red);
DrawCircleV(new Vector2(start.X + (angle / 360.0f) * start.Width, start.Y + ((-sinRad + 1) * start.Height / 2.0f)), 4.0f, Color.Red);
fixed (Vector2* p = sinePoints) DrawSplineLinear(p, WAVE_POINTS, 1.0f, Color.Red);
fixed (Vector2* p = sinePoints)
{
DrawSplineLinear(p, WAVE_POINTS, 1.0f, Color.Red);
}
// Cosine (blue - horizontal)
DrawLineEx(new Vector2(center.X, center.Y), new Vector2(point.X, center.Y), 2.0f, Color.Blue);
DrawLineDashed(new Vector2(center.X, point.Y), new Vector2(point.X, point.Y), 10, 4, Color.Blue);
DrawText($"Cosine {cosRad:0.00}", 640, 210, 6, Color.Blue);
DrawCircleV(new Vector2(start.X + (angle / 360.0f) * start.Width, start.Y + ((-cosRad + 1) * start.Height / 2.0f)), 4.0f, Color.Blue);
fixed (Vector2* p = cosPoints) DrawSplineLinear(p, WAVE_POINTS, 1.0f, Color.Blue);
fixed (Vector2* p = cosPoints)
{
DrawSplineLinear(p, WAVE_POINTS, 1.0f, Color.Blue);
}
// Tangent (purple)
DrawLineEx(new Vector2(limitMax.X, center.Y), new Vector2(limitMax.X, tangentPoint.Y), 2.0f, Color.Purple);

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class MouseTrail : IExample

View file

@ -16,11 +16,7 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
@ -79,7 +75,10 @@ public partial class PenroseTile : IExample
// Initialize new penrose tile
ls = CreatePenroseLSystem(drawLength * (generations / (float)maxGenerations));
for (int i = 0; i < generations; i++) BuildProductionStep(ls);
for (int i = 0; i < generations; i++)
{
BuildProductionStep(ls);
}
}
public void Update()
@ -100,14 +99,20 @@ public partial class PenroseTile : IExample
if (generations > minGenerations)
{
generations--;
if (generations > 0) rebuild = true;
if (generations > 0)
{
rebuild = true;
}
}
}
if (rebuild)
{
ls = CreatePenroseLSystem(drawLength * (generations / (float)maxGenerations));
for (int i = 0; i < generations; i++) BuildProductionStep(ls);
for (int i = 0; i < generations; i++)
{
BuildProductionStep(ls);
}
}
//----------------------------------------------------------------------------------
@ -117,7 +122,10 @@ public partial class PenroseTile : IExample
ClearBackground(Color.RayWhite);
if (generations > 0) DrawPenroseLSystem(ls);
if (generations > 0)
{
DrawPenroseLSystem(ls);
}
DrawText("penrose l-system", 10, 10, 20, Color.DarkGray);
DrawText("press up or down to change generations", 10, 30, 20, Color.DarkGray);
@ -143,8 +151,14 @@ public partial class PenroseTile : IExample
// Pop turtle state step
private TurtleState PopTurtleState()
{
if (turtleStack.Count > 0) return turtleStack.Pop();
else TraceLog(TraceLogLevel.Warning, "TURTLE STACK UNDERFLOW!");
if (turtleStack.Count > 0)
{
return turtleStack.Pop();
}
else
{
TraceLog(TraceLogLevel.Warning, "TURTLE STACK UNDERFLOW!");
}
return new TurtleState();
}
@ -186,8 +200,11 @@ public partial class PenroseTile : IExample
case 'Z': newProduction.Append(ls.ruleZ); break;
default:
{
if (step != 'F') newProduction.Append(step);
} break;
if (step != 'F')
{
newProduction.Append(step);
}
} break;
}
}
@ -211,7 +228,10 @@ public partial class PenroseTile : IExample
int productionLength = production.Length;
ls.steps += 12;
if (ls.steps > productionLength) ls.steps = productionLength;
if (ls.steps > productionLength)
{
ls.steps = productionLength;
}
for (int i = 0; i < ls.steps; i++)
{
@ -234,19 +254,34 @@ public partial class PenroseTile : IExample
}
else if (step == '+')
{
for (int j = 0; j < repeats; j++) turtle.angle += ls.theta;
for (int j = 0; j < repeats; j++)
{
turtle.angle += ls.theta;
}
repeats = 1;
}
else if (step == '-')
{
for (int j = 0; j < repeats; j++) turtle.angle += -ls.theta;
for (int j = 0; j < repeats; j++)
{
turtle.angle += -ls.theta;
}
repeats = 1;
}
else if (step == '[') PushTurtleState(turtle);
else if (step == ']') turtle = PopTurtleState();
else if ((step >= 48) && (step <= 57)) repeats = (int)step - 48;
else if (step == '[')
{
PushTurtleState(turtle);
}
else if (step == ']')
{
turtle = PopTurtleState();
}
else if ((step >= 48) && (step <= 57))
{
repeats = (int)step - 48;
}
}
turtleStack.Clear();

View file

@ -15,10 +15,7 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using System.Text;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
@ -71,7 +68,10 @@ public partial class PieChart : IExample
labels = new StringBuilder[MAX_PIE_SLICES];
editingLabel = new bool[MAX_PIE_SLICES];
for (int i = 0; i < MAX_PIE_SLICES; i++) labels[i] = new StringBuilder($"Slice {i + 1:D2}");
for (int i = 0; i < MAX_PIE_SLICES; i++)
{
labels[i] = new StringBuilder($"Slice {i + 1:D2}");
}
showValues = true;
showPercentages = false;
@ -110,7 +110,10 @@ public partial class PieChart : IExample
//----------------------------------------------------------------------------------
// Calculate total value for percentage calculations
totalValue = 0.0f;
for (int i = 0; i < sliceCount; i++) totalValue += values[i];
for (int i = 0; i < sliceCount; i++)
{
totalValue += values[i];
}
// Check for mouse hover over slices
hoveredSlice = -1; // Reset hovered slice
@ -124,7 +127,10 @@ public partial class PieChart : IExample
if (distance <= radius) // Inside the pie radius
{
float angle = MathF.Atan2(dy, dx) * RAD2DEG;
if (angle < 0) angle += 360;
if (angle < 0)
{
angle += 360;
}
float currentAngle = 0.0f;
for (int i = 0; i < sliceCount; i++)
@ -159,7 +165,10 @@ public partial class PieChart : IExample
float currentRadius = radius;
// Make the hovered slice pop out by adding pixels to its radius
if (i == hoveredSlice) currentRadius += 20.0f;
if (i == hoveredSlice)
{
currentRadius += 20.0f;
}
// Draw the pie slice using raylib's DrawCircleSector function
DrawCircleSector(center, currentRadius, startAngle, startAngle + sweepAngle, 120, color);
@ -168,10 +177,22 @@ public partial class PieChart : IExample
if (values[i] > 0)
{
string labelText;
if (showValues && showPercentages) labelText = $"{values[i]:F1} ({(values[i] / totalValue) * 100.0f:F0}%)";
else if (showValues) labelText = $"{values[i]:F1}";
else if (showPercentages) labelText = $"{(values[i] / totalValue) * 100.0f:F0}%";
else labelText = "";
if (showValues && showPercentages)
{
labelText = $"{values[i]:F1} ({(values[i] / totalValue) * 100.0f:F0}%)";
}
else if (showValues)
{
labelText = $"{values[i]:F1}";
}
else if (showPercentages)
{
labelText = $"{(values[i] / totalValue) * 100.0f:F0}%";
}
else
{
labelText = "";
}
Vector2 textSize = MeasureTextEx(GetFontDefault(), labelText, 20, 1);
float labelRadius = radius * 0.7f;
@ -182,7 +203,10 @@ public partial class PieChart : IExample
// Draw inner circle to create donut effect
// TODO: This is a hacky solution, better use DrawRing()
if (showDonut) DrawCircleV(center, donutInnerRadius, Color.RayWhite);
if (showDonut)
{
DrawCircleV(center, donutInnerRadius, Color.RayWhite);
}
startAngle += sweepAngle;
}
@ -196,7 +220,11 @@ public partial class PieChart : IExample
GuiCheckBox(new Rectangle(panelPos.X + 20, (float)panelPos.Y + 12 + 70, 20, 20), "Show Percentages", ref showPercentages);
GuiCheckBox(new Rectangle(panelPos.X + 20, (float)panelPos.Y + 12 + 100, 20, 20), "Make Donut", ref showDonut);
if (showDonut) GuiDisable();
if (showDonut)
{
GuiDisable();
}
GuiSliderBar(new Rectangle(panelPos.X + 80, (float)panelPos.Y + 12 + 130, panelRect.Width - 100, 30),
"Inner Radius", null, ref donutInnerRadius, 5.0f, radius - 10.0f);
GuiEnable();
@ -217,8 +245,15 @@ public partial class PieChart : IExample
{
scrollContentOffset.Y += GetMouseWheelMove() * 20.0f;
float minOffset = MathF.Min(0.0f, scrollPanelBounds.Height - contentHeight);
if (scrollContentOffset.Y < minOffset) scrollContentOffset.Y = minOffset;
if (scrollContentOffset.Y > 0.0f) scrollContentOffset.Y = 0.0f;
if (scrollContentOffset.Y < minOffset)
{
scrollContentOffset.Y = minOffset;
}
if (scrollContentOffset.Y > 0.0f)
{
scrollContentOffset.Y = 0.0f;
}
}
Rectangle view = scrollPanelBounds;
@ -236,7 +271,10 @@ public partial class PieChart : IExample
DrawRectangle((int)(contentX + 15), rowY + 5, 20, 20, color);
// Label textbox
if (GuiTextBox(new Rectangle(contentX + 45, (float)rowY, 75, 30), labels[i], 32, editingLabel[i])) editingLabel[i] = !editingLabel[i];
if (GuiTextBox(new Rectangle(contentX + 45, (float)rowY, 75, 30), labels[i], 32, editingLabel[i]))
{
editingLabel[i] = !editingLabel[i];
}
GuiSliderBar(new Rectangle(contentX + 130, (float)rowY, 110, 30), null, null, ref values[i], 0.0f, 1000.0f);
}
@ -267,11 +305,21 @@ public partial class PieChart : IExample
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (!guiDisabled && hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (!guiDisabled && hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiSpinner(Rectangle bounds, string text, ref int value, int minValue, int maxValue)
@ -281,8 +329,15 @@ public partial class PieChart : IExample
Rectangle right = new Rectangle(bounds.X + bounds.Width - bounds.Height, bounds.Y, bounds.Height, bounds.Height);
Rectangle mid = new Rectangle(bounds.X + bounds.Height, bounds.Y, bounds.Width - 2 * bounds.Height, bounds.Height);
if (!guiDisabled && CheckCollisionPointRec(mouse, left) && IsMouseButtonPressed(MouseButton.Left) && value > minValue) value--;
if (!guiDisabled && CheckCollisionPointRec(mouse, right) && IsMouseButtonPressed(MouseButton.Left) && value < maxValue) value++;
if (!guiDisabled && CheckCollisionPointRec(mouse, left) && IsMouseButtonPressed(MouseButton.Left) && value > minValue)
{
value--;
}
if (!guiDisabled && CheckCollisionPointRec(mouse, right) && IsMouseButtonPressed(MouseButton.Left) && value < maxValue)
{
value++;
}
DrawRectangleRec(mid, Color.RayWhite);
DrawRectangleLinesEx(mid, 1, Color.Gray);
@ -294,7 +349,10 @@ public partial class PieChart : IExample
DrawText("+", (int)(right.X + right.Width / 2 - 3), (int)(right.Y + right.Height / 2 - 5), 10, Color.DarkGray);
string vs = value.ToString();
DrawText(vs, (int)(mid.X + mid.Width / 2 - MeasureText(vs, 10) / 2), (int)(mid.Y + mid.Height / 2 - 5), 10, Color.DarkGray);
if (text != null) DrawText(text, (int)bounds.X - MeasureText(text, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (text != null)
{
DrawText(text, (int)bounds.X - MeasureText(text, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiSliderBar(Rectangle bounds, string textLeft, string textRight, ref float value, float minValue, float maxValue)
@ -304,16 +362,30 @@ public partial class PieChart : IExample
if (!guiDisabled && hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, guiDisabled ? Color.Gray : Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), guiDisabled ? Color.DarkGray : Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private bool GuiTextBox(Rectangle bounds, StringBuilder text, int maxChars, bool editMode)
@ -335,7 +407,10 @@ public partial class PieChart : IExample
key = GetCharPressed();
}
if (IsKeyPressed(KeyboardKey.Backspace) && (text.Length > 0)) text.Remove(text.Length - 1, 1);
if (IsKeyPressed(KeyboardKey.Backspace) && (text.Length > 0))
{
text.Remove(text.Length - 1, 1);
}
}
DrawRectangleRec(bounds, Color.RayWhite);
@ -349,7 +424,10 @@ public partial class PieChart : IExample
DrawText("_", (int)bounds.X + 4 + MeasureText(content, 10), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (hover && IsMouseButtonPressed(MouseButton.Left)) pressed = true;
if (hover && IsMouseButtonPressed(MouseButton.Left))
{
pressed = true;
}
return pressed;
}

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Rlgl;
namespace Examples.Shapes;
@ -88,18 +85,35 @@ public partial class RectangleAdvanced : IExample
return;
}
if (roundnessLeft >= 1.0f) roundnessLeft = 1.0f;
if (roundnessRight >= 1.0f) roundnessRight = 1.0f;
if (roundnessLeft >= 1.0f)
{
roundnessLeft = 1.0f;
}
if (roundnessRight >= 1.0f)
{
roundnessRight = 1.0f;
}
// Calculate corner radius both from right and left
float recSize = rec.Width > rec.Height ? rec.Height : rec.Width;
float radiusLeft = (recSize * roundnessLeft) / 2;
float radiusRight = (recSize * roundnessRight) / 2;
if (radiusLeft <= 0.0f) radiusLeft = 0.0f;
if (radiusRight <= 0.0f) radiusRight = 0.0f;
if (radiusLeft <= 0.0f)
{
radiusLeft = 0.0f;
}
if (radiusRight <= 0.0f && radiusLeft <= 0.0f) return;
if (radiusRight <= 0.0f)
{
radiusRight = 0.0f;
}
if (radiusRight <= 0.0f && radiusLeft <= 0.0f)
{
return;
}
float stepLength = 90.0f / (float)segments;

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class RectangleScaling : IExample

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class RecursiveTree : IExample
@ -78,7 +74,10 @@ public partial class RecursiveTree : IExample
for (int i = 0; i < count; i++)
{
Branch branch = branches[i];
if (branch.length < 2) continue;
if (branch.length < 2)
{
continue;
}
float nextLength = branch.length * branchDecay;
@ -108,8 +107,14 @@ public partial class RecursiveTree : IExample
Branch branch = branches[i];
if (branch.length >= 2)
{
if (bezier) DrawLineBezier(branch.start, branch.end, thick, Color.Red);
else DrawLineEx(branch.start, branch.end, thick, Color.Red);
if (bezier)
{
DrawLineBezier(branch.start, branch.end, thick, Color.Red);
}
else
{
DrawLineEx(branch.start, branch.end, thick, Color.Red);
}
}
}
@ -146,27 +151,51 @@ public partial class RecursiveTree : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (textLeft != null) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (textRight != null) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (textLeft != null)
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (textRight != null)
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiCheckBox(Rectangle bounds, string text, ref bool active)
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -15,9 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
using static Raylib_cs.Rlgl;
@ -146,27 +143,48 @@ public partial class RlglColorWheel : IExample
}
// Update flag when mouse button is released
if (IsMouseButtonReleased(MouseButton.Left)) settingColor = false;
if (IsMouseButtonReleased(MouseButton.Left))
{
settingColor = false;
}
// Check if the user clicked/released the slider for the color's value
if (sliderHover && IsMouseButtonPressed(MouseButton.Left)) sliderClicked = true;
if (sliderHover && IsMouseButtonPressed(MouseButton.Left))
{
sliderClicked = true;
}
if (sliderClicked && IsMouseButtonReleased(MouseButton.Left)) sliderClicked = false;
if (sliderClicked && IsMouseButtonReleased(MouseButton.Left))
{
sliderClicked = false;
}
// Update render mode accordingly
if (IsKeyPressed(KeyboardKey.Space)) renderType = DrawMode.Lines;
if (IsKeyPressed(KeyboardKey.Space))
{
renderType = DrawMode.Lines;
}
if (IsKeyReleased(KeyboardKey.Space)) renderType = DrawMode.Triangles;
if (IsKeyReleased(KeyboardKey.Space))
{
renderType = DrawMode.Triangles;
}
// If the slider or the wheel was clicked, update the current color
if (settingColor || sliderClicked)
{
if (settingColor) circlePosition = GetMousePosition();
if (settingColor)
{
circlePosition = GetMousePosition();
}
float distance = Vector2Distance(center, circlePosition) / pointScale;
float angle = ((Vector2Angle(new Vector2(0.0f, -pointScale), Vector2Subtract(center, circlePosition)) / MathF.PI + 1.0f) / 2.0f);
if (settingColor && distance > 1.0f) circlePosition = Vector2Add(new Vector2(MathF.Sin(angle * (MathF.PI * 2.0f)) * pointScale, -MathF.Cos(angle * (MathF.PI * 2.0f)) * pointScale), center);
if (settingColor && distance > 1.0f)
{
circlePosition = Vector2Add(new Vector2(MathF.Sin(angle * (MathF.PI * 2.0f)) * pointScale, -MathF.Cos(angle * (MathF.PI * 2.0f)) * pointScale), center);
}
float angle360 = angle * 360.0f;
float valueActual = Clamp(distance, 0.0f, 1.0f);
@ -288,16 +306,30 @@ public partial class RlglColorWheel : IExample
if (hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
public static int Main()

View file

@ -15,8 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Rlgl;
namespace Examples.Shapes;
@ -57,7 +55,10 @@ public partial class RlglTriangle : IExample
{
// Update
//----------------------------------------------------------------------------------
if (IsKeyPressed(KeyboardKey.Space)) linesMode = !linesMode;
if (IsKeyPressed(KeyboardKey.Space))
{
linesMode = !linesMode;
}
// Check selected vertex
for (int i = 0; i < 3; i++)
@ -80,11 +81,21 @@ public partial class RlglTriangle : IExample
}
// Reset index on release
if (IsMouseButtonReleased(MouseButton.Left)) triangleIndex = -1;
if (IsMouseButtonReleased(MouseButton.Left))
{
triangleIndex = -1;
}
// Enable/disable backface culling (2-sided triangles, slower to render)
if (IsKeyPressed(KeyboardKey.Left)) EnableBackfaceCulling();
if (IsKeyPressed(KeyboardKey.Right)) DisableBackfaceCulling();
if (IsKeyPressed(KeyboardKey.Left))
{
EnableBackfaceCulling();
}
if (IsKeyPressed(KeyboardKey.Right))
{
DisableBackfaceCulling();
}
// Reset triangle vertices to starting positions and reset backface culling
if (IsKeyPressed(KeyboardKey.R))
@ -147,10 +158,15 @@ public partial class RlglTriangle : IExample
{
// Draw handle fill focused by mouse
if (CheckCollisionPointCircle(GetMousePosition(), trianglePositions[i], handleRadius))
{
DrawCircleV(trianglePositions[i], handleRadius, ColorAlpha(Color.DarkGray, 0.5f));
}
// Draw handle fill selected
if (i == triangleIndex) DrawCircleV(trianglePositions[i], handleRadius, Color.DarkGray);
if (i == triangleIndex)
{
DrawCircleV(trianglePositions[i], handleRadius, Color.DarkGray);
}
// Draw handle outline
DrawCircleLinesV(trianglePositions[i], handleRadius, Color.Black);

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class SimpleParticles : IExample
@ -90,11 +86,17 @@ public partial class SimpleParticles : IExample
// Emit new particles: when emissionRate is 1, emit every frame
if (emissionRate < 0)
{
if (random.Next(-emissionRate) == 0) EmitParticle(emitterPosition, currentType);
if (random.Next(-emissionRate) == 0)
{
EmitParticle(emitterPosition, currentType);
}
}
else
{
for (int i = 0; i <= emissionRate; i++) EmitParticle(emitterPosition, currentType);
for (int i = 0; i <= emissionRate; i++)
{
EmitParticle(emitterPosition, currentType);
}
}
// Update the parameters of each particle
@ -104,14 +106,31 @@ public partial class SimpleParticles : IExample
UpdateCircularBuffer();
// Change Particle Emission Rate (UP/DOWN arrows)
if (IsKeyPressed(KeyboardKey.Up)) emissionRate++;
if (IsKeyPressed(KeyboardKey.Down)) emissionRate--;
if (IsKeyPressed(KeyboardKey.Up))
{
emissionRate++;
}
if (IsKeyPressed(KeyboardKey.Down))
{
emissionRate--;
}
// Change Particle Type (LEFT/RIGHT arrows)
if (IsKeyPressed(KeyboardKey.Right)) currentType = (currentType == ParticleType.Fire) ? ParticleType.Water : (ParticleType)((int)currentType + 1);
if (IsKeyPressed(KeyboardKey.Left)) currentType = (currentType == ParticleType.Water) ? ParticleType.Fire : (ParticleType)((int)currentType - 1);
if (IsKeyPressed(KeyboardKey.Right))
{
currentType = (currentType == ParticleType.Fire) ? ParticleType.Water : (ParticleType)((int)currentType + 1);
}
if (IsMouseButtonDown(MouseButton.Left)) emitterPosition = GetMousePosition();
if (IsKeyPressed(KeyboardKey.Left))
{
currentType = (currentType == ParticleType.Water) ? ParticleType.Fire : (ParticleType)((int)currentType - 1);
}
if (IsMouseButtonDown(MouseButton.Left))
{
emitterPosition = GetMousePosition();
}
//----------------------------------------------------------------------------------
// Draw
@ -131,8 +150,14 @@ public partial class SimpleParticles : IExample
DrawText("UP/DOWN: Change Particle Emission Rate", 15, 35, 10, Color.Black);
DrawText("LEFT/RIGHT: Change Particle Type (Water, Smoke, Fire)", 15, 55, 10, Color.Black);
if (emissionRate < 0) DrawText($"Particles every {-emissionRate} frames | Type: {particleTypeNames[(int)currentType]}", 15, 95, 10, Color.DarkGray);
else DrawText($"{emissionRate + 1} Particles per frame | Type: {particleTypeNames[(int)currentType]}", 15, 95, 10, Color.DarkGray);
if (emissionRate < 0)
{
DrawText($"Particles every {-emissionRate} frames | Type: {particleTypeNames[(int)currentType]}", 15, 95, 10, Color.DarkGray);
}
else
{
DrawText($"{emissionRate + 1} Particles per frame | Type: {particleTypeNames[(int)currentType]}", 15, 95, 10, Color.DarkGray);
}
DrawFPS(screenWidth - 80, 10);
@ -227,8 +252,11 @@ public partial class SimpleParticles : IExample
buffer[i].color.A -= 4; // Decrement alpha: smoke fades
// If alpha transparent, particle dies
if (buffer[i].color.A < 4) buffer[i].alive = false;
} break;
if (buffer[i].color.A < 4)
{
buffer[i].alive = false;
}
} break;
case ParticleType.Fire:
{
// Add a little horizontal oscillation to fire particles
@ -239,8 +267,11 @@ public partial class SimpleParticles : IExample
buffer[i].color.G -= 3; // Decrement green: fire turns reddish starting from yellow
// If radius too small, particle dies
if (buffer[i].radius <= 0.02f) buffer[i].alive = false;
} break;
if (buffer[i].radius <= 0.02f)
{
buffer[i].alive = false;
}
} break;
default: break;
}

View file

@ -13,9 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class SplinesDrawing : IExample
@ -131,14 +128,20 @@ public partial class SplinesDrawing : IExample
break;
}
}
if (IsMouseButtonPressed(MouseButton.Left)) selectedPoint = focusedPoint;
if (IsMouseButtonPressed(MouseButton.Left))
{
selectedPoint = focusedPoint;
}
}
// Spline point movement logic
if (selectedPoint >= 0)
{
points[selectedPoint] = GetMousePosition();
if (IsMouseButtonReleased(MouseButton.Left)) selectedPoint = -1;
if (IsMouseButtonReleased(MouseButton.Left))
{
selectedPoint = -1;
}
}
// Cubic Bezier spline control points logic
@ -173,20 +176,45 @@ public partial class SplinesDrawing : IExample
// Spline control point movement logic
if (selectedControlIndex != -1)
{
if (selectedControlStart) control[selectedControlIndex].start = GetMousePosition();
else control[selectedControlIndex].end = GetMousePosition();
if (IsMouseButtonReleased(MouseButton.Left)) selectedControlIndex = -1;
if (selectedControlStart)
{
control[selectedControlIndex].start = GetMousePosition();
}
else
{
control[selectedControlIndex].end = GetMousePosition();
}
if (IsMouseButtonReleased(MouseButton.Left))
{
selectedControlIndex = -1;
}
}
}
// Spline selection logic
if (IsKeyPressed(KeyboardKey.One)) splineTypeActive = 0;
else if (IsKeyPressed(KeyboardKey.Two)) splineTypeActive = 1;
else if (IsKeyPressed(KeyboardKey.Three)) splineTypeActive = 2;
else if (IsKeyPressed(KeyboardKey.Four)) splineTypeActive = 3;
if (IsKeyPressed(KeyboardKey.One))
{
splineTypeActive = 0;
}
else if (IsKeyPressed(KeyboardKey.Two))
{
splineTypeActive = 1;
}
else if (IsKeyPressed(KeyboardKey.Three))
{
splineTypeActive = 2;
}
else if (IsKeyPressed(KeyboardKey.Four))
{
splineTypeActive = 3;
}
// Clear selection when changing to a spline without control points
if (IsKeyPressed(KeyboardKey.One) || IsKeyPressed(KeyboardKey.Two) || IsKeyPressed(KeyboardKey.Three)) selectedControlIndex = -1;
if (IsKeyPressed(KeyboardKey.One) || IsKeyPressed(KeyboardKey.Two) || IsKeyPressed(KeyboardKey.Three))
{
selectedControlIndex = -1;
}
//----------------------------------------------------------------------------------
// Draw
@ -232,8 +260,15 @@ public partial class SplinesDrawing : IExample
// Every cubic bezier point have two control points
DrawCircleV(control[i].start, 6, Color.Gold);
DrawCircleV(control[i].end, 6, Color.Gold);
if (focusedControlIndex == i && focusedControlStart) DrawCircleV(control[i].start, 8, Color.Green);
else if (focusedControlIndex == i && !focusedControlStart) DrawCircleV(control[i].end, 8, Color.Green);
if (focusedControlIndex == i && focusedControlStart)
{
DrawCircleV(control[i].start, 8, Color.Green);
}
else if (focusedControlIndex == i && !focusedControlStart)
{
DrawCircleV(control[i].end, 8, Color.Green);
}
DrawLineEx(points[i], control[i].start, 1.0f, Color.LightGray);
DrawLineEx(points[i + 1], control[i].end, 1.0f, Color.LightGray);
@ -251,14 +286,20 @@ public partial class SplinesDrawing : IExample
DrawCircleLinesV(points[i], (focusedPoint == i) ? 12.0f : 8.0f, (focusedPoint == i) ? Color.Blue : Color.DarkBlue);
if ((splineTypeActive != SPLINE_LINEAR) &&
(splineTypeActive != SPLINE_BEZIER) &&
(i < pointCount - 1)) DrawLineV(points[i], points[i + 1], Color.Gray);
(i < pointCount - 1))
{
DrawLineV(points[i], points[i + 1], Color.Gray);
}
DrawText($"[{points[i].X:F0}, {points[i].Y:F0}]", (int)points[i].X, (int)points[i].Y + 10, 10, Color.Black);
}
}
// Check all possible UI states that require controls lock
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlIndex != -1)) GuiLock();
if (splineTypeEditMode || (selectedPoint != -1) || (selectedControlIndex != -1))
{
GuiLock();
}
// Draw spline config
GuiLabel(new Rectangle(12, 62, 140, 24), $"Spline thickness: {(int)splineThickness}");
@ -266,10 +307,16 @@ public partial class SplinesDrawing : IExample
GuiCheckBox(new Rectangle(12, 110, 20, 20), "Show point helpers", ref splineHelpersActive);
if (splineTypeEditMode) GuiUnlock();
if (splineTypeEditMode)
{
GuiUnlock();
}
GuiLabel(new Rectangle(12, 10, 140, 24), "Spline type:");
if (GuiDropdownBox(new Rectangle(12, 8 + 24, 140, 28), "LINEAR;BSPLINE;CATMULLROM;BEZIER", ref splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
if (GuiDropdownBox(new Rectangle(12, 8 + 24, 140, 28), "LINEAR;BSPLINE;CATMULLROM;BEZIER", ref splineTypeActive, splineTypeEditMode))
{
splineTypeEditMode = !splineTypeEditMode;
}
GuiUnlock();
@ -299,27 +346,51 @@ public partial class SplinesDrawing : IExample
if (!guiLocked && hover && IsMouseButtonDown(MouseButton.Left))
{
value = minValue + ((mouse.X - bounds.X) / bounds.Width) * (maxValue - minValue);
if (value < minValue) value = minValue;
if (value > maxValue) value = maxValue;
if (value < minValue)
{
value = minValue;
}
if (value > maxValue)
{
value = maxValue;
}
}
DrawRectangleRec(bounds, Color.LightGray);
float pct = (value - minValue) / (maxValue - minValue);
DrawRectangleRec(new Rectangle(bounds.X, bounds.Y, bounds.Width * pct, bounds.Height), Color.SkyBlue);
DrawRectangleLinesEx(bounds, 1, Color.Gray);
if (!string.IsNullOrEmpty(textLeft)) DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textRight)) DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (!string.IsNullOrEmpty(textLeft))
{
DrawText(textLeft, (int)bounds.X - MeasureText(textLeft, 10) - 5, (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
if (!string.IsNullOrEmpty(textRight))
{
DrawText(textRight, (int)(bounds.X + bounds.Width + 5), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static void GuiCheckBox(Rectangle bounds, string text, ref bool active)
{
Vector2 mouse = GetMousePosition();
bool hover = CheckCollisionPointRec(mouse, bounds);
if (!guiLocked && hover && IsMouseButtonPressed(MouseButton.Left)) active = !active;
if (!guiLocked && hover && IsMouseButtonPressed(MouseButton.Left))
{
active = !active;
}
DrawRectangleLinesEx(bounds, 1, hover ? Color.DarkBlue : Color.Gray);
if (active) DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
if (text != null) DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
if (active)
{
DrawRectangle((int)bounds.X + 4, (int)bounds.Y + 4, (int)bounds.Width - 8, (int)bounds.Height - 8, Color.DarkGray);
}
if (text != null)
{
DrawText(text, (int)(bounds.X + bounds.Width + 8), (int)(bounds.Y + bounds.Height / 2 - 5), 10, Color.DarkGray);
}
}
private static bool GuiDropdownBox(Rectangle bounds, string text, ref int active, bool editMode)
@ -351,7 +422,10 @@ public partial class SplinesDrawing : IExample
}
}
if (clickable && hoverMain && IsMouseButtonPressed(MouseButton.Left)) pressed = true;
if (clickable && hoverMain && IsMouseButtonPressed(MouseButton.Left))
{
pressed = true;
}
return pressed;
}

View file

@ -15,8 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath; // Required for: Lerp()
namespace Examples.Shapes;
@ -71,12 +69,25 @@ public partial class StarfieldEffect : IExample
//----------------------------------------------------------------------------------
// Change speed based on mouse
float mouseMove = GetMouseWheelMove();
if ((int)mouseMove != 0) speed += 2.0f * mouseMove / 9.0f;
if (speed < 0.0f) speed = 0.1f;
else if (speed > 2.0f) speed = 2.0f;
if ((int)mouseMove != 0)
{
speed += 2.0f * mouseMove / 9.0f;
}
if (speed < 0.0f)
{
speed = 0.1f;
}
else if (speed > 2.0f)
{
speed = 2.0f;
}
// Toggle lines / points with space bar
if (IsKeyPressed(KeyboardKey.Space)) drawLines = !drawLines;
if (IsKeyPressed(KeyboardKey.Space))
{
drawLines = !drawLines;
}
float dt = GetFrameTime();
for (int i = 0; i < STAR_COUNT; i++)

View file

@ -15,8 +15,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath;
using static Raylib_cs.Rlgl;
@ -66,7 +64,10 @@ public partial class TopDownLights : IExample
public LightInfo()
{
for (int i = 0; i < MAX_SHADOWS; i++) shadows[i] = new ShadowGeometry();
for (int i = 0; i < MAX_SHADOWS; i++)
{
shadows[i] = new ShadowGeometry();
}
}
}
@ -85,7 +86,10 @@ public partial class TopDownLights : IExample
public void Init()
{
lights = new LightInfo[MAX_LIGHTS];
for (int i = 0; i < MAX_LIGHTS; i++) lights[i] = new LightInfo();
for (int i = 0; i < MAX_LIGHTS; i++)
{
lights[i] = new LightInfo();
}
// Initialize our 'world' of boxes
boxCount = 0;
@ -112,7 +116,10 @@ public partial class TopDownLights : IExample
// Update
//----------------------------------------------------------------------------------
// Drag light 0
if (IsMouseButtonDown(MouseButton.Left)) MoveLight(0, GetMousePosition().X, GetMousePosition().Y);
if (IsMouseButtonDown(MouseButton.Left))
{
MoveLight(0, GetMousePosition().X, GetMousePosition().Y);
}
// Make a new light
if (IsMouseButtonPressed(MouseButton.Right) && (nextLight < MAX_LIGHTS))
@ -122,13 +129,19 @@ public partial class TopDownLights : IExample
}
// Toggle debug info
if (IsKeyPressed(KeyboardKey.F1)) showLines = !showLines;
if (IsKeyPressed(KeyboardKey.F1))
{
showLines = !showLines;
}
// Update the lights and keep track if any were dirty so we know if we need to update the master light mask
bool dirtyLights = false;
for (int i = 0; i < MAX_LIGHTS; i++)
{
if (UpdateLight(i, boxes, boxCount)) dirtyLights = true;
if (UpdateLight(i, boxes, boxCount))
{
dirtyLights = true;
}
}
// Update the light mask
@ -146,7 +159,10 @@ public partial class TopDownLights : IExample
// Merge in all the light masks
for (int i = 0; i < MAX_LIGHTS; i++)
{
if (lights[i].active) DrawTextureRec(lights[i].mask.Texture, new Rectangle(0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight()), Vector2Zero(), Color.White);
if (lights[i].active)
{
DrawTextureRec(lights[i].mask.Texture, new Rectangle(0, 0, (float)GetScreenWidth(), -(float)GetScreenHeight()), Vector2Zero(), Color.White);
}
}
DrawRenderBatchActive();
@ -172,7 +188,10 @@ public partial class TopDownLights : IExample
// Draw the lights
for (int i = 0; i < MAX_LIGHTS; i++)
{
if (lights[i].active) DrawCircle((int)lights[i].position.X, (int)lights[i].position.Y, 10, (i == 0) ? Color.Yellow : Color.White);
if (lights[i].active)
{
DrawCircle((int)lights[i].position.X, (int)lights[i].position.Y, 10, (i == 0) ? Color.Yellow : Color.White);
}
}
if (showLines)
@ -184,7 +203,10 @@ public partial class TopDownLights : IExample
for (int b = 0; b < boxCount; b++)
{
if (CheckCollisionRecs(boxes[b], lights[0].bounds)) DrawRectangleRec(boxes[b], Color.Purple);
if (CheckCollisionRecs(boxes[b], lights[0].bounds))
{
DrawRectangleRec(boxes[b], Color.Purple);
}
DrawRectangleLines((int)boxes[b].X, (int)boxes[b].Y, (int)boxes[b].Width, (int)boxes[b].Height, Color.DarkBlue);
}
@ -210,7 +232,10 @@ public partial class TopDownLights : IExample
UnloadRenderTexture(lightMask);
for (int i = 0; i < MAX_LIGHTS; i++)
{
if (lights[i].active) UnloadRenderTexture(lights[i].mask);
if (lights[i].active)
{
UnloadRenderTexture(lights[i].mask);
}
}
}
@ -233,7 +258,10 @@ public partial class TopDownLights : IExample
// It takes the edge and projects it back by the light radius and turns it into a quad
private void ComputeShadowVolumeForEdge(int slot, Vector2 sp, Vector2 ep)
{
if (lights[slot].shadowCount >= MAX_SHADOWS) return;
if (lights[slot].shadowCount >= MAX_SHADOWS)
{
return;
}
float extension = lights[slot].outerRadius * 2;
@ -271,7 +299,10 @@ public partial class TopDownLights : IExample
// See if a light needs to update it's mask
private bool UpdateLight(int slot, Rectangle[] boxes, int count)
{
if (!lights[slot].active || !lights[slot].dirty) return false;
if (!lights[slot].active || !lights[slot].dirty)
{
return false;
}
lights[slot].dirty = false;
lights[slot].shadowCount = 0;
@ -280,10 +311,16 @@ public partial class TopDownLights : IExample
for (int i = 0; i < count; i++)
{
// Are we in a box? if so we are not valid
if (CheckCollisionPointRec(lights[slot].position, boxes[i])) return false;
if (CheckCollisionPointRec(lights[slot].position, boxes[i]))
{
return false;
}
// If this box is outside our bounds, we can skip it
if (!CheckCollisionRecs(lights[slot].bounds, boxes[i])) continue;
if (!CheckCollisionRecs(lights[slot].bounds, boxes[i]))
{
continue;
}
// Check the edges that are on the same side we are, and cast shadow volumes out from them
@ -291,22 +328,34 @@ public partial class TopDownLights : IExample
Vector2 sp = new Vector2(boxes[i].X, boxes[i].Y);
Vector2 ep = new Vector2(boxes[i].X + boxes[i].Width, boxes[i].Y);
if (lights[slot].position.Y > ep.Y) ComputeShadowVolumeForEdge(slot, sp, ep);
if (lights[slot].position.Y > ep.Y)
{
ComputeShadowVolumeForEdge(slot, sp, ep);
}
// Right
sp = ep;
ep.Y += boxes[i].Height;
if (lights[slot].position.X < ep.X) ComputeShadowVolumeForEdge(slot, sp, ep);
if (lights[slot].position.X < ep.X)
{
ComputeShadowVolumeForEdge(slot, sp, ep);
}
// Bottom
sp = ep;
ep.X -= boxes[i].Width;
if (lights[slot].position.Y < ep.Y) ComputeShadowVolumeForEdge(slot, sp, ep);
if (lights[slot].position.Y < ep.Y)
{
ComputeShadowVolumeForEdge(slot, sp, ep);
}
// Left
sp = ep;
ep.Y -= boxes[i].Height;
if (lights[slot].position.X > ep.X) ComputeShadowVolumeForEdge(slot, sp, ep);
if (lights[slot].position.X > ep.X)
{
ComputeShadowVolumeForEdge(slot, sp, ep);
}
// The box itself
lights[slot].shadows[lights[slot].shadowCount].vertices[0] = new Vector2(boxes[i].X, boxes[i].Y);
@ -336,7 +385,10 @@ public partial class TopDownLights : IExample
SetBlendMode(BlendMode.Custom);
// If we are valid, then draw the light radius to the alpha mask
if (lights[slot].valid) DrawCircleGradient(lights[slot].position, lights[slot].outerRadius, ColorAlpha(Color.White, 0), Color.White);
if (lights[slot].valid)
{
DrawCircleGradient(lights[slot].position, lights[slot].outerRadius, ColorAlpha(Color.White, 0), Color.White);
}
DrawRenderBatchActive();

View file

@ -15,10 +15,6 @@
*
********************************************************************************************/
using System;
using System.Numerics;
using static Raylib_cs.Raylib;
namespace Examples.Shapes;
public partial class TriangleStrip : IExample

View file

@ -13,8 +13,6 @@
*
********************************************************************************************/
using System.Numerics;
using static Raylib_cs.Raylib;
using static Raylib_cs.Raymath; // Required for: Vector2LineAngle()
namespace Examples.Shapes;
@ -51,14 +49,27 @@ public partial class VectorAngle : IExample
//----------------------------------------------------------------------------------
float startangle = 0.0f;
if (angleMode == 0) startangle = -Vector2LineAngle(v0, v1) * RAD2DEG;
if (angleMode == 1) startangle = 0.0f;
if (angleMode == 0)
{
startangle = -Vector2LineAngle(v0, v1) * RAD2DEG;
}
if (angleMode == 1)
{
startangle = 0.0f;
}
v2 = GetMousePosition();
if (IsKeyPressed(KeyboardKey.Space)) angleMode = (angleMode == 0) ? 1 : 0;
if (IsKeyPressed(KeyboardKey.Space))
{
angleMode = (angleMode == 0) ? 1 : 0;
}
if ((angleMode == 0) && IsMouseButtonDown(MouseButton.Right)) v1 = GetMousePosition();
if ((angleMode == 0) && IsMouseButtonDown(MouseButton.Right))
{
v1 = GetMousePosition();
}
if (angleMode == 0)
{
@ -104,11 +115,21 @@ public partial class VectorAngle : IExample
DrawText("v0", (int)v0.X, (int)v0.Y, 10, Color.DarkGray);
// If the line from v0 to v1 would overlap the text, move it's position up 10
if (angleMode == 0 && Vector2Subtract(v0, v1).Y > 0.0f) DrawText("v1", (int)v1.X, (int)v1.Y - 10, 10, Color.DarkGray);
if (angleMode == 0 && Vector2Subtract(v0, v1).Y < 0.0f) DrawText("v1", (int)v1.X, (int)v1.Y, 10, Color.DarkGray);
if (angleMode == 0 && Vector2Subtract(v0, v1).Y > 0.0f)
{
DrawText("v1", (int)v1.X, (int)v1.Y - 10, 10, Color.DarkGray);
}
if (angleMode == 0 && Vector2Subtract(v0, v1).Y < 0.0f)
{
DrawText("v1", (int)v1.X, (int)v1.Y, 10, Color.DarkGray);
}
// If angle mode 1, use v1 to emphasize the horizontal line
if (angleMode == 1) DrawText("v1", (int)v0.X + 40, (int)v0.Y, 10, Color.DarkGray);
if (angleMode == 1)
{
DrawText("v1", (int)v0.X + 40, (int)v0.Y, 10, Color.DarkGray);
}
// position adjusted by -10 so it isn't hidden by cursor
DrawText("v2", (int)v2.X - 10, (int)v2.Y - 10, 10, Color.DarkGray);