roam-commit Mailing List for Roam, a Windows Mobile library (Page 4)
Status: Alpha
Brought to you by:
jonfroehlich
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
(9) |
Apr
(10) |
May
|
Jun
|
Jul
(10) |
Aug
(1) |
Sep
(7) |
Oct
(4) |
Nov
(6) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(1) |
Feb
(9) |
Mar
(11) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(2) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
|
Feb
|
Mar
(1) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <jon...@us...> - 2007-03-06 11:57:15
|
Revision: 63
http://roam.svn.sourceforge.net/roam/?rev=63&view=rev
Author: jonfroehlich
Date: 2007-03-06 03:57:11 -0800 (Tue, 06 Mar 2007)
Log Message:
-----------
1. Refactored the Fill.cs file into multiple Fill classes
2. Updated FillRoundedRectangle to have exposed properties and to use a pen/brush
3. Worked on ScrollableLabelTest2 to test borders and FillSimpleLinearGradient
Modified Paths:
--------------
Trunk/Source/Roam.Common/Utils/StringUtils.cs
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.Designer.cs
Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.cs
Trunk/Source/Roam.UI/Drawing/Fill.cs
Trunk/Source/Roam.UI/Roam.UI.csproj
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam.UI/Drawing/FillImage.cs
Trunk/Source/Roam.UI/Drawing/FillNone.cs
Trunk/Source/Roam.UI/Drawing/FillRoundedRectangle.cs
Trunk/Source/Roam.UI/Drawing/FillSimpleLinearGradient.cs
Trunk/Source/Roam.UI/Drawing/FillSolid.cs
Modified: Trunk/Source/Roam.Common/Utils/StringUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -60,5 +60,37 @@
}
return list.ToArray();
}
+
+ public static bool ContainsMultiple(string s, char ch)
+ {
+ int index = s.IndexOf(ch);
+ if (index == -1) return false;
+
+ int nextIndex = s.IndexOf(ch, index);
+ if (nextIndex == -1) return false;
+
+ return true;
+ }
+
+ public static bool Contains(string s, char ch)
+ {
+ return s.IndexOf(ch) != -1;
+ }
+
+ public static bool ContainsMultiple(string s, string value)
+ {
+ int index = s.IndexOf(value);
+ if (index == -1) return false;
+
+ int nextIndex = s.IndexOf(value, index);
+ if (nextIndex == -1) return false;
+
+ return true;
+ }
+
+ public static bool Contains(string s, string value)
+ {
+ return s.IndexOf(value) != -1;
+ }
}
}
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-06 11:57:11 UTC (rev 63)
@@ -438,7 +438,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/UI/Controls/ScrollableLabelTest2.Designer.cs
===================================================================
--- Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.Designer.cs 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.Designer.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -61,11 +61,15 @@
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
- this.scrollableLabel1 = new Roam.UI.Controls.ScrollableLabel();
+ this.menuItem11 = new System.Windows.Forms.MenuItem();
this._menuBackFillImageMode = new System.Windows.Forms.MenuItem();
+ this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
- this.menuItem14 = new System.Windows.Forms.MenuItem();
+ this.menuItemBorderStyle = new System.Windows.Forms.MenuItem();
+ this.scrollableLabel1 = new Roam.UI.Controls.ScrollableLabel();
+ this.menuItemBorderBehavior = new System.Windows.Forms.MenuItem();
+ this.menuItem15 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// mainMenu1
@@ -86,6 +90,8 @@
this.menuItem2.MenuItems.Add(this.menuItem6);
this.menuItem2.MenuItems.Add(this.menuItem7);
this.menuItem2.MenuItems.Add(this._menuBackFillImageMode);
+ this.menuItem2.MenuItems.Add(this.menuItemBorderStyle);
+ this.menuItem2.MenuItems.Add(this.menuItemBorderBehavior);
this.menuItem2.Text = "Menu";
//
// menuItem3
@@ -113,6 +119,8 @@
this.menuItem7.MenuItems.Add(this.menuItem8);
this.menuItem7.MenuItems.Add(this.menuItem9);
this.menuItem7.MenuItems.Add(this.menuItem10);
+ this.menuItem7.MenuItems.Add(this.menuItem11);
+ this.menuItem7.MenuItems.Add(this.menuItem15);
this.menuItem7.Text = "BackFill";
//
// menuItem8
@@ -122,7 +130,7 @@
//
// menuItem9
//
- this.menuItem9.Text = "Random Color";
+ this.menuItem9.Text = "Random Solid Color";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem10
@@ -130,15 +138,10 @@
this.menuItem10.Text = "Random Gradient";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
- // scrollableLabel1
+ // menuItem11
//
- this.scrollableLabel1.Location = new System.Drawing.Point(13, 17);
- this.scrollableLabel1.MaxLines = 100;
- this.scrollableLabel1.Name = "scrollableLabel1";
- this.scrollableLabel1.ScrollLock = false;
- this.scrollableLabel1.ShowScrollBar = true;
- this.scrollableLabel1.Size = new System.Drawing.Size(213, 231);
- this.scrollableLabel1.TabIndex = 0;
+ this.menuItem11.Text = "Random Rounded Rect";
+ this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
//
// _menuBackFillImageMode
//
@@ -147,6 +150,11 @@
this._menuBackFillImageMode.MenuItems.Add(this.menuItem13);
this._menuBackFillImageMode.Text = "BackFill Image Mode";
//
+ // menuItem14
+ //
+ this.menuItem14.Text = "Center";
+ this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
+ //
// menuItem12
//
this.menuItem12.Text = "Normal";
@@ -157,11 +165,29 @@
this.menuItem13.Text = "Stretch";
this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
//
- // menuItem14
+ // menuItemBorderStyle
//
- this.menuItem14.Text = "Center";
- this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
+ this.menuItemBorderStyle.Text = "Border Style";
//
+ // scrollableLabel1
+ //
+ this.scrollableLabel1.Location = new System.Drawing.Point(13, 17);
+ this.scrollableLabel1.MaxLines = 100;
+ this.scrollableLabel1.Name = "scrollableLabel1";
+ this.scrollableLabel1.ScrollLock = false;
+ this.scrollableLabel1.ShowScrollBar = true;
+ this.scrollableLabel1.Size = new System.Drawing.Size(213, 231);
+ this.scrollableLabel1.TabIndex = 0;
+ //
+ // menuItemBorderBehavior
+ //
+ this.menuItemBorderBehavior.Text = "Border Behavior";
+ //
+ // menuItem15
+ //
+ this.menuItem15.Text = "Solid White Color";
+ this.menuItem15.Click += new System.EventHandler(this.menuItem15_Click);
+ //
// ScrollableLabelTest2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(131F, 131F);
@@ -193,5 +219,9 @@
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
+ private System.Windows.Forms.MenuItem menuItem11;
+ private System.Windows.Forms.MenuItem menuItemBorderStyle;
+ private System.Windows.Forms.MenuItem menuItemBorderBehavior;
+ private System.Windows.Forms.MenuItem menuItem15;
}
}
Modified: Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.cs
===================================================================
--- Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.cs 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.Test/UI/Controls/ScrollableLabelTest2.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -23,6 +23,7 @@
using Roam.UI.Drawing;
using Roam.Test.Utils;
using Roam.Common.Utils;
+using Roam.UI.Controls;
namespace MyExperience.Test
{
@@ -47,8 +48,36 @@
_timer.Tick += new EventHandler(OnTimerTick);
_timer.Enabled = false;
menuItem3.Text = _timer.Enabled ? "Stop" : "Start";
+
+ foreach(string name in EnumUtils.GetNames(typeof(BorderStyle)))
+ {
+ MenuItem mi = new MenuItem();
+ mi.Text = name;
+ mi.Click += new EventHandler(OnBorderStyleMenuItemClick);
+ menuItemBorderStyle.MenuItems.Add(mi);
+ }
+
+ foreach (string name in EnumUtils.GetNames(typeof(BorderBehavior)))
+ {
+ MenuItem mi = new MenuItem();
+ mi.Text = name;
+ mi.Click += new EventHandler(OnBorderBehaviorMenuItemClick);
+ menuItemBorderBehavior.MenuItems.Add(mi);
+ }
}
+ private void OnBorderStyleMenuItemClick(object sender, EventArgs e)
+ {
+ MenuItem mi = (MenuItem)sender;
+ scrollableLabel1.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), mi.Text, true);
+ }
+
+ private void OnBorderBehaviorMenuItemClick(object sender, EventArgs e)
+ {
+ MenuItem mi = (MenuItem)sender;
+ scrollableLabel1.BorderBehavior = (BorderBehavior)Enum.Parse(typeof(BorderBehavior), mi.Text, true);
+ }
+
private void OnTimerTick(object sender, EventArgs e)
{
Debug.WriteLine(String.Format("Timer tick in {0} milliseconds", ((TimeSpan)(DateTime.Now - _timeStamp)).TotalMilliseconds));
@@ -125,6 +154,12 @@
scrollableLabel1.BackFill = new FillSolid(ColorUtils.GetRandomColor());
}
+ //solid white color
+ private void menuItem15_Click(object sender, EventArgs e)
+ {
+ scrollableLabel1.BackFill = new FillSolid(Color.White);
+ }
+
//random gradient
private void menuItem10_Click(object sender, EventArgs e)
{
@@ -134,6 +169,16 @@
new SimpleLinearGradient(ColorUtils.GetRandomColor(), ColorUtils.GetRandomColor(), fillDirect));
}
+ //random fill rounded rect
+ private void menuItem11_Click(object sender, EventArgs e)
+ {
+ Random random = new Random();
+ int corner = random.Next(5, (int)(this.Width / 2f));
+ scrollableLabel1.BackFill = new FillRoundedRectangle(
+ ColorUtils.GetRandomColor(), ColorUtils.GetRandomColor(), corner, corner);
+
+ }
+
//normal
private void menuItem12_Click(object sender, EventArgs e)
{
Modified: Trunk/Source/Roam.UI/Drawing/Fill.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/Fill.cs 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.UI/Drawing/Fill.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -102,229 +102,4 @@
}
protected abstract void DrawInternal(Graphics g, Rectangle rect);
}
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class FillNone : Fill
- {
- public static FillNone Empty = new FillNone();
-
- public FillNone() : base(0) {}
- public override float AlphaBlend
- {
- get { return base.AlphaBlend; }
- set { throw new InvalidOperationException("AlphaBlend cannot be set in FillNone"); }
- }
-
- public override void Draw(Graphics g, Rectangle rect)
- {
- //do nothing
- }
-
- protected override void DrawInternal(Graphics g, Rectangle rect)
- {
- //do nothing
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class FillRoundedRectangle : Fill
- {
- private Color _foreColor = Color.Black;
- private int _roundedCornerWidth = 5;
- private int _roundedCornerHeight = 5;
-
- public FillRoundedRectangle(Color backColor) : this(backColor, Color.Black, 0) { }
- public FillRoundedRectangle(Color backColor, Color foreColor) : this(backColor, foreColor, 0) { }
- public FillRoundedRectangle(Color backColor, Color foreColor, float alphaBlend)
- : this(backColor, foreColor, 5, 5, alphaBlend)
- {
- }
-
- public FillRoundedRectangle(Color backColor, Color foreColor, int roundedCornerWidth, int roundedCornerHeight, float alphaBlend)
- : base(alphaBlend, backColor)
- {
- _foreColor = foreColor;
- _roundedCornerWidth = roundedCornerWidth;
- _roundedCornerHeight = roundedCornerHeight;
- }
-
- protected override void DrawInternal(Graphics g, Rectangle rect)
- {
- Pen pen = new Pen(_foreColor);
- SolidBrush solidBrush = new SolidBrush(Color);
- DrawingUtils.RoundRect(g, rect.X, rect.Y, rect.Right, rect.Bottom,
- _roundedCornerWidth, _roundedCornerHeight);
- pen.Dispose();
- solidBrush.Dispose();
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class FillSolid : Fill
- {
- public FillSolid(Color color) : this(color, 0) { }
- public FillSolid(Color color, float alphaBlend) : base(alphaBlend, color) { }
-
- protected override void DrawInternal(Graphics g, Rectangle rect)
- {
- SolidBrush solidBrush = new SolidBrush(Color);
- g.FillRectangle(solidBrush, rect);
- solidBrush.Dispose();
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class FillSimpleLinearGradient : Fill
- {
- private SimpleLinearGradient _gradient;
- public FillSimpleLinearGradient(SimpleLinearGradient gradient) : this(gradient, 0) { }
- public FillSimpleLinearGradient(SimpleLinearGradient gradient, float alphaBlend)
- : base(alphaBlend)
- {
- _gradient = gradient;
- }
-
- public SimpleLinearGradient Gradient { get { return _gradient; } set { _gradient = value; } }
-
- protected override void DrawInternal(Graphics g, Rectangle rect)
- {
- _gradient.Fill(g, rect);
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public class FillImage : Fill
- {
- private Image _image;
- private bool _useTransparencyKey = false;
- private Color _tranparencyKey;
- private FillImageSizeMode _fillSizeMode = FillImageSizeMode.Normal;
-
- public FillImage(Image image) : this(image, 0) { }
- public FillImage(Image image, Color transparencyKey) : this(image, transparencyKey, FillImageSizeMode.Normal, 0) { }
- public FillImage(Image image, Color transparencyKey, FillImageSizeMode fillImageSizeMode, float alphaBlend)
- : base(alphaBlend)
- {
- _image = image;
- _useTransparencyKey = true;
- _tranparencyKey = transparencyKey;
- _fillSizeMode = fillImageSizeMode;
- }
-
- public FillImage(Image image, float alphaBlend)
- : base(alphaBlend)
- {
- _image = image;
- }
-
- public Image Image { get { return _image; } set { _image = value; } }
- public FillImageSizeMode SizeMode { get { return _fillSizeMode; } set { _fillSizeMode = value; } }
- public Color TransparencyKey { get { return _tranparencyKey; } set { _tranparencyKey = value; } }
- public bool UseTransparencyKey { get { return _useTransparencyKey; } set { _useTransparencyKey = value; } }
-
- public override void Dispose()
- {
- if (_image != null)
- {
- _image.Dispose();
- _image = null;
- }
- base.Dispose();
- }
-
- protected override void DrawInternal(Graphics g, Rectangle rect)
- {
- ImageAttributes attr = new ImageAttributes();
- if (_useTransparencyKey) { attr.SetColorKey(_tranparencyKey, _tranparencyKey); }
- else
- {
- SolidBrush solidBrush = new SolidBrush(this.Color);
- g.FillRectangle(solidBrush, rect);
- solidBrush.Dispose();
- }
-
- if (_fillSizeMode == FillImageSizeMode.StretchImage)
- {
- g.DrawImage(_image, rect, 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
- }
- else if (_fillSizeMode == FillImageSizeMode.CenterImage)
- {
- int x = (int)(rect.X + rect.Width / 2f - _image.Width / 2f);
- int y = (int)(rect.Y + rect.Height / 2f - _image.Height / 2f);
- g.Clip = new Region(rect);
- g.DrawImage(_image, new Rectangle(x, y, _image.Width, _image.Height),
- 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
- g.Clip.MakeInfinite();
- }
- else if (_fillSizeMode == FillImageSizeMode.Normal)
- {
- g.Clip = new Region(rect);
- g.DrawImage(_image, new Rectangle(rect.X, rect.Y, _image.Width, _image.Height),
- 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
- g.Clip.MakeInfinite();
- }
- }
- }
-
- /// <summary>
- /// Specifies how an image is positioned within a FillImage
- /// </summary>
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public enum FillImageSizeMode
- {
- /// <summary>
- /// The image is placed in the upper-left corner of the Fill rectangle.
- /// The image is clipped if it is larger than the provided area
- /// it is contained in.
- /// </summary>
- Normal,
-
- /// <summary>
- /// The image within the Fill is stretched or shrunk to fit the size of the provided rectangle
- /// </summary>
- StretchImage,
-
- /// <summary>
- /// The image is displayed in the center if the given area is larger than the image. If the
- /// image is larger than the area, the picture is placed in the center of the area
- /// and the outside edges are clipped.
- /// </summary>
- CenterImage
- }
}
Added: Trunk/Source/Roam.UI/Drawing/FillImage.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/FillImage.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/FillImage.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -0,0 +1,137 @@
+#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 System.Drawing.Imaging;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class FillImage : Fill
+ {
+ #region Fields
+ private Image _image;
+ private bool _useTransparencyKey = false;
+ private Color _tranparencyKey;
+ private FillImageSizeMode _fillSizeMode = FillImageSizeMode.Normal;
+ #endregion Fields
+
+ #region Constructors
+ public FillImage(Image image) : this(image, 0) { }
+ public FillImage(Image image, Color transparencyKey) : this(image, transparencyKey, FillImageSizeMode.Normal, 0) { }
+ public FillImage(Image image, Color transparencyKey, FillImageSizeMode fillImageSizeMode, float alphaBlend)
+ : base(alphaBlend)
+ {
+ _image = image;
+ _useTransparencyKey = true;
+ _tranparencyKey = transparencyKey;
+ _fillSizeMode = fillImageSizeMode;
+ }
+
+ public FillImage(Image image, float alphaBlend)
+ : base(alphaBlend)
+ {
+ _image = image;
+ }
+ #endregion Constructors
+
+ #region Properties
+ public Image Image { get { return _image; } set { _image = value; } }
+ public FillImageSizeMode SizeMode { get { return _fillSizeMode; } set { _fillSizeMode = value; } }
+ public Color TransparencyKey { get { return _tranparencyKey; } set { _tranparencyKey = value; } }
+ public bool UseTransparencyKey { get { return _useTransparencyKey; } set { _useTransparencyKey = value; } }
+ #endregion Properties
+
+ public override void Dispose()
+ {
+ if (_image != null)
+ {
+ _image.Dispose();
+ _image = null;
+ }
+ base.Dispose();
+ }
+
+ protected override void DrawInternal(Graphics g, Rectangle rect)
+ {
+ ImageAttributes attr = new ImageAttributes();
+ if (_useTransparencyKey) { attr.SetColorKey(_tranparencyKey, _tranparencyKey); }
+ else
+ {
+ SolidBrush solidBrush = new SolidBrush(this.Color);
+ g.FillRectangle(solidBrush, rect);
+ solidBrush.Dispose();
+ }
+
+ if (_fillSizeMode == FillImageSizeMode.StretchImage)
+ {
+ g.DrawImage(_image, rect, 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
+ }
+ else if (_fillSizeMode == FillImageSizeMode.CenterImage)
+ {
+ int x = (int)(rect.X + rect.Width / 2f - _image.Width / 2f);
+ int y = (int)(rect.Y + rect.Height / 2f - _image.Height / 2f);
+ g.Clip = new Region(rect);
+ g.DrawImage(_image, new Rectangle(x, y, _image.Width, _image.Height),
+ 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
+ g.Clip.MakeInfinite();
+ }
+ else if (_fillSizeMode == FillImageSizeMode.Normal)
+ {
+ g.Clip = new Region(rect);
+ g.DrawImage(_image, new Rectangle(rect.X, rect.Y, _image.Width, _image.Height),
+ 0, 0, _image.Width, _image.Height, GraphicsUnit.Pixel, attr);
+ g.Clip.MakeInfinite();
+ }
+ }
+ }
+
+ /// <summary>
+ /// Specifies how an image is positioned within a FillImage
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public enum FillImageSizeMode
+ {
+ /// <summary>
+ /// The image is placed in the upper-left corner of the Fill rectangle.
+ /// The image is clipped if it is larger than the provided area
+ /// it is contained in.
+ /// </summary>
+ Normal,
+
+ /// <summary>
+ /// The image within the Fill is stretched or shrunk to fit the size of the provided rectangle
+ /// </summary>
+ StretchImage,
+
+ /// <summary>
+ /// The image is displayed in the center if the given area is larger than the image. If the
+ /// image is larger than the area, the picture is placed in the center of the area
+ /// and the outside edges are clipped.
+ /// </summary>
+ CenterImage
+ }
+}
Added: Trunk/Source/Roam.UI/Drawing/FillNone.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/FillNone.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/FillNone.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -0,0 +1,51 @@
+#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;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class FillNone : Fill
+ {
+ public static FillNone Empty = new FillNone();
+
+ public FillNone() : base(0) { }
+
+ public override float AlphaBlend
+ {
+ get { return base.AlphaBlend; }
+ set { throw new InvalidOperationException("AlphaBlend cannot be set in FillNone"); }
+ }
+
+ public override void Draw(Graphics g, Rectangle rect)
+ {
+ //do nothing
+ }
+
+ protected override void DrawInternal(Graphics g, Rectangle rect)
+ {
+ //do nothing
+ }
+ }
+}
Added: Trunk/Source/Roam.UI/Drawing/FillRoundedRectangle.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/FillRoundedRectangle.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/FillRoundedRectangle.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -0,0 +1,107 @@
+#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 class FillRoundedRectangle : Fill
+ {
+ #region Fields
+ private Color _foreColor = Color.Black;
+ private int _roundedCornerWidth = 5;
+ private int _roundedCornerHeight = 5;
+ private int _penWidth = 2;
+ private bool _drawSolidBack = true;
+ private Color _solidBackColor = Color.White;
+ #endregion Fields
+
+ #region Constructors
+ public FillRoundedRectangle(Color backColor) : this(backColor, Color.Black, 0) { }
+ public FillRoundedRectangle(Color backColor, Color foreColor) : this(backColor, foreColor, 0) { }
+ public FillRoundedRectangle(Color backColor, Color foreColor, float alphaBlend)
+ : this(backColor, foreColor, 5, 5, alphaBlend) { }
+ public FillRoundedRectangle(Color backColor, Color foreColor, int roundedCornerWidth, int roundedCornerHeight)
+ : this(backColor, foreColor, roundedCornerWidth, roundedCornerHeight, 0) { }
+ public FillRoundedRectangle(Color backColor, Color foreColor, int roundedCornerWidth, int roundedCornerHeight, float alphaBlend)
+ : base(alphaBlend, backColor)
+ {
+ _foreColor = foreColor;
+ _roundedCornerWidth = roundedCornerWidth;
+ _roundedCornerHeight = roundedCornerHeight;
+ }
+ #endregion Constructors
+
+ #region Properties
+ public float PenWidth
+ {
+ get { return _penWidth; }
+ set { _penWidth = value; }
+ }
+
+ public int RoundedCornerWidth
+ {
+ get { return _roundedCornerWidth; }
+ set { _roundedCornerWidth = value; }
+ }
+
+ public int RoundedCornerHeight
+ {
+ get { return _roundedCornerHeight; }
+ set { _roundedCornerHeight = value; }
+ }
+
+ public bool DrawSolidBackColor
+ {
+ get { return _drawSolidBack; }
+ set { _drawSolidBack = value; }
+ }
+
+ public Color SolidBackColor
+ {
+ get { return _solidBackColor; }
+ set { _solidBackColor = value; }
+ }
+ #endregion Properties
+
+ protected override void DrawInternal(Graphics g, Rectangle rect)
+ {
+ if (_drawSolidBack)
+ {
+ SolidBrush backBrush = new SolidBrush(_solidBackColor);
+ g.FillRectangle(backBrush, rect);
+ backBrush.Dispose();
+ }
+
+ SolidBrush solidBrush = new SolidBrush(Color);
+ Pen pen = new Pen(_foreColor);
+ pen.Width = _penWidth;
+ DrawingUtils.RoundRect(g, pen, solidBrush, rect.X, rect.Y, rect.Right, rect.Bottom,
+ _roundedCornerWidth, _roundedCornerHeight);
+ pen.Dispose();
+ solidBrush.Dispose();
+ }
+ }
+}
Added: Trunk/Source/Roam.UI/Drawing/FillSimpleLinearGradient.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/FillSimpleLinearGradient.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/FillSimpleLinearGradient.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -0,0 +1,46 @@
+#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;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class FillSimpleLinearGradient : Fill
+ {
+ private SimpleLinearGradient _gradient;
+ public FillSimpleLinearGradient(SimpleLinearGradient gradient) : this(gradient, 0) { }
+ public FillSimpleLinearGradient(SimpleLinearGradient gradient, float alphaBlend)
+ : base(alphaBlend)
+ {
+ _gradient = gradient;
+ }
+
+ public SimpleLinearGradient Gradient { get { return _gradient; } set { _gradient = value; } }
+
+ protected override void DrawInternal(Graphics g, Rectangle rect)
+ {
+ _gradient.Fill(g, rect);
+ }
+ }
+}
Added: Trunk/Source/Roam.UI/Drawing/FillSolid.cs
===================================================================
--- Trunk/Source/Roam.UI/Drawing/FillSolid.cs (rev 0)
+++ Trunk/Source/Roam.UI/Drawing/FillSolid.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -0,0 +1,41 @@
+#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;
+
+namespace Roam.UI.Drawing
+{
+ /// <summary>
+ ///
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ /// <author>Jon Froehlich</author>
+ public class FillSolid : Fill
+ {
+ public FillSolid(Color color) : this(color, 0) { }
+ public FillSolid(Color color, float alphaBlend) : base(alphaBlend, color) { }
+
+ protected override void DrawInternal(Graphics g, Rectangle rect)
+ {
+ SolidBrush solidBrush = new SolidBrush(Color);
+ g.FillRectangle(solidBrush, rect);
+ solidBrush.Dispose();
+ }
+ }
+}
Modified: Trunk/Source/Roam.UI/Roam.UI.csproj
===================================================================
--- Trunk/Source/Roam.UI/Roam.UI.csproj 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.UI/Roam.UI.csproj 2007-03-06 11:57:11 UTC (rev 63)
@@ -175,6 +175,11 @@
</Compile>
<Compile Include="Drawing\AngleGradient.cs" />
<Compile Include="Drawing\BitmapFactory.cs" />
+ <Compile Include="Drawing\FillImage.cs" />
+ <Compile Include="Drawing\FillNone.cs" />
+ <Compile Include="Drawing\FillRoundedRectangle.cs" />
+ <Compile Include="Drawing\FillSimpleLinearGradient.cs" />
+ <Compile Include="Drawing\FillSolid.cs" />
<Compile Include="Drawing\OrthogonalGradient.cs" />
<Compile Include="Drawing\Fill.cs" />
<Compile Include="Drawing\BitmapItem.cs" />
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-05 09:02:39 UTC (rev 62)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-06 11:57:11 UTC (rev 63)
@@ -192,6 +192,18 @@
return ret;
}
+ public static bool RoundRect(Graphics g, SolidBrush brush, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidth, int nHeight)
+ {
+ IntPtr hdc = g.GetHdc();
+ IntPtr hNewBrush = CreateSolidBrush(ColorUtils.ToRgb(brush.Color));
+ IntPtr hOldBrush = SelectObject(hdc, hNewBrush);
+ bool ret = RoundRect(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect, nWidth, nHeight);
+ SelectObject(hdc, hOldBrush);
+ DeleteObject(hNewBrush);
+ g.ReleaseHdc(hdc);
+ return ret;
+ }
+
public static bool RoundRect(Graphics g, Pen pen, SolidBrush brush, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidth, int nHeight)
{
IntPtr hdc = g.GetHdc();
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.
|
|
From: <jon...@us...> - 2007-03-05 09:02:45
|
Revision: 62
http://roam.svn.sourceforge.net/roam/?rev=62&view=rev
Author: jonfroehlich
Date: 2007-03-05 01:02:39 -0800 (Mon, 05 Mar 2007)
Log Message:
-----------
1. Removed FileUtils from Roam.Common (this class is in the Roam.csproj now under StorageCardUtils)
2. Cleaned up Roam.Common so that it no longer relies on OpenNETCF
3. Added some helper methods to FontUtils and DrawingUtils
Modified Paths:
--------------
Trunk/Source/Roam.Common/Roam.Common.csproj
Trunk/Source/Roam.Common/Utils/FontUtils.cs
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Removed Paths:
-------------
Trunk/Source/Roam.Common/Utils/FileUtils.cs
Modified: Trunk/Source/Roam.Common/Roam.Common.csproj
===================================================================
--- Trunk/Source/Roam.Common/Roam.Common.csproj 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.Common/Roam.Common.csproj 2007-03-05 09:02:39 UTC (rev 62)
@@ -49,7 +49,6 @@
<HintPath>..\..\Library\Release\log4net.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
- <Reference Include="OpenNETCF, Version=2.0.0.0, Culture=neutral, PublicKeyToken=e60dbea84bb431b7, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
@@ -85,7 +84,6 @@
<Compile Include="Utils\BufferAppender.cs" />
<Compile Include="Utils\CollectionUtils.cs" />
<Compile Include="Utils\ColorUtils.cs" />
- <Compile Include="Utils\FileUtils.cs" />
<Compile Include="Utils\FontUtils.cs" />
<Compile Include="Utils\GraphicsUtils.cs" />
<Compile Include="Utils\IFilter.cs" />
Deleted: Trunk/Source/Roam.Common/Utils/FileUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/FileUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.Common/Utils/FileUtils.cs 2007-03-05 09:02:39 UTC (rev 62)
@@ -1,117 +0,0 @@
-#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 OpenNETCF.Runtime.InteropServices.ComTypes;
-using System.Runtime.InteropServices;
-using Roam.Common;
-
-namespace Roam.Common.Utils
-{
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public static class FileUtils
- {
- public const int MAX_PATH = 260;
-
- //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/apisp/html/sp__wcesdk_findfirstflashcard.asp
- //HANDLE FindFirstFlashCard(
- // LPWIN32_FIND_DATA lpFindFlashData
- //);
- [DllImport("note_prj.dll")]
- public static extern IntPtr FindFirstFlashCard(out Win32FindData findData);
-
- //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcedata5/html/wce50lrfWIN32FINDDATA.asp
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- //typedef struct _WIN32_FIND_DATA {
- // DWORD dwFileAttributes;
- // FILETIME ftCreationTime;
- // FILETIME ftLastAccessTime;
- // FILETIME ftLastWriteTime;
- // DWORD nFileSizeHigh;
- // DWORD nFileSizeLow;
- // DWORD dwOID;
- // TCHAR cFileName[MAX_PATH];
- //} WIN32_FIND_DATA;
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- /// <summary>
- ///
- /// </summary>
- /// <remarks>
- ///
- /// </remarks>
- /// <author>Jon Froehlich</author>
- public struct Win32FindData
- {
- public uint dwFileAttributes;
- public FILETIME ftCreationTime;
- public FILETIME ftLastAccessTime;
- public FILETIME ftLastWriteTime;
- public uint nFileSizeHigh;
- public uint nFileSizeLow;
- public uint dwOID;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH)]
- public string cFileName;
- }
-
- //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcedata5/html/wce50lrffindclose.asp
- //BOOL FindClose(
- // HANDLE hFindFile
- //);
- [DllImport("coredll.dll")]
- public static extern bool FindClose(IntPtr hFindFile);
-
- public static String GetFirstFlashCardPath()
- {
- Win32FindData win32FindData;
- IntPtr intPtr = FindFirstFlashCard(out win32FindData);
- String path = win32FindData.cFileName;
- FindClose(intPtr);
-
- if (String.IsNullOrEmpty(path))
- {
- throw new ResourceNotFoundException("Could not find a flash card on this device");
- }
-
- return path;
- }
-
- public static bool FlashCardExists()
- {
- try
- {
- string flashCardPath = GetFirstFlashCardPath();
- return !String.IsNullOrEmpty(flashCardPath);
- }
- catch (ResourceNotFoundException rnfe)
- {
- return false;
- }
- }
-
- }
-}
Modified: Trunk/Source/Roam.Common/Utils/FontUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-03-05 09:02:39 UTC (rev 62)
@@ -46,6 +46,21 @@
}
}
+ public static Font GetFont(string fontName, Font defaultFont)
+ {
+ return GetFont(fontName, defaultFont.Size, defaultFont.Style, defaultFont);
+ }
+
+ public static Font GetFont(float fontSize, Font defaultFont)
+ {
+ return GetFont(defaultFont.Name, fontSize, defaultFont.Style, defaultFont);
+ }
+
+ public static Font GetFont(FontStyle fontStyle, Font defaultFont)
+ {
+ return GetFont(defaultFont.Name, defaultFont.Size, fontStyle, defaultFont);
+ }
+
public static FontFamily GetFontFamily(string fontFamily)
{
switch (fontFamily)
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-05 09:02:39 UTC (rev 62)
@@ -438,7 +438,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>
@@ -576,7 +576,7 @@
<DependentUpon>SystemColorTest.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\TabControlTest.cs">
- <SubType>Component</SubType>
+ <SubType>Form</SubType>
</Compile>
<Compile Include="UI\Controls\TabControlTest.Designer.cs">
<DependentUpon>TabControlTest.cs</DependentUpon>
Modified: Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs
===================================================================
--- Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.UI/Controls/ScrollableLabel.cs 2007-03-05 09:02:39 UTC (rev 62)
@@ -23,6 +23,7 @@
using Roam.Common.Collections;
using Roam.UI.Drawing;
using Roam.Common.Utils;
+using Roam.UI.Utils;
namespace Roam.UI.Controls
{
@@ -58,7 +59,12 @@
private Fill _backFill = new FillSimpleLinearGradient(new SimpleLinearGradient(Color.FromArgb(206, 223, 239), Color.White, SimpleLinearGradient.FillDirection.TopToBottom));
#endregion Private Fields
- public ScrollableLabel()
+ public ScrollableLabel()
+ : this(String.Empty)
+ {
+ }
+
+ public ScrollableLabel(string text)
{
_vScrollBar = new VScrollBar();
_vScrollBar.ValueChanged += new EventHandler(OnVerticalScrollbarValueChanged);
@@ -66,6 +72,7 @@
this.Controls.Add(_vScrollBar);
InitializeComponent();
OnResize(EventArgs.Empty);
+ Text = text;
}
#region Properties
@@ -534,6 +541,12 @@
RectangleF drawStringArea = new RectangleF(xPos + _textPadding, yPos, width - 2 * _textPadding, _textBounds.Height);
g.DrawString(str, this.Font, frontBrush, drawStringArea);
+ //debug - draw an outline in red
+ //Pen redPen = new Pen(Color.Red);
+ //g.DrawRectangle(redPen, DrawingUtils.GetRectangle(drawStringArea));
+ //redPen.Dispose();
+ //end debug
+
//cleanup
backBrush.Dispose();
frontBrush.Dispose();
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-05 09:02:39 UTC (rev 62)
@@ -18,6 +18,7 @@
using System.Drawing;
using System.Runtime.InteropServices;
using Roam.Common.Utils;
+using System.Windows.Forms;
namespace Roam.UI.Utils
{
@@ -290,6 +291,24 @@
return ret == 0 ? false : true;
}
+ private static Control _control = new Control();
+ public static SizeF MeasureString(string s, Font font)
+ {
+ SizeF sizeText;
+ lock (_control)
+ {
+ Graphics g = _control.CreateGraphics();
+ sizeText = g.MeasureString(s, font);
+ g.Dispose();
+ }
+ return sizeText;
+ }
+
+ public static float GetHeight(Font font)
+ {
+ return MeasureString("Aghfy!q#'", font).Height;
+ }
+
public static string ToString(Size size)
{
return "[" + size.Width + ", " + size.Height + "]";
@@ -304,6 +323,11 @@
{
return "[" + r.X + ", " + r.Y + ", " + r.Width + ", " + r.Height + "]";
}
+
+ public static Rectangle GetRectangle(RectangleF drawStringArea)
+ {
+ return new Rectangle((int)drawStringArea.X, (int)drawStringArea.Y, (int)drawStringArea.Width, (int)drawStringArea.Height);
+ }
}
/// <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.
|
|
From: <jon...@us...> - 2007-03-04 09:24:35
|
Revision: 61
http://roam.svn.sourceforge.net/roam/?rev=61&view=rev
Author: jonfroehlich
Date: 2007-03-04 01:24:32 -0800 (Sun, 04 Mar 2007)
Log Message:
-----------
1. added AddRange methods to HashSet
2. Added a non-generic version of ReverseComparer
3. Added EnumUtils--has one method which returns the value names in the enum
Modified Paths:
--------------
Trunk/Source/Roam/PocketOutlook/Sms.cs
Trunk/Source/Roam/Utils/DeviceUtils.cs
Trunk/Source/Roam.Common/Collections/HashSet.cs
Trunk/Source/Roam.Common/Collections/ReverseComparer.cs
Trunk/Source/Roam.Common/Roam.Common.csproj
Trunk/Source/Roam.Common/Utils/CollectionUtils.cs
Trunk/Source/Roam.Common/Utils/FontUtils.cs
Trunk/Source/Roam.Common/Utils/StringUtils.cs
Trunk/Source/Roam.Test/Roam.Test.csproj
Trunk/Source/Roam.Test/UI/Controls/FontTest.Designer.cs
Trunk/Source/Roam.Test/UI/Controls/FontTest.cs
Trunk/Source/Roam.UI/Controls/NumericTextBox.cs
Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
Trunk/Source/Roam.suo
Added Paths:
-----------
Trunk/Source/Roam.Common/Utils/EnumUtils.cs
Modified: Trunk/Source/Roam/PocketOutlook/Sms.cs
===================================================================
--- Trunk/Source/Roam/PocketOutlook/Sms.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam/PocketOutlook/Sms.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -425,7 +425,6 @@
return "The radio hardware is unavailable.";
default:
return "error code unknown.";
- break;
}
}
#endregion SMS Error
Modified: Trunk/Source/Roam/Utils/DeviceUtils.cs
===================================================================
--- Trunk/Source/Roam/Utils/DeviceUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam/Utils/DeviceUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -84,6 +84,7 @@
/// to be easily tested for correct overflow handling.
/// </summary>
/// <returns>The number of milliseconds indicates success.</returns>
+ [DllImport("coredll.dll")]
public extern static int GetTickCount();
Modified: Trunk/Source/Roam.Common/Collections/HashSet.cs
===================================================================
--- Trunk/Source/Roam.Common/Collections/HashSet.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Collections/HashSet.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -109,6 +109,36 @@
return true;
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="items"></param>
+ /// <returns>Returns the number of items added to the list</returns>
+ public int AddRange(T[] items)
+ {
+ int cnt = 0;
+ foreach (T t in items)
+ {
+ if (!Add(t)) { cnt++; }
+ }
+ return cnt;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="items"></param>
+ /// <returns>Returns the number of items added to the list</returns>
+ public int AddRange(ICollection<T> items)
+ {
+ int cnt = 0;
+ foreach (T t in items)
+ {
+ if (!Add(t)) { cnt++; }
+ }
+ return cnt;
+ }
+
public void Clear()
{
_dictionary.Clear();
Modified: Trunk/Source/Roam.Common/Collections/ReverseComparer.cs
===================================================================
--- Trunk/Source/Roam.Common/Collections/ReverseComparer.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Collections/ReverseComparer.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -49,4 +49,23 @@
return Compare((T)x, (T)y);
}
}
+
+ public class ReverseComparer : IComparer
+ {
+ private IComparer _comparer;
+
+ public ReverseComparer(IComparer comparer)
+ {
+ if (comparer == null)
+ {
+ throw new ArgumentNullException("comparer");
+ }
+ _comparer = comparer;
+ }
+
+ public int Compare(object x, object y)
+ {
+ return _comparer.Compare(y, x);
+ }
+ }
}
Modified: Trunk/Source/Roam.Common/Roam.Common.csproj
===================================================================
--- Trunk/Source/Roam.Common/Roam.Common.csproj 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Roam.Common.csproj 2007-03-04 09:24:32 UTC (rev 61)
@@ -75,6 +75,7 @@
<Compile Include="Collections\WalkUpTreeBranchEnumerator.cs" />
<Compile Include="Collections\WalkUpTreeBranch.cs" />
<Compile Include="Utils\DebugWriteAppender.cs" />
+ <Compile Include="Utils\EnumUtils.cs" />
<Compile Include="Utils\ErrorUtils.cs" />
<Compile Include="Utils\ImagingUtils.cs" />
<Compile Include="Utils\Vector2.cs" />
Modified: Trunk/Source/Roam.Common/Utils/CollectionUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/CollectionUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/CollectionUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -113,7 +113,6 @@
public static string ToString<T, S>(Dictionary<T, S> dict)
{
- int i = 0;
StringBuilder sb = new StringBuilder();
foreach (T key in dict.Keys)
{
Added: Trunk/Source/Roam.Common/Utils/EnumUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/EnumUtils.cs (rev 0)
+++ Trunk/Source/Roam.Common/Utils/EnumUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Reflection;
+
+namespace Roam.Common.Utils
+{
+ public static class EnumUtils
+ {
+ public static string[] GetNames(Type t)
+ {
+ List<string> l = new List<string>();
+ foreach (FieldInfo fi in t.GetFields())
+ {
+ if (fi.Name != "value__")
+ {
+ l.Add(fi.Name);
+ }
+ }
+ return l.ToArray();
+ }
+ }
+}
Modified: Trunk/Source/Roam.Common/Utils/FontUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/FontUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -45,5 +45,20 @@
return defaultFont;
}
}
- }
+
+ public static FontFamily GetFontFamily(string fontFamily)
+ {
+ switch (fontFamily)
+ {
+ case "GenericSansSerif":
+ return FontFamily.GenericSansSerif;
+ case "GenericMonospace":
+ return FontFamily.GenericMonospace;
+ case "GenericSerif":
+ return FontFamily.GenericSerif;
+ default:
+ throw new ArgumentException("The FontFamliy " + fontFamily + " was not found. ", "fontFamily");
+ }
+ }
+ }
}
Modified: Trunk/Source/Roam.Common/Utils/StringUtils.cs
===================================================================
--- Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Common/Utils/StringUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -15,6 +15,7 @@
using System;
using System.Text;
using System.Collections;
+using System.Collections.Generic;
namespace Roam.Common.Utils
{
@@ -43,5 +44,21 @@
string str = new string(chars);
return str.Trim(new char[] { '\0' });
}
+
+ public static string [] ParseWords(string s)
+ {
+ char[] whitespace = new char[] { ' ', '\t', '\r', '\n' };
+ string [] words = s.Split(whitespace);
+ List<string> list = new List<string>();
+ foreach (string w in words)
+ {
+ string wTrim = w.Trim();
+ if (wTrim.Length > 0)
+ {
+ list.Add(wTrim);
+ }
+ }
+ return list.ToArray();
+ }
}
}
Modified: Trunk/Source/Roam.Test/Roam.Test.csproj
===================================================================
--- Trunk/Source/Roam.Test/Roam.Test.csproj 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Test/Roam.Test.csproj 2007-03-04 09:24:32 UTC (rev 61)
@@ -576,7 +576,7 @@
<DependentUpon>SystemColorTest.cs</DependentUpon>
</Compile>
<Compile Include="UI\Controls\TabControlTest.cs">
- <SubType>Form</SubType>
+ <SubType>Component</SubType>
</Compile>
<Compile Include="UI\Controls\TabControlTest.Designer.cs">
<DependentUpon>TabControlTest.cs</DependentUpon>
Modified: Trunk/Source/Roam.Test/UI/Controls/FontTest.Designer.cs
===================================================================
(Binary files differ)
Modified: Trunk/Source/Roam.Test/UI/Controls/FontTest.cs
===================================================================
--- Trunk/Source/Roam.Test/UI/Controls/FontTest.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.Test/UI/Controls/FontTest.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -19,6 +19,8 @@
using System.Drawing;
using System.Text;
using System.Windows.Forms;
+using System.Reflection;
+using Roam.Common.Utils;
namespace Roam.Test.UI.Controls
{
@@ -34,6 +36,93 @@
public FontTest()
{
InitializeComponent();
+ _textBoxFontSize.TextChanged += new EventHandler(OnTextBoxFontSizeChanged);
+ _comboBoxFontFamily.SelectedValueChanged += new EventHandler(OnComboBoxFontFamilySelectedValueChanged);
+ _comboBoxFontStyle.SelectedValueChanged += new EventHandler(OnComboBoxFontStyleSelectedValueChanged);
+ _comboBoxFontName.SelectedValueChanged += new EventHandler(OnComboBoxFontNameSelectedValueChanged);
+ _textBox.TextChanged += new EventHandler(OnTextBoxTextChanged);
+
+ foreach(string s in EnumUtils.GetNames(typeof(FontStyle)))
+ {
+ _comboBoxFontStyle.Items.Add(s);
+ }
+
+ _comboBoxFontName.Items.Add(this.Font.Name);
+ _comboBoxFontName.SelectedItem = this.Font.Name;
+ _comboBoxFontFamily.Items.Add("GenericSansSerif");
+ _comboBoxFontFamily.Items.Add("GenericMonospace");
+ _comboBoxFontFamily.Items.Add("GenericSerif");
+
+ _fontTestControl.Text = "This is example text.";
+ _fontTestControl.TabStop = false;
+
+ _textBoxFontSize.Text = _fontTestControl.Font.Size.ToString();
+ //_comboBoxFontFamily.SelectedItem = new FontFamily();
}
+
+ void MeasureTextbox()
+ {
+ Graphics g = _fontTestControl.CreateGraphics();
+ SizeF textSize = g.MeasureString(_fontTestControl.Text, _fontTestControl.Font);
+ _labelStringMetrics.Text = string.Format("[{0:#.#}, {1:#.#}]", textSize.Width, textSize.Height);
+ g.Dispose();
+ }
+
+ void OnComboBoxFontNameSelectedValueChanged(object sender, EventArgs e)
+ {
+
+ }
+
+ void OnComboBoxFontStyleSelectedValueChanged(object sender, EventArgs e)
+ {
+ FontStyle fs = (FontStyle)Enum.Parse(typeof(FontStyle), _comboBoxFontStyle.Text, true);
+ _fontTestControl.Font = FontUtils.GetFont(_fontTestControl.Font.Name, _fontTestControl.Font.Size, fs, _fontTestControl.Font);
+ MeasureTextbox();
+ }
+
+ void OnComboBoxFontFamilySelectedValueChanged(object sender, EventArgs e)
+ {
+ FontFamily fontFamily = FontUtils.GetFontFamily(_comboBoxFontFamily.SelectedItem.ToString());
+ _fontTestControl.Font = new Font(FontUtils.GetFontFamily(_comboBoxFontFamily.Text),
+ _fontTestControl.Font.Size, _fontTestControl.Font.Style);
+ MeasureTextbox();
+ }
+
+ void OnTextBoxTextChanged(object sender, EventArgs e)
+ {
+ _fontTestControl.Text = _textBox.Text;
+ MeasureTextbox();
+ }
+
+ void OnTextBoxFontSizeChanged(object sender, EventArgs e)
+ {
+ if (_textBoxFontSize.TextAsInt > 0)
+ {
+ _fontTestControl.Font = FontUtils.GetFont(_fontTestControl.Font.Name,
+ _textBoxFontSize.TextAsInt, _fontTestControl.Font.Style, _fontTestControl.Font);
+ MeasureTextbox();
+ }
+ }
+
+ private void menuItem1_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void menuItem3_Click(object sender, EventArgs e)
+ {
+ this.Invalidate();
+ }
}
+
+ public class FontTestControl : Control
+ {
+ protected override void OnPaint(PaintEventArgs e)
+ {
+ SolidBrush solidBrush = new SolidBrush(this.ForeColor);
+ e.Graphics.DrawString(this.Text, this.Font, solidBrush, 0, 0);
+ solidBrush.Dispose();
+ base.OnPaint(e);
+ }
+ }
}
Modified: Trunk/Source/Roam.UI/Controls/NumericTextBox.cs
===================================================================
--- Trunk/Source/Roam.UI/Controls/NumericTextBox.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.UI/Controls/NumericTextBox.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -39,12 +39,12 @@
public virtual int TextAsInt
{
- get { return int.Parse(Text); }
+ get { return (Text.Length <= 0) ? 0 : int.Parse(Text); }
}
public virtual double TextAsFloat
{
- get { return float.Parse(Text); }
+ get { return (Text.Length <= 0) ? 0 : float.Parse(Text); }
}
public bool AcceptDecimal
Modified: Trunk/Source/Roam.UI/Utils/DrawingUtils.cs
===================================================================
--- Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-02-28 04:51:45 UTC (rev 60)
+++ Trunk/Source/Roam.UI/Utils/DrawingUtils.cs 2007-03-04 09:24:32 UTC (rev 61)
@@ -252,9 +252,10 @@
public static bool AlphaBlend(Image imageDest, Image imageSrc, float blend)
{
Graphics g = Graphics.FromImage(imageDest);
- return AlphaBlend(g, new Rectangle(0, 0, imageDest.Width, imageDest.Height),
+ bool b = AlphaBlend(g, new Rectangle(0, 0, imageDest.Width, imageDest.Height),
imageSrc, blend);
g.Dispose();
+ return b;
}
public static bool AlphaBlend(Graphics gxDest, Rectangle destRect, Image imageSrc, float blend)
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.
|