[Roam-commit] SF.net SVN: roam: [72] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2007-04-09 08:04:00
|
Revision: 72
http://roam.svn.sourceforge.net/roam/?rev=72&view=rev
Author: jonfroehlich
Date: 2007-04-09 01:03:58 -0700 (Mon, 09 Apr 2007)
Log Message:
-----------
Added FormFactory that allows you to quickly create parameterized forms. For example,
NumericTextBox numericTextBox = new NumericTextBox();
numericTextBox.SelectTextOnFocus = true;
numericTextBox.Text = _strokePenWidth.ToString();
Form form = FormFactory.Create("Pen Width:", numericTextBox);
if (form.ShowDialog() == DialogResult.OK)
{
_strokePenWidth = numericTextBox.TextAsInt;
}
Modified Paths:
--------------
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.UI/Roam.UI.csproj
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam.UI/Utils/FormFactory.cs
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-04-08 03:04:10 UTC (rev 71)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-04-09 08:03:58 UTC (rev 72)
@@ -461,7 +461,7 @@
<DependentUpon>TextBoxFilteredListTest.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\FontTest.cs">
- <SubType>Form</SubType>
+ <SubType>Component</SubType>
</Compile>
<Compile Include="UI\Controls\FontTest.Designer.cs">
<DependentUpon>FontTest.cs</DependentUpon>
Modified: Trunk/Source/Roam.UI/Roam.UI.csproj
===================================================================
--- Trunk/Source/Roam.UI/Roam.UI.csproj 2007-04-08 03:04:10 UTC (rev 71)
+++ Trunk/Source/Roam.UI/Roam.UI.csproj 2007-04-09 08:03:58 UTC (rev 72)
@@ -232,6 +232,9 @@
</Compile>
<Compile Include="Utils\DesktopUtils.cs" />
<Compile Include="Utils\DrawingUtils.cs" />
+ <Compile Include="Utils\FormFactory.cs">
+ <SubType>Form</SubType>
+ </Compile>
<Compile Include="Utils\HotKeyManager.cs" />
<Compile Include="Utils\ScreenUtils.cs" />
<Compile Include="Utils\WindowsMessagingUtils.cs" />
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-04-08 03:04:10 UTC (rev 71)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-04-09 08:03:58 UTC (rev 72)
@@ -337,10 +337,39 @@
return "[" + r.X + ", " + r.Y + ", " + r.Width + ", " + r.Height + "]";
}
- public static Rectangle GetRectangle(RectangleF drawStringArea)
+ public static Rectangle GetMinimumAxisAlignedBoundingBox(Point p1, Point p2)
{
- return new Rectangle((int)drawStringArea.X, (int)drawStringArea.Y, (int)drawStringArea.Width, (int)drawStringArea.Height);
+ Point topLeft = Point.Empty, botRight = Point.Empty;
+ if (p1.X < p2.X) { topLeft.X = p1.X; botRight.X = p2.X; }
+ else { topLeft.X = p2.X; botRight.X = p1.X; }
+ if (p1.Y < p2.Y) { topLeft.Y = p1.Y; botRight.Y = p2.Y; }
+ else { topLeft.Y = p2.Y; botRight.Y = p1.Y; }
+ return new Rectangle(topLeft.X, topLeft.Y, botRight.X - topLeft.X, botRight.Y - topLeft.Y);
}
+
+ public static Rectangle GetMinimumAxisAlignedBoundingBox(ICollection<Point> points)
+ {
+ bool initialized = false;
+ Point topLeft = Point.Empty, botRight = Point.Empty;
+ foreach (Point p in points)
+ {
+ if (!initialized)
+ {
+ topLeft = p;
+ botRight = p;
+ initialized = true;
+ }
+ else
+ {
+ if (topLeft.X > p.X) { topLeft.X = p.X; }
+ if (botRight.X < p.X) { botRight.X = p.X; }
+ if (topLeft.Y > p.Y) { topLeft.Y = p.Y; }
+ if (botRight.Y < p.Y) { botRight.Y = p.Y; }
+ }
+ }
+ return new Rectangle(topLeft.X, topLeft.Y, botRight.X - topLeft.X, botRight.Y - topLeft.Y);
+ }
+
}
/// <summary>
Added: Trunk/Source/Roam.UI/Utils/FormFactory.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/FormFactory.cs (rev 0)
+++ Trunk/Source/Roam.UI/Utils/FormFactory.cs 2007-04-09 08:03:58 UTC (rev 72)
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using Roam.UI.Controls;
+using System.Drawing;
+using Roam.UI.Forms;
+
+namespace Roam.UI.Utils
+{
+ public static class FormFactory
+ {
+ public static Form Create(string label, Control control)
+ {
+ FactoryForm form = new FactoryForm();
+
+ ScrollableLabel scrollableLabel = new ScrollableLabel(label);
+ form.Controls.Add(scrollableLabel);
+ form.Controls.Add(control);
+
+ scrollableLabel.Location = new Point(0, 0);
+ control.Location = new Point(0, scrollableLabel.Bottom + 1);
+
+ form.Menu = new MainMenu();
+ MenuItem menuItemLeft = new MenuItem();
+ menuItemLeft.Text = "OK";
+ menuItemLeft.Click += delegate(System.Object o, System.EventArgs e)
+ {
+ form.DialogResult = DialogResult.OK;
+ };
+ form.Menu.MenuItems.Add(menuItemLeft);
+
+ MenuItem menuItemRight = new MenuItem();
+ menuItemRight.Text = "Cancel";
+ menuItemRight.Click += delegate(System.Object o, System.EventArgs e)
+ {
+ form.DialogResult = DialogResult.Cancel;
+ };
+ form.Menu.MenuItems.Add(menuItemRight);
+ control.Focus();
+ return form;
+ }
+ }
+
+ public class FactoryForm : RoamForm
+ {
+ protected override void OnResize(EventArgs e)
+ {
+ int x = ClientRectangle.X; int y = ClientRectangle.Y;
+ //for (int i = this.Controls.Count - 1; i >= 0; i--)
+ //{
+ // Control c = this.Controls[i];
+ foreach(Control c in this.Controls)
+ {
+ c.Width = this.ClientSize.Width;
+ c.Location = new Point(x, y);
+ if (c is ScrollableLabel)
+ {
+ c.Height = ((ScrollableLabel)c).PreferredHeight;
+ }
+
+ y = c.Bottom + 1;
+ }
+ base.OnResize(e);
+ }
+ }
+}
Modified: Trunk/Source/Roam.suo
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|