Skip to content

Commit

Permalink
Create gradient directly
Browse files Browse the repository at this point in the history
  • Loading branch information
EVAST9919 committed Oct 4, 2023
1 parent 5077a8d commit d0867a1
Showing 1 changed file with 5 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Rendering;
using osu.Framework.Graphics.Shaders;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osuTK;
Expand Down Expand Up @@ -60,7 +58,10 @@ protected SaturationValueSelector()
SelectionArea = new Container
{
RelativeSizeAxes = Axes.Both,
Child = box = new SaturationBox()
Child = box = new SaturationBox
{
Colour = ColourInfo.GradientHorizontal(Color4.White, Color4.Red)
}
},
marker = CreateMarker().With(d =>
{
Expand Down Expand Up @@ -148,7 +149,7 @@ private bool shouldUpdateHue(float newHue)

private void hueChanged()
{
box.Hue = Hue.Value;
box.Colour = ColourInfo.GradientHorizontal(Color4.White, Colour4.FromHSV(Hue.Value, 1f, 1f));
updateCurrent();
}

Expand Down Expand Up @@ -211,21 +212,6 @@ protected abstract partial class Marker : CompositeDrawable

private partial class SaturationBox : Box
{
private float hue;
private ColourInfo gradient = ColourInfo.GradientHorizontal(Color4.White, Color4.Red);

public float Hue
{
set
{
if (hue == value) return;

hue = value;
gradient = ColourInfo.GradientHorizontal(Color4.White, Colour4.FromHSV(hue, 1f, 1f));
Invalidate(Invalidation.DrawNode);
}
}

public SaturationBox()
{
RelativeSizeAxes = Axes.Both;
Expand All @@ -236,39 +222,6 @@ private void load(ShaderManager shaders)
{
TextureShader = shaders.Load(VertexShaderDescriptor.TEXTURE_2, "SaturationSelectorBackground");
}

protected override DrawNode CreateDrawNode() => new SaturationBoxDrawNode(this);

private class SaturationBoxDrawNode : SpriteDrawNode
{
public new SaturationBox Source => (SaturationBox)base.Source;

public SaturationBoxDrawNode(SaturationBox source)
: base(source)
{
}

private ColourInfo gradient;

public override void ApplyState()
{
base.ApplyState();
gradient = Source.gradient;
}

protected override void Blit(IRenderer renderer)
{
if (DrawRectangle.Width == 0 || DrawRectangle.Height == 0)
return;

ColourInfo col = DrawColourInfo.Colour;
col.ApplyChild(gradient);

renderer.DrawQuad(Texture, ScreenSpaceDrawQuad, col, null, null,
new Vector2(InflationAmount.X / DrawRectangle.Width, InflationAmount.Y / DrawRectangle.Height),
null, TextureCoords);
}
}
}
}
}
Expand Down

0 comments on commit d0867a1

Please sign in to comment.