Стартовый пул
This commit is contained in:
BIN
bgracontrols/test/test_bcxbutton/Desert.jpg
Normal file
BIN
bgracontrols/test/test_bcxbutton/Desert.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
185
bgracontrols/test/test_bcxbutton/test_bcxbutton.lpi
Normal file
185
bgracontrols/test/test_bcxbutton/test_bcxbutton.lpi
Normal file
@@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="test_bcxbutton"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<BuildModes Count="3">
|
||||
<Item1 Name="Debug" Default="True"/>
|
||||
<Item2 Name="Release">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="test_bcxbutton"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
<Optimizations>
|
||||
<OptimizationLevel Value="3"/>
|
||||
<VariablesInRegisters Value="True"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<StripSymbols Value="True"/>
|
||||
</Debugging>
|
||||
<LinkSmart Value="True"/>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item2>
|
||||
<Item3 Name="Debug macOS 64">
|
||||
<MacroValues Count="1">
|
||||
<Macro1 Name="LCLWidgetType" Value="cocoa"/>
|
||||
</MacroValues>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="test_bcxbutton"/>
|
||||
</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>
|
||||
<Optimizations>
|
||||
<VariablesInRegisters Value="True"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
<UseHeaptrc Value="True"/>
|
||||
<StripSymbols Value="True"/>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item3>
|
||||
<SharedMatrixOptions Count="1">
|
||||
<Item1 ID="612023007301" Modes="Debug macOS 64" Type="IDEMacro" MacroName="LCLWidgetType" Value="cocoa"/>
|
||||
</SharedMatrixOptions>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="1">
|
||||
<Mode0 Name="default"/>
|
||||
</Modes>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="2">
|
||||
<Item1>
|
||||
<PackageName Value="bgracontrols"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="test_bcxbutton.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="utest.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="test_bcxbutton"/>
|
||||
</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>
|
||||
<Optimizations>
|
||||
<VariablesInRegisters Value="True"/>
|
||||
</Optimizations>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
<UseHeaptrc Value="True"/>
|
||||
<StripSymbols Value="True"/>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
<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>
|
21
bgracontrols/test/test_bcxbutton/test_bcxbutton.lpr
Normal file
21
bgracontrols/test/test_bcxbutton/test_bcxbutton.lpr
Normal file
@@ -0,0 +1,21 @@
|
||||
program test_bcxbutton;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, utest
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource := True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
91
bgracontrols/test/test_bcxbutton/utest.lfm
Normal file
91
bgracontrols/test/test_bcxbutton/utest.lfm
Normal file
@@ -0,0 +1,91 @@
|
||||
object Form1: TForm1
|
||||
Left = 353
|
||||
Height = 283
|
||||
Top = 169
|
||||
Width = 368
|
||||
Caption = 'BCXButton'
|
||||
ClientHeight = 283
|
||||
ClientWidth = 368
|
||||
DesignTimePPI = 72
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
LCLVersion = '1.9.0.0'
|
||||
object vs1: TBGRAVirtualScreen
|
||||
Left = 0
|
||||
Height = 283
|
||||
Top = 0
|
||||
Width = 368
|
||||
OnRedraw = vs1Redraw
|
||||
Align = alClient
|
||||
Alignment = taLeftJustify
|
||||
ClientHeight = 283
|
||||
ClientWidth = 368
|
||||
Color = clWhite
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
TabOrder = 0
|
||||
object BCXButton2: TBCXButton
|
||||
Left = 12
|
||||
Height = 39
|
||||
Top = 120
|
||||
Width = 318
|
||||
OnRenderControl = BCXButton1RenderControl
|
||||
Caption = 'Button 2'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton1: TBCXButton
|
||||
Left = 12
|
||||
Height = 30
|
||||
Top = 6
|
||||
Width = 102
|
||||
OnRenderControl = BCXButton1RenderControl
|
||||
Caption = 'Button 1'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton3: TBCXButton
|
||||
Left = 12
|
||||
Height = 30
|
||||
Top = 42
|
||||
Width = 102
|
||||
OnRenderControl = BCXButton3RenderControl
|
||||
Caption = 'Button 3'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton4: TBCXButton
|
||||
Left = 12
|
||||
Height = 30
|
||||
Top = 78
|
||||
Width = 102
|
||||
OnRenderControl = BCXButton3RenderControl
|
||||
Caption = 'Button 4'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton5: TBCXButton
|
||||
Left = 120
|
||||
Height = 102
|
||||
Top = 6
|
||||
Width = 102
|
||||
OnRenderControl = BCXButton1RenderControl
|
||||
Caption = 'Button 5'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton6: TBCXButton
|
||||
Left = 228
|
||||
Height = 102
|
||||
Top = 6
|
||||
Width = 102
|
||||
OnRenderControl = BCXButton1RenderControl
|
||||
Caption = 'Button 6'
|
||||
ParentFont = False
|
||||
end
|
||||
object BCXButton7: TBCXButton
|
||||
Left = 12
|
||||
Height = 66
|
||||
Top = 174
|
||||
Width = 318
|
||||
OnRenderControl = BCXButton1RenderControl
|
||||
Caption = 'Button 7'
|
||||
ParentFont = False
|
||||
end
|
||||
end
|
||||
end
|
250
bgracontrols/test/test_bcxbutton/utest.pas
Normal file
250
bgracontrols/test/test_bcxbutton/utest.pas
Normal file
@@ -0,0 +1,250 @@
|
||||
unit utest;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
|
||||
BCImageButton, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes, BCTypes,
|
||||
BCFilters, BGRATextFX, Types;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
BCXButton1: TBCXButton;
|
||||
BCXButton2: TBCXButton;
|
||||
BCXButton3: TBCXButton;
|
||||
BCXButton4: TBCXButton;
|
||||
BCXButton5: TBCXButton;
|
||||
BCXButton6: TBCXButton;
|
||||
BCXButton7: TBCXButton;
|
||||
vs1: TBGRAVirtualScreen;
|
||||
procedure BCXButton1RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
procedure BCXButton3RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
procedure vs1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
Image: TBGRABitmap;
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Themes, LCLType;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ Button }
|
||||
|
||||
procedure DrawBasicXButton(Sender: TObject; Bitmap: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
begin
|
||||
case State of
|
||||
gbsNormal: Bitmap.Fill(BGRA(255, 0, 0, 100));
|
||||
gbsHover: Bitmap.Fill(BGRA(0, 255, 0, 100));
|
||||
gbsActive: Bitmap.Fill(BGRA(0, 0, 255, 100));
|
||||
gbsDisabled: Bitmap.Fill(BGRA(0, 0, 0, 100));
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DrawGlassXButton(Sender: TObject; Bitmap, Background: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
var
|
||||
tmp: TBGRABitmap;
|
||||
r: TRect;
|
||||
begin
|
||||
{ Rect to copy backround }
|
||||
with TBCXButton(Sender) do
|
||||
r := Rect(Left, Top, Left + Width, Top + Height);
|
||||
{ Copy background }
|
||||
tmp := Background.GetPart(r) as TBGRABitmap;
|
||||
{ Apply blur }
|
||||
BGRAReplace(tmp, tmp.FilterBlurRadial(25, rbFast));
|
||||
{ Blend }
|
||||
Bitmap.BlendImageOver(0, 0, tmp, boLinearBlend);
|
||||
tmp.Free;
|
||||
{ Rect to draw borders }
|
||||
r := Rect(0, 0, Bitmap.Width, Bitmap.Height);
|
||||
{ Draw borders }
|
||||
case State of
|
||||
gbsNormal:
|
||||
begin
|
||||
Bitmap.Rectangle(r, BGRA(0, 0, 0, 100), BGRA(255, 255, 255, 10),
|
||||
dmDrawWithTransparency);
|
||||
r := Rect(r.Left + 1, r.Top + 1, r.Right - 1, r.Bottom - 1);
|
||||
Bitmap.Rectangle(r, BGRA(255, 255, 255, 100), BGRAPixelTransparent,
|
||||
dmDrawWithTransparency);
|
||||
end;
|
||||
gbsHover:
|
||||
begin
|
||||
Bitmap.Rectangle(r, BGRA(0, 0, 0, 100), BGRA(255, 255, 255, 50),
|
||||
dmDrawWithTransparency);
|
||||
r := Rect(r.Left + 1, r.Top + 1, r.Right - 1, r.Bottom - 1);
|
||||
Bitmap.Rectangle(r, BGRA(255, 255, 255, 100), BGRAPixelTransparent,
|
||||
dmDrawWithTransparency);
|
||||
end;
|
||||
gbsActive:
|
||||
begin
|
||||
Bitmap.Rectangle(r, BGRA(0, 0, 0, 100), BGRA(100, 100, 100, 50),
|
||||
dmDrawWithTransparency);
|
||||
r := Rect(r.Left + 1, r.Top + 1, r.Right - 1, r.Bottom - 1);
|
||||
Bitmap.Rectangle(r, BGRA(255, 255, 255, 50), BGRAPixelTransparent,
|
||||
dmDrawWithTransparency);
|
||||
end;
|
||||
gbsDisabled:
|
||||
begin
|
||||
Bitmap.Rectangle(r, BGRA(0, 0, 0, 100), BGRA(100, 100, 100, 50),
|
||||
dmDrawWithTransparency);
|
||||
r := Rect(r.Left + 1, r.Top + 1, r.Right - 1, r.Bottom - 1);
|
||||
Bitmap.Rectangle(r, BGRA(100, 100, 100, 100), BGRAPixelTransparent,
|
||||
dmDrawWithTransparency);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure DrawXButtonText(Sender: TObject; Bitmap: TBGRABitmap; State: TBCGraphicButtonState; Text: String);
|
||||
var
|
||||
tmp: TBGRABitmap;
|
||||
op: byte;
|
||||
begin
|
||||
if State = gbsDisabled then
|
||||
op := 100
|
||||
else
|
||||
op := 255;
|
||||
|
||||
tmp := TextShadow(Bitmap.Width, Bitmap.Height, Text, 18, BGRA(255, 255, 255, op),
|
||||
BGRABlack, 1, 1, 2) as TBGRABitmap;
|
||||
|
||||
Bitmap.BlendImageOver(0, 0, tmp, boLinearBlend);
|
||||
tmp.Free;
|
||||
end;
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.BCXButton1RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
var
|
||||
str: string;
|
||||
begin
|
||||
{ Style }
|
||||
DrawGlassXButton(Sender, Bitmap, Image, State);
|
||||
//DrawBasicXButton(Sender, Bitmap, State);
|
||||
|
||||
{ Strings }
|
||||
str := TControl(Sender).Caption;
|
||||
|
||||
{ Text }
|
||||
DrawXButtonText(Sender, Bitmap, State, str);
|
||||
end;
|
||||
|
||||
function SaveAlphaRect(ABitmap: TBGRABitmap; ARect: TRect): Pointer;
|
||||
var width,height,count,y: Integer;
|
||||
pAlphaData: PByte;
|
||||
pSrc: PBGRAPixel;
|
||||
begin
|
||||
IntersectRect(ARect,ARect,Classes.Rect(0,0,ABitmap.Width,ABitmap.Height));
|
||||
width := ARect.Right-ARect.Left;
|
||||
height := ARect.Bottom-ARect.Top;
|
||||
if (width <= 0) or (height <= 0) then result := nil;
|
||||
getmem(result, sizeof(longint)*2 + sizeof(byte)*width*height);
|
||||
PLongint(result)^ := width;
|
||||
(PLongint(result)+1)^ := height;
|
||||
pAlphaData := pbyte(plongint(result)+2);
|
||||
for y := ARect.Top to ARect.Bottom-1 do
|
||||
begin
|
||||
pSrc := ABitmap.ScanLine[y]+ARect.Left;
|
||||
count := width;
|
||||
while count > 0 do
|
||||
begin
|
||||
pAlphaData^ := pSrc^.alpha;
|
||||
inc(pAlphaData);
|
||||
inc(pSrc);
|
||||
dec(count);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure RestoreAlphaRectAndFree(ABitmap: TBGRABitmap; AX,AY: integer; ASavedAlphaRect: Pointer);
|
||||
var width,height,count,y: Integer;
|
||||
pAlphaData: PByte;
|
||||
pSrc: PBGRAPixel;
|
||||
begin
|
||||
if ASavedAlphaRect = nil then exit;
|
||||
if AX < 0 then AX := 0;
|
||||
if AY < 0 then AY := 0;
|
||||
width := PLongint(ASavedAlphaRect)^;
|
||||
height := (PLongint(ASavedAlphaRect)+1)^;
|
||||
pAlphaData := pbyte(plongint(ASavedAlphaRect)+2);
|
||||
for y := AY to AY+height-1 do
|
||||
begin
|
||||
pSrc := ABitmap.ScanLine[y]+AX;
|
||||
count := width;
|
||||
while count > 0 do
|
||||
begin
|
||||
pSrc^.alpha := pAlphaData^;
|
||||
inc(pAlphaData);
|
||||
inc(pSrc);
|
||||
dec(count);
|
||||
end;
|
||||
end;
|
||||
freemem(ASavedAlphaRect);
|
||||
end;
|
||||
|
||||
procedure TForm1.BCXButton3RenderControl(Sender: TObject; Bitmap: TBGRABitmap;
|
||||
State: TBCGraphicButtonState);
|
||||
var
|
||||
Details: TThemedElementDetails;
|
||||
PaintRect: TRect;
|
||||
AlphaRect: Pointer;
|
||||
begin
|
||||
PaintRect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
|
||||
|
||||
case State of
|
||||
gbsNormal: Details := ThemeServices.GetElementDetails(tbPushButtonNormal);
|
||||
gbsHover: Details := ThemeServices.GetElementDetails(tbPushButtonHot);
|
||||
gbsActive: Details := ThemeServices.GetElementDetails(tbPushButtonPressed);
|
||||
gbsDisabled: Details := ThemeServices.GetElementDetails(tbPushButtonDisabled);
|
||||
end;
|
||||
|
||||
ThemeServices.DrawElement(Bitmap.Canvas.Handle, Details, PaintRect, nil);
|
||||
Bitmap.Canvas.Changed;
|
||||
|
||||
PaintRect := ThemeServices.ContentRect(Bitmap.Canvas.Handle, Details, PaintRect);
|
||||
AlphaRect := SaveAlphaRect(Bitmap, PaintRect);
|
||||
ThemeServices.DrawText(Bitmap.Canvas, Details, TControl(Sender).Caption, PaintRect,
|
||||
DT_CENTER or DT_VCENTER or DT_SINGLELINE, 0);
|
||||
RestoreAlphaRectAndFree(Bitmap, PaintRect.Left,PaintRect.Top, AlphaRect);
|
||||
end;
|
||||
|
||||
{ Image }
|
||||
|
||||
procedure TForm1.vs1Redraw(Sender: TObject; Bitmap: TBGRABitmap);
|
||||
begin
|
||||
Bitmap.BlendImageOver(0, 0, Image, boLinearBlend);
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
BCXButton2.Enabled := False;
|
||||
BCXButton4.Enabled := False;
|
||||
Image := TBGRABitmap.Create(Application.Location + 'Desert.jpg');
|
||||
end;
|
||||
|
||||
procedure TForm1.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
Image.Free;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user