]> O.S.I.I.S - jp/crow.git/commitdiff
add facilities for using icons for EnumSelector + path parsing documentation and...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 21 Apr 2020 13:45:23 +0000 (15:45 +0200)
committerj-p <jp_bruyere@hotmail.com>
Sat, 9 May 2020 22:50:02 +0000 (00:50 +0200)
28 files changed:
Crow.sln
Crow/Default.style
Crow/Templates/HScrollBar.template
Crow/Templates/ScrollBar.template
Crow/Templates/Spinner.template
Crow/src/Enums.cs
Crow/src/Widgets/Container.cs
Crow/src/Widgets/EnumSelector.cs
Crow/src/Widgets/GroupBox.cs
Crow/src/Widgets/ScrollBar.cs
Crow/src/Widgets/Shape.cs
Directory.Build.props
Samples/BasicTests/BasicTests.cs
Samples/BasicTests/BasicTests.csproj
Samples/ShowCase/main.cs
Samples/common/samples.style [new file with mode: 0644]
Samples/common/ui/Icons/Bottom.svg [new file with mode: 0644]
Samples/common/ui/Icons/Center.svg [new file with mode: 0644]
Samples/common/ui/Icons/Top.svg [new file with mode: 0644]
Samples/common/ui/Interfaces/Divers/0.crow
Samples/common/ui/Interfaces/Divers/testShape.crow
Samples/common/ui/Interfaces/GraphicObject/5.crow
Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow [new file with mode: 0644]
Samples/common/ui/images/valign.svg [new file with mode: 0644]
Samples/common/ui/templates/CheckBox2.imlt
Samples/common/ui/templates/enumGetIcons.itmp
Samples/common/ui/templates/enumSingleSVG.itmp [new file with mode: 0644]
Samples/common/ui/templates/test.style

index 18b3f358723a38f92458a42f0679c01889bb8838..20fc3366feaf4ef43737dcc23c1730393efce453 100644 (file)
--- a/Crow.sln
+++ b/Crow.sln
@@ -64,7 +64,7 @@ Global
        GlobalSection(MonoDevelopProperties) = preSolution
                Policies = $0
                $0.StandardHeader = $1
-               $1.Text = @Copyright (c) ${Year}  ${AuthorName} <${AuthorEmail}>\n\nThis code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+               $1.Text = @Copyright (c) 2013-${Year}  ${AuthorName} <${AuthorEmail}>\n\nThis code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
                $0.DotNetNamingPolicy = $2
                $0.TextStylePolicy = $3
                $3.EolMarker = Unix
