Skip to content

Commit

Permalink
hot reload work resets styles
Browse files Browse the repository at this point in the history
  • Loading branch information
FlurinBruehwiler committed Mar 9, 2024
1 parent 503fdcb commit c11c9f2
Show file tree
Hide file tree
Showing 18 changed files with 1,071 additions and 1,003 deletions.
2 changes: 1 addition & 1 deletion Flamui.Components/DebugWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public override void Build(Ui ui)
{
ui.Window.IsDebugWindow = true;

var otherWindow = eventLoop.Windows.First(x => x != ui.Window);
var otherWindow = EventLoop.Windows.First(x => x != ui.Window);

using (ui.Div().Padding(3).ShrinkHeight())
{
Expand Down
176 changes: 88 additions & 88 deletions Flamui.Components/Graph/Camera.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
using System.Numerics;
using Flamui.UiElements;
using SkiaSharp;

namespace Flamui.Components.Graph;

public record struct CameraInfo(Vector2 Offset, Vector2 Target, float Zoom)
{
public Vector2 ScreenToWorld(Vector2 screenVector)
{
var invertedCameraMatrix = GetCameraMatrix().Invert();
var worldPoint = invertedCameraMatrix.MapPoint(screenVector.X, screenVector.Y);
return new Vector2(worldPoint.X, worldPoint.Y);
}

public SKMatrix GetCameraMatrix()
{
var matOrigin = SKMatrix.CreateTranslation(-Target.X, -Target.Y);
var matScale = SKMatrix.CreateScale(Zoom, Zoom);
var matTranslation = SKMatrix.CreateTranslation(Offset.X, Offset.Y);

return SKMatrix.Concat(SKMatrix.Concat(matTranslation, matScale), matOrigin);
}
};


public class Camera : UiElementContainer
{
public Camera Info(CameraInfo cameraInfo)
{
CameraInfo = cameraInfo;
return this;
}

public CameraInfo CameraInfo { get; set; }

public override void Render(RenderContext renderContext)
{
var matrix = CameraInfo.GetCameraMatrix();

renderContext.Add(new Matrix
{
SkMatrix = matrix
});

foreach (var uiElement in Children)
{
uiElement.Render(renderContext);
}

renderContext.Add(new Matrix
{
SkMatrix = matrix.Invert()
});
}

public override void Layout()
{
foreach (var uiElement in Children)
{
//todo big refactor needed, because wtf
if (uiElement.PWidth.Kind == SizeKind.Pixel)
{
uiElement.ComputedBounds.W = uiElement.PWidth.Value;
}
if (uiElement.PHeight.Kind == SizeKind.Pixel)
{
uiElement.ComputedBounds.H = uiElement.PHeight.Value;
}
uiElement.Layout();
}
}

public override Vector2 ProjectPoint(Vector2 point)
{
return CameraInfo.ScreenToWorld(point);
}

public override bool LayoutHasChanged()
{
throw new NotImplementedException();
}

public override bool HasChanges()
{
throw new NotImplementedException();
}
}
// using System.Numerics;
// using Flamui.UiElements;
// using SkiaSharp;
//
// namespace Flamui.Components.Graph;
//
// public record struct CameraInfo(Vector2 Offset, Vector2 Target, float Zoom)
// {
// public Vector2 ScreenToWorld(Vector2 screenVector)
// {
// var invertedCameraMatrix = GetCameraMatrix().Invert();
// var worldPoint = invertedCameraMatrix.MapPoint(screenVector.X, screenVector.Y);
// return new Vector2(worldPoint.X, worldPoint.Y);
// }
//
// public SKMatrix GetCameraMatrix()
// {
// var matOrigin = SKMatrix.CreateTranslation(-Target.X, -Target.Y);
// var matScale = SKMatrix.CreateScale(Zoom, Zoom);
// var matTranslation = SKMatrix.CreateTranslation(Offset.X, Offset.Y);
//
// return SKMatrix.Concat(SKMatrix.Concat(matTranslation, matScale), matOrigin);
// }
// };
//
//
// public class Camera : UiElementContainer
// {
// public Camera Info(CameraInfo cameraInfo)
// {
// CameraInfo = cameraInfo;
// return this;
// }
//
// public CameraInfo CameraInfo { get; set; }
//
// public override void Render(RenderContext renderContext)
// {
// var matrix = CameraInfo.GetCameraMatrix();
//
// renderContext.Add(new Matrix
// {
// SkMatrix = matrix
// });
//
// foreach (var uiElement in Children)
// {
// uiElement.Render(renderContext);
// }
//
// renderContext.Add(new Matrix
// {
// SkMatrix = matrix.Invert()
// });
// }
//
// public override void Layout()
// {
// foreach (var uiElement in Children)
// {
// //todo big refactor needed, because wtf
// if (uiElement.PWidth.Kind == SizeKind.Pixel)
// {
// uiElement.ComputedBounds.W = uiElement.PWidth.Value;
// }
// if (uiElement.PHeight.Kind == SizeKind.Pixel)
// {
// uiElement.ComputedBounds.H = uiElement.PHeight.Value;
// }
// uiElement.Layout();
// }
// }
//
// public override Vector2 ProjectPoint(Vector2 point)
// {
// return CameraInfo.ScreenToWorld(point);
// }
//
// public override bool LayoutHasChanged()
// {
// throw new NotImplementedException();
// }
//
// public override bool HasChanges()
// {
// throw new NotImplementedException();
// }
// }
Loading

0 comments on commit c11c9f2

Please sign in to comment.