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/SampleBase.cs | |
| parent | 2866fa7335eabc4371cb6909348a8db688c9f59d (diff) | |
| parent | a4367fb29faf7ee987b937e2397359a6020f25b9 (diff) | |
Merge branch 'FileDialogImprove'
Diffstat (limited to 'Samples/common/src/SampleBase.cs')
| -rw-r--r-- | Samples/common/src/SampleBase.cs | 78 |
1 files changed, 59 insertions, 19 deletions
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 |