diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-26 08:23:19 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2021-10-26 08:23:19 +0200 |
| commit | c706b713a716e8b7fd29508ccf88e5de5041d1d4 (patch) | |
| tree | c71fcc73e4f28c9248eece7df8a2c70225cc498c /Samples/common/src | |
| parent | 942155da0d427b7c4f98fa91da390461b5f1dd9f (diff) | |
rename all 'GraphicObject' to 'Widget', move to netcoreapp3.0 for crow library to use LoadContext for native dll resolutionFileDialogImprove
Diffstat (limited to 'Samples/common/src')
| -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 |