diff options
author | David Karlaš <david.karlas@xamarin.com> | 2014-09-30 15:59:01 +0400 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2014-09-30 15:59:01 +0400 |
commit | 95574218f46e8d1cfb9409f437f1f74822ef66eb (patch) | |
tree | af6807ba76ef7476ac0ed1ed1003e63a4c17ad2e /main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers | |
parent | d14aa5f366e2fd180710b5c4111c8b530389a7ad (diff) |
[DebuggerVisualizers] Moved Converters and Previews from MD to md-addins
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers')
6 files changed, 1 insertions, 653 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 deleted file mode 100644 index 9a9c809b39..0000000000 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/BezierPathPreviewVisualizer.cs +++ /dev/null @@ -1,173 +0,0 @@ -// -// 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/ColorPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ColorPreviewVisualizer.cs deleted file mode 100644 index 1427e6747a..0000000000 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ColorPreviewVisualizer.cs +++ /dev/null @@ -1,150 +0,0 @@ -// -// ColorPreviewVisualizer.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 MonoDevelop.Components; -using Gtk; - -namespace MonoDevelop.Debugger.PreviewVisualizers -{ - public class ColorPreviewVisualizer : PreviewVisualizer - { - public override bool CanVisualize (ObjectValue val) - { - return DebuggingService.HasGetConverter<Xwt.Drawing.Color> (val); - } - - public override Control GetVisualizerWidget (ObjectValue val) - { - var color = DebuggingService.GetGetConverter<Xwt.Drawing.Color> (val).GetValue (val); - var mainBox = new HBox (); - var colorBox = new ColorBox { Color = color }; - mainBox.PackStart (colorBox); - - - var mainTable = new Table (3, 6, false); - mainTable.RowSpacing = 2; - mainTable.ColumnSpacing = 3; - mainTable.SetColSpacing (1, 18); - mainTable.SetColSpacing (3, 18); - - var titleColor = new Gdk.Color (139, 139, 139); - var valueColor = new Gdk.Color (100, 100, 100); - var titleLabel = new Label ("R"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 0, 1, 0, 1); - var valueLabel = new Label (((byte)(color.Red * 255.0)).ToString ()){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 1, 2, 0, 1); - titleLabel = new Label ("G"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 0, 1, 1, 2); - valueLabel = new Label (((byte)(color.Green * 255.0)).ToString ()){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 1, 2, 1, 2); - titleLabel = new Label ("B"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 0, 1, 2, 3); - valueLabel = new Label (((byte)(color.Blue * 255.0)).ToString ()){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 1, 2, 2, 3); - - titleLabel = new Label ("H"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 2, 3, 0, 1); - valueLabel = new Label ((color.Hue * 360.0).ToString ("0.##") + "°"){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 3, 4, 0, 1); - titleLabel = new Label ("S"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 2, 3, 1, 2); - valueLabel = new Label ((color.Saturation * 100.0).ToString ("0.##") + "%"){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 3, 4, 1, 2); - titleLabel = new Label ("L"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 2, 3, 2, 3); - valueLabel = new Label ((color.Light * 100.0).ToString ("0.##") + "%"){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 3, 4, 2, 3); - - titleLabel = new Label ("A"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 4, 5, 0, 1); - valueLabel = new Label (((byte)(color.Alpha * 255.0)).ToString () + " (" + (color.Alpha * 100.0).ToString ("0.##") + "%)"){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 5, 6, 0, 1); - titleLabel = new Label ("#"); - titleLabel.ModifyFg (StateType.Normal, titleColor); - mainTable.Attach (titleLabel, 4, 5, 1, 2); - valueLabel = new Label ( - ((byte)(color.Red * 255.0)).ToString ("X2") + - ((byte)(color.Green * 255.0)).ToString ("X2") + - ((byte)(color.Blue * 255.0)).ToString ("X2")){ Xalign = 0 }; - valueLabel.ModifyFg (StateType.Normal, valueColor); - mainTable.Attach (valueLabel, 5, 6, 1, 2); - var font = mainBox.Style.FontDescription.Copy (); - if (font.SizeIsAbsolute) { - font.AbsoluteSize = font.Size - 1; - } else { - font.Size -= (int)(Pango.Scale.PangoScale); - } - foreach (var child in mainTable.AllChildren) - ((Gtk.Label)child).ModifyFont (font); - mainBox.PackStart (mainTable, true, true, 9); - mainBox.ShowAll (); - return mainBox; - } - } - - class ColorBox : DrawingArea - { - protected override bool OnExposeEvent (Gdk.EventExpose evnt) - { - using (Cairo.Context cr = Gdk.CairoHelper.Create (GdkWindow)) { - cr.RoundedRectangle (2, 2, 42, 42, 2); - cr.SetSourceRGB (Color.Red, Color.Green, Color.Blue); - cr.FillPreserve (); - var darkColor = Color.WithIncreasedLight (-0.3); - cr.SetSourceRGB (darkColor.Red, darkColor.Green, darkColor.Blue); - cr.LineWidth = 1; - cr.Stroke (); - } - return base.OnExposeEvent (evnt); - } - - protected override void OnSizeRequested (ref Requisition requisition) - { - requisition = new Requisition () { - Width = 46, - Height = 46 - }; - } - - public Xwt.Drawing.Color Color { get; set; } - } -} - diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/GenericPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/GenericPreviewVisualizer.cs index 9edd7b747e..705e4d6655 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/GenericPreviewVisualizer.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/GenericPreviewVisualizer.cs @@ -29,7 +29,7 @@ using Mono.Debugging.Client; namespace MonoDevelop.Debugger.PreviewVisualizers { - class GenericPreviewVisualizer : PreviewVisualizer + public class GenericPreviewVisualizer : PreviewVisualizer { #region implemented abstract members of PreviewVisualizer diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ImagePreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ImagePreviewVisualizer.cs deleted file mode 100644 index 7fc6de87fc..0000000000 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ImagePreviewVisualizer.cs +++ /dev/null @@ -1,53 +0,0 @@ -// -// ImagePreviewVisualizer.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 MonoDevelop.Components; - -namespace MonoDevelop.Debugger.PreviewVisualizers -{ - class ImagePreviewVisualizer : PreviewVisualizer - { - #region implemented abstract members of PreviewVisualizer - - public override bool CanVisualize (ObjectValue val) - { - return DebuggingService.HasGetConverter<Xwt.Drawing.Image> (val); - } - - public override Control GetVisualizerWidget (ObjectValue val) - { - var image = DebuggingService.GetGetConverter<Xwt.Drawing.Image> (val).GetValue (val); - image = image.WithBoxSize (250); - var imageView = new ImageView (image); - imageView.Show (); - return imageView; - } - - #endregion - } -} - diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs deleted file mode 100644 index 72656ea10f..0000000000 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/LocationPreviewVisualizer.cs +++ /dev/null @@ -1,90 +0,0 @@ -// -// LocationPreviewVisualizer.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 MonoDevelop.Components; -using Mono.Debugging.Client; -using MonoDevelop.Debugger.Converters; -using System.Net; -using System.Globalization; -using System.IO; -using System.Threading; -using MonoDevelop.Core; -using MonoDevelop.Ide; -using Gtk; - -namespace MonoDevelop.Debugger.PreviewVisualizers -{ - public class LocationPreviewVisualizer : PreviewVisualizer - { - #region implemented abstract members of PreviewVisualizer - - public override bool CanVisualize (ObjectValue val) - { - return DebuggingService.HasGetConverter<GpsLocation> (val); - } - - public override Control GetVisualizerWidget (ObjectValue val) - { - var location = DebuggingService.GetGetConverter<GpsLocation> (val).GetValue (val); - var mainBox = new Gtk.VBox (); - mainBox.PackStart (new Label (GettextCatalog.GetString ("Loading..."))); - using (var stream = new MemoryStream ()) { - var cancelSource = new CancellationTokenSource (); - new Timer (delegate { - cancelSource.Cancel (); - }, null, 4000, System.Threading.Timeout.Infinite); - WebRequestHelper.GetResponseAsync ( - () => (HttpWebRequest)WebRequest.Create ("http://maps.googleapis.com/maps/api/staticmap?&size=500x300&zoom=15&markers=color:blue%7C" + - location.Longitude.ToString (CultureInfo.InvariantCulture.NumberFormat) + "," + - location.Latitude.ToString (CultureInfo.InvariantCulture.NumberFormat)), - null, - cancelSource.Token).ContinueWith ((System.Threading.Tasks.Task<HttpWebResponse> arg) => { - Application.Invoke (delegate { - if (mainBox.Children.Length > 0) { - mainBox.Remove (mainBox.Children [0]); - } - if (arg.Exception == null) { - var imageView = new ImageView (Xwt.Drawing.Image.FromStream (arg.Result.GetResponseStream ())); - imageView.Show (); - mainBox.PackStart (imageView); - PreviewWindowManager.RepositionWindow (); - } else { - mainBox.PackStart (new GenericPreviewVisualizer ().GetVisualizerWidget (val)); - PreviewWindowManager.RepositionWindow (); - DebuggingService.DebuggerSession.LogWriter (true, "Failed to load map preview: " + arg.Exception.InnerException); - arg.Exception.Handle ((e) => true); - } - }); - }); - } - mainBox.ShowAll (); - return mainBox; - } - - #endregion - } -} - diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizeAndRectanglePreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizeAndRectanglePreviewVisualizer.cs deleted file mode 100644 index d96dcd8ed2..0000000000 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizeAndRectanglePreviewVisualizer.cs +++ /dev/null @@ -1,186 +0,0 @@ -// -// SizeAndRectanglePreviewVisualizer.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 Gtk; -using MonoDevelop.Components; -using Xwt; - -namespace MonoDevelop.Debugger.PreviewVisualizers -{ - class SizeAndRectanglePreviewVisualizer : PreviewVisualizer - { - #region implemented abstract members of PreviewVisualizer - - public override bool CanVisualize (ObjectValue val) - { - return DebuggingService.HasGetConverter<Xwt.Size> (val) || DebuggingService.HasGetConverter<Xwt.Rectangle> (val); - } - - public override Control GetVisualizerWidget (ObjectValue val) - { - var sizeConverter = DebuggingService.GetGetConverter<Xwt.Size> (val); - if (sizeConverter != null) { - var size = sizeConverter.GetValue (val); - return new SizeAndRectanglePreviewVisualizerWidget (size); - } - var rectangleConverter = DebuggingService.GetGetConverter<Xwt.Rectangle> (val); - var rectangle = rectangleConverter.GetValue (val); - return new SizeAndRectanglePreviewVisualizerWidget (rectangle); - } - - #endregion - } - - class SizeAndRectanglePreviewVisualizerWidget : Gtk.DrawingArea - { - bool sizeCalculated; - - bool drawDot; - const int Padding = 7; - const int TextPadding = 4; - const int MaxRectangleDrawSize = 250; - Cairo.Rectangle square; - string pointString; - Cairo.PointD pointTextPosition; - string widthString; - Cairo.PointD widthTextPosition; - string heightString; - Cairo.PointD heightTextPosition; - Size requisition = new Size (); - Rectangle rectangle; - - SizeAndRectanglePreviewVisualizerWidget (Rectangle rectangle, bool drawPosition) - { - this.drawDot = drawPosition; - this.rectangle = rectangle; - Show (); - } - - public SizeAndRectanglePreviewVisualizerWidget (Xwt.Size size) - : this (new Rectangle (Point.Zero, size), false) - { - } - - public SizeAndRectanglePreviewVisualizerWidget (Xwt.Rectangle rectangle) - : this (rectangle, true) - { - } - - const string valuesFormat = "0.0####"; - - void CaclulateSize () - { - using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) { - widthString = rectangle.Width.ToString (valuesFormat); - var widthExtents = ctx.TextExtents (widthString); - heightString = rectangle.Height.ToString (valuesFormat); - var heightExtents = ctx.TextExtents (heightString); - pointString = "(" + rectangle.X.ToString (valuesFormat) + ", " + rectangle.Y.ToString (valuesFormat) + ")"; - var pointExtents = ctx.TextExtents (pointString); - if (rectangle.Width > MaxRectangleDrawSize || rectangle.Height > MaxRectangleDrawSize) { - double ratio; - if (rectangle.Width > rectangle.Height) { - ratio = rectangle.Width / MaxRectangleDrawSize; - } else { - ratio = rectangle.Height / MaxRectangleDrawSize; - } - square = new Cairo.Rectangle (Padding, Padding + widthExtents.Height + TextPadding, rectangle.Width / ratio, rectangle.Height / ratio); - } else { - square = new Cairo.Rectangle (Padding, Padding + widthExtents.Height + TextPadding, rectangle.Width, rectangle.Height); - } - requisition.Width = (int)Math.Max (widthExtents.Width, square.Width); - if (drawDot && (pointExtents.Width > requisition.Width)) - requisition.Width = (int)pointExtents.Width; - requisition.Width += (int)heightExtents.Height + TextPadding; - - requisition.Height = (int)Math.Max (heightExtents.Width, square.Height); - requisition.Height += (int)widthExtents.Height + TextPadding; - if (drawDot) { - requisition.Height += (int)pointExtents.Height + TextPadding; - } - - requisition.Width += Padding * 2; - requisition.Height += Padding * 2; - - widthTextPosition = new Cairo.PointD (requisition.Width / 2 - widthExtents.Width / 2, square.Y - TextPadding); - heightTextPosition = new Cairo.PointD (Math.Max (square.X + square.Width + TextPadding, widthTextPosition.X + widthExtents.Width + TextPadding), - requisition.Height / 2 - heightExtents.Width / 2); - if (drawDot) { - pointTextPosition = new Cairo.PointD (TextPadding, - Math.Max (square.Y + square.Height, heightExtents.Width + heightTextPosition.Y)); - pointTextPosition.Y += TextPadding + pointExtents.Height; - heightTextPosition.X = Math.Max (heightTextPosition.X, pointTextPosition.X + pointExtents.Width + TextPadding); - } - } - sizeCalculated = true; - QueueResize (); - PreviewWindowManager.RepositionWindow (); - } - - protected override bool OnExposeEvent (Gdk.EventExpose evnt) - { - if (!sizeCalculated) - CaclulateSize (); - using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) { - ctx.SetSourceRGB (219 / 256.0, 229 / 256.0, 242 / 256.0); - ctx.Rectangle (square); - ctx.FillPreserve (); - ctx.SetSourceRGB (74 / 256.0, 144 / 256.0, 226 / 256.0); - ctx.Antialias = Cairo.Antialias.None; - ctx.LineWidth = 1; - ctx.Stroke (); - ctx.Antialias = Cairo.Antialias.Default; - if (drawDot) { - ctx.Arc (square.X, square.Y + square.Height, 4, 0, 2 * Math.PI); - ctx.Fill (); - } - - ctx.SetSourceRGB (0, 0, 0); - - ctx.MoveTo (widthTextPosition); - ctx.ShowText (widthString); - if (drawDot) { - ctx.MoveTo (pointTextPosition); - ctx.ShowText (pointString); - } - ctx.MoveTo (heightTextPosition); - ctx.Rotate (Math.PI / 2); - ctx.ShowText (heightString); - } - return true; - } - - protected override void OnSizeRequested (ref Requisition requisition) - { - requisition = new Requisition () { - Width = (int)this.requisition.Width, - Height = (int)this.requisition.Height - }; - } - } -} - |