Skip to content

Commit

Permalink
Merge pull request #193 from bgrabitmap/dev-bgracontrols
Browse files Browse the repository at this point in the history
Merge 9.0.1.6
  • Loading branch information
BobanSpasic authored Aug 15, 2024
2 parents caa4183 + 2865a51 commit f5efbf8
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 7 deletions.
9 changes: 9 additions & 0 deletions bcleaboard.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Boban Spasic
}

unit BCLeaBoard;

{$mode objfpc}{$H+}
Expand Down
272 changes: 272 additions & 0 deletions bcleaengrave.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Boban Spasic
}

unit BCLeaEngrave;

{$mode ObjFPC}{$H+}

interface

uses
Classes, SysUtils, Controls, Graphics, ExtCtrls, LResources,
BGRABitmapTypes, BGRABitmap, BGRATextFX, BGRATransform;

type
TBCLeaEngrave = class(TCustomControl)
private
FBitmap: TBGRABitmap;
FFontShadowColor: TColor;
FFontShadowOffsetX: integer;
FFontShadowOffsetY: integer;
FFontShadowRadius: integer;
FLayerZoom: integer;
FLayerOffsetX: integer;
FLayerOffsetY: integer;
FBlendOperation: TBlendOperation;
FInvBlending: boolean;
FLayerColor: TColor;
FAngle: integer;
procedure SetFFontShadowColor(AValue: TColor);
procedure SetFFontShadowOffsetX(AValue: integer);
procedure SetFFontShadowOffsetY(AValue: integer);
procedure SetFFontShadowRadius(AValue: integer);
procedure SetLayerZoom(AValue: integer);
procedure SetBlendOperation(AValue: TBlendOperation);
procedure SetInvBlending(AValue: boolean);
procedure SetLayerColor(AValue: TColor);
procedure SetLayerOffsetX(AValue: integer);
procedure SetLayerOffsetY(AValue: integer);
procedure SetAngle(AValue: integer);
protected
procedure SetVisible(Value: boolean); override;
procedure Paint; override;
procedure Redraw;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;

published
property Align;
property Caption;
property Color default clBtnFace;
property Cursor;
property Font;
property ParentShowHint;
property ShowHint;
property Anchors;
property Constraints;
property Visible;
property FontShadowColor: TColor read FFontShadowColor write SetFFontShadowColor default clBlack;
property FontShadowOffsetX: integer read FFontShadowOffsetX write SetFFontShadowOffsetX default 2;
property FontShadowOffsetY: integer read FFontShadowOffsetY write SetFFontShadowOffsetY default 2;
property FontShadowRadius: integer read FFontSHadowRadius write SetFFontShadowRadius default 4;
property BlendOperation: TBlendOperation read FBlendOperation write SetBlendOperation default boSubtractInverse;
property LayerZoom: integer read FLayerZoom write SetLayerZoom default 102;
property InverseBlending: boolean read FInvBlending write SetInvBlending default False;
property LayerColor: TColor read FLayerColor write SetLayerColor default clBlack;
property LayerOffsetX: integer read FLayerOffsetX write SetLayerOffsetX default 0;
property LayerOffsetY: integer read FLayerOffsetY write SetLayerOffsetY default 0;
property Angle: integer read FAngle write SetAngle default 0;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('BGRA Controls', [TBCLeaEngrave]);
end;

constructor TBCLeaEngrave.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

with GetControlClassDefaultSize do
SetInitialBounds(0, 0, 100, 100);
Font.Color := clBlack;
Font.Height := 20;
FLayerZoom := 102;
FBlendOperation := boSubtractInverse;
FFontShadowRadius := 4;
FFontShadowOffsetX := 2;
FFontShadowOffsetY := 2;
FFontShadowColor := clBlack;
Color := clBtnFace;
FLayerColor := clBlack;
FLayerOffsetX := 0;
FLayerOffsetY := 0;
FAngle := 0;
FInvBlending := False;
FBitmap := TBGRABitmap.Create(Width, Height, Color);
end;

destructor TBCLeaEngrave.Destroy;
begin
FreeAndNil(FBitmap);
inherited Destroy;
end;

