diff options
Diffstat (limited to 'Samples/DebugLogAnalyzer/src')
| -rw-r--r-- | Samples/DebugLogAnalyzer/src/DbgEventWidget.cs | 162 | ||||
| -rw-r--r-- | Samples/DebugLogAnalyzer/src/DbgLogViewer.cs | 807 | ||||
| -rw-r--r-- | Samples/DebugLogAnalyzer/src/DebugInterface.cs | 142 | ||||
| -rw-r--r-- | Samples/DebugLogAnalyzer/src/DebugInterfaceWidget.cs | 472 | ||||
| -rw-r--r-- | Samples/DebugLogAnalyzer/src/Program.cs | 259 |
5 files changed, 0 insertions, 1842 deletions
diff --git a/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs b/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs deleted file mode 100644 index 3e11aa3f..00000000 --- a/Samples/DebugLogAnalyzer/src/DbgEventWidget.cs +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2013-2020 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using System.ComponentModel; -using Crow.Drawing; -using Crow.DebugLogger; -using DebugLogAnalyzer; - -namespace Crow -{ - public class DbgEventView : TemplatedContainer { - DbgEvent evt; - public DbgEvent Event { - get => evt; - set { - if (evt == value) - return; - evt = value; - NotifyValueChangedAuto (evt); - } - } - } - public class DbgEventWidget : Widget - { - public DbgEventWidget (){} - - DbgEvent evt, hoverEvt; - long ticksPerPixel; - double pixelPerTick; - - object dataMutex = new object(); - - public DbgEvent Event { - get => evt; - set { - if (evt == value) - return; - lock (dataMutex) - evt = value; - updatePixelPerTicks (); - NotifyValueChangedAuto (evt); - RegisterForRedraw (); - } - } - public DbgEvent HoverEvent { - get => hoverEvt; - private set { - if (hoverEvt == value) - return; - lock (dataMutex) - evt = value; - hoverEvt = value; - NotifyValueChangedAuto (hoverEvt); - } - } - - [DefaultValue ("1000")] - public long TicksPerPixel { - get => ticksPerPixel; - set { - if (ticksPerPixel == value) - return; - ticksPerPixel = value; - NotifyValueChangedAuto (ticksPerPixel); - if (Width == Measure.Fit) - RegisterForLayouting (LayoutingType.Width); - } - } - - public override int measureRawSize (LayoutingType lt) - { - updatePixelPerTicks (); - if (lt == LayoutingType.Width) - contentSize.Width = Event == null ? 0 : (int)Math.Max(pixelPerTick * Event.Duration, 2); - - return base.measureRawSize (lt); - } - - public override void OnLayoutChanges (LayoutingType layoutType) - { - if (layoutType == LayoutingType.Width) - updatePixelPerTicks (); - - base.OnLayoutChanges (layoutType); - } - - protected override void onDraw (Context gr) - { - lock (dataMutex) { - - if (Event == null) { - base.onDraw (gr); - return; - } - - gr.LineWidth = 1; - gr.SetDash (new double [] { 1.0, 3.0 }, 0); - - Rectangle cb = ClientRectangle; - - if (Event.Duration == 0) { - gr.SetSource (Event.Color); - gr.Rectangle (cb); - gr.Fill (); - return; - } - - drawEvent (gr, cb.Height, Event); - } - } - void drawEvent (Context ctx, int h, DbgEvent dbge) - { - double w = Math.Max(dbge.Duration * pixelPerTick, 2.0); - double x = (dbge.begin - Event.begin) * pixelPerTick; - - ctx.Rectangle (x, 0, w, h); - ctx.SetSource (dbge.Color); - /*if (dbge.IsSelected) { - ctx.FillPreserve (); - ctx.SetSource (1, 1, 1); - ctx.Stroke (); - }else*/ - ctx.Fill (); - - if (dbge.Events == null) - return; - foreach (DbgEvent e in dbge.Events) - drawEvent (ctx, h, e); - } - - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - if (Event != null) { - Point m = ScreenPointToLocal (e.Position); - long curTick = (long)(m.X / pixelPerTick) + Event.begin; - HoverEvent = hoverEvent (Event, curTick); - - e.Handled = true; - } - base.onMouseMove (sender, e); - } - - DbgEvent hoverEvent (DbgEvent hevt, long curTick){ - if (hevt.Events != null) { - foreach (DbgEvent e in hevt.Events) { - if (curTick >= e.begin && curTick <= e.end) - return hoverEvent (e, curTick); - } - } - return hevt; - } - void updatePixelPerTicks () - { - if (Width == Measure.Fit) - pixelPerTick = 1.0 / ticksPerPixel; - else - pixelPerTick = Event == null ? 0 : (double)ClientRectangle.Width / Event.Duration; - } - } -}
\ No newline at end of file diff --git a/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs b/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs deleted file mode 100644 index 7b91f9f0..00000000 --- a/Samples/DebugLogAnalyzer/src/DbgLogViewer.cs +++ /dev/null @@ -1,807 +0,0 @@ -// Copyright (c) 2013-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com> -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; -using Crow.Drawing; -using Crow.DebugLogger; -using System.Diagnostics; - -namespace Crow -{ - public class DbgLogViewer : Widget - { - public static Dictionary<DbgEvtType, Color> colors; - - public static Configuration colorsConf = new Configuration ("dbgcolor.conf");//, Interface.GetStreamFromPath("#Crow.dbgcolor.conf")); - - public static void reloadColors () { - colors = new Dictionary<DbgEvtType, Color>(); - foreach (string n in colorsConf.Names) { - DbgEvtType t = (DbgEvtType)Enum.Parse (typeof(DbgEvtType), n); - Color c = colorsConf.Get<Color> (n); - colors.Add (t, c); - } - - } - #region CTOR - static DbgLogViewer() { - //reloadColors (); - - } - protected DbgLogViewer () : base(){} - public DbgLogViewer (Interface iface, string style = null) : base(iface, style){} - #endregion - - FontExtents fe; - - - double xScale = 1.0/1024.0, yScale = 1.0, leftMargin, topMargin = 0.0; - DbgWidgetRecord curWidget, hoverWidget; - DbgEvent curEvent, hoverEvent; - - IList<DbgEvent> events = new List<DbgEvent> (); - IList<DbgWidgetRecord> widgets = new List<DbgWidgetRecord> (); - - - public DbgEvtType Filter { - get => Configuration.Global.Get<DbgEvtType> ("DbgLogViewFilter"); - set { - if (Filter == value) - return; - Configuration.Global.Set ("DbgLogViewFilter", value); - NotifyValueChangedAuto(Filter); - RegisterForGraphicUpdate(); - } - } - public IList<DbgEvent> Events { - get => events; - set { - if (events == value) - return; - events = value; - NotifyValueChanged (nameof (Events), events); - - maxTicks = minTicks = 0; - if (events != null && events.Count > 0) { - minTicks = long.MaxValue; - foreach (DbgEvent e in events) { - if (e.begin < minTicks) - minTicks = e.begin; - if (e.end > maxTicks) - maxTicks = e.end; - } - visibleTicks = maxTicks - minTicks; - XScale = (ClientRectangle.Width - leftMargin)/visibleTicks; - ScrollX = 0; - ScrollY = 0; - } else { - maxTicks = 1; - XScale = 1.0/1024.0; - } - - - RegisterForGraphicUpdate (); - } - } - public IList<DbgWidgetRecord> Widgets { - get => widgets; - set { - if (widgets == value) - return; - widgets = value; - NotifyValueChanged (nameof (Widgets), widgets); - updateMargins (); - updateMaxScrollX (); - updateMaxScrollY (); - } - } - public DbgWidgetRecord CurrentWidget { - get => curWidget; - set { - if (curWidget == value) - return; - curWidget = value; - NotifyValueChanged (nameof (CurrentWidget), curWidget); - if (CurrentWidget == null) - return; - if (CurrentWidget.listIndex < scrollY || CurrentWidget.listIndex > scrollY + visibleLines) - ScrollY = CurrentWidget.listIndex - (visibleLines / 2); - - currentLine = CurrentWidget.listIndex; - RegisterForRedraw(); - } - } - public DbgEvent CurrentEvent { - get => curEvent; - set { - if (curEvent == value) - return; - /*if (curEvent != null) - curEvent.IsSelected = false;*/ - curEvent = value; - if (curEvent != null) { - //curEvent.IsSelected = true; - if (curEvent is DbgWidgetEvent we) { - //CurrentWidget = Widgets [we.InstanceIndex]; - hoverLine = we.InstanceIndex; - } - currentTick = curEvent.begin; - if (curEvent.begin > minTicks + ScrollX + visibleTicks || - curEvent.end < minTicks + ScrollX) - ScrollX = curEvent.begin - minTicks - visibleTicks / 2; - } - NotifyValueChanged (nameof (CurrentEvent), curEvent); - RegisterForRedraw (); - } - } - public DbgWidgetRecord HoverWidget { - get => hoverWidget; - internal set { - if (hoverWidget == value) - return; - hoverWidget = value; - NotifyValueChanged (nameof (HoverWidget), hoverWidget); - } - } - - public DbgEvent HoverEvent { - get => hoverEvent; - set { - if (hoverEvent == value) - return; - hoverEvent = value; - NotifyValueChanged (nameof (HoverEvent), hoverEvent); - RegisterForRepaint (); - } - } - - long hoverTick = 0, currentTick, selStart = -1, selEnd = -1, minTicks = 0, maxTicks = 0, visibleTicks = 0; - int hoverLine = -1, currentLine = -1; - int visibleLines = 1; - Point mousePos; - - public double XScale { - get => xScale; - set { - if (xScale == value) - return; - xScale = value; - NotifyValueChanged ("XScale", xScale); - updateVisibleTicks (); - RegisterForGraphicUpdate (); - } - } - public double YScale { - get => yScale; - set { - if (yScale == value) - return; - yScale = value; - NotifyValueChanged ("YScale", yScale); - RegisterForGraphicUpdate (); - } - } - public override Font Font { - get { return base.Font; } - set { - base.Font = value; - using (Context gr = new Context (IFace.surf)) { - setFontForContext (gr); - fe = gr.FontExtents; - } - updateMargins (); - } - } - RectangleD getWidgetEvtBounds (DbgEvent evt, ref Rectangle cb, double penY) { - double x = xScale * (evt.begin - minTicks - ScrollX); - double w = Math.Max (Math.Max (2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale); - if (x < 0.0) { - w += x; - x = 0.0; - } - x += leftMargin + cb.Left; - double rightDiff = x + w - cb.Right; - if (rightDiff > 0) - w -= rightDiff; - return new RectangleD(x, penY, w, fe.Height); - } - void drawEvents (Context ctx, IList<DbgEvent> evts) - { - if (evts == null || evts.Count == 0) - return; - Rectangle cb = ClientRectangle; - - foreach (DbgEvent evt in evts) { - if ((evt.Category & currentFilter) == currentFilter) { - if (evt.end - minTicks <= ScrollX) - continue; - if (evt.begin - minTicks > ScrollX + visibleTicks) - break; - double penY = topMargin + ClientRectangle.Top; - - if (evt.type.HasFlag (DbgEvtType.Widget)) { - DbgWidgetEvent eW = evt as DbgWidgetEvent; - int lIdx = eW.InstanceIndex - ScrollY; - if (lIdx >= 0 && lIdx <= visibleLines) { - - penY += (lIdx) * fe.Height; - - ctx.SetSource (evt.Color); - ctx.Rectangle (getWidgetEvtBounds (evt, ref cb, penY)); - ctx.Fill (); - } - } else if (evt.type.HasFlag (DbgEvtType.IFace)) { - double x = xScale * (evt.begin - minTicks - ScrollX); - double w = Math.Max (Math.Max (2.0, 2.0 * xScale), (double)(evt.end - evt.begin) * xScale); - if (x < 0.0) { - w += x; - x = 0.0; - } - x += leftMargin + cb.Left; - double rightDiff = x + w - cb.Right; - if (rightDiff > 0) - w -= rightDiff; - //ctx.SetSource (0.9,0.9,0.0,0.1); - ctx.SetSource (evt.Color.AdjustAlpha(0.15)); - ctx.Rectangle (x, cb.Top + topMargin, w, cb.Height); - ctx.Fill (); - } - } - drawEvents (ctx, evt.Events); - } - } - - DbgEvtType currentFilter; - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - setFontForContext (gr); - - if (widgets == null) - return; - - gr.LineWidth = 1.0; - - Rectangle cb = ClientRectangle; - - double penY = topMargin + ClientRectangle.Top; - - for (int i = 0; i < visibleLines; i++) { - if (i + ScrollY >= widgets.Count) - break; - int gIdx = i + ScrollY; - DbgWidgetRecord g = widgets [gIdx]; - - penY += fe.Height; - - gr.SetSource (Crow.Colors.Jet); - gr.MoveTo (cb.X, penY - 0.5); - gr.LineTo (cb.Right, penY - 0.5); - gr.Stroke (); - - double penX = 5.0 * g.xLevel + cb.Left; - - if (g.xLevel == 0) - gr.SetSource (Crow.Colors.LightSalmon); - else if (currentLine == g.listIndex) - gr.SetSource(Colors.RoyalBlue); - else - Foreground.SetAsSource (IFace, gr); - - gr.MoveTo (penX, penY - gr.FontExtents.Descent); - gr.ShowText (g.name + gIdx); - } - - currentFilter = Filter; - drawEvents (gr, events); - - gr.MoveTo (cb.Left, topMargin - 0.5 + cb.Top); - gr.LineTo (cb.Right, topMargin - 0.5 + cb.Top); - - gr.MoveTo (leftMargin + cb.Left, cb.Top); - gr.LineTo (leftMargin + cb.Left, cb.Bottom); - gr.SetSource (Crow.Colors.Grey); - - penY = topMargin + ClientRectangle.Top; - - //graduation - long largeGrad = long.Parse ("1" + new string ('0', visibleTicks.ToString ().Length - 1)); - long smallGrad = Math.Max (1, largeGrad / 10); - - long firstVisibleTicks = minTicks + ScrollX; - long curGrad = firstVisibleTicks - firstVisibleTicks % smallGrad + smallGrad; - - long gg = curGrad - ScrollX - minTicks; - while (gg < visibleTicks ) { - double x = (double)gg * xScale + leftMargin + cb.Left; - - gr.MoveTo (x, penY - 0.5); - if (curGrad % largeGrad == 0) { - gr.LineTo (x, penY - 8.5); - string str = ticksToMS(curGrad); - TextExtents te = gr.TextExtents (str); - gr.RelMoveTo (-0.5 * te.Width, -2.0); - gr.ShowText (str); - }else - gr.LineTo (x, penY - 2.5); - - curGrad += smallGrad; - gg = curGrad - ScrollX - minTicks; - } - - gr.Stroke (); - - - - } - string ticksToMS(long ticks) => Math.Round ((double)ticks / Stopwatch.Frequency * 1000.0, 2).ToString(); - public override void Paint (Context ctx) - { - base.Paint (ctx); - - Rectangle r = new Rectangle(mousePos.X, 0, 1, Slot.Height); - Rectangle ctxR = ContextCoordinates (r); - Rectangle cb = ClientRectangle; - ctx.LineWidth = 1.0; - if (hoverTick >= 0) { - double x = xScale * (hoverTick - minTicks - ScrollX) + leftMargin; - if (x - Math.Truncate (x) > 0.5) - x = Math.Truncate (x) + 0.5; - else - x = Math.Truncate (x) - 0.5; - ctx.MoveTo (x, cb.Top + topMargin - 4.0); - ctx.LineTo (x, cb.Bottom); - ctx.SetSource (0.7,0.7,0.7,0.5); - ctx.Stroke(); - } - if (currentTick >= 0) { - double x = xScale * (currentTick - minTicks - ScrollX) + leftMargin; - if (x > leftMargin && x < cb.Right) { - if (x - Math.Truncate (x) > 0.5) - x = Math.Truncate (x) + 0.5; - else - x = Math.Truncate (x) - 0.5; - ctx.MoveTo (x, cb.Top); - ctx.LineTo (x, cb.Bottom); - ctx.SetSource (0.2,0.7,1.0,0.6); - ctx.Stroke(); - } - } - - setFontForContext (ctx); - - string str = ticksToMS(hoverTick); - - ctx.MoveTo (ctxR.X - ctx.TextExtents (str).Width / 2, ctxR.Y + fe.Height); - ctx.ShowText (str); - - ctx.Operator = Operator.Add; - - if (hoverLine >= 0) { - double y = fe.Height * (hoverLine - ScrollY) + topMargin + cb.Top; - r = new Rectangle (cb.Left, (int)y, cb.Width, (int)fe.Height); - - ctx.SetSource (0.1, 0.1, 0.1, 0.4); - ctx.Rectangle (ContextCoordinates (r)); - ctx.Fill (); - - if (hoverEvent is DbgWidgetEvent wevt) { - ctx.SetSource (1.0,1.0,1.0,0.7); - ctx.SetDash (new double[] {1, 2}); - ctx.Rectangle ((Rectangle)getWidgetEvtBounds (wevt, ref cb, y).Inflated (1), 1); - } - } - - if (currentLine >= ScrollY && currentLine < scrollY + visibleLines) { - double y = fe.Height * (currentLine - ScrollY) + topMargin + cb.Top; - r = new Rectangle (cb.Left, (int)y, cb.Width, (int)fe.Height); - - ctx.SetSource (0.1, 0.1, 0.7, 0.2); - ctx.Rectangle (ContextCoordinates (r)); - ctx.Fill (); - } - - if (selStart < 0 || selEnd < 0) { - ctx.Operator = Operator.Over; - return; - } - double selStartX = (double)(selStart - ScrollX - minTicks) * xScale + leftMargin + cb.Left; - double selEndX = (double)(selEnd - ScrollX - minTicks) * xScale + leftMargin + cb.Left; - - if (selStartX < selEndX) { - ctxR.X = (int)selStartX; - ctxR.Width = (int)(selEndX - selStartX); - } else { - ctxR.X = (int)selEndX; - ctxR.Width = (int)(selStartX - selEndX); - } - - ctxR.Width = Math.Max (1, ctxR.Width); - ctx.Rectangle (ctxR); - ctx.SetSource (0.0,0.2,0.8,0.15); - //ctx.SetSource (Colors.Jet); - ctx.Fill(); - ctx.Operator = Operator.Over; - - str = $"{ticksToMS(Math.Abs (selEnd - selStart))} (ms)"; - - ctx.MoveTo (ctxR.Center.X - ctx.TextExtents (str).Width / 2, ctxR.Y + fe.Height); - ctx.SetSource (Colors.Black); - ctx.ShowText (str); - - - - } - public override void OnLayoutChanges (LayoutingType layoutType) - { - base.OnLayoutChanges (layoutType); - switch (layoutType) { - case LayoutingType.Width: - if (xScale < 0) { - visibleTicks = maxTicks - minTicks; - XScale = (ClientRectangle.Width - leftMargin) / visibleTicks; - } - updateVisibleTicks (); - break; - case LayoutingType.Height: - updateVisibleLines (); - break; - } - } - - public override void onMouseLeave (object sender, MouseMoveEventArgs e) - { - base.onMouseLeave (sender, e); - hoverLine = -1; - hoverTick = 0; - } - public override void onMouseMove (object sender, MouseMoveEventArgs e) - { - long lastTick = hoverTick; - int lastLine = hoverLine; - updateMouseLocalPos (e.Position); - - if ((IFace.IsDown (Glfw.MouseButton.Left) || IFace.IsDown (Glfw.MouseButton.Middle)) && selStart >= 0) - selEnd = hoverTick; - else if (IFace.IsDown(Glfw.MouseButton.Right)) { - if (lastTick >= 0 && hoverTick >= 0) - ScrollX += lastTick - hoverTick; - if (lastLine >= 0 && hoverLine >= 0) - ScrollY += lastLine - hoverLine; - updateMouseLocalPos (e.Position); - } else if (widgets != null) { - HoverWidget = (hoverLine < 0 || hoverLine >= widgets.Count) ? null : widgets [hoverLine]; - //HoverEvent = hoverWidget?.Events.FirstOrDefault (ev => ev.begin <= hoverTick && ev.end >= hoverTick); - double tickPerPixel = (double)visibleTicks / ClientRectangle.Width; - //Console.WriteLine ($"ticks per pixel: {tickPerPixel}"); - Task.Run (() => findHoverEvent (hoverWidget, hoverTick, (int)tickPerPixel)); - } - - RegisterForRepaint(); - - e.Handled = true; - base.onMouseMove (sender, e); - } - void findHoverEvent (DbgWidgetRecord widget, long tick, long precision = 0) { - DbgEvent tmp = widget?.Events.FirstOrDefault (ev => ev.begin - precision <= tick && ev.end + precision >= tick); - if (tmp == null) { - tmp = Events.Where(e=>e.type.HasFlag(DbgEvtType.IFace)).Where (ev => ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault(); - while(tmp != null) { - DbgEvent che = tmp.Events?.Where(e=>e.type.HasFlag(DbgEvtType.IFace)).Where (ev => ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault(); - if (che == null) - break; - tmp = che; - } - } else { - while(tmp != null) { - DbgEvent che = tmp.Events?.OfType<DbgWidgetEvent>()?.Where(ev=>ev.InstanceIndex == widget.listIndex && ev.begin - precision <= tick && ev.end + precision >= tick).FirstOrDefault(); - if (che == null) - break; - tmp = che; - } - } - HoverEvent = tmp; - } - public override void onMouseClick(object sender, MouseButtonEventArgs e) - { - if (e.Button == Glfw.MouseButton.Left) { - if (selEnd < 0) { - currentTick = hoverTick; - currentLine = hoverLine; - CurrentWidget = hoverWidget; - CurrentEvent = hoverEvent; - } - selStart = -1; - selEnd = -1; - } - - e.Handled = true; - base.onMouseClick(sender, e); - } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - if (e.Button == Glfw.MouseButton.Left || e.Button == Glfw.MouseButton.Middle) { - selStart = hoverTick; - selEnd = -1; - } - - RegisterForRedraw (); - e.Handled = true; - base.onMouseDown (sender, e); - } - public override void onMouseUp (object sender, MouseButtonEventArgs e) - { - - if (e.Button == Glfw.MouseButton.Left && selEnd > 0 && selEnd != selStart) { - long scrX = 0; - if (selStart < selEnd) { - visibleTicks = selEnd - selStart; - scrX = selStart - minTicks; - } else { - visibleTicks = selStart - selEnd; - scrX = selEnd - minTicks; - } - XScale = (ClientRectangle.Width - leftMargin) / visibleTicks; - ScrollX = scrX; - } - - RegisterForRedraw (); - e.Handled = true; - base.onMouseUp (sender, e); - } - - /// <summary> Process scrolling vertically, or if shift is down, vertically </summary> - public override void onMouseWheel (object sender, MouseWheelEventArgs e) - { - //base.onMouseWheel (sender, e); - - if (IFace.Shift) - ScrollX -= (int)((double)(e.Delta * MouseWheelSpeed) / xScale); - else if (IFace.Ctrl) - ScrollY -= e.Delta * MouseWheelSpeed; - else { - if (e.Delta > 0) { - XScale *= 2.0; - } else { - if (MaxScrollX > 0) - XScale *= 0.5; - } - ScrollX = (long)(hoverTick - (long)((double)Math.Max(0, mousePos.X - (long)leftMargin) / xScale) - minTicks); - } - } - - public override void onKeyDown (object sender, KeyEventArgs e) - { - base.onKeyDown (sender, e); - - if (e.Key == Glfw.Key.F3) { - if (selEnd < 0) - return; - if (selEnd < selStart) - zoom (selEnd, selStart); - else - zoom (selStart, selEnd); - selEnd = selStart = -1; - } - } - - void updateMargins () - { - leftMargin = topMargin = 0.0; - - if (widgets == null) - return; - - using (Context gr = new Context (IFace.surf)) { - double maxNameWidth = 0.0; - - setFontForContext (gr); - - foreach (DbgWidgetRecord o in widgets) { - double nameWidth = gr.TextExtents (o.name).Width + 5.0 * o.xLevel; - if (nameWidth > maxNameWidth) - maxNameWidth = nameWidth; - } - - leftMargin = 10.5 + maxNameWidth; - topMargin = 2.0 * fe.Height; - - RegisterForGraphicUpdate (); - } - } - - void updateVisibleLines () - { - visibleLines = fe.Height < 1 ? 1 : (int)Math.Ceiling (((double)ClientRectangle.Height - topMargin) / fe.Height); - NotifyValueChanged ("VisibleLines", visibleLines); - updateMaxScrollY (); - } - void updateVisibleTicks () - { - visibleTicks = Math.Max (0, (long)((double)(ClientRectangle.Width - leftMargin) / XScale)); - NotifyValueChanged ("VisibleTicks", visibleTicks); - updateMaxScrollX (); - } - - void updateMaxScrollX () - { - if (widgets == null) { - MaxScrollX = 0; - } else { - long tot = maxTicks - minTicks; - MaxScrollX = Math.Max (0L, tot - visibleTicks); - NotifyValueChanged ("ChildWidthRatio", (double)visibleTicks / tot); - } - } - void updateMaxScrollY () - { - if (widgets == null) - MaxScrollY = 0; - else { - MaxScrollY = Math.Max (0, widgets.Count + 1 - visibleLines); - NotifyValueChanged ("ChildHeightRatio", (double)visibleLines / (widgets.Count + 1)); - } - } - - void updateMouseLocalPos (Point mPos) - { - Rectangle r = ScreenCoordinates (Slot); - Rectangle cb = ClientRectangle; - cb.Left += (int)leftMargin; - cb.Width -= (int)leftMargin; - cb.Y += (int)topMargin; - cb.Height -= (int)topMargin; - - mousePos = mPos - r.Position; - - mousePos.X = Math.Max (cb.X, mousePos.X); - mousePos.X = Math.Min (cb.Right, mousePos.X); - - if (mousePos.Y < cb.Top || mousePos.Y > cb.Bottom) - hoverLine = -1; - else - hoverLine = (int)((double)(mousePos.Y - cb.Top) / fe.Height) + ScrollY; - - NotifyValueChanged ("CurrentLine", hoverLine); - - mousePos.Y = Math.Max (cb.Y, mousePos.Y); - mousePos.Y = Math.Min (cb.Bottom, mousePos.Y); - - hoverTick = (long)((double)(mousePos.X - cb.X) / xScale) + minTicks + ScrollX; - RegisterForRedraw (); - } - void zoom (long start, long end) { - //Rectangle cb = ClientRectangle; - //cb.X += (int)leftMargin; - XScale = ((double)ClientRectangle.Width - leftMargin)/(end - start); - ScrollX = (int)(start - minTicks); - } - - - long scrollX, maxScrollX; - int scrollY, maxScrollY, mouseWheelSpeed; - - /// <summary> - /// if true, key stroke are handled in derrived class - /// </summary> - protected bool KeyEventsOverrides = false; - - /// <summary> Horizontal Scrolling Position </summary> - [DefaultValue(0)] - public virtual long ScrollX { - get => scrollX; - set { - if (scrollX == value) - return; - - long newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollX) - newS = maxScrollX; - - if (newS == scrollX) - return; - - scrollX = newS; - - NotifyValueChangedAuto (scrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling Position </summary> - [DefaultValue(0)] - public virtual int ScrollY { - get => scrollY; - set { - if (scrollY == value) - return; - - int newS = value; - if (newS < 0) - newS = 0; - else if (newS > maxScrollY) - newS = maxScrollY; - - if (newS == scrollY) - return; - - scrollY = newS; - - NotifyValueChangedAuto (scrollY); - RegisterForGraphicUpdate (); - - if (widgets == null) - return; - - Rectangle cb = ClientRectangle; - cb.Left += (int)leftMargin; - cb.Width -= (int)leftMargin; - cb.Y += (int)topMargin; - cb.Height -= (int)topMargin; - - if (mousePos.Y < cb.Top || mousePos.Y > cb.Bottom) - hoverLine = -1; - else - hoverLine = (int)((double)(mousePos.Y - cb.Top) / fe.Height) + ScrollY; - - NotifyValueChanged ("CurrentLine", hoverLine); - } - } - /// <summary> Horizontal Scrolling maximum value </summary> - [DefaultValue(0)] - public virtual long MaxScrollX { - get => maxScrollX; - set { - if (maxScrollX == value) - return; - - maxScrollX = Math.Max(0, value); - - if (scrollX > maxScrollX) - ScrollX = maxScrollX; - - NotifyValueChangedAuto (maxScrollX); - RegisterForGraphicUpdate (); - } - } - /// <summary> Vertical Scrolling maximum value </summary> - [DefaultValue(0)] - public virtual int MaxScrollY { - get => maxScrollY; - set { - if (maxScrollY == value) - return; - - maxScrollY = Math.Max (0, value); - - if (scrollY > maxScrollY) - ScrollY = maxScrollY; - - NotifyValueChangedAuto (maxScrollY); - RegisterForGraphicUpdate (); - } - } - /// <summary> Mouse Wheel Scrolling multiplier </summary> - [DefaultValue(1)] - public virtual int MouseWheelSpeed { - get => mouseWheelSpeed; - set { - if (mouseWheelSpeed == value) - return; - - mouseWheelSpeed = value; - - NotifyValueChangedAuto (mouseWheelSpeed); - } - } - } -} - - diff --git a/Samples/DebugLogAnalyzer/src/DebugInterface.cs b/Samples/DebugLogAnalyzer/src/DebugInterface.cs deleted file mode 100644 index 40656bfe..00000000 --- a/Samples/DebugLogAnalyzer/src/DebugInterface.cs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2013-2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com> -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Crow.Drawing; -using System.Threading; -using Samples; -using System.Runtime.InteropServices; - -namespace Crow -{ - public class DebugInterface : SampleBase { - static DebugInterface() { - DbgLogger.IncludeEvents = DbgEvtType.None; - DbgLogger.DiscardEvents = DbgEvtType.None; - DbgLogger.ConsoleOutput = false; - } - public DebugInterface (IntPtr hWin) : base (hWin) - { - SolidBackground = false; - initBackend (true); - - clientRectangle = new Rectangle (0, 0, 100, 100); - CreateMainSurface (ref clientRectangle); - - } - - public override void Run() - { - Init(); - - Thread t = new Thread (interfaceThread) { - IsBackground = true - }; - t.Start (); - } - public bool ShutDown; - string source; - Action delRegisterForRepaint;//call RegisterForRepaint in the container widget (DebugInterfaceWidget) - Action<Exception> delSetCurrentException; - Func<object> delGetScreenCoordinate; - - void interfaceThread () { - while (!ShutDown) { - try - { - Update(); - } - catch (System.Exception ex) - { - while (Monitor.IsEntered(LayoutMutex)) { - Console.WriteLine ($"[DebugIFace] trying to exit LayoutMutex on error"); - Monitor.Exit (LayoutMutex); - } - while (Monitor.IsEntered(UpdateMutex)) { - Console.WriteLine ($"[DebugIFace] trying to exit UpdateMutex on error"); - Monitor.Exit (UpdateMutex); - } - while (Monitor.IsEntered(ClippingMutex)) { - Console.WriteLine ($"[DebugIFace] trying to exit ClippingMutex on error"); - Monitor.Exit (ClippingMutex); - } - - - /*while (Monitor.IsEntered(LayoutMutex)) - Monitor.Exit (LayoutMutex); - while (Monitor.IsEntered(UpdateMutex)) - Monitor.Exit (UpdateMutex); - while (Monitor.IsEntered(ClippingMutex)) - Monitor.Exit (ClippingMutex);*/ - delSetCurrentException (ex); - Console.WriteLine ($"[DbgIFace] {ex}"); - ClearInterface(); - Thread.Sleep(1000); - } - - if (IsDirty) - delRegisterForRepaint(); - - Thread.Sleep (UPDATE_INTERVAL); - } - } - public void RegisterDebugInterfaceCallback (object w){ - Type t = w.GetType(); - delRegisterForRepaint = (Action)Delegate.CreateDelegate(typeof(Action), w, t.GetMethod("RegisterForRepaint")); - delSetCurrentException = (Action<Exception>)Delegate.CreateDelegate(typeof(Action<Exception>), w, t.GetProperty("CurrentException").GetSetMethod()); - delGetScreenCoordinate = (Func<object>)Delegate.CreateDelegate(typeof(Func<object>), w, t.GetMethod("GetScreenCoordinates")); - } - 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) { - if (!HaveVkvgBackend) - ProcessResize (new Rectangle(0,0,width, height)); - } - public override void ProcessResize(Rectangle bounds) { - lock (UpdateMutex) { - clientRectangle = bounds.Size; - - CreateMainSurface (ref clientRectangle); - - foreach (Widget g in GraphicTree) - g.RegisterForLayouting (LayoutingType.All); - - RegisterClip (clientRectangle); - } - } - public override void ForceMousePosition() - { - Point p = Point.Parse(delGetScreenCoordinate().ToString()); - Glfw.Glfw3.SetCursorPosition (WindowHandle, p.X + MousePosition.X, p.Y + MousePosition.Y); - } - } -} diff --git a/Samples/DebugLogAnalyzer/src/DebugInterfaceWidget.cs b/Samples/DebugLogAnalyzer/src/DebugInterfaceWidget.cs deleted file mode 100644 index 113e5e07..00000000 --- a/Samples/DebugLogAnalyzer/src/DebugInterfaceWidget.cs +++ /dev/null @@ -1,472 +0,0 @@ -// Copyright (c) 2013-2019 Bruyère Jean-Philippe <jp_bruyere@hotmail.com> -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Glfw; -using System.Reflection; -using System.Runtime.Loader; -using System.IO; -using Crow.Drawing; -using System.Diagnostics; -using System.Collections.Generic; -using Crow.DebugLogger; -using System.Linq; - -namespace Crow -{ - public class DebugInterfaceWidget : Widget { - - string imlSource; - List<DbgEvent> events; - List<DbgWidgetRecord> widgets; - Exception currentException; - object dbgIFace; - AssemblyLoadContext crowLoadCtx; - Assembly crowAssembly, thisAssembly; - Type dbgIfaceType; - Action<int, int> delResize; - Func<int, int, bool> delMouseMove; - Func<float, bool> delMouseWheelChanged; - Func<MouseButton, bool> delMouseDown, delMouseUp; - Func<char, bool> delKeyPress; - Func<Key, bool> delKeyDown, delKeyUp; - Action delResetDirtyState; - Action delResetDebugger; - Action<object, string> delSaveDebugLog; - Func<IntPtr> delGetSurfacePointer; - Action<string> delSetSource; - - FieldInfo fiDbg_IncludeEvents, fiDbg_DiscardEvents, fiDbg_ConsoleOutput; - - bool initialized, recording, hasVkvgBackend; - string crowDbgAssemblyLocation; - DbgEvtType recordedEvents, discardedEvents; - - public CommandGroup LoggerCommands => - new CommandGroup( - new Command("Get logs", () => getLog ()), - new Command("Reset logs", () => delResetDebugger ()), - new Command("Save to file", () => saveLogToDebugLogFilePath ()), - new Command("Load from file", () => loadLogFromDebugLogFilePath ()) - ); - public string IMLSource { - get => imlSource; - set { - if (imlSource == value) - return; - imlSource = value; - if (initialized) - delSetSource (imlSource); - NotifyValueChangedAuto(imlSource); - RegisterForRedraw(); - } - } - public Exception CurrentException { - get => currentException; - set { - if (currentException == value) - return; - currentException = value; - NotifyValueChangedAuto(currentException); - } - } - public string CrowDbgAssemblyLocation { - get => crowDbgAssemblyLocation; - set { - if (crowDbgAssemblyLocation == value) - return; - crowDbgAssemblyLocation = value; - NotifyValueChangedAuto(CrowDbgAssemblyLocation); - tryStartDebugInterface(); - } - } - - public bool Recording { - get => recording; - set { - if (recording == value) - return; - recording = value & initialized; - if (recording) { - fiDbg_DiscardEvents.SetValue (dbgIFace, DiscardedEvents); - fiDbg_IncludeEvents.SetValue (dbgIFace, RecordedEvents); - } else { - fiDbg_DiscardEvents.SetValue (dbgIFace, DiscardedEvents); - fiDbg_IncludeEvents.SetValue (dbgIFace, RecordedEvents); - } - NotifyValueChangedAuto(recording); - } - } - public DbgEvtType RecordedEvents { - get => recordedEvents; - set { - if (recordedEvents == value) - return; - recordedEvents = value; - if (Recording) - fiDbg_IncludeEvents.SetValue (dbgIFace, value); - NotifyValueChangedAuto (recordedEvents); - } - } - public DbgEvtType DiscardedEvents { - get => discardedEvents; - set { - if (discardedEvents == value) - return; - discardedEvents = value; - if (Recording) - fiDbg_DiscardEvents.SetValue (dbgIFace, value); - NotifyValueChangedAuto (discardedEvents); - } - } - public string DebugLogFilePath { - get => Configuration.Global.Get<string> ("DebugLogFilePath"); - set { - if (DebugLogFilePath == value) - return; - Configuration.Global.Set ("DebugLogFilePath", value); - NotifyValueChangedAuto (value); - } - } - public string DebugLogFileFolder => System.IO.Path.GetDirectoryName (DebugLogFilePath); - public Command CMDSelectDebugLogFilePath => new Command ("...", - () => { - FileDialog dlg = IFace.LoadIMLFragment<FileDialog> (@" - <FileDialog Caption='Select Log file' CurrentDirectory='{DebugLogFileFolder}' - ShowFiles='true' ShowHidden='true' />"); - dlg.OkClicked += (sender, e) => DebugLogFilePath = (sender as FileDialog).SelectedFileFullPath; - dlg.DataSource = this; - } - ); - int firstWidgetIndexToSave, lastWidgetIndexToSave; - public int FirstWidgetIndexToSave { - get => firstWidgetIndexToSave; - set { - if (firstWidgetIndexToSave == value) - return; - if (value > lastWidgetIndexToSave) - firstWidgetIndexToSave = lastWidgetIndexToSave; - else - firstWidgetIndexToSave = value; - - NotifyValueChangedAuto (firstWidgetIndexToSave); - } - } - public int LastWidgetIndexToSave { - get => lastWidgetIndexToSave; - set { - if (lastWidgetIndexToSave == value) - return; - if (lastWidgetIndexToSave > widgets.Count) - lastWidgetIndexToSave = widgets.Count; - else - lastWidgetIndexToSave = value; - - NotifyValueChangedAuto (lastWidgetIndexToSave); - } - } - - protected override void onInitialized(object sender, EventArgs e) - { - base.onInitialized(sender, e); - - - } - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - } - - public bool CrowDebuggerOK => initialized; - public bool CrowDebuggerNOK => !initialized; - public string CrowDebuggerErrorMessage = ""; - void notifyCrowDebuggerState (string errorMsg = null) { - NotifyValueChanged("CrowDebuggerOK", CrowDebuggerOK); - NotifyValueChanged("CrowDebuggerNOK", CrowDebuggerNOK); - CrowDebuggerErrorMessage = errorMsg; - NotifyValueChanged("CrowDebuggerErrorMessage", CrowDebuggerErrorMessage); - } - - void tryStartDebugInterface () { - if (initialized) - return; - if (!File.Exists (crowDbgAssemblyLocation)) { - notifyCrowDebuggerState($"Crow.dll for debugging file not found"); - return; - } - - crowLoadCtx = new AssemblyLoadContext("CrowDebuggerLoadContext"); - crowLoadCtx.Resolving += (context, assemblyName) => { - return crowLoadCtx.LoadFromAssemblyPath ( - System.IO.Path.Combine ( - System.IO.Path.GetDirectoryName(crowDbgAssemblyLocation), assemblyName.Name + ".dll")); - }; - - //using (crowLoadCtx.EnterContextualReflection()) { - crowAssembly = crowLoadCtx.LoadFromAssemblyPath (crowDbgAssemblyLocation); - thisAssembly = crowLoadCtx.LoadFromAssemblyPath (new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath); - - Type debuggerType = crowAssembly.GetType("Crow.DbgLogger"); - if (!(bool)debuggerType.GetField("IsEnabled").GetValue(null)) { - notifyCrowDebuggerState("Crow.dll must be compiled with CrowDebugLogEnabled='True'"); - return; - } - - dbgIfaceType = thisAssembly.GetType("Crow.DebugInterface"); - dbgIFace = Activator.CreateInstance (dbgIfaceType, new object[] {IFace.WindowHandle}); - - delResize = (Action<int, int>)Delegate.CreateDelegate(typeof(Action<int, int>), - dbgIFace, dbgIfaceType.GetMethod("Resize")); - - delMouseMove = (Func<int, int, bool>)Delegate.CreateDelegate(typeof(Func<int, int, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnMouseMove")); - - delMouseWheelChanged = (Func<float, bool>)Delegate.CreateDelegate(typeof(Func<float, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnMouseWheelChanged")); - - - delMouseDown = (Func<MouseButton, bool>)Delegate.CreateDelegate(typeof(Func<MouseButton, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnMouseButtonDown")); - - delMouseUp = (Func<MouseButton, bool>)Delegate.CreateDelegate(typeof(Func<MouseButton, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnMouseButtonUp")); - - delKeyDown = (Func<Key, bool>)Delegate.CreateDelegate(typeof(Func<Key, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnKeyDown")); - delKeyUp = (Func<Key, bool>)Delegate.CreateDelegate(typeof(Func<Key, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnKeyUp")); - delKeyPress = (Func<char, bool>)Delegate.CreateDelegate(typeof(Func<char, bool>), - dbgIFace, dbgIfaceType.GetMethod("OnKeyPress")); - - - delGetSurfacePointer = (Func<IntPtr>)Delegate.CreateDelegate(typeof(Func<IntPtr>), - dbgIFace, dbgIfaceType.GetProperty("SurfacePointer").GetGetMethod()); - delSetSource = (Action<string>)Delegate.CreateDelegate(typeof(Action<string>), - dbgIFace, dbgIfaceType.GetProperty("Source").GetSetMethod()); - - delResetDirtyState = (Action)Delegate.CreateDelegate(typeof(Action), - dbgIFace, dbgIfaceType.GetMethod("ResetDirtyState")); - - fiDbg_IncludeEvents = debuggerType.GetField("IncludeEvents"); - fiDbg_DiscardEvents = debuggerType.GetField("DiscardEvents"); - fiDbg_ConsoleOutput = debuggerType.GetField("ConsoleOutput"); - delResetDebugger = (Action)Delegate.CreateDelegate(typeof(Action), - null, debuggerType.GetMethod("Reset")); - /*delSaveDebugLog = (Action<object, string>)Delegate.CreateDelegate(typeof(Action<object, string>), - null, debuggerType.GetMethod("Save", new Type[] {dbgIfaceType, typeof(string)}));*/ - hasVkvgBackend = (bool)dbgIfaceType.GetField ("HaveVkvgBackend", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue (null); - - dbgIfaceType.GetMethod("RegisterDebugInterfaceCallback").Invoke (dbgIFace, new object[] {this} ); - dbgIfaceType.GetMethod("Run").Invoke (dbgIFace, null); - - initialized = true; - notifyCrowDebuggerState(); - - //Console.WriteLine($"DbgIFace: LoadCtx:{AssemblyLoadContext.GetLoadContext (dbgIFace.GetType().Assembly).Name})"); - //} - } - - protected override void onDraw(Context gr) - { - gr.SetSource(Colors.RoyalBlue); - gr.Paint(); - } - public override bool CacheEnabled { get => true; set => base.CacheEnabled = true; } - - public override void onKeyDown(object sender, KeyEventArgs e) - { - if (initialized) { - try - { - e.Handled = delKeyDown (e.Key); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace key down]{ex}"); - } - } - base.onKeyDown(sender, e); - } - public override void onKeyUp(object sender, KeyEventArgs e) - { - if (initialized) { - try - { - e.Handled = delKeyUp (e.Key); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace key up]{ex}"); - } - } - base.onKeyUp(sender, e); - } - public override void onKeyPress(object sender, KeyPressEventArgs e) - { - if (initialized) { - try - { - e.Handled = delKeyPress (e.KeyChar); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace key press]{ex}"); - } - } - base.onKeyPress(sender, e); - } - public override void onMouseMove(object sender, MouseMoveEventArgs e) - { - if (initialized) { - try - { - Point m = ScreenPointToLocal (e.Position); - e.Handled = delMouseMove (m.X, m.Y); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace mouse move]{ex}"); - } - } - base.onMouseMove(sender, e); - } - public override void onMouseDown(object sender, MouseButtonEventArgs e) - { - if (initialized) { - try - { - e.Handled = delMouseDown (e.Button); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace mouse down]{ex}"); - } - } - base.onMouseDown (sender, e); - } - public override void onMouseUp(object sender, MouseButtonEventArgs e) - { - if (initialized) { - try - { - e.Handled = delMouseUp (e.Button); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace mouse up]{ex}"); - } - } - base.onMouseUp (sender, e); - } - public override void onMouseWheel(object sender, MouseWheelEventArgs e) - { - if (initialized) { - try - { - e.Handled = delMouseWheelChanged (e.Delta); - } - catch (System.Exception ex) - { - Console.WriteLine($"[Error][DebugIFace mouse wheel change]{ex}"); - } - } - base.onMouseWheel(sender, e); - } - - protected override void RecreateCache() - { - bmp?.Dispose (); - - if (initialized) { - delResize (Slot.Width, Slot.Height); - if (hasVkvgBackend) - bmp = IFace.CreateSurfaceForData (delGetSurfacePointer(), Slot.Width, Slot.Height); - else - bmp = IFace.CreateSurface (delGetSurfacePointer()); - - } else - bmp = IFace.CreateSurface (Slot.Width, Slot.Height); - - IsDirty = false; - } - protected override void UpdateCache(Context ctx) - { - if (initialized && bmp != null) { - paintCache (ctx, Slot + Parent.ClientRectangle.Position); - delResetDirtyState (); - } - - } - - int firstWidgetIndexToGet = 0; - void getLog () { - DebugLogAnalyzer.Program dla = IFace as DebugLogAnalyzer.Program; - - using (Stream stream = new MemoryStream (1024)) { - Type debuggerType = crowAssembly.GetType("Crow.DbgLogger"); - MethodInfo miSave = debuggerType.GetMethod("Save", - new Type[] { - dbgIfaceType, - typeof(Stream), - typeof(int), - typeof(bool) - }); - - - widgets = new List<DbgWidgetRecord>(); - events = new List<DbgEvent>(); - miSave.Invoke(null, new object[] {dbgIFace, stream, firstWidgetIndexToGet, true}); - stream.Seek(0, SeekOrigin.Begin); - DbgLogger.Load (stream, events, widgets); - - lock (dla.UpdateMutex) { - for (int i = 0; i < widgets.Count; i++) { - widgets[i].listIndex = dla.Widgets.Count; - dla.Widgets.Add (widgets[i]); - } - for (int i = 0; i < events.Count; i++) { - dla.Events.Add (events[i]); - updateWidgetEvents (dla.Widgets, events[i]); - } - } - firstWidgetIndexToGet += widgets.Count; - if (widgets.Count > 0 && firstWidgetIndexToGet != widgets.Last().InstanceIndex + 1) - Debugger.Break (); - } - } - void updateWidgetEvents (IList<DbgWidgetRecord> widgets, DbgEvent evt) { - if (evt is DbgWidgetEvent we) - widgets.FirstOrDefault (w => w.InstanceIndex == we.InstanceIndex)?.Events.Add (we); - if (evt.Events == null) - return; - foreach (DbgEvent e in evt.Events) - updateWidgetEvents (widgets, e); - } - void saveLogToDebugLogFilePath () { - - } - void loadLogFromDebugLogFilePath () { - DebugLogAnalyzer.Program dla = IFace as DebugLogAnalyzer.Program; - - widgets = new List<DbgWidgetRecord>(); - events = new List<DbgEvent>(); - - DbgLogger.Load(DebugLogFilePath, events, widgets); - - lock (dla.UpdateMutex) { - for (int i = 0; i < widgets.Count; i++) { - widgets[i].listIndex = dla.Widgets.Count; - dla.Widgets.Add (widgets[i]); - } - for (int i = 0; i < events.Count; i++) { - dla.Events.Add (events[i]); - updateWidgetEvents (dla.Widgets, events[i]); - } - } - } - - public virtual object GetScreenCoordinates () => ScreenCoordinates(Slot).TopLeft; - } -}
\ No newline at end of file diff --git a/Samples/DebugLogAnalyzer/src/Program.cs b/Samples/DebugLogAnalyzer/src/Program.cs deleted file mode 100644 index 13e0234d..00000000 --- a/Samples/DebugLogAnalyzer/src/Program.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System.Reflection.PortableExecutable; -// Copyright (c) 2013-2021 Bruyère Jean-Philippe <jp_bruyere@hotmail.com> -// -// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - -using System; -using Crow; -using System.IO; -using Glfw; -using Crow.Text; -using System.Collections.Generic; -using Encoding = System.Text.Encoding; -using Crow.DebugLogger; -using System.Linq; -using Samples; - -namespace DebugLogAnalyzer -{ - public class Program : SampleBaseForEditor - { - - static void Main (string [] args) - { - initDebugLog (); - - using (Program app = new Program ()) { - CurrentProgramInstance = app; - app.Run (); - } - } - protected override void OnInitialized () { - base.OnInitialized (); - - Load ("#Dbg.main.crow").DataSource = this; - //crowContainer = FindByName ("CrowContainer") as Container; - editor = FindByName ("tb") as TextBox; - - /*TreeView tv = FindByName("dbgTV") as TreeView; - dbgTreeViewScroller = tv.FindByNameInTemplate ("scroller1") as Scroller;*/ - if (DebugLogOnStartup) - DebugLogRecording = true; - - if (!File.Exists (CurrentFile)) - newFile (); - //I set an empty object as datasource at this level to force update when new - //widgets are added to the interface - - reloadFromFile (); - } - - public override void UpdateFrame() - { - base.UpdateFrame(); - - } - - - ObservableList<DbgEvent> events = new ObservableList<DbgEvent>(); - ObservableList<DbgWidgetRecord> widgets = new ObservableList<DbgWidgetRecord>(); - DbgEvent curEvent; - bool disableCurrentEventHistory; - Stack<DbgEvent> CurrentEventHistoryForward = new Stack<DbgEvent>(); - Stack<DbgEvent> CurrentEventHistoryBackward = new Stack<DbgEvent>(); - DbgWidgetRecord curWidget = new DbgWidgetRecord(); - bool debugLogRecording; - int targetTvScroll = -1; - - public string[] AllEventTypes => Enum.GetNames (typeof(DbgEvtType)); - string searchEventType; - DbgWidgetRecord searchWidget; - public string SearchEventType { - get => searchEventType; - set { - if (searchEventType == value) - return; - searchEventType = value; - NotifyValueChanged (searchEventType); - } - } - - public DbgWidgetRecord SearchWidget { - get => searchWidget; - set { - if (searchWidget == value) - return; - searchWidget = value; - NotifyValueChanged (searchWidget); - } - } - public Command CMDGotoParentEvent, CMDEventHistoryForward, CMDEventHistoryBackward; - public CommandGroup EventCommands, DirectoryCommands; - protected override void initCommands () - { - base.initCommands (); - - CMDGotoParentEvent = new Command("parent", ()=> { CurrentEvent = CurrentEvent?.parentEvent; }, null, false); - CMDEventHistoryBackward = new Command("back.", currentEventHistoryGoBack, null, false); - CMDEventHistoryForward = new Command("forw.", currentEventHistoryGoForward, null, false); - - EventCommands = new CommandGroup( - CMDGotoParentEvent, CMDEventHistoryBackward, CMDEventHistoryForward - ); - DirectoryCommands = new CommandGroup( - new Command("Set as root directory", ()=> { CurrentEvent = CurrentEvent?.parentEvent; }) - ); - - } - - public string CrowDbgAssemblyLocation { - get => Configuration.Global.Get<string>("CrowDbgAssemblyLocation"); - set { - if (CrowDbgAssemblyLocation == value) - return; - Configuration.Global.Set ("CrowDbgAssemblyLocation", value); - NotifyValueChanged(CrowDbgAssemblyLocation); - } - } - public ObservableList<DbgEvent> Events { - get => events; - set { - if (events == value) - return; - events = value; - NotifyValueChanged (nameof (Events), events); - } - } - public ObservableList<DbgWidgetRecord> Widgets { - get => widgets; - set { - if (widgets == value) - return; - widgets = value; - NotifyValueChanged (nameof (Widgets), widgets); - } - } - - public DbgEvent CurrentEvent { - get => curEvent; - set { - if (curEvent == value) - return; - - if (!disableCurrentEventHistory) { - CurrentEventHistoryForward.Clear (); - CMDEventHistoryForward.CanExecute = false; - if (!(value == null || curEvent == null)) { - CurrentEventHistoryBackward.Push (curEvent); - CMDEventHistoryBackward.CanExecute = true; - } - } - - curEvent = value; - - NotifyValueChanged (nameof (CurrentEvent), curEvent); - NotifyValueChanged ("CurEventChildEvents", curEvent?.Events); - if (CurrentEvent != null && CurrentEvent.parentEvent != null) - CMDGotoParentEvent.CanExecute = true; - else - CMDGotoParentEvent.CanExecute = false; - } - } - void currentEventHistoryGoBack () { - disableCurrentEventHistory = true; - if (CurrentEvent != null) { - CurrentEventHistoryForward.Push (CurrentEvent); - CMDEventHistoryForward.CanExecute = true; - } - CurrentEvent = CurrentEventHistoryBackward.Pop (); - CMDEventHistoryBackward.CanExecute = CurrentEventHistoryBackward.Count > 0; - - disableCurrentEventHistory = false; - } - - void currentEventHistoryGoForward () { - disableCurrentEventHistory = true; - CurrentEventHistoryBackward.Push (CurrentEvent); - CMDEventHistoryBackward.CanExecute = true; - CurrentEvent = CurrentEventHistoryForward.Pop (); - CMDEventHistoryForward.CanExecute = CurrentEventHistoryForward.Count > 0; - - disableCurrentEventHistory = false; - } - - public DbgWidgetRecord CurrentWidget { - get => curWidget; - set { - if (curWidget == value) - return; - curWidget = value; - NotifyValueChanged (nameof (CurrentWidget), curWidget); - NotifyValueChanged ("CurWidgetRootEvents", curWidget?.RootEvents); - NotifyValueChanged ("CurrentWidgetEvents", curWidget?.Events); - } - } - public List<DbgWidgetEvent> CurWidgetRootEvents => curWidget == null? new List<DbgWidgetEvent>() : curWidget.RootEvents; - - /*public string DebugLogFilePath { - get => Configuration.Global.Get<string> (nameof (DebugLogFilePath)); - set { - if (CurrentFile == value) - return; - Configuration.Global.Set (nameof (DebugLogFilePath), value); - NotifyValueChanged (DebugLogFilePath); - } - }*/ - public bool DebugLogOnStartup { - get => Configuration.Global.Get<bool> (nameof(DebugLogOnStartup)); - set { - if (DebugLogOnStartup == value) - return; - Configuration.Global.Set (nameof(DebugLogOnStartup), value); - NotifyValueChanged(DebugLogOnStartup); - } - } - - - Exception currentException; - - public Exception CurrentException { - get => currentException; - set { - if (currentException == value) - return; - currentException = value; - NotifyValueChanged ("ShowError", ShowError); - NotifyValueChanged ("CurrentExceptionMSG", (object)CurrentExceptionMSG); - NotifyValueChanged (currentException); - } - } - public bool ShowError => currentException != null; - public string CurrentExceptionMSG => currentException == null ? "" : currentException.Message; - - - public override bool OnKeyDown (Key key) { - - switch (key) { - case Key.F5: - Load ("#Dbg.DebugLog.crow").DataSource = this; - return true; - /*case Key.F6: - if (DebugLogRecording) { - DbgLogger.IncludeEvents = DbgEvtType.None; - DbgLogger.DiscardEvents = DbgEvtType.All; - if (DebugLogToFile && !string.IsNullOrEmpty(DebugLogFilePath)) - DbgLogger.Save (this, DebugLogFilePath); - DebugLogRecording = false; - } else { - DbgLogger.Reset (); - DbgLogger.IncludeEvents = RecordedEvents; - DbgLogger.DiscardEvents = DiscardedEvents; - DebugLogRecording = true; - } - return true;*/ - } - return base.OnKeyDown (key); - } - } -} - |