bgraresizespeedbutton.pas 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. {
  3. Created by Fox. Part of BGRA Controls.
  4. For detailed information see readme.txt
  5. Site: https://sourceforge.net/p/bgra-controls/
  6. Wiki: http://wiki.lazarus.freepascal.org/BGRAControls
  7. Forum: http://forum.lazarus.freepascal.org/index.php/board,46.0.html
  8. }
  9. {******************************* CONTRIBUTOR(S) ******************************
  10. - Edivando S. Santos Brasil | [email protected]
  11. (Compatibility with delphi VCL 11/2018)
  12. ***************************** END CONTRIBUTOR(S) *****************************}
  13. unit BGRAResizeSpeedButton;
  14. {$I bgracontrols.inc}
  15. interface
  16. uses
  17. Classes, SysUtils, Buttons, {$IFDEF FPC}LResources,{$ENDIF} Forms,
  18. Controls, Graphics, Dialogs,
  19. {$IFNDEF FPC}Types, BGRAGraphics, GraphType, FPImage, {$ENDIF}
  20. BGRASpeedButton, BGRABitmap;
  21. type
  22. TBGRAResizeSpeedButton = class(TBGRASpeedButton)
  23. private
  24. { Private declarations }
  25. FBGRA: TBGRABitmap;
  26. protected
  27. { Protected declarations }
  28. function DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
  29. const {%H-}AOffset: TPoint; AState: TButtonState; {%H-}ATransparent: boolean;
  30. {%H-}BiDiFlags: longint): TRect; {$IFDEF FPC}override;{$ENDIF}
  31. public
  32. { Public declarations }
  33. constructor Create(AOwner: TComponent); override;
  34. destructor Destroy; override;
  35. published
  36. { Published declarations }
  37. end;
  38. {$IFDEF FPC}procedure Register;{$ENDIF}
  39. implementation
  40. function TBGRAResizeSpeedButton.DrawGlyph(ACanvas: TCanvas;
  41. const AClient: TRect; const AOffset: TPoint; AState: TButtonState;
  42. ATransparent: boolean; BiDiFlags: longint): TRect;
  43. begin
  44. Result := Rect(0, 0, 0, 0);
  45. if Glyph = nil then
  46. Exit;
  47. Result := AClient;
  48. if Assigned(Glyph) and not Glyph.Empty then
  49. begin
  50. FBGRA.Assign(Glyph);
  51. BGRAReplace(FBGRA, FBGRA.Resample(Self.Width - 6, Self.Height - 6));
  52. if (AState = bsDown) or (Down = True) then
  53. FBGRA.Draw(ACanvas, 4, 4, False)
  54. else
  55. FBGRA.Draw(ACanvas, 3, 3, False);
  56. end;
  57. end;
  58. constructor TBGRAResizeSpeedButton.Create(AOwner: TComponent);
  59. begin
  60. inherited Create(AOwner);
  61. FBGRA := TBGRABitmap.Create;
  62. end;
  63. destructor TBGRAResizeSpeedButton.Destroy;
  64. begin
  65. FBGRA.Free;
  66. inherited Destroy;
  67. end;
  68. {$IFDEF FPC}
  69. procedure Register;
  70. begin
  71. RegisterComponents('BGRA Button Controls', [TBGRAResizeSpeedButton]);
  72. end;
  73. {$ENDIF}
  74. end.