Recent

Author Topic: [ SOLVED ] Question BGRAGraphicsControl  (Read 999 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 647
[ SOLVED ] Question BGRAGraphicsControl
« on: August 08, 2025, 02:27:07 pm »
Hello, I am writing my own component. In dependencies, I have added bgracontrols and bgrabitmap. Why can't I use BGRAGraphicsControl?
« Last Edit: August 09, 2025, 09:50:32 am by Pe3s »

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Question BGRAGraphicsControl
« Reply #1 on: August 08, 2025, 09:47:43 pm »
Please give more information on how you're doing this...

You've created a new package, added dependencies, then added a new file inheriting from TBGRAGraphicsControl...?

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Question BGRAGraphicsControl
« Reply #2 on: August 08, 2025, 09:56:49 pm »
Exactly. Adds a screenshot of dependencies.

lainz

  • Hero Member
  • *****
  • Posts: 4743
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Question BGRAGraphicsControl
« Reply #3 on: August 08, 2025, 11:40:18 pm »
Show the error message and the content of the pas file.

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Question BGRAGraphicsControl
« Reply #4 on: August 09, 2025, 07:24:36 am »
Code: Pascal  [Select][+][-]
  1. flatcirclebutton.pas(152,43) Error: Identifier not found "rmLanczos3"


Code: Pascal  [Select][+][-]
  1. unit FlatCircleButton;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Controls, Graphics, LCLType,
  9.   BGRABitmap, BGRABitmapTypes, Math;
  10.  
  11. type
  12.   TFlatCircleButton = class(TCustomControl)
  13.   private
  14.     FHover: Boolean;
  15.     FNormalColor: TColor;
  16.     FHoverColor: TColor;
  17.     FPicture: TPicture;
  18.     FOnClick: TNotifyEvent;
  19.     FMargin: Integer;
  20.     procedure SetNormalColor(AValue: TColor);
  21.     procedure SetHoverColor(AValue: TColor);
  22.     procedure SetPicture(AValue: TPicture);
  23.     procedure SetMargin(AValue: Integer);
  24.   protected
  25.     procedure Paint; override;
  26.     procedure MouseEnter; override;
  27.     procedure MouseLeave; override;
  28.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  29.   public
  30.     constructor Create(AOwner: TComponent); override;
  31.     destructor Destroy; override;
  32.   published
  33.     property NormalColor: TColor read FNormalColor write SetNormalColor default clBtnFace;
  34.     property HoverColor: TColor read FHoverColor write SetHoverColor default clSilver;
  35.     property Picture: TPicture read FPicture write SetPicture;
  36.     property Margin: Integer read FMargin write SetMargin default 4;
  37.     property Align;
  38.     property Anchors;
  39.     property OnClick: TNotifyEvent read FOnClick write FOnClick;
  40.     property Width;
  41.     property Height;
  42.   end;
  43.  
  44. procedure Register;
  45.  
  46. implementation
  47.  
  48. procedure Register;
  49. begin
  50.   RegisterComponents('FlatControls', [TFlatCircleButton]);
  51. end;
  52.  
  53. { TFlatCircleButton }
  54.  
  55. constructor TFlatCircleButton.Create(AOwner: TComponent);
  56. begin
  57.   inherited Create(AOwner);
  58.   Width := 64;
  59.   Height := 64;
  60.   FNormalColor := clBtnFace;
  61.   FHoverColor := clSilver;
  62.   FPicture := TPicture.Create;
  63.   FMargin := 4;
  64. end;
  65.  
  66. destructor TFlatCircleButton.Destroy;
  67. begin
  68.   FPicture.Free;
  69.   inherited Destroy;
  70. end;
  71.  
  72. procedure TFlatCircleButton.SetNormalColor(AValue: TColor);
  73. begin
  74.   if FNormalColor <> AValue then
  75.   begin
  76.     FNormalColor := AValue;
  77.     Invalidate;
  78.   end;
  79. end;
  80.  
  81. procedure TFlatCircleButton.SetHoverColor(AValue: TColor);
  82. begin
  83.   if FHoverColor <> AValue then
  84.   begin
  85.     FHoverColor := AValue;
  86.     Invalidate;
  87.   end;
  88. end;
  89.  
  90. procedure TFlatCircleButton.SetPicture(AValue: TPicture);
  91. begin
  92.   FPicture.Assign(AValue);
  93.   Invalidate;
  94. end;
  95.  
  96. procedure TFlatCircleButton.SetMargin(AValue: Integer);
  97. begin
  98.   if FMargin <> AValue then
  99.   begin
  100.     FMargin := AValue;
  101.     Invalidate;
  102.   end;
  103. end;
  104.  
  105. procedure TFlatCircleButton.Paint;
  106. var
  107.   bmp: TBGRABitmap;
  108.   cx, cy, radius: Integer;
  109.   fillColor: TBGRAPixel;
  110.   img: TBGRABitmap;
  111.   bmpSource: TBitmap;
  112.   ImgW, ImgH, ImgX, ImgY: Integer;
  113. begin
  114.   bmp := TBGRABitmap.Create(Width, Height, BGRABlack);
  115.   try
  116.     bmp.FillTransparent;
  117.  
  118.     cx := Width div 2;
  119.     cy := Height div 2;
  120.     radius := Min(Width, Height) div 2 - FMargin;
  121.  
  122.     fillColor := ColorToBGRA(IfThen(FHover, FHoverColor, FNormalColor));
  123.     bmp.FillEllipseAntialias(cx, cy, radius, radius, fillColor);
  124.  
  125.     // Rysowanie ikony, jeśli jest
  126.     if Assigned(FPicture.Graphic) and not FPicture.Graphic.Empty then
  127.     begin
  128.       bmpSource := TBitmap.Create;
  129.       try
  130.         bmpSource.Assign(FPicture.Graphic);
  131.  
  132.         ImgW := bmpSource.Width;
  133.         ImgH := bmpSource.Height;
  134.  
  135.         // Skaluj do rozmiaru koła
  136.         if (ImgW > radius * 2) or (ImgH > radius * 2) then
  137.         begin
  138.           if ImgW > ImgH then
  139.           begin
  140.             ImgH := Round((radius * 2) * ImgH / ImgW);
  141.             ImgW := radius * 2;
  142.           end
  143.           else
  144.           begin
  145.             ImgW := Round((radius * 2) * ImgW / ImgH);
  146.             ImgH := radius * 2;
  147.           end;
  148.         end;
  149.  
  150.         img := TBGRABitmap.Create(bmpSource);
  151.         try
  152.           img := img.Resample(ImgW, ImgH, rmLanczos3);
  153.           ImgX := cx - ImgW div 2;
  154.           ImgY := cy - ImgH div 2;
  155.           bmp.PutImage(ImgX, ImgY, img, dmDrawWithTransparency);
  156.         finally
  157.           img.Free;
  158.         end;
  159.       finally
  160.         bmpSource.Free;
  161.       end;
  162.     end;
  163.  
  164.     bmp.Draw(Canvas, 0, 0, True);
  165.   finally
  166.     bmp.Free;
  167.   end;
  168. end;
  169.  
  170. procedure TFlatCircleButton.MouseEnter;
  171. begin
  172.   inherited MouseEnter;
  173.   FHover := True;
  174.   Invalidate;
  175. end;
  176.  
  177. procedure TFlatCircleButton.MouseLeave;
  178. begin
  179.   inherited MouseLeave;
  180.   FHover := False;
  181.   Invalidate;
  182. end;
  183.  
  184. procedure TFlatCircleButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  185. begin
  186.   inherited MouseUp(Button, Shift, X, Y);
  187.   if Assigned(FOnClick) then
  188.     FOnClick(Self);
  189. end;
  190.  
  191. end.
  192.  

Pe3s

  • Hero Member
  • *****
  • Posts: 647
Re: Question BGRAGraphicsControl
« Reply #5 on: August 09, 2025, 09:50:10 am »
Sorry, my mistake. I fixed it and it works.

 

TinyPortal © 2005-2018