From e580066d66e35cd2ceeb14cd8df0c53d1a6400da Mon Sep 17 00:00:00 2001
From: MrScautHD <65916181+MrScautHD@users.noreply.github.com>
Date: Sun, 12 May 2024 21:34:36 +0200
Subject: [PATCH] Fixed Lines of Button and Toggle Element do not rotate
---
src/Sparkle.Test/CSharp/TestGui.cs | 1 +
src/Sparkle/CSharp/Effects/Types/PbrEffect.cs | 1 +
.../CSharp/GUI/Elements/ButtonElement.cs | 13 ++++++++--
.../CSharp/GUI/Elements/ToggleElement.cs | 13 ++++++++--
src/Sparkle/CSharp/Particles/Particle.cs | 25 ++++++++++---------
5 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/src/Sparkle.Test/CSharp/TestGui.cs b/src/Sparkle.Test/CSharp/TestGui.cs
index 5bbe2e6..b4722c4 100644
--- a/src/Sparkle.Test/CSharp/TestGui.cs
+++ b/src/Sparkle.Test/CSharp/TestGui.cs
@@ -49,6 +49,7 @@ public class TestGui : Gui {
ToggledText = "Checked",
ToggledColor = Color.Green,
ToggledTextColor = Color.DarkGreen,
+ Rotation = 60
};
LabelData toggleLabelData = new LabelData() {
diff --git a/src/Sparkle/CSharp/Effects/Types/PbrEffect.cs b/src/Sparkle/CSharp/Effects/Types/PbrEffect.cs
index 4a0dacc..cf9416b 100644
--- a/src/Sparkle/CSharp/Effects/Types/PbrEffect.cs
+++ b/src/Sparkle/CSharp/Effects/Types/PbrEffect.cs
@@ -8,6 +8,7 @@
namespace Sparkle.CSharp.Effects.Types;
+// TODO FIX IT!
public class PbrEffect : Effect {
public Color AmbientColor;
diff --git a/src/Sparkle/CSharp/GUI/Elements/ButtonElement.cs b/src/Sparkle/CSharp/GUI/Elements/ButtonElement.cs
index 4c6fd9e..8a0cf06 100644
--- a/src/Sparkle/CSharp/GUI/Elements/ButtonElement.cs
+++ b/src/Sparkle/CSharp/GUI/Elements/ButtonElement.cs
@@ -1,5 +1,6 @@
using System.Drawing;
using System.Numerics;
+using Raylib_CSharp;
using Raylib_CSharp.Fonts;
using Raylib_CSharp.Rendering;
using Raylib_CSharp.Textures;
@@ -100,9 +101,17 @@ public class ButtonElement : GuiElement {
///
protected virtual void DrawRectangle(RectangleF dest, Vector2 origin, float rotation, Color color) {
Graphics.DrawRectanglePro(dest, origin, rotation, color);
-
- RectangleF rec = new RectangleF(dest.X - (dest.Width / 2), dest.Y - (dest.Height / 2), dest.Width, dest.Height);
+
+ RlGl.PushMatrix();
+
+ RlGl.TranslateF(dest.X, dest.Y, 0);
+ RlGl.RotateF(rotation, 0, 0, 1);
+ RlGl.TranslateF(-origin.X, -origin.Y, 0);
+
+ RectangleF rec = new RectangleF(0, 0, dest.Width, dest.Height);
Graphics.DrawRectangleLinesEx(rec, 4, Color.Brightness(color, -0.5F));
+
+ RlGl.PopMatrix();
}
///
diff --git a/src/Sparkle/CSharp/GUI/Elements/ToggleElement.cs b/src/Sparkle/CSharp/GUI/Elements/ToggleElement.cs
index ee54cd3..e499200 100644
--- a/src/Sparkle/CSharp/GUI/Elements/ToggleElement.cs
+++ b/src/Sparkle/CSharp/GUI/Elements/ToggleElement.cs
@@ -1,5 +1,6 @@
using System.Drawing;
using System.Numerics;
+using Raylib_CSharp;
using Raylib_CSharp.Fonts;
using Raylib_CSharp.Rendering;
using Raylib_CSharp.Textures;
@@ -119,9 +120,17 @@ public class ToggleElement : GuiElement {
///
protected virtual void DrawRectangle(RectangleF dest, Vector2 origin, float rotation, Color color) {
Graphics.DrawRectanglePro(dest, origin, rotation, color);
-
- RectangleF rec = new RectangleF(dest.X - (dest.Width / 2), dest.Y - (dest.Height / 2), dest.Width, dest.Height);
+
+ RlGl.PushMatrix();
+
+ RlGl.TranslateF(dest.X, dest.Y, 0);
+ RlGl.RotateF(rotation, 0, 0, 1);
+ RlGl.TranslateF(-origin.X, -origin.Y, 0);
+
+ RectangleF rec = new RectangleF(0, 0, dest.Width, dest.Height);
Graphics.DrawRectangleLinesEx(rec, 4, Color.Brightness(color, -0.5F));
+
+ RlGl.PopMatrix();
}
///
diff --git a/src/Sparkle/CSharp/Particles/Particle.cs b/src/Sparkle/CSharp/Particles/Particle.cs
index 09dc179..719b75c 100644
--- a/src/Sparkle/CSharp/Particles/Particle.cs
+++ b/src/Sparkle/CSharp/Particles/Particle.cs
@@ -80,21 +80,22 @@ public class Particle : Disposable {
if (cam == null) return;
Vector2 size = RayMath.Vector2Lerp(this._data.StartSize, this._data.EndSize, this._interpolationFactor);
- float rotation = RayMath.Lerp(this._data.StartRotation, this._data.EndRotation, this._interpolationFactor);
+ BoundingBox box = new BoundingBox(this.Position - new Vector3(size.X / 2, size.Y / 2, size.X / 2), this.Position + new Vector3(size.X / 2, size.Y / 2, size.X / 2));
- Color color = new Color() {
- R = (byte) RayMath.Lerp(this._data.StartColor.R, this._data.EndColor.R, this._interpolationFactor),
- G = (byte) RayMath.Lerp(this._data.StartColor.G, this._data.EndColor.G, this._interpolationFactor),
- B = (byte) RayMath.Lerp(this._data.StartColor.B, this._data.EndColor.B, this._interpolationFactor),
- A = (byte) RayMath.Lerp(this._data.StartColor.A, this._data.EndColor.A, this._interpolationFactor)
- };
+ if (SceneManager.ActiveCam3D!.GetFrustum().ContainsBox(box)) {
+ float rotation = RayMath.Lerp(this._data.StartRotation, this._data.EndRotation, this._interpolationFactor);
- RectangleF source = new RectangleF(0, 0, this.Texture.Width, this.Texture.Height);
- RectangleF dest = new RectangleF(this.Position.X + (source.X / 2), this.Position.Y + (source.Y / 2), source.X, source.Y); // TODO FIX FOR GUI THE ROTATION (CHECK IF IT EVEN BROKEN, I THINK NOT)
- Vector2 origin = new Vector2(dest.Width / 2.0F, dest.Height / 2.0F);
+ Color color = new Color() {
+ R = (byte) RayMath.Lerp(this._data.StartColor.R, this._data.EndColor.R, this._interpolationFactor),
+ G = (byte) RayMath.Lerp(this._data.StartColor.G, this._data.EndColor.G, this._interpolationFactor),
+ B = (byte) RayMath.Lerp(this._data.StartColor.B, this._data.EndColor.B, this._interpolationFactor),
+ A = (byte) RayMath.Lerp(this._data.StartColor.A, this._data.EndColor.A, this._interpolationFactor)
+ };
- BoundingBox box = new BoundingBox(this.Position - new Vector3(size.X / 2, size.Y / 2, size.X / 2), this.Position + new Vector3(size.X / 2, size.Y / 2, size.X / 2));
- if (SceneManager.ActiveCam3D!.GetFrustum().ContainsBox(box)) {
+ RectangleF source = new RectangleF(0, 0, this.Texture.Width, this.Texture.Height);
+ RectangleF dest = new RectangleF(this.Position.X + (source.X / 2), this.Position.Y + (source.Y / 2), source.X, source.Y); // TODO FIX FOR GUI THE ROTATION (CHECK IF IT EVEN BROKEN, I THINK NOT)
+ Vector2 origin = new Vector2(dest.Width / 2.0F, dest.Height / 2.0F);
+
Graphics.BeginShaderMode(this._data.Effect.Shader);
Graphics.DrawBillboardPro(cam.GetCamera3D(), this.Texture, source, this.Position, cam.Up, size, origin, rotation, color);
Graphics.EndShaderMode();