Browse Source

Added bgracustomdrawn.pas

lainz 9 years ago
parent
commit
1a90822a3e

+ 49 - 41
bgracontrols.lpk

@@ -21,8 +21,8 @@
         </Debugging>
         </Debugging>
       </Linking>
       </Linking>
     </CompilerOptions>
     </CompilerOptions>
-    <Version Major="3" Minor="9"/>
-    <Files Count="35">
+    <Version Major="4"/>
+    <Files Count="36">
       <Item1>
       <Item1>
         <Filename Value="bcbasectrls.pas"/>
         <Filename Value="bcbasectrls.pas"/>
         <UnitName Value="BCBaseCtrls"/>
         <UnitName Value="BCBaseCtrls"/>
@@ -104,103 +104,111 @@
         <UnitName Value="bctypes"/>
         <UnitName Value="bctypes"/>
       </Item17>
       </Item17>
       <Item18>
       <Item18>
-        <Filename Value="bgraflashprogressbar.pas"/>
+        <Filename Value="bgracustomdrawn.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="BGRAFlashProgressBar"/>
+        <UnitName Value="bgracustomdrawn"/>
       </Item18>
       </Item18>
       <Item19>
       <Item19>
-        <Filename Value="bgragraphiccontrol.pas"/>
+        <Filename Value="bgraflashprogressbar.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="BGRAGraphicControl"/>
+        <UnitName Value="BGRAFlashProgressBar"/>
       </Item19>
       </Item19>
       <Item20>
       <Item20>
-        <Filename Value="bgraimagelist.pas"/>
+        <Filename Value="bgragraphiccontrol.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="BGRAImageList"/>
+        <UnitName Value="BGRAGraphicControl"/>
       </Item20>
       </Item20>
       <Item21>
       <Item21>
-        <Filename Value="bgraimagemanipulation.pas"/>
+        <Filename Value="bgraimagelist.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="BGRAImageManipulation"/>
+        <UnitName Value="BGRAImageList"/>
       </Item21>
       </Item21>
       <Item22>
       <Item22>
-        <Filename Value="bgraknob.pas"/>
+        <Filename Value="bgraimagemanipulation.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
-        <UnitName Value="BGRAKnob"/>
+        <UnitName Value="BGRAImageManipulation"/>
       </Item22>
       </Item22>
       <Item23>
       <Item23>
-        <Filename Value="bgrapascalscript.pas"/>
-        <UnitName Value="BGRAPascalScript"/>
+        <Filename Value="bgraknob.pas"/>
+        <HasRegisterProc Value="True"/>
+        <UnitName Value="BGRAKnob"/>
       </Item23>
       </Item23>
       <Item24>
       <Item24>
+        <Filename Value="bgrapascalscript.pas"/>
+        <UnitName Value="BGRAPascalScript"/>
+      </Item24>
+      <Item25>
         <Filename Value="bgraresizespeedbutton.pas"/>
         <Filename Value="bgraresizespeedbutton.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="BGRAResizeSpeedButton"/>
         <UnitName Value="BGRAResizeSpeedButton"/>
-      </Item24>
-      <Item25>
-        <Filename Value="bgrascript.pas"/>
-        <UnitName Value="BGRAScript"/>
       </Item25>
       </Item25>
       <Item26>
       <Item26>
+        <Filename Value="bgrascript.pas"/>
+        <UnitName Value="BGRAScript"/>
+      </Item26>
+      <Item27>
         <Filename Value="bgrashape.pas"/>
         <Filename Value="bgrashape.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="BGRAShape"/>
         <UnitName Value="BGRAShape"/>
-      </Item26>
-      <Item27>
+      </Item27>
+      <Item28>
         <Filename Value="bgraspeedbutton.pas"/>
         <Filename Value="bgraspeedbutton.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="BGRASpeedButton"/>
         <UnitName Value="BGRASpeedButton"/>
-      </Item27>
-      <Item28>
+      </Item28>
+      <Item29>
         <Filename Value="bgraspriteanimation.pas"/>
         <Filename Value="bgraspriteanimation.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="BGRASpriteAnimation"/>
         <UnitName Value="BGRASpriteAnimation"/>
-      </Item28>
-      <Item29>
+      </Item29>
+      <Item30>
         <Filename Value="bgravirtualscreen.pas"/>
         <Filename Value="bgravirtualscreen.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="BGRAVirtualScreen"/>
         <UnitName Value="BGRAVirtualScreen"/>
