Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧Create testing scene with ctrls for all attrs #88

Draft
wants to merge 6 commits into
base: preview
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions Plazma.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,38 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfShared", "Performance\P
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Debug|x64 = Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7858F8F1-497A-4261-94D7-339442B09494}.Debug|Any CPU.ActiveCfg = Debug|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Debug|Any CPU.Build.0 = Debug|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Release|Any CPU.ActiveCfg = Release|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Release|Any CPU.Build.0 = Release|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Debug|Any CPU.ActiveCfg = Debug|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Debug|Any CPU.Build.0 = Debug|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Release|Any CPU.ActiveCfg = Release|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Release|Any CPU.Build.0 = Release|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Debug|Any CPU.ActiveCfg = Debug|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Debug|Any CPU.Build.0 = Debug|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Release|Any CPU.ActiveCfg = Release|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Release|Any CPU.Build.0 = Release|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Debug|Any CPU.ActiveCfg = Debug|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Debug|Any CPU.Build.0 = Debug|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Release|Any CPU.ActiveCfg = Release|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Release|Any CPU.Build.0 = Release|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Debug|Any CPU.ActiveCfg = Debug|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Debug|Any CPU.Build.0 = Debug|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Release|Any CPU.ActiveCfg = Release|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Release|Any CPU.Build.0 = Release|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Debug|Any CPU.ActiveCfg = Debug|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Debug|Any CPU.Build.0 = Debug|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Release|Any CPU.ActiveCfg = Release|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Release|Any CPU.Build.0 = Release|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Debug|Any CPU.ActiveCfg = Debug|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Debug|Any CPU.Build.0 = Debug|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Release|Any CPU.ActiveCfg = Release|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Release|Any CPU.Build.0 = Release|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Release|x64.ActiveCfg = Release|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Release|x64.Build.0 = Release|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Debug|x64.ActiveCfg = Debug|x64
{32D301FD-1E4D-431C-8C9D-E304E769C19F}.Debug|x64.Build.0 = Debug|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Release|x64.ActiveCfg = Release|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Release|x64.Build.0 = Release|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Debug|x64.ActiveCfg = Debug|x64
{960AD89D-364C-4455-8C7A-3B2D4188A0A1}.Debug|x64.Build.0 = Debug|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Release|x64.ActiveCfg = Release|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Release|x64.Build.0 = Release|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Debug|x64.ActiveCfg = Debug|x64
{A5790981-C319-48BD-9790-34F2C2E775B4}.Debug|x64.Build.0 = Debug|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Release|x64.ActiveCfg = Release|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Release|x64.Build.0 = Release|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Debug|x64.ActiveCfg = Debug|x64
{7858F8F1-497A-4261-94D7-339442B09494}.Debug|x64.Build.0 = Debug|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Release|x64.ActiveCfg = Release|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Release|x64.Build.0 = Release|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Debug|x64.ActiveCfg = Debug|x64
{D2B0088E-5452-48FE-B804-FA985A114635}.Debug|x64.Build.0 = Debug|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Release|x64.ActiveCfg = Release|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Release|x64.Build.0 = Release|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Debug|x64.ActiveCfg = Debug|x64
{AF6A9738-F676-408A-B1B9-E7F43631BC08}.Debug|x64.Build.0 = Debug|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Release|x64.ActiveCfg = Release|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Release|x64.Build.0 = Release|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Debug|x64.ActiveCfg = Debug|x64
{E2532556-570E-4416-B163-00CA1EAAE03C}.Debug|x64.Build.0 = Debug|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions Plazma/Behaviors/EasingRandomBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,38 @@ public override void Update(TimeSpan timeElapsed)
_ => Value
};

// Override the current value between the start and end if the update delegate is set
if (this.settings.UpdateValue is not null)
{
Value = this.settings.UpdateValue.Invoke(Value);
}

// Override the random start min value if the update delegate is set
if (this.settings.UpdateRandomStartMin is not null)
{
this.settings = this.settings with { RandomStartMin = this.settings.UpdateRandomStartMin?.Invoke(Value) ?? 0f };
}

// Override the random start max value if the update delegate is set
if (this.settings.UpdateRandomStartMax is not null)
{
this.settings = this.settings with { RandomStartMax = this.settings.UpdateRandomStartMax?.Invoke(Value) ?? 0f };
}

