From: Jean-Philippe Bruyère Date: Wed, 20 May 2020 13:32:47 +0000 (+0200) Subject: Scalable abstract base class for path and Image, ScrollBar theming X-Git-Tag: v0.9.5-beta~113^2~27 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=aceb88de72a83e06ef081b4f23c5e1332da38b0c;p=jp%2Fcrow.git Scalable abstract base class for path and Image, ScrollBar theming --- diff --git a/Crow.sln b/Crow.sln index bac0b9b2..0974d737 100644 --- 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 diff --git a/Crow/Default.style b/Crow/Default.style index 666bfd81..c031339e 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -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"; diff --git a/Crow/Templates/HScrollBar.template b/Crow/Templates/HScrollBar.template index 23a56cd9..18c32fdb 100644 --- a/Crow/Templates/HScrollBar.template +++ b/Crow/Templates/HScrollBar.template @@ -1,8 +1,8 @@ - + - + CursorColor="Onyx" + Background="Transparent" Foreground="{./Foreground}"/> + \ No newline at end of file diff --git a/Crow/Templates/ScrollBar.template b/Crow/Templates/ScrollBar.template index 27047829..c1835f13 100644 --- a/Crow/Templates/ScrollBar.template +++ b/Crow/Templates/ScrollBar.template @@ -2,7 +2,7 @@ + Height="10" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z F"/> + CursorColor="Onyx" + Background="Transparent" Foreground="{./Foreground}"/> + Height="10" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z F"/> \ No newline at end of file diff --git a/Crow/src/Widgets/Image.cs b/Crow/src/Widgets/Image.cs index dd80a1bc..b67c9d70 100644 --- a/Crow/src/Widgets/Image.cs +++ b/Crow/src/Widgets/Image.cs @@ -16,11 +16,11 @@ namespace Crow /// /// /// - 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. /// [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. /// [DefaultValue(true)] - public virtual bool KeepProportions { + public override bool KeepProportions { get { return keepProps; } set { if (keepProps == value) @@ -60,8 +60,7 @@ namespace Crow } /// /// Image file path, may be on disk or embedded. Accepts bitmaps or SVG drawings. - /// - + /// public string Path { get { return _pic == null ? "" : _pic.Path; } set { @@ -85,8 +84,7 @@ namespace Crow /// /// Used only for svg images, repaint only node named referenced in SvgSub. /// If null, all the svg is rendered - /// - + /// public string SvgSub { get { return _svgSub; } set { @@ -99,8 +97,7 @@ namespace Crow /// /// Object holding the image data once loaded, may be used directely to pupulate this control without /// specifying a path. - /// - + /// 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 index 00000000..adb17184 --- /dev/null +++ b/Crow/src/Widgets/Scalable.cs @@ -0,0 +1,48 @@ +// 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; + +namespace Crow +{ + public abstract class Scalable : Widget + { + #region CTOR + protected Scalable () : base () { } + public Scalable (Interface iface) : base (iface) { } + #endregion + + protected bool scaled, keepProps; + /// + /// If true, content will be scalled to fit widget client area. + /// + [DefaultValue (true)] + public virtual bool Scaled { + get { return scaled; } + set { + if (scaled == value) + return; + scaled = value; + NotifyValueChanged ("Scaled", scaled); + RegisterForGraphicUpdate (); + } + } + /// + /// If image is scaled, proportions will be preserved. + /// + [DefaultValue (true)] + public virtual bool KeepProportions { + get { return keepProps; } + set { + if (keepProps == value) + return; + keepProps = value; + NotifyValueChanged ("KeepProportions", keepProps); + RegisterForGraphicUpdate (); + } + } + + + } +} diff --git a/Crow/src/Widgets/Shape.cs b/Crow/src/Widgets/Shape.cs index 5f576134..d8b17943 100644 --- a/Crow/src/Widgets/Shape.cs +++ b/Crow/src/Widgets/Shape.cs @@ -134,7 +134,7 @@ namespace Crow /// /// Widget for drawing a shape define with a path expression as defined in the PathParser. /// - 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; + /// /// Path expression, for syntax see 'PathParser'. /// @@ -177,7 +178,6 @@ namespace Crow /// /// View box /// - /// The size. [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); diff --git a/Samples/common/ui/Interfaces/TemplatedControl/testScrollbar.crow b/Samples/common/ui/Interfaces/TemplatedControl/testScrollbar.crow index f8c4a9ae..5de771f9 100644 --- a/Samples/common/ui/Interfaces/TemplatedControl/testScrollbar.crow +++ b/Samples/common/ui/Interfaces/TemplatedControl/testScrollbar.crow @@ -1,5 +1,5 @@  - - + + + \ No newline at end of file