From 7ec412bbf32017f1a9a1be8eea7024f770baefff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 1 Feb 2021 14:57:37 +0100 Subject: [PATCH] DbgLogger output to console by default --- Crow/Crow.csproj | 3 +- Crow/src/DebugUtils/DbgEvent.cs | 16 +- Crow/src/DebugUtils/DebugLogger.cs | 12 +- Crow/src/Widgets/Widget.cs | 10 +- Samples/ShowCase/ShowCase.cs | 21 +- Samples/ShowCase/ui/showcase.crow | 8 +- Samples/common/ui/Interfaces/Divers/4.crow | 2295 +++++--------------- 7 files changed, 650 insertions(+), 1715 deletions(-) diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj index a3c9e805..fc39aa69 100644 --- a/Crow/Crow.csproj +++ b/Crow/Crow.csproj @@ -26,11 +26,12 @@ _DESIGN_MODE;_MEASURE_TIME false false + App.config full - $(DefineConstants);_DEBUG;_DEBUG_LOG;TRACE;_DEBUG_DISPOSE;_DEBUG_BINDING;_DEBUG_CLIP_RECTANGLE + $(DefineConstants);DEBUG;_DEBUG_LOG;TRACE;_DEBUG_DISPOSE;_DEBUG_BINDING;_DEBUG_CLIP_RECTANGLE true diff --git a/Crow/src/DebugUtils/DbgEvent.cs b/Crow/src/DebugUtils/DbgEvent.cs index a4bdd058..fe056f79 100644 --- a/Crow/src/DebugUtils/DbgEvent.cs +++ b/Crow/src/DebugUtils/DbgEvent.cs @@ -128,6 +128,8 @@ namespace Crow type = evtType, }; } + public virtual string Print() + => $"{begin,10}:{threadId,-2}:{type,-20}:"; public override string ToString () => $"{begin};{end};{threadId};{type}"; @@ -171,11 +173,8 @@ namespace Crow case DbgEvtType.TGCancelLoadingThread: return Colors.Maroon; default: - return Colors.Crimson; + return Colors.White; } - if (type.HasFlag (DbgEvtType.Lock)) - return Colors.DarkMagenta; - return Colors.White; } } public override bool IsWidgetEvent => true; @@ -186,7 +185,11 @@ namespace Crow InstanceIndex = w.instanceIndex; #endif } - public override string ToString () +#if DEBUG_LOG + public override string Print () + => $"{base.Print ()} {Widget.GraphicObjects[InstanceIndex]}"; +#endif + public override string ToString () => $"{base.ToString ()};{InstanceIndex}"; } public class DbgLayoutEvent : DbgWidgetEvent @@ -235,6 +238,9 @@ namespace Crow public void SetLQI (LayoutingQueueItem lqi) { } #endif + public override string Print () + => $"{layouting} {result} {OldSlot}->{NewSlot} {base.Print ()}"; + public override string ToString () => $"{base.ToString ()};{layouting};{result};{OldSlot};{NewSlot}"; } diff --git a/Crow/src/DebugUtils/DebugLogger.cs b/Crow/src/DebugUtils/DebugLogger.cs index cbaec88c..0c5d7f6c 100644 --- a/Crow/src/DebugUtils/DebugLogger.cs +++ b/Crow/src/DebugUtils/DebugLogger.cs @@ -85,6 +85,7 @@ namespace Crow { public static DbgEvtType IncludeEvents = DbgEvtType.All; public static DbgEvtType DiscardEvents = DbgEvtType.Focus; + public static bool ConsoleOutput = true; static bool logevt (DbgEvtType evtType) => (evtType & DiscardEvents) == 0 && (evtType & IncludeEvents) != 0; @@ -202,6 +203,7 @@ namespace Crow static DbgEvent addEventInternal (DbgEvtType evtType, params object [] data) { DbgEvent evt = null; +#if DEBUG_LOG if (data == null || data.Length == 0) evt = new DbgEvent (chrono.ElapsedTicks, evtType); else if (data [0] is Widget w) @@ -211,7 +213,15 @@ namespace Crow else evt = new DbgEvent (chrono.ElapsedTicks, evtType); - curEventList.Add (evt); + if (ConsoleOutput) { + if (evt.type.HasFlag (DbgEvtType.Error)) { + Console.ForegroundColor = ConsoleColor.Red; + } + Console.WriteLine (evt.Print()); + Console.ResetColor (); + } else + curEventList.Add (evt); +#endif return evt; } #if DEBUG_LOG diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 92711e27..05e258ef 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -141,8 +141,7 @@ namespace Crow Dispose(true); GC.SuppressFinalize(this); } - ~Widget(){ - Debug.WriteLine(this.ToString() + " not disposed by user"); + ~Widget(){ Dispose(false); } protected virtual void Dispose(bool disposing){ @@ -1832,7 +1831,6 @@ namespace Crow if (cacheEnabled) { if (IsDirty) RecreateCache (); - UpdateCache (ctx); if (!IsEnabled) paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); @@ -2013,9 +2011,7 @@ namespace Crow } public virtual void onMouseEnter(object sender, MouseMoveEventArgs e) { - if (Focusable) - IFace.MouseCursor = MouseCursor; - + IFace.MouseCursor = MouseCursor; if (IFace.DragAndDropOperation != null) { Widget g = this; while (g != null) { @@ -2044,7 +2040,7 @@ namespace Crow #endregion protected virtual void onFocused(object sender, EventArgs e){ - DbgLogger.AddEvent (DbgEvtType.FocusedWidget, this); + DbgLogger.AddEvent (DbgEvtType.FocusedWidget, this); Focused.Raise (this, e); } protected virtual void onUnfocused(object sender, EventArgs e){ diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs index d3b40d6f..b504648e 100644 --- a/Samples/ShowCase/ShowCase.cs +++ b/Samples/ShowCase/ShowCase.cs @@ -9,6 +9,7 @@ using System.Text; using Crow.IML; using System.Runtime.CompilerServices; using Glfw; +using System.Diagnostics; namespace ShowCase { @@ -16,7 +17,11 @@ namespace ShowCase { static void Main () { + DbgLogger.IncludeEvents = DbgEvtType.Widget; + DbgLogger.DiscardEvents = DbgEvtType.Focus; + Environment.SetEnvironmentVariable ("FONTCONFIG_PATH", @"C:\Users\Jean-Philippe\source\vcpkg\installed\x64-windows\tools\fontconfig\fonts"); + using (Showcase app = new Showcase ()) app.Run (); } @@ -43,6 +48,7 @@ namespace ShowCase NotifyValueChanged (CurrentFile); } } + public string Source { get => source; set { @@ -50,7 +56,9 @@ namespace ShowCase return; source = value; - reloadFromSource (); + if (!reloadChrono.IsRunning) + reloadChrono.Restart (); + CMDSave.CanExecute = source != origSource; NotifyValueChanged (source); } @@ -243,7 +251,14 @@ namespace ShowCase showError (ex); } } + Stopwatch reloadChrono = Stopwatch.StartNew (); + public override void UpdateFrame () { + base.UpdateFrame (); + if (reloadChrono.ElapsedMilliseconds < 200) + return; + reloadFromSource (); + reloadChrono.Reset (); + } - - } + } } \ No newline at end of file diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 95aa0999..2447ab67 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -21,13 +21,13 @@ - + Font="consolas, 12"/> - + CursorSize="{../scroller1.ChildHeightRatio}" Maximum="{../scroller1.MaxScrollY}" />-->