index ba59c54f354bec50c73e256a461f10c73b3deda8..666bfd81f62d10d5d858da371cd6b6d9b0e7049d 100644 (file)
@@ -206,7 +206,7 @@ ArrowBut {
 }
 HArrowBut {
        MouseRepeat="true";
-    Focusable="true";
+       Focusable="true";
        Foreground="Onyx";
        Background="vgradient|0:Grey|1:DimGrey";
        MouseDown="{Background=vgradient|0:White|0.4:DarkBlue|1:Jet}";
@@ -232,9 +232,8 @@ HScrollBar {
     Orientation = "Horizontal";
 }
 EnumSelector {
-    Orientation = "Vertical";
-    Height = "Fit";
-    Spacing = "0";
+    Width = "Fit";
+    Height = "Fit";    
 }
 labColor {
        Margin="2";     
index a4ab641654ac8b06920fb15dc4202199c83a794b..23a56cd9afb8235875728a651b78a4c18d084a79 100644 (file)
@@ -2,7 +2,7 @@
 <Border BorderWidth="1" Foreground="{./Foreground}" Background="{./Background}">
        <GenericStack Orientation="{./Orientation}" Spacing="0">
                <Shape Style="HArrowBut" MouseDown="./onScrollBack"
-            Margin="1" Width="6" Size="10,10" Path="M 0.5,4.5 L 9.5,0.5 L 9.5,9.5 Z"/>
+            Margin="1" Width="6" Size="10,10" Path="M 0.5,4.5 L 9.5,0.5 L 9.5,9.5 Z G"/>
                <Slider Name="Slider"                   
                        Orientation="{./Orientation}"
                        Value="{²./Value}"
@@ -15,6 +15,6 @@
             Background="Transparent"
                        Foreground="{./Foreground}"/>
                <Shape Style="HArrowBut" MouseDown="./onScrollForth"
-            Margin="1" Width="6" Size="10,10" Path="M 0.5,0.5 L 9.5,4.5 L 0.5,9.5 Z"/>
+            Margin="1" Width="6" Size="10,10" Path="M 0.5,0.5 L 9.5,4.5 L 0.5,9.5 Z G"/>
        </GenericStack>
 </Border>
\ No newline at end of file
index 158671e5706b52b512fd3c814975da577c6282b8..27047829abe4247a8f878009f6827107a64d0651 100644 (file)
@@ -2,7 +2,7 @@
 <Border BorderWidth="1" Foreground="{./Foreground}" Background="{./Background}">
        <GenericStack Orientation="{./Orientation}" Spacing="0">
                <Shape Style="ArrowBut" MouseDown="./onScrollBack"
-            Margin="1" Height="6" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"/>
+            Margin="1" Height="6" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"/>
                <Slider Name="Slider"                   
                        Orientation="{./Orientation}"
                        Value="{²./Value}"
@@ -15,6 +15,6 @@
                        Foreground="{./Foreground}"
             Background="Transparent"/>
                <Shape Style="ArrowBut" MouseDown="./onScrollForth"
-             Margin="1" Height="6" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z"/>
+             Margin="1" Height="6" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z G"/>
        </GenericStack>
 </Border>
\ No newline at end of file
index 1bac0d1dc4ab7f007d41db60b96af051fb5a6054..f81a128a743997fff07421916f0f5331469a665b 100644 (file)
@@ -6,7 +6,7 @@
                        Text="{²./Value}" TextAlignment="Right" Margin="0"/>
        </Border>
        <VerticalStack MinimumSize="13,13" Width="16" Height="Stretched" Spacing="1" Margin="1">
-               <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"/>                   
-               <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z"/>
+               <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G"/>                 
+               <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z G"/>
        </VerticalStack>
 </HorizontalStack>
index 4c55d4514e47594f3516bc0a8e69c6d041e09589..df741d5042bde9af858764f3a534bd9e5f6bad7a 100644 (file)
@@ -1,37 +1,10 @@
-//
-// Enums.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// 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.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
 
 namespace Crow
 {
-    public enum Orientation
+       public enum Orientation
     {
         Horizontal,
         Vertical
index ce54514e28e4e9ad38085f76a4337561d2eecb4e..07ccfa9b653dd81c257532f9c4857270c850afdc 100644 (file)
@@ -1,28 +1,6 @@
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Container.cs
-//
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// 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;
index fa43e3b35d4b25f1d4e4a72102d0e663a65480af..bac4f5f6cd15b829d8f37323a0772df12a4b549e 100644 (file)
@@ -11,6 +11,11 @@ namespace Crow
        /// Convenient widget for selecting value among enum values. This is a templated control
        /// expecting a 'Group' widget named 'Content' inside the template to handle the enum values display.
        /// </summary>
+       /// <remarks>
+       /// Instanced RadioButton's names are set to enum values, and Tags are populated with a string build with
+       /// 'IconsPrefix+EnumValueName+IconsExtension to ease associating icons with values.
+       /// There's many other way to use this control, for examples see 'testEnumSelector.crow' in  the samples directory.
+       /// </remarks>
        public class EnumSelector : TemplatedControl
        {
                #region CTOR
@@ -31,11 +36,33 @@ namespace Crow
                #region private fields
                Enum enumValue;
                Type enumType;
-               string rbStyle;
+               string rbStyle, iconsPrefix, iconsExtension;
                IML.Instantiator radioButtonITor;
                #endregion
 
                #region public properties
+               [DefaultValue ("#Icons.")]
+               public string IconsPrefix {
+                       get => iconsPrefix;
+                       set {
+                               if (iconsPrefix == value)
+                                       return;
+                               iconsPrefix = value;
+                               forceRefresh ();
+                               NotifyValueChanged ("IconsPrefix", iconsPrefix);
+                       }
+               }
+               [DefaultValue (".svg")]
+               public string IconsExtension {
+                       get => iconsExtension;
+                       set {
+                               if (iconsExtension == value)
+                                       return;
+                               iconsExtension = value;
+                               forceRefresh ();
+                               NotifyValueChanged ("IconsExtension", iconsExtension);
+                       }
+               }
                /// <summary>
                /// Enum values are presented with RadioButton controls. Here you may specify a template to use
                /// for the radio buttons.
@@ -48,12 +75,7 @@ namespace Crow
                                        return;
                                rbStyle = value;
                                radioButtonITor = null;
-                               //force refresh to use new template if values are already displayed
-                               if (enumValue != null) {
-                                       Enum tmp = enumValue;
-                                       enumValue = null;
-                                       EnumValue = tmp;
-                               }
+                               forceRefresh ();
                                NotifyValueChanged ("RadioButtonStyle", rbStyle);
                        }
                }
@@ -80,12 +102,20 @@ namespace Crow
                                                        RadioButton rb = radioButtonITor.CreateInstance<RadioButton> ();
                                                        rb.Caption = en;
                                                        rb.LogicalParent = this;
+                                                       rb.Tag = $"{iconsPrefix}{en}{IconsExtension}";
                                                        if (enumValue.ToString () == en)
                                                                rb.IsChecked = true;
                                                        rb.Checked += (sender, e) => (((RadioButton)sender).LogicalParent as EnumSelector).EnumValue = (Enum)Enum.Parse (enumType, (sender as RadioButton).Caption);
                                                        enumValueContainer.AddChild (rb);
                                                }
-                                       
+
+                                       } else {
+                                               foreach (RadioButton rb in enumValueContainer.Children) {
+                                                       if (rb.Caption == enumValue.ToString ())
+                                                               rb.IsChecked = true;
+                                                       else if (rb.IsChecked)
+                                                               rb.IsChecked = false;
+                                               }
                                        }
                                } else
                                        enumValueContainer.ClearChildren ();