-      </Item29>
-      <Item30>
+      </Item30>
+      <Item31>
         <Filename Value="dtanalogclock.pas"/>
         <Filename Value="dtanalogclock.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="DTAnalogClock"/>
         <UnitName Value="DTAnalogClock"/>
-      </Item30>
-      <Item31>
-        <Filename Value="dtanalogcommon.pp"/>
-        <UnitName Value="DTAnalogCommon"/>
       </Item31>
       </Item31>
       <Item32>
       <Item32>
+        <Filename Value="dtanalogcommon.pp"/>
+        <UnitName Value="DTAnalogCommon"/>
+      </Item32>
+      <Item33>
         <Filename Value="dtanaloggauge.pp"/>
         <Filename Value="dtanaloggauge.pp"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="DTAnalogGauge"/>
         <UnitName Value="DTAnalogGauge"/>
-      </Item32>
-      <Item33>
+      </Item33>
+      <Item34>
         <Filename Value="dtthemedclock.pas"/>
         <Filename Value="dtthemedclock.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="dtthemedclock"/>
         <UnitName Value="dtthemedclock"/>
-      </Item33>
-      <Item34>
+      </Item34>
+      <Item35>
         <Filename Value="dtthemedgauge.pp"/>
         <Filename Value="dtthemedgauge.pp"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="dtthemedgauge"/>
         <UnitName Value="dtthemedgauge"/>
-      </Item34>
-      <Item35>
+      </Item35>
+      <Item36>
         <Filename Value="upsi_bgrapascalscript.pas"/>
         <Filename Value="upsi_bgrapascalscript.pas"/>
         <HasRegisterProc Value="True"/>
         <HasRegisterProc Value="True"/>
         <UnitName Value="uPSI_BGRAPascalScript"/>
         <UnitName Value="uPSI_BGRAPascalScript"/>
-      </Item35>
+      </Item36>
     </Files>
     </Files>
-    <RequiredPkgs Count="3">
+    <RequiredPkgs Count="4">
       <Item1>
       <Item1>
-        <PackageName Value="BGRABitmapPack"/>
+        <PackageName Value="customdrawn"/>
       </Item1>
       </Item1>
       <Item2>
       <Item2>
-        <PackageName Value="pascalscript"/>
+        <PackageName Value="BGRABitmapPack"/>
       </Item2>
       </Item2>
       <Item3>
       <Item3>
-        <PackageName Value="IDEIntf"/>
+        <PackageName Value="pascalscript"/>
       </Item3>
       </Item3>
+      <Item4>
+        <PackageName Value="IDEIntf"/>
+      </Item4>
     </RequiredPkgs>
     </RequiredPkgs>
     <UsageOptions>
     <UsageOptions>
       <UnitPath Value="$(PkgOutDir)"/>
       <UnitPath Value="$(PkgOutDir)"/>

+ 9 - 7
bgracontrols.pas

@@ -8,13 +8,14 @@ interface
 
 
 uses
 uses
   BCBaseCtrls, BCButton, BCButtonFocus, BCEffect, bcfilters, BCGameGrid, 
   BCBaseCtrls, BCButton, BCButtonFocus, BCEffect, bcfilters, BCGameGrid, 
-  BCImageButton, BCLabel, bcmaterialdesignbutton, BCPanel, 
+  BCImageButton, BCLabel, BCMaterialDesignButton, BCPanel, 
   BCRadialProgressBar, BCRTTI, BCStylesForm, BCToolBar, BCTools, 
   BCRadialProgressBar, BCRTTI, BCStylesForm, BCToolBar, BCTools, 
-  BCTrackbarUpdown, BGRAFlashProgressBar, BGRAGraphicControl, BGRAImageList, 
-  BGRAImageManipulation, BGRAKnob, BGRAPascalScript, BGRAResizeSpeedButton, 
-  BGRAScript, BGRAShape, BGRASpeedButton, BGRASpriteAnimation, 
-  BGRAVirtualScreen, DTAnalogClock, DTAnalogCommon, DTAnalogGauge, 
-  dtthemedclock, dtthemedgauge, uPSI_BGRAPascalScript, LazarusPackageIntf;
+  BCTrackbarUpdown, BGRACustomDrawn, BGRAFlashProgressBar, BGRAGraphicControl, 
+  BGRAImageList, BGRAImageManipulation, BGRAKnob, BGRAPascalScript, 
+  BGRAResizeSpeedButton, BGRAScript, BGRAShape, BGRASpeedButton, 
+  BGRASpriteAnimation, BGRAVirtualScreen, DTAnalogClock, DTAnalogCommon, 
+  DTAnalogGauge, dtthemedclock, dtthemedgauge, uPSI_BGRAPascalScript, 
+  LazarusPackageIntf;
 
 
 implementation
 implementation
 
 
