Browse Source

Added TBGRASVGTheme.

lainz 5 years ago
parent
commit
c03d92b83c
3 changed files with 189 additions and 6 deletions
  1. 9 5
      bgracontrols.lpk
  2. 3 1
      bgracontrols.pas
  3. 177 0
      bgrasvgtheme.pas

+ 9 - 5
bgracontrols.lpk

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <CONFIG>
-  <Package Version="5">
+  <Package Version="4">
     <Name Value="bgracontrols"/>
     <Type Value="RunAndDesignTime"/>
     <Author Value="Dibo, Circular, Lainz and others"/>
@@ -34,7 +34,7 @@
     <Description Value="BGRA Controls is a set of graphical UI elements that you can use with Lazarus LCL applications."/>
     <License Value="Modified LGPL"/>
     <Version Major="7"/>
-    <Files Count="60">
+    <Files Count="61">
       <Item1>
         <Filename Value="atshapelinebgra.pas"/>
         <HasRegisterProc Value="True"/>
@@ -205,7 +205,7 @@
       </Item35>
       <Item36>
         <Filename Value="bgradrawerflashprogressbar.pas"/>
-        <UnitName Value="bgradrawerflashprogressbar"/>
+        <UnitName Value="BGRADrawerFlashProgressBar"/>
       </Item36>
       <Item37>
         <Filename Value="bgraflashprogressbar.pas"/>
@@ -270,7 +270,7 @@
       <Item49>
         <Filename Value="bgrathemecheckbox.pas"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="bgrathemecheckbox"/>
+        <UnitName Value="BGRAThemeCheckBox"/>
       </Item49>
       <Item50>
         <Filename Value="bgrathemeradiobutton.pas"/>
@@ -326,8 +326,12 @@
         <Filename Value="bclistboxex.pas"/>
         <UnitName Value="BCListBoxEx"/>
       </Item60>
+      <Item61>
+        <Filename Value="bgrasvgtheme.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="BGRASVGTheme"/>
+      </Item61>
     </Files>
-    <CompatibilityMode Value="True"/>
     <LazDoc Paths="fpdoc"/>
     <RequiredPkgs Count="2">
       <Item1>

+ 3 - 1
bgracontrols.pas

@@ -19,7 +19,8 @@ uses
   BGRAShape, BGRASpeedButton, BGRASpriteAnimation, BGRATheme, BGRAThemeButton, 
   BGRAThemeCheckBox, BGRAThemeRadioButton, BGRAVirtualScreen, 
   ColorSpeedButton, DTAnalogClock, DTAnalogCommon, DTAnalogGauge, 
-  dtthemedclock, dtthemedgauge, MaterialColors, BCListBoxEx, LazarusPackageIntf;
+  dtthemedclock, dtthemedgauge, MaterialColors, BCListBoxEx,
+  BGRASVGTheme, LazarusPackageIntf;
 
 implementation
 
@@ -65,6 +66,7 @@ begin
   RegisterUnit('DTAnalogGauge', @DTAnalogGauge.Register);
   RegisterUnit('dtthemedclock', @dtthemedclock.Register);
   RegisterUnit('dtthemedgauge', @dtthemedgauge.Register);
+  RegisterUnit('BGRASVGTheme', @BGRASVGTheme.Register);
 end;
 
 initialization

+ 177 - 0
bgrasvgtheme.pas

