From e8b13fbea6cab4f01af769a1246c49c588fa2f3e Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 22 Dec 2014 08:08:36 +0100 Subject: CompilerServices for EventHandler statements in XML attributes Improve code formatting debug --- src/GraphicObjects/Button.cs | 286 +++++++------------------------------------ 1 file changed, 47 insertions(+), 239 deletions(-) mode change 100644 => 100755 src/GraphicObjects/Button.cs (limited to 'src/GraphicObjects/Button.cs') diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs old mode 100644 new mode 100755 index c426d51d..837b7012 --- 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