diff options
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/AnalogMeter.cs | 41 | ||||
| -rw-r--r-- | src/GraphicObjects/Border.cs | 81 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/Button.cs | 286 | ||||
| -rwxr-xr-x | src/GraphicObjects/Checkbox.cs | 266 | ||||
| -rw-r--r-- | src/GraphicObjects/Container.cs | 80 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 86 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/GraduatedSlider.cs | 9 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/GraphicObject.cs | 323 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 68 | ||||
| -rw-r--r-- | src/GraphicObjects/GroupBox.cs | 134 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/HorizontalStack.cs | 0 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/Image.cs | 12 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/Label.cs | 129 | ||||
| -rw-r--r-- | src/GraphicObjects/NumericControl.cs | 28 | ||||
| -rw-r--r-- | src/GraphicObjects/ProgressBar.cs | 105 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/Slider.cs | 130 | ||||
| -rw-r--r-- | src/GraphicObjects/TextBox.cs | 146 | ||||
| -rwxr-xr-x[-rw-r--r--] | src/GraphicObjects/VerticalStack.cs | 0 |
19 files changed, 993 insertions, 939 deletions
diff --git a/src/GraphicObjects/AnalogMeter.cs b/src/GraphicObjects/AnalogMeter.cs new file mode 100644 index 00000000..5ef18090 --- /dev/null +++ b/src/GraphicObjects/AnalogMeter.cs @@ -0,0 +1,41 @@ +using System; +using System.Xml.Serialization; +using System.ComponentModel; +using Cairo; + +namespace go +{ + public class AnalogMeter : NumericControl + { + #region CTOR + public AnalogMeter() : base() + {} + public AnalogMeter(double minimum, double maximum, double step) + : base(minimum,maximum,step) + { + } + #endregion + + #region GraphicObject Overrides + protected override void onDraw (Context gr) + { + base.onDraw (gr); + + Rectangle r = ClientRectangle; + Point m = r.Center; + + double aUnit = Math.PI*2.0 / (Maximum - Minimum); + gr.Translate (m.X, m.Y); + gr.Rotate (Value * aUnit); + gr.Translate (-m.X, -m.Y); + + gr.LineWidth = 2; + gr.Color = Foreground; + gr.MoveTo (m); + gr.LineTo (m.X, 0); + gr.Stroke (); + } + #endregion + } +} + diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs new file mode 100644 index 00000000..281db215 --- /dev/null +++ b/src/GraphicObjects/Border.cs @@ -0,0 +1,81 @@ +using System; +using System.Xml.Serialization; +using System.ComponentModel; + +namespace go +{ + public class Border : Container + { + #region CTOR + public Border () : base(){} + #endregion + + #region private fields + Color _borderColor; + int _borderWidth; + #endregion + + #region public properties + [XmlAttributeAttribute()][DefaultValue(2)] + public virtual int BorderWidth { + get { return _borderWidth; } + set { + _borderWidth = value; + registerForGraphicUpdate (); + } + } + [XmlAttributeAttribute()][DefaultValue("White")] + public virtual Color BorderColor { + get { return _borderColor; } + set { + _borderColor = value; + registerForGraphicUpdate (); + } + } + #endregion + + #region GraphicObject override + [XmlIgnore]public override Rectangle ClientRectangle { + get { + Rectangle cb = base.ClientRectangle; + cb.Inflate (- BorderWidth); + return cb; + } + } + + protected override Size measureRawSize () + { + Size raw = Bounds.Size; + + if (child != null) { + if (Bounds.Width < 0 && child.WIsValid) + raw.Width = child.Slot.Width + 2 * (Margin+BorderWidth); + if (Bounds.Height < 0 && child.HIsValid) + raw.Height = child.Slot.Height + 2 * (Margin+BorderWidth); + } + + return raw; + } + protected override void onDraw (Cairo.Context gr) + { + Rectangle rBack = new Rectangle (Slot.Size); + + if (BorderWidth > 0) + rBack.Inflate (-BorderWidth / 2); + + gr.Color = Background; + CairoHelpers.CairoRectangle(gr,rBack,CornerRadius); + gr.Fill (); + + if (BorderWidth > 0) { + + gr.LineWidth = BorderWidth; + gr.Color = BorderColor; + CairoHelpers.CairoRectangle(gr,rBack,CornerRadius); + gr.Stroke (); + } + } + #endregion + } +} + diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index c426d51d..837b7012 100644..100755 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -1,266 +1,74 @@ using System;
-
-
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using OpenTK.Graphics.OpenGL;
-using Cairo;
-
-using winColors = System.Drawing.Color;
using System.Diagnostics;
+
using System.Xml.Serialization;
+using Cairo;
using OpenTK.Input;
+using System.ComponentModel;
namespace go
{
- public delegate void GOEvent(GraphicObject sender);
-
- public enum ButtonStates
- {
- normal,
- mouseOver,
- mouseDown,
- Disable
- }
-
public class Button : Container, IXmlSerializable
{
- public GOEvent Click;
-
- bool _isCheckable = false;
- bool _isChecked = false;
- bool _affectMultiSelectState = false;
- bool _border3D = false;
- Color _checkedColor;
- ButtonStates _CurrentState = ButtonStates.normal;
-
+ #region CTOR
public Button() : base()
- {}
+ {
+ MouseEnter += delegate { Background = Color.Lion;};
+ MouseLeave += delegate { Background = Color.Gray;};
+ MouseButtonDown += delegate { Background = Color.Red;};
+ MouseButtonUp += delegate { Background = Color.Gray;};
+ }
+ #endregion
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(true)]
+ #region GraphicObject Overrides
+ [XmlAttributeAttribute()][DefaultValue(60)]
+ public override int Width {
+ get { return base.Width; }
+ set { base.Width = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(30)]
+ public override int Height {
+ get { return base.Height; }
+ set { base.Height = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue("Gray")]
+ public virtual Color Background {
+ get { return base.Background; }
+ set { base.Background = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(true)]
public override bool Focusable
{
get { return base.Focusable; }
set { base.Focusable = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- public Color CheckedColor
- {
- get { return _checkedColor; }
- set
- {
- _checkedColor = value;
- registerForGraphicUpdate();
- }
- }
-
- [System.Xml.Serialization.XmlIgnore]
- public ButtonStates CurrentState
- {
- get { return _CurrentState; }
- set
- {
- if (value == _CurrentState)
- return;
- _CurrentState = value;
- registerForRedraw();
- }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
- public bool IsChecked
- {
- get { return _isChecked; }
- set
- {
- if (value == _isChecked)
- return;
-
- _isChecked = value;
-
- if (Click != null)
- Click(this);
-
- registerForGraphicUpdate();
- }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
- public bool IsCheckable
- {
- get { return _isCheckable; }
- set { _isCheckable = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
- public bool AffectMultiSelectState
- {
- get { return _affectMultiSelectState; }
- set { _affectMultiSelectState = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
- public bool Border3d
- {
- get { return _border3D; }
- set { _border3D = value; }
- }
-
- public override void Paint(ref Context ctx, Rectangles clip = null)
- {
- base.Paint(ref ctx, clip);
-
- Rectangle r = Parent.ContextCoordinates (Slot);
-
- ctx.Save();
- //ctx.ResetClip();
-
- if (IsCheckable){
- if (IsChecked){
- ctx.Color = CheckedColor;
- ctx.Rectangle(r);
- ctx.Fill();
-
- if (Border3d)
- CairoHelpers.StrokeLoweredRectangle(ctx, r);
- }
- else{
- if (Border3d)
- CairoHelpers.StrokeRaisedRectangle(ctx, r);
- }
- }
-
- switch (CurrentState){
- case ButtonStates.normal:
- break;
- case ButtonStates.mouseOver:
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
- ctx.Operator = Operator.Add;
- ctx.Color = new Color(0.2, 0.2, 0.2, 1.0);
- ctx.Fill();
- ctx.Operator = Operator.Over;
- break;
- case ButtonStates.mouseDown:
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
- ctx.Operator = Operator.Add;
- ctx.Color = Color.Red;
- ctx.Fill();
- ctx.Operator = Operator.Over;
- break;
- case ButtonStates.Disable:
- CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
- ctx.Color = new Color(0.2, 0.2, 0.2, 0.7);
- ctx.Fill();
- break;
-
- }
- ctx.Restore();
- }
+ }
+ #endregion
- #region mouse handling
- public override void onMouseButtonDown (object sender,MouseButtonEventArgs e)
- {
- if (CurrentState != ButtonStates.Disable)
- {
- if (IsCheckable)
- {
- if (IsChecked)
- IsChecked = false;
- else
- {
- Group wg = Parent as Group;
- if (wg != null)
- {
- if (AffectMultiSelectState && !wg.MultiSelect)
- {
- foreach (Button but in wg.Children.OfType<Button>())
- {
- if (but.IsCheckable)
- {
- if (but.IsChecked && but.AffectMultiSelectState)
- {
- but.IsChecked = false;
- break;
- }
- }
- }
- }
- }
- IsChecked = true;
- }
- }
- //else if (Click != null)
- // Click(this);
-
- CurrentState = ButtonStates.mouseDown;
- }
-
- base.onMouseButtonDown (sender, e);
- }
- public override void onMouseButtonUp (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ [XmlAttributeAttribute][DefaultValue("Button")]
+ public string Text
{
- if (CurrentState != ButtonStates.Disable) {
- if (MouseIsIn (e.Position))
- CurrentState = ButtonStates.mouseOver;
+ get {
+ Label l = child as Label;
+ return l == null ? "" : l.Text;
+ }
+ set
+ {
+ Label l = child as Label;
+ if (l == null)
+ this.setChild(new Label (value)
+ {
+ TextAlignment = Alignment.Center,
+ Foreground = Color.Black
+ });
else
- CurrentState = ButtonStates.normal;
-
+ l.Text = value;
}
-
- base.onMouseButtonUp (sender, e);
- }
- public override void onMouseEnter (object sender, MouseMoveEventArgs e)
- {
- if (CurrentState == ButtonStates.normal)
- CurrentState = ButtonStates.mouseOver;
-
- base.onMouseEnter (sender, e);
- }
- public override void onMouseLeave (object sender, MouseMoveEventArgs e)
- {
- if (CurrentState == ButtonStates.mouseOver)
- CurrentState = ButtonStates.normal;
-
- base.onMouseLeave (sender, e);
- }
- #endregion
-
- #region IXmlSerializable
- public override System.Xml.Schema.XmlSchema GetSchema()
- {
- return null;
- }
- public override void ReadXml(System.Xml.XmlReader reader)
- {
- string handler = reader.GetAttribute("OnClick");
- GraphicObject.EventsToResolve.Add(new EventSource
- {
- Source = this,
- Handler = handler,
- EventName = "OnClick"
- });
-
- //Container c = this as Container;
- base.ReadXml(reader);
- }
- public override void WriteXml(System.Xml.XmlWriter writer)
- {
- if (Click != null)
- {
- writer.WriteAttributeString("OnClick", Click.Method.Name);
- }
-
- base.WriteXml(writer);
- }
- #endregion
+ }
}
}
diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs new file mode 100755 index 00000000..68704127 --- /dev/null +++ b/src/GraphicObjects/Checkbox.cs @@ -0,0 +1,266 @@ +using System;
+
+
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+//using OpenTK.Graphics.OpenGL;
+
+using Cairo;
+
+using winColors = System.Drawing.Color;
+using System.Diagnostics;
+using System.Xml.Serialization;
+using OpenTK.Input;
+
+namespace go
+{
+ public delegate void GOEvent(GraphicObject sender);
+
+ public enum ButtonStates
+ {
+ normal,
+ mouseOver,
+ mouseDown,
+ Disable
+ }
+
+ public class Checkbox : Container, IXmlSerializable
+ {
+ public GOEvent Click;
+
+ bool _isCheckable = false;
+ bool _isChecked = false;
+ bool _affectMultiSelectState = false;
+ bool _border3D = false;
+ Color _checkedColor;
+ ButtonStates _CurrentState = ButtonStates.normal;
+
+ public Checkbox() : base()
+ {}
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ [System.ComponentModel.DefaultValue(true)]
+ public override bool Focusable
+ {
+ get { return base.Focusable; }
+ set { base.Focusable = value; }
+ }
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ public Color CheckedColor
+ {
+ get { return _checkedColor; }
+ set
+ {
+ _checkedColor = value;
+ registerForGraphicUpdate();
+ }
+ }
+
+ [System.Xml.Serialization.XmlIgnore]
+ public ButtonStates CurrentState
+ {
+ get { return _CurrentState; }
+ set
+ {
+ if (value == _CurrentState)
+ return;
+ _CurrentState = value;
+ registerForRedraw();
+ }
+ }
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ [System.ComponentModel.DefaultValue(false)]
+ public bool IsChecked
+ {
+ get { return _isChecked; }
+ set
+ {
+ if (value == _isChecked)
+ return;
+
+ _isChecked = value;
+
+ if (Click != null)
+ Click(this);
+
+ registerForGraphicUpdate();
+ }
+ }
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ [System.ComponentModel.DefaultValue(false)]
+ public bool IsCheckable
+ {
+ get { return _isCheckable; }
+ set { _isCheckable = value; }
+ }
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ [System.ComponentModel.DefaultValue(false)]
+ public bool AffectMultiSelectState
+ {
+ get { return _affectMultiSelectState; }
+ set { _affectMultiSelectState = value; }
+ }
+
+ [System.Xml.Serialization.XmlAttributeAttribute()]
+ [System.ComponentModel.DefaultValue(false)]
+ public bool Border3d
+ {
+ get { return _border3D; }
+ set { _border3D = value; }
+ }
+
+ public override void Paint(ref Context ctx, Rectangles clip = null)
+ {
+ base.Paint(ref ctx, clip);
+
+ Rectangle r = Parent.ContextCoordinates (Slot);
+
+ ctx.Save();
+ //ctx.ResetClip();
+
+ if (IsCheckable){
+ if (IsChecked){
+ ctx.Color = CheckedColor;
+ ctx.Rectangle(r);
+ ctx.Fill();
+
+ if (Border3d)
+ CairoHelpers.StrokeLoweredRectangle(ctx, r);
+ }
+ else{
+ if (Border3d)
+ CairoHelpers.StrokeRaisedRectangle(ctx, r);
+ }
+ }
+
+ switch (CurrentState){
+ case ButtonStates.normal:
+ break;
+ case ButtonStates.mouseOver:
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
+ ctx.Operator = Operator.Add;
+ ctx.Color = new Color(0.2, 0.2, 0.2, 1.0);
+ ctx.Fill();
+ ctx.Operator = Operator.Over;
+ break;
+ case ButtonStates.mouseDown:
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
+ ctx.Operator = Operator.Add;
+ ctx.Color = Color.Red;
+ ctx.Fill();
+ ctx.Operator = Operator.Over;
+ break;
+ case ButtonStates.Disable:
+ CairoHelpers.CairoRectangle(ctx,r,CornerRadius);
+ ctx.Color = new Color(0.2, 0.2, 0.2, 0.7);
+ ctx.Fill();
+ break;
+
+ }
+ ctx.Restore();
+ }
+
+
+ #region mouse handling
+ public override void onMouseButtonDown (object sender,MouseButtonEventArgs e)
+ {
+ if (CurrentState != ButtonStates.Disable)
+ {
+ if (IsCheckable)
+ {
+ if (IsChecked)
+ IsChecked = false;
+ else
+ {
+ Group wg = Parent as Group;
+ if (wg != null)
+ {
+ if (AffectMultiSelectState && !wg.MultiSelect)
+ {
+ foreach (Checkbox but in wg.Children.OfType<Checkbox>())
+ {
+ if (but.IsCheckable)
+ {
+ if (but.IsChecked && but.AffectMultiSelectState)
+ {
+ but.IsChecked = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ IsChecked = true;
+ }
+ }
+ //else if (Click != null)
+ // Click(this);
+
+ CurrentState = ButtonStates.mouseDown;
+ }
+
+ base.onMouseButtonDown (sender, e);
+ }
+ public override void onMouseButtonUp (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ {
+ if (CurrentState != ButtonStates.Disable) {
+ if (MouseIsIn (e.Position))
+ CurrentState = ButtonStates.mouseOver;
+ else
+ CurrentState = ButtonStates.normal;
+
+ }
+
+ base.onMouseButtonUp (sender, e);
+ }
+ public override void onMouseEnter (object sender, MouseMoveEventArgs e)
+ {
+ if (CurrentState == ButtonStates.normal)
+ CurrentState = ButtonStates.mouseOver;
+
+ base.onMouseEnter (sender, e);
+ }
+ public override void onMouseLeave (object sender, MouseMoveEventArgs e)
+ {
+ if (CurrentState == ButtonStates.mouseOver)
+ CurrentState = ButtonStates.normal;
+
+ base.onMouseLeave (sender, e);
+ }
+ #endregion
+
+ #region IXmlSerializable
+ public override System.Xml.Schema.XmlSchema GetSchema()
+ {
+ return null;
+ }
+ public override void ReadXml(System.Xml.XmlReader reader)
+ {
+ string handler = reader.GetAttribute("OnClick");
+ GraphicObject.EventsToResolve.Add(new EventSource
+ {
+ Source = this,
+ Handler = handler,
+ EventName = "OnClick"
+ });
+
+ //Container c = this as Container;
+ base.ReadXml(reader);
+ }
+ public override void WriteXml(System.Xml.XmlWriter writer)
+ {
+ if (Click != null)
+ {
+ writer.WriteAttributeString("OnClick", Click.Method.Name);
+ }
+
+ base.WriteXml(writer);
+ }
+ #endregion
+ }
+}
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs index ef843cbc..67d9e6ff 100644 --- a/src/GraphicObjects/Container.cs +++ b/src/GraphicObjects/Container.cs @@ -7,16 +7,18 @@ namespace go {
public class Container : GraphicObject, IXmlSerializable
{
- public GraphicObject child;
+ #region CTOR
+ public Container()
+ : base()
+ {
+ }
+ public Container(Rectangle _bounds)
+ : base(_bounds)
+ {
+ }
+ #endregion
- public Container()
- : base()
- {
- }
- public Container(Rectangle _bounds)
- : base(_bounds)
- {
- }
+ public GraphicObject child;
public T setChild<T>(T _child)
{
@@ -31,6 +33,22 @@ namespace go return (T)_child;
}
+
+ #region GraphicObject Overrides
+ [XmlIgnore]public override bool LayoutIsValid
+ {
+ get
+ {
+ if (!Visible)
+ return true;
+
+ return !base.LayoutIsValid || child == null ?
+ base.LayoutIsValid :
+ child.LayoutIsValid;
+ }
+ set { base.LayoutIsValid = value; }
+ }
+
public override GraphicObject FindByName (string nameToFind)
{
if (Name == nameToFind)
@@ -45,28 +63,15 @@ namespace go if (child != null)
child.InvalidateLayout();
}
- public override bool LayoutIsValid
- {
- get
- {
- if (!Visible)
- return true;
-
- return !base.LayoutIsValid || child == null ?
- base.LayoutIsValid :
- child.LayoutIsValid;
- }
- set { base.LayoutIsValid = value; }
- }
- public override Size measureRawSize ()
+ protected override Size measureRawSize ()
{
Size raw = Bounds.Size;
if (child != null) {
if (Bounds.Width < 0 && child.WIsValid)
- raw.Width = child.Width + 2 * (Margin + BorderWidth);
+ raw.Width = child.Slot.Width + 2 * (Margin);
if (Bounds.Height < 0 && child.HIsValid)
- raw.Height = child.Height + 2 * (Margin + BorderWidth);
+ raw.Height = child.Slot.Height + 2 * (Margin);
}
return raw;
@@ -88,36 +93,12 @@ namespace go {
if (!child.LayoutIsValid) {
child.UpdateLayout ();
-
- if (!WIsValid) {
- if (Width < 0 && child.WIsValid) {
- Slot.Width = child.Slot.Width + 2 * Margin + 2 * BorderWidth;
- WIsValid = true;
- }
- }
- if (!HIsValid) {
- if (Height < 0 && child.HIsValid) {
- Slot.Height = child.Slot.Height + 2 * Margin + 2 * BorderWidth;
- HIsValid = true;
- }
- }
}
}
if (LayoutIsValid)
registerForRedraw();
}
-// public override void onDraw (Cairo.Context gr)
-// {
-// base.onDraw (gr);
-//
-// if (child == null)
-// return;
-// if (!child.Visible)
-// return;
-//
-// child.Paint (ref gr);
-// }
public override Rectangle ContextCoordinates (Rectangle r)
{
return
@@ -151,6 +132,7 @@ namespace go ctx.Restore();
}
+ #endregion
#region Mouse handling
public override void onMouseMove (object sender, MouseMoveEventArgs e)
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 90e0d132..a36cd7b1 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -10,57 +10,56 @@ namespace go {
public class GenericStack : Group
{
- int currentXForWidget = 0;
- int currentYForWidget = 0;
- bool childrenArePositionned = false;
- int _widgetSpacing;
- Orientation _orientation;
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(-1)]
- public override int Width {
- get { return base.Width; }
- set { base.Width = value; }
+ #region CTOR
+ public GenericStack()
+ : base()
+ {
}
+ #endregion
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(-1)]
- public override int Height {
- get { return base.Height; }
- set { base.Height = value; }
- }
+ #region Private fields
+ bool childrenArePositionned = false;
+ int _spacing;
+ Orientation _orientation;
+ #endregion
- [XmlAttributeAttribute()]
- [DefaultValue(2)]
- public int WidgetSpacing
+ #region Public Properties
+ [XmlAttributeAttribute()][DefaultValue(2)]
+ public int Spacing
{
- get { return _widgetSpacing; }
- set { _widgetSpacing = value; }
+ get { return _spacing; }
+ set { _spacing = value; }
}
-
- [XmlAttributeAttribute()]
- [DefaultValue(Orientation.Horizontal)]
+ [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
public virtual Orientation Orientation
{
get { return _orientation; }
set { _orientation = value; }
}
+ #endregion
- public GenericStack()
- : base()
- {
- }
-
- public override bool LayoutIsValid {
+ #region GraphicObject Overrides
+ [XmlAttributeAttribute()][DefaultValue(-1)]
+ public override int Width {
+ get { return base.Width; }
+ set { base.Width = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(-1)]
+ public override int Height {
+ get { return base.Height; }
+ set { base.Height = value; }
+ }
+ [XmlIgnore]public override bool LayoutIsValid {
get { return childrenArePositionned && base.LayoutIsValid; }
set { base.LayoutIsValid = value; }
}
+
public override void InvalidateLayout ()
{
childrenArePositionned = false;
base.InvalidateLayout ();
}
- public override Size measureRawSize ()
+ protected override Size measureRawSize ()
{
Size raw = Bounds.Size;
Size tmp = new Size ();
@@ -72,7 +71,7 @@ namespace go if (raw.Width < 0) {
if (c.WIsValid) {
if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0)
- tmp.Width += c.Slot.Width + WidgetSpacing;
+ tmp.Width += c.Slot.Width + Spacing;
else
tmp.Width = Math.Max (tmp.Width, c.Slot.Right);
}else
@@ -81,7 +80,7 @@ namespace go if (raw.Height < 0) {
if (c.HIsValid) {
if (Orientation == Orientation.Vertical && c.Bounds.Height != 0)
- tmp.Height += c.Slot.Height + WidgetSpacing;
+ tmp.Height += c.Slot.Height + Spacing;
else
tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);
}else
@@ -90,9 +89,9 @@ namespace go }
if (raw.Width < 0)
- tmp.Width += 2*(BorderWidth+Margin);
+ tmp.Width += 2*Margin;
if (raw.Height < 0)
- tmp.Height += 2*(BorderWidth+Margin);
+ tmp.Height += 2*Margin;
return tmp;
}
@@ -106,7 +105,7 @@ namespace go c.Slot.X = d;
c.XIsValid = true;
- d += c.Slot.Width + WidgetSpacing;
+ d += c.Slot.Width + Spacing;
}
} else {
foreach (GraphicObject c in Children) {
@@ -115,7 +114,7 @@ namespace go c.Slot.Y = d;
c.YIsValid = true;
- d += c.Slot.Height + WidgetSpacing;
+ d += c.Slot.Height + Spacing;
}
}
childrenArePositionned = true;
@@ -130,7 +129,9 @@ namespace go if (LayoutIsValid)
registerForRedraw();
}
-//
+ #endregion
+
+ //
// bool enoughtSpaceForWidget(GraphicObject w)
// {
// if (!SizeToContent)
@@ -144,9 +145,9 @@ namespace go // nextYForWidget = nextYForWidget + w.Slot.Height;
//
//
-// if (nextXForWidget > clientBounds.Right )
+// if (nextXForWidget > ClientRectangle.Right )
// return false;
-// if (currentYForWidget > clientBounds.Bottom )
+// if (currentYForWidget > ClientRectangle.Bottom )
// return false;
// }
// return true;
@@ -159,5 +160,6 @@ namespace go // currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height;
//
// }
- }
+
+ }
}
diff --git a/src/GraphicObjects/GraduatedSlider.cs b/src/GraphicObjects/GraduatedSlider.cs index 9eb0ec7a..c3de8d11 100644..100755 --- a/src/GraphicObjects/GraduatedSlider.cs +++ b/src/GraphicObjects/GraduatedSlider.cs @@ -8,7 +8,8 @@ using System.Xml.Serialization; namespace go
{
public class GraduatedSlider : Slider
- {
+ {
+ #region CTOR
public GraduatedSlider() : base()
{}
public GraduatedSlider(double minimum, double maximum, double step)
@@ -19,9 +20,11 @@ namespace go SmallIncrement = step;
LargeIncrement = step * 5;
}
- public override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
+ #endregion
+
+ protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
{
- Rectangle r = clientBounds;
+ Rectangle r = ClientRectangle;
gr.Color = Foreground;
gr.LineWidth = 2;
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 06f52da3..ec3b7fef 100644..100755 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -19,15 +19,25 @@ namespace go {
public class GraphicObject : IXmlSerializable, ILayoutable
{
+ #region CTOR
+ public GraphicObject ()
+ {
+ loadDefaultValues ();
+ registerForGraphicUpdate ();
+ }
+ public GraphicObject (Rectangle _bounds)
+ {
+ loadDefaultValues ();
+ Bounds = _bounds;
+ registerForGraphicUpdate ();
+ }
+ #endregion
- #region private properties
-
+ #region private fields
ILayoutable _parent;
string _name;
Color _background;
Color _foreground;
- Color _borderColor;
- int _borderWidth;
double _cornerRadius;
int _margin;
bool _focusable = false;
@@ -40,59 +50,51 @@ namespace go bool wIsValid = false;
bool xIsValid = false;
bool yIsValid = false;
-
#endregion
+ #region public fields
public Rectangle Bounds;
public Rectangle Slot = new Rectangle ();
public object Tag;
public byte[] bmp;
+ #endregion
#region ILayoutable
-
- [System.Xml.Serialization.XmlIgnore]
- public ILayoutable Parent {
+ [XmlIgnore]public ILayoutable Parent {
get { return _parent; }
set { _parent = value; }
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool SizeIsValid {
+ [XmlIgnore]public virtual bool SizeIsValid {
get { return hIsValid & wIsValid; }
set {
hIsValid = value;
wIsValid = value;
}
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool WIsValid {
+ [XmlIgnore]public virtual bool WIsValid {
get { return wIsValid; }
set { wIsValid = value; }
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool HIsValid {
+ [XmlIgnore]public virtual bool HIsValid {
get { return hIsValid; }
set { hIsValid = value; }
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool XIsValid {
+ [XmlIgnore]public virtual bool XIsValid {
get { return xIsValid; }
set { xIsValid = value; }
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool YIsValid {
+ [XmlIgnore]public virtual bool YIsValid {
get { return yIsValid; }
set { yIsValid = value; }
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool PositionIsValid {
+ [XmlIgnore]public virtual bool PositionIsValid {
get { return xIsValid & yIsValid; }
set {
xIsValid = value;
yIsValid = value;
}
}
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool LayoutIsValid {
+ [XmlIgnore]public virtual bool LayoutIsValid {
get { return SizeIsValid & PositionIsValid; }
set {
if (value == SizeIsValid & PositionIsValid)
@@ -105,21 +107,19 @@ namespace go // Parent.layoutIsValid = false;
}
}
+ [XmlIgnore]public virtual Rectangle ClientRectangle {
+ get {
+ Rectangle cb = Slot.Size;
+ cb.Inflate ( - Margin);
+ return cb;
+ }
+ }
public virtual void InvalidateLayout ()
{
bmp = null;
LayoutIsValid = false;
}
-
- [System.Xml.Serialization.XmlIgnore]
- public virtual Rectangle ClientRectangle {
- get {
- Rectangle cb = Slot.Size;
- cb.Inflate ( - BorderWidth - Margin);
- return cb;
- }
- }
public virtual Rectangle ContextCoordinates(Rectangle r){
return
Parent.ContextCoordinates (r);// + ClientRectangle.Position;
@@ -130,14 +130,17 @@ namespace go return
Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;
}
+ public virtual Rectangle getSlot()
+ {
+ return Slot;
+ }
#endregion
- #region event handlers
-
+ #region EVENT HANDLERS
public event EventHandler<MouseWheelEventArgs> MouseWheelChanged = delegate { };
public event EventHandler<MouseButtonEventArgs> MouseButtonUp = delegate { };
public event EventHandler<MouseButtonEventArgs> MouseButtonDown = delegate { };
- public event EventHandler<MouseButtonEventArgs> MouseClicked = delegate { };
+ public event EventHandler<MouseButtonEventArgs> MouseClick = delegate { };
public event EventHandler<MouseMoveEventArgs> MouseMove = delegate { };
public event EventHandler<MouseMoveEventArgs> MouseEnter = delegate { };
public event EventHandler<MouseMoveEventArgs> MouseLeave = delegate { };
@@ -145,19 +148,15 @@ namespace go public event EventHandler<KeyboardKeyEventArgs> KeyUp = delegate { };
public event EventHandler Focused = delegate { };
public event EventHandler Unfocused = delegate { };
-
#endregion
#region public properties
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("unamed")]
+ [XmlAttributeAttribute()][DefaultValue("unamed")]
public virtual string Name {
get { return _name; }
set { _name = value; }
}
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(VerticalAlignment.Center)]
+ [XmlAttributeAttribute()][DefaultValue(VerticalAlignment.Center)]
public virtual VerticalAlignment VerticalAlignment {
get { return _verticalAlignment; }
set {
@@ -169,14 +168,12 @@ namespace go // if (Top > 0)
}
}
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(HorizontalAlignment.Center)]
+ [XmlAttributeAttribute()][DefaultValue(HorizontalAlignment.Center)]
public virtual HorizontalAlignment HorizontalAlignment {
get { return _horizontalAlignment; }
set { _horizontalAlignment = value; }
}
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Left {
get { return Bounds.X; }
set {
@@ -189,9 +186,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Top {
get { return Bounds.Y; }
set {
@@ -204,9 +199,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Width {
get { return Bounds.Width; }
set {
@@ -218,9 +211,7 @@ namespace go InvalidateLayout ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Height {
get { return Bounds.Height; }
set {
@@ -232,16 +223,23 @@ namespace go InvalidateLayout ();
}
}
+ [XmlAttributeAttribute()][DefaultValue(false)]
+ public virtual bool Fit {
+ get { return Bounds.Width < 0 && Bounds.Height < 0 ? true : false; }
+ set {
+ if (value == Fit)
+ return;
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
+ Bounds.Width = Bounds.Height = -1;
+ InvalidateLayout ();
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue(false)]
public virtual bool Focusable {
get { return _focusable; }
set { _focusable = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("Transparent")]
+ }
+ [XmlAttributeAttribute()][DefaultValue("Transparent")]
public virtual Color Background {
get { return _background; }
set {
@@ -249,9 +247,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("White")]
+ [XmlAttributeAttribute()][DefaultValue("White")]
public virtual Color Foreground {
get { return _foreground; }
set {
@@ -259,29 +255,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("White")]
- public virtual Color BorderColor {
- get { return _borderColor; }
- set {
- _borderColor = value;
- registerForGraphicUpdate ();
- }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
- public virtual int BorderWidth {
- get { return _borderWidth; }
- set {
- _borderWidth = value;
- registerForGraphicUpdate ();
- }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(5)]
+ [XmlAttributeAttribute()][DefaultValue(5)]
public virtual double CornerRadius {
get { return _cornerRadius; }
set {
@@ -289,9 +263,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ [XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Margin {
get { return _margin; }
set {
@@ -299,9 +271,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(true)]
+ [XmlAttributeAttribute()][DefaultValue(true)]
public virtual bool Visible {
get { return _isVisible; }
set {
@@ -315,59 +285,16 @@ namespace go // registerForRedraw();
}
}
- //should maybe test only focusedWidget in higher container (opentkwin for now)
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool HasFocus {
+ [XmlIgnore]public virtual bool HasFocus {
get { return _hasFocus; }
set { _hasFocus = value; }
}
-
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool isCached {
- get { return false; }
- }
-
- [System.Xml.Serialization.XmlIgnore]
- public virtual bool cachingInProgress {
- get { return false; }
- set { return; }
- }
-
- public virtual Rectangle clientBounds {
- get {
- Rectangle cb = Slot.Size;
- cb.Inflate (-(BorderWidth + Margin));
- return cb;
- }
- }
-
-
-
-
-
-
- public virtual Rectangle getSlot()
- {
- return Slot;
- }
- [XmlIgnore]
- public virtual bool DrawingIsValid
+ [XmlIgnore]public virtual bool DrawingIsValid
{ get { return bmp == null ?
false :
true; } }
#endregion
- public GraphicObject ()
- {
- loadDefaultValues ();
- registerForGraphicUpdate ();
- }
- public GraphicObject (Rectangle _bounds)
- {
- loadDefaultValues ();
- Bounds = _bounds;
- registerForGraphicUpdate ();
- }
/// <summary>
/// Loads the default values from XML attributes default
/// </summary>
@@ -404,6 +331,8 @@ namespace go if (dv != null) {
if (pi.PropertyType == typeof(Color))
pi.SetValue (this, Color.Parse ((string)dv.Value), null);
+ else if (pi.PropertyType == typeof(Font))
+ pi.SetValue (this, Font.Parse ((string)dv.Value), null);
else
pi.SetValue (this, dv.Value, null);
continue;
@@ -441,12 +370,12 @@ namespace go {
OpenTKGameWindow.redrawClip.AddRectangle (ScreenCoordinates(Slot));
}
- public virtual Size measureRawSize ()
+ protected virtual Size measureRawSize ()
{
return Bounds.Size;
}
- public virtual void ComputeSize()
+ protected virtual void ComputeSize()
{
Size rawSize = measureRawSize ();
@@ -480,7 +409,7 @@ namespace go hIsValid = false;
}
}
- public virtual void ComputePosition()
+ protected virtual void ComputePosition()
{
if (!xIsValid) {
xIsValid = true;
@@ -528,13 +457,6 @@ namespace go }
public virtual void UpdateLayout ()
{
-// if (LayoutIsValid)
-// return;
-//
- //should maybe invalidate drawing
-
- //Rectangle oldRenderBounds = Slot;
-
if (!SizeIsValid)
ComputeSize ();
if (!PositionIsValid)
@@ -543,27 +465,15 @@ namespace go registerForRedraw ();
}
- public virtual void onDraw(Context gr)
+ protected virtual void onDraw(Context gr)
{
Rectangle rBack = new Rectangle (Slot.Size);
- if (BorderWidth > 0)
- rBack.Inflate (-BorderWidth / 2);
-
gr.Color = Background;
CairoHelpers.CairoRectangle(gr,rBack,_cornerRadius);
gr.Fill ();
-
- if (BorderWidth > 0) {
-
- gr.LineWidth = BorderWidth;
- gr.Color = BorderColor;
- CairoHelpers.CairoRectangle(gr,rBack,_cornerRadius);
- gr.Stroke ();
- }
}
-
- internal virtual void UpdateGraphic ()
+ protected virtual void UpdateGraphic ()
{
int stride = 4 * Slot.Width;
@@ -579,8 +489,7 @@ namespace go draw.Flush ();
}
}
-
- //could maybe be internal
+
public virtual void Paint (ref Context ctx, Rectangles clip = null)
{
if (!Visible)
@@ -605,10 +514,9 @@ namespace go #endregion
#region Mouse handling
-
public virtual bool MouseIsIn(Point m)
{
- return Visible ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false;
+ return Visible & Focusable ? ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false;
}
public virtual void onMouseMove(object sender, MouseMoveEventArgs e)
{
@@ -618,53 +526,47 @@ namespace go w.hoverWidget = this;
onMouseEnter (sender, e);
}
-
- if (MouseMove != null)
- MouseMove (sender, e);
+
+ MouseMove (this, e);
}
public virtual void onMouseButtonUp(object sender, MouseButtonEventArgs e){
if (MouseIsIn (e.Position))
- onMouseClicked (sender, e);
- if (MouseButtonUp != null)
- MouseButtonUp (sender, e);
+ onMouseClick (sender, e);
+
+ MouseButtonUp (this, e);
}
public virtual void onMouseButtonDown(object sender, MouseButtonEventArgs e){
(sender as OpenTKGameWindow).FocusedWidget = this;
- if (MouseButtonDown!=null)
- MouseButtonDown (sender, e);
+
+ MouseButtonDown (this, e);
}
- public virtual void onMouseClicked(object sender, MouseButtonEventArgs e){
- if (MouseClicked!=null)
- MouseClicked(sender,e);
+ public virtual void onMouseClick(object sender, MouseButtonEventArgs e){
+ MouseClick(this,e);
}
public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){
GraphicObject p = Parent as GraphicObject;
if (p != null)
p.onMouseWheel(this,e);
-
- if (MouseWheelChanged!=null)
- MouseWheelChanged (this, e);
+
+ MouseWheelChanged (this, e);
}
public virtual void onFocused(object sender, EventArgs e){
- if (Focused!=null)
- Focused (sender, e);
+ Focused (this, e);
this.HasFocus = true;
}
public virtual void onUnfocused(object sender, EventArgs e){
- if (Unfocused!=null)
- Unfocused (sender, e);
+ Unfocused (this, e);
this.HasFocus = false;
}
public virtual void onMouseEnter(object sender, MouseMoveEventArgs e)
{
- //Debug.WriteLine ("Mouse Enter: " + this.ToString ());
- if (MouseEnter != null)
- MouseEnter (this, e);
+ Debug.WriteLine ("Mouse enter: " + this.Name);
+ MouseEnter (this, e);
}
public virtual void onMouseLeave(object sender, MouseMoveEventArgs e)
{
- if (MouseLeave != null)
- MouseLeave (this, e);
+ Debug.WriteLine ("Mouse leave: " + this.Name);
+ MouseLeave (this, e);
}
#endregion
@@ -702,30 +604,24 @@ namespace go foreach (EventSource es in EventsToResolve)
{
- if (es.Handler == null)
+ if (string.IsNullOrEmpty(es.Handler))
continue;
-
- MethodInfo mi = ClassContainingHandlers.GetType().GetMethod(es.Handler, BindingFlags.NonPublic | BindingFlags.Public
- | BindingFlags.Instance);
- if (mi == null) {
- Debug.WriteLine ("Handler Method not found: " + es.Handler);
- continue;
- }
- FieldInfo fi;
- Type ty = es.Source.GetType ();
- do {
- fi = ty.GetField (es.EventName,
- BindingFlags.NonPublic |
- BindingFlags.Instance |
- BindingFlags.GetField);
- ty = ty.BaseType;
- if (ty == null)
- break;
- } while(fi == null);
- Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);
- fi.SetValue(es.Source, del);
+ if (es.Handler.StartsWith ("{")) {
+ CompilerServices.CompileEventSource (es);
+ } else {
+ MethodInfo mi = ClassContainingHandlers.GetType ().GetMethod (es.Handler, BindingFlags.NonPublic | BindingFlags.Public
+ | BindingFlags.Instance);
+
+ if (mi == null) {
+ Debug.WriteLine ("Handler Method not found: " + es.Handler);
+ continue;
+ }
+ FieldInfo fi = CompilerServices.getEventHandlerField (es.Source.GetType (), es.EventName);
+ Delegate del = Delegate.CreateDelegate(fi.FieldType, ClassContainingHandlers, mi);
+ fi.SetValue(es.Source, del);
+ }
}
}
@@ -735,14 +631,6 @@ namespace go public override string ToString ()
{
return Name == "unamed" ? this.GetType ().ToString() : Name;
-// string tmp = this.GetType ().ToString ().Split (new char[] { '.' }).Last () + ":-";
-// if (!LayoutIsValid)
-// tmp += "L-";
-// //if (Interface.graphicUpdateList.Contains(this))
-// // tmp += "GU-";
-// if (OpenTKGameWindow.redrawClip.intersect (this.renderBoundsInBackendSurfaceCoordonate))
-// tmp += "D-";
-// return tmp + string.Format ("rb:{0}", Slot);
}
#region IXmlSerializable
@@ -762,6 +650,7 @@ namespace go string handler = reader.GetAttribute(ei.Name);
if (string.IsNullOrEmpty (handler))
continue;
+
GraphicObject.EventsToResolve.Add(new EventSource
{
Source = this,
@@ -829,6 +718,8 @@ namespace go //TODO: maybe find another way to convert correctely colors default values
if (pi.PropertyType == typeof(Color))
pi.SetValue (this, Color.Parse ((string)defaultValue), null);
+ else if (pi.PropertyType == typeof(Font))
+ pi.SetValue (this, Font.Parse ((string)defaultValue), null);
else
pi.SetValue (this, defaultValue, null);
} else {
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index d65e07af..ef101ed1 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -12,25 +12,25 @@ namespace go {
public class Group : GraphicObject, IXmlSerializable
{
+ #region CTOR
+ public Group()
+ : base()
+ {
+ }
+ #endregion
+
bool _multiSelect = false;
public GraphicObject activeWidget;
-
public List<GraphicObject> Children = new List<GraphicObject>();
- [XmlAttributeAttribute()]
- [DefaultValue(false)]
+ [XmlAttributeAttribute()][DefaultValue(false)]
public bool MultiSelect
{
get { return _multiSelect; }
set { _multiSelect = value; }
}
-
- public Group()
- : base()
- {
- }
public virtual T addChild<T>(T child)
{
@@ -46,17 +46,31 @@ namespace go child.Parent = null;
LayoutIsValid = false;
}
+ public void putWidgetOnTop(GraphicObject w)
+ {
+ if (Children.Contains(w))
+ {
+ Children.Remove(w);
+ Children.Add(w);
+ }
+ }
+ public void putWidgetOnBottom(GraphicObject w)
+ {
+ if (Children.Contains(w))
+ {
+ Children.Remove(w);
+ Children.Insert(0, w);
+ }
+ }
#region GraphicObject overrides
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(true)]//overiden to get default to true
+ [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true
public override bool Focusable
{
get { return base.Focusable; }
set { base.Focusable = value; }
}
- [XmlIgnore]
- public override bool DrawingIsValid {
+ [XmlIgnore]public override bool DrawingIsValid {
get {
if (!base.DrawingIsValid)
return false;
@@ -67,8 +81,7 @@ namespace go return true;
}
}
- [XmlIgnore]
- public override bool LayoutIsValid
+ [XmlIgnore]public override bool LayoutIsValid
{
get
{
@@ -107,7 +120,7 @@ namespace go foreach (GraphicObject w in Children)
w.InvalidateLayout();
}
- public override Size measureRawSize ()
+ protected override Size measureRawSize ()
{
Size raw = Bounds.Size;
Size tmp = new Size ();
@@ -131,9 +144,9 @@ namespace go }
if (raw.Width < 0)
- tmp.Width += 2*(BorderWidth+Margin);
+ tmp.Width += 2*Margin;
if (raw.Height < 0)
- tmp.Height += 2*(BorderWidth+Margin);
+ tmp.Height += 2*Margin;
return tmp;
}
@@ -169,7 +182,7 @@ namespace go return r + ClientRectangle.Position;
}
- public override void onDraw (Context gr)
+ protected override void onDraw (Context gr)
{
Rectangle rBack = new Rectangle (Slot.Size);
gr.Color = Background;
@@ -183,7 +196,7 @@ namespace go public override void Paint(ref Context ctx, Rectangles clip = null)
{
- if ( !(Visible & LayoutIsValid) )
+ if ( !(Visible&LayoutIsValid) )
return;
// ctx.Save ();
@@ -251,23 +264,6 @@ namespace go base.onMouseMove (sender, e);
}
#endregion
-
- public void putWidgetOnTop(GraphicObject w)
- {
- if (Children.Contains(w))
- {
- Children.Remove(w);
- Children.Add(w);
- }
- }
- public void putWidgetOnBottom(GraphicObject w)
- {
- if (Children.Contains(w))
- {
- Children.Remove(w);
- Children.Insert(0, w);
- }
- }
public override string ToString()
{
diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs index 77419f5e..0ad074e5 100644 --- a/src/GraphicObjects/GroupBox.cs +++ b/src/GraphicObjects/GroupBox.cs @@ -1,20 +1,32 @@ using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Text;
-using Cairo;
using System.Xml.Serialization;
-using System.ComponentModel;
+using Cairo;
namespace go
{
- public class GroupBox : Container
+ public class GroupBox : Border
{
+ #region CTOR
+ public GroupBox() : base (){
+ }
+ public GroupBox(string _title = "GroupBox")
+ : base()
+ {
+ Text = _title;
+ }
+ #endregion
+
+ #region private fields
string _title;
- int _fontSize = 10;
+ Font _font;
+ #endregion
- [XmlAttributeAttribute]
- [DefaultValue("GroupBox")]
+ #region public properties
+ [XmlAttributeAttribute][DefaultValue("GroupBox")]
public string Text
{
get { return _title; }
@@ -23,82 +35,68 @@ namespace go _title = value;
registerForGraphicUpdate();
}
- }
-
- [XmlAttributeAttribute]
- [DefaultValue(10)]
- public int fontSize
- {
- get { return _fontSize; }
- set
- {
- _fontSize = value;
- registerForGraphicUpdate();
- }
- }
+ }
+ [XmlAttributeAttribute()][DefaultValue("droid,12")]
+ public Font Font {
+ get { return _font; }
+ set { _font = value; }
+ }
+ #endregion
- public Size titleSize()
- {
+ Size titleSize {
+ get {
#if _WIN32 || _WIN64
byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(_title);
#endif
- Size s;
+ Size s;
- using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
- using (Context gr = new Context (img)) {
- gr.SetFontSize (fontSize);
- TextExtents te;
+ using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
+ using (Context gr = new Context (img)) {
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
+ TextExtents te;
#if _WIN32 || _WIN64
te = gr.TextExtents(txt);
#elif __linux__
- te = gr.TextExtents (Text);
+ te = gr.TextExtents (Text);
#endif
- FontExtents fe = gr.FontExtents;
- s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height));
+ FontExtents fe = gr.FontExtents;
+ s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height));
+ }
}
+ return s;// +borderWidth;
}
- return s;// +borderWidth;
- }
-
- public GroupBox() : base (){
}
- public GroupBox(Rectangle _bounds, string _title = "GroupBox")
- : base(_bounds)
- {
- Text = _title;
- }
-
- public GroupBox(string _title = "GroupBox")
- : base()
- {
- Text = _title;
- }
-
- public override Rectangle clientBounds
- {
- get
- {
- Size ts = titleSize();
- Rectangle cb = Slot;
- cb.X = 0;
- cb.Y = ts.Height;
- cb.Height -= ts.Height;
- cb.Inflate(-BorderWidth - Margin);
-
- return cb;
- }
- }
-
- public override void onDraw (Context gr)
+ #region GraphicObject overrides
+ public override Rectangle ClientRectangle {
+ get {
+ Size ts = titleSize;
+ Rectangle cb = Slot.Size;
+ cb.Y = ts.Height;
+ cb.Height -= ts.Height;
+ cb.Inflate ( - Margin);
+ return cb;
+ }
+ }
+ protected override Size measureRawSize ()
+ {
+ Size raw = base.measureRawSize ();
+ return raw > 0 ? raw + titleSize : raw;
+ }
+ protected override void onDraw (Context gr)
{
//base.onDraw (gr);
byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(Text);
Rectangle r = new Rectangle(Slot.Size);
+ if (BorderWidth > 0)
+ r.Inflate (-BorderWidth / 2);
+
//gr.Rotate(Math.PI);
- gr.SetFontSize(fontSize);
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
FontExtents fe = gr.FontExtents;
TextExtents te = gr.TextExtents(Text);
@@ -106,8 +104,7 @@ namespace go gr.LineWidth = BorderWidth;
gr.Color = Background;
- CairoHelpers.CairoRectangle (gr, r, CornerRadius);
- gr.Fill();
+
Rectangle rTitle = r;
@@ -115,14 +112,14 @@ namespace go r.Y += th;
r.Height -= th;
+ CairoHelpers.CairoRectangle (gr, r, CornerRadius);
+ gr.Fill();
+
const int titleGap = 5;
if (BorderWidth > 0)
{
gr.Color = BorderColor;
- gr.LineWidth = BorderWidth;
-
- r.Inflate(-BorderWidth / 2, -BorderWidth / 2);
rTitle.X = r.X + titleGap;
rTitle.Width = (int)Math.Ceiling(te.XAdvance) + 2 * titleGap;
@@ -149,10 +146,11 @@ namespace go gr.Color = Foreground;
gr.Fill();
}
+ #endregion
public override string ToString()
{
- return this.Text + ":" + base.ToString();
+ return base.ToString() + ": " + this.Text;
}
}
}
diff --git a/src/GraphicObjects/HorizontalStack.cs b/src/GraphicObjects/HorizontalStack.cs index bdfc136e..bdfc136e 100644..100755 --- a/src/GraphicObjects/HorizontalStack.cs +++ b/src/GraphicObjects/HorizontalStack.cs diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index ce60a8eb..a71205b6 100644..100755 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -56,12 +56,12 @@ namespace go Bitmap = _bitmap;
}
- public override Size measureRawSize ()
+ protected override Size measureRawSize ()
{
if (image == null)
loadImage (@"Images/Icons/icon_alert.gif");
- return imgSize + (BorderWidth + Margin)*2;
+ return imgSize + Margin*2;
}
//load image via System.Drawing.Bitmap, cairo load png only
@@ -94,15 +94,15 @@ namespace go bitmap.UnlockBits (data);
//bitmap.Dispose();
}
- public override void onDraw (Context gr)
+ protected override void onDraw (Context gr)
{
base.onDraw (gr);
float ratio = 1f;
- float widthRatio = (float)clientBounds.Width / imgSize.Width;
- float heightRatio = (float)clientBounds.Height / imgSize.Height;
+ float widthRatio = (float)ClientRectangle.Width / imgSize.Width;
+ float heightRatio = (float)ClientRectangle.Height / imgSize.Height;
ratio = Math.Min (widthRatio, heightRatio);
- Rectangle rImg = clientBounds;
+ Rectangle rImg = ClientRectangle;
gr.Scale (widthRatio, heightRatio);
using (ImageSurface imgSurf = new ImageSurface(image, Format.Argb32,
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index c29050a1..91f53291 100644..100755 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -5,17 +5,32 @@ using System.Text; using System.Diagnostics;
using Cairo;
using System.Text.RegularExpressions;
+using System.Xml.Serialization;
+using System.ComponentModel;
namespace go
{
[Serializable]
public class Label : GraphicObject
{
+ #region CTOR
+ public Label()
+ {
+
+ }
+ public Label(string _text)
+ : base()
+ {
+ Text = _text;
+ }
+ #endregion
+
//TODO:change protected to private
+ #region private and protected fields
protected string _text = "label";
- Alignment _textAlignment = Alignment.LeftCenter;
- int _fontSize = 12;
+ Alignment _textAlignment = Alignment.LeftCenter;
+ Font _font;
bool _multiline = false;
protected Rectangle rText;
@@ -23,41 +38,17 @@ namespace go protected float heightRatio = 1f;
protected FontExtents fe;
protected TextExtents te;
+ #endregion
//public string FontFace = "MagicMedieval";
- public string FontFace = "droid";
-
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(-1)]
- public override int Width {
- get { return base.Width; }
- set { base.Width = value; }
- }
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(-1)]
- public override int Height {
- get { return base.Height; }
- set { base.Height = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(2)]
- public virtual int Margin {
- get { return base.Margin; }
- set { base.Margin = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(Alignment.LeftCenter)]
+ [XmlAttributeAttribute()][DefaultValue(Alignment.LeftCenter)]
public Alignment TextAlignment
{
get { return _textAlignment; }
set { _textAlignment = value; }
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
+ [XmlAttributeAttribute()][DefaultValue("label")]
public string Text
{
get { return _text; }
@@ -73,21 +64,12 @@ namespace go _text = value;
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(10)]
- public int FontSize
- {
- get { return _fontSize; }
- set
- {
- _fontSize = value;
- registerForGraphicUpdate();
- }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(false)]
+ [XmlAttributeAttribute()][DefaultValue("droid,10")]
+ public Font Font {
+ get { return _font; }
+ set { _font = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(false)]
public bool Multiline
{
get { return _multiline; }
@@ -97,26 +79,7 @@ namespace go registerForGraphicUpdate();
}
}
-
- public Label()
- {
-
- }
-
- public Label(string _text)
- : base()
- {
- //updateFont();
- Text = _text;
- }
-
- void updateFont()
- {
- //TextFont = new Font(fontFamily, fontSize, fontStyle, GraphicsUnit.Pixel);
-
- bmp = null;
- }
-
+
string[] getLines {
get {
return _multiline ?
@@ -125,7 +88,24 @@ namespace go }
}
- public override Size measureRawSize()
+ #region GraphicObject overrides
+ [XmlAttributeAttribute()][DefaultValue(-1)]
+ public override int Width {
+ get { return base.Width; }
+ set { base.Width = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(-1)]
+ public override int Height {
+ get { return base.Height; }
+ set { base.Height = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(2)]
+ public override int Margin {
+ get { return base.Margin; }
+ set { base.Margin = value; }
+ }
+
+ protected override Size measureRawSize()
{
Size s;
@@ -138,8 +118,9 @@ namespace go using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
- gr.SelectFontFace (FontFace, FontSlant.Normal, FontWeight.Normal);
- gr.SetFontSize (FontSize);
+
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
te = new TextExtents();
@@ -153,30 +134,29 @@ namespace go te = tmp;
}
fe = gr.FontExtents;
- s = new Size ((int)Math.Ceiling (te.XAdvance) + (BorderWidth + Margin) * 2, (int)Math.Ceiling (fe.Height) * lines.Length + (BorderWidth + Margin) * 2);
+ s = new Size ((int)Math.Ceiling (te.XAdvance) + Margin * 2, (int)Math.Ceiling (fe.Height) * lines.Length + Margin*2);
}
}
return s;// +borderWidth;
}
- public override void onDraw (Context gr)
+ protected override void onDraw (Context gr)
{
base.onDraw (gr);
string[] lines = getLines;
- gr.SelectFontFace(FontFace, FontSlant.Normal, FontWeight.Normal);
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
- gr.LineWidth = BorderWidth;
gr.Antialias = Antialias.Subpixel;
//gr.FontOptions.Antialias = Antialias.Subpixel;
//gr.FontOptions.HintMetrics = HintMetrics.On;
- gr.SetFontSize(FontSize);
rText = new Rectangle(new Point(0, 0),new Size((int)te.Width,(int)fe.Height * lines.Length));
widthRatio = 1f;
heightRatio = 1f;
- Rectangle cb = clientBounds;
+ Rectangle cb = ClientRectangle;
//ignore text alignment if size to content = true
if (Bounds.Size < 0)
@@ -278,7 +258,7 @@ namespace go gr.Color = Foreground;
- gr.FontMatrix = new Matrix(widthRatio * FontSize, 0, 0, heightRatio * FontSize, 0, 0);
+ gr.FontMatrix = new Matrix(widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);
for (int i = 0; i < lines.Length; i++) {
gr.MoveTo(rText.X, rText.Y + fe.Ascent + fe.Height * i);
@@ -290,5 +270,6 @@ namespace go }
gr.Fill();
}
+ #endregion
}
}
diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index c8aa48d2..1d4336e2 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -1,9 +1,12 @@ using System; +using System.Xml.Serialization; +using System.ComponentModel; namespace go { public class NumericControl : GraphicObject { + #region CTOR public NumericControl () : base() { } @@ -15,6 +18,7 @@ namespace go _smallStep = step; _bigStep = step * 5; } + #endregion #region event handlers public EventHandler<ValueChangeEventArgs> ValueChanged; @@ -26,10 +30,12 @@ namespace go } #endregion + #region private fields double _actualValue, _minValue, _maxValue, _smallStep, _bigStep; + #endregion - [System.Xml.Serialization.XmlAttributeAttribute()] - [System.ComponentModel.DefaultValue(0)] + #region public properties + [XmlAttributeAttribute()][DefaultValue(0)] public virtual double Minimum { get { return _minValue; } set { @@ -42,9 +48,7 @@ namespace go registerForGraphicUpdate (); } } - - [System.Xml.Serialization.XmlAttributeAttribute()] - [System.ComponentModel.DefaultValue(10.0)] + [XmlAttributeAttribute()][DefaultValue(10.0)] public virtual double Maximum { get { return _maxValue; } @@ -58,9 +62,7 @@ namespace go registerForGraphicUpdate (); } } - - [System.Xml.Serialization.XmlAttributeAttribute()] - [System.ComponentModel.DefaultValue(0.5)] + [XmlAttributeAttribute()][DefaultValue(0.5)] public virtual double SmallIncrement { get { return _smallStep; } @@ -74,9 +76,7 @@ namespace go registerForGraphicUpdate (); } } - - [System.Xml.Serialization.XmlAttributeAttribute()] - [System.ComponentModel.DefaultValue(2.0)] + [XmlAttributeAttribute()][DefaultValue(2.0)] public virtual double LargeIncrement { get { return _bigStep; } @@ -90,9 +90,7 @@ namespace go registerForGraphicUpdate (); } } - - [System.Xml.Serialization.XmlAttributeAttribute()] - [System.ComponentModel.DefaultValue(0)] + [XmlAttributeAttribute()][DefaultValue(0)] public double Value { get { return _actualValue; } @@ -114,6 +112,8 @@ namespace go registerForGraphicUpdate(); } } + #endregion + } } diff --git a/src/GraphicObjects/ProgressBar.cs b/src/GraphicObjects/ProgressBar.cs index b9743c5a..ad43fc23 100644 --- a/src/GraphicObjects/ProgressBar.cs +++ b/src/GraphicObjects/ProgressBar.cs @@ -4,58 +4,47 @@ using System.Linq; using System.Text;
using Cairo;
using System.Diagnostics;
+using System.Xml.Serialization;
+using System.ComponentModel;
namespace go
{
[Serializable]
- public class ProgressBar : GraphicObject
+ public class ProgressBar : Border
{
+ #region CTOR
+ public ProgressBar() : base(){}
+ public ProgressBar(int _max) : base()
+ {
+ Maximum = _max;
+ }
+ #endregion
+
+ #region private fields
int _currentValue = 0;
int _minimum = 0;
int _maximum = 100;
+ #endregion
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("Gray")]
- public override Color Background {
- get { return base.Background; }
- set { base.Background = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
- public override int BorderWidth {
- get { return base.BorderWidth; }
- set { base.BorderWidth = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("BlueCrayola")]
- public virtual Color Foreground {
- get { return base.Foreground; }
- set { base.Foreground = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
- public int Value
- {
- get { return _currentValue; }
- set
- {
- if (_currentValue == value)
- return;
-
- _currentValue = value;
+ #region public properties
+ [XmlAttributeAttribute()][DefaultValue(0)]
+ public int Value
+ {
+ get { return _currentValue; }
+ set
+ {
+ if (_currentValue == value)
+ return;
- if (_currentValue > Maximum)
- _currentValue = Maximum;
+ _currentValue = value;
- registerForGraphicUpdate();
- }
- }
+ if (_currentValue > Maximum)
+ _currentValue = Maximum;
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(0)]
+ registerForGraphicUpdate();
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue(0)]
public int Minimum {
get {return _minimum;}
set {
@@ -65,9 +54,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(100)]
+ [XmlAttributeAttribute()][DefaultValue(100)]
public int Maximum {
get {return _maximum;}
set {
@@ -77,15 +64,26 @@ namespace go registerForGraphicUpdate();
}
}
-
- public ProgressBar() : base(){}
+ #endregion
- public ProgressBar(int _max) : base()
- {
- Maximum = _max;
- }
+ #region GraphicObject overrides
+ [XmlAttributeAttribute()][DefaultValue("Gray")]
+ public override Color Background {
+ get { return base.Background; }
+ set { base.Background = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(0)]
+ public override int BorderWidth {
+ get { return base.BorderWidth; }
+ set { base.BorderWidth = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue("BlueCrayola")]
+ public virtual Color Foreground {
+ get { return base.Foreground; }
+ set { base.Foreground = value; }
+ }
- public override void onDraw (Context gr)
+ protected override void onDraw (Context gr)
{
base.onDraw (gr);
@@ -100,11 +98,6 @@ namespace go CairoHelpers.CairoRectangle(gr,rBack,CornerRadius);
gr.Fill();
}
- public override void Paint (ref Context ctx, Rectangles clip)
- {
- base.Paint (ref ctx, clip);
-// if (clip != null)
-// clip.stroke (ctx, Color.Amethyst);
- }
+ #endregion
}
}
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 74300dba..c896f3b4 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -80,8 +80,8 @@ namespace go if (scrollY > 0)
scrollY = 0;
- else if (scrollY < -child.Slot.Height + clientBounds.Height)
- scrollY = -child.Slot.Height + clientBounds.Height;
+ else if (scrollY < -child.Slot.Height + ClientRectangle.Height)
+ scrollY = -child.Slot.Height + ClientRectangle.Height;
}
if (HorizontalScrolling )
@@ -93,8 +93,8 @@ namespace go if (scrollX > 0)
scrollX = 0;
- else if (scrollX < -child.Slot.Width + clientBounds.Width)
- scrollX = -child.Slot.Width + clientBounds.Width;
+ else if (scrollX < -child.Slot.Width + ClientRectangle.Width)
+ scrollX = -child.Slot.Width + ClientRectangle.Width;
}
diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index bb295f2c..56c9dd0b 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -4,35 +4,32 @@ using System.Linq; using System.Text;
using Cairo;
using System.Xml.Serialization;
+using System.ComponentModel;
namespace go
{
public class Slider : NumericControl
{
+ #region CTOR
+ public Slider() : base()
+ {}
+ public Slider(double minimum, double maximum, double step)
+ : base(minimum,maximum,step)
+ {
+ }
+ #endregion
+
+ #region private fields
Rectangle cursor;
int _cursorWidth;
Color _cursorColor;
- //Point mouseDownPos;
- bool holdCursor = false;//may use maybe active go equality
+ bool holdCursor = false;
+ #endregion
protected double unity;
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("Gray")]
- public override Color Background {
- get { return base.Background; }
- set { base.Background = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(2)]
- public override int BorderWidth {
- get { return base.BorderWidth; }
- set { base.BorderWidth = value; }
- }
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue("BlueGray")]
+ #region Public properties
+ [XmlAttributeAttribute()][DefaultValue("BlueGray")]
public virtual Color CursorColor {
get { return _cursorColor; }
set {
@@ -40,9 +37,7 @@ namespace go registerForGraphicUpdate ();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(20)]
+ [XmlAttributeAttribute()][DefaultValue(20)]
public virtual int CursorWidth {
get { return _cursorWidth; }
set {
@@ -50,27 +45,61 @@ namespace go registerForGraphicUpdate ();
}
}
+ #endregion
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(true)]
+ #region GraphicObject Overrides
+ [XmlAttributeAttribute()][DefaultValue("Gray")]
+ public override Color Background {
+ get { return base.Background; }
+ set { base.Background = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue(true)]
public override bool Focusable
{
get { return base.Focusable; }
set { base.Focusable = value; }
}
+ protected override void UpdateGraphic ()
+ {
+ computeCursorPosition();
+ base.UpdateGraphic ();
+ }
+ protected override void onDraw (Context gr)
+ {
+ base.onDraw (gr);
-
- public Slider() : base()
- {}
- public Slider(double minimum, double maximum, double step)
- : base(minimum,maximum,step)
- {
- }
+ Rectangle r = ClientRectangle;
+ PointD pStart = r.TopLeft + new Point(cursor.Width/2, r.Height / 2);
+ PointD pEnd = r.TopRight + new Point(-cursor.Width/2, r.Height / 2);
+
+ DrawGraduations (gr, pStart,pEnd);
+
+ DrawCursor (gr, cursor);
+ }
+ #endregion
+
+ protected virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
+ {
+ gr.Color = Foreground;
+
+ gr.LineWidth = 1;
+ gr.MoveTo(pStart);
+ gr.LineTo(pEnd);
+
+ gr.Stroke();
+
+ }
+ protected virtual void DrawCursor(Context gr, Rectangle _cursor)
+ {
+ gr.Color = CursorColor;
+ CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius);
+ gr.FillPreserve();
+ }
void computeCursorPosition()
{
- Rectangle r = clientBounds;
+ Rectangle r = ClientRectangle;
cursor = new Rectangle(new Size(_cursorWidth,(int) (r.Height)));
@@ -113,44 +142,5 @@ namespace go }
#endregion
-
- internal override void UpdateGraphic ()
- {
- computeCursorPosition();
- base.UpdateGraphic ();
- }
-
- public override void onDraw (Context gr)
- {
- base.onDraw (gr);
-
- Rectangle r = clientBounds;
- PointD pStart = r.TopLeft + new Point(cursor.Width/2, r.Height / 2);
- PointD pEnd = r.TopRight + new Point(-cursor.Width/2, r.Height / 2);
-
- DrawGraduations (gr, pStart,pEnd);
-
- DrawCursor (gr, cursor);
- }
-
- public virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
- {
- gr.Color = Foreground;
-
- gr.LineWidth = 1;
- gr.MoveTo(pStart);
- gr.LineTo(pEnd);
-
- gr.Stroke();
-
- }
- public virtual void DrawCursor(Context gr, Rectangle _cursor)
- {
- gr.Color = CursorColor;
- CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius);
- gr.FillPreserve();
- gr.Color = BorderColor;
- gr.Stroke ();
- }
}
}
diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 4df0b3f7..70d841aa 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -7,15 +7,25 @@ using Cairo; using System.Diagnostics;
using System.Xml.Serialization;
using System.Globalization;
+using System.ComponentModel;
namespace go
{
public class TextBoxWidget : Label
{
- public static KeyboardDevice Keyboard;
- public static char decimalSeparator = '.';//????? should follow locale policy
+ #region CTOR
+ public TextBoxWidget(string _initialValue, GOEvent _onTextChanged = null)
+ : base(_initialValue)
+ {
+
+ }
+
+ public TextBoxWidget()
+ { }
+ #endregion
+
static bool _capitalOn = false; //????????????????
- public static bool capitalOn
+ [XmlIgnore]public static bool capitalOn
{
get
{
@@ -26,17 +36,36 @@ namespace go set { _capitalOn = value; }
}
- Color selColor = Color.BlueBell;
- Color selFontColor = Color.WhiteSmoke;
+ #region private fields
+ Color selColor;
+ Color selFontColor;
Point mouseLocalPos; //mouse coord in widget space, filled only when clicked
int _currentPos; //0 based cursor position in string
double textCursorPos; //cursor position in cairo units in widget client coord.
double SelStartCursorPos = -1;
double SelEndCursorPos = -1;
bool SelectionInProgress = false;
+ #endregion
- [XmlIgnore]
- public override bool HasFocus //trigger update when lost focus to errase text beam
+ [XmlAttributeAttribute()][DefaultValue("SkyBlue")]
+ public virtual Color SelectionBackground {
+ get { return selColor; }
+ set {
+ selColor = value;
+ registerForGraphicUpdate ();
+ }
+ }
+ [XmlAttributeAttribute()][DefaultValue("Black")]
+ public virtual Color SelectionForeground {
+ get { return selFontColor; }
+ set {
+ selFontColor = value;
+ registerForGraphicUpdate ();
+ }
+ }
+
+ #region GraphicObject overrides
+ [XmlIgnore]public override bool HasFocus //trigger update when lost focus to errase text beam
{
get
{
@@ -48,65 +77,31 @@ namespace go registerForGraphicUpdate();
}
}
-
- [System.Xml.Serialization.XmlAttributeAttribute()]
- [System.ComponentModel.DefaultValue(true)]
+ [XmlAttributeAttribute()][DefaultValue(true)]
public override bool Focusable
{
get { return base.Focusable; }
set { base.Focusable = value; }
}
+ [XmlAttributeAttribute()][DefaultValue("White")]
+ public virtual Color Background {
+ get { return base.Background; }
+ set { base.Background = value; }
+ }
+ [XmlAttributeAttribute()][DefaultValue("Black")]
+ public virtual Color Foreground {
+ get { return base.Foreground; }
+ set { base.Foreground = value; }
+ }
- [XmlIgnore]
- public GOEvent onTextChanged;
-
- [XmlIgnore]
- public int currentPos
- {
- get { return _currentPos; }
- set { _currentPos = value; }
- }
-
- [XmlIgnore]
- public int selBeginPos;
- [XmlIgnore]
- public int selReleasePos;
- [XmlIgnore]
- public int selectionStart //ordered selection start and end positions
- {
- get { return selReleasePos < 0 ? selBeginPos : Math.Min(selBeginPos, selReleasePos); }
- }
- [XmlIgnore]
- public int selectionEnd
- { get { return selReleasePos < 0 ? selReleasePos : Math.Max(selBeginPos, selReleasePos); } }
- [XmlIgnore]
- public string selectedText
- { get { return selectionEnd < 0 ? null : Text.Substring(selectionStart, selectionEnd - selectionStart); } }
- [XmlIgnore]
- public bool selectionIsEmpty
- { get { return string.IsNullOrEmpty(selectedText); } }
-
- public TextBoxWidget(string _initialValue, GOEvent _onTextChanged = null)
- : base(_initialValue)
- {
- onTextChanged = _onTextChanged;
- Focusable = true;
- selColor = Color.SkyBlue;
- selFontColor = Color.Black;
- Foreground = Color.Black;
- Background = Color.White;
- TextAlignment = Alignment.LeftCenter;
- }
-
- public TextBoxWidget()
- { }
-
- public override void onDraw (Context gr)
+ protected override void onDraw (Context gr)
{
base.onDraw (gr);
-// gr.FontOptions.Antialias = Antialias.Subpixel;
-// gr.FontOptions.HintMetrics = HintMetrics.On;
- gr.SetFontSize(FontSize);
+ // gr.FontOptions.Antialias = Antialias.Subpixel;
+ // gr.FontOptions.HintMetrics = HintMetrics.On;
+ gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
+ gr.SetFontSize (Font.Size);
+
FontExtents fe = gr.FontExtents;
#region draw text cursor
@@ -135,7 +130,7 @@ namespace go if (HasFocus)
{
//TODO:
- gr.Color = Color.White;
+ gr.Color = Foreground;
gr.LineWidth = 2;
gr.MoveTo(new PointD(textCursorPos + rText.X, rText.Y ));
gr.LineTo(new PointD(textCursorPos + rText.X, rText.Y + fe.Height));
@@ -166,6 +161,34 @@ namespace go gr.Fill();
}
+ #endregion
+
+ public event EventHandler<TextChangeEventArgs> TextChanged = delegate { };
+
+ public virtual void onTextChanged(Object sender, TextChangeEventArgs e)
+ {
+ TextChanged (this, e);
+ }
+
+
+ [XmlIgnore]public int currentPos{
+ get { return _currentPos; }
+ set { _currentPos = value; }
+ }
+ [XmlIgnore]public int selBeginPos;
+ [XmlIgnore]public int selReleasePos;
+ [XmlIgnore]public int selectionStart //ordered selection start and end positions
+ {
+ get { return selReleasePos < 0 ? selBeginPos : Math.Min(selBeginPos, selReleasePos); }
+ }
+ [XmlIgnore]public int selectionEnd
+ { get { return selReleasePos < 0 ? selReleasePos : Math.Max(selBeginPos, selReleasePos); } }
+ [XmlIgnore]public string selectedText
+ { get { return selectionEnd < 0 ? null : Text.Substring(selectionStart, selectionEnd - selectionStart); } }
+ [XmlIgnore]public bool selectionIsEmpty
+ { get { return string.IsNullOrEmpty(selectedText); } }
+
+
#region Keyboard handling
public override void onKeyDown (object sender, KeyboardKeyEventArgs e)
@@ -208,8 +231,7 @@ namespace go break;
case Key.Enter:
case Key.KeypadEnter:
- if (onTextChanged != null)
- onTextChanged(this);
+ onTextChanged(this,new TextChangeEventArgs(Text));
break;
case Key.Escape:
Text = "";
@@ -330,7 +352,7 @@ namespace go public override void onMouseButtonDown (object sender, MouseButtonEventArgs e)
{
if (this.HasFocus){
- mouseLocalPos = Mouse.Position - ScreenCoordinates(rText).TopLeft - rText.TopLeft;
+ mouseLocalPos = e.Position - ScreenCoordinates(rText).TopLeft - rText.TopLeft;
selBeginPos = -1;
selReleasePos = -1;
}else{
diff --git a/src/GraphicObjects/VerticalStack.cs b/src/GraphicObjects/VerticalStack.cs index 0fd063a0..0fd063a0 100644..100755 --- a/src/GraphicObjects/VerticalStack.cs +++ b/src/GraphicObjects/VerticalStack.cs |