]> O.S.I.I.S - jp/crow.git/commitdiff
Scalable abstract base class for path and Image, ScrollBar theming
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 20 May 2020 13:32:47 +0000 (15:32 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 20 May 2020 13:32:47 +0000 (15:32 +0200)
Crow.sln
Crow/Default.style
Crow/Templates/HScrollBar.template
Crow/Templates/ScrollBar.template
Crow/src/Widgets/Image.cs
Crow/src/Widgets/Scalable.cs [new file with mode: 0644]
Crow/src/Widgets/Shape.cs
Samples/common/ui/Interfaces/TemplatedControl/testScrollbar.crow

index bac0b9b20c63992026dc3a30a74c08ec70b9833e..0974d737e505657571decbdade1cf51e93b86bae 100644 (file)
--- a/Crow.sln
+++ b/Crow.sln
@@ -21,8 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "unitTests", "unitTests\unit
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicTests", "Samples\BasicTests\BasicTests.csproj", "{7AEB6DD5-916E-4415-84E1-78EC6E5881CE}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "glfw-sharp", "..\..\glfw-sharp\glfw-sharp.csproj", "{A07754EB-1CAF-4D2D-8247-A3B6A46FB943}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfTests", "PerfTests\PerfTests.csproj", "{18EBB41F-815E-4BF5-B80F-C9E2FAB2993A}"
 EndProject
 Global
@@ -53,10 +51,6 @@ Global
                {7AEB6DD5-916E-4415-84E1-78EC6E5881CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {7AEB6DD5-916E-4415-84E1-78EC6E5881CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {7AEB6DD5-916E-4415-84E1-78EC6E5881CE}.Release|Any CPU.Build.0 = Release|Any CPU
-               {A07754EB-1CAF-4D2D-8247-A3B6A46FB943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-               {A07754EB-1CAF-4D2D-8247-A3B6A46FB943}.Debug|Any CPU.Build.0 = Debug|Any CPU
-               {A07754EB-1CAF-4D2D-8247-A3B6A46FB943}.Release|Any CPU.ActiveCfg = Release|Any CPU
-               {A07754EB-1CAF-4D2D-8247-A3B6A46FB943}.Release|Any CPU.Build.0 = Release|Any CPU
                {18EBB41F-815E-4BF5-B80F-C9E2FAB2993A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
                {18EBB41F-815E-4BF5-B80F-C9E2FAB2993A}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {18EBB41F-815E-4BF5-B80F-C9E2FAB2993A}.Release|Any CPU.ActiveCfg = Release|Any CPU
index 666bfd81f62d10d5d858da371cd6b6d9b0e7049d..c031339e6b9deca20a8ffd38e91c491d1d4d8f0a 100644 (file)
@@ -197,31 +197,27 @@ CheckBoxAlt {
 ArrowBut {
        MouseRepeat="true";     
        Focusable="true";
-       Foreground="Onyx";
-       Background="hgradient|0:Grey|1:Jet";
-       MouseDown="{Background=hgradient|0:White|0.4:CornflowerBlue|1:Jet}";
-       MouseUp="{Background=hgradient|0:Grey|1:DimGrey}";
-       MouseEnter="{Foreground=Black}";
-       MouseLeave="{Foreground=Onyx}";
-}
-HArrowBut {
-       MouseRepeat="true";
-       Focusable="true";
-       Foreground="Onyx";
-       Background="vgradient|0:Grey|1:DimGrey";
-       MouseDown="{Background=vgradient|0:White|0.4:DarkBlue|1:Jet}";
-       MouseUp="{Background=vgradient|0:Grey|1:DimGrey}";
-       MouseEnter="{Foreground=Black}";
-       MouseLeave="{Foreground=DimGrey}";
+       
+       Foreground="Jet";
+       Background="Transparent";
+       
+       MouseUp="{Background=Transparent}";
+       MouseDown="{Background=Grey}";
+       
+       MouseEnter="{Foreground=CornflowerBlue}";
+       MouseLeave="{Foreground=Jet}";
+       
+       Margin="2";
+       KeepProportions="true";
 }
+
 ScrollBar {
     Maximum = "0";
     Value = "0";
-    Background = "Silver";
-    Foreground = "DimGrey";
-    Width = "12";
+    Foreground="Transparent";
+    Background="DimGrey";
+    Width = "12";    
     CornerRadius = "0";
-    Margin="0";
 }
 HScrollBar {
     Template = "#Crow.HScrollBar.template";
index 23a56cd9afb8235875728a651b78a4c18d084a79..18c32fdbf103ea16934c3f6e3445aa3f6b1535c4 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0"?>
 <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 G"/>
+               <Shape Style="ArrowBut" MouseDown="./onScrollBack"
+      Width="10" Size="10,10" Path="M 0.5,4.5 L 9.5,0.5 L 9.5,9.5 Z F"/>
                <Slider Name="Slider"                   
                        Orientation="{./Orientation}"
                        Value="{²./Value}"
                        Height="{./HeightPolicy}" Width="{./WidthPolicy}"
                        LargeIncrement="{./LargeIncrement}"
                        SmallIncrement="{./SmallIncrement}"
-                       CursorColor="vgradient|0:Silver|1:Grey"
-            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 G"/>
+                       CursorColor="Onyx"
+      Background="Transparent" Foreground="{./Foreground}"/>
+               <Shape Style="ArrowBut" MouseDown="./onScrollForth"
+       Width="10" Size="10,10" Path="M 0.5,0.5 L 9.5,4.5 L 0.5,9.5 Z F"/>
        </GenericStack>
 </Border>
\ No newline at end of file
index 27047829abe4247a8f878009f6827107a64d0651..c1835f13b467b27fec84b7995a56e232bde3fb8b 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 G"/>
+       Height="10" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z F"/>
                <Slider Name="Slider"                   
                        Orientation="{./Orientation}"
                        Value="{²./Value}"
                        Height="{./HeightPolicy}" Width="{./WidthPolicy}"
                        LargeIncrement="{./LargeIncrement}"
                        SmallIncrement="{./SmallIncrement}"
-                       CursorColor="hgradient|0:Silver|1:Grey"
-                       Foreground="{./Foreground}"
-            Background="Transparent"/>
+                       CursorColor="Onyx"
+                       Background="Transparent" Foreground="{./Foreground}"/>
                <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 G"/>
+      Height="10" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z F"/>
        </GenericStack>
 </Border>
\ No newline at end of file
index dd80a1bccff17ebce6f2e96aac1f048f67c109ea..b67c9d7057497bc9378c5913d60000a6072259da 100644 (file)
@@ -16,11 +16,11 @@ namespace Crow
        /// </summary>
        /// <remarks>
        /// </remarks>
-       public class Image : Widget
+       public class Image : Scalable
        {
                Picture _pic;
                string _svgSub;
-               bool scaled, keepProps;
+
                double opacity;
 
                #region Public properties
@@ -28,8 +28,8 @@ namespace Crow
                /// If false, original size will be kept in any case.
                /// </summary>
                [DefaultValue(true)]
-               public virtual bool Scaled {
-                       get { return scaled; }
+               public override bool Scaled {
+                       get => base.Scaled;
                        set {
                                if (scaled == value)
                                        return;
@@ -45,7 +45,7 @@ namespace Crow
                /// If image is scaled, proportions will be preserved.
                /// </summary>
                [DefaultValue(true)]
-               public virtual bool KeepProportions {
+               public override bool KeepProportions {
                        get { return keepProps; }
                        set {
                                if (keepProps == value)
@@ -60,8 +60,7 @@ namespace Crow
                }
                /// <summary>
                /// Image file path, may be on disk or embedded. Accepts bitmaps or SVG drawings.
-               /// </summary>
-        
+               /// </summary>        
                public string Path {
                        get { return _pic == null ? "" : _pic.Path; }
                        set {
@@ -85,8 +84,7 @@ namespace Crow
                /// <summary>
                /// Used only for svg images, repaint only node named referenced in SvgSub.
                /// If null, all the svg is rendered
-               /// </summary>
-               
+               /// </summary>          
                public string SvgSub {
                        get { return _svgSub; }
                        set {
@@ -99,8 +97,7 @@ namespace Crow
                /// <summary>
                /// Object holding the image data once loaded, may be used directely to pupulate this control without 
                /// specifying a path.
-               /// </summary>
-               
+               /// </summary>          
                public Picture Picture {
                        get { return _pic; }
                        set {
diff --git a/Crow/src/Widgets/Scalable.cs b/Crow/src/Widgets/Scalable.cs
new file mode 100644 (file)
index 0000000..adb1718
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.ComponentModel;
+
+namespace Crow
+{
+       public abstract class Scalable : Widget
+       {
+               #region CTOR
+               protected Scalable () : base () { }
+               public Scalable (Interface iface) : base (iface) { }
+               #endregion
+
+               protected bool scaled, keepProps;
+               /// <summary>
+               /// If true, content will be scalled to fit widget client area.
+               /// </summary>
+               [DefaultValue (true)]
+               public virtual bool Scaled {
+                       get { return scaled; }
+                       set {
+                               if (scaled == value)
+                                       return;
+                               scaled = value;
+                               NotifyValueChanged ("Scaled", scaled);
+                               RegisterForGraphicUpdate ();
+                       }
+               }
+               /// <summary>
+               /// If image is scaled, proportions will be preserved.
+               /// </summary>
+               [DefaultValue (true)]
+               public virtual bool KeepProportions {
+                       get { return keepProps; }
+                       set {
+                               if (keepProps == value)
+                                       return;
+                               keepProps = value;
+                               NotifyValueChanged ("KeepProportions", keepProps);
+                               RegisterForGraphicUpdate ();
+                       }
+               }
+
+
+       }
+}
index 5f5761344f26f6deccd2e60a9772627135db795b..d8b179432d26fde69ee51631110936cb77622759 100644 (file)
@@ -134,7 +134,7 @@ namespace Crow
        /// <summary>
        /// Widget for drawing a shape define with a path expression as defined in the PathParser.
        /// </summary>
-       public class Shape : Widget
+       public class Shape : Scalable
        {
                #region CTOR
                protected Shape () : base () { }
@@ -144,6 +144,7 @@ namespace Crow
                string path;
                double strokeWidth;
                Size size;
+
                /// <summary>
                /// Path expression, for syntax see 'PathParser'.
                /// </summary>
@@ -177,7 +178,6 @@ namespace Crow
                /// <summary>
                /// View box 
                /// </summary>
-               /// <value>The size.</value>
                [DefaultValue ("0,0")]
                public Size Size {
                        get { return size; }
@@ -190,6 +190,7 @@ namespace Crow
                                RegisterForLayouting (LayoutingType.Sizing);
                        }
                }
+
                protected override void onDraw (Context gr)
                {
                        base.onDraw (gr);
@@ -197,19 +198,32 @@ namespace Crow
                        if (string.IsNullOrEmpty (path))
                                return;
 
-                       gr.Save ();
+                       Rectangle cr = ClientRectangle;
+                       double widthRatio = 1f, heightRatio = 1f;
 
-                       Rectangle r = ClientRectangle;
+                       double w = (double)(contentSize.Width == 0 ? size.Width : contentSize.Width);
+                       double h = (double)(contentSize.Height == 0 ? size.Height : contentSize.Height);
 
+                       if (Scaled) {
+                               widthRatio = cr.Width / w;
+                               heightRatio = cr.Height / h;
+                       }
 
-                       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);
+                       if (KeepProportions) {
+                               if (widthRatio < heightRatio)
+                                       heightRatio = widthRatio;
+                               else
+                                       widthRatio = heightRatio;
+                       }
+
+                       gr.Save ();
 
-                       gr.Translate (r.Left, r.Top);
-                       gr.Scale (sx, sy);
+                       gr.Translate (cr.Left, cr.Top);
+                       gr.Scale (widthRatio, heightRatio);
+                       gr.Translate ((cr.Width / widthRatio - w) / 2, (cr.Height / heightRatio - h) / 2);
 
                        gr.LineWidth = strokeWidth;
-                       Foreground.SetAsSource (gr, r);
+                       Foreground.SetAsSource (gr, cr);
 
                        using (PathParser parser = new PathParser (path))
                                parser.Draw (gr);
index f8c4a9aeee78f636b97506dc7d0d33dda8d1fe88..5de771f99dc8da5f00c112de8b0fddb0afd5fc9d 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<Group Name="TopContainer" Width="400" Height="400"
-       Focusable="True" Background="Grey">
-       <ScrollBar Height="16" Orientation="Horizontal" Width="Stretched" Maximum="100"/>
+<Group Name="TopContainer" Focusable="True" Background="Onyx" Margin="50">
+       <ScrollBar  Maximum="100" Height="90%"/>
+       <ScrollBar Style="HScrollBar" Maximum="100" VerticalAlignment="Bottom"/>
 </Group>
\ No newline at end of file