aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-22 12:48:11 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-22 12:48:11 +0200
commit8c99bee3d98f7c3221e969c2924d87729ba7faea (patch)
treea9d397745c633f2306762e740486da8413b84223 /src
parentdc995bd1da98971009454f4efe043d6237d00729 (diff)
- simplify value change with only actual value, not the old one
- First tests with Scrollbar
Diffstat (limited to 'src')
-rw-r--r--src/CompilerServices/CompilerServices.cs4
-rw-r--r--src/GraphicObjects/Checkbox.cs10
-rw-r--r--src/GraphicObjects/GraphicObject.cs36
-rw-r--r--src/GraphicObjects/NumericControl.cs4
-rw-r--r--src/GraphicObjects/Scrollbar.cs59
-rw-r--r--src/GraphicObjects/Slider.cs75
-rw-r--r--src/GraphicObjects/TextBox.cs4
-rw-r--r--src/TextChangeEventArgs.cs4
8 files changed, 147 insertions, 49 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index ae4b700a..7bd91805 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -270,8 +270,10 @@ namespace go
if (!srcValueType.IsValueType)
il.Emit(OpCodes.Castclass, srcValueType);
+ else if (piTarget.PropertyType != srcValueType)
+ il.Emit(OpCodes.Callvirt, GetConvertMethod( piTarget.PropertyType ));
else
- il.Emit( OpCodes.Callvirt, GetConvertMethod( piTarget.PropertyType ));
+ il.Emit(OpCodes.Unbox_Any, piTarget.PropertyType);
// if (piTarget.PropertyType == typeof(string))
// else if ( srcValueType != piTarget.PropertyType)
//
diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs
index 30db3849..49532820 100644
--- a/src/GraphicObjects/Checkbox.cs
+++ b/src/GraphicObjects/Checkbox.cs
@@ -25,10 +25,7 @@ namespace go
public Checkbox() : base()
{
}
- protected override void loadDefaultValues ()
- {
- base.loadDefaultValues ();
- }
+
protected override void loadTemplate(GraphicObject template = null)
{
base.loadTemplate (template);
@@ -71,10 +68,5 @@ namespace go
IsChecked = !IsChecked;
base.onMouseClick (sender, e);
}
-
- public override void ReadXml (System.Xml.XmlReader reader)
- {
- base.ReadXml (reader);
- }
}
}
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 0944703f..5b896b53 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -19,8 +19,16 @@ using System.Xml;
namespace go
{
- public class GraphicObject : IXmlSerializable, ILayoutable
+ public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange
{
+ #region IValueChange implementation
+ public event EventHandler<ValueChangeEventArgs> ValueChanged;
+ void NotifyValueChanged(string MemberName, object _value)
+ {
+ ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value));
+ }
+ #endregion
+
#region CTOR
public GraphicObject ()
{
@@ -115,7 +123,12 @@ namespace go
[XmlAttributeAttribute()][DefaultValue("unamed")]
public virtual string Name {
get { return _name; }
- set { _name = value; }
+ set {
+ if (_name == value)
+ return;
+ _name = value;
+ NotifyValueChanged("Name", _verticalAlignment);
+ }
}
[XmlAttributeAttribute()][DefaultValue(VerticalAlignment.Center)]
public virtual VerticalAlignment VerticalAlignment {
@@ -125,14 +138,19 @@ namespace go
return;
_verticalAlignment = value;
-
-// if (Top > 0)
+ NotifyValueChanged("VerticalAlignment", _verticalAlignment);
}
}
[XmlAttributeAttribute()][DefaultValue(HorizontalAlignment.Center)]
public virtual HorizontalAlignment HorizontalAlignment {
get { return _horizontalAlignment; }
- set { _horizontalAlignment = value; }
+ set {
+ if (_horizontalAlignment == value)
+ return;
+
+ _horizontalAlignment = value;
+ NotifyValueChanged("HorizontalAlignment", _horizontalAlignment);
+ }
}
[XmlAttributeAttribute()][DefaultValue(0)]
public virtual int Left {
@@ -142,7 +160,7 @@ namespace go
return;
Bounds.X = value;
-
+ NotifyValueChanged ("Left", Bounds.X);
this.RegisterForLayouting ((int)LayoutingType.X);
}
}
@@ -154,7 +172,7 @@ namespace go
return;
Bounds.Y = value;
-
+ NotifyValueChanged ("Top", Bounds.Y);
this.RegisterForLayouting ((int)LayoutingType.Y);
}
}
@@ -166,7 +184,7 @@ namespace go
return;
Bounds.Width = value;
-
+ NotifyValueChanged ("Width", Bounds.Width);
this.RegisterForLayouting ((int)LayoutingType.Width);
}
}
@@ -178,7 +196,7 @@ namespace go
return;
Bounds.Height = value;
-
+ NotifyValueChanged ("Height", Bounds.Height);
this.RegisterForLayouting ((int)LayoutingType.Height);
}
}
diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs
index 247b4e92..c6d76bcd 100644
--- a/src/GraphicObjects/NumericControl.cs
+++ b/src/GraphicObjects/NumericControl.cs
@@ -90,8 +90,6 @@ namespace go
if (value == _actualValue)
return;
- int oldV = Convert.ToInt32(_actualValue);
-
if (value < minValue)
_actualValue = minValue;
else if (value > maxValue)
@@ -99,7 +97,7 @@ namespace go
else
_actualValue = value;
- onValueChanged(this,new ValueChangeEventArgs("Value", oldV, Convert.ToInt32( _actualValue)));
+ onValueChanged(this,new ValueChangeEventArgs("Value", Convert.ToInt32( _actualValue)));
registerForGraphicUpdate();
}
}
diff --git a/src/GraphicObjects/Scrollbar.cs b/src/GraphicObjects/Scrollbar.cs
new file mode 100644
index 00000000..ca17393e
--- /dev/null
+++ b/src/GraphicObjects/Scrollbar.cs
@@ -0,0 +1,59 @@
+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;
+using System.ComponentModel;
+
+namespace go
+{
+ [DefaultTemplate("#go.Templates.Scrollbar.goml")]
+ public class Scrollbar : TemplatedControl, IValueChange
+ {
+ #region IValueChange implementation
+ public event EventHandler<ValueChangeEventArgs> ValueChanged;
+ #endregion
+
+ Orientation _orientation;
+ Slider _slider;
+
+ public Scrollbar() : base()
+ {
+ }
+
+ protected override void loadTemplate(GraphicObject template = null)
+ {
+ base.loadTemplate (template);
+ _slider = this.child.FindByName ("Slider") as Slider;
+ }
+
+ [XmlAttributeAttribute()][DefaultValue(Orientation.Vertical)]
+ public virtual Orientation Orientation
+ {
+ get { return _orientation; }
+ set {
+ if (_orientation == value)
+ return;
+ _orientation = value;
+ ValueChanged.Raise(this, new ValueChangeEventArgs ("Orientation", _orientation));
+ }
+ }
+ public void onScrollBack (object sender, MouseButtonEventArgs e)
+ {
+ _slider.Value -= _slider.LargeIncrement;
+ }
+ public void onScrollForth (object sender, MouseButtonEventArgs e)
+ {
+ _slider.Value += _slider.LargeIncrement;
+ }
+ }
+}
diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs
index 25da2241..4bf41d52 100644
--- a/src/GraphicObjects/Slider.cs
+++ b/src/GraphicObjects/Slider.cs
@@ -31,8 +31,9 @@ namespace go
#region private fields
Rectangle cursor;
- int _cursorWidth;
+ int _cursorSize;
Color _cursorColor;
+ Orientation _orientation;
bool holdCursor = false;
#endregion
@@ -48,13 +49,19 @@ namespace go
}
}
[XmlAttributeAttribute()][DefaultValue(20)]
- public virtual int CursorWidth {
- get { return _cursorWidth; }
+ public virtual int CursorSize {
+ get { return _cursorSize; }
set {
- _cursorWidth = value;
+ _cursorSize = value;
registerForGraphicUpdate ();
}
}
+ [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
+ public virtual Orientation Orientation
+ {
+ get { return _orientation; }
+ set { _orientation = value; }
+ }
#endregion
#region GraphicObject Overrides
@@ -80,8 +87,15 @@ namespace go
base.onDraw (gr);
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);
+ PointD pStart;
+ PointD pEnd;
+ if (_orientation == Orientation.Horizontal) {
+ pStart = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2);
+ pEnd = r.TopRight + new Point (-_cursorSize / 2, r.Height / 2);
+ } else {
+ pStart = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2);
+ pEnd = r.BottomLeft + new Point (r.Width / 2,- _cursorSize / 2);
+ }
DrawGraduations (gr, pStart,pEnd);
@@ -110,15 +124,21 @@ namespace go
void computeCursorPosition()
{
Rectangle r = ClientRectangle;
+ PointD p1;
- cursor = new Rectangle(new Size(_cursorWidth,(int) (r.Height)));
-
- PointD p1 = r.TopLeft + new Point(cursor.Width/2, r.Height / 2);
-
- unity = (double)(r.Width - cursor.Width) / (Maximum - Minimum);
-
- cursor.TopLeft = new Point(r.Left + (int)(Value * unity),
- (int)(p1.Y - cursor.Height / 2));
+ if (_orientation == Orientation.Horizontal) {
+ cursor = new Rectangle (new Size (_cursorSize, (int)(r.Height)));
+ p1 = r.TopLeft + new Point (_cursorSize / 2, r.Height / 2);
+ unity = (double)(r.Width - _cursorSize) / (Maximum - Minimum);
+ cursor.TopLeft = new Point (r.Left + (int)(Value * unity),
+ (int)(p1.Y - cursor.Height / 2));
+ } else {
+ cursor = new Rectangle (new Size ((int)(r.Width), _cursorSize));
+ p1 = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2);
+ unity = (double)(r.Height - _cursorSize) / (Maximum - Minimum);
+ cursor.TopLeft = new Point ((int)(p1.X - r.Width / 2),
+ r.Top + (int)(Value * unity));
+ }
}
#region mouse handling
@@ -126,13 +146,20 @@ namespace go
{
base.onMouseButtonDown (sender, e);
- Rectangle cursInScreenCoord = ScreenCoordinates(cursor+Slot.Position);
- if (cursInScreenCoord.ContainsOrIsEqual(e.Position))
+ Rectangle cursInScreenCoord = ScreenCoordinates (cursor + Slot.Position);
+ if (cursInScreenCoord.ContainsOrIsEqual (e.Position))
holdCursor = true;
- else if (e.Position.X < cursInScreenCoord.Left)
- Value -= LargeIncrement;
- else
- Value += LargeIncrement;
+ else if (_orientation == Orientation.Horizontal) {
+ if (e.Position.X < cursInScreenCoord.Left)
+ Value -= LargeIncrement;
+ else
+ Value += LargeIncrement;
+ } else {
+ if (e.Position.Y < cursInScreenCoord.Top)
+ Value -= LargeIncrement;
+ else
+ Value += LargeIncrement;
+ }
}
public override void onMouseButtonUp (object sender, OpenTK.Input.MouseButtonEventArgs e)
{
@@ -142,8 +169,12 @@ namespace go
}
public override void onMouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e)
{
- if (holdCursor)
- Value += (double)e.XDelta / unity;
+ if (holdCursor) {
+ if (_orientation == Orientation.Horizontal)
+ Value += (double)e.XDelta / unity;
+ else
+ Value += (double)e.YDelta / unity;
+ }
base.onMouseMove (sender, e);
}
diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs
index 7ba10fe8..65bfacb7 100644
--- a/src/GraphicObjects/TextBox.cs
+++ b/src/GraphicObjects/TextBox.cs
@@ -69,7 +69,7 @@ namespace go
public event EventHandler<TextChangeEventArgs> TextChanged;
- public virtual void onTextChanged(Object sender, TextChangeEventArgs e)
+ public virtual void OnTextChanged(Object sender, TextChangeEventArgs e)
{
TextChanged.Raise (this, e);
}
@@ -102,7 +102,7 @@ namespace go
break;
case Key.Enter:
case Key.KeypadEnter:
- onTextChanged(this,new TextChangeEventArgs(Text));
+ OnTextChanged(this,new TextChangeEventArgs(Text));
break;
case Key.Escape:
Text = "";
diff --git a/src/TextChangeEventArgs.cs b/src/TextChangeEventArgs.cs
index 726c9ae9..532d72f0 100644
--- a/src/TextChangeEventArgs.cs
+++ b/src/TextChangeEventArgs.cs
@@ -5,14 +5,12 @@ namespace go
public class ValueChangeEventArgs: EventArgs
{
public string MemberName;
- public object OldValue;
public object NewValue;
- public ValueChangeEventArgs (string _memberName, object _oldValue, object _newValue) : base()
+ public ValueChangeEventArgs (string _memberName, object _newValue) : base()
{
MemberName = _memberName;
- OldValue = _oldValue;
NewValue = _newValue;
}
}