[Roam-commit] SF.net SVN: roam: [79] Trunk/Source
Status: Alpha
Brought to you by:
jonfroehlich
|
From: <jon...@us...> - 2007-04-25 06:42:53
|
Revision: 79
http://roam.svn.sourceforge.net/roam/?rev=79&view=rev
Author: jonfroehlich
Date: 2007-04-24 23:42:49 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
1. added ShapeContains abstract method to ShapeItem
2. implemented ShapeContains in all the ShapeItem derived classes.
3. added a polygon contains point algorithm in DrawingUtils
4. added hex print out of colors in ColorUtils
5. updated file size / directory info in DirectoryUtils
Modified Paths:
--------------
Trunk/Source/Roam.Common/Utils/ColorUtils.cs
Trunk/Source/Roam.Common/Utils/DirectoryUtils.cs
Trunk/Source/Roam.Common/Utils/MathUtils.cs
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.Test.Desktop/Program.cs
Trunk/Source/Roam.Test.Desktop/Roam.Test.Desktop.csproj
Trunk/Source/Roam.UI/Drawing/EllipseItem.cs
Trunk/Source/Roam.UI/Drawing/ImageItem.cs
Trunk/Source/Roam.UI/Drawing/ShapeItem.cs
Trunk/Source/Roam.UI/Drawing/StarItem.cs
Trunk/Source/Roam.UI/Drawing/VisualItem.cs
Trunk/Source/Roam.UI/Roam.UI.csproj
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam.Test.Desktop/ShapeItemTest.Designer.cs
Trunk/Source/Roam.Test.Desktop/ShapeItemTest.cs
Trunk/Source/Roam.Test.Desktop/ShapeItemTest.resx
Trunk/Source/Roam.UI/Drawing/PolygonItem.cs
Trunk/Source/Roam.UI/Drawing/RectangleItem.cs
Modified: Trunk/Source/Roam.Common/Utils/ColorUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/ColorUtils.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Common/Utils/ColorUtils.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -55,6 +55,16 @@
return GetStaticColors()[colorName];
}
+ public static string ToHexadecimalRgb(Color color)
+ {
+ return color.ToArgb().ToString("X").Substring(2);
+ }
+
+ public static string ToString(Color color)
+ {
+ return string.Format("[{0}, {1}, {2}, {3}]", color.R, color.G, color.B, color.A);
+ }
+
public static Color GetRandomColor()
{
Random rand = new Random();
@@ -74,6 +84,20 @@
return HsbToRgb(hsl);
}
+ public static Color Darken(Color c)
+ {
+ Hsb hsl = RgbToHsb(c);
+ hsl.Brightness = Math.Max(0, hsl.Brightness - 0.05);
+ return HsbToRgb(hsl);
+ }
+
+ public static Color Lighten(Color c)
+ {
+ Hsb hsl = RgbToHsb(c);
+ hsl.Brightness = Math.Min(1, hsl.Brightness + 0.05);
+ return HsbToRgb(hsl);
+ }
+
/// <summary>
/// Sets the absolute brightness of a colour
/// </summary>
Modified: Trunk/Source/Roam.Common/Utils/DirectoryUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/DirectoryUtils.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Common/Utils/DirectoryUtils.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -40,6 +40,11 @@
public static long GetSize(string directoryPath, bool recursive)
{
+ return GetSize(directoryPath, recursive, string.Empty);
+ }
+
+ public static long GetSize(string directoryPath, bool recursive, string fileSearchPattern)
+ {
long size = 0;
if (recursive)
@@ -47,11 +52,14 @@
string[] directories = Directory.GetDirectories(directoryPath);
foreach (string directory in directories)
{
- size += GetSize(directory, recursive);
+ size += GetSize(directory, recursive, fileSearchPattern);
}
}
- string[] files = Directory.GetFiles(directoryPath);
+ string[] files = string.IsNullOrEmpty(fileSearchPattern) ?
+ Directory.GetFiles(directoryPath) :
+ Directory.GetFiles(directoryPath, fileSearchPattern);
+
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
@@ -61,8 +69,39 @@
return size;
}
+ /// <summary>
+ /// Returns a list of FileInfo objects for this directory and all sub-directories
+ /// </summary>
+ /// <param name="directoryPath"></param>
+ /// <returns></returns>
+ public static List<FileInfo> GetFileInfos(string directoryPath)
+ {
+ return GetFileInfos(directoryPath, true);
+ }
+
+ /// <summary>
+ /// Returns a list of FileInfo objects. If recursive is true, this list includes
+ /// all FileInfo objects found in sub-directories
+ /// </summary>
+ /// <param name="directoryPath"></param>
+ /// <param name="recursive"></param>
+ /// <returns></returns>
public static List<FileInfo> GetFileInfos(string directoryPath, bool recursive)
{
+ return GetFileInfos(directoryPath, recursive, string.Empty);
+ }
+
+ /// <summary>
+ /// Returns a list of FileInfo objects. If recursive is true, this list includes
+ /// all FileInfo objects found in sub-directories. If fileSearchPattern != string.Empty,
+ /// this list only includes those files that match the file search pattern.
+ /// </summary>
+ /// <param name="directoryPath"></param>
+ /// <param name="recursive"></param>
+ /// <param name="fileSearchPattern"></param>
+ /// <returns></returns>
+ public static List<FileInfo> GetFileInfos(string directoryPath, bool recursive, string fileSearchPattern)
+ {
List<FileInfo> listFileInfos = new List<FileInfo>();
if (recursive)
@@ -70,11 +109,14 @@
string[] directories = Directory.GetDirectories(directoryPath);
foreach (string directory in directories)
{
- listFileInfos.AddRange(GetFileInfos(directoryPath, recursive));
+ listFileInfos.AddRange(GetFileInfos(directoryPath, recursive, fileSearchPattern));
}
}
- string[] files = Directory.GetFiles(directoryPath);
+ string[] files = string.IsNullOrEmpty(fileSearchPattern) ?
+ Directory.GetFiles(directoryPath) :
+ Directory.GetFiles(directoryPath, fileSearchPattern);
+
foreach (string file in files)
{
listFileInfos.Add(new FileInfo(file));
@@ -83,19 +125,31 @@
return listFileInfos;
}
+ public static int GetNumFiles(string directoryPath)
+ {
+ return GetNumFiles(directoryPath, true);
+ }
+
public static int GetNumFiles(string directoryPath, bool recursive)
{
+ return GetNumFiles(directoryPath, recursive, string.Empty);
+ }
+
+ public static int GetNumFiles(string directoryPath, bool recursive, string fileSearchPattern)
+ {
int numFiles = 0;
if (recursive)
{
string[] directories = Directory.GetDirectories(directoryPath);
foreach (string directory in directories)
{
- numFiles += GetNumFiles(directoryPath, recursive);
+ numFiles += GetNumFiles(directoryPath, recursive, fileSearchPattern);
}
}
- string[] files = Directory.GetFiles(directoryPath);
+ string[] files = string.IsNullOrEmpty(fileSearchPattern) ?
+ Directory.GetFiles(directoryPath) :
+ Directory.GetFiles(directoryPath, fileSearchPattern);
numFiles += files.Length;
return numFiles;
}
Modified: Trunk/Source/Roam.Common/Utils/MathUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/MathUtils.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Common/Utils/MathUtils.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -28,6 +28,14 @@
/// <author>Jon Froehlich</author>
public static class MathUtils
{
+
+ public static double GetDistance(Point ptStart, Point ptEnd)
+ {
+ int xDiff = ptEnd.X - ptStart.X;
+ int yDiff = ptEnd.Y - ptStart.Y;
+ return Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
+ }
+
/// <summary>
/// Gets the angle in radians between these two points and the Vector (1,0)
/// </summary>
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-04-25 06:42:49 UTC (rev 79)
@@ -483,7 +483,7 @@
<DependentUpon>TextBoxFilteredListTest.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\FontTest.cs">
- <SubType>Component</SubType>
+ <SubType>Form</SubType>
</Compile>
<Compile Include="UI\Controls\FontTest.Designer.cs">
<DependentUpon>FontTest.cs</DependentUpon>
Modified: Trunk/Source/Roam.Test.Desktop/Program.cs
===================================================================
--- Trunk/Source/Roam.Test.Desktop/Program.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Test.Desktop/Program.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -35,7 +35,7 @@
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new MeasureStringTest());
+ Application.Run(new ShapeItemTest());
}
}
}
Modified: Trunk/Source/Roam.Test.Desktop/Roam.Test.Desktop.csproj
===================================================================
--- Trunk/Source/Roam.Test.Desktop/Roam.Test.Desktop.csproj 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.Test.Desktop/Roam.Test.Desktop.csproj 2007-04-25 06:42:49 UTC (rev 79)
@@ -79,6 +79,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
+ <EmbeddedResource Include="ShapeItemTest.resx">
+ <SubType>Designer</SubType>
+ <DependentUpon>ShapeItemTest.cs</DependentUpon>
+ </EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
@@ -93,6 +97,12 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
+ <Compile Include="ShapeItemTest.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="ShapeItemTest.Designer.cs">
+ <DependentUpon>ShapeItemTest.cs</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Roam.Common\Roam.Common.csproj">
Added: Trunk/Source/Roam.Test.Desktop/ShapeItemTest.Designer.cs
===================================================================
--- Trunk/Source/Roam.Test.Desktop/ShapeItemTest.Designer.cs (rev 0)
+++ Trunk/Source/Roam.Test.Desktop/ShapeItemTest.Designer.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -0,0 +1,47 @@
+namespace Roam.Test.Desktop
+{
+ partial class ShapeItemTest
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.SuspendLayout();
+ //
+ // ShapeItemTest
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(292, 273);
+ this.DoubleBuffered = true;
+ this.Name = "ShapeItemTest";
+ this.Text = "ShapeItemTest";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Added: Trunk/Source/Roam.Test.Desktop/ShapeItemTest.cs
===================================================================
--- Trunk/Source/Roam.Test.Desktop/ShapeItemTest.cs (rev 0)
+++ Trunk/Source/Roam.Test.Desktop/ShapeItemTest.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -0,0 +1,83 @@
+#region Copyright & License
+//
+// Copyright (c) 2005 - 2007 The Regents of the University of Washington, Intel
+// Research Seattle, and the Roam project. All rights reserved.
+//
+// This software is open-source under the BSD license. You may obtain a copy
+// of this license at
+//
+// http://roam.sourceforge.net/license.txt
+//
+// Alternatively, please see "license.txt" which should be included in
+// this source code distribution.
+//
+#endregion Copyright & License
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+using Roam.UI.Drawing;
+using System.Diagnostics;
+using Roam.UI.Utils;
+
+namespace Roam.Test.Desktop
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public partial class ShapeItemTest : Form
+ {
+ private ShapeItem _shapeItem;
+ private Insets _insets = new Insets(10, 10, 10, 10);
+
+ public ShapeItemTest()
+ {
+ InitializeComponent();
+ this.DoubleBuffered = true;
+ //_shapeItem = new StarItem(CalculateShapeSize(), new Point(_insets.Left, _insets.Top));
+ //_shapeItem = new EllipseItem(CalculateShapeSize(), new Point(_insets.Left, _insets.Top));
+ _shapeItem = new RectangleItem(CalculateShapeSize(), new Point(_insets.Left, _insets.Top));
+ }
+
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ _shapeItem.Draw(e.Graphics, _shapeItem.GetBounds(e.Graphics));
+ base.OnPaint(e);
+ }
+
+ protected override void OnResize(EventArgs e)
+ {
+ if (this.ClientSize.Width > 0 && this.ClientSize.Height > 0)
+ {
+ _shapeItem.ShapeSize = CalculateShapeSize();
+ this.Invalidate();
+ }
+
+ base.OnResize(e);
+ }
+
+ protected override void OnMouseMove(MouseEventArgs e)
+ {
+ Stopwatch sw = Stopwatch.StartNew();
+ bool contains = _shapeItem.ShapeContains(e.Location);
+ sw.Stop();
+ Debug.WriteLine(string.Format("Mouse point {0} is inside shape {1}? {2} (calculated in {3} ms)",
+ DrawingUtils.ToString(e.Location), DrawingUtils.ToString(new Rectangle(_shapeItem.Location, _shapeItem.ShapeSize)),
+ contains, sw.ElapsedMilliseconds));
+ base.OnMouseMove(e);
+ }
+
+ private Size CalculateShapeSize()
+ {
+ return new Size(ClientSize.Width - _insets.TotalHorizontalInset,
+ ClientSize.Height - _insets.TotalVerticalInset); ;
+ }
+ }
+}
\ No newline at end of file
Added: Trunk/Source/Roam.Test.Desktop/ShapeItemTest.resx
===================================================================
--- Trunk/Source/Roam.Test.Desktop/ShapeItemTest.resx (rev 0)
+++ Trunk/Source/Roam.Test.Desktop/ShapeItemTest.resx 2007-04-25 06:42:49 UTC (rev 79)
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
\ No newline at end of file
Modified: Trunk/Source/Roam.UI/Drawing/EllipseItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/EllipseItem.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Drawing/EllipseItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -28,6 +28,7 @@
/// <author>Jon Froehlich</author>
public class EllipseItem : ShapeItem
{
+ #region Constructors
public EllipseItem() : base() { }
public EllipseItem(string label) : base(label) { }
public EllipseItem(Size size)
@@ -36,48 +37,34 @@
: base(size, location) { }
public EllipseItem(Size size, Point location, string label)
: base(size, location, label) { }
-
+ #endregion Constructors
+
protected override void DrawShape(Graphics g, int x, int y)
{
- SolidBrush shapeBrush = new SolidBrush(BackColor);
- Pen shapePen = new Pen(BorderColor, PenWidth);
-
+ SolidBrush shapeBrush = new SolidBrush(GetCurrentShapeBackColor());
+ Pen shapePen = new Pen(GetCurrentBorderColor(), PenWidth);
+
g.FillEllipse(shapeBrush, x, y, ShapeSize.Width, ShapeSize.Height);
g.DrawEllipse(shapePen, x, y, ShapeSize.Width, ShapeSize.Height);
shapeBrush.Dispose();
shapePen.Dispose();
}
- }
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class RectangleItem : ShapeItem
- {
- public RectangleItem() : base() { }
- public RectangleItem(string label) : base(label) { }
- public RectangleItem(Size size)
- : base(size) { }
- public RectangleItem(Size size, Point location)
- : base(size, location) { }
- public RectangleItem(Size size, Point location, string label)
- : base(size, location, label) { }
-
- protected override void DrawShape(Graphics g, int x, int y)
+ public override bool ShapeContains(Point p)
{
- SolidBrush shapeBrush = new SolidBrush(BackColor);
- Pen shapePen = new Pen(BorderColor, PenWidth);
+ //That point is inside the ellipse whenever
+ //((x-x0)/a)^2 + ((y-y0)/b)^2 <= 1
+
+ double xRadius = ShapeWidth / 2.0;
+ double yRadius = ShapeHeight / 2.0;
+ double x0 = xRadius;
+ double y0 = yRadius;
- g.FillEllipse(shapeBrush, x, y, ShapeSize.Width, ShapeSize.Height);
- g.DrawEllipse(shapePen, x, y, ShapeSize.Width, ShapeSize.Height);
+ double xCalc = (p.X - x0) / xRadius;
+ double yCalc = (p.Y - y0) / yRadius;
- shapeBrush.Dispose();
- shapePen.Dispose();
+ return xCalc * xCalc + yCalc * yCalc <= 1;
}
}
}
Modified: Trunk/Source/Roam.UI/Drawing/ImageItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/ImageItem.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Drawing/ImageItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -79,6 +79,12 @@
}
#endregion Properties
+ #region Abstract Methods
+ protected abstract void DrawImage(Graphics g, int x, int y);
+ protected abstract void ResizeImage(float newWidth, float newHeight);
+ #endregion
+
+ #region Methods
protected override void DrawShape(Graphics g, int x, int y)
{
DrawImage(g, x, y);
@@ -89,7 +95,10 @@
ResizeImage(newWidth, newHeight);
}
- protected abstract void DrawImage(Graphics g, int x, int y);
- protected abstract void ResizeImage(float newWidth, float newHeight);
+ public override bool ShapeContains(Point p)
+ {
+ return new Rectangle(this.Location.X, this.Location.Y, this.ShapeWidth, this.ShapeHeight).Contains(p);
+ }
+ #endregion Methods
}
}
Added: Trunk/Source/Roam.UI/Drawing/PolygonItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/PolygonItem.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/PolygonItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -0,0 +1,125 @@
+#region Copyright & License
+//
+// Copyright (c) 2005 - 2007 The Regents of the University of Washington, Intel
+// Research Seattle, and the Roam project. All rights reserved.
+//
+// This software is open-source under the BSD license. You may obtain a copy
+// of this license at
+//
+// http://roam.sourceforge.net/license.txt
+//
+// Alternatively, please see "license.txt" which should be included in
+// this source code distribution.
+//
+#endregion Copyright & License
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+using Roam.UI.Utils;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public abstract class PolygonItem : ShapeItem
+ {
+ private Point[] _pts;
+
+ #region Constructors
+ public PolygonItem() : base() { }
+ public PolygonItem(string label) : base(label) { }
+ public PolygonItem(string label, object item) : base(label, item) { }
+ public PolygonItem(Size size) : this(size, new Point(0, 0)) { }
+ public PolygonItem(Size size, Point location)
+ : this(size, location, string.Empty) { }
+ public PolygonItem(Size size, Point location, string label)
+ : base(size, location, label)
+ {
+ }
+ #endregion Constructors
+
+ #region Properties
+ public override Size ShapeSize
+ {
+ get { return base.ShapeSize; }
+ set
+ {
+ if (ShapeSize != value)
+ {
+ base.ShapeSize = value;
+ _pts = CreateShape();
+ }
+ }
+ }
+
+ public override int ShapeWidth
+ {
+ get { return base.ShapeWidth; }
+ set
+ {
+ if (ShapeSize.Width != value)
+ {
+ base.ShapeWidth = value;
+ _pts = CreateShape();
+ }
+ }
+ }
+
+ public override int ShapeHeight
+ {
+ get { return base.ShapeHeight; }
+ set
+ {
+ if (ShapeSize.Height != value)
+ {
+ base.ShapeHeight = value;
+ _pts = CreateShape();
+ }
+ }
+ }
+
+ protected virtual Point[] Points
+ {
+ get { return _pts; }
+ set { _pts = value; }
+ }
+ #endregion Properties
+
+ #region Abstract Methods
+ protected abstract Point[] CreateShape();
+ #endregion Abstract Methods
+
+ #region Methods
+ public override bool ShapeContains(Point p)
+ {
+ return DrawingUtils.IsPointInPolygon(p, _pts);
+ }
+
+ protected override void DrawShape(Graphics g, int x, int y)
+ {
+ if (_pts == null) { _pts = CreateShape(); }
+
+ Point[] pts = new Point[_pts.Length];
+ for (int i = 0; i < pts.Length; i++)
+ {
+ pts[i] = new Point(_pts[i].X + x, _pts[i].Y + y);
+ }
+
+ SolidBrush shapeBrush = new SolidBrush(GetCurrentShapeBackColor());
+ Pen shapePen = new Pen(GetCurrentBorderColor(), PenWidth);
+
+ g.FillPolygon(shapeBrush, pts);
+ g.DrawPolygon(shapePen, pts);
+
+ shapeBrush.Dispose();
+ shapePen.Dispose();
+ }
+ #endregion Methods
+ }
+}
Added: Trunk/Source/Roam.UI/Drawing/RectangleItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/RectangleItem.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/RectangleItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Drawing;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class RectangleItem : ShapeItem
+ {
+ #region Constructors
+ public RectangleItem() : base() { }
+ public RectangleItem(string label) : base(label) { }
+ public RectangleItem(Size size)
+ : base(size) { }
+ public RectangleItem(Size size, Point location)
+ : base(size, location) { }
+ public RectangleItem(Size size, Point location, string label)
+ : base(size, location, label) { }
+ #endregion Constructors
+
+ public override bool ShapeContains(Point p)
+ {
+ return new Rectangle(this.Location.X, this.Location.Y, this.ShapeWidth, this.ShapeHeight).Contains(p);
+ }
+
+ protected override void DrawShape(Graphics g, int x, int y)
+ {
+ SolidBrush shapeBrush = new SolidBrush(GetCurrentShapeBackColor());
+ Pen shapePen = new Pen(GetCurrentBorderColor(), PenWidth);
+
+ g.FillRectangle(shapeBrush, x, y, ShapeSize.Width, ShapeSize.Height);
+ g.DrawRectangle(shapePen, x, y, ShapeSize.Width, ShapeSize.Height);
+
+ shapeBrush.Dispose();
+ shapePen.Dispose();
+ }
+ }
+}
Modified: Trunk/Source/Roam.UI/Drawing/ShapeItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/ShapeItem.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Drawing/ShapeItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -16,6 +16,19 @@
private RelativeAlignment _textAlign = RelativeAlignment.Right;
private ContentAlignment _shapeAlign = ContentAlignment.TopCenter;
private ScaleMode _scaleMode = ScaleMode.None;
+
+ private Color _shapeBackColor = Color.LightBlue;
+ //private Color _shapeForeColor = Color.Black;
+ //private Color _shapeOutlineColor = Color.Black;
+
+ private Color _shapeSelectedBackColor = SystemColors.Highlight;
+ //private Color _shapeSelectedForeColor = SystemColors.HighlightText;
+ //private Color _shapeSelectedOutlineColor = Color.Black;
+
+ private Color _shapeDisabledBackColor = Color.LightGray;
+ //private Color _shapeDisabledForeColor = Color.Black;
+ //private Color _shapeDisabledOutlineColor = Color.Black;
+
#endregion Fields
#region Constructors
@@ -40,6 +53,70 @@
set { _penWidth = value; }
}
+ //public virtual Rectangle ShapeRectangle
+ //{
+ // get { return new Rectangle(this.Location.X, this.Location.Y, this.ShapeWidth, this.ShapeHeight); }
+ // set
+ // {
+ // ShapeSize = value.Size;
+ // Location = value.Location;
+ // }
+ //}
+
+ public virtual Color ShapeBackColor
+ {
+ get { return _shapeBackColor; }
+ set { _shapeBackColor = value; }
+ }
+
+ //public virtual Color ShapeForeColor
+ //{
+ // get { return _shapeForeColor; }
+ // set { _shapeForeColor = value; }
+ //}
+
+ //public virtual Color ShapeOutlineColor
+ //{
+ // get { return _shapeOutlineColor; }
+ // set { _shapeOutlineColor = value; }
+ //}
+
+ public virtual Color ShapeSelectedBackColor
+ {
+ get { return _shapeSelectedBackColor; }
+ set { _shapeSelectedBackColor = value; }
+ }
+
+ //public virtual Color ShapeSelectedForeColor
+ //{
+ // get { return _shapeSelectedForeColor; }
+ // set { _shapeSelectedForeColor = value; }
+ //}
+
+ //public virtual Color ShapeSelectedOutlineColor
+ //{
+ // get { return _shapeSelectedOutlineColor; }
+ // set { _shapeSelectedOutlineColor = value; }
+ //}
+
+ public virtual Color ShapeDisabledBackColor
+ {
+ get { return _shapeDisabledBackColor; }
+ set { _shapeDisabledBackColor = value; }
+ }
+
+ //public virtual Color ShapeDisabledForeColor
+ //{
+ // get { return _shapeDisabledForeColor; }
+ // set { _shapeDisabledForeColor = value; }
+ //}
+
+ //public virtual Color ShapeDisabledOutlineColor
+ //{
+ // get { return _shapeDisabledOutlineColor; }
+ // set { _shapeDisabledOutlineColor = value; }
+ //}
+
public virtual Size ShapeSize
{
get { return _shapeSize; }
@@ -113,10 +190,38 @@
#endregion Properties
#region Abstract Methods
+ /// <summary>
+ /// TODO : So, as of now, this abstract method is sort of weird because we don't actually define our
+ /// shape location until DrawShape which is based on a set of parameters such as TextAlign,
+ /// ShapeAlign, text size, etc. I'll need to change this in the future. For now, I'm
+ /// just writing the implementers like the shape is drawn at Location.X, Location.Y
+ /// </summary>
+ /// <param name="p"></param>
+ public abstract bool ShapeContains(Point p);
protected abstract void DrawShape(Graphics g, int x, int y);
#endregion Abstract Methods
#region Methods
+ //public virtual Color GetCurrentShapeOutlineColor()
+ //{
+ // if (Selected) { return ShapeSelectedBorderColor; }
+ // else if (!Enabled) { return ShapeDisabledBorderColor; }
+ // else { return ShapeOutlineColor; }
+ //}
+
+ //public virtual Color GetCurrentShapeForeColor()
+ //{
+ // if (Selected) { return ShapeSelectedForeColor; }
+ // else if (!Enabled) { return ShapeDisabledForeColor; }
+ // else { return ShapeForeColor; }
+ //}
+ public virtual Color GetCurrentShapeBackColor()
+ {
+ if (Selected) { return ShapeSelectedBackColor; }
+ else if (!Enabled) { return ShapeDisabledBackColor; }
+ else { return ShapeBackColor; }
+ }
+
public override Rectangle GetBounds(Graphics g)
{
SizeF prefixSize = GetPrefixSize(g);
@@ -253,7 +358,6 @@
RectangleF layoutRectangle = new RectangleF(xLabel + ptOffset.X,
yLabel + ptOffset.Y, labelSize.Width, labelSize.Height);
DrawText(g, layoutRectangle);
-
}
//public virtual ScaleMode GetAutoScaleMode()
@@ -337,7 +441,6 @@
{
this.ShapeSize = new Size((int)newWidth, (int)newHeight);
}
- #endregion Methods
-
+ #endregion Methods
}
}
Modified: Trunk/Source/Roam.UI/Drawing/StarItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/StarItem.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Drawing/StarItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -29,14 +29,14 @@
///
/// </remarks>
/// <author>Jon Froehlich</author>
- public class StarItem : ShapeItem
+ public class StarItem : PolygonItem
{
#region Fields
private int _numStarPoints = 5;
private double _pointiness = 2.5;
- private Point[] _pts;
#endregion Fields
+ #region Constructors
public StarItem() : base() { }
public StarItem(string label) : base(label) { }
public StarItem(Size size)
@@ -53,47 +53,9 @@
_numStarPoints = numStarPoints;
_pointiness = pointiness;
}
+ #endregion Constructors
#region Properties
- public override Size ShapeSize
- {
- get { return base.ShapeSize; }
- set
- {
- if (ShapeSize != value)
- {
- base.ShapeSize = value;
- _pts = CreateStar();
- }
- }
- }
-
- public override int ShapeWidth
- {
- get { return base.ShapeWidth; }
- set
- {
- if (ShapeSize.Width != value)
- {
- base.ShapeWidth = value;
- _pts = CreateStar();
- }
- }
- }
-
- public override int ShapeHeight
- {
- get { return base.ShapeHeight; }
- set
- {
- if (ShapeSize.Height != value)
- {
- base.ShapeHeight = value;
- _pts = CreateStar();
- }
- }
- }
-
public int NumPoints
{
get { return _numStarPoints; }
@@ -107,7 +69,7 @@
if (_numStarPoints != value)
{
_numStarPoints = value;
- _pts = CreateStar();
+ Points = CreateShape();
}
}
}
@@ -120,34 +82,15 @@
if (_pointiness != value)
{
_pointiness = value;
- _pts = CreateStar();
+ Points = CreateShape();
}
}
}
#endregion Properties
- protected override void DrawShape(Graphics g, int x, int y)
+ #region Methods
+ protected override Point[] CreateShape()
{
- if (_pts == null) { _pts = CreateStar(); }
-
- Point [] pts = new Point[_pts.Length];
- for (int i = 0; i < pts.Length; i++)
- {
- pts[i] = new Point(_pts[i].X + x, _pts[i].Y + y);
- }
-
- SolidBrush starBrush = new SolidBrush(BackColor);
- Pen starPen = new Pen(BorderColor, PenWidth);
-
- g.FillPolygon(starBrush, pts);
- g.DrawPolygon(starPen, pts);
-
- starBrush.Dispose();
- starPen.Dispose();
- }
-
- protected virtual Point[] CreateStar()
- {
return CreateStar(ShapeSize, _numStarPoints, _pointiness);
}
@@ -177,5 +120,6 @@
return pts;
}
+ #endregion Methods
}
}
Modified: Trunk/Source/Roam.UI/Drawing/VisualItem.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/VisualItem.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Drawing/VisualItem.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -38,6 +38,8 @@
private bool _isSelected = false;
private bool _isFiltered = false;
private bool _isEnabled = true;
+ private bool _isVisible = true;
+
private int _startTextHighlight = -1;
private int _textHighlightLength = -1;
private Font _font = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Regular);
@@ -120,6 +122,15 @@
set { _isFiltered = value; }
}
+ //TODO : just added this on 4/21, but i have not yet updated the classes that use
+ //VisualItems with functionality that looks to see if a item is visible before drawing it
+ //or calculating layout... Perhaps combine this and filtered? Do we need two separate flags for that?
+ public virtual bool Visible
+ {
+ get { return _isVisible; }
+ set { _isVisible = value; }
+ }
+
public virtual Font Font
{
get { return _font; }
@@ -155,36 +166,6 @@
}
}
- public virtual Color CurrentBorderColor
- {
- get
- {
- if (Selected) { return SelectedBorderColor; }
- else if (!Enabled) { return DisabledBorderColor; }
- else { return BorderColor; }
- }
- }
-
- public virtual Color CurrentForeColor
- {
- get
- {
- if (Selected) { return SelectedForeColor; }
- else if (!Enabled) { return DisabledForeColor; }
- else { return ForeColor; }
- }
- }
-
- public virtual Color CurrentBackColor
- {
- get
- {
- if (Selected) { return SelectedBackColor; }
- else if (!Enabled) { return DisabledBackColor; }
- else { return BackColor; }
- }
- }
-
public virtual Color BorderColor
{
get { return _borderColor; }
@@ -311,6 +292,27 @@
}
}
+ public virtual Color GetCurrentBorderColor()
+ {
+ if (Selected) { return SelectedBorderColor; }
+ else if (!Enabled) { return DisabledBorderColor; }
+ else { return BorderColor; }
+ }
+
+ public virtual Color GetCurrentForeColor()
+ {
+ if (Selected) { return SelectedForeColor; }
+ else if (!Enabled) { return DisabledForeColor; }
+ else { return ForeColor; }
+ }
+
+ public virtual Color GetCurrentBackColor()
+ {
+ if (Selected) { return SelectedBackColor; }
+ else if (!Enabled) { return DisabledBackColor; }
+ else { return BackColor; }
+ }
+
public virtual Rectangle GetBounds(Graphics g)
{
return GetTextBounds(g);
Modified: Trunk/Source/Roam.UI/Roam.UI.csproj
===================================================================
--- Trunk/Source/Roam.UI/Roam.UI.csproj 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Roam.UI.csproj 2007-04-25 06:42:49 UTC (rev 79)
@@ -198,6 +198,7 @@
<Compile Include="Drawing\IVisualItem.cs" />
<Compile Include="Drawing\LinearGradient.cs" />
<Compile Include="Drawing\ListItem.cs" />
+ <Compile Include="Drawing\PolygonItem.cs" />
<Compile Include="Drawing\RadialGradient.cs" />
<Compile Include="Drawing\RadioItem.cs" />
<Compile Include="Drawing\RelativeAlignment.cs" />
@@ -227,6 +228,7 @@
<Compile Include="Forms\SplashForm.Designer.cs">
<DependentUpon>SplashForm.cs</DependentUpon>
</Compile>
+ <Compile Include="Drawing\RectangleItem.cs" />
<Compile Include="Utils\DesktopUtils.cs" />
<Compile Include="Utils\DrawingUtils.cs" />
<Compile Include="Forms\FormFactory.cs">
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-04-17 07:41:29 UTC (rev 78)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-04-25 06:42:49 UTC (rev 79)
@@ -370,6 +370,125 @@
return new Rectangle(topLeft.X, topLeft.Y, botRight.X - topLeft.X, botRight.Y - topLeft.Y);
}
+ /// <summary>
+ /// This routine determines if the point passed is in the polygon. It uses
+ /// the classical polygon hit-testing algorithm: a horizontal ray starting
+ /// at the point is extended infinitely rightwards and the number of
+ /// polygon edges that intersect the ray are counted. If the number is odd,
+ /// the point is inside the polygon.
+ ///
+ /// Code adapted from: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q121960
+ /// </summary>
+ /// <param name="polygon"></param>
+ /// <param name="ptTest"></param>
+ /// <returns></returns>
+ public static bool IsPointInPolygon(Point ptTest, Point[] polygon)
+ {
+ Rectangle boundingBox = GetMinimumAxisAlignedBoundingBox(polygon);
+ return IsPointInPolygon(ptTest, polygon, boundingBox);
+ }
+
+ /// <summary>
+ /// This routine determines if the point passed is in the polygon. It uses
+ /// the classical polygon hit-testing algorithm: a horizontal ray starting
+ /// at the point is extended infinitely rightwards and the number of
+ /// polygon edges that intersect the ray are counted. If the number is odd,
+ /// the point is inside the polygon.
+ ///
+ /// Code adapted from: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q121960
+ /// </summary>
+ /// <param name="polygon"></param>
+ /// <param name="ptTest"></param>
+ /// <param name="boundingBox"></param>
+ /// <returns>true if point is in polygon, false otherwise</returns>
+ public static bool IsPointInPolygon(Point ptTest, Point[] polygon, Rectangle boundingBox)
+ {
+ Point pt1, pt2;
+ int numIntersections = 0;
+
+ if (!boundingBox.Contains(ptTest)) { return false; }
+
+ pt1 = pt2 = ptTest;
+ pt2.X = boundingBox.Right + 50;
+
+ // Now go through each of the lines in the polygon and see if it
+ // intersects
+ for(int i=0; i<polygon.Length - 1; i++)
+ {
+ if (Intersect(ptTest, pt2, polygon[i], polygon[i + 1]))
+ {
+ numIntersections++;
+ }
+ }
+
+ // And the last line
+ if (Intersect(ptTest, pt2, polygon[polygon.Length - 1], polygon[0]))
+ {
+ numIntersections++;
+ }
+
+ //return (numIntersections & 1);
+ return (numIntersections % 2 == 1);
+ }
+
+ /// <summary>
+ /// Given two line segments, determine if they intersect.
+ ///
+ /// Code adapted from: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q121960
+ /// </summary>
+ /// <param name="p1"></param>
+ /// <param name="p2"></param>
+ /// <param name="p3"></param>
+ /// <param name="p4"></param>
+ /// <returns>true if they intersect, false otherwise</returns>
+ public static bool Intersect(Point p1, Point p2, Point p3, Point p4)
+ {
+ return (((CCW(p1, p2, p3) * CCW(p1, p2, p4)) <= 0)
+ && ((CCW(p3, p4, p1) * CCW(p3, p4, p2) <= 0)));
+ }
+
+ /// <summary>
+ /// Determines, given three points, if when travelling from the first to
+ /// the second to the third, we travel in a counterclockwise direction.
+ ///
+ /// Code adapted from: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q121960
+ /// </summary>
+ /// <param name="p0"></param>
+ /// <param name="p1"></param>
+ /// <param name="p2"></param>
+ /// <returns>1 if the movement is in a counterclockwise direction, -1 if not.</returns>
+ private static int CCW(Point p0, Point p1, Point p2)
+ {
+ long dx1, dx2;
+ long dy1, dy2;
+
+ dx1 = p1.X - p0.X; dx2 = p2.X - p0.X;
+ dy1 = p1.Y - p0.Y; dy2 = p2.Y - p0.Y;
+
+ /* This is basically a slope comparison: we don't do divisions because
+ * of divide by zero possibilities with pure horizontal and pure
+ * vertical lines.
+ */
+ return ((dx1 * dy2 > dy1 * dx2) ? 1 : -1);
+ }
+
+ //public static Rectangle GetBoundingBox(Point[] polygon)
+ //{
+ // int xmin = int.MaxValue, ymin = int.MaxValue;
+ // int xmax = int.MinValue, ymax = int.MinValue;
+ // foreach(Point p in polygon)
+ // {
+ // if (p.X < xmin) { xmin = ppt->x; }
+
+ // if (ppt->x > xmax) { xmax = ppt->x; }
+
+ // if (ppt->y < ymin)
+ // ymin = ppt->y;
+ // if (ppt->y > ymax)
+ // ymax = ppt->y;
+ // }
+ //}
+
}
/// <summary>
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.
|