From fba381d72cfa6c83d8b5d706526563428ff6c885 Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 21:48:29 -0400 Subject: [PATCH 1/6] Removed extra zoom, add sizef extent. --- .../Services/IMesVirtualCanvasControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs index e7639d5d..a965aa20 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs @@ -7,13 +7,13 @@ namespace MinoriEditorShell.VirtualCanvas.Services public interface IMesVirtualCanvasControl { IMesContentCanvas ContentCanvas { get; } - IMesMapZoom Zoom { get; set; } Double ExtentWidth { get; } Double ExtentHeight { get; } Double ViewportWidth { get; } Double ViewportHeight { get; } ObservableCollection VirtualChildren { get; } + SizeF Extent { get; } void AddVirtualChild(IMesVirtualChild shape); } From 785c06ceb260819268f0a59f43c2cbef13cd1545 Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 21:48:53 -0400 Subject: [PATCH 2/6] bring up ResetTranslate to move to 0,0 --- Modules/MinoriEditorShell.VirtualCanvas/Services/IMesMapZoom.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesMapZoom.cs b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesMapZoom.cs index c17284f5..08d406fa 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesMapZoom.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesMapZoom.cs @@ -8,5 +8,6 @@ public interface IMesMapZoom event EventHandler ValueChanged; Double Value { get; set; } void ZoomToRect(RectangleF rectangle); + void ResetTranslate(); } } \ No newline at end of file From 09cbe88f1e92aa98d37c028ef0987799986c4987 Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 21:49:06 -0400 Subject: [PATCH 3/6] documentation --- .../Platforms/Wpf/Gestures/MesMapZoom.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Gestures/MesMapZoom.cs b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Gestures/MesMapZoom.cs index 8d7a7677..8aebf7ce 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Gestures/MesMapZoom.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Gestures/MesMapZoom.cs @@ -399,7 +399,7 @@ void StopAnimations() /// /// Overload to assist in platform interface /// - /// + /// public void ZoomToRect(System.Drawing.RectangleF rectf) { Rect r = new Rect(rectf.X, rectf.Y, rectf.Width, rectf.Height); From 9d1e32638d862ec69182db246eca07d07dc017ed Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 21:51:30 -0400 Subject: [PATCH 4/6] removed extra zoom. Make makevisible not finished. --- .../Wpf/Controls/MesVirtualCanvas.cs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs index 306d235f..ddc9863a 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs @@ -107,14 +107,6 @@ public void ShowQuadTree(Boolean drawing) /// noop void OnChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) => RebuildVisuals(); - /// - /// Get/Set the MapZoom object used for manipulating the scale and translation on this canvas. - /// - public IMesMapZoom Zoom { - get => _zoom; - set => _zoom = (MesMapZoom)value; - } - /// /// Returns true if all Visuals have been created for the current scroll position /// and there is no more idle processing needed. @@ -434,7 +426,6 @@ void SetViewportSize(System.Windows.Size s) private readonly MesContentCanvas _contentCanvas; Int32 _added; RectangleF _visible = RectangleF.Empty; - private MesMapZoom _zoom; delegate Int32 QuantizedWorkHandler(Int32 quantum); @@ -815,11 +806,12 @@ Int32 LazyGarbageCollectNodes(Int32 quantum) /// The bounds that is actually visible. public Rect MakeVisible(Visual visual, Rect rectangle) { - if (Zoom != null && visual != this) - { - return _zoom.ScrollIntoView(visual as FrameworkElement); - } - return rectangle; + //if (_contentCanvas.Zoom != null && visual != this) + //{ + // return _zoom.ScrollIntoView(visual as FrameworkElement); + //} + //return rectangle; + throw new NotImplementedException(); } /// @@ -912,6 +904,7 @@ public void SetVerticalOffset(Double offset) public SizeF SmallScrollIncrement1 { get; set; } = new SizeF(10, 10); public Int32 Removed { get; set; } + #endregion /// From c07ddc0c1e350cba1756d3603bc0adf69dead466 Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 21:51:53 -0400 Subject: [PATCH 5/6] add extension, and remove old zoom methods. --- .../ViewModels/VirtualCanvasViewModel.cs | 14 +--- .../Extensions/IMesVirtualCanvasExtensions.cs | 73 +++++++++++++++++++ 2 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 Modules/MinoriEditorShell.VirtualCanvas/Extensions/IMesVirtualCanvasExtensions.cs diff --git a/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs b/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs index 37ca1b21..f8ab8f26 100644 --- a/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs +++ b/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs @@ -1,5 +1,6 @@ using MinoriDemo.Core.Modules.VirtualCanvas.Models; using MinoriEditorShell.Services; +using MinoriEditorShell.VirtualCanvas.Extensions; using MinoriEditorShell.VirtualCanvas.Services; using MvvmCross; using MvvmCross.Commands; @@ -81,7 +82,7 @@ public class VirtualCanvasViewModel : MesDocument, IMesVirtualCanvas { if (x == "Fit") { - ResetZoom(); + this.ZoomToContent(ZoomToContent.WidthAndHeight); } else { @@ -91,15 +92,6 @@ public class VirtualCanvasViewModel : MesDocument, IMesVirtualCanvas } }); - private void ResetZoom() - { - Double scaleX = Graph.ViewportWidth / Graph.ExtentWidth; - Double scaleY = Graph.ViewportHeight / Graph.ExtentHeight; - - Zoom.Value = Math.Min(scaleX, scaleY); - //zoom.Offset = new Point(0, 0); - } - public Double ZoomValue { get => Zoom?.Value ?? 0; @@ -127,7 +119,7 @@ public override void ViewAppeared() _statusbar.Text = $"Zoom:{e}"; }; - RectZoom.ZoomReset += (s, e) => ResetZoom(); + RectZoom.ZoomReset += (s, e) => this.ZoomToContent(ZoomToContent.WidthAndHeight); // Do I even need this? //IVirtualCanvasControl graph = Canvas.Graph; diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Extensions/IMesVirtualCanvasExtensions.cs b/Modules/MinoriEditorShell.VirtualCanvas/Extensions/IMesVirtualCanvasExtensions.cs new file mode 100644 index 00000000..104597cf --- /dev/null +++ b/Modules/MinoriEditorShell.VirtualCanvas/Extensions/IMesVirtualCanvasExtensions.cs @@ -0,0 +1,73 @@ +using MinoriEditorShell.VirtualCanvas.Services; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; + +namespace MinoriEditorShell.VirtualCanvas.Extensions +{ + /// + /// Sets the zoom property, or manual if user changed + /// + public enum ZoomToContent + { + /// + /// User definded size + /// + Manual = 0, + /// + /// request zoom by width + /// + Width, + + /// + /// Request zoom by height + /// + Height, + + /// + /// Reuqest to zoom by both + /// + WidthAndHeight + } + + /// + /// Extensions for IMesVirtualCanvas used in place of inheritance. + /// + public static class IMesVirtualCanvasExtensions + { + /// + /// Zoom content to view. Must be done on IVirtualCanvas due to needing zoom and graph + /// + /// + /// + public static void ZoomToContent(this IMesVirtualCanvas canvas, ZoomToContent zoomToContent) + { + Double? zoom = null; + switch (zoomToContent) + { + case Extensions.ZoomToContent.Manual: + zoom = null; + break; + case Extensions.ZoomToContent.Width: + zoom = canvas.Graph.ViewportWidth / canvas.Graph.Extent.Width; + break; + case Extensions.ZoomToContent.Height: + zoom = canvas.Graph.ViewportHeight / canvas.Graph.Extent.Width; + break; + case Extensions.ZoomToContent.WidthAndHeight: + Double scaleX = canvas.Graph.ViewportWidth / canvas.Graph.Extent.Width; + Double scaleY = canvas.Graph.ViewportHeight / canvas.Graph.Extent.Height; + + zoom = Math.Min(scaleX, scaleY); + break; + } + + if (zoom != null) + { + canvas.Zoom.Value = zoom.Value; + canvas.Zoom.ResetTranslate(); + } + } + } +} From 7801f7cddd00f6d70bf9b90693b839cdbcec9e09 Mon Sep 17 00:00:00 2001 From: Mark Kromis Date: Sun, 27 Oct 2019 23:25:38 -0400 Subject: [PATCH 6/6] Add ability to set background canvas color --- .../ViewModels/VirtualCanvasViewModel.cs | 3 +++ .../Platforms/Wpf/Controls/MesContentCanvas.cs | 14 +++++++++++++- .../Platforms/Wpf/Controls/MesVirtualCanvas.cs | 11 ----------- .../Services/IMesContentCanvas.cs | 6 ++++++ .../Services/IMesVirtualCanvasControl.cs | 14 ++++++++++++++ 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs b/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs index f8ab8f26..a8092052 100644 --- a/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs +++ b/Demos/MinoriDemo/MinoriDemo.Core/ViewModels/VirtualCanvasViewModel.cs @@ -121,6 +121,9 @@ public override void ViewAppeared() RectZoom.ZoomReset += (s, e) => this.ZoomToContent(ZoomToContent.WidthAndHeight); + // Set the background to see the boarder vs demo. + Graph.ContentCanvas.SetCanvasBackgroundColor(Color.AliceBlue); + // Do I even need this? //IVirtualCanvasControl graph = Canvas.Graph; //graph.SmallScrollIncrement = new Size(_tileWidth + _tileMargin, _tileHeight + _tileMargin); diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesContentCanvas.cs b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesContentCanvas.cs index 7ab323aa..56b9fb35 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesContentCanvas.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesContentCanvas.cs @@ -1,6 +1,7 @@ using MinoriEditorShell.VirtualCanvas.Services; using System; using System.Collections.Generic; +using System.Drawing; using System.Text; using System.Windows.Controls; @@ -11,5 +12,16 @@ namespace MinoriEditorShell.VirtualCanvas.Platforms.Wpf.Controls /// public class MesContentCanvas : Canvas, IMesContentCanvas { + /// + /// Sets the background color of the canvas object + /// + /// + public void SetCanvasBackgroundColor(Color color) + { + System.Windows.Media.Color newcolor = + System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); + System.Windows.Media.Brush brush = new System.Windows.Media.SolidColorBrush(newcolor); + Background = brush; + } } -} +} \ No newline at end of file diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs index ddc9863a..bb332c97 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Platforms/Wpf/Controls/MesVirtualCanvas.cs @@ -23,17 +23,6 @@ namespace MinoriEditorShell.VirtualCanvas.Platforms.Wpf.Controls { - public class VisualChangeEventArgs : EventArgs - { - public Int32 Added { get; set; } - public Int32 Removed { get; set; } - public VisualChangeEventArgs(Int32 added, Int32 removed) - { - Added = added; - Removed = removed; - } - } - /// /// VirtualCanvas dynamically figures out which children are visible and creates their visuals /// and which children are no longer visible (due to scrolling or zooming) and destroys their diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesContentCanvas.cs b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesContentCanvas.cs index 565e53b8..d0010b73 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesContentCanvas.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesContentCanvas.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Text; namespace MinoriEditorShell.VirtualCanvas.Services @@ -10,5 +11,10 @@ namespace MinoriEditorShell.VirtualCanvas.Services /// public interface IMesContentCanvas { + /// + /// Sets the background color of the canvas object + /// + /// + void SetCanvasBackgroundColor(Color color); } } diff --git a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs index a965aa20..96d6f9ef 100644 --- a/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs +++ b/Modules/MinoriEditorShell.VirtualCanvas/Services/IMesVirtualCanvasControl.cs @@ -4,6 +4,17 @@ namespace MinoriEditorShell.VirtualCanvas.Services { + public class VisualChangeEventArgs : EventArgs + { + public Int32 Added { get; set; } + public Int32 Removed { get; set; } + public VisualChangeEventArgs(Int32 added, Int32 removed) + { + Added = added; + Removed = removed; + } + } + public interface IMesVirtualCanvasControl { IMesContentCanvas ContentCanvas { get; } @@ -14,6 +25,9 @@ public interface IMesVirtualCanvasControl ObservableCollection VirtualChildren { get; } SizeF Extent { get; } + Int32 LiveVisualCount { get; } + + event EventHandler VisualsChanged; void AddVirtualChild(IMesVirtualChild shape); }