// Override the random change min value if the update delegate is set
// This is the end value that the easing function is trying to approach
if (this.settings.UpdateRandomChangeMin is not null)
{
this.settings = this.settings with { RandomChangeMin = this.settings.UpdateRandomChangeMin?.Invoke(Value) ?? 0f };
}

// Override the random change max value if the update delegate is set
// This is the end value that the easing function is trying to approach
if (this.settings.UpdateRandomChangeMax is not null)
{
this.settings = this.settings with { RandomChangeMax = this.settings.UpdateRandomChangeMax?.Invoke(Value) ?? 0f };
}

base.Update(timeElapsed);
}

Expand Down
36 changes: 31 additions & 5 deletions Plazma/Behaviors/EasingRandomBehaviorSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public readonly record struct EasingRandomBehaviorSettings
public float RandomStartMax { get; init; }

/// <summary>
/// Gets a delegate that will give the current value and return a value.
/// Gets a delegate that will override or manipulate the current value.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -53,8 +53,7 @@ public readonly record struct EasingRandomBehaviorSettings
public Func<float, float>? UpdateValue { get; init; }

/// <summary>
/// Gets a delegate that will give the current value of the behavior and
/// returns a value that will be used as the new <see cref="RandomStartMin"/>.
/// Gets a delegate that will override or manipulate the current value.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -68,8 +67,7 @@ public readonly record struct EasingRandomBehaviorSettings
public Func<float, float>? UpdateRandomStartMin { get; init; }

/// <summary>
/// Gets a delegate that will give the current value of the behavior and
/// returns a value that will be used as the new <see cref="RandomStartMax"/>.
/// Gets a delegate that will override or manipulate the current value.
/// </summary>
/// <remarks>
/// <para>
Expand All @@ -82,6 +80,34 @@ public readonly record struct EasingRandomBehaviorSettings
[JsonIgnore]
public Func<float, float>? UpdateRandomStartMax { get; init; }

/// <summary>
/// Gets a delegate that will override or manipulate the current value.
/// </summary>
/// <remarks>
/// <para>
/// This is invoked during the behavior update process.
/// </para>
/// <para>
/// The value returned from the delegate will be used as the new value for the <see cref="RandomStartMax"/>.
/// </para>
/// </remarks>
[JsonIgnore]
public Func<float, float>? UpdateRandomChangeMin { get; init; }

/// <summary>
/// Gets a delegate that will override or manipulate the current value.
/// </summary>
/// <remarks>
/// <para>
/// This is invoked during the behavior update process.
/// </para>
/// <para>
/// The value returned from the delegate will be used as the new value for the <see cref="RandomStartMax"/>.
/// </para>
/// </remarks>
[JsonIgnore]
public Func<float, float>? UpdateRandomChangeMax { get; init; }

/// <summary>
/// Gets the minimum amount of change used in randomization.
/// </summary>
Expand Down
202 changes: 202 additions & 0 deletions Testing/PlazmaTesting/CustomControls/MinMax.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// <copyright file="MinMax.cs" company="KinsonDigital">
// Copyright (c) KinsonDigital. All rights reserved.
// </copyright>

namespace PlazmaTesting.CustomControls;

using System.Drawing;
using KdGui;
using KdGui.Factories;

