diff options
author | Vsevolod Kukol <sevoku@xamarin.com> | 2015-12-16 16:07:01 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@xamarin.com> | 2015-12-16 16:07:01 +0300 |
commit | 43b65afbfc323e7b9c5e01b4949db3e31800b0b9 (patch) | |
tree | a82aa4891fd7b3b267ac51e5da79d9a6959503d3 /main | |
parent | a8440366b98622eb7b6a23f1557475976fd5998d (diff) |
[Ide] Fix status icon rendering in ExtensibleTreeView
* selected state support
* zoom support
* use default size for multisized icons
Diffstat (limited to 'main')
3 files changed, 66 insertions, 16 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/CellRendererImage.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/CellRendererImage.cs index 278637bc8a..48bb6d0925 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/CellRendererImage.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/CellRendererImage.cs @@ -135,6 +135,8 @@ namespace MonoDevelop.Components if ((flags & Gtk.CellRendererState.Selected) != 0) img = img.WithStyles ("sel"); + if (!img.HasFixedSize) + img = img.WithSize (Gtk.IconSize.Menu); using (var ctx = Gdk.CairoHelper.Create (window)) { var x = cell_area.X + cell_area.Width / 2 - (int)(img.Width / 2); @@ -159,8 +161,11 @@ namespace MonoDevelop.Components { var img = GetImage (); if (img != null) { - width = (int)img.Width; - height = (int)img.Height; + if (img.HasFixedSize) { + width = (int)img.Width; + height = (int)img.Height; + } else + Gtk.IconSize.Menu.GetSize(out width, out height); } else width = height = 0; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs index c2f0a3156f..c50f749d68 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components/GtkUtil.cs @@ -156,13 +156,25 @@ namespace MonoDevelop.Components public static Xwt.Drawing.Image WithSize (this Xwt.Drawing.Image image, Gtk.IconSize size) { int w, h; - if (!Gtk.Icon.SizeLookup (size, out w, out h)) - return image; - if (size == IconSize.Menu) - w = h = 16; + size.GetSize (out w, out h); return image.WithSize (w, h); } + public static Xwt.Size GetSize (this IconSize size) + { + int w, h; + size.GetSize (out w, out h); + return new Xwt.Size (w, h); + } + + public static void GetSize (this IconSize size, out int width, out int height) + { + if (!Icon.SizeLookup (size, out width, out height)) + return; + if (size == IconSize.Menu) + width = height = 16; + } + public static Gdk.Point GetScreenCoordinates (this Gtk.Widget w, Gdk.Point p) { if (w.ParentWindow == null) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs index 9b8a832cc5..8336c1a1b4 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/ExtensibleTreeView.cs @@ -2395,6 +2395,31 @@ namespace MonoDevelop.Ide.Gui.Components this.parent = parent; } + static Xwt.Size defaultIconSize = Gtk.IconSize.Menu.GetSize (); + + static Xwt.Size GetZoomedIconSize (Xwt.Drawing.Image icon, double zoom) + { + if (icon == null || icon == CellRendererImage.NullImage) + return defaultIconSize; + + var size = icon.HasFixedSize ? icon.Size : defaultIconSize; + + if (zoom == 1) + return size; + + int w = (int) (zoom * (double) size.Width); + int h = (int) (zoom * (double) size.Height); + if (w == 0) w = 1; + if (h == 0) h = 1; + return new Xwt.Size (w, h); + } + + static Xwt.Drawing.Image GetResized (Xwt.Drawing.Image icon, double zoom) + { + var size = GetZoomedIconSize (icon, zoom); + return icon.WithSize (size); + } + void SetupLayout (Gtk.Widget widget) { @@ -2440,9 +2465,12 @@ namespace MonoDevelop.Ide.Gui.Components bool hasStatusIcon = StatusIcon != CellRendererImage.NullImage && StatusIcon != null; if (hasStatusIcon) { + var img = GetResized (StatusIcon, zoom); + if (st == Gtk.StateType.Selected) + img = img.WithStyles ("sel"); var x = tx + w + StatusIconSpacing; using (var ctx = Gdk.CairoHelper.Create (window)) { - ctx.DrawImage (widget, StatusIcon, x, cell_area.Y + (cell_area.Height - StatusIcon.Height) / 2); + ctx.DrawImage (widget, img, x, cell_area.Y + (cell_area.Height - img.Height) / 2); } } @@ -2458,16 +2486,19 @@ namespace MonoDevelop.Ide.Gui.Components int w, h; layout.GetPixelSize (out w, out h); + var iconSize = GetZoomedIconSize (StatusIcon, zoom); int tx = cell_area.X + (int)Xpad; var x = tx + w + StatusIconSpacing; - return new Gdk.Rectangle (x, cell_area.Y, (int) StatusIcon.Width, (int) cell_area.Height); + return new Gdk.Rectangle (x, cell_area.Y, (int) iconSize.Width, (int) cell_area.Height); } public override void GetSize (Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height) { base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height); - if (StatusIcon != CellRendererImage.NullImage && StatusIcon != null) - width += (int) StatusIcon.Width + StatusIconSpacing; + if (StatusIcon != CellRendererImage.NullImage && StatusIcon != null) { + var iconSize = GetZoomedIconSize (StatusIcon, zoom); + width += (int)iconSize.Width + StatusIconSpacing; + } } public double Zoom { @@ -2657,19 +2688,21 @@ namespace MonoDevelop.Ide.Gui.Components if (value == null || value == CellRendererImage.NullImage) return null; + var img = value.HasFixedSize ? value : value.WithSize (Gtk.IconSize.Menu); + if (zoom == 1) - return value; + return img; Xwt.Drawing.Image resized; - if (resizedCache.TryGetValue (value, out resized)) + if (resizedCache.TryGetValue (img, out resized)) return resized; - int w = (int) (zoom * (double) value.Width); - int h = (int) (zoom * (double) value.Height); + int w = (int) (zoom * (double) img.Width); + int h = (int) (zoom * (double) img.Height); if (w == 0) w = 1; if (h == 0) h = 1; - resized = value.WithSize (w, h); - resizedCache [value] = resized; + resized = img.WithSize (w, h); + resizedCache [img] = resized; return resized; } |