@@ -96,6 +126,15 @@ namespace Crow
                }
                #endregion
 
+               //force refresh to use new template if values are already displayed
+               void forceRefresh ()
+               {
+                       if (enumValue != null) {
+                               Enum tmp = enumValue;
+                               enumValue = null;
+                               EnumValue = tmp;
+                       }
+               }
        }
 }
 
index 2e32ddd5bb1648fa17a14f28f270629830fa46ea..0ec191ad8a985bcafc1cc7e3db15d2be3e11638f 100644 (file)
@@ -1,28 +1,6 @@
-//
-// GroupBox.cs
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
-// Author:
-//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// 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;
index cf6201e4e12e27c7556ae7edd70bd409e978ab5a..08ee5e0970e11c2629713ab4cfc375bc0c182f2c 100644 (file)
@@ -55,9 +55,9 @@ namespace Crow
                                _orientation = value;
                                NotifyValueChanged ("Orientation", _orientation);
                                if (_orientation == Orientation.Horizontal)
-                                       NotifyValueChanged ("ScrollBackShape", "M 1.5,3.5 L 6.5,0.5 L 6.5,6.5 Z");
+                                       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");
+                                       NotifyValueChanged ("ScrollBackShape", "M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z G");
 
                 RegisterForGraphicUpdate ();
                        }
