Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
tweak style
Browse files Browse the repository at this point in the history
  • Loading branch information
EtheraelEspeon committed Jan 24, 2024
1 parent 29f6abf commit 7e819f2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 79 deletions.
142 changes: 65 additions & 77 deletions Client/Gui/GuiCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,83 +81,6 @@ internal static void RebuildQuadCache() {
}

public class GuiRect {

public struct Extents {
public Extents(GuiRect rect) {
if (rect.screenAnchor.x < -1 || rect.screenAnchor.x > 1 || rect.screenAnchor.y < -1 ||
rect.screenAnchor.y > 1) {
// TODO: Warn that anchor is out of range
}

// The percentage of each dimensions that goes in the negative direction
// == (0.5, 0.5) if anchor is at (0, 0)
// https://www.desmos.com/calculator/mpfe8d8fhv
vec2 percentNegative = rect.screenAnchor / 2 + new vec2(0.5f, 0.5f);
vec2 percentPositive = 1 - percentNegative;

var globalPos = rect.globalScreenPosition;
var globalSize = rect.globalScreenSize;

globalPos += vec2.Ones;
globalPos /= 2;

ScreenBottomLeft = globalPos - percentNegative * globalSize;
ScreenTopRight = globalPos + percentPositive * globalSize;

ScreenBottomLeft *= 2;
ScreenBottomLeft -= vec2.Ones;
ScreenTopRight *= 2;
ScreenTopRight -= vec2.Ones;
}
// For quad building, avoids expensive recursive calls
internal Extents(vec2 anchor, vec2 globalPos, vec2 globalSize) {

// The percentage of each dimensions that goes in the negative direction
// == (0.5, 0.5) if anchor is at (0, 0)
// https://www.desmos.com/calculator/mpfe8d8fhv
vec2 percentNegative = anchor / 2 + new vec2(0.5f, 0.5f);
vec2 percentPositive = 1 - percentNegative;

globalPos += vec2.Ones;
globalPos /= 2;

ScreenBottomLeft = globalPos - percentNegative * globalSize;
ScreenTopRight = globalPos + percentPositive * globalSize;

ScreenBottomLeft *= 2;
ScreenBottomLeft -= vec2.Ones;
ScreenTopRight *= 2;
ScreenTopRight -= vec2.Ones;
}

public readonly vec2 ScreenBottomLeft;
public readonly vec2 ScreenTopRight;
public vec2 ScreenBottomRight {
get => new vec2(ScreenTopRight.x, ScreenBottomLeft.y);
}
public vec2 ScreenTopLeft {
get => new vec2(ScreenBottomLeft.x, ScreenTopRight.y);
}

public vec2 PixelTopLeft {
get => GuiCanvas.ScreenToPixel(ScreenTopLeft, GuiCanvas.ReferenceResolution);
}
public vec2 PixelBottomRight {
get => GuiCanvas.ScreenToPixel(ScreenBottomRight, GuiCanvas.ReferenceResolution);
}
public vec2 PixelTopRight {
get => GuiCanvas.ScreenToPixel(ScreenTopRight, GuiCanvas.ReferenceResolution);
}
public vec2 PixelBottomLeft {
get => GuiCanvas.ScreenToPixel(ScreenBottomLeft, GuiCanvas.ReferenceResolution);
}
}
public class ByTreeDepth : IComparer<GuiRect>
{
public int Compare(GuiRect? lhs, GuiRect? rhs)
=> (int)(lhs!.treeDepth - rhs!.treeDepth);
}
public delegate void SizeInitializer(GuiRect parent, GuiRect rect);

/// <returns>
/// a closure that encapsulates these parameters and will give return a GuiRect with the proper dimensions
Expand Down Expand Up @@ -393,4 +316,69 @@ private void UpdateVertexUVs() {
GuiCanvas._QuadCache[quadIdx + 2] = new GuiVertex(GuiCanvas._QuadCache[quadIdx + 2].position, uvTopLeft );
GuiCanvas._QuadCache[quadIdx + 3] = new GuiVertex(GuiCanvas._QuadCache[quadIdx + 3].position, uvTopRight );
}

public struct Extents {
public Extents(GuiRect rect) {
if (rect.screenAnchor.x < -1 || rect.screenAnchor.x > 1 || rect.screenAnchor.y < -1 ||
rect.screenAnchor.y > 1) {
// TODO: Warn that anchor is out of range
}

// The percentage of each dimensions that goes in the negative direction
// == (0.5, 0.5) if anchor is at (0, 0)
// https://www.desmos.com/calculator/mpfe8d8fhv
vec2 percentNegative = rect.screenAnchor / 2 + new vec2(0.5f, 0.5f);
vec2 percentPositive = 1 - percentNegative;

var globalPos = rect.globalScreenPosition;
var globalSize = rect.globalScreenSize;

globalPos += vec2.Ones;
globalPos /= 2;

ScreenBottomLeft = globalPos - percentNegative * globalSize;
ScreenTopRight = globalPos + percentPositive * globalSize;

ScreenBottomLeft *= 2;
ScreenBottomLeft -= vec2.Ones;
ScreenTopRight *= 2;
ScreenTopRight -= vec2.Ones;
}
// For quad building, avoids expensive recursive calls
internal Extents(vec2 anchor, vec2 globalPos, vec2 globalSize) {

// The percentage of each dimensions that goes in the negative direction
// == (0.5, 0.5) if anchor is at (0, 0)
// https://www.desmos.com/calculator/mpfe8d8fhv
vec2 percentNegative = anchor / 2 + new vec2(0.5f, 0.5f);
vec2 percentPositive = 1 - percentNegative;

globalPos += vec2.Ones;
globalPos /= 2;

ScreenBottomLeft = globalPos - percentNegative * globalSize;
ScreenTopRight = globalPos + percentPositive * globalSize;

ScreenBottomLeft *= 2;
ScreenBottomLeft -= vec2.Ones;
ScreenTopRight *= 2;
ScreenTopRight -= vec2.Ones;
}

public readonly vec2 ScreenBottomLeft;
public readonly vec2 ScreenTopRight;
public vec2 ScreenBottomRight => new vec2(ScreenTopRight.x, ScreenBottomLeft.y);
public vec2 ScreenTopLeft => new vec2(ScreenBottomLeft.x, ScreenTopRight.y);

public vec2 PixelTopLeft => GuiCanvas.ScreenToPixel(ScreenTopLeft, GuiCanvas.ReferenceResolution);
public vec2 PixelBottomRight => GuiCanvas.ScreenToPixel(ScreenBottomRight, GuiCanvas.ReferenceResolution);
public vec2 PixelTopRight => GuiCanvas.ScreenToPixel(ScreenTopRight, GuiCanvas.ReferenceResolution);
public vec2 PixelBottomLeft => GuiCanvas.ScreenToPixel(ScreenBottomLeft, GuiCanvas.ReferenceResolution);
}
public class ByTreeDepth : IComparer<GuiRect>
{
public int Compare(GuiRect? lhs, GuiRect? rhs)
=> (int)(lhs!.treeDepth - rhs!.treeDepth);
}
public delegate void SizeInitializer(GuiRect parent, GuiRect rect);
}
2 changes: 0 additions & 2 deletions Client/Rendering/Gui/GuiRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public override void CreatePipeline(MainFramebuffer framebuffer) {
Shaders = shaders
}
}));


}
public override void Render(double delta) {
CommandList.SetPipeline(GuiPipeline);
Expand Down

0 comments on commit 7e819f2

Please sign in to comment.