@@ -0,0 +1,177 @@
+unit BGRASVGTheme;
+
+{$mode delphi}
+
+interface
+
+uses
+  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
+  BGRATheme, BGRABitmap, BGRABitmapTypes, BGRASVG;
+
+type
+
+  { TBGRASVGTheme }
+
+  TBGRASVGTheme = class(TBGRATheme)
+  private
+    FCheckBoxChecked: String;
+    FCheckBoxUnchecked: String;
+    FRadioButtonChecked: String;
+    FRadioButtonUnchecked: String;
+    procedure SetCheckBoxChecked(AValue: String);
+    procedure SetCheckBoxUnchecked(AValue: String);
+    procedure SetRadioButtonChecked(AValue: String);
+    procedure SetRadioButtonUnchecked(AValue: String);
+
+  protected
+
+  public
+    constructor Create(AOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure DrawRadioButton(Caption: string; State: TBGRAThemeButtonState;
+    {%H-}Focused: boolean; Checked: boolean; ARect: TRect;
+      DestCanvas: TCanvas); override;
+    procedure DrawCheckBox(Caption: string; State: TBGRAThemeButtonState;
+    {%H-}Focused: boolean; Checked: boolean; ARect: TRect;
+      DestCanvas: TCanvas); override;
+  published
+    property CheckBoxUnChecked: String
+      read FCheckBoxUnchecked write SetCheckBoxUnchecked;
+    property CheckBoxChecked: String read FCheckBoxChecked
+      write SetCheckBoxChecked;
+    property RadioButtonUnchecked: String
+      read FRadioButtonUnchecked write SetRadioButtonUnchecked;
+    property RadioButtonChecked: String
+      read FRadioButtonChecked write SetRadioButtonChecked;
+  end;
+
+procedure Register;
+
+implementation
+
+procedure Register;
+begin
+  RegisterComponents('BGRA Themes', [TBGRASVGTheme]);
+end;
+
+{ TBGRASVGTheme }
+
+procedure TBGRASVGTheme.SetCheckBoxUnchecked(AValue: String);
+begin
+  if FCheckBoxUnchecked = AValue then
+    Exit;
+  FCheckBoxUnchecked := AValue;
+end;
+
+procedure TBGRASVGTheme.SetRadioButtonChecked(AValue: String);
+begin
+  if FRadioButtonChecked = AValue then
+    Exit;
+  FRadioButtonChecked := AValue;
+end;
+
+procedure TBGRASVGTheme.SetRadioButtonUnchecked(AValue: String);
+begin
+  if FRadioButtonUnchecked = AValue then
+    Exit;
+  FRadioButtonUnchecked := AValue;
+end;
+
+constructor TBGRASVGTheme.Create(AOwner: TComponent);
+begin
+  inherited Create(AOwner);
+  // https://material.io/resources/icons/
+  FCheckBoxUnchecked :=
+    '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"/></svg>';
+  FCheckBoxChecked :=
+    '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>';
+  FRadioButtonUnchecked :=
+    '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg>';
+  FRadioButtonChecked :=
+    '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M12 7c-2.76 0-5 2.24-5 5s2.24 5 5 5 5-2.24 5-5-2.24-5-5-5zm0-5C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z"/></svg>';
+end;
+
+destructor TBGRASVGTheme.Destroy;
+begin
+  inherited Destroy;
+end;
+
+procedure TBGRASVGTheme.DrawRadioButton(Caption: string;
+  State: TBGRAThemeButtonState; Focused: boolean; Checked: boolean;
+  ARect: TRect; DestCanvas: TCanvas);
+var
+  Style: TTextStyle;
+  Bitmap: TBGRABitmap;
+  svg: TBGRASVG;
+  aleft, atop, aright, abottom: integer;
+begin
+  if Checked then
+    svg := TBGRASVG.CreateFromString(FRadioButtonChecked)
+  else
+    svg := TBGRASVG.CreateFromString(FRadioButtonUnchecked);
+  Bitmap := TBGRABitmap.Create(ARect.Height, ARect.Height);
+  aleft := 0;
+  aright := Bitmap.Height;
+  atop := 0;
+  abottom := Bitmap.Height;
+  svg.StretchDraw(Bitmap.Canvas2D, aleft, atop, aright, abottom);
+  Bitmap.Draw(DestCanvas, Arect.Left, Arect.Top, False);
+  Bitmap.Free;
+  svg.Free;
+
+  if Caption <> '' then
+  begin
+    Style.Alignment := taLeftJustify;
+    Style.Layout := tlCenter;
+    Style.Wordbreak := True;
+    Style.SystemFont := False;
+    Style.Clipping := True;
+    Style.Opaque := False;
+    DestCanvas.TextRect(Rect(Arect.Height, 0, ARect.Right, ARect.Bottom),
+      ARect.Height, 0, Caption, Style);
+  end;
+end;
+
+procedure TBGRASVGTheme.SetCheckBoxChecked(AValue: String);
+begin
+  if FCheckBoxChecked = AValue then
+    Exit;
+  FCheckBoxChecked := AValue;
+end;
+
+procedure TBGRASVGTheme.DrawCheckBox(Caption: string; State: TBGRAThemeButtonState;
+  Focused: boolean; Checked: boolean; ARect: TRect; DestCanvas: TCanvas);
+var
+  Style: TTextStyle;
+  Bitmap: TBGRABitmap;
+  svg: TBGRASVG;
+  aleft, atop, aright, abottom: integer;
+begin
+  if Checked then
+    svg := TBGRASVG.CreateFromString(FCheckBoxChecked)
+  else
+    svg := TBGRASVG.CreateFromString(FCheckBoxUnchecked);
+  Bitmap := TBGRABitmap.Create(ARect.Height, ARect.Height);
+  aleft := 0;
+  aright := Bitmap.Height;
+  atop := 0;
+  abottom := Bitmap.Height;
+  svg.StretchDraw(Bitmap.Canvas2D, aleft, atop, aright, abottom);
+  Bitmap.Draw(DestCanvas, Arect.Left, Arect.Top, False);
+  Bitmap.Free;
+  svg.Free;
+
+  if Caption <> '' then
+  begin
+    Style.Alignment := taLeftJustify;
+    Style.Layout := tlCenter;
+    Style.Wordbreak := True;
+    Style.SystemFont := False;
+    Style.Clipping := True;
+    Style.Opaque := False;
+    DestCanvas.TextRect(Rect(Arect.Height, 0, ARect.Right, ARect.Bottom),
+      ARect.Height, 0, Caption, Style);
+  end;
+end;
+
+end.