]> O.S.I.I.S - jp/crow.git/commitdiff
add some events to Button and IsPressed var
authorjp <jp_bruyere@hotmail.com>
Tue, 19 Apr 2016 10:32:25 +0000 (12:32 +0200)
committerjp <jp_bruyere@hotmail.com>
Tue, 19 Apr 2016 10:32:25 +0000 (12:32 +0200)
src/GraphicObjects/Button.cs

index 0b37118c3c2f82efd8033b326bf8618da03790c2..3dd10606e260bb5a1141216f6fd270d2d7ad32c3 100644 (file)
@@ -16,15 +16,21 @@ namespace Crow
        [DefaultTemplate("#Crow.Templates.Button.crow")]
     public class Button : TemplatedContainer
     {
+               string caption;
+               string image;
+               bool isPressed;
+               Container _contentContainer;
+
                #region CTOR
         public Button() : base()
         {}
                #endregion
 
-               string caption;
-               string image;
-               Container _contentContainer;
+               public event EventHandler Pressed;
+               public event EventHandler Released;
+               public event EventHandler Clicked;
 
+               #region TemplatedContainer overrides
                public override GraphicObject Content {
                        get {
                                return _contentContainer == null ? null : _contentContainer.Child;
@@ -40,6 +46,7 @@ namespace Crow
 
                        _contentContainer = this.child.FindByName ("Content") as Container;
                }
+               #endregion
 
                #region GraphicObject Overrides
                public override void ResolveBindings ()
@@ -50,12 +57,20 @@ namespace Crow
                }
                public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
+                       IsPressed = true;
+
                        base.onMouseDown (sender, e);
+
+                       //TODO:remove
                        NotifyValueChanged ("State", "pressed");
                }
                public override void onMouseUp (object sender, MouseButtonEventArgs e)
                {
+                       IsPressed = false;
+
                        base.onMouseUp (sender, e);
+
+                       //TODO:remove
                        NotifyValueChanged ("State", "normal");
                }
                #endregion
@@ -79,6 +94,25 @@ namespace Crow
                                image = value; 
                                NotifyValueChanged ("Image", image);
                        }
-               }     
+               } 
+               [XmlAttributeAttribute()][DefaultValue(false)]
+               public bool IsPressed
+               {
+                       get { return isPressed; }
+                       set
+                       {
+                               if (isPressed == value)
+                                       return;
+
+                               isPressed = value;
+
+                               NotifyValueChanged ("IsPressed", isPressed);
+
+                               if (isPressed)
+                                       Pressed.Raise (this, null);
+                               else
+                                       Released.Raise (this, null);
+                       }
+               }
        }
 }