diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-30 19:39:53 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-30 19:39:53 +0200 |
| commit | 882652abf66dadccbec62dfa478547f18b343fc8 (patch) | |
| tree | 8860eee422aeae37477306bdb1aa8598f8c287e4 /Samples/common/src | |
| parent | 2866fa7335eabc4371cb6909348a8db688c9f59d (diff) | |
| parent | a4367fb29faf7ee987b937e2397359a6020f25b9 (diff) | |
Merge branch 'FileDialogImprove'
Diffstat (limited to 'Samples/common/src')
| -rw-r--r-- | Samples/common/src/MyNumericControl.cs | 46 | ||||
| -rw-r--r-- | Samples/common/src/SampleBase.cs | 78 | ||||
| -rw-r--r-- | Samples/common/src/TestWidget.cs | 26 |
3 files changed, 131 insertions, 19 deletions
diff --git a/Samples/common/src/MyNumericControl.cs b/Samples/common/src/MyNumericControl.cs new file mode 100644 index 00000000..38e162a3 --- /dev/null +++ b/Samples/common/src/MyNumericControl.cs @@ -0,0 +1,46 @@ +//Tutorial +using Crow; + +namespace MyNumericControl { + public class MyNumericControl : TemplatedControl { + protected double actualValue, minValue, maxValue; + public double Minimum { + get => minValue; + set { + if (minValue == value) + return; + minValue = value; + if (Value < minValue) + Value = minValue; + NotifyValueChangedAuto (minValue); + } + } + public double Maximum { + get => maxValue; + set { + if (maxValue == value) + return; + maxValue = value; + NotifyValueChangedAuto (maxValue); + + if (Value > maxValue) + Value = maxValue; + + } + } + public virtual double Value { + get => actualValue; + set { + if (actualValue == value) + return; + if (value < minValue) + actualValue = minValue; + else if (value > maxValue) + actualValue = maxValue; + else + actualValue = value; + NotifyValueChangedAuto (actualValue); + } + } + } +}
\ No newline at end of file diff --git a/Samples/common/src/SampleBase.cs b/Samples/common/src/SampleBase.cs index 3e0ef714..ce043b37 100644 --- a/Samples/common/src/SampleBase.cs +++ b/Samples/common/src/SampleBase.cs @@ -11,31 +11,13 @@ using System.Runtime.InteropServices; using System.Threading; using Crow.Drawing; +using System.Diagnostics; namespace Samples { public class SampleBase : Interface { -#if NETCOREAPP - static IntPtr resolveUnmanaged(Assembly assembly, String libraryName) - { - switch (libraryName) - { - case "glfw3": - return NativeLibrary.Load("glfw", assembly, null); - case "rsvg-2.40": - return NativeLibrary.Load("rsvg-2", assembly, null); - } - Console.WriteLine($"[UNRESOLVE] {assembly} {libraryName}"); - return IntPtr.Zero; - } - - static SampleBase() - { - System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()).ResolvingUnmanagedDll += resolveUnmanaged; - } -#endif public SampleBase(IntPtr hWin) : base(800, 600, hWin) { } public SampleBase() : base(800, 600, true, true) { } public SampleBase(int width, int height, bool startUIThread, bool createSurface) : @@ -436,5 +418,63 @@ namespace Samples } return base.OnKeyDown(e); } + public IEnumerable<RandomProgress> RandomProgressList { + get { + for (int i=0; i< RandomProgressItemCount; i++) + yield return new RandomProgress (); + } + } + int randomProgressItemCount = 10; + public int RandomProgressItemCount { + get => randomProgressItemCount; + set { + if (randomProgressItemCount == value) + return; + randomProgressItemCount = value; + NotifyValueChanged (randomProgressItemCount); + NotifyValueChanged ("RandomProgressList", RandomProgressList); + } + } + + public class RandomProgress : IValueChange { + static Random rnd = new Random(); + public event EventHandler<ValueChangeEventArgs> ValueChanged; + public void NotifyValueChanged(object _value, [CallerMemberName] string caller = null) + => ValueChanged.Raise(this, new ValueChangeEventArgs(caller, _value)); + public void NotifyValueChanged(string membername, object _value) + => ValueChanged.Raise(this, new ValueChangeEventArgs(membername, _value)); + public RandomProgress () { + step = rnd.Next (10); + max = rnd.Next (100, 1000); + sleep = rnd.Next (2,200); + Thread t = new Thread(increment); + t.IsBackground = true; + t.Start (); + + NotifyValueChanged ("Maximum", max); + } + int val, step, max, sleep; + public int Value { + get => val; + set { + if (val == value) + return; + val = value; + NotifyValueChanged (val); + } + } + public int Maximum => max; + + void increment() { + Stopwatch sw = Stopwatch.StartNew(); + while (sw.ElapsedMilliseconds < 10000) { + Value += step; + if (Value > max) + Value = 0; + Thread.Sleep (sleep); + } + Value = max; + } + } } }
\ No newline at end of file diff --git a/Samples/common/src/TestWidget.cs b/Samples/common/src/TestWidget.cs new file mode 100644 index 00000000..bf2f6bd0 --- /dev/null +++ b/Samples/common/src/TestWidget.cs @@ -0,0 +1,26 @@ +//Tutorial +using Crow; +using Crow.Drawing; +using Glfw; + +namespace TestWidget { + public class TestWidget : Widget { + protected override void onDraw (Context gr) { + base.onDraw (gr); + gr.SetSource (myColor); + gr.Rectangle (ClientRectangle); + gr.Fill(); + } + Color myColor = Colors.Green; + public override void onMouseEnter(object sender, MouseMoveEventArgs e) { + base.onMouseEnter (sender, e); + myColor = Colors.Chartreuse; + RegisterForRedraw (); + } + public override void onMouseLeave(object sender, MouseMoveEventArgs e) { + base.onMouseLeave (sender, e); + myColor = Colors.Green; + RegisterForRedraw (); + } + } +}
\ No newline at end of file |