bgraspeedbutton.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. { This component partialy solve problem with no alpha in lazarus GTK.
  3. It is using BGRABitmap library for drawing icons.
  4. originally written in 2011 by Krzysztof Dibowski dibowski at interia.pl
  5. }
  6. {******************************* CONTRIBUTOR(S) ******************************
  7. - Edivando S. Santos Brasil | [email protected]
  8. (Compatibility with delphi VCL 11/2018)
  9. ***************************** END CONTRIBUTOR(S) *****************************}
  10. unit BGRASpeedButton;
  11. {$I bgracontrols.inc}
  12. interface
  13. uses
  14. Classes, SysUtils, {$IFDEF FPC}LResources,{$ENDIF} Forms, Controls, Graphics, Dialogs, Buttons, BGRABitmap,
  15. {$IFNDEF FPC}Types, BGRAGraphics, GraphType, FPImage, {$ENDIF}
  16. BGRABitmapTypes;
  17. {$IFDEF LCLgtk}
  18. {$DEFINE BGRA_DRAW}
  19. {$ELSE}
  20. {$IFDEF LCLgtk2}
  21. {$DEFINE BGRA_DRAW}
  22. {$ENDIF}
  23. {$ENDIF}
  24. type
  25. { TBGRASpeedButton }
  26. TBGRASpeedButton = class(TSpeedButton)
  27. private
  28. { Private declarations }
  29. {$IFDEF BGRA_DRAW}
  30. FBGRA: TBGRABitmap;
  31. {$ENDIF}
  32. protected
  33. { Protected declarations }
  34. {$IFDEF BGRA_DRAW}
  35. function DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
  36. const AOffset: TPoint; AState: TButtonState; {%H-}ATransparent: boolean;
  37. {%H-}BiDiFlags: longint): TRect; override;
  38. {$ENDIF}
  39. public
  40. { Public declarations }
  41. {$IFDEF BGRA_DRAW}
  42. constructor Create(AOwner: TComponent); override;
  43. destructor Destroy; override;
  44. {$ENDIF}
  45. published
  46. { Published declarations }
  47. end;
  48. {$IFDEF FPC}procedure Register;{$ENDIF}
  49. implementation
  50. {$IFDEF FPC}
  51. procedure Register;
  52. begin
  53. RegisterComponents('BGRA Button Controls', [TBGRASpeedButton]);
  54. end;
  55. {$ENDIF}
  56. {$IFDEF BGRA_DRAW}
  57. { TBGRASpeedButton }
  58. function TBGRASpeedButton.DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
  59. const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
  60. BiDiFlags: longint): TRect;
  61. begin
  62. {*** We are using BGRABitmap drawing only ***}
  63. {Result := inherited DrawGlyph(ACanvas, AClient, AOffset, AState,
  64. ATransparent, BiDiFlags); }
  65. if not Assigned(Glyph) then
  66. begin
  67. Result := Rect(0,0,0,0);
  68. Exit;
  69. end;
  70. { It's not good solution assigning glyph on each draw call but FGlyph and SetGlyph is
  71. in private section }
  72. FBGRA.Assign(Glyph);
  73. if (AState = bsDown) or (Down = True) then
  74. FBGRA.Draw(ACanvas, AOffset.x + 1, AOffset.y + 1, False)
  75. else
  76. FBGRA.Draw(ACanvas, AOffset.x, AOffset.y, False);
  77. Result := AClient;
  78. end;
  79. constructor TBGRASpeedButton.Create(AOwner: TComponent);
  80. begin
  81. inherited Create(AOwner);
  82. FBGRA := TBGRABitmap.Create;
  83. end;
  84. destructor TBGRASpeedButton.Destroy;
  85. begin
  86. FBGRA.Free;
  87. inherited Destroy;
  88. end;
  89. {$ENDIF}
  90. end.