@@ -25,11 +26,12 @@ begin
   RegisterUnit('BCGameGrid', @BCGameGrid.Register);
   RegisterUnit('BCGameGrid', @BCGameGrid.Register);
   RegisterUnit('BCImageButton', @BCImageButton.Register);
   RegisterUnit('BCImageButton', @BCImageButton.Register);
   RegisterUnit('BCLabel', @BCLabel.Register);
   RegisterUnit('BCLabel', @BCLabel.Register);
-  RegisterUnit('bcmaterialdesignbutton', @bcmaterialdesignbutton.Register);
+  RegisterUnit('BCMaterialDesignButton', @BCMaterialDesignButton.Register);
   RegisterUnit('BCPanel', @BCPanel.Register);
   RegisterUnit('BCPanel', @BCPanel.Register);
   RegisterUnit('BCRadialProgressBar', @BCRadialProgressBar.Register);
   RegisterUnit('BCRadialProgressBar', @BCRadialProgressBar.Register);
   RegisterUnit('BCToolBar', @BCToolBar.Register);
   RegisterUnit('BCToolBar', @BCToolBar.Register);
   RegisterUnit('BCTrackbarUpdown', @BCTrackbarUpdown.Register);
   RegisterUnit('BCTrackbarUpdown', @BCTrackbarUpdown.Register);
+  RegisterUnit('BGRACustomDrawn', @BGRACustomDrawn.Register);
   RegisterUnit('BGRAFlashProgressBar', @BGRAFlashProgressBar.Register);
   RegisterUnit('BGRAFlashProgressBar', @BGRAFlashProgressBar.Register);
   RegisterUnit('BGRAGraphicControl', @BGRAGraphicControl.Register);
   RegisterUnit('BGRAGraphicControl', @BGRAGraphicControl.Register);
   RegisterUnit('BGRAImageList', @BGRAImageList.Register);
   RegisterUnit('BGRAImageList', @BGRAImageList.Register);

+ 123 - 0
bgracustomdrawn.pas

