mirror of
https://gitlab.acidiclight.dev/sociallydistant/sociallydistant.git
synced 2025-01-22 09:31:47 -05:00
Add support for widget transforms
Signed-off-by: Ritchie Frodomar <alkalinethunder@gmail.com>
This commit is contained in:
parent
8cc68337f9
commit
78f858f7ec
7 changed files with 25 additions and 17 deletions
|
@ -1,3 +1,5 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace AcidicGUI.Effects;
|
||||
|
||||
public interface IEffect
|
||||
|
@ -5,5 +7,5 @@ public interface IEffect
|
|||
int PassesCount { get; }
|
||||
|
||||
void Use(int pass);
|
||||
void UpdateOpacity(float opacity);
|
||||
void UpdateWidgetParameters(float opacity, Matrix widgetTransform);
|
||||
}
|
|
@ -232,9 +232,7 @@ public sealed class GuiManager : IFontFamilyProvider
|
|||
renderer.SetLayer(-32768);
|
||||
|
||||
foreach (Widget widget in topLevels)
|
||||
widget.RenderInternal(renderer);
|
||||
|
||||
renderer.RenderBatches();
|
||||
widget.RenderInternal(renderer, Matrix.Identity);
|
||||
|
||||
isRendering = false;
|
||||
}
|
||||
|
|
|
@ -207,12 +207,11 @@ public abstract partial class Widget : IFontFamilyProvider
|
|||
return ourRect;
|
||||
}
|
||||
|
||||
internal void RenderInternal(GuiRenderer renderer)
|
||||
internal void RenderInternal(GuiRenderer renderer, Matrix parentMatrix)
|
||||
{
|
||||
if (visibility != Visibility.Visible)
|
||||
return;
|
||||
|
||||
renderer.PushTransformMatrix(Transform.ComputedMatrix);
|
||||
|
||||
effectOverride?.UpdateParameters(this, renderer);
|
||||
|
||||
|
@ -226,7 +225,12 @@ public abstract partial class Widget : IFontFamilyProvider
|
|||
}
|
||||
|
||||
renderer.RenderGuiMesh(cachedGeometry.Value);
|
||||
|
||||
Matrix matrix = parentMatrix * Transform.ComputedMatrix;
|
||||
|
||||
renderer.PushTransformMatrix(matrix);
|
||||
renderer.RenderBatches(effectOverride, ComputedOpacity, clipRect);
|
||||
renderer.PopTransformMatrix();
|
||||
|
||||
effectOverride?.AfterRebuildGeometry(this, renderer);
|
||||
|
||||
|
@ -234,10 +238,9 @@ public abstract partial class Widget : IFontFamilyProvider
|
|||
|
||||
foreach (Widget child in children)
|
||||
{
|
||||
child.RenderInternal(renderer);
|
||||
child.RenderInternal(renderer, matrix);
|
||||
}
|
||||
|
||||
renderer.PopTransformMatrix();
|
||||
}
|
||||
|
||||
public T GetCustomProperty<T>() where T : struct
|
||||
|
|
|
@ -21,7 +21,6 @@ public class WidgetTransform
|
|||
|
||||
position = value;
|
||||
dirty = true;
|
||||
widget.InvalidateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +34,6 @@ public class WidgetTransform
|
|||
|
||||
rotation = value;
|
||||
dirty = true;
|
||||
widget.InvalidateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +47,6 @@ public class WidgetTransform
|
|||
|
||||
scale = value;
|
||||
dirty = true;
|
||||
widget.InvalidateGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,9 +63,9 @@ public sealed class BackgroundBlurWidgetEffect : IWidgetEffect,
|
|||
defaultUiShader.Use(pass);
|
||||
}
|
||||
|
||||
public void UpdateOpacity(float opacity)
|
||||
public void UpdateWidgetParameters(float opacity, Matrix widgetTransform)
|
||||
{
|
||||
defaultUiShader.UpdateOpacity(opacity);
|
||||
defaultUiShader.UpdateWidgetParameters(opacity, widgetTransform);
|
||||
}
|
||||
|
||||
public void UpdateParameters(Widget widget, GuiRenderer renderer)
|
||||
|
|
|
@ -14,6 +14,8 @@ public class MonoGameEffect :
|
|||
private readonly int techniqueIndex;
|
||||
private readonly EffectParameter transformMatrixParameter;
|
||||
private readonly EffectParameter opacityParameter;
|
||||
private Matrix widgetTransform = Matrix.Identity;
|
||||
private bool mustUpdateTransform;
|
||||
private Viewport lastViewport;
|
||||
private Matrix transformMatrix;
|
||||
|
||||
|
@ -26,7 +28,6 @@ public class MonoGameEffect :
|
|||
|
||||
transformMatrixParameter = underlyingEffect.Parameters[TransformMatrixParameterName];
|
||||
opacityParameter = underlyingEffect.Parameters[OpacityParameterName];
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -34,8 +35,14 @@ public class MonoGameEffect :
|
|||
underlyingEffect.Dispose();
|
||||
}
|
||||
|
||||
public void UpdateOpacity(float opacity)
|
||||
public void UpdateWidgetParameters(float opacity, Matrix widgetTransform)
|
||||
{
|
||||
if (this.widgetTransform != widgetTransform)
|
||||
{
|
||||
mustUpdateTransform = true;
|
||||
this.widgetTransform = widgetTransform;
|
||||
}
|
||||
|
||||
opacityParameter.SetValue(opacity);
|
||||
}
|
||||
|
||||
|
@ -45,11 +52,12 @@ public class MonoGameEffect :
|
|||
|
||||
Viewport viewport = underlyingEffect.GraphicsDevice.Viewport;
|
||||
|
||||
if (viewport.Width != lastViewport.Width || viewport.Height != lastViewport.Height)
|
||||
if (mustUpdateTransform || viewport.Width != lastViewport.Width || viewport.Height != lastViewport.Height)
|
||||
{
|
||||
lastViewport = viewport;
|
||||
|
||||
Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, -32768, 32768, out transformMatrix);
|
||||
transformMatrix *= widgetTransform;
|
||||
}
|
||||
|
||||
transformMatrixParameter.SetValue(transformMatrix);
|
||||
|
|
|
@ -164,7 +164,7 @@ public sealed class GuiService :
|
|||
IEffect effectToUse = effectOverride ?? defaultEffect;
|
||||
|
||||
effectToUse.Use(0);
|
||||
effectToUse.UpdateOpacity(opacity);
|
||||
effectToUse.UpdateWidgetParameters(opacity, widgetTransform ?? Matrix.Identity);
|
||||
device.Textures[0] = texture ?? white;
|
||||
device.SamplerStates[0] = SamplerState.LinearClamp;
|
||||
device.BlendState = blendState;
|
||||
|
|
Loading…
Reference in a new issue