Skip to content

Commit

Permalink
Fixed Lines of Button and Toggle Element do not rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
MrScautHD committed May 12, 2024
1 parent 3d4e7bb commit e580066
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/Sparkle.Test/CSharp/TestGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TestGui : Gui {
ToggledText = "Checked",
ToggledColor = Color.Green,
ToggledTextColor = Color.DarkGreen,
Rotation = 60
};

LabelData toggleLabelData = new LabelData() {
Expand Down
1 change: 1 addition & 0 deletions src/Sparkle/CSharp/Effects/Types/PbrEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Sparkle.CSharp.Effects.Types;

// TODO FIX IT!
public class PbrEffect : Effect {

public Color AmbientColor;
Expand Down
13 changes: 11 additions & 2 deletions src/Sparkle/CSharp/GUI/Elements/ButtonElement.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -100,9 +101,17 @@ public class ButtonElement : GuiElement {
/// </summary>
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();
}

/// <summary>
Expand Down
13 changes: 11 additions & 2 deletions src/Sparkle/CSharp/GUI/Elements/ToggleElement.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -119,9 +120,17 @@ public class ToggleElement : GuiElement {
/// </summary>
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();
}

/// <summary>
Expand Down
25 changes: 13 additions & 12 deletions src/Sparkle/CSharp/Particles/Particle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e580066

Please sign in to comment.