diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-14 03:45:57 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-08-14 03:45:57 +0200 |
| commit | 854f2f732acc4c1d9fa4126962149cae14f4d4e9 (patch) | |
| tree | b9ed25c54bf261b6e22c755db86811a6ee12836f /src/GraphicObjects/GraphicObject.cs | |
| parent | 4f1128a8001b90e1d163056ef66763bc3b7b8576 (diff) | |
* 0.crow, 1.crow, 2.crow, 5.crow, 7.crow:
tests
* GraphicObject.cs:
enabled, code clean and naming conventions
* Label.cs, TextBox.cs:
debug
* Interface.cs:
keyboard repeat
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 297 |
1 files changed, 163 insertions, 134 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index aef23cc2..f8a1e508 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -61,24 +61,25 @@ namespace Crow #region private fields LayoutingType registeredLayoutings = LayoutingType.All; ILayoutable logicalParent; - ILayoutable _parent; - string _name = "unamed"; - Fill _background = Color.Transparent; - Fill _foreground = Color.White; - Font _font = "droid, 10"; - Measure _width, _height; - int _left, _top; - double _cornerRadius = 0; - int _margin = 0; - bool _focusable = false; - bool _hasFocus = false; - bool _isActive = false; - bool _mouseRepeat; - protected bool _isVisible = true; - VerticalAlignment _verticalAlignment = VerticalAlignment.Center; - HorizontalAlignment _horizontalAlignment = HorizontalAlignment.Center; - Size _maximumSize = "0,0"; - Size _minimumSize = "0,0"; + ILayoutable parent; + string name = "unamed"; + Fill background = Color.Transparent; + Fill foreground = Color.White; + Font font = "droid, 10"; + Measure width, height; + int left, top; + double cornerRadius = 0; + int margin = 0; + bool focusable = false; + bool hasFocus = false; + bool isActive = false; + bool mouseRepeat; + protected bool isVisible = true; + bool isEnabled = true; + VerticalAlignment verticalAlignment = VerticalAlignment.Center; + HorizontalAlignment horizontalAlignment = HorizontalAlignment.Center; + Size maximumSize = "0,0"; + Size minimumSize = "0,0"; bool cacheEnabled = false; object dataSource; string style; @@ -124,8 +125,8 @@ namespace Crow /// Parent in the graphic tree, used for rendering and layouting /// </summary> [XmlIgnore]public virtual ILayoutable Parent { - get { return _parent; } - set { _parent = value; } + get { return parent; } + set { parent = value; } } [XmlIgnore]public ILayoutable LogicalParent { get { return logicalParent == null ? Parent : logicalParent; } @@ -167,6 +168,8 @@ namespace Crow public event EventHandler<KeyPressEventArgs> KeyPress; public event EventHandler Focused; public event EventHandler Unfocused; + public event EventHandler Enabled; + public event EventHandler Disabled; public event EventHandler<LayoutingEventArgs> LayoutChanged; #endregion @@ -183,85 +186,85 @@ namespace Crow } [XmlAttributeAttribute()][DefaultValue("unamed")] public virtual string Name { - get { return _name; } + get { return name; } set { - if (_name == value) + if (name == value) return; - _name = value; - NotifyValueChanged("Name", _verticalAlignment); + name = value; + NotifyValueChanged("Name", verticalAlignment); } } [XmlAttributeAttribute ()][DefaultValue(VerticalAlignment.Center)] public virtual VerticalAlignment VerticalAlignment { - get { return _verticalAlignment; } + get { return verticalAlignment; } set { - if (_verticalAlignment == value) + if (verticalAlignment == value) return; - _verticalAlignment = value; - NotifyValueChanged("VerticalAlignment", _verticalAlignment); + verticalAlignment = value; + NotifyValueChanged("VerticalAlignment", verticalAlignment); } } [XmlAttributeAttribute()][DefaultValue(HorizontalAlignment.Center)] public virtual HorizontalAlignment HorizontalAlignment { - get { return _horizontalAlignment; } + get { return horizontalAlignment; } set { - if (_horizontalAlignment == value) + if (horizontalAlignment == value) return; - _horizontalAlignment = value; - NotifyValueChanged("HorizontalAlignment", _horizontalAlignment); + horizontalAlignment = value; + NotifyValueChanged("HorizontalAlignment", horizontalAlignment); } } [XmlAttributeAttribute()][DefaultValue(0)] public virtual int Left { - get { return _left; } + get { return left; } set { - if (_left == value) + if (left == value) return; - _left = value; - NotifyValueChanged ("Left", _left); + left = value; + NotifyValueChanged ("Left", left); this.RegisterForLayouting (LayoutingType.X); } } [XmlAttributeAttribute()][DefaultValue(0)] public virtual int Top { - get { return _top; } + get { return top; } set { - if (_top == value) + if (top == value) return; - _top = value; - NotifyValueChanged ("Top", _top); + top = value; + NotifyValueChanged ("Top", top); this.RegisterForLayouting (LayoutingType.Y); } } [XmlAttributeAttribute()][DefaultValue("Stretched")] public virtual Measure Width { - get { return _width; } + get { return width; } set { - if (_width == value) + if (width == value) return; if (value.IsFixed) { if (value < MinimumSize.Width || (value > MaximumSize.Width && MaximumSize.Width > 0)) return; } Measure lastWP = WidthPolicy; - _width = value; - NotifyValueChanged ("Width", _width); + width = value; + NotifyValueChanged ("Width", width); if (WidthPolicy != lastWP) { NotifyValueChanged ("WidthPolicy", WidthPolicy); //contentSize in Stacks are only update on childLayoutChange, and the single stretched //child of the stack is not counted in contentSize, so when changing size policy of a child //we should adapt contentSize //TODO:check case when child become stretched, and another stretched item already exists. - if (_parent is GenericStack) {//TODO:check if I should test Group instead - if ((_parent as GenericStack).Orientation == Orientation.Horizontal) { + if (parent is GenericStack) {//TODO:check if I should test Group instead + if ((parent as GenericStack).Orientation == Orientation.Horizontal) { if (lastWP == Measure.Fit) - (_parent as GenericStack).contentSize.Width -= this.LastSlots.Width; + (parent as GenericStack).contentSize.Width -= this.LastSlots.Width; else - (_parent as GenericStack).contentSize.Width += this.LastSlots.Width; + (parent as GenericStack).contentSize.Width += this.LastSlots.Width; } } } @@ -271,25 +274,25 @@ namespace Crow } [XmlAttributeAttribute()][DefaultValue("Stretched")] public virtual Measure Height { - get { return _height; } + get { return height; } set { - if (_height == value) + if (height == value) return; if (value.IsFixed) { if (value < MinimumSize.Height || (value > MaximumSize.Height && MaximumSize.Height > 0)) return; } Measure lastHP = HeightPolicy; - _height = value; - NotifyValueChanged ("Height", _height); + height = value; + NotifyValueChanged ("Height", height); if (HeightPolicy != lastHP) { NotifyValueChanged ("HeightPolicy", HeightPolicy); - if (_parent is GenericStack) { - if ((_parent as GenericStack).Orientation == Orientation.Vertical) { + if (parent is GenericStack) { + if ((parent as GenericStack).Orientation == Orientation.Vertical) { if (lastHP == Measure.Fit) - (_parent as GenericStack).contentSize.Height -= this.LastSlots.Height; + (parent as GenericStack).contentSize.Height -= this.LastSlots.Height; else - (_parent as GenericStack).contentSize.Height += this.LastSlots.Height; + (parent as GenericStack).contentSize.Height += this.LastSlots.Height; } } } @@ -326,113 +329,113 @@ namespace Crow } [XmlAttributeAttribute()][DefaultValue(false)] public virtual bool Focusable { - get { return _focusable; } + get { return focusable; } set { - if (_focusable == value) + if (focusable == value) return; - _focusable = value; - NotifyValueChanged ("Focusable", _focusable); + focusable = value; + NotifyValueChanged ("Focusable", focusable); } } [XmlIgnore]public virtual bool HasFocus { - get { return _hasFocus; } + get { return hasFocus; } set { - if (value == _hasFocus) + if (value == hasFocus) return; - _hasFocus = value; - NotifyValueChanged ("HasFocus", _hasFocus); + hasFocus = value; + NotifyValueChanged ("HasFocus", hasFocus); } } [XmlIgnore]public virtual bool IsActive { - get { return _isActive; } + get { return isActive; } set { - if (value == _isActive) + if (value == isActive) return; - _isActive = value; - NotifyValueChanged ("IsActive", _isActive); + isActive = value; + NotifyValueChanged ("IsActive", isActive); } } [XmlAttributeAttribute()][DefaultValue(false)] public virtual bool MouseRepeat { - get { return _mouseRepeat; } + get { return mouseRepeat; } set { - if (_mouseRepeat == value) + if (mouseRepeat == value) return; - _mouseRepeat = value; - NotifyValueChanged ("MouseRepeat", _mouseRepeat); + mouseRepeat = value; + NotifyValueChanged ("MouseRepeat", mouseRepeat); } } [XmlAttributeAttribute()][DefaultValue("Transparent")] public virtual Fill Background { - get { return _background; } + get { return background; } set { - if (_background == value) + if (background == value) return; - _background = value; - NotifyValueChanged ("Background", _background); + background = value; + NotifyValueChanged ("Background", background); RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue("White")] public virtual Fill Foreground { - get { return _foreground; } + get { return foreground; } set { - if (_foreground == value) + if (foreground == value) return; - _foreground = value; - NotifyValueChanged ("Foreground", _foreground); + foreground = value; + NotifyValueChanged ("Foreground", foreground); RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue("sans,10")] public virtual Font Font { - get { return _font; } + get { return font; } set { - if (value == _font) + if (value == font) return; - _font = value; - NotifyValueChanged ("Font", _font); + font = value; + NotifyValueChanged ("Font", font); RegisterForGraphicUpdate (); } } [XmlAttributeAttribute()][DefaultValue(0.0)] public virtual double CornerRadius { - get { return _cornerRadius; } + get { return cornerRadius; } set { - if (value == _cornerRadius) + if (value == cornerRadius) return; - _cornerRadius = value; - NotifyValueChanged ("CornerRadius", _cornerRadius); + cornerRadius = value; + NotifyValueChanged ("CornerRadius", cornerRadius); RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(0)] public virtual int Margin { - get { return _margin; } + get { return margin; } set { - if (value == _margin) + if (value == margin) return; - _margin = value; - NotifyValueChanged ("Margin", _margin); + margin = value; + NotifyValueChanged ("Margin", margin); RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue(true)] + [XmlAttributeAttribute][DefaultValue(true)] public virtual bool Visible { - get { return _isVisible; } + get { return isVisible; } set { - if (value == _isVisible) + if (value == isVisible) return; - _isVisible = value; + isVisible = value; if (Interface.CurrentInterface == null) return; //ensure main win doesn't keep hidden childrens ref - if (!_isVisible && this.Contains (Interface.CurrentInterface.HoverWidget)) + if (!isVisible && this.Contains (Interface.CurrentInterface.HoverWidget)) Interface.CurrentInterface.HoverWidget = null; if (Parent is GraphicObject) @@ -440,36 +443,53 @@ namespace Crow if (Parent is GenericStack) (Parent as GraphicObject).RegisterForLayouting (LayoutingType.ArrangeChildren); - if (_isVisible) + if (isVisible) RegisterForLayouting (LayoutingType.Sizing); Interface.CurrentInterface.EnqueueForRepaint (this); - NotifyValueChanged ("Visible", _isVisible); + NotifyValueChanged ("Visible", isVisible); + } + } + [XmlAttributeAttribute][DefaultValue(true)] + public virtual bool IsEnabled { + get { return isEnabled; } + set { + if (value == isEnabled) + return; + + isEnabled = value; + + if (isEnabled) + onEnable (this, null); + else + onDisable (this, null); + + NotifyValueChanged ("IsEnabled", isEnabled); } } [XmlAttributeAttribute()][DefaultValue("1,1")] public virtual Size MinimumSize { - get { return _minimumSize; } + get { return minimumSize; } set { - if (value == _minimumSize) + if (value == minimumSize) return; - _minimumSize = value; + minimumSize = value; - NotifyValueChanged ("MinimumSize", _minimumSize); + NotifyValueChanged ("MinimumSize", minimumSize); RegisterForLayouting (LayoutingType.Sizing); } } [XmlAttributeAttribute()][DefaultValue("0,0")] public virtual Size MaximumSize { - get { return _maximumSize; } + get { return maximumSize; } set { - if (value == _maximumSize) + if (value == maximumSize) return; - _maximumSize = value; + maximumSize = value; - NotifyValueChanged ("MaximumSize", _maximumSize); + NotifyValueChanged ("MaximumSize", maximumSize); RegisterForLayouting (LayoutingType.Sizing); } } @@ -669,11 +689,13 @@ namespace Crow #endregion public virtual GraphicObject FindByName(string nameToFind){ - return string.Equals(nameToFind, _name, StringComparison.Ordinal) ? this : null; + return string.Equals(nameToFind, name, StringComparison.Ordinal) ? this : null; } public virtual bool Contains(GraphicObject goToFind){ return false; } + + #region Queuing public virtual void RegisterClip(Rectangle clip){ if (CacheEnabled && bmp != null) Clipping.AddRectangle (clip + ClientRectangle.Position); @@ -698,17 +720,18 @@ namespace Crow if (RegisteredLayoutings == LayoutingType.None) Interface.CurrentInterface.EnqueueForRepaint (this); } -// public Interface CurrentInterface { -// get { -// ILayoutable tmp = this.Parent; -// while (tmp != null) { -// if (tmp is Interface) -// return tmp as Interface; -// tmp = tmp.Parent; -// } -// return null; -// } -// } + // public Interface CurrentInterface { + // get { + // ILayoutable tmp = this.Parent; + // while (tmp != null) { + // if (tmp is Interface) + // return tmp as Interface; + // tmp = tmp.Parent; + // } + // return null; + // } + // } + #endregion #region Layouting @@ -941,7 +964,7 @@ namespace Crow Rectangle rBack = new Rectangle (Slot.Size); Background.SetAsSource (gr, rBack); - CairoHelpers.CairoRectangle(gr,rBack,_cornerRadius); + CairoHelpers.CairoRectangle(gr,rBack,cornerRadius); gr.Fill (); } @@ -1128,6 +1151,22 @@ namespace Crow MouseWheelChanged.Raise (this, e); } + public virtual void onMouseEnter(object sender, MouseMoveEventArgs e) + { + #if DEBUG_FOCUS + Debug.WriteLine("MouseEnter => " + this.ToString()); + #endif + MouseEnter.Raise (this, e); + } + public virtual void onMouseLeave(object sender, MouseMoveEventArgs e) + { + #if DEBUG_FOCUS + Debug.WriteLine("MouseLeave => " + this.ToString()); + #endif + MouseLeave.Raise (this, e); + } + #endregion + public virtual void onFocused(object sender, EventArgs e){ #if DEBUG_FOCUS Debug.WriteLine("Focused => " + this.ToString()); @@ -1143,22 +1182,12 @@ namespace Crow Unfocused.Raise (this, e); this.HasFocus = false; } - public virtual void onMouseEnter(object sender, MouseMoveEventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseEnter => " + this.ToString()); - #endif - MouseEnter.Raise (this, e); + public virtual void onEnable(object sender, EventArgs e){ + Enabled.Raise (this, e); } - public virtual void onMouseLeave(object sender, MouseMoveEventArgs e) - { - #if DEBUG_FOCUS - Debug.WriteLine("MouseLeave => " + this.ToString()); - #endif - MouseLeave.Raise (this, e); + public virtual void onDisable(object sender, EventArgs e){ + Disabled.Raise (this, e); } - #endregion - public override string ToString () { string tmp =""; |