diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 32 | ||||
| -rwxr-xr-x | src/Size.cs | 38 |
2 files changed, 61 insertions, 9 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 72fccfba..0a402f12 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -47,6 +47,8 @@ namespace go protected bool _isVisible = true;
VerticalAlignment _verticalAlignment;
HorizontalAlignment _horizontalAlignment;
+ Size _maximumSize;
+ Size _minimumSize;
Picture _backgroundImage;
string _template;
@@ -264,7 +266,18 @@ namespace go registerForGraphicUpdate ();
}
}
+ [XmlAttributeAttribute()][DefaultValue("0;0")]
+ public Size MaximumSize {
+ get { return _maximumSize; }
+ set { _maximumSize = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue("0;0")]
+ public Size MinimumSize {
+ get { return _minimumSize; }
+ set { _minimumSize = value; }
+ }
#endregion
+
public string BackImgSub = null;
/// <summary>
@@ -307,6 +320,8 @@ namespace go pi.SetValue (this, Font.Parse ((string)dv.Value), null);
else if (pi.PropertyType == typeof(Picture))
pi.SetValue (this, Picture.Parse ((string)dv.Value), null);
+ else if (pi.PropertyType == typeof(Size))
+ pi.SetValue (this, Size.Parse ((string)dv.Value), null);
else
pi.SetValue (this, dv.Value, null);
continue;
@@ -354,7 +369,7 @@ namespace go TopContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot));
}
protected virtual Size measureRawSize ()
- {
+ {
return Bounds.Size;
}
@@ -489,6 +504,12 @@ namespace go else
Slot.Width = Parent.ClientRectangle.Width;
+ //size constrain
+ if (Slot.Width < MinimumSize.Width)
+ Slot.Width = MinimumSize.Width;
+ else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0)
+ Slot.Width = MaximumSize.Width;
+
if (LastSlots.Width == Slot.Width)
break;
@@ -506,6 +527,13 @@ namespace go else
Slot.Height = Parent.ClientRectangle.Height;
+ //size constrain
+ if (Slot.Height < MinimumSize.Height)
+ Slot.Height = MinimumSize.Height;
+ else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0)
+ Slot.Height = MaximumSize.Height;
+
+
if (LastSlots.Height == Slot.Height)
break;
@@ -728,6 +756,8 @@ namespace go pi.SetValue (this, Font.Parse ((string)defaultValue), null);
else if (pi.PropertyType == typeof(Picture))
pi.SetValue (this, Picture.Parse ((string)defaultValue), null);
+ else if (pi.PropertyType == typeof(Size))
+ pi.SetValue (this, Size.Parse ((string)defaultValue), null);
else
pi.SetValue (this, defaultValue, null);
} else {
diff --git a/src/Size.cs b/src/Size.cs index 72f8fff1..c2231576 100755 --- a/src/Size.cs +++ b/src/Size.cs @@ -9,16 +9,20 @@ namespace go {
public static Size Zero
{ get { return new Size(0, 0); } }
+
int _width;
int _height;
- //public Size()
- //{ }
public Size(int width, int height)
{
_width = width;
_height = height;
}
+ public Size(int size)
+ {
+ _width = size;
+ _height = size;
+ }
public int Width
{
get { return _width; }
@@ -29,10 +33,7 @@ namespace go get { return _height; }
set { _height = value; }
}
- public override string ToString()
- {
- return string.Format("({0},{1})", Width, Height);
- }
+ #region operators
public static implicit operator Rectangle(Size s)
{
return new Rectangle (s);
@@ -41,7 +42,15 @@ namespace go {
return new Size(i, i);
}
- public static bool operator ==(Size s1, Size s2)
+ public static implicit operator string(Size s)
+ {
+ return s.ToString ();
+ }
+ public static implicit operator Size(string s)
+ {
+ return string.IsNullOrEmpty (s) ? Size.Zero : Parse (s);
+ }
+ public static bool operator ==(Size s1, Size s2)
{
if (s1.Width == s2.Width && s1.Height == s2.Height)
return true;
@@ -118,6 +127,19 @@ namespace go {
return new Size(s.Width + i, s.Height + i);
}
- }
+ #endregion
+
+ public override string ToString()
+ {
+ return string.Format("{0},{1}", Width, Height);
+ }
+ public static Size Parse(string s)
+ {
+ string[] d = s.Split(new char[] { ';' });
+ return d.Length == 1 ? new Size(int.Parse(d[0])) : new Size(
+ int.Parse(d[0]),
+ int.Parse(d[1]));
+ }
+ }
}
|