public class MinMax
{
private readonly IControlGroup group;
private readonly ICheckBox randomize;
private readonly ISlider value;
private readonly ISlider randomMin;
private readonly ISlider randomMax;
private readonly ICheckBox lockRanges;
private readonly ICheckBox growShrink;

public MinMax(string title, string minText = "Min", string maxText = "Max")
{
var ctrlFactory = new ControlFactory();

this.randomMin = ctrlFactory.CreateSlider();
this.randomMin.Text = minText;
this.randomMin.Min = 0;
this.randomMin.Max = 100;
this.randomMin.Value = 50;
this.randomMin.ValueChanged += RandomMin_OnValueChanged;
this.randomMin.Visible = false;

this.randomMax = ctrlFactory.CreateSlider();
this.randomMax.Text = maxText;
this.randomMax.Min = 0;
this.randomMax.Max = 100;
this.randomMax.Value = 50;
this.randomMax.ValueChanged += RandomMax_OnValueChanged;
this.randomMax.Visible = false;

this.randomize = ctrlFactory.CreateCheckbox();
this.randomize.IsChecked = false;
this.randomize.LabelWhenChecked = "Randomized";
this.randomize.LabelWhenUnchecked = "Not Randomized";
this.randomize.CheckedChanged += Randomize_OnCheckedChanged;

this.growShrink = ctrlFactory.CreateCheckbox();
this.growShrink.IsChecked = true;
this.growShrink.Visible = true;
this.growShrink.LabelWhenChecked = "Growing";
this.growShrink.LabelWhenUnchecked = "Shrinking";

this.value = ctrlFactory.CreateSlider();
this.value.Text = "Value";
this.value.Visible = true;
this.value.Min = 0;
this.value.Max = 100;
this.value.Value = 100;

this.lockRanges = ctrlFactory.CreateCheckbox();
this.lockRanges.IsChecked = true;
this.lockRanges.Visible = false;
this.lockRanges.LabelWhenChecked = "Locked";
this.lockRanges.LabelWhenUnchecked = "Unlocked";
this.lockRanges.CheckedChanged += LockRanges_OnCheckedChanged;

this.group = ctrlFactory.CreateControlGroup();
this.group.AutoSizeToFitContent = true;
this.group.Title = title;
this.group.Add(this.randomize);
this.group.Add(this.lockRanges);
this.group.Add(this.randomMin);
this.group.Add(this.randomMax);
this.group.Add(this.growShrink);
this.group.Add(this.value);
this.group.Render();
}

public string MinText
{
get => this.randomMin.Text;
set => this.randomMin.Text = value;
}

public string MaxText
{
get => this.randomMax.Text;
set => this.randomMax.Text = value;
}

public float Min
{
get => this.randomMin.Value;
set
{
this.randomMin.Min = value;
this.randomMax.Min = value;
}
}

public float Max
{
get => this.randomMax.Value;
set
{
this.randomMin.Max = value;
this.randomMax.Max = value;
}
}

public float MinValue
{
get => this.randomMin.Value;
set => this.randomMin.Value = value;
}

public float MaxValue
{
get => this.randomMax.Value;
set => this.randomMax.Value = value;
}

public Point Position
{
get => this.group.Position;
set => this.group.Position = value;
}

public float Value
{
get => this.value.Value;
set => this.value.Value = value;
}

public bool GrowValue => this.growShrink.IsChecked;

public bool IsRandomized => this.randomize.IsChecked;

public bool IsNotRandomized => !this.randomize.IsChecked;

public float Left => this.group.Left;

public float Top => this.group.Top;

public float Right => this.group.Right;

public float Bottom => this.group.Bottom;

public float Width => this.group.Width;

public float Height => this.group.Height;

public void Render() => this.group.Render();

private void Randomize_OnCheckedChanged(object? sender, bool e)
{
this.growShrink.Visible = !this.growShrink.Visible;
this.value.Visible = !this.value.Visible;
this.randomMin.Visible = !this.randomMin.Visible;
this.randomMax.Visible = !this.randomMax.Visible;
this.lockRanges.Visible = !this.lockRanges.Visible;
}

private void RandomMin_OnValueChanged(object? sender, float e)
{
if (this.lockRanges.IsChecked)
{
this.randomMax.Value = e;
}
}

private void RandomMax_OnValueChanged(object? sender, float e)
{
if (this.lockRanges.IsChecked)
{
this.randomMin.Value = e;
}
}

private void LockRanges_OnCheckedChanged(object? sender, bool e)
{
if (!e)
{
return;
}

if (Math.Abs(this.randomMin.Value - this.randomMax.Value) < 0.0001)
{
return;
}

var minValue = Math.Min(this.randomMin.Value, this.randomMax.Value);
var maxValue = Math.Max(this.randomMax.Value, this.randomMax.Value);
var delta = maxValue - minValue;

var newMinValue = minValue + (delta / 2f);
var newMaxValue = maxValue - (delta / 2f);

this.randomMin.Value = newMinValue;
this.randomMax.Value = newMaxValue;
}
}
5 changes: 4 additions & 1 deletion Testing/PlazmaTesting/PlazmaTesting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="KinsonDigital.KdGui" Version="1.0.0-preview.1" />
<PackageReference Include="KinsonDigital.KdGui" Version="1.0.0-preview.3" />
<PackageReference Include="KinsonDigital.Velaptor" Version="1.0.0-preview.36" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -34,6 +34,9 @@
<None Update="Content\Graphics\drop.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Content\Graphics\angle.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading