Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Stedfast <jeff@xamarin.com>2012-03-30 22:29:09 +0400
committerJeffrey Stedfast <jeff@xamarin.com>2012-03-30 22:29:09 +0400
commitfc174e2e1fc9b59168c0c5b17b0757cbd17d758d (patch)
tree43ee66770629b070a9f2615b5e380a72f6ac08b1
parent11b888316cbc7aabbbd8796f1c6955e4e78173af (diff)
[MacDev] Add a RecommendedSize prop to ImageChooser
The new RecommendedSize property is a non-strict version of the AcceptedSize property. Images not matching the RecommendedSize are allowed to be set, but are given a warning overlay in the UI to signal to the user that the chosen image does not fit the recommended size.
-rw-r--r--main/src/addins/MonoDevelop.MacDev/Makefile.am4
-rw-r--r--main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.PlistEditor/ImageChooser.cs136
-rw-r--r--main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj3
-rwxr-xr-xmain/src/addins/MonoDevelop.MacDev/icons/error.pngbin0 -> 666 bytes
4 files changed, 109 insertions, 34 deletions
diff --git a/main/src/addins/MonoDevelop.MacDev/Makefile.am b/main/src/addins/MonoDevelop.MacDev/Makefile.am
index 379c5aa7a8..3128334ee6 100644
--- a/main/src/addins/MonoDevelop.MacDev/Makefile.am
+++ b/main/src/addins/MonoDevelop.MacDev/Makefile.am
@@ -102,7 +102,9 @@ FILES = \
XcodeSyncing/XcodeSyncedItem.cs \
XcodeSyncing/XcodeSyncedType.cs
-RES = MonoDevelop.MacDev.addin.xml
+RES = \
+ icons/error.png \
+ MonoDevelop.MacDev.addin.xml
ICON_FILES = \
icons/application-x-mono-develop-xib-48.png \
diff --git a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.PlistEditor/ImageChooser.cs b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.PlistEditor/ImageChooser.cs
index 9ffde3cac0..614a3d1a95 100644
--- a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.PlistEditor/ImageChooser.cs
+++ b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.PlistEditor/ImageChooser.cs
@@ -44,15 +44,30 @@ namespace MonoDevelop.MacDev.PlistEditor
[ToolboxItem(true)]
public class ImageChooser : Button
{
+ static Pixbuf WarningIcon = Pixbuf.LoadFromResource ("error.png");
+
+ Size imageSize, displaySize, acceptedSize, recommendedSize;
+ Pixbuf scaledPixbuf;
+ string description;
Project project;
Gtk.Image image;
- Pixbuf scaledPixbuf;
- Size displaySize, acceptedSize;
Gtk.TargetEntry[] targetEntryTypes = new Gtk.TargetEntry[] {
new Gtk.TargetEntry ("text/uri-list", 0, 100u)
};
+ public string Description {
+ get { return description; }
+ set {
+ if (value == description)
+ return;
+
+ description = value;
+
+ UpdateTooltip ();
+ }
+ }
+
public Size DisplaySize {
get { return displaySize; }
set {
@@ -62,12 +77,30 @@ namespace MonoDevelop.MacDev.PlistEditor
}
}
-
public Size AcceptedSize {
get { return acceptedSize; }
set {
+ if (value == acceptedSize)
+ return;
+
+ recommendedSize = value;
acceptedSize = value;
- TooltipText = GettextCatalog.GetString ("Image size {0}x{1}", value.Width, value.Height);
+
+ UpdateTooltip ();
+ QueueDraw ();
+ }
+ }
+
+ public Size RecommendedSize {
+ get { return recommendedSize; }
+ set {
+ if (value == recommendedSize)
+ return;
+
+ recommendedSize = value;
+
+ UpdateTooltip ();
+ QueueDraw ();
}
}
@@ -84,6 +117,8 @@ namespace MonoDevelop.MacDev.PlistEditor
{
DestroyScaledPixbuf ();
+ imageSize = pixbuf != null ? new Size (pixbuf.Width, pixbuf.Height) : Size.Empty;
+
//scale image down to fit
if (pixbuf != null && (pixbuf.Width > DisplaySize.Width || pixbuf.Height > DisplaySize.Height)) {
if (DisplaySize.Width == 0 || displaySize.Height == 0)
@@ -95,6 +130,7 @@ namespace MonoDevelop.MacDev.PlistEditor
destHeight = Math.Max (1, Math.Min (DisplaySize.Height, destHeight));
scaledPixbuf = pixbuf = pixbuf.ScaleSimple (destWidth, destHeight, InterpType.Bilinear);
}
+
image.Pixbuf = pixbuf;
}
@@ -107,6 +143,28 @@ namespace MonoDevelop.MacDev.PlistEditor
Gtk.Drag.DestSet (this, DestDefaults.Drop, targetEntryTypes, DragAction.Link);
SupportedFormats = new List<string> { "png" };
}
+
+ void UpdateTooltip ()
+ {
+ if (imageSize != Size.Empty && RecommendedSize != Size.Empty && imageSize != RecommendedSize) {
+ if (!string.IsNullOrEmpty (description)) {
+ TooltipText = GettextCatalog.GetString ("{0} - the size of the current image does not match the recommended size of {1}x{2} pixels",
+ description, RecommendedSize.Width, RecommendedSize.Height);
+ } else {
+ TooltipText = GettextCatalog.GetString ("The size of the current image does not match the recommended size of {0}x{1} pixels",
+ RecommendedSize.Width, RecommendedSize.Height);
+ }
+ } else if (RecommendedSize != Size.Empty) {
+ if (!string.IsNullOrEmpty (description))
+ TooltipText = GettextCatalog.GetString ("{0}, {1}x{2} pixels in size", description, RecommendedSize.Width, RecommendedSize.Height);
+ else
+ TooltipText = GettextCatalog.GetString ("An image, {0}x{1} pixels in size", RecommendedSize.Width, RecommendedSize.Height);
+ } else if (string.IsNullOrEmpty (description)) {
+ TooltipText = GettextCatalog.GetString ("Choose an image");
+ } else {
+ TooltipText = description;
+ }
+ }
public bool CheckImage (FilePath path)
{
@@ -126,7 +184,6 @@ namespace MonoDevelop.MacDev.PlistEditor
errorMessage = GettextCatalog.GetString (
"Only images with size {0}x{1} are allowed. Picture was {2}x{3}.",
AcceptedSize.Width, AcceptedSize.Height, width, height);
-
} else if (!SupportedFormats.Contains (type.Name)) {
var formats = string.Join (", ", SupportedFormats.Select (f => "'" + f + "'"));
errorTitle = GettextCatalog.GetString ("Invalid image selected");
@@ -152,9 +209,9 @@ namespace MonoDevelop.MacDev.PlistEditor
try {
if (AcceptedSize.IsEmpty)
- dialog.Title = GettextCatalog.GetString ("Select icon...");
+ dialog.Title = GettextCatalog.GetString ("Select image...");
else
- dialog.Title = GettextCatalog.GetString ("Select icon ({0}x{1})...", AcceptedSize.Width, AcceptedSize.Height);
+ dialog.Title = GettextCatalog.GetString ("Select image ({0}x{1})...", RecommendedSize.Width, RecommendedSize.Height);
while (MessageService.RunCustomDialog (dialog) == (int)Gtk.ResponseType.Ok && dialog.SelectedFile != null) {
var path = dialog.SelectedFile.FilePath;
if (!CheckImage (path))
@@ -190,34 +247,48 @@ namespace MonoDevelop.MacDev.PlistEditor
protected override bool OnExposeEvent (EventExpose evnt)
{
var ret = base.OnExposeEvent (evnt);
- if (image.Pixbuf != null)
- return ret;
- using (var cr = CairoHelper.Create (evnt.Window)) {
- cr.Rectangle (evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
- cr.Clip ();
- var imgAlloc = image.Allocation;
- cr.Translate (imgAlloc.X, imgAlloc.Y);
-
- using (var layout = new Pango.Layout (PangoContext)) {
- layout.SetText (string.Format ("({0}x{1})", acceptedSize.Width, acceptedSize.Height));
- layout.Width = (int) (imgAlloc.Width * Pango.Scale.PangoScale);
- layout.Wrap = Pango.WrapMode.WordChar;
- layout.Alignment = Pango.Alignment.Center;
-
- int pw, ph;
- layout.GetPixelSize (out pw, out ph);
- cr.MoveTo (0, (imgAlloc.Height - ph) / 2);
- cr.Color = new Cairo.Color (0.5, 0.5, 0.5);
- cr.ShowLayout (layout);
+ if (image.Pixbuf == null) {
+ using (var cr = CairoHelper.Create (evnt.Window)) {
+ cr.Rectangle (evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
+ cr.Clip ();
+
+ var imgAlloc = image.Allocation;
+ cr.Translate (imgAlloc.X, imgAlloc.Y);
+
+ using (var layout = new Pango.Layout (PangoContext)) {
+ layout.SetText (string.Format ("({0}x{1})", RecommendedSize.Width, RecommendedSize.Height));
+ layout.Width = (int) (imgAlloc.Width * Pango.Scale.PangoScale);
+ layout.Wrap = Pango.WrapMode.WordChar;
+ layout.Alignment = Pango.Alignment.Center;
+
+ int pw, ph;
+ layout.GetPixelSize (out pw, out ph);
+ cr.MoveTo (0, (imgAlloc.Height - ph) / 2);
+ cr.Color = new Cairo.Color (0.5, 0.5, 0.5);
+ cr.ShowLayout (layout);
+ }
+
+ CairoExtensions.RoundedRectangle (cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5);
+ cr.LineWidth = 3;
+ cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
+ cr.SetDash (new double[] { 12, 2 }, 0);
+ cr.Stroke ();
+ }
+ } else if (RecommendedSize != Size.Empty && imageSize != RecommendedSize) {
+ using (var cr = CairoHelper.Create (evnt.Window)) {
+ cr.Rectangle (evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
+ cr.Clip ();
+
+ var imgAlloc = image.Allocation;
+ cr.Translate (imgAlloc.X + displaySize.Width - WarningIcon.Width - 3, imgAlloc.Y + displaySize.Height - WarningIcon.Height);
+
+ CairoHelper.SetSourcePixbuf (cr, WarningIcon, 0, 0);
+ cr.Rectangle (0, 0, WarningIcon.Width, WarningIcon.Height);
+ cr.Fill ();
}
-
- CairoExtensions.RoundedRectangle (cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5);
- cr.LineWidth = 3;
- cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
- cr.SetDash (new double[] { 12, 2 }, 0);
- cr.Stroke ();
}
+
return ret;
}
@@ -256,7 +327,6 @@ namespace MonoDevelop.MacDev.PlistEditor
OnChanged (EventArgs.Empty);
}
}
-
}
}
}
diff --git a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj
index 05c256da96..7faa176270 100644
--- a/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj
+++ b/main/src/addins/MonoDevelop.MacDev/MonoDevelop.MacDev.csproj
@@ -149,6 +149,9 @@
<EmbeddedResource Include="MonoDevelop.MacDev.addin.xml">
<LogicalName>MonoDevelop.MacDev.addin.xml</LogicalName>
</EmbeddedResource>
+ <EmbeddedResource Include="icons\error.png">
+ <LogicalName>error.png</LogicalName>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="icons\application-x-mono-develop-xib.svg" />
diff --git a/main/src/addins/MonoDevelop.MacDev/icons/error.png b/main/src/addins/MonoDevelop.MacDev/icons/error.png
new file mode 100755
index 0000000000..628cf2dae3
--- /dev/null
+++ b/main/src/addins/MonoDevelop.MacDev/icons/error.png
Binary files differ