diff --git a/Deployment/Setup.NuGet/Build.cmd b/Deployment/Setup.NuGet/Build.cmd
index fb863f6..1031694 100644
--- a/Deployment/Setup.NuGet/Build.cmd
+++ b/Deployment/Setup.NuGet/Build.cmd
@@ -12,7 +12,7 @@ echo.
timeout /T 5
:: Set version info
-set version=4.6.5
+set version=4.7.0
set output=%cd%\bin\
:: Create output directory
diff --git a/Deployment/Setup.NuGet/UI/UI.nuspec b/Deployment/Setup.NuGet/UI/UI.nuspec
index 07fe853..571bea8 100644
--- a/Deployment/Setup.NuGet/UI/UI.nuspec
+++ b/Deployment/Setup.NuGet/UI/UI.nuspec
@@ -12,7 +12,7 @@
https://raw.githubusercontent.com/dajuric/dot-imaging/master/Deployment/Logo/logo-small.png
true
- Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog).
+ Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog, menu dialog).
In order to support other OS platforms (except Windows) install one (or more) of the following packages:
- Eto.Platform.Windows (included by default)
@@ -24,7 +24,7 @@
- Eto.Platform.XamMac * requires Xamarin Studio on OS X.
- Eto.Platform.XamMac2 * requires Xamarin Studio on OS X.
- Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog).
+ Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog, menu dialog).
UI, portable-UI, UI-extensions, DotImaging-UI
diff --git a/Deployment/Setup.NuGet/UI/readmeUI.txt b/Deployment/Setup.NuGet/UI/readmeUI.txt
index e4a032f..108e4b0 100644
--- a/Deployment/Setup.NuGet/UI/readmeUI.txt
+++ b/Deployment/Setup.NuGet/UI/readmeUI.txt
@@ -1,4 +1,4 @@
-Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog).
+Portable standalone UI elements invokable as extensions (image display, progress bar, open-save file dialogs, folder-selection dialog, color-picker, mask-drawing dialog, rectangle-drawing dialog, menu dialog).
1) image show
Bgr[,] image = new Bgr[480, 640];
@@ -29,6 +29,13 @@
image.SetValue>(Bgr.Red);
RectangleF rect = image.GetRectangle(); //get user-defined rectangle dialog
+7) menu dialog
+ var selectedNumber = -1;
+ UI.ShowMenu(itemNames: new string[] { "2", "3" },
+ actions: new Action[] { () => selectedNumber = 2, () => selectedNumber = 3 });
+
+
+ Console.WriteLine("Selected number: {0}", selectedNumber);
---------------------------------------------------------------------------
In order to support other OS platforms (except Windows) install one (or more) of the following packages:
diff --git a/README.md b/README.md
index 2dba5d9..57dba5d 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
-
+
**DotImaging** - .NET array as imaging object
@@ -112,11 +112,15 @@ image.Show(); //show image (non-blocking)
string fileName = UI.OpenFile(); //open-file dialog
-Bgr color = UI.PickColor(); //color picker dialog
+Bgr color = UI.PickColor(); //color-picker dialog
-Gray[,] mask = image.GetMask(); //get user-defined mask dialog
+Gray[,] mask = image.GetMask(); //draw-mask dialog
-RectangleF rect = image.GetRectangle(); //get user-defined rectangle dialog
+RectangleF rect = image.GetRectangle(); //draw-rectangle dialog
+
+var num = -1;
+UI.ShowMenu(itemNames: new string[] { "2", "3" },
+ actions: new Action[] { () => num = 2, () => num = 3 }); //menu-dialog
```
+ DotImaging.Linq
diff --git a/Source/UI/Forms/MenuForm.cs b/Source/UI/Forms/MenuForm.cs
new file mode 100644
index 0000000..689dd5c
--- /dev/null
+++ b/Source/UI/Forms/MenuForm.cs
@@ -0,0 +1,87 @@
+#region Licence and Terms
+// DotImaging Framework
+// https://github.com/dajuric/dot-imaging
+//
+// Copyright © Darko Jurić, 2014-2016
+// darko.juric2@gmail.com
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#endregion
+
+using Eto.Drawing;
+using Eto.Forms;
+using System;
+
+namespace DotImaging
+{
+ ///
+ /// Menu form.
+ ///
+ internal class MenuForm : Form
+ {
+ ///
+ /// Creates a new menu form.
+ ///
+ /// Window title.
+ public MenuForm(string title = "")
+ :this(title, null, null)
+ { }
+
+ ///
+ /// Creates a new menu form.
+ ///
+ /// Window title.
+ /// Item names.
+ /// Actions.
+ public MenuForm(string title, string[] itemNames, Action[] actions)
+ {
+ Title = title;
+ SelectedIndex = -1;
+
+ if (itemNames == null || actions == null)
+ return;
+ if (itemNames.Length != actions.Length)
+ return;
+
+ var stackLayout = new StackLayout {Orientation = Orientation.Vertical, HorizontalContentAlignment = HorizontalAlignment.Stretch };
+
+ for (int i = 0; i < itemNames.Length; i++)
+ {
+ var idx = i;
+
+ var button = new Button { Text = itemNames[idx], Size = new Size(240, 60) };
+ button.Click += (s, e) =>
+ {
+ actions[idx]();
+ SelectedIndex = idx;
+ this.Close();
+ };
+
+ stackLayout.Items.Add(new StackLayoutItem(button, true));
+ }
+
+ Content = stackLayout;
+ Size = new Size(-1, -1);
+ }
+
+ ///
+ /// Gets the selected menu item index or returns -1 in case the form is closed.
+ ///
+ public int SelectedIndex
+ {
+ get; private set;
+ }
+ }
+
+}
diff --git a/Source/UI/UI.cs b/Source/UI/UI.cs
index 0094196..dc6df90 100644
--- a/Source/UI/UI.cs
+++ b/Source/UI/UI.cs
@@ -21,6 +21,7 @@
using Eto.Forms;
using DotImaging.Primitives2D;
+using System;
namespace DotImaging
{
@@ -219,6 +220,27 @@ public static RectangleF GetRectangle(this Bgr[,] image, string windowTitl
return new RectangleF(rect.X, rect.Y, rect.Width, rect.Height);
}
+ ///
+ /// Displays a menu dialog specified by user defined menu items.
+ /// If no items are specified, or in case of a error, the dialog will not be shown.
+ ///
+ /// Window title (ID).
+ /// Names of the menu items.
+ /// Item actions.
+ /// Selected menu index or -1 in case the form is closed.
+ public static int ShowMenu(string windowTitle = "Menu (close when finished)", string[] itemNames = null, Action[] actions = null)
+ {
+ var idx = FormCollection.CreateAndShowDialog(() =>
+ {
+ var f = new MenuForm(windowTitle, itemNames, actions);
+ f.Title = windowTitle;
+ return f;
+ },
+ f => f.SelectedIndex);
+
+ return idx;
+ }
+
///
/// Closes all UI controls if displayed.
///
diff --git a/Source/UI/UI.csproj b/Source/UI/UI.csproj
index 0e9c603..5524dc3 100644
--- a/Source/UI/UI.csproj
+++ b/Source/UI/UI.csproj
@@ -52,6 +52,7 @@
+
diff --git a/Test/Program.cs b/Test/Program.cs
index 8b4e4f3..74d7a9b 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -38,6 +38,13 @@ class Program
[STAThread]
unsafe static void Main()
{
+ var selectedIdx = UI.ShowMenu(itemNames: new string[] { "Option A", "Option B" },
+ actions: new Action[] { () => Console.WriteLine("Option A"), () => Console.WriteLine("Option B") });
+
+ Console.WriteLine("Selected option: {0}", selectedIdx);
+ UI.CloseAll();
+ return;
+
var resourceDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "Resources");
var imgColor = ImageIO.LoadColor(Path.Combine(resourceDir, "testColorBig.jpg")).Clone();