diff --git a/AnnoDesigner.Core/DataStructures/QuadTree.cs b/AnnoDesigner.Core/DataStructures/QuadTree.cs index ab12863d..0c6d10cb 100644 --- a/AnnoDesigner.Core/DataStructures/QuadTree.cs +++ b/AnnoDesigner.Core/DataStructures/QuadTree.cs @@ -335,7 +335,6 @@ public Quadrant GetContainingQuadrant(Rect bounds) return null; } -#if DEBUG /// /// Retrieves a list of Rects that make up this quadrant and the quadrants beneath it. /// Used when debugging to draw quadrants to a canvas. @@ -377,7 +376,6 @@ public IEnumerable GetQuadrantRects() } } } -#endif } /// @@ -546,7 +544,6 @@ public void AddRange(IEnumerable collection) } } -#if DEBUG /// /// Retrieves a list of Rects that make up the Quadrants in this QuadTree. /// Used when debugging to draw the QuadTree quadrants to a canvas. @@ -556,6 +553,5 @@ public IEnumerable GetQuadrantRects() { return root.GetQuadrantRects(); } -#endif } } diff --git a/AnnoDesigner/AnnoCanvas.xaml.cs b/AnnoDesigner/AnnoCanvas.xaml.cs index 03173914..5e7d918d 100644 --- a/AnnoDesigner/AnnoCanvas.xaml.cs +++ b/AnnoDesigner/AnnoCanvas.xaml.cs @@ -53,6 +53,7 @@ public partial class AnnoCanvas : UserControl, IAnnoCanvas, IHotkeySource, IScro public const string DELETE_OBJECT_UNDER_CURSOR_LOCALIZATION_KEY = "DeleteObjectUnderCursor"; public const string UNDO_LOCALIZATION_KEY = "Undo"; public const string REDO_LOCALIZATION_KEY = "Redo"; + public const string ENABLE_DEBUG_MODE_LOCALIZATION_KEY = "EnableDebugMode"; public event EventHandler StatisticsUpdated; public event EventHandler ColorsInLayoutUpdated; @@ -534,7 +535,6 @@ public double LinePenThickness #endregion -#if DEBUG #region Debug options /// @@ -546,19 +546,18 @@ public double LinePenThickness /// private readonly SolidColorBrush _debugBrushLight; - private bool debugModeIsEnabled = false; - private readonly bool debugShowObjectPositions = true; - private readonly bool debugShowQuadTreeViz = true; - private readonly bool debugShowSelectionRectCoordinates = true; - private readonly bool debugShowSelectionCollisionRect = true; - private readonly bool debugShowViewportRectCoordinates = true; - private readonly bool debugShowScrollableRectCoordinates = true; - private readonly bool debugShowLayoutRectCoordinates = true; - private readonly bool debugShowMouseGridCoordinates = true; - private readonly bool debugShowObjectCount = true; + private bool _debugModeIsEnabled = false; + private readonly bool _debugShowObjectPositions = true; + private readonly bool _debugShowQuadTreeViz = true; + private readonly bool _debugShowSelectionRectCoordinates = true; + private readonly bool _debugShowSelectionCollisionRect = true; + private readonly bool _debugShowViewportRectCoordinates = true; + private readonly bool _debugShowScrollableRectCoordinates = true; + private readonly bool _debugShowLayoutRectCoordinates = true; + private readonly bool _debugShowMouseGridCoordinates = true; + private readonly bool _debugShowObjectCount = true; #endregion -#endif #region Constructor /// @@ -621,6 +620,7 @@ public AnnoCanvas(BuildingPresets presetsToUse, deleteObjectUnderCursorCommand = new RelayCommand(ExecuteDeleteObjectUnderCursor); undoCommand = new RelayCommand(ExecuteUndo); redoCommand = new RelayCommand(ExecuteRedo); + enableDebugModeCommand = new RelayCommand(ExecuteEnableDebugMode); //Set up default keybindings @@ -656,6 +656,9 @@ public AnnoCanvas(BuildingPresets presetsToUse, var redoBinding = new InputBinding(redoCommand, new PolyGesture(Key.Y, ModifierKeys.Control)); redoHotkey = new Hotkey(REDO_LOCALIZATION_KEY, redoBinding, REDO_LOCALIZATION_KEY); + var enableDebugModeBinding = new InputBinding(enableDebugModeCommand, new PolyGesture(Key.D, ModifierKeys.Control | ModifierKeys.Shift)); + enableDebugModeHotkey = new Hotkey(ENABLE_DEBUG_MODE_LOCALIZATION_KEY, enableDebugModeBinding, ENABLE_DEBUG_MODE_LOCALIZATION_KEY); + //We specifically do not add the `InputBinding`s to the `InputBindingCollection` of `AnnoCanvas`, as if we did that, //`InputBinding.Gesture.Matches()` would be fired for *every* event - MouseWheel, MouseDown, KeyUp, KeyDown, MouseMove etc //which we don't want, as it produces a noticeable performance impact. @@ -674,10 +677,8 @@ public AnnoCanvas(BuildingPresets presetsToUse, color = Colors.LawnGreen; color.A = 32; _influencedBrush = _brushCache.GetSolidBrush(color); -#if DEBUG _debugBrushLight = Brushes.Blue; _debugBrushDark = Brushes.DarkBlue; -#endif sw.Stop(); logger.Trace($"init variables took: {sw.ElapsedMilliseconds}ms"); @@ -1078,11 +1079,10 @@ protected override void OnRender(DrawingContext drawingContext) #region Draw debug information -#if DEBUG - if (debugModeIsEnabled) + if (_debugModeIsEnabled) { drawingContext.PushTransform(_viewportTransform); - if (debugShowQuadTreeViz) + if (_debugShowQuadTreeViz) { var brush = Brushes.Transparent; var pen = _penCache.GetPen(_debugBrushDark, 2); @@ -1092,7 +1092,7 @@ protected override void OnRender(DrawingContext drawingContext) } } - if (debugShowSelectionCollisionRect) + if (_debugShowSelectionCollisionRect) { var color = _debugBrushLight.Color; color.A = 0x08; @@ -1106,7 +1106,7 @@ protected override void OnRender(DrawingContext drawingContext) drawingContext.Pop(); var debugText = new List(3); - if (debugShowViewportRectCoordinates) + if (_debugShowViewportRectCoordinates) { //The first time this is called, App.DpiScale is still 0 which causes this code to throw an error if (App.DpiScale.PixelsPerDip != 0) @@ -1124,7 +1124,7 @@ protected override void OnRender(DrawingContext drawingContext) } } - if (debugShowScrollableRectCoordinates) + if (_debugShowScrollableRectCoordinates) { //The first time this is called, App.DpiScale is still 0 which causes this code to throw an error if (App.DpiScale.PixelsPerDip != 0) @@ -1142,7 +1142,7 @@ protected override void OnRender(DrawingContext drawingContext) } } - if (debugShowLayoutRectCoordinates) + if (_debugShowLayoutRectCoordinates) { //The first time this is called, App.DpiScale is still 0 which causes this code to throw an error if (App.DpiScale.PixelsPerDip != 0) @@ -1160,7 +1160,7 @@ protected override void OnRender(DrawingContext drawingContext) } } - if (debugShowObjectCount) + if (_debugShowObjectCount) { //The first time this is called, App.DpiScale is still 0 which causes this code to throw an error if (App.DpiScale.PixelsPerDip != 0) @@ -1179,7 +1179,7 @@ protected override void OnRender(DrawingContext drawingContext) drawingContext.DrawText(debugText[i], new Point(5, (i * 15) + 5)); } - if (debugShowMouseGridCoordinates) + if (_debugShowMouseGridCoordinates) { //The first time this is called, App.DpiScale is still 0 which causes this code to throw an error if (App.DpiScale.PixelsPerDip != 0) @@ -1203,7 +1203,7 @@ protected override void OnRender(DrawingContext drawingContext) //draw selection rect coords last so they draw over the top of everything else if (CurrentMode == MouseMode.SelectionRect) { - if (debugShowSelectionRectCoordinates) + if (_debugShowSelectionRectCoordinates) { var rect = _coordinateHelper.ScreenToGrid(_selectionRect, _gridSize); var top = rect.Top; @@ -1223,7 +1223,6 @@ protected override void OnRender(DrawingContext drawingContext) } } } -#endif #endregion @@ -1455,8 +1454,8 @@ private void RenderObjectList(DrawingContext drawingContext, List drawingContext.DrawText(text, textLocation); } -#if DEBUG - if (debugModeIsEnabled && debugShowObjectPositions) + + if (_debugModeIsEnabled && _debugShowObjectPositions) { var text = new FormattedText(obj.Position.ToString(), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, TYPEFACE, 12, _debugBrushLight, @@ -1472,7 +1471,6 @@ private void RenderObjectList(DrawingContext drawingContext, List drawingContext.DrawText(text, textLocation); } -#endif } } @@ -2439,13 +2437,7 @@ protected override void OnKeyDown(KeyEventArgs e) //When an InputBinding is added to the InputBindingsCollection, the `Matches` method is fired for every event - KeyUp, //KeyDown, MouseUp, MouseMove, MouseWheel etc. HotkeyCommandManager.HandleCommand(e); -#if DEBUG - if (e.Key == Key.D && Keyboard.Modifiers == (ModifierKeys.Control | ModifierKeys.Shift)) - { - debugModeIsEnabled = !debugModeIsEnabled; - e.Handled = true; - } -#endif + if (e.Handled) { InvalidateVisual(); @@ -2685,6 +2677,7 @@ public void RegisterHotkeys(HotkeyCommandManager manager) manager.AddHotkey(deleteObjectUnderCursorHotkey); manager.AddHotkey(undoHotkey); manager.AddHotkey(redoHotkey); + manager.AddHotkey(enableDebugModeHotkey); } #endregion @@ -3015,6 +3008,14 @@ private void ExecuteRedo(object param) StatisticsUpdated?.Invoke(this, UpdateStatisticsEventArgs.All); } + private readonly Hotkey enableDebugModeHotkey; + private readonly ICommand enableDebugModeCommand; + private void ExecuteEnableDebugMode(object param) + { + _debugModeIsEnabled = !_debugModeIsEnabled; + ForceRendering(); + } + #endregion #region Helper methods diff --git a/doc/Enable_DebugMode.md b/doc/Enable_DebugMode.md new file mode 100644 index 00000000..e099635d --- /dev/null +++ b/doc/Enable_DebugMode.md @@ -0,0 +1,21 @@ +# Enable `DebugMode` + +## General information + +For further investigation of issues, it is possible to activate a `DebugMode`. + +## How to enable/disable + +The default Hotkey to enable/disable `DebugMode` is `CTRL + Shift + D`.
+You can change the Hotkey via `Tools -> Preferences -> Manage Keybindings` menu. + +## Supported features of `DebugMode` + +- display coordinates of current Viewport +- display coordinates of current scrollable area +- display coordinates and bounding box of current layout +- display collision rectangle of current selection +- display helper lines of `QuadTree` +- display coordinates of objects (on each object) +- display count of placed objects +- display coordinates of mouse cursor (on mouse cursor)