diff options
| author | j-p <jp.bruyere@live.be> | 2016-08-02 00:25:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-02 00:25:42 +0200 |
| commit | 7aa1b2660fa257e570fb75f4c03bb33f1d7d151e (patch) | |
| tree | 639804dec0ca0d0cfd96cec38489808f9fce197e /src | |
| parent | fd5b776826028a0c12a92f11d1daf4065d4c6024 (diff) | |
| parent | 77f7028debf55a8d6faff8e88c18e33500867774 (diff) | |
Merge pull request #13 from jpbruyere/UpdateQueuingReview
Update queuing review and styling debug
Diffstat (limited to 'src')
| -rw-r--r-- | src/GraphicObjects/Border.cs | 5 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 41 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 111 | ||||
| -rw-r--r-- | src/GraphicObjects/Grid.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/Label.cs | 24 | ||||
| -rw-r--r-- | src/GraphicObjects/ListBox.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/NumericControl.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 10 | ||||
| -rw-r--r-- | src/GraphicObjects/Scroller.cs | 4 | ||||
| -rw-r--r-- | src/GraphicObjects/Slider.cs | 3 | ||||
| -rw-r--r-- | src/GraphicObjects/TabView.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/TextBox.cs | 10 | ||||
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/Trend.cs | 12 | ||||
| -rw-r--r-- | src/Interface.cs | 158 | ||||
| -rw-r--r-- | src/StyleReader.cs | 9 |
17 files changed, 215 insertions, 202 deletions
diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index c6355726..6c1ed6a1 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -24,11 +24,6 @@ namespace Crow RegisterForGraphicUpdate (); } } - [XmlAttributeAttribute()][DefaultValue("White")] - public override Fill Foreground { - get { return base.Foreground;} - set {base.Foreground = value;} - } #endregion #region GraphicObject override diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 3ec29fb5..efa98d1a 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Xml.Serialization; +using System; namespace Crow { @@ -99,7 +100,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - RegisterForGraphicUpdate (); + Interface.CurrentInterface.EnqueueForRepaint (this); return true; } @@ -126,15 +127,22 @@ namespace Crow contentSize.Width += go.Slot.Width - go.LastSlots.Width; if (stretchedGO != null) { - stretchedGO.Slot.Width = this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1); - stretchedGO.bmp = null; + int newW = Math.Max ( + this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1), + stretchedGO.MinimumSize.Width); + if (stretchedGO.MaximumSize.Width > 0) + newW = Math.Min (newW, stretchedGO.MaximumSize.Width); + if (newW != stretchedGO.Slot.Width) { + stretchedGO.Slot.Width = newW; + stretchedGO.bmp = null; #if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); #endif - stretchedGO.LayoutChanged -= OnChildLayoutChanges; - stretchedGO.OnLayoutChanges (LayoutingType.Width); - stretchedGO.LayoutChanged += OnChildLayoutChanges; - stretchedGO.LastSlots.Width = stretchedGO.Slot.Width; + stretchedGO.LayoutChanged -= OnChildLayoutChanges; + stretchedGO.OnLayoutChanges (LayoutingType.Width); + stretchedGO.LayoutChanged += OnChildLayoutChanges; + stretchedGO.LastSlots.Width = stretchedGO.Slot.Width; + } } if (Width == Measure.Fit) @@ -158,15 +166,22 @@ namespace Crow contentSize.Height += go.Slot.Height - go.LastSlots.Height; if (stretchedGO != null) { - stretchedGO.Slot.Height = this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count -1); - stretchedGO.bmp = null; + int newH = Math.Max ( + this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count - 1), + stretchedGO.MinimumSize.Height); + if (stretchedGO.MaximumSize.Height > 0) + newH = Math.Min (newH, stretchedGO.MaximumSize.Height); + if (newH != stretchedGO.Slot.Height) { + stretchedGO.Slot.Height = newH; + stretchedGO.bmp = null; #if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); #endif - stretchedGO.LayoutChanged -= OnChildLayoutChanges; - stretchedGO.OnLayoutChanges (LayoutingType.Height); - stretchedGO.LayoutChanged += OnChildLayoutChanges; - stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; + stretchedGO.LayoutChanged -= OnChildLayoutChanges; + stretchedGO.OnLayoutChanges (LayoutingType.Height); + stretchedGO.LayoutChanged += OnChildLayoutChanges; + stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; + } } if (Height == Measure.Fit) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 8c91824d..7a2e8ec5 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -241,10 +241,22 @@ namespace Crow if (value < MinimumSize.Width || (value > MaximumSize.Width && MaximumSize.Width > 0)) return; } - + Measure lastWP = WidthPolicy; _width = value; NotifyValueChanged ("Width", _width); - NotifyValueChanged ("WidthPolicy", WidthPolicy); + 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 (lastWP == Measure.Fit) + (_parent as GenericStack).contentSize.Width -= this.LastSlots.Width; + else + (_parent as GenericStack).contentSize.Width += this.LastSlots.Width; + } + } this.RegisterForLayouting (LayoutingType.Width); } @@ -259,10 +271,18 @@ namespace Crow if (value < MinimumSize.Height || (value > MaximumSize.Height && MaximumSize.Height > 0)) return; } - + Measure lastHP = HeightPolicy; _height = value; NotifyValueChanged ("Height", _height); - NotifyValueChanged ("HeightPolicy", HeightPolicy); + if (HeightPolicy != lastHP) { + NotifyValueChanged ("HeightPolicy", HeightPolicy); + if (_parent is GenericStack) { + if (lastHP == Measure.Fit) + (_parent as GenericStack).contentSize.Height -= this.LastSlots.Height; + else + (_parent as GenericStack).contentSize.Height += this.LastSlots.Height; + } + } this.RegisterForLayouting (LayoutingType.Height); } @@ -342,7 +362,7 @@ namespace Crow return; _background = value; NotifyValueChanged ("Background", _background); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue("White")] @@ -353,7 +373,7 @@ namespace Crow return; _foreground = value; NotifyValueChanged ("Foreground", _foreground); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue("sans,10")] @@ -375,7 +395,7 @@ namespace Crow return; _cornerRadius = value; NotifyValueChanged ("CornerRadius", _cornerRadius); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -402,8 +422,8 @@ namespace Crow return; //ensure main win doesn't keep hidden childrens ref - if (!_isVisible && this.Contains (Interface.CurrentInterface.hoverWidget)) - Interface.CurrentInterface.hoverWidget = null; + if (!_isVisible && this.Contains (Interface.CurrentInterface.HoverWidget)) + Interface.CurrentInterface.HoverWidget = null; if (Parent is GraphicObject) (Parent as GraphicObject).RegisterForLayouting (LayoutingType.Sizing); @@ -412,7 +432,7 @@ namespace Crow if (_isVisible) RegisterForLayouting (LayoutingType.Sizing); - RegisterForGraphicUpdate (); + Interface.CurrentInterface.EnqueueForRepaint (this); NotifyValueChanged ("Visible", _isVisible); } @@ -497,14 +517,16 @@ namespace Crow Interface.DefaultValuesLoader [Style] (this); return; } - } - if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { - Interface.DefaultValuesLoader [thisType.FullName] (this); - return; - } - if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { - Interface.DefaultValuesLoader [thisType.Name] (this); - return; + } else { + if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { + Interface.DefaultValuesLoader [thisType.FullName] (this); + return; + } else if (!Interface.Styling.ContainsKey (thisType.FullName)) { + if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { + Interface.DefaultValuesLoader [thisType.Name] (this); + return; + } + } } List<Dictionary<string, object>> styling = new List<Dictionary<string, object>>(); @@ -516,17 +538,17 @@ namespace Crow // those files being placed in a Styles folder string styleKey = Style; if (!string.IsNullOrEmpty (Style)) { - if (Interface.CurrentInterface.Styling.ContainsKey (Style)) { - styling.Add (Interface.CurrentInterface.Styling [Style]); + if (Interface.Styling.ContainsKey (Style)) { + styling.Add (Interface.Styling [Style]); } } - if (Interface.CurrentInterface.Styling.ContainsKey (thisType.FullName)) { - styling.Add (Interface.CurrentInterface.Styling [thisType.FullName]); + if (Interface.Styling.ContainsKey (thisType.FullName)) { + styling.Add (Interface.Styling [thisType.FullName]); if (string.IsNullOrEmpty (styleKey)) styleKey = thisType.FullName; } - if (Interface.CurrentInterface.Styling.ContainsKey (thisType.Name)) { - styling.Add (Interface.CurrentInterface.Styling [thisType.Name]); + if (Interface.Styling.ContainsKey (thisType.Name)) { + styling.Add (Interface.Styling [thisType.Name]); if (string.IsNullOrEmpty (styleKey)) styleKey = thisType.Name; } @@ -582,7 +604,10 @@ namespace Crow } } if (styleIndex >= 0){ - defaultValue = styling[styleIndex] [name]; + if (pi.PropertyType.IsEnum)//maybe should be in parser.. + defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true); + else + defaultValue = styling[styleIndex] [name]; }else { DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute)); if (dv == null) @@ -685,8 +710,12 @@ namespace Crow il.Emit(OpCodes.Ret); #endregion - Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); - Interface.DefaultValuesLoader[styleKey] (this); + try { + Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); + Interface.DefaultValuesLoader[styleKey] (this); + } catch (Exception ex) { + throw new Exception ("Error applying style <" + styleKey + ">:", ex); + } } public virtual GraphicObject FindByName(string nameToFind){ @@ -701,21 +730,29 @@ namespace Crow if (Parent != null) Parent.RegisterClip (clip + Slot.Position + ClientRectangle.Position); } - public bool IsQueueForGraphicUpdate = false; - /// <summary> - /// Clear chached object and add clipping region in redraw list of interface - /// </summary> + public bool IsQueueForRedraw = false; + /// <summary> Full update, taking care of sizing policy </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForGraphicUpdate () { - Interface.RegisterForGraphicUpdate (this); + bmp = null; + if (Width == Measure.Fit || Height == Measure.Fit) + RegisterForLayouting (LayoutingType.Sizing); + Interface.CurrentInterface.EnqueueForRepaint (this); + } + /// <summary> query an update of the content, a redraw </summary> + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void RegisterForRedraw () + { + bmp = null; + Interface.CurrentInterface.EnqueueForRepaint (this); } - #region Layouting [XmlIgnore]public int LayoutingTries { get { return layoutingTries; } set { layoutingTries = value; } } - protected Size contentSize; + internal Size contentSize; /// <summary> return size of content + margins </summary> protected virtual int measureRawSize (LayoutingType lt) { return lt == LayoutingType.Width ? @@ -930,7 +967,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (this.registeredLayoutings == LayoutingType.None && bmp == null) - RegisterForGraphicUpdate (); + Interface.CurrentInterface.EnqueueForRepaint (this); return true; } @@ -1044,8 +1081,8 @@ namespace Crow } public virtual void checkHoverWidget(MouseMoveEventArgs e) { - if (Interface.CurrentInterface.hoverWidget != this) { - Interface.CurrentInterface.hoverWidget = this; + if (Interface.CurrentInterface.HoverWidget != this) { + Interface.CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 92b4f906..525827e0 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -136,7 +136,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - this.RegisterForGraphicUpdate (); + Interface.CurrentInterface.EnqueueForRepaint (this); return true; } diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 2b440ac1..48f835ac 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -290,8 +290,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (Interface.CurrentInterface.hoverWidget != this) { - Interface.CurrentInterface.hoverWidget = this; + if (Interface.CurrentInterface.HoverWidget != this) { + Interface.CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } for (int i = Children.Count - 1; i >= 0; i--) { diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 505bd69e..2f5798ee 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -79,7 +79,7 @@ namespace Crow return; selColor = value; NotifyValueChanged ("SelectionBackground", selColor); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute][DefaultValue("White")] @@ -90,7 +90,7 @@ namespace Crow return; selFontColor = value; NotifyValueChanged ("SelectionForeground", selFontColor); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute][DefaultValue(Alignment.Left)] @@ -101,8 +101,7 @@ namespace Crow if (value == _textAlignment) return; _textAlignment = value; - RegisterForGraphicUpdate (); - RegisterForGraphicUpdate (); + RegisterForRedraw (); NotifyValueChanged ("TextAlignment", _textAlignment); } } @@ -113,7 +112,7 @@ namespace Crow if (horizontalStretch == value) return; horizontalStretch = value; - RegisterForGraphicUpdate (); + RegisterForRedraw (); NotifyValueChanged ("HorizontalStretch", horizontalStretch); } } @@ -124,8 +123,8 @@ namespace Crow if (verticalStretch == value) return; verticalStretch = value; + RegisterForRedraw (); NotifyValueChanged ("VerticalStretch", verticalStretch); - } } [XmlAttributeAttribute][DefaultValue("label")] @@ -147,9 +146,8 @@ namespace Crow lines = getLines; - this.RegisterForGraphicUpdate (); - this.RegisterForLayouting (LayoutingType.Sizing); NotifyValueChanged ("Text", _text); + RegisterForGraphicUpdate (); } } [XmlAttributeAttribute][DefaultValue(false)] @@ -598,7 +596,7 @@ namespace Crow SelBegin = new Point(0,0); SelRelease = new Point (lines.LastOrDefault ().Length, lines.Count-1); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } public override void onUnfocused (object sender, EventArgs e) { @@ -606,7 +604,7 @@ namespace Crow SelBegin = -1; SelRelease = -1; - RegisterForGraphicUpdate (); + RegisterForRedraw (); } public override void onMouseMove (object sender, MouseMoveEventArgs e) { @@ -617,7 +615,7 @@ namespace Crow updatemouseLocalPos (e.Position); - RegisterForGraphicUpdate(); + RegisterForRedraw(); } public override void onMouseDown (object sender, MouseButtonEventArgs e) { @@ -626,7 +624,7 @@ namespace Crow SelBegin = -1; SelRelease = -1; SelectionInProgress = true; - RegisterForGraphicUpdate();//TODO:should put it in properties + RegisterForRedraw();//TODO:should put it in properties } //done at the end to set 'hasFocus' value after testing it @@ -641,7 +639,7 @@ namespace Crow updatemouseLocalPos (e.Position); SelectionInProgress = false; - RegisterForGraphicUpdate (); + RegisterForRedraw (); } #endregion diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 34834b8d..79efac33 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -141,7 +141,7 @@ namespace Crow using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) stream.CopyTo (templateStream); } - templateBaseType = Interface.GetTopContainerOfGOMLStream (templateStream); + templateBaseType = Interface.GetTopContainerOfXMLStream (templateStream); } lock (Interface.CurrentInterface.UpdateMutex) { diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index 0f74eb2d..b1b097c6 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -30,7 +30,7 @@ namespace Crow minValue = value; NotifyValueChanged ("Minimum", minValue); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(100.0)] @@ -43,7 +43,7 @@ namespace Crow maxValue = value; NotifyValueChanged ("Maximum", maxValue); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(1.0)] @@ -56,7 +56,7 @@ namespace Crow smallStep = value; NotifyValueChanged ("SmallIncrement", smallStep); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(5.0)] @@ -69,7 +69,7 @@ namespace Crow bigStep = value; NotifyValueChanged ("LargeIncrement", bigStep); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(0.0)] diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 16a797d7..08abf95a 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -126,21 +126,19 @@ namespace Crow LayoutingType ltChild = LayoutingType.None; if (layoutType == LayoutingType.Width) { - if (Width == Measure.Fit) - return; if (child.Width.Units == Unit.Percent) { ltChild |= LayoutingType.Width; if (child.Width.Value < 100 && child.Left == 0) ltChild |= LayoutingType.X; - } + } else if (child.Left == 0) + ltChild |= LayoutingType.X; } else if (layoutType == LayoutingType.Height) { - if (Height == Measure.Fit) - return; if (child.Height.Units == Unit.Percent) { ltChild |= LayoutingType.Height; if (child.Height.Value < 100 && child.Top == 0) ltChild |= LayoutingType.Y; - } + } else if (child.Top == 0) + ltChild |= LayoutingType.Y; } if (ltChild == LayoutingType.None) return; diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 22b36fd2..0d57cdb3 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -70,7 +70,7 @@ namespace Crow else _scrollX = value; NotifyValueChanged("ScrollX", _scrollX); - RegisterForGraphicUpdate (); + RegisterForRedraw (); Scrolled.Raise (this, new ScrollingEventArgs (Orientation.Horizontal)); } } @@ -89,7 +89,7 @@ namespace Crow else _scrollY = value; NotifyValueChanged("ScrollY", _scrollY); - RegisterForGraphicUpdate (); + RegisterForRedraw (); Scrolled.Raise (this, new ScrollingEventArgs (Orientation.Vertical)); } } diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index bce74971..526c2759 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -65,7 +65,7 @@ namespace Crow if (_cursorColor == value) return; _cursorColor = value; - RegisterForGraphicUpdate (); + RegisterForRedraw (); NotifyValueChanged ("CursorColor", _cursorColor); } } @@ -76,7 +76,6 @@ namespace Crow if (_cursorSize == value) return; _cursorSize = value; - RegisterForLayouting (LayoutingType.Sizing); RegisterForGraphicUpdate (); NotifyValueChanged ("CursorSize", _cursorSize); } diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 5afcdaad..d616ffc6 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -78,7 +78,7 @@ namespace Crow (Children [selectedTab] as TabItem).IsSelected = true; NotifyValueChanged ("SelectedTab", selectedTab); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(22)] @@ -148,7 +148,7 @@ namespace Crow //if no layouting remains in queue for item, registre for redraw if (RegisteredLayoutings == LayoutingType.None && bmp == null) - RegisterForGraphicUpdate (); + Interface.CurrentInterface.EnqueueForRepaint (this); return true; } @@ -183,8 +183,8 @@ namespace Crow #region Mouse handling public override void checkHoverWidget (MouseMoveEventArgs e) { - if (Interface.CurrentInterface.hoverWidget != this) { - Interface.CurrentInterface.hoverWidget = this; + if (Interface.CurrentInterface.HoverWidget != this) { + Interface.CurrentInterface.HoverWidget = this; onMouseEnter (this, e); } diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index fc02f0d6..5c3772b7 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -49,7 +49,7 @@ namespace Crow set { base.HasFocus = value; - RegisterForGraphicUpdate(); + RegisterForRedraw(); } } @@ -210,10 +210,6 @@ namespace Crow default: break; } - if (Width < 0) - RegisterForLayouting (LayoutingType.Width); - if (Height < 0) - RegisterForLayouting (LayoutingType.Height); RegisterForGraphicUpdate(); } public override void onKeyPress (object sender, KeyPressEventArgs e) @@ -225,10 +221,6 @@ namespace Crow SelRelease = -1; SelBegin = new Point(CurrentColumn, SelBegin.Y); - if (Width < 0) - RegisterForLayouting (LayoutingType.Width); - if (Height < 0) - RegisterForLayouting (LayoutingType.Height); RegisterForGraphicUpdate(); } #endregion diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 35b46f18..6b6f7999 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -55,7 +55,7 @@ namespace Crow if (horizontalStretch == value) return; horizontalStretch = value; - RegisterForGraphicUpdate (); + RegisterForRedraw (); NotifyValueChanged ("HorizontalStretch", horizontalStretch); } } @@ -67,8 +67,8 @@ namespace Crow if (verticalStretch == value) return; verticalStretch = value; + RegisterForRedraw (); NotifyValueChanged ("VerticalStretch", verticalStretch); - } } [XmlAttributeAttribute ()] @@ -83,8 +83,6 @@ namespace Crow return; RegisterForGraphicUpdate (); - this.RegisterForLayouting (LayoutingType.Sizing); - _text = value; diff --git a/src/GraphicObjects/Trend.cs b/src/GraphicObjects/Trend.cs index e9ff4c06..fef1e48f 100644 --- a/src/GraphicObjects/Trend.cs +++ b/src/GraphicObjects/Trend.cs @@ -41,7 +41,7 @@ namespace Crow values.Add (_value); while (values.Count > nbValues) values.RemoveAt (0); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } public Trend () @@ -61,7 +61,7 @@ namespace Crow nbValues = value; NotifyValueChanged ("NbValues", minValue); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(0.0)] @@ -73,7 +73,7 @@ namespace Crow minValue = value; NotifyValueChanged ("Minimum", minValue); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(100.0)] @@ -86,7 +86,7 @@ namespace Crow maxValue = value; NotifyValueChanged ("Maximum", maxValue); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue(20.0)] @@ -119,7 +119,7 @@ namespace Crow return; lowThresholdFill = value; NotifyValueChanged ("LowThresholdFill", lowThresholdFill); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } [XmlAttributeAttribute()][DefaultValue("DarkGreen")] @@ -130,7 +130,7 @@ namespace Crow return; highThresholdFill = value; NotifyValueChanged ("HighThresholdFill", highThresholdFill); - RegisterForGraphicUpdate (); + RegisterForRedraw (); } } protected override void onDraw (Cairo.Context gr) diff --git a/src/Interface.cs b/src/Interface.cs index dee5e146..607044d9 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -44,7 +44,8 @@ namespace Crow { #region CTOR static Interface(){ - Interface.LoadCursors (); + LoadCursors (); + LoadStyling (); FontRenderingOptions = new FontOptions (); FontRenderingOptions.Antialias = Antialias.Subpixel; @@ -54,12 +55,10 @@ namespace Crow } public Interface(){ Interface.CurrentInterface = this; - LoadStyling (); } #endregion #region Static and constants - internal bool XmlLoading = false; /// <summary> keep ressource path for debug msg </summary> internal static string CurrentGOMLPath = ""; //used in templatedControl @@ -87,32 +86,53 @@ namespace Crow public static FontOptions FontRenderingOptions; #endregion + internal bool XmlLoading = false; + public Queue<LayoutingQueueItem> LayoutingQueue = new Queue<LayoutingQueueItem> (); - public Queue<GraphicObject> GraphicUpdateQueue = new Queue<GraphicObject>(); - public Dictionary<string, Dictionary<string, object>> Styling; - public string Clipboard; - public static void RegisterForGraphicUpdate(GraphicObject g) + public Queue<GraphicObject> DrawingQueue = new Queue<GraphicObject>(); + public string Clipboard;//TODO:use object instead for complex copy paste + public void EnqueueForRepaint(GraphicObject g) { - lock (CurrentInterface.GraphicUpdateQueue) { - if (g.IsQueueForGraphicUpdate) - return; - if (CurrentInterface == null) + lock (DrawingQueue) { + if (g.IsQueueForRedraw) return; - CurrentInterface.GraphicUpdateQueue.Enqueue (g); - g.IsQueueForGraphicUpdate = true; + DrawingQueue.Enqueue (g); + g.IsQueueForRedraw = true; } } - #region default values loading helpers + #region default values and style loading /// Default values of properties from GraphicObjects are retrieve from XML Attributes. /// The reflexion process used to retrieve those values being very slow, it is compiled in MSIL /// and injected as a dynamic method referenced in the DefaultValuesLoader Dictionnary. /// The compilation is done on the first object instancing, and is also done for custom widgets public delegate void loadDefaultInvoker(object instance); public static Dictionary<String, loadDefaultInvoker> DefaultValuesLoader = new Dictionary<string, loadDefaultInvoker>(); - #endregion + public static Dictionary<string, Dictionary<string, object>> Styling; + /// <summary> parse all styling data's and build global Styling Dictionary </summary> + static void LoadStyling() { + System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; + + Styling = new Dictionary<string, Dictionary<string, object>> (); - public static void LoadCursors(){ + //fetch styling info in this order, if member styling is alreadey referenced in previous + //assembly, it's ignored. + loadStylingFromAssembly (Assembly.GetEntryAssembly ()); + loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); + + Thread.CurrentThread.CurrentCulture = savedCulture; + } + /// <summary> Search for .style resources in assembly </summary> + static void loadStylingFromAssembly (Assembly assembly) { + foreach (string s in assembly + .GetManifestResourceNames () + .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { + new StyleReader (assembly, s) + .Dispose (); + } + } + static void LoadCursors(){ //Load cursors XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0]; XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0]; @@ -123,6 +143,8 @@ namespace Crow XCursor.H = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0]; XCursor.V = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0]; } + #endregion + #region Load/Save public static Stream GetStreamFromPath (string path) @@ -151,7 +173,7 @@ namespace Crow /// Pre-read first node to set GraphicObject class for loading /// and reset stream position to 0 /// </summary> - public static Type GetTopContainerOfGOMLStream (Stream stream) + public static Type GetTopContainerOfXMLStream (Stream stream) { string root = "Object"; stream.Seek (0, SeekOrigin.Begin); @@ -197,8 +219,12 @@ namespace Crow Interface.XmlLoaderCount ++; CurrentGOMLPath = path; GraphicObject tmp = null; - using (Stream stream = GetStreamFromPath (path)) { - tmp = Load(stream, GetTopContainerOfGOMLStream(stream), hostClass); + try { + using (Stream stream = GetStreamFromPath (path)) { + tmp = Load(stream, GetTopContainerOfXMLStream(stream), hostClass); + } + } catch (Exception ex) { + throw new Exception ("Error loading <" + CurrentGOMLPath + ">:", ex); } Interface.XmlLoaderCount --; @@ -249,30 +275,6 @@ namespace Crow return tmp; } } - - public void LoadStyling() { - System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; - Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; - - Styling = new Dictionary<string, Dictionary<string, object>> (); - - //fetch styling info in this order, if member styling is alreadey referenced in previous - //assembly, it's ignored. - loadStylingFromAssembly (Assembly.GetEntryAssembly ()); - loadStylingFromAssembly (Assembly.GetExecutingAssembly ()); - - Thread.CurrentThread.CurrentCulture = savedCulture; - } - - void loadStylingFromAssembly (Assembly assembly) { - foreach (string s in assembly - .GetManifestResourceNames () - .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { - - StyleReader sr = new StyleReader (assembly, s); - sr.Dispose (); - } - } #endregion #if MEASURE_TIME @@ -283,12 +285,10 @@ namespace Crow #endif public List<GraphicObject> GraphicTree = new List<GraphicObject>(); - public Color Background = Color.Transparent; - internal static Interface currentWindow; public static Interface CurrentInterface; - Rectangles _redrawClip = new Rectangles();//should find another way to access it from child + Rectangles _redrawClip = new Rectangles(); Context ctx; Surface surf; @@ -330,7 +330,7 @@ namespace Crow #endif } } - public GraphicObject hoverWidget + public GraphicObject HoverWidget { get { return _hoverWidget; } set { @@ -380,24 +380,6 @@ namespace Crow processDrawing (); Monitor.Exit (UpdateMutex); - - // if (ToolTip.isVisible) { - // ToolTip.panel.processkLayouting(); - // if (ToolTip.panel.layoutIsValid) - // ToolTip.panel.Paint(ref ctx); - // } - // Debug.WriteLine("INTERFACE: layouting: {0} ticks \t graphical update {1} ticks \t drawing {2} ticks", - // layoutTime.ElapsedTicks, - // guTime.ElapsedTicks, - // drawingTime.ElapsedTicks); - // Debug.WriteLine("INTERFACE: layouting: {0} ms \t graphical update {1} ms \t drawing {2} ms", - // layoutTime.ElapsedMilliseconds, - // guTime.ElapsedMilliseconds, - // drawingTime.ElapsedMilliseconds); - - // Debug.WriteLine("UPDATE: {0} ticks \t, {1} ms", - // updateTime.ElapsedTicks, - // updateTime.ElapsedMilliseconds); } void processLayouting(){ #if MEASURE_TIME @@ -419,16 +401,16 @@ namespace Crow #if MEASURE_TIME clippingTime.Restart (); #endif - lock (CurrentInterface.GraphicUpdateQueue) { - while (CurrentInterface.GraphicUpdateQueue.Count > 0) { - GraphicObject g = CurrentInterface.GraphicUpdateQueue.Dequeue (); - g.bmp = null; - g.IsQueueForGraphicUpdate = false; + lock (CurrentInterface.DrawingQueue) { + while (CurrentInterface.DrawingQueue.Count > 0) { + GraphicObject g = CurrentInterface.DrawingQueue.Dequeue (); + g.IsQueueForRedraw = false; try { if (g.Parent == null) continue; g.Parent.RegisterClip (g.LastPaintedSlot); - g.Parent.RegisterClip (g.getSlot ()); + if (g.getSlot () != g.LastPaintedSlot) + g.Parent.RegisterClip (g.getSlot ()); } catch (Exception ex) { Debug.WriteLine ("Error Register Clip: " + ex.ToString ()); } @@ -519,7 +501,7 @@ namespace Crow { GraphicTree.Remove(g); GraphicTree.Insert(0, g); - //g.registerClipRect (); + EnqueueForRepaint (g); } } /// <summary> Remove all Graphic objects from top container </summary> @@ -596,10 +578,10 @@ namespace Crow return true; } - if (hoverWidget != null) { + if (HoverWidget != null) { //TODO, ensure object is still in the graphic tree //check topmost graphicobject first - GraphicObject tmp = hoverWidget; + GraphicObject tmp = HoverWidget; GraphicObject topc = null; while (tmp is GraphicObject) { topc = tmp; @@ -610,7 +592,7 @@ namespace Crow int i = 0; while (i < idxhw) { if (GraphicTree [i].MouseIsIn (e.Position)) { - hoverWidget.onMouseLeave (this, e); + HoverWidget.onMouseLeave (this, e); GraphicTree [i].checkHoverWidget (e); return true; } @@ -619,19 +601,19 @@ namespace Crow } - if (hoverWidget.MouseIsIn (e.Position)) { - hoverWidget.checkHoverWidget (e); + if (HoverWidget.MouseIsIn (e.Position)) { + HoverWidget.checkHoverWidget (e); return true; } else { - hoverWidget.onMouseLeave (this, e); + HoverWidget.onMouseLeave (this, e); //seek upward from last focused graph obj's - while (hoverWidget.Parent as GraphicObject != null) { - hoverWidget = hoverWidget.Parent as GraphicObject; - if (hoverWidget.MouseIsIn (e.Position)) { - hoverWidget.checkHoverWidget (e); + while (HoverWidget.Parent as GraphicObject != null) { + HoverWidget = HoverWidget.Parent as GraphicObject; + if (HoverWidget.MouseIsIn (e.Position)) { + HoverWidget.checkHoverWidget (e); return true; } else - hoverWidget.onMouseLeave (this, e); + HoverWidget.onMouseLeave (this, e); } } } @@ -645,7 +627,7 @@ namespace Crow return true; } } - hoverWidget = null; + HoverWidget = null; return false; } public bool ProcessMouseButtonUp(int button) @@ -671,10 +653,10 @@ namespace Crow Mouse.EnableBit (button); MouseButtonEventArgs e = new MouseButtonEventArgs () { Mouse = Mouse }; - if (hoverWidget == null) + if (HoverWidget == null) return false; - hoverWidget.onMouseDown(hoverWidget,new BubblingMouseButtonEventArg(e)); + HoverWidget.onMouseDown(HoverWidget,new BubblingMouseButtonEventArg(e)); if (FocusedWidget == null) return true; @@ -690,9 +672,9 @@ namespace Crow Mouse.SetScrollRelative (0, delta); MouseWheelEventArgs e = new MouseWheelEventArgs () { Mouse = Mouse, DeltaPrecise = delta }; - if (hoverWidget == null) + if (HoverWidget == null) return false; - hoverWidget.onMouseWheel (this, e); + HoverWidget.onMouseWheel (this, e); return true; } diff --git a/src/StyleReader.cs b/src/StyleReader.cs index 11174e29..92b24e2d 100644 --- a/src/StyleReader.cs +++ b/src/StyleReader.cs @@ -34,7 +34,6 @@ namespace Crow public StyleReader (Assembly assembly, string resId) : base(assembly.GetManifestResourceStream (resId)) { - Interface iface = Interface.CurrentInterface; string styleKey = resId.Substring (0, resId.Length - 6); string token = ""; List<string> targetsClasses = new List<string> (); @@ -105,11 +104,11 @@ namespace Crow string expression = token.Trim (); foreach (string tc in targetsClasses) { - if (!iface.Styling.ContainsKey (tc)) - iface.Styling [tc] = new Dictionary<string, object> (); - else if (iface.Styling [tc].ContainsKey (currentProperty)) + if (!Interface.Styling.ContainsKey (tc)) + Interface.Styling [tc] = new Dictionary<string, object> (); + else if (Interface.Styling [tc].ContainsKey (currentProperty)) continue; - iface.Styling [tc] [currentProperty] = expression; + Interface.Styling [tc] [currentProperty] = expression; } token = ""; } |