index 952c3738b522d58565beaf8cf159ba78134e5611..ac006b82254edd0c2cfa69f9c198358111a3d2f9 100644 (file)
@@ -10,76 +10,143 @@ using Crow.Cairo;
 
 namespace Crow
 {
+       /// <summary>
+       /// String Parser for drawing shape
+       /// </summary>
+       /// <remarks>
+       /// All fields are separated by one or more space. Each statement is composed of one letter followed by 0 to n
+       /// double parameters. The following list enumerate available instructions:
+       /// - M x y: Move to (x,y) absolute coordinate.
+       /// - m x y: Relative move to by x in the horizontal direction and y in the vertical.
+       /// - L x y: Line to (x,y)
+       /// - l x y: trace line from current point by moving pen by x and y in each direction.
+       /// - R x y w h: draw rectangle at (x,y) with width and height equal to w and h.
+       /// - C x1 y1 x2 y2 x3 y3: draw bezier curve with current point as first control point, and parameters as others.
+       /// - c x1 y1 x2 y2 x3 y3: draw bezier curve with control points relative to current position.
+       /// - A x y r a1 a2: draw positive arc at (x,y) with radius r from angle a1 to angle a2.
+       /// - N x y r a1 a2: draw negative arc at (x,y) with radius r from angle a1 to angle a2.
+       /// - Z: close path
+       /// - F: fill path.
+       /// - f: fill preserve.
+       /// - G: stroke path.
+       /// - g: stroke preserve.
+       /// - S x: set line width to x.
+       /// - O r g b a: set solid color as source with rgba values.
+       /// </remarks>
        public class PathParser : StringReader
        {
-               public PathParser (string str) : base (str) {}
+               public PathParser (string str) : base (str) { }
 
-               double readDouble () {
-                       StringBuilder tmp = new StringBuilder();
+               double readDouble ()
+               {
+                       StringBuilder tmp = new StringBuilder ();
 
-                       while (Peek () >= 0) {                          
-                               char c = (char)Read();
-                               if (c.IsWhiteSpaceOrNewLine()) {
+                       while (Peek () >= 0) {
+                               char c = (char)Read ();
+                               if (c.IsWhiteSpaceOrNewLine ()) {
                                        if (tmp.Length == 0)
                                                continue;
                                        else
                                                break;
                                } else if (c == ',')
-                                       break;                          
+                                       break;
                                tmp.Append (c);
                        }
                        return double.Parse (tmp.ToString ());
                }
-               public void Draw (Context gr) {
-                       while (Peek () >= 0) {
-                               char c = (char)Read ();
-                               if (c.IsWhiteSpaceOrNewLine ())
-                                       continue;
-                               switch (c) {
-                               case 'M':
-                                       gr.MoveTo (readDouble (), readDouble ());
-                                       break;
-                               case 'm':
-                                       gr.RelMoveTo (readDouble (), readDouble ());
-                                       break;
-                               case 'L':
-                                       gr.LineTo (readDouble (), readDouble ());
-                                       break;
-                               case 'l':
-                                       gr.RelLineTo (readDouble (), readDouble ());
-                                       break;
-                               case 'C':
-                                       gr.CurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
-                                       break;
-                               case 'c':
-                                       gr.RelCurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
-                                       break;
-                               case 'Z':
-                                       gr.ClosePath ();
-                                       break;
-                               case 'F':
-                                       gr.Fill ();
-                                       break;
-                               case 'G':
-                                       gr.Stroke ();
-                                       break;
-                               default:
-                                       throw new Exception ("Invalid character in path string of Shape control");
+               public void Draw (Context gr, bool measure = false)
+               {
+                       try {
+                               while (Peek () >= 0) {
+                                       char c = (char)Read ();
+                                       if (c.IsWhiteSpaceOrNewLine ())
+                                               continue;
+                                       switch (c) {
+                                       case 'M':
+                                               gr.MoveTo (readDouble (), readDouble ());
+                                               break;
+                                       case 'm':
+                                               gr.RelMoveTo (readDouble (), readDouble ());
+                                               break;
+                                       case 'L':
+                                               gr.LineTo (readDouble (), readDouble ());
+                                               break;
+                                       case 'l':
+                                               gr.RelLineTo (readDouble (), readDouble ());
+                                               break;
+                                       case 'R':
+                                               gr.Rectangle (readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       case 'C':
+                                               gr.CurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       case 'c':
+                                               gr.RelCurveTo (readDouble (), readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       case 'A':
+                                               gr.Arc (readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       case 'N':
+                                               gr.ArcNegative (readDouble (), readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       case 'Z':
+                                               gr.ClosePath ();
+                                               break;
+                                       case 'f':
+                                               if (measure)
+                                                       continue;
+                                               gr.FillPreserve ();
+                                               break;
+                                       case 'g':
+                                               if (measure)
+                                                       break;
+                                               gr.StrokePreserve ();
+                                               break;
+                                       case 'F':
+                                               if (measure)
+                                                       break;
+                                               gr.Fill ();
+                                               break;
+                                       case 'G':
+                                               if (measure)
+                                                       break;
+                                               gr.Stroke ();
+                                               break;
+                                       case 'S':
+                                               gr.LineWidth = readDouble ();
+                                               break;
+                                       case 'O':
+                                               if (measure) {
+                                                       readDouble (); readDouble (); readDouble (); readDouble ();
+                                                       break;
+                                               }
+                                               gr.SetSourceRGBA (readDouble (), readDouble (), readDouble (), readDouble ());
+                                               break;
+                                       default:
+                                               throw new Exception ("Invalid character in path string of Shape control");
+                                       }
                                }
-                       }                       
+                       } catch (Exception ex) {
+                               System.Diagnostics.Debug.WriteLine ($"Error parsing path: {ex.Message}");
+                       }
                }
        }
+       /// <summary>
+       /// Widget for drawing a shape define with a path expression as defined in the PathParser.
+       /// </summary>
        public class Shape : Widget
        {
                #region CTOR
-               protected Shape () : base() {}
-               public Shape (Interface iface) : base (iface) {}
+               protected Shape () : base () { }
+               public Shape (Interface iface) : base (iface) { }
                #endregion
 
                string path;
                double strokeWidth;
-        Size size;
-
+               Size size;
+               /// <summary>
+               /// Path expression, for syntax see 'PathParser'.
+               /// </summary>
                public string Path {
                        get { return path; }
                        set {
@@ -91,7 +158,11 @@ namespace Crow
                                RegisterForGraphicUpdate ();
                        }
                }
-               [DefaultValue(1.0)]
+               /// <summary>
+               /// Default stroke width, may be overriden by a 'S' command in the path string.
+               /// </summary>
+               /// <value>The width of the stoke.</value>
+               [DefaultValue (1.0)]
                public double StokeWidth {
                        get { return strokeWidth; }
                        set {
@@ -103,70 +174,66 @@ namespace Crow
                                RegisterForGraphicUpdate ();
                        }
                }
-        [DefaultValue("0,0")]
-        public Size Size
-        {
-            get { return size; }
-            set
-            {
-                if (size == value)
-                    return;
-                size = value;
-                contentSize = default(Size);
-                NotifyValueChanged("Size", size);
-                RegisterForLayouting(LayoutingType.Sizing);
-            }
-        }
-        protected override void onDraw(Context gr)
-        {
+               /// <summary>
+               /// View box 
+               /// </summary>
+               /// <value>The size.</value>
+               [DefaultValue ("0,0")]
+               public Size Size {
+                       get { return size; }
+                       set {
+                               if (size == value)
+                                       return;
+                               size = value;
+                               contentSize = default (Size);
+                               NotifyValueChanged ("Size", size);
+                               RegisterForLayouting (LayoutingType.Sizing);
+                       }
+               }
+               protected override void onDraw (Context gr)
+               {
+                       base.onDraw (gr);
 
-            if (string.IsNullOrEmpty(path))
-                return;
+                       if (string.IsNullOrEmpty (path))
+                               return;
 
-            gr.Save();
+                       gr.Save ();
 
-            Rectangle r = ClientRectangle;
+                       Rectangle r = ClientRectangle;
 
 
-            double sx = (double)r.Width / (double)(contentSize.Width == 0? size.Width : contentSize.Width);
-            double sy = (double)r.Height / (double)(contentSize.Height == 0 ? size.Height : contentSize.Height);            
+                       double sx = (double)r.Width / (double)(contentSize.Width == 0 ? size.Width : contentSize.Width);
+                       double sy = (double)r.Height / (double)(contentSize.Height == 0 ? size.Height : contentSize.Height);
 
-            gr.Translate(r.Left, r.Top);
-            gr.Scale (sx,sy);
+                       gr.Translate (r.Left, r.Top);
+                       gr.Scale (sx, sy);
 
-                       using (PathParser parser = new PathParser (path))
-                               parser.Draw (gr);
-                               
-                       Background.SetAsSource (gr, r);
-                       gr.FillPreserve ();
                        gr.LineWidth = strokeWidth;
                        Foreground.SetAsSource (gr, r);
-                       gr.Stroke ();
-            gr.Restore();
+
+                       using (PathParser parser = new PathParser (path))
+                               parser.Draw (gr);
+
+                       gr.Restore ();
                }
 
 
                protected override int measureRawSize (LayoutingType lt)
                {
                        if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) {
-                if (size != default(Size))
-                    contentSize = size;
-                else
-                {
-                    using (Surface drawing = new ImageSurface(Format.A1, 1, 1))
-                    {
-                        using (Context ctx = new Context(drawing))
-                        {
-                                                       using (PathParser parser = new PathParser (path))
-                                                               parser.Draw (ctx);                                                              
-                            Rectangle r = ctx.StrokeExtents();
-                            contentSize = new Size(r.Right, r.Bottom);
-                        }
-                    }
-                }
+                               if (size != default (Size))
+                                       contentSize = size;
+                               else {
+                                       using (Context ctx = new Context (IFace.surf)) {
+                                               using (PathParser parser = new PathParser (path))
+                                                       parser.Draw (ctx, true);
+                                               Rectangle r = ctx.StrokeExtents ();
+                                               contentSize = new Size (r.Right, r.Bottom);
+                                       }
+                               }
                        }
                        return lt == LayoutingType.Width ?
-                               contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin;
+                               contentSize.Width + 2 * Margin : contentSize.Height + 2 * Margin;
                }
        }
 }
index 66bf81326e9daf3ee849ee30803e9495727301c7..4ef561d42c5baa7a4c5f89bc73b3672050248701 100644 (file)
@@ -7,8 +7,8 @@
                <Authors>Jean-Philippe Bruyère</Authors>           
                <LangVersion>7.2</LangVersion>
                
-               <CrowVersion>0.8.8</CrowVersion>
+               <CrowVersion>0.8.9</CrowVersion>
                <CrowPackageVersion>$(CrowVersion)-beta</CrowPackageVersion>
-        <CrowStbSharp>true</CrowStbSharp>
+               <CrowStbSharp>true</CrowStbSharp>
        </PropertyGroup>
 </Project>
index 8d76b31e491aff10740d4a27994393b2e2f91b75..9091730288bd7815dda8d5976adbd40c1107bca3 100644 (file)
@@ -32,8 +32,9 @@ namespace tests
                        //testFiles = new string [] { @"Interfaces/Experimental/testDock.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
                        //testFiles = new string [] { @"Interfaces/TemplatedGroup/3.crow" };
-                       //testFiles = new string [] { @"Interfaces/Divers/perfMeasures.crow" };
-                       testFiles = new string [] { @"Interfaces/Divers/colorPicker2.crow" };
+                       //testFiles = new string [] { @"Interfaces/Divers/testShape.crow" };
+                       testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.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 ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
@@ -126,6 +127,16 @@ namespace tests
                                NotifyValueChanged ("IntValue", intValue);
                        }
                }
+               VerticalAlignment currentVAlign;
+               public VerticalAlignment CurrentVAlign {
+                       get => currentVAlign;
+                       set {
+                               if (currentVAlign == value)
+                                       return;
+                               currentVAlign = value;
+                               NotifyValueChanged ("CurrentVAlign", currentVAlign);
+                       }
+               }
                void onSpinnerValueChange (object sender, ValueChangeEventArgs e)
                {
                        if (e.MemberName != "Value")
index 813b9b660d97014b1f2bb9e249c753d68f05dcfe..71a7a82942f3f45b46a2af9ba8a913c5273282a2 100644 (file)
@@ -14,6 +14,9 @@
        <ItemGroup>
                <ProjectReference Include="..\..\Crow\Crow.csproj" />
        </ItemGroup>
+       <ItemGroup>
+         <EmbeddedResource Remove="..\common\ui\templates\test.style" />
+       </ItemGroup>
        <ItemGroup>
                <Datas Include="..\data\**\*.*">
                        <Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link>
                        <LogicalName>ui.%(Filename)%(Extension)</LogicalName>
                        <Link>Templates\%(Filename)%(Extension)</Link>
                </EmbeddedResource>
-       </ItemGroup>    
+               <EmbeddedResource Include="..\common\samples.style" />
+               <EmbeddedResource Include="..\common\ui\images\**\*.*">
+                       <LogicalName>images.%(Filename)%(Extension)</LogicalName>
+                       <Link>Images\%(Filename)%(Extension)</Link>
+               </EmbeddedResource>
+               <EmbeddedResource Include="..\common\ui\Icons\*.*">
+                       <LogicalName>Icons.%(Filename)%(Extension)</LogicalName>
+                       <Link>Icons\%(Filename)%(Extension)</Link>
+               </EmbeddedResource>
+       </ItemGroup>
 </Project>
\ No newline at end of file
index d780c5116c1bae5eb5f4813b0a719d6e35259df5..ac1032900850355d20f3bb3bca4ff9de49e64291 100644 (file)
@@ -206,5 +206,11 @@ namespace tests
 
        }
 
-
+       public static class Extensions
+       {
+               public static Fill GetIcon (this Alignment align)
+               {
+                       return (Crow.Fill)Fill.Parse ("#images.valign.svg");
+               }
+       }
 }
\ No newline at end of file
diff --git a/Samples/common/samples.style b/Samples/common/samples.style
new file mode 100644 (file)
index 0000000..ff95632
--- /dev/null
@@ -0,0 +1,67 @@
+FpsLabel {
+       Width = "30";
+       Font = "droid, 10";
+       Margin = "0";
+       TextAlignment = "Center";
+}
+FpsDisp {
+       Font = "droid bold, 10";
+       Width = "60";
+       Margin = "0";
+       CornerRadius = "3";
+       TextAlignment = "Center";
+       Background = "MediumSeaGreen";
+}
+HStackMeasure {
+       Margin = "2";
+       Width = "Fit";
+       Height = "Fit";
+       Background = "DimGrey";
+}
+CheckBox2 {
+       Template= "Interfaces/CheckBox2.imlt";
+       Background = "Jet";
+       Checked="{Background=MediumSeaGreen}";
+       Unchecked = "{Background=Jet}";
+}
+CheckBox3 {
+       Template= "Interfaces/CheckBox2.imlt";
+       Background = "Jet";
+       Width = "Stretched";
+       Height = "Fit";
+       CornerRadius = "5";
+       Checked="{Background=MediumSeaGreen}";
+       Unchecked = "{Background=Jet}";
+}
+labPerf {
+       Font = "droid, 8";
+       Width = "50%";
+}
+labPerfVal{
+       Font = "droid, 8";
+       Width = "50%";
+}
+DbgLogViewer{
+       Background = "Onyx";
+       Font = "mono, 8";
+       Foreground = "LightGrey";
+       Focusable = "true";
+}
+DockWindow{
+       Background = "0.1,0.1,0.1,0.5";
+}
+
+valignStyle {
+       Template="#ui.enumSingleSVG.itmp";
+       Checked="{Background=MediumSeaGreen}";
+       Unchecked = "{Background=Black}";
+       //Initialized="GetDrawModeIcon";
+       //Initialized="{Background=Blue}";
+}
+valignStyle2 {
+       Template="#ui.enumGetIcons.itmp";
+       Checked="{Background=MediumSeaGreen}";
+       Unchecked = "{Background=Black}";
+       //Initialized="GetDrawModeIcon";
+       //Initialized="{Background=Blue}";
+}
\ No newline at end of file
diff --git a/Samples/common/ui/Icons/Bottom.svg b/Samples/common/ui/Icons/Bottom.svg
new file mode 100644 (file)
index 0000000..38e5fa6
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generated by IcoMoon.io -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16">
+<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/>
+<line id="Bottom" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="12.5" x2="14.5" y2="12.5" />
+</svg>
diff --git a/Samples/common/ui/Icons/Center.svg b/Samples/common/ui/Icons/Center.svg
new file mode 100644 (file)
index 0000000..ac2efdb
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generated by IcoMoon.io -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16">
+<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/>
+<line id="Center" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="8" x2="14.5" y2="8" />
+</svg>
diff --git a/Samples/common/ui/Icons/Top.svg b/Samples/common/ui/Icons/Top.svg
new file mode 100644 (file)
index 0000000..01d11d5
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generated by IcoMoon.io -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16">
+<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/>
+<line id="Top" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="3.5" x2="14.5" y2="3.5" />
+</svg>
index 8850e26dc6f429d6aaca0b3fb9e76c924b195c32..c98d6410da423cc889b1a8c61ca95326e01cb770 100644 (file)
                                        </VerticalStack>
                                        <Splitter />
                                        <VerticalStack Width="50%">
-                                               <RadioButton Style="RadioButton2" />
-                                               <RadioButton Style="RadioButton2" />
-                                               <RadioButton Style="RadioButton2" />
-                                               <RadioButton Style="RadioButton2" />
+                                               <RadioButton Style="CheckBox2" />
+                                               <RadioButton Style="CheckBox2" />
+                                               <RadioButton Style="CheckBox2" />
+                                               <RadioButton Style="CheckBox2" />
                                        </VerticalStack>
                                </HorizontalStack>
                        </GroupBox>
index 99b89b07aca495fc575a250c54a50112d504cd40..14af0f21e0149aae8e00242f6e76d1c476f40dc5 100644 (file)
@@ -1,6 +1,5 @@
 <?xml version="1.0"?>
-<Container Fit="true" Background="Red" Tooltip="test tooltip" >
-       <Shape Foreground="Transparent" Background="DimGrey" Size="11,11" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z"
-               MouseEnter="{Background=hgradient|0:DimGrey|0.5:RoyalBlue|1:Black}"
-               MouseLeave="{Background=DimGrey}"/>
-</Container>
\ No newline at end of file
+<VerticalStack>
+       <TextBox Text="{²../shape.Path}"/>     
+       <Shape Margin="0" Width="400" Height="400" Name="shape" Foreground="Blue" Background="DimGrey" Size="100,100" Path="M 5.5,0.5 L 10.5,10.5 L 0.5,10.5 Z G"/>                     
+</VerticalStack>
\ No newline at end of file
index 0e0560fc18de86c53b9ea649763ca2969e5b4c69..8fdf887d5c4434642d2554262b7c5a470ad9ff3e 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<HorizontalStack Width="Stretched" Height="Fit" Margin="5" Background="Mantis">
+<HorizontalStack Width="Stretched" Height="Fit" Margin="5" Background="RoyalBlue">
        <Widget Background="Carmine" Width="10%" Height="20"/>
        <Widget Background="Carmine" Width="Stretched" Height="20"/>
        <Widget Background="Carmine" Width="10%" Height="20"/>
diff --git a/Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow b/Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow
new file mode 100644 (file)
index 0000000..303f543
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<VerticalStack Spacing="5" Margin="5">
+       <Image Path="#images.valign.svg" Fit="True" Background="White" Margin="5" SvgSub="{²CurrentVAlign}"/>
+       <Border Height="100" Width="Fit" Background="Jet">
+               <Label Margin="5" Text="vertical aligned text" VerticalAlignment="{CurrentVAlign}" Background="DarkBlue"/>
+       </Border>
+       <EnumSelector Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" />
+       <EnumSelector RadioButtonStyle="CheckBox3" Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" >
+               <Template>
+                       <VerticalStack Name="Content" Width="100"/>
+               </Template>
+       </EnumSelector>
+       <EnumSelector RadioButtonStyle="CheckBox2" Name="valign" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" />
+       <EnumSelector RadioButtonStyle="valignStyle" Name="valign1" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" />
+       <EnumSelector RadioButtonStyle="valignStyle2" Name="valign2" Caption="Vertical Alignment" EnumValue="{²CurrentVAlign}" />
+</VerticalStack>
\ No newline at end of file
diff --git a/Samples/common/ui/images/valign.svg b/Samples/common/ui/images/valign.svg
new file mode 100644 (file)
index 0000000..b24cf26
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generated by IcoMoon.io -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16">
+<rect fill="#00000000" stroke="#444444" stroke-width="1" x="0.5" y="0.5" width="15" height="15"/>
+<line id="Top" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="3.5" x2="14.5" y2="3.5" />
+<line id="Center" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="8" x2="14.5" y2="8" />
+<line id="Bottom" fill="#00000000" stroke="#444444" stroke-width="4" x1="1.5" y1="12.5" x2="14.5" y2="12.5" />
+</svg>
index c2bfe8da7edaaf7d60eb2133aad5fa277652d96d..048d495bcb5d4595ab49521c66024abf062b2f0f 100644 (file)
@@ -1,4 +1,4 @@
-<Label Font="{./Font}" Text="{./Caption}" Height="{./HeightPolicy}" Width="{./WidthPolicy}"
+<Label Font="{./Font}" Text="{./Caption}" CornerRadius="{./CornerRadius}"
        Margin="3"
        Background="{./Background}"
        Foreground="DimGrey"
index 048d495bcb5d4595ab49521c66024abf062b2f0f..63f6fdbde3e37f9794c8f7e54c9d0827155224ce 100644 (file)
@@ -1,7 +1,4 @@
-<Label Font="{./Font}" Text="{./Caption}" CornerRadius="{./CornerRadius}"
-       Margin="3"
-       Background="{./Background}"
-       Foreground="DimGrey"
-       TextAlignment="Center"
-       MouseEnter="{Foreground=White}"
-       MouseLeave="{Foreground=DimGrey}"/>
\ No newline at end of file
+<Border Foreground="Grey" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Grey}">
+       <Image Path="{./Tag}" Fit="True" Margin="1" CornerRadius="{./CornerRadius}"     
+               Background="{./Background}"/>
+</Border>
\ No newline at end of file
diff --git a/Samples/common/ui/templates/enumSingleSVG.itmp b/Samples/common/ui/templates/enumSingleSVG.itmp
new file mode 100644 (file)
index 0000000..83bcfa3
--- /dev/null
@@ -0,0 +1,4 @@
+<Border Foreground="Grey" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Grey}">
+       <Image Path="#images.valign.svg" Fit="True" Margin="1" SvgSub="{./Caption}" CornerRadius="{./CornerRadius}"     
+               Background="{./Background}"/>
+</Border>
\ No newline at end of file
index 6f5dc8fb9dc3fe51a8608a55c3a19dde3c32c2a6..5f282702bb03ef11d7184d19c80927b47f919764 100644 (file)
@@ -1,49 +1 @@
-FpsLabel {
-       Width = "30";
-       Font = "droid, 10";
-       Margin = "0";
-       TextAlignment = "Center";
-}
-FpsDisp {
-       Font = "droid bold, 10";
-       Width = "60";
-       Margin = "0";
-       CornerRadius = "3";
-       TextAlignment = "Center";
-       Background = "MediumSeaGreen";
-}
-HStackMeasure {
-       Margin = "2";
-       Width = "Fit";
-       Height = "Fit";
-       Background = "DimGrey";
-}
-CheckBox2 {
-       Template= "Interfaces/CheckBox2.imlt";
-       Background = "Jet";
-       Checked="{Background=MediumSeaGreen}";
-       Unchecked = "{Background=Jet}";
-}
-RadioButton2 {
-       Template="Interfaces/CheckBox2.imlt";
-       Background = "Jet";
-       Checked = "{Background=MediumSeaGreen}";
-       Unchecked = "{Background=Jet}";
-}
-labPerf {
-       Font = "droid, 8";
-       Width = "50%";
-}
-labPerfVal{
-       Font = "droid, 8";
-       Width = "50%";
-}
-DbgLogViewer{
-       Background = "Onyx";
-       Font = "mono, 8";
-       Foreground = "LightGrey";
-       Focusable = "true";
-}
-DockWindow{
-       Background = "0.1,0.1,0.1,0.5";
-}
+
\ No newline at end of file