procedure TBCLeaEngrave.SetVisible(Value: boolean);
begin
inherited SetVisible(Value);
Invalidate;
end;

procedure TBCLeaEngrave.Paint;
begin
inherited Paint;
Redraw;
end;

procedure TBCLeaEngrave.Redraw;
var
TextBmp, LayerTextBmp: TBGRABitmap;
Zoom, UnZoom, RotBmp: TBGRABitmap;
CopyRect: TRect;
ZFactor: single;
Rad: single;
Affine: TBGRAAffineBitmapTransform;
begin
ZFactor := FLayerZoom / 100;
FBitmap.SetSize(Width, Height);
FBitmap.Fill(Color);

TextBmp := TextShadow(Width, Height, Caption, Font.Height,
Font.Color, FontShadowColor, FontShadowOFfsetX,
FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
LayerTextBmp := TextShadow(Width, Height, Caption, Font.Height,
LayerColor, FontShadowColor, FontShadowOFfsetX,
FontShadowOffsetY, FontShadowRadius, Font.Style, Font.Name) as TBGRABitmap;
Zoom := LayerTextBmp.Resample(round(Width * ZFactor), round(Height * ZFactor)) as TBGRABitmap;
CopyRect.Left := (Zoom.Width - Width) div 2 + FLayerOffsetX;
CopyRect.Right := CopyRect.Left + Width + FLayerOffsetX;
CopyRect.Top := (Zoom.Height - Height) div 2 + FLayerOffsetY;
CopyRect.Bottom := CopyRect.Top + Height + FLayerOffsetY;
UnZoom := Zoom.GetPart(CopyRect) as TBGRABitmap;
if FInvBlending then
begin
FBitmap.PutImage(0, 0, UnZoom, dmDrawWithTransparency);
FBitmap.BlendImageOver(0, 0, TextBmp, FBlendOperation);
end
else
begin
FBitmap.PutImage(0, 0, TextBmp, dmDrawWithTransparency);
FBitmap.BlendImageOver(0, 0, UnZoom, FBlendOperation);
end;
if FAngle <> 0 then
begin
RotBmp := TBGRABitmap.Create(Width, Height, Color);
Affine := TBGRAAffineBitmapTransform.Create(FBitmap);
Affine.Translate(-FBitmap.Width div 2, -FBitmap.Height div 2);
Affine.RotateDeg(FAngle);
Affine.Translate(FBitmap.Width div 2, FBitmap.Height div 2);
RotBmp.Fill(Affine);
FBitmap.Fill(Color);
FBitmap.PutImage(0, 0, RotBmp, dmDrawWithTransparency);
Affine.Free;
RotBmp.Free;
end;

if Visible then
FBitmap.Draw(Canvas, 0, 0, True);
TextBmp.Free;
Zoom.Free;
UnZoom.Free;
end;

procedure TBCLeaEngrave.SetFFontShadowColor(AValue: TColor);
begin
if FFontShadowColor = AValue then
Exit;
FFontShadowColor := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetFFontShadowOffsetX(AValue: integer);
begin
if FFontShadowOffsetX = AValue then
Exit;
FFontShadowOffsetX := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetFFontShadowOffsetY(AValue: integer);
begin
if FFontShadowOffsetY = AValue then
Exit;
FFontShadowOffsetY := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetFFontShadowRadius(AValue: integer);
begin
if FFontSHadowRadius = AValue then
Exit;
FFontSHadowRadius := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetBlendOperation(AValue: TBlendOperation);
begin
if FBlendOperation = AValue then
Exit;
FBlendOperation := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetLayerZoom(AValue: integer);
begin
if FLayerZoom = AValue then
Exit;
FLayerZoom := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetInvBlending(AValue: boolean);
begin
if FInvBlending = AValue then
Exit;
FInvBlending := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetLayerColor(AValue: TColor);
begin
if FLayerColor = AValue then
Exit;
FLayerColor := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetLayerOffsetX(AValue: integer);
begin
if FLayerOffsetX = AValue then
Exit;
FLayerOffsetX := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetLayerOffsetY(AValue: integer);
begin
if FLayerOffsetY = AValue then
Exit;
FLayerOffsetY := AValue;
Invalidate;
end;

procedure TBCLeaEngrave.SetAngle(AValue: integer);
begin
if FAngle = AValue then
Exit;
FAngle := AValue;
Invalidate;
end;

end.
9 changes: 7 additions & 2 deletions bgracontrols.lpk
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
</CompilerOptions>
<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="9" Release="1" Build="4"/>
<Files Count="78">
<Version Major="9" Release="1" Build="6"/>
<Files Count="79">
<Item1>
<Filename Value="atshapelinebgra.pas"/>
<HasRegisterProc Value="True"/>
Expand Down Expand Up @@ -416,6 +416,11 @@
<HasRegisterProc Value="True"/>
<UnitName Value="BCLeaBoard"/>
</Item78>
<Item79>
<Filename Value="bcleaengrave.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="BCLeaEngrave"/>
</Item79>
</Files>
<CompatibilityMode Value="True"/>
<LazDoc Paths="fpdoc"/>
Expand Down
4 changes: 3 additions & 1 deletion bgracontrols.pas
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ interface
ColorSpeedButton, DTAnalogClock, DTAnalogCommon, DTAnalogGauge,
dtthemedclock, dtthemedgauge, MaterialColors, bgrasvgimagelistform,
BCLeaLCDDisplay, BCLeaLED, BCLeaQLED, BCLeaRingSlider, BCLeaSelector,
BCLeaTheme, BCLeaLCDDisplay_EditorRegister, BCLeaBoard, LazarusPackageIntf;
BCLeaTheme, BCLeaLCDDisplay_EditorRegister, BCLeaBoard, BCLeaEngrave,
LazarusPackageIntf;

implementation

Expand Down Expand Up @@ -91,6 +92,7 @@ procedure Register;
RegisterUnit('BCLeaLCDDisplay_EditorRegister',
@BCLeaLCDDisplay_EditorRegister.Register);
RegisterUnit('BCLeaBoard', @BCLeaBoard.Register);
RegisterUnit('BCLeaEngrave', @BCLeaEngrave.Register);
end;

initialization
Expand Down
5 changes: 3 additions & 2 deletions bgrapascalscriptcomponent.lpk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<Package Version="5">
<PathDelim Value="\"/>
<Name Value="bgrapascalscriptcomponent"/>
<Type Value="RunAndDesignTime"/>
Expand All @@ -11,7 +11,7 @@
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Version Major="9" Release="1" Build="5"/>
<Version Major="9" Release="1" Build="6"/>
<Files Count="3">
<Item1>
<Filename Value="bgrapascalscript.pas"/>
Expand All @@ -29,6 +29,7 @@
<UnitName Value="BGRAScript"/>
</Item3>
</Files>
<CompatibilityMode Value="True"/>
<RequiredPkgs Count="3">
<Item1>
<PackageName Value="BGRABitmapPack"/>
Expand Down
Binary file added images/TBCLeaEngrave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/TBCLeaEngrave_150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/TBCLeaEngrave_200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/bgracontrols_images.res
Binary file not shown.
5 changes: 4 additions & 1 deletion images/bgracontrols_images_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ TBCLeaTheme_150.png
TBCLeaTheme_200.png
TBCLeaBoard.png
TBCLeaBoard_150.png
TBCLeaBoard_200.png
TBCLeaBoard_200.png
TBCLeaEngrave.png
TBCLeaEngrave_150.png
TBCLeaEngrave_200.png
2 changes: 1 addition & 1 deletion update_bgracontrols_force.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"UpdatePackageData" : {
"DownloadZipURL" : "https://github.com/bgrabitmap/bgracontrols/archive/master.zip",
"DownloadZipURL" : "https://github.com/bgrabitmap/bgracontrols/archive/refs/heads/master.zip",
"Name" : "bgracontrols-master"
},
"UpdatePackageFiles" : [
Expand Down

0 comments on commit f5efbf8

Please sign in to comment.