diff options
author | David Karlaš <david.karlas@xamarin.com> | 2014-07-14 16:15:42 +0400 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2014-07-14 16:54:29 +0400 |
commit | ce7b38f0ba0609cc01b40c05ff1c31db7bd8bc46 (patch) | |
tree | 1f39454e1bd6f1f7095170a8d8484c4ccb36bb69 /main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers | |
parent | a2ba569ad148d0359a95e73ebb05c7f305c345f8 (diff) |
[Debugger] BezierPathPreview and UI/NSBezierPath converters
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers')
2 files changed, 174 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/BezierPathPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/BezierPathPreviewVisualizer.cs new file mode 100644 index 0000000000..9a9c809b39 --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/BezierPathPreviewVisualizer.cs @@ -0,0 +1,173 @@ +// +// BezierPathPreviewVisualizer.cs +// +// Author: +// David Karlaš <david.karlas@xamarin.com> +// +// Copyright (c) 2014 Xamarin, Inc (http://www.xamarin.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using Mono.Debugging.Client; +using Xwt.Drawing; +using MonoDevelop.Components; +using Gtk; +using System.Collections.Generic; +using MonoDevelop.Debugger.Converters; + +namespace MonoDevelop.Debugger.PreviewVisualizers +{ + public class BezierPathPreviewVisualizer : PreviewVisualizer + { + #region implemented abstract members of PreviewVisualizer + + public override bool CanVisualize (ObjectValue val) + { + return DebuggingService.HasGetConverter<List<BezierPathElement>> (val); + } + + public override Control GetVisualizerWidget (ObjectValue val) + { + var elements = DebuggingService.GetGetConverter<List<BezierPathElement>> (val).GetValue (val); + if (elements == null) { + //This happens on older mono runtimes which don't support outArgs + //Returning null means it will fallback to GenericPreview + return null; + } + var bezierPathWidget = new BezierPathWidget (new Gdk.Size (300, 300), elements); + bezierPathWidget.Show (); + return bezierPathWidget; + } + + #endregion + } + + class BezierPathWidget : Gtk.DrawingArea + { + List<BezierPathElement> elements; + Gdk.Size size; + + public BezierPathWidget (Gdk.Size size, List<BezierPathElement> elements) + { + this.elements = elements; + this.size = size; + } + + protected override bool OnExposeEvent (Gdk.EventExpose evnt) + { + using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) { + foreach (var element in elements) { + switch (element.ElementType) { + case BezierPathElementType.MoveTo: + ctx.MoveTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.LineTo: + ctx.LineTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.ClosePath: + ctx.ClosePath (); + break; + case BezierPathElementType.CurveTo: + ctx.CurveTo ( + element.Point1.X, element.Point1.Y, + element.Point2.X, element.Point2.Y, + element.Point3.X, element.Point3.Y); + break; + } + } + + //Scale down if it's bigger then size + var ext = ctx.StrokeExtents (); + double scaleRatio = 1; + if (ext.Width > size.Width || ext.Height > size.Height) { + scaleRatio = Math.Min ( + ext.Width < 1 ? 1 : size.Width / ext.Width, + ext.Height < 1 ? 1 : size.Height / ext.Height); + ctx.Scale (scaleRatio, scaleRatio); + } + + //Center object + double targetX = (size.Width - ext.Width * scaleRatio) / 2; + double targetY = (size.Height - ext.Height * scaleRatio) / 2; + ctx.Translate (targetX - ext.X, targetY - ext.Y); + + ctx.NewPath (); + foreach (var element in elements) { + switch (element.ElementType) { + case BezierPathElementType.MoveTo: + ctx.MoveTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.LineTo: + ctx.LineTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.ClosePath: + ctx.ClosePath (); + break; + case BezierPathElementType.CurveTo: + ctx.CurveTo ( + element.Point1.X, element.Point1.Y, + element.Point2.X, element.Point2.Y, + element.Point3.X, element.Point3.Y); + break; + } + } + + + ctx.NewPath (); + foreach (var element in elements) { + switch (element.ElementType) { + case BezierPathElementType.MoveTo: + ctx.MoveTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.LineTo: + ctx.LineTo (element.Point1.X, element.Point1.Y); + break; + case BezierPathElementType.ClosePath: + ctx.ClosePath (); + break; + case BezierPathElementType.CurveTo: + ctx.CurveTo ( + element.Point1.X, element.Point1.Y, + element.Point2.X, element.Point2.Y, + element.Point3.X, element.Point3.Y); + break; + } + } + + ctx.SetSourceRGB (219 / 256.0, 229 / 256.0, 242 / 256.0); + ctx.FillPreserve (); + ctx.SetSourceRGB (74 / 256.0, 144 / 256.0, 226 / 256.0); + //ctx.Antialias = Cairo.Antialias.None; + ctx.LineWidth = 1; + ctx.Stroke (); + } + return true; + } + + protected override void OnSizeRequested (ref Gtk.Requisition requisition) + { + requisition = new Requisition () { + Width = size.Width, + Height = size.Height + }; + } + + } +} + diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs index c31bb74260..e31e0457b3 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs @@ -53,7 +53,7 @@ namespace MonoDevelop.Debugger.PreviewVisualizers mainBox.PackStart (new Label (GettextCatalog.GetString ("Loading..."))); using (var stream = new MemoryStream ()) { var cancelSource = new CancellationTokenSource (); - var timer = new Timer (delegate { + new Timer (delegate { cancelSource.Cancel (); }, null, 4000, System.Threading.Timeout.Infinite); WebRequestHelper.GetResponseAsync ( |