@@ -0,0 +1,123 @@
+unit BGRACustomDrawn;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, Types, FPCanvas, Graphics,
+  { CustomDrawn }
+  CustomDrawnControls, CustomDrawnDrawers, Customdrawn_Common,
+  { BGRABitmap }
+  BGRABitmap, BGRABitmapTypes;
+
+type
+  TBCDButton = class(TCDButton)
+
+  end;
+
+  { TBGRADrawer }
+
+  TBGRADrawer = class(TCDDrawerCommon)
+  protected
+    procedure AssignFont(Bitmap: TBGRABitmap; Font: TFont);
+  public
+    procedure DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint;
+      ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx); override;
+  end;
+
+procedure Register;
+
+implementation
+
+procedure Register;
+begin
+  RegisterComponents('BGRA Custom Drawn', [TBCDButton]);
+end;
+
+{ TBGRADrawer }
+
+procedure TBGRADrawer.AssignFont(Bitmap: TBGRABitmap; Font: TFont);
+begin
+  Bitmap.FontName := Font.Name;
+  Bitmap.FontStyle := Font.Style;
+  Bitmap.FontHeight := Font.Height;
+  Bitmap.FontQuality := fqSystemClearType;
+end;
+
+procedure TBGRADrawer.DrawButton(ADest: TFPCustomCanvas; ADestPos: TPoint;
+  ASize: TSize; AState: TCDControlState; AStateEx: TCDButtonStateEx);
+var
+  Bitmap: TBGRABitmap;
+  ts: TSize;
+begin
+  Bitmap := TBGRABitmap.Create(ASize.cx, ASize.cy);
+
+  if csfEnabled in AState then
+  begin
+    if csfSunken in AState then
+    begin
+      { Button Down }
+      Bitmap.Rectangle(0, 0, ASize.cx, ASize.cy - 1, BGRA(48, 48, 48),
+        BGRA(61, 61, 61), dmSet);
+      Bitmap.Rectangle(1, 1, ASize.cx - 1, ASize.cy - 2, BGRA(55, 55, 55),
+        BGRA(61, 61, 61), dmSet);
+      Bitmap.SetHorizLine(0, ASize.cy - 1, ASize.cx - 1, BGRA(115, 115, 115));
+    end
+    else
+    begin
+      if csfMouseOver in AState then
+      begin
+        { Button Hovered }
+        Bitmap.GradientFill(0, 0, ASize.cx, ASize.cy, BGRA(132, 132, 132),
+          BGRA(109, 109, 109), gtLinear, PointF(0, 0), PointF(0, ASize.cy), dmSet);
+        Bitmap.Rectangle(0, 0, ASize.cx, ASize.cy - 1, BGRA(48, 48, 48), dmSet);
+        Bitmap.SetHorizLine(1, 1, ASize.cx - 2, BGRA(160, 160, 160));
+        Bitmap.SetHorizLine(0, ASize.cy - 1, ASize.cx - 1, BGRA(115, 115, 115));
+      end
+      else
+      begin
+        { Button Normal }
+        Bitmap.GradientFill(0, 0, ASize.cx, ASize.cy, BGRA(107, 107, 107),
+          BGRA(84, 84, 84), gtLinear, PointF(0, 0), PointF(0, ASize.cy), dmSet);
+        Bitmap.Rectangle(0, 0, ASize.cx, ASize.cy - 1, BGRA(48, 48, 48), dmSet);
+        Bitmap.SetHorizLine(1, 1, ASize.cx - 2, BGRA(130, 130, 130));
+        Bitmap.SetHorizLine(0, ASize.cy - 1, ASize.cx - 1, BGRA(115, 115, 115));
+        { Button Focused }
+        if csfHasFocus in AState then
+          Bitmap.Rectangle(1, 2, ASize.cx - 1, ASize.cy - 2, BGRA(80, 111, 172), dmSet);
+      end;
+    end;
+  end
+  else
+  begin
+    { Button Disabled }
+    Bitmap.Rectangle(0, 0, ASize.cx, ASize.cy - 1, BGRA(66, 66, 66),
+      BGRA(71, 71, 71), dmSet);
+    Bitmap.SetHorizLine(0, ASize.cy - 1, ASize.cx - 1, BGRA(94, 94, 94));
+  end;
+
+  AssignFont(Bitmap, AStateEx.Font);
+  ts := Bitmap.TextSize(AStateEx.Caption);
+
+  if csfEnabled in AState then
+  begin
+    { Text Enabled }
+    Bitmap.TextOut((ASize.cx - ts.cx) div 2, ((ASize.cy - ts.cy) div 2) -
+      1, AStateEx.Caption, BGRA(47, 47, 47));
+    Bitmap.TextOut((ASize.cx - ts.cx) div 2, (ASize.cy - ts.cy) div 2,
+      AStateEx.Caption, BGRA(229, 229, 229));
+  end
+  else
+    { Text Disabled }
+    Bitmap.TextOut((ASize.cx - ts.cx) div 2, (ASize.cy - ts.cy) div 2,
+      AStateEx.Caption, BGRA(170, 170, 170));
+
+  Bitmap.Draw(TCanvas(ADest), ADestPos.x, ADestPos.y, True);
+end;
+
+initialization
+  RegisterDrawer(TBGRADrawer.Create, dsCommon);
+
+end.
+

