diff options
author | David Karlaš <david.karlas@xamarin.com> | 2014-06-20 15:29:29 +0400 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2014-06-22 15:46:29 +0400 |
commit | cdf422259e6bf53b946d62a9ee6dfbb34549169b (patch) | |
tree | 6bd84a864d479c13c697227120beba549bc0176e /main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers | |
parent | 0379ad2a24a66c4f0800198ba59264396b69b7c1 (diff) |
[Debugger] Initial commit for PreviewVisualizers(partial Size and Color)
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers')
4 files changed, 397 insertions, 0 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ColorPreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ColorPreviewVisualizer.cs new file mode 100644 index 0000000000..770ad16fcf --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/ColorPreviewVisualizer.cs @@ -0,0 +1,127 @@ +// +// 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.HasColorConverter (val); + } + + public override Gtk.Widget GetVisualizerWidget (ObjectValue val) + { + var color = DebuggingService.GetColorConverter (val).GetColor (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, 12); + mainTable.SetColSpacing (3, 12); + + var titleColor = new Gdk.Color (139, 139, 139); + var titleLabel = new Label ("R"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 0, 1, 0, 1); + mainTable.Attach (new Label (((byte)(color.Red * 255.0)).ToString ()){ Xalign = 0 }, 1, 2, 0, 1); + titleLabel = new Label ("G"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 0, 1, 1, 2); + mainTable.Attach (new Label (((byte)(color.Green * 255.0)).ToString ()){ Xalign = 0 }, 1, 2, 1, 2); + titleLabel = new Label ("B"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 0, 1, 2, 3); + mainTable.Attach (new Label (((byte)(color.Blue * 255.0)).ToString ()){ Xalign = 0 }, 1, 2, 2, 3); + + titleLabel = new Label ("H"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 2, 3, 0, 1); + mainTable.Attach (new Label ((color.Hue * 360.0).ToString ("0.##") + "°"){ Xalign = 0 }, 3, 4, 0, 1); + titleLabel = new Label ("S"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 2, 3, 1, 2); + mainTable.Attach (new Label ((color.Saturation * 100.0).ToString ("0.##") + "%"){ Xalign = 0 }, 3, 4, 1, 2); + titleLabel = new Label ("L"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 2, 3, 2, 3); + mainTable.Attach (new Label ((color.Light * 100.0).ToString ("0.##") + "%"){ Xalign = 0 }, 3, 4, 2, 3); + + titleLabel = new Label ("A"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 4, 5, 0, 1); + mainTable.Attach (new Label (((byte)(color.Alpha * 255.0)).ToString () + " (" + (color.Alpha * 100.0).ToString ("0.##") + "%)"){ Xalign = 0 }, 5, 6, 0, 1); + titleLabel = new Label ("#"); + titleLabel.ModifyFg (StateType.Normal, titleColor); + mainTable.Attach (titleLabel, 4, 5, 1, 2); + mainTable.Attach (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 }, 5, 6, 1, 2); + + mainBox.PackStart (mainTable, true, true, 3); + 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.5); + 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/PreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/PreviewVisualizer.cs new file mode 100644 index 0000000000..ca11464f3f --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/PreviewVisualizer.cs @@ -0,0 +1,67 @@ +// +// PreviewVisualizer.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; + +namespace MonoDevelop.Debugger +{ + public abstract class PreviewVisualizer + { + /// <summary> + /// Determines whether this instance can visualize the specified value + /// </summary> + /// <returns> + /// <c>true</c> if this instance can visualize the specified value; otherwise, <c>false</c>. + /// </returns> + /// <param name='val'> + /// The value + /// </param> + /// <remarks> + /// This method must check the value and return <c>true</c> if it is able to display that value. + /// Typically, this method will check the TypeName of the value. + /// </remarks> + public abstract bool CanVisualize (ObjectValue val); + + /// <summary> + /// Gets a visualizer widget for a value + /// </summary> + /// <returns> + /// The visualizer widget. + /// </returns> + /// <param name='val'> + /// A value + /// </param> + /// <remarks> + /// This method is called to get a widget for displaying the specified value. + /// The method should create the widget and load the required information from + /// the value. Notice that the ObjectValue.Value property returns a string + /// representation of the value. If the visualizer needs to get values from + /// the object properties, it can use the ObjectValue.GetRawValue method. + /// </remarks> + public abstract Gtk.Widget GetVisualizerWidget (ObjectValue val); + } +} + diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/PreviewVisualizerWindow.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/PreviewVisualizerWindow.cs new file mode 100644 index 0000000000..49cefd2d84 --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/PreviewVisualizerWindow.cs @@ -0,0 +1,92 @@ +// +// PreviewVisualizerWindow.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 System.Linq; +using MonoDevelop.Components; +using Mono.Debugging.Client; +using Gdk; +using Gtk; +using MonoDevelop.Ide; + +namespace MonoDevelop.Debugger +{ + public class PreviewVisualizerWindow : PopoverWindow + { + public PreviewVisualizerWindow () + { + TransientFor = IdeApp.Workbench.RootWindow; + } + + public void Show (ObjectValue val, Gtk.Widget invokingWidget, Rectangle previewButtonArea) + { + var previewVisualizer = DebuggingService.GetPreviewVisualizer (val); + if (previewVisualizer == null) + return; + Theme.SetFlatColor (new Cairo.Color (245 / 256.0, 245 / 256.0, 245 / 256.0)); + ShowArrow = true; + VBox mainBox = new VBox (); + HBox headerBox = new HBox (); + var closeButton = new ImageButton () { + InactiveImage = ImageService.GetIcon ("md-popup-close", IconSize.Menu), + Image = ImageService.GetIcon ("md-popup-close-hover", IconSize.Menu) + }; + closeButton.Clicked += delegate { + this.Destroy (); + }; + var vb = new VBox (); + vb.PackStart (closeButton, false, false, 0); + headerBox.PackStart (vb, false, false, 0); + + var headerTitle = new Label (); + headerTitle.UseMarkup = true; + headerTitle.Markup = "<b>" + val.TypeName.Split ('.').LastOrDefault () + "</b>"; + + var vb2 = new VBox (); + vb2.PackStart (headerTitle, false, false, 0); + headerBox.PackStart (vb2, true, true, 0); + + if (DebuggingService.HasValueVisualizers (val)) { + var openButton = new Button (); + openButton.Label = "Open"; + openButton.Relief = ReliefStyle.Half; + openButton.Clicked += delegate { + DebuggingService.ShowValueVisualizer (val); + }; + headerBox.PackEnd (openButton, false, false, 0); + } + + mainBox.PackStart (headerBox); + mainBox.ShowAll (); + + var widget = previewVisualizer.GetVisualizerWidget (val); + mainBox.Add (widget); + widget.Show (); + ContentBox.Add (mainBox); + ShowPopup (invokingWidget, previewButtonArea, PopupPosition.Left); + } + } +} + diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizePreviewVisualizer.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizePreviewVisualizer.cs new file mode 100644 index 0000000000..93a20d95ff --- /dev/null +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.PreviewVisualizers/SizePreviewVisualizer.cs @@ -0,0 +1,111 @@ +// +// SizePreviewVisualizer.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; + +namespace MonoDevelop.Debugger.PreviewVisualizers +{ + class SizePreviewVisualizer : PreviewVisualizer + { + #region implemented abstract members of PreviewVisualizer + + public override bool CanVisualize (ObjectValue val) + { + return val.TypeName == "System.Drawing.Size" || + val.TypeName == "Gdk.Size" || + val.TypeName == "Xamarin.Forms.Size" || + val.TypeName == "System.Drawing.SizeF"; + } + + public override Gtk.Widget GetVisualizerWidget (ObjectValue val) + { + var ops = DebuggingService.DebuggerSession.EvaluationOptions.Clone (); + ops.AllowTargetInvoke = true; + + double width, height; + + if (val.TypeName == "System.Drawing.SizeF") { + width = (float)val.GetChild ("Width", ops).GetRawValue (ops); + height = (float)val.GetChild ("Height", ops).GetRawValue (ops); + } else { + width = (int)val.GetChild ("Width", ops).GetRawValue (ops); + height = (int)val.GetChild ("Height", ops).GetRawValue (ops); + } + return new SizePreviewVisualizerWidget (width, height); + } + + #endregion + } + + class SizePreviewVisualizerWidget : Gtk.DrawingArea + { + double width; + double height; + + public SizePreviewVisualizerWidget (double width, double height) + { + this.width = width; + this.height = height; + } + + protected override bool OnExposeEvent (Gdk.EventExpose evnt) + { + using (var ctx = Gdk.CairoHelper.Create (GdkWindow)) { + ctx.SetSourceRGB (219 / 256.0, 229 / 256.0, 242 / 256.0); + ctx.Rectangle (10, 10, width, height); + 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; + + //TODO: Rectangle only dot +// ctx.Arc (10, height + 10, 4, 0, 2 * Math.PI); +// ctx.Fill (); + + //TODO: Write width and height text(rectangle dot point) +// ctx.MoveTo (20, 20); +// ctx.SetSourceRGB (0, 0, 0); +// ctx.SelectFontFace ("sans-serif", Cairo.FontSlant.Normal, Cairo.FontWeight.Normal); +// ctx.SetFontSize (10); +// ctx.Rotate (Math.PI / 2); +// ctx.ShowText ("500.0"); + } + return true; + } + + protected override void OnSizeRequested (ref Requisition requisition) + { + requisition = new Requisition () { + Height = (int)height + 20, + Width = (int)width + 20 + }; + } + } +} + |