From 8c0f9d6b02eac97b7a45780f82f5683771745cf0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Fri, 2 Apr 2021 07:54:52 +0200 Subject: DebugLog, event bindings resolutions, enumSelector bitfields, wip --- Samples/DebugLogAnalyzer/src/DebugInterface.cs | 114 +++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Samples/DebugLogAnalyzer/src/DebugInterface.cs (limited to 'Samples/DebugLogAnalyzer/src/DebugInterface.cs') diff --git a/Samples/DebugLogAnalyzer/src/DebugInterface.cs b/Samples/DebugLogAnalyzer/src/DebugInterface.cs new file mode 100644 index 00000000..c0615321 --- /dev/null +++ b/Samples/DebugLogAnalyzer/src/DebugInterface.cs @@ -0,0 +1,114 @@ +// Copyright (c) 2013-2019 Bruyère Jean-Philippe +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; +using Crow.Cairo; +using System.Threading; + +namespace Crow +{ + public class DebugInterface : SampleBase { + static DebugInterface() { + DbgLogger.IncludeEvents = DbgEvtType.None; + DbgLogger.DiscardEvents = DbgEvtType.None; + DbgLogger.ConsoleOutput = true; + } + public DebugInterface (IntPtr hWin) : base (hWin) + { + surf = new ImageSurface (Format.Argb32, 100, 100); + } + + public override void Run() + { + Init(); + + Thread t = new Thread (interfaceThread) { + IsBackground = true + }; + t.Start (); + } + public bool Terminate; + string source; + Action delRegisterForRepaint;//call RegisterForRepaint in the container widget (DebugInterfaceWidget) + Action delSetCurrentException; + + void interfaceThread () { + while (!Terminate) { + try + { + Update(); + } + catch (System.Exception ex) + { + if (Monitor.IsEntered(LayoutMutex)) + Monitor.Exit (LayoutMutex); + if (Monitor.IsEntered(UpdateMutex)) + Monitor.Exit (UpdateMutex); + if (Monitor.IsEntered(ClippingMutex)) + Monitor.Exit (ClippingMutex); + delSetCurrentException (ex); + ClearInterface(); + Thread.Sleep(1000); + } + + if (IsDirty) + delRegisterForRepaint(); + + Thread.Sleep (UPDATE_INTERVAL); + } + } + public IntPtr SurfacePointer { + get { + lock(UpdateMutex) + return surf.Handle; + } + } + public void RegisterDebugInterfaceCallback (object w){ + Type t = w.GetType(); + delRegisterForRepaint = (Action)Delegate.CreateDelegate(typeof(Action), w, t.GetMethod("RegisterForRepaint")); + delSetCurrentException = (Action)Delegate.CreateDelegate(typeof(Action), w, t.GetProperty("CurrentException").GetSetMethod()); + } + public void ResetDirtyState () { + IsDirty = false; + } + public string Source { + set { + if (source == value) + return; + source = value; + if (string.IsNullOrEmpty(source)) + return; + delSetCurrentException(null); + try + { + lock (UpdateMutex) { + Widget tmp = CreateITorFromIMLFragment (source).CreateInstance(); + ClearInterface(); + AddWidget (tmp); + tmp.DataSource = this; + } + } + catch (IML.InstantiatorException iTorEx) + { + delSetCurrentException(iTorEx.InnerException); + } + catch (System.Exception ex) + { + delSetCurrentException(ex); + } + } + } + public void Resize (int width, int height) { + + lock (UpdateMutex) { + clientRectangle = new Rectangle (0, 0, width, height); + surf?.Dispose(); + surf = new ImageSurface (Format.Argb32, width, height); + foreach (Widget g in GraphicTree) + g.RegisterForLayouting (LayoutingType.All); + RegisterClip (clientRectangle); + } + } + } +} \ No newline at end of file -- cgit v1.3.1-4-g156e