+ 134 - 0
test/test_bgracustomdrawn/test_bgracustomdrawn.lpi

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="9"/>
+    <PathDelim Value="\"/>
+    <General>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="BGRA Custom Drawn"/>
+      <ResourceType Value="res"/>
+      <UseXPManifest Value="True"/>
+      <XPManifest>
+        <DpiAware Value="True"/>
+      </XPManifest>
+    </General>
+    <i18n>
+      <EnableI18N LFM="False"/>
+    </i18n>
+    <VersionInfo>
+      <StringTable ProductVersion=""/>
+    </VersionInfo>
+    <BuildModes Count="2">
+      <Item1 Name="Release" Default="True"/>
+      <Item2 Name="Debug">
+        <CompilerOptions>
+          <Version Value="11"/>
+          <PathDelim Value="\"/>
+          <Target>
+            <Filename Value="test_bgracustomdrawn"/>
+          </Target>
+          <SearchPaths>
+            <IncludeFiles Value="$(ProjOutDir)"/>
+            <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+          </SearchPaths>
+          <Parsing>
+            <SyntaxOptions>
+              <IncludeAssertionCode Value="True"/>
+            </SyntaxOptions>
+          </Parsing>
+          <CodeGeneration>
+            <Checks>
+              <IOChecks Value="True"/>
+              <RangeChecks Value="True"/>
+              <OverflowChecks Value="True"/>
+              <StackChecks Value="True"/>
+            </Checks>
+          </CodeGeneration>
+          <Linking>
+            <Debugging>
+              <DebugInfoType Value="dsDwarf2Set"/>
+              <UseHeaptrc Value="True"/>
+              <UseExternalDbgSyms Value="True"/>
+            </Debugging>
+            <Options>
+              <Win32>
+                <GraphicApplication Value="True"/>
+              </Win32>
+            </Options>
+          </Linking>
+        </CompilerOptions>
+      </Item2>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+    </PublishOptions>
+    <RunParams>
+      <local>
+        <FormatVersion Value="1"/>
+      </local>
+    </RunParams>
+    <RequiredPackages Count="2">
+      <Item1>
+        <PackageName Value="bgracontrols"/>
+      </Item1>
+      <Item2>
+        <PackageName Value="LCL"/>
+      </Item2>
+    </RequiredPackages>
+    <Units Count="2">
+      <Unit0>
+        <Filename Value="test_bgracustomdrawn.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit0>
+      <Unit1>
+        <Filename Value="umain.pas"/>
+        <IsPartOfProject Value="True"/>
+        <ComponentName Value="frmMain"/>
+        <HasResources Value="True"/>
+        <ResourceBaseClass Value="Form"/>
+      </Unit1>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <Target>
+      <Filename Value="test_bgracustomdrawn"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+    <CodeGeneration>
+      <SmartLinkUnit Value="True"/>
+      <Optimizations>
+        <OptimizationLevel Value="3"/>
+      </Optimizations>
+    </CodeGeneration>
+    <Linking>
+      <Debugging>
+        <GenerateDebugInfo Value="False"/>
+      </Debugging>
+      <LinkSmart Value="True"/>
+      <Options>
+        <Win32>
+          <GraphicApplication Value="True"/>
+        </Win32>
+      </Options>
+    </Linking>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 22 - 0
test/test_bgracustomdrawn/test_bgracustomdrawn.lpr

@@ -0,0 +1,22 @@
+program test_bgracustomdrawn;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  cthreads,
+  {$ENDIF}{$ENDIF}
+  Interfaces, // this includes the LCL widgetset
+  Forms, umain
+  { you can add units after this };
+
+{$R *.res}
+
+begin
+  Application.Title:='BGRA Custom Drawn';
+  RequireDerivedFormResource:=True;
+  Application.Initialize;
+  Application.CreateForm(TfrmMain, frmMain);
+  Application.Run;
+end.
+

+ 32 - 0
test/test_bgracustomdrawn/umain.lfm

@@ -0,0 +1,32 @@
+object frmMain: TfrmMain
+  Left = 474
+  Height = 240
+  Top = 178
+  Width = 320
+  Caption = 'BGRA Custom Drawn'
+  ClientHeight = 240
+  ClientWidth = 320
+  Color = 5460819
+  LCLVersion = '1.6.0.4'
+  object BCDButton1: TBCDButton
+    Left = 8
+    Height = 25
+    Top = 8
+    Width = 96
+    Caption = 'BCDButton1'
+    DrawStyle = dsDefault
+    TabOrder = 0
+    TabStop = True
+  end
+  object BCDButton2: TBCDButton
+    Left = 8
+    Height = 25
+    Top = 40
+    Width = 96
+    Caption = 'BCDButton2'
+    DrawStyle = dsDefault
+    Enabled = False
+    TabOrder = 1
+    TabStop = True
+  end
+end

+ 32 - 0
test/test_bgracustomdrawn/umain.pas

@@ -0,0 +1,32 @@
+unit umain;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
+  BGRACustomDrawn;
+
+type
+
+  { TfrmMain }
+
+  TfrmMain = class(TForm)
+    BCDButton1: TBCDButton;
+    BCDButton2: TBCDButton;
+  private
+    { private declarations }
+  public
+    { public declarations }
+  end;
+
+var
+  frmMain: TfrmMain;
+
+implementation
+
+{$R *.lfm}
+
+end.
+