From: Jean-Philippe Bruyère Date: Sat, 6 Jun 2020 11:40:54 +0000 (+0200) Subject: slider as base for scrollbar, gauge widget X-Git-Tag: v0.9.5-beta~113^2~12 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=c928fc85cd1faed7273722f99b2a1edd9de14299;p=jp%2Fcrow.git slider as base for scrollbar, gauge widget --- diff --git a/Crow/Default.style b/Crow/Default.style index 0c188df6..773b1eeb 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -100,7 +100,6 @@ MessageBox { AlwaysOnTop = "true"; } Slider { - Background = "vgradient|0:Black|0.1:Grey|0.9:Grey|1:LightGrey"; Foreground = "Grey"; Height = "10"; Value="5"; @@ -228,18 +227,19 @@ ArrowBut { } ScrollBar { + Orientation = "Vertical"; Maximum = "0"; Value = "0"; Foreground="Transparent"; Background="Onyx"; - Width = "12"; + Width = "14"; CornerRadius = "0"; } HScrollBar { Template = "#Crow.HScrollBar.template"; Maximum = "0"; Value = "0"; - Height = "12"; + Height = "14"; Width = "Stretched"; Orientation = "Horizontal"; } diff --git a/Crow/Templates/HScrollBar.template b/Crow/Templates/HScrollBar.template index 393ea9a0..03e4d512 100644 --- a/Crow/Templates/HScrollBar.template +++ b/Crow/Templates/HScrollBar.template @@ -1,19 +1,12 @@ - - - + + + + + - \ No newline at end of file + diff --git a/Crow/Templates/ScrollBar.template b/Crow/Templates/ScrollBar.template index 59387a44..02685f41 100644 --- a/Crow/Templates/ScrollBar.template +++ b/Crow/Templates/ScrollBar.template @@ -1,19 +1,12 @@ - - - + + + \ No newline at end of file diff --git a/Crow/Templates/Slider.template b/Crow/Templates/Slider.template index 9c7bb705..608ba7be 100644 --- a/Crow/Templates/Slider.template +++ b/Crow/Templates/Slider.template @@ -1 +1,4 @@  + + + \ No newline at end of file diff --git a/Crow/Templates/TreeView.template b/Crow/Templates/TreeView.template index 0f4d9ebd..54910de5 100644 --- a/Crow/Templates/TreeView.template +++ b/Crow/Templates/TreeView.template @@ -11,5 +11,5 @@ LargeIncrement="{../scroller1.PageHeight}" SmallIncrement="30" CursorSize="{../scroller1.ChildHeightRatio}" Value="{²../scroller1.ScrollY}" - Maximum="{../scroller1.MaxScrollY}" Orientation="Vertical"/> + Maximum="{../scroller1.MaxScrollY}" /> diff --git a/Crow/src/Command.cs b/Crow/src/Command.cs index 5d5f85e4..940b7f48 100644 --- a/Crow/src/Command.cs +++ b/Crow/src/Command.cs @@ -1,35 +1,11 @@ -// -// Command.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; -using System.Xml.Serialization; using System.ComponentModel; -namespace Crow -{ +namespace Crow { /// /// helper class to bind in one step icon, caption, action, and validity tests to a controls /// @@ -57,7 +33,7 @@ namespace Crow Action execute; string caption; - Picture icon; + string icon; bool canExecute = true; #region Public properties @@ -66,7 +42,7 @@ namespace Crow /// [DefaultValue(true)] public virtual bool CanExecute { - get { return canExecute; } + get => canExecute; set { if (canExecute == value) return; @@ -74,6 +50,7 @@ namespace Crow NotifyValueChanged ("CanExecute", canExecute); } } + /// /// label to display in the bound control /// @@ -92,7 +69,7 @@ namespace Crow /// Icon to display in the bound control /// - public Picture Icon { + public string Icon { get { return icon; } set { if (icon == value) @@ -111,7 +88,7 @@ namespace Crow execute (); } internal void raiseAllValuesChanged(){ - NotifyValueChanged ("CanExecute", canExecute); + NotifyValueChanged ("CanExecute", CanExecute); NotifyValueChanged ("Icon", icon); NotifyValueChanged ("Caption", caption); } diff --git a/Crow/src/Widgets/Button.cs b/Crow/src/Widgets/Button.cs index db83d4b2..58a35032 100644 --- a/Crow/src/Widgets/Button.cs +++ b/Crow/src/Widgets/Button.cs @@ -17,8 +17,9 @@ namespace Crow public Button (Interface iface, string style = null) : base (iface, style) { } #endregion - string image; + string icon; bool isPressed; + Command command; public event EventHandler Pressed; public event EventHandler Released; @@ -38,17 +39,51 @@ namespace Crow } #endregion - [DefaultValue("#Crow.Images.button.svg")] - public string Image { - get { return image; } + [DefaultValue (null)] + public virtual Command Command { + get { return command; } set { - if (image == value) + if (command == value) return; - image = value; - NotifyValueChangedAuto (image); + + if (command != null) { + command.raiseAllValuesChanged (); + command.ValueChanged -= Command_ValueChanged; + } + + command = value; + + if (command != null) { + command.ValueChanged += Command_ValueChanged; + command.raiseAllValuesChanged (); + } + + NotifyValueChangedAuto (command); + } + } + + [DefaultValue ("#Crow.Images.button.svg")] + public string Icon { + get { return Command == null ? icon : Command.Icon; ; } + set { + if (icon == value) + return; + icon = value; + if (command == null) + NotifyValueChangedAuto (icon); } } - [DefaultValue(false)] + public override bool IsEnabled { + get { return Command == null ? base.IsEnabled : Command.CanExecute; } + set { base.IsEnabled = value; } + } + + public override string Caption { + get { return Command == null ? base.Caption : Command.Caption; } + set { base.Caption = value; } + } + + [DefaultValue (false)] public bool IsPressed { get { return isPressed; } @@ -67,5 +102,21 @@ namespace Crow Released.Raise (this, null); } } + + public override void onMouseClick (object sender, MouseButtonEventArgs e) + { + command?.Execute (); + e.Handled = true; + base.onMouseClick (sender, e); + } + + void Command_ValueChanged (object sender, ValueChangeEventArgs e) + { + string mName = e.MemberName; + if (mName == "CanExecute") + mName = "IsEnabled"; + NotifyValueChanged (mName, e.NewValue); + } + } } diff --git a/Crow/src/Widgets/Gauge.cs b/Crow/src/Widgets/Gauge.cs new file mode 100644 index 00000000..267692d7 --- /dev/null +++ b/Crow/src/Widgets/Gauge.cs @@ -0,0 +1,126 @@ +// Copyright (c) 2013-2020 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + + +using System; +using System.ComponentModel; +using Crow.Cairo; + +namespace Crow { + public class Gauge : Widget + { + #region CTOR + protected Gauge () {} + public Gauge (Interface iface, string style = null) : base (iface, style) { } + #endregion + + #region protected fields + protected double actualValue, minValue, maxValue; + CursorType cursorType; + Orientation orientation; + int borderWidth; + #endregion + + #region public properties + [DefaultValue (0.0)] + public virtual double Minimum { + get { return minValue; } + set { + if (minValue == value) + return; + + minValue = value; + NotifyValueChangedAuto (minValue); + RegisterForRedraw (); + } + } + [DefaultValue(100.0)] + public virtual double Maximum + { + get { return maxValue; } + set { + if (maxValue == value) + return; + + maxValue = value; + NotifyValueChangedAuto (maxValue); + RegisterForRedraw (); + } + } + [DefaultValue(0.0)] + public virtual double Value + { + get { return actualValue; } + set + { + if (value == actualValue) + return; + + if (value < minValue) + actualValue = minValue; + else if (value > maxValue) + actualValue = maxValue; + else + actualValue = value; + + NotifyValueChangedAuto (actualValue); + RegisterForGraphicUpdate(); + } + } + [DefaultValue (CursorType.Pentagone)] + public CursorType CursorType { + get => cursorType; + set { + if (cursorType == value) + return; + cursorType = value; + NotifyValueChangedAuto (cursorType); + RegisterForRedraw (); + } + } + [DefaultValue (Orientation.Horizontal)] + public virtual Orientation Orientation { + get => orientation; + set { + if (orientation == value) + return; + orientation = value; + NotifyValueChangedAuto (orientation); + RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); + } + } + /// + /// border width in pixels + /// + [DefaultValue (0)] + public virtual int BorderWidth { + get { return borderWidth; } + set { + if (borderWidth == value) + return; + borderWidth = value; + NotifyValueChangedAuto (borderWidth); + RegisterForGraphicUpdate (); + } + } + #endregion + + protected override void onDraw (Context gr) { + Rectangle cb = ClientRectangle; + + if (orientation == Orientation.Horizontal) + cb.Width = (int)(cb.Width / Maximum * Value); + else + cb.Height = (int)(cb.Height / Maximum * Value); + + Background.SetAsSource (gr, cb); + CairoHelpers.CairoRectangle (gr, cb, CornerRadius); + gr.Fill (); + Foreground.SetAsSource (gr, cb); + if (borderWidth > 0) + CairoHelpers.CairoRectangle (gr, cb, CornerRadius, borderWidth); + } + } +} + diff --git a/Crow/src/Widgets/GenericStack.cs b/Crow/src/Widgets/GenericStack.cs index f4473252..1d2c0f6a 100644 --- a/Crow/src/Widgets/GenericStack.cs +++ b/Crow/src/Widgets/GenericStack.cs @@ -6,67 +6,66 @@ using System; using System.ComponentModel; using System.Linq; -namespace Crow -{ +namespace Crow { /// /// group container that stacked its children horizontally or vertically /// - public class GenericStack : Group - { + public class GenericStack : Group { #region CTOR - protected GenericStack() {} - public GenericStack(Interface iface, string style = null) : base (iface, style) { } + protected GenericStack () { } + public GenericStack (Interface iface, string style = null) : base (iface, style) { } #endregion #region Private fields - int _spacing; - Orientation _orientation; + int spacing; + Orientation orientation; #endregion #region Public Properties - [DefaultValue(2)] - public int Spacing - { - get { return _spacing; } - set { - if (_spacing == value) + [DefaultValue (2)] + public int Spacing { + get => spacing; + set { + if (spacing == value) return; - _spacing = value; - NotifyValueChangedAuto (Spacing); - RegisterForLayouting (LayoutingType.Sizing|LayoutingType.ArrangeChildren); + spacing = value; + NotifyValueChangedAuto (spacing); + RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); } - } - [DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { _orientation = value; } - } + } + [DefaultValue (Orientation.Horizontal)] + public virtual Orientation Orientation { + get => orientation; + set { + if (orientation == value) + return; + orientation = value; + NotifyValueChangedAuto (orientation); + RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); + } + } #endregion #region GraphicObject Overrides public override bool ArrangeChildren { get { return true; } } - public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) - { + public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) { //Prevent child repositionning in the direction of stacking if (Orientation == Orientation.Horizontal) layoutType &= (~LayoutingType.X); else - layoutType &= (~LayoutingType.Y); + layoutType &= (~LayoutingType.Y); } - public override int measureRawSize (LayoutingType lt) - { - int totSpace = Math.Max(0, Spacing * (Children.Count (c => c.Visible) - 1)); + public override int measureRawSize (LayoutingType lt) { + int totSpace = Math.Max (0, Spacing * (Children.Count (c => c.Visible) - 1)); if (lt == LayoutingType.Width) { if (Orientation == Orientation.Horizontal) return contentSize.Width + totSpace + 2 * Margin; - }else if (Orientation == Orientation.Vertical) - return contentSize.Height + totSpace + 2 * Margin; - + } else if (Orientation == Orientation.Vertical) + return contentSize.Height + totSpace + 2 * Margin; + return base.measureRawSize (lt); } - public virtual void ComputeChildrenPositions() - { + public virtual void ComputeChildrenPositions () { int d = 0; if (Orientation == Orientation.Horizontal) { foreach (Widget c in Children) { @@ -78,7 +77,7 @@ namespace Crow } else { foreach (Widget c in Children) { if (!c.Visible) - continue; + continue; c.Slot.Y = d; d += c.Slot.Height + Spacing; } @@ -86,8 +85,7 @@ namespace Crow IsDirty = true; } Widget stretchedGO = null; - public override bool UpdateLayout (LayoutingType layoutType) - { + public override bool UpdateLayout (LayoutingType layoutType) { RegisteredLayoutings &= (~layoutType); if (layoutType == LayoutingType.ArrangeChildren) { @@ -104,24 +102,24 @@ namespace Crow return true; } - return base.UpdateLayout(layoutType); - } + return base.UpdateLayout (layoutType); + } - void adjustStretchedGo (LayoutingType lt){ + void adjustStretchedGo (LayoutingType lt) { if (stretchedGO == null) return; if (lt == LayoutingType.Width) { int newW = Math.Max ( - this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1), - stretchedGO.MinimumSize.Width); + 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) { + if (newW != stretchedGO.Slot.Width) { stretchedGO.Slot.Width = newW; stretchedGO.IsDirty = true; - #if DEBUG_LAYOUTING +#if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); - #endif +#endif stretchedGO.LayoutChanged -= OnChildLayoutChanges; stretchedGO.OnLayoutChanges (LayoutingType.Width); stretchedGO.LayoutChanged += OnChildLayoutChanges; @@ -136,19 +134,18 @@ namespace Crow if (newH != stretchedGO.Slot.Height) { stretchedGO.Slot.Height = newH; stretchedGO.IsDirty = true; - #if DEBUG_LAYOUTING +#if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString()); - #endif +#endif stretchedGO.LayoutChanged -= OnChildLayoutChanges; stretchedGO.OnLayoutChanges (LayoutingType.Height); stretchedGO.LayoutChanged += OnChildLayoutChanges; stretchedGO.LastSlots.Height = stretchedGO.Slot.Height; - } + } } } - public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) - { + public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { Widget go = sender as Widget; //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString()); switch (arg.LayoutType) { @@ -170,11 +167,11 @@ namespace Crow contentSize.Width += go.Slot.Width - go.LastSlots.Width; - adjustStretchedGo (LayoutingType.Width); - + adjustStretchedGo (LayoutingType.Width); + if (Width == Measure.Fit) this.RegisterForLayouting (LayoutingType.Width); - + this.RegisterForLayouting (LayoutingType.ArrangeChildren); return; } @@ -195,7 +192,7 @@ namespace Crow contentSize.Height += go.Slot.Height; } else contentSize.Height += go.Slot.Height - go.LastSlots.Height; - + adjustStretchedGo (LayoutingType.Height); if (Height == Measure.Fit) @@ -210,26 +207,24 @@ namespace Crow } #endregion - public override void RemoveChild (Widget child) - { + public override void RemoveChild (Widget child) { if (child != stretchedGO) { if (Orientation == Orientation.Horizontal) contentSize.Width -= child.LastSlots.Width; - else - contentSize.Height -= child.LastSlots.Height; + else + contentSize.Height -= child.LastSlots.Height; } base.RemoveChild (child); if (child == stretchedGO) { stretchedGO = null; RegisterForLayouting (LayoutingType.Sizing); - }else if (Orientation == Orientation.Horizontal) + } else if (Orientation == Orientation.Horizontal) adjustStretchedGo (LayoutingType.Width); - else - adjustStretchedGo (LayoutingType.Height); + else + adjustStretchedGo (LayoutingType.Height); } - public override void ClearChildren () - { + public override void ClearChildren () { base.ClearChildren (); stretchedGO = null; } diff --git a/Crow/src/Widgets/GraduatedSlider.cs b/Crow/src/Widgets/GraduatedSlider.cs index 938e0054..01b8b4cb 100644 --- a/Crow/src/Widgets/GraduatedSlider.cs +++ b/Crow/src/Widgets/GraduatedSlider.cs @@ -22,7 +22,7 @@ namespace Crow // } #endregion - protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd) + /*protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd) { Rectangle r = ClientRectangle; Foreground.SetAsSource (gr); @@ -49,6 +49,6 @@ namespace Crow gr.LineTo(new PointD(p.X, p.Y + lineLength)); } gr.Stroke(); - } + }*/ } } diff --git a/Crow/src/Widgets/Menu.cs b/Crow/src/Widgets/Menu.cs index afd40060..1abf7dd4 100644 --- a/Crow/src/Widgets/Menu.cs +++ b/Crow/src/Widgets/Menu.cs @@ -1,35 +1,10 @@ -// -// Menu.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.Xml.Serialization; using System.ComponentModel; -namespace Crow -{ +namespace Crow { public class Menu : TemplatedGroup { #region CTOR diff --git a/Crow/src/Widgets/MenuItem.cs b/Crow/src/Widgets/MenuItem.cs index 2491c49b..be7d4b33 100644 --- a/Crow/src/Widgets/MenuItem.cs +++ b/Crow/src/Widgets/MenuItem.cs @@ -1,31 +1,8 @@ -// -// MenuItem.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; -using System.Xml.Serialization; using System.ComponentModel; namespace Crow @@ -41,7 +18,7 @@ namespace Crow public event EventHandler Close; Command command; - Picture icon; + string icon; bool isOpened; Measure popWidth, popHeight; @@ -96,7 +73,7 @@ namespace Crow set { base.Caption = value; } } - public Picture Icon { + public string Icon { get { return Command == null ? icon : Command.Icon;; } set { if (icon == value) diff --git a/Crow/src/Widgets/NumericControl.cs b/Crow/src/Widgets/NumericControl.cs index 8a0eb7d6..504c7516 100644 --- a/Crow/src/Widgets/NumericControl.cs +++ b/Crow/src/Widgets/NumericControl.cs @@ -1,62 +1,35 @@ -// -// NumericControl.cs +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2013-2017 Jean-Philippe Bruyère -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + using System; -using System.Xml.Serialization; using System.ComponentModel; -namespace Crow -{ - public abstract class NumericControl : TemplatedControl +namespace Crow { + public class NumericControl : TemplatedControl { #region CTOR protected NumericControl () {} public NumericControl (Interface iface, string style = null) : base (iface, style) { } -// public NumericControl(double minimum, double maximum, double step) -// : base() -// { -// } #endregion #region protected fields - protected double _actualValue, minValue, maxValue, smallStep, bigStep; - protected int _decimals; + protected double actualValue, minValue, maxValue, smallStep, bigStep; + protected int decimals; #endregion #region public properties [DefaultValue(2)] public int Decimals { - get { return _decimals; } + get { return decimals; } set { - if (value == _decimals) + if (value == decimals) return; - _decimals = value; - NotifyValueChangedAuto (_decimals); + decimals = value; + NotifyValueChangedAuto (decimals); RegisterForGraphicUpdate(); } } @@ -114,22 +87,22 @@ namespace Crow [DefaultValue(0.0)] public virtual double Value { - get { return _actualValue; } + get { return actualValue; } set { - if (value == _actualValue) + if (value == actualValue) return; if (value < minValue) - _actualValue = minValue; + actualValue = minValue; else if (value > maxValue) - _actualValue = maxValue; + actualValue = maxValue; else - _actualValue = value; + actualValue = value; - _actualValue = Math.Round (_actualValue, _decimals); + actualValue = Math.Round (actualValue, decimals); - NotifyValueChangedAuto (_actualValue); + NotifyValueChangedAuto (actualValue); RegisterForGraphicUpdate(); } } diff --git a/Crow/src/Widgets/ProgressBar.cs b/Crow/src/Widgets/ProgressBar.cs index 816b9352..a0d8e10a 100644 --- a/Crow/src/Widgets/ProgressBar.cs +++ b/Crow/src/Widgets/ProgressBar.cs @@ -6,6 +6,7 @@ using Crow.Cairo; namespace Crow { + //TODO:to be removed, numeric control with template having Gauge child is enough public class ProgressBar : NumericControl { #region CTOR diff --git a/Crow/src/Widgets/ScrollBar.cs b/Crow/src/Widgets/ScrollBar.cs index 15695e5d..ffbd023b 100644 --- a/Crow/src/Widgets/ScrollBar.cs +++ b/Crow/src/Widgets/ScrollBar.cs @@ -2,66 +2,17 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.ComponentModel; - namespace Crow { /// /// templeted numeric control /// - public class ScrollBar : NumericControl + public class ScrollBar : Slider { - //TODO:could be replaced by a template for a Slider - - Orientation _orientation; - int _cursorSize; - #region CTOR protected ScrollBar () {} public ScrollBar(Interface iface, string style = null) : base (iface, style) { } #endregion - [DefaultValue(Orientation.Vertical)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) - return; - _orientation = value; - NotifyValueChangedAuto (_orientation); - if (_orientation == Orientation.Horizontal) - NotifyValueChanged ("ScrollBackShape", "M 1.5,3.5 L 6.5,0.5 L 6.5,6.5 Z G"); - else - NotifyValueChanged ("ScrollBackShape", "M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"); - - RegisterForGraphicUpdate (); - } - } - [DefaultValue(20)] - public virtual int CursorSize { - get { return _cursorSize; } - set { - if (_cursorSize == value) - return; - _cursorSize = value; - RegisterForGraphicUpdate (); - NotifyValueChangedAuto (_cursorSize); - } - } - public void onScrollBack (object sender, MouseButtonEventArgs e) - { - Value -= SmallIncrement; - } - public void onScrollForth (object sender, MouseButtonEventArgs e) - { - Value += SmallIncrement; - } - - public void onSliderValueChange(object sender, ValueChangeEventArgs e){ - if (e.MemberName == "Value") - Value = Convert.ToDouble(e.NewValue); - } } } diff --git a/Crow/src/Widgets/Slider.cs b/Crow/src/Widgets/Slider.cs index 4a6d8bb0..45ecbf81 100644 --- a/Crow/src/Widgets/Slider.cs +++ b/Crow/src/Widgets/Slider.cs @@ -12,173 +12,201 @@ namespace Crow /// templated numeric control to select a value /// by slidding a cursor /// - public class Slider : NumericControl + public class Slider : TemplatedControl { #region CTOR protected Slider() {} public Slider(Interface iface, string style = null) : base (iface, style) { } -// public Slider(double minimum, double maximum, double step) -// : base(minimum,maximum,step) -// { -// } #endregion #region implemented abstract members of TemplatedControl - protected override void loadTemplate (Widget template = null) { - + base.loadTemplate (template); + + cursor = child.FindByName ("Cursor"); + if (cursor == null) + return; + (cursor.Parent as Widget).LayoutChanged += HandleCursorContainerLayoutChanged; + updateCursorWidgetProps (); } + void HandleCursorContainerLayoutChanged (object sender, LayoutingEventArgs e) + { + computeCursorPosition (); + } #endregion - #region private fields - Rectangle cursor; - int _cursorSize; - Fill _cursorColor; - Orientation _orientation; - CursorType cursorType; - bool holdCursor = false; + #region protected fields + protected double actualValue, minValue, maxValue, smallStep, bigStep; + protected int decimals; #endregion - protected double unity; - - #region Public properties - [DefaultValue("vgradient|0:White|0,1:LightGrey|0,9:LightGrey|1:DimGrey")] - public virtual Fill CursorColor { - get { return _cursorColor; } + #region public properties + [DefaultValue (2)] + public int Decimals { + get { return decimals; } set { - if (_cursorColor == value) + if (value == decimals) return; - _cursorColor = value; - RegisterForRedraw (); - NotifyValueChangedAuto (_cursorColor); + decimals = value; + NotifyValueChangedAuto (decimals); + RegisterForGraphicUpdate (); } } - [DefaultValue(20)] - public virtual int CursorSize { - get { return _cursorSize; } + [DefaultValue (0.0)] + public virtual double Minimum { + get { return minValue; } set { - if (_cursorSize == value || value < 4) + if (minValue == value) return; - _cursorSize = value; - RegisterForGraphicUpdate (); - NotifyValueChangedAuto (_cursorSize); + + minValue = value; + NotifyValueChangedAuto (minValue); + RegisterForLayouting (LayoutingType.ArrangeChildren); } } - [DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation - { - get { return _orientation; } - set { - if (_orientation == value) + [DefaultValue (100.0)] + public virtual double Maximum { + get { return maxValue; } + set { + if (maxValue == value) return; - _orientation = value; - RegisterForLayouting (LayoutingType.All); - NotifyValueChangedAuto (_orientation); + maxValue = value; + NotifyValueChangedAuto (maxValue); + RegisterForLayouting (LayoutingType.ArrangeChildren); } } - [DefaultValue (CursorType.Rectangle)] - public CursorType CursorType { - get => cursorType; + [DefaultValue (1.0)] + public virtual double SmallIncrement { + get { return smallStep; } set { - if (cursorType == value) + if (smallStep == value) return; - cursorType = value; - NotifyValueChangedAuto (cursorType); - RegisterForRedraw (); + + smallStep = value; + NotifyValueChangedAuto (smallStep); + RegisterForLayouting (LayoutingType.ArrangeChildren); } } - #endregion - - #region GraphicObject Overrides - protected override void onDraw (Context gr) - { - base.onDraw (gr); - - if (Maximum <= 0) - return; - - computeCursorPosition (); - - Rectangle r = ClientRectangle; - 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); - pStart.Y += 0.5; - pEnd.Y += 0.5; - } else { - pStart = r.TopLeft + new Point (r.Width / 2, _cursorSize / 2); - pEnd = r.BottomLeft + new Point (r.Width / 2,- _cursorSize / 2); - pStart.X += 0.5; - pEnd.X += 0.5; + [DefaultValue (5.0)] + public virtual double LargeIncrement { + get { return bigStep; } + set { + if (bigStep == value) + return; + bigStep = value; + NotifyValueChangedAuto (bigStep); + RegisterForLayouting (LayoutingType.ArrangeChildren); } + } + [DefaultValue (0.0)] + public virtual double Value { + get { return actualValue; } + set { + if (value == actualValue) + return; - Background.SetAsSource(gr, r); - gr.Rectangle (r); - gr.Fill (); + if (value < minValue) + actualValue = minValue; + else if (value > maxValue) + actualValue = maxValue; + else + actualValue = value; - DrawGraduations (gr, pStart,pEnd); + actualValue = Math.Round (actualValue, decimals); - DrawCursor (gr, cursor); + NotifyValueChangedAuto (actualValue); + RegisterForLayouting (LayoutingType.ArrangeChildren); + } } #endregion - protected virtual void DrawGraduations(Context gr, PointD pStart, PointD pEnd) - { - Foreground.SetAsSource (gr); - gr.LineWidth = 1; - gr.MoveTo(pStart); - gr.LineTo(pEnd); + #region private fields + //Rectangle cursor; + int cursorSize; + //Fill _cursorColor; + Orientation _orientation; + //CursorType cursorType; + bool holdCursor = false; + #endregion + Widget cursor; + + protected double unity; - gr.Stroke(); + public override bool ArrangeChildren => true; + public override bool UpdateLayout (LayoutingType layoutType) + { + if (layoutType == LayoutingType.ArrangeChildren) + computeCursorPosition (); + + return base.UpdateLayout (layoutType); } - protected virtual void DrawCursor(Context gr, Rectangle _cursor) + + #region Public properties + [DefaultValue (Orientation.Horizontal)] + public virtual Orientation Orientation { - if (cursorType != CursorType.None) { - switch (CursorType) { - case CursorType.Rectangle: - CairoHelpers.CairoRectangle (gr, _cursor, CornerRadius); - break; - case CursorType.Circle: - gr.Arc (_cursor.CenterD, 0.5 * _cursorSize, 0, Math.PI * 2.0); - break; - case CursorType.Pentagone: - break; - } - Foreground.SetAsSource (gr, _cursor); - gr.StrokePreserve (); - } + get { return _orientation; } + set { + if (_orientation == value) + return; + _orientation = value; - CursorColor.SetAsSource(gr, _cursor); - gr.Fill(); + RegisterForLayouting (LayoutingType.All); + NotifyValueChangedAuto (_orientation); + updateCursorWidgetProps (); + } + } + [DefaultValue (20)] + public virtual int CursorSize { + get { return cursorSize; } + set { + if (cursorSize == value) + return; + cursorSize = value; + RegisterForGraphicUpdate (); + NotifyValueChangedAuto (cursorSize); + updateCursorWidgetProps (); + } } + #endregion + void updateCursorWidgetProps () + { + if (cursor == null) + return; + if (Orientation == Orientation.Horizontal) { + cursor.Width = CursorSize; + cursor.Height = Measure.Stretched; + cursor.HorizontalAlignment = HorizontalAlignment.Left; + } else { + cursor.Height = CursorSize; + cursor.Width = Measure.Stretched; + cursor.VerticalAlignment = VerticalAlignment.Top; + } + } void computeCursorPosition () - { - Rectangle r = ClientRectangle; - PointD p1; - + { + if (cursor == null) + return; + if (Maximum <= Minimum) { + cursor.Visible = false; + return; + } + cursor.Visible = true; + Rectangle r = cursor.Parent.ClientRectangle; 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 - Minimum) * unity), - (int)(p1.Y - cursor.Height / 2)); + unity = (r.Width - cursorSize) / (Maximum - Minimum); + cursor.Left = r.Left + (int)((Value - Minimum) * unity); } 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 - Minimum) * unity)); + unity = (r.Height - cursorSize) / (Maximum - Minimum); + cursor.Top = r.Top + (int)((Value - Minimum) * unity); } - //cursor.Inflate (-1); } Point mouseDownInit; double mouseDownInitValue; @@ -189,25 +217,24 @@ namespace Crow base.onMouseDown (sender, e); mouseDownInit = ScreenPointToLocal (e.Position); mouseDownInitValue = Value; - Rectangle cursInScreenCoord = ScreenCoordinates (cursor + Slot.Position); + Rectangle cursInScreenCoord = cursor == null ? default : cursor.ScreenCoordinates (cursor.Slot); if (cursInScreenCoord.ContainsOrIsEqual (e.Position)){ -// Rectangle r = ClientRectangle; -// if (r.Width - _cursorSize > 0) { -// double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize); -// mouseDownInit += new Point ((int)(Value / unit), (int)(Value / unit)); -// } + //Rectangle r = cursor.Parent.ClientRectangle; + //if (r.Width - cursorSize > 0) { + // double unit = (Maximum - Minimum) / (double)(r.Width - cursorSize); + // mouseDownInit += new Point ((int)(Value / unit), (int)(Value / unit)); + //} holdCursor = true; }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; - } + } else if (e.Position.Y < cursInScreenCoord.Top) + Value -= LargeIncrement; + else + Value += LargeIncrement; + } public override void onMouseUp (object sender,MouseButtonEventArgs e) { @@ -219,19 +246,19 @@ namespace Crow { if (holdCursor) { Point m = ScreenPointToLocal (e.Position) - mouseDownInit; - Rectangle r = ClientRectangle; + Rectangle r = cursor.Parent.ClientRectangle; if (_orientation == Orientation.Horizontal) { - if (r.Width - _cursorSize == 0) + if (r.Width - cursorSize == 0) return; - double unit = (Maximum - Minimum) / (double)(r.Width - _cursorSize); + double unit = (Maximum - Minimum) / (double)(r.Width - cursorSize); double tmp = mouseDownInitValue + (double)m.X * unit; tmp -= tmp % SmallIncrement; Value = tmp; } else { - if (r.Height - _cursorSize == 0) + if (r.Height - cursorSize == 0) return; - double unit = (Maximum - Minimum) / (double)(r.Height - _cursorSize); + double unit = (Maximum - Minimum) / (double)(r.Height - cursorSize); double tmp = mouseDownInitValue + (double)m.Y * unit; tmp -= tmp % SmallIncrement; Value = tmp; @@ -241,5 +268,14 @@ namespace Crow base.onMouseMove (sender, e); } #endregion + + public void OnDecrease (object sender, MouseButtonEventArgs e) + { + Value -= SmallIncrement; + } + public void OnIncrease (object sender, MouseButtonEventArgs e) + { + Value += SmallIncrement; + } } } diff --git a/Crow/src/Widgets/TemplatedGroup.cs b/Crow/src/Widgets/TemplatedGroup.cs index 5916af84..d06ea064 100644 --- a/Crow/src/Widgets/TemplatedGroup.cs +++ b/Crow/src/Widgets/TemplatedGroup.cs @@ -339,13 +339,13 @@ namespace Crow { /// Items loading thread /// void loading(){ - //try { + try { loadPage (data, items, dataTest); - /*} catch (Exception ex) { + } catch (Exception ex) { if (Monitor.IsEntered (IFace.LayoutMutex)) Monitor.Exit (IFace.LayoutMutex); System.Diagnostics.Debug.WriteLine ("loading thread aborted: " + ex.ToString()); - }*/ + } } // //if (!ItemTemplates.ContainsKey ("default")) diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index 96f4ce7b..ca678fdd 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -881,12 +881,12 @@ namespace Crow isEnabled = value; - if (isEnabled) + if (IsEnabled) onEnable (this, null); else onDisable (this, null); - NotifyValueChangedAuto (isEnabled); + NotifyValueChangedAuto (IsEnabled); RegisterForRedraw (); } } @@ -1782,7 +1782,7 @@ namespace Crow RecreateCache (); UpdateCache (ctx); - if (!isEnabled) + if (!IsEnabled) paintDisabled (ctx, Slot + Parent.ClientRectangle.Position); } else { Rectangle rb = Slot + Parent.ClientRectangle.Position; @@ -1791,7 +1791,7 @@ namespace Crow ctx.Translate (rb.X, rb.Y); onDraw (ctx); - if (!isEnabled) + if (!IsEnabled) paintDisabled (ctx, Slot); ctx.Restore (); @@ -1840,7 +1840,7 @@ namespace Crow { if (parent == null) return false; - if (!(isVisible & isEnabled)||IsDragged) + if (!(isVisible & IsEnabled)||IsDragged) return false; if (!parent.PointIsIn(ref m)) return false; @@ -1849,7 +1849,7 @@ namespace Crow } public virtual bool MouseIsIn(Point m) { - return (!(isVisible & isEnabled)||IsDragged) ? false : PointIsIn (ref m); + return (!(isVisible & IsEnabled)||IsDragged) ? false : PointIsIn (ref m); } public virtual void checkHoverWidget(MouseMoveEventArgs e) { diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs index 13c0758c..bfebafcd 100644 --- a/Samples/BasicTests/BasicTests.cs +++ b/Samples/BasicTests/BasicTests.cs @@ -38,7 +38,8 @@ namespace tests //testFiles = new string [] { @"Interfaces/Divers/testShape.crow" }; //testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.crow" }; //testFiles = new string [] { @"Interfaces/Divers/all.crow" }; - testFiles = new string [] { @"Interfaces/Divers/templateInStyle.crow" }; + //testFiles = new string [] { @"Interfaces/Divers/gauge.crow" }; + testFiles = new string [] { @"Interfaces/Divers/testSlider.crow" }; //testFiles = new string [] { @"Interfaces/Divers/colorPicker2.crow" }; testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray (); testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray (); diff --git a/Samples/Directory.Build.props b/Samples/Directory.Build.props index 1a85bb22..fec3cb65 100644 --- a/Samples/Directory.Build.props +++ b/Samples/Directory.Build.props @@ -34,7 +34,7 @@ images.%(Filename)%(Extension) Images\%(Filename)%(Extension) - + Icons.%(Filename)%(Extension) Icons\%(Filename)%(Extension) diff --git a/Samples/HelloWorld/ui/helloworld.crow b/Samples/HelloWorld/ui/helloworld.crow index b3facb0e..82fd4ab5 100644 --- a/Samples/HelloWorld/ui/helloworld.crow +++ b/Samples/HelloWorld/ui/helloworld.crow @@ -1,2 +1,39 @@ - - - - - \ No newline at end of file diff --git a/Samples/ShowCase/ui/Button.template b/Samples/ShowCase/ui/Button.template new file mode 100644 index 00000000..c7e2fa06 --- /dev/null +++ b/Samples/ShowCase/ui/Button.template @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Samples/ShowCase/ui/ShowCase.style b/Samples/ShowCase/ui/ShowCase.style new file mode 100644 index 00000000..0d688507 --- /dev/null +++ b/Samples/ShowCase/ui/ShowCase.style @@ -0,0 +1,4 @@ +IcoButton { + Template = "#ShowCase.Button.template"; + Background = "Onyx"; +} \ No newline at end of file diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 4805e96e..5405a5ef 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -1,32 +1,38 @@ - + - + - + - + - - - - - - -