source: trunk/Packages/bgracontrols/bgraspeedbutton.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 3.7 KB
Line 
1{ This component partialy solve problem with no alpha in lazarus GTK.
2 It is using BGRABitmap library for drawing icons.
3
4 Copyright (C) 2011 Krzysztof Dibowski dibowski at interia.pl
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version with the following modification:
10
11 As a special exception, the copyright holders of this library give you
12 permission to link this library with independent modules to produce an
13 executable, regardless of the license terms of these independent modules,and
14 to copy and distribute the resulting executable under terms of your choice,
15 provided that you also meet, for each linked independent module, the terms
16 and conditions of the license of that module. An independent module is a
17 module which is not derived from or based on this library. If you modify
18 this library, you may extend this exception to your version of the library,
19 but you are not obligated to do so. If you do not wish to do so, delete this
20 exception statement from your version.
21
22 This program is distributed in the hope that it will be useful, but WITHOUT
23 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
25 for more details.
26
27 You should have received a copy of the GNU Library General Public License
28 along with this library; if not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30}
31unit BGRASpeedButton;
32
33{$mode objfpc}{$H+}
34
35interface
36
37uses
38 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons, BGRABitmap,
39 BGRABitmapTypes;
40
41{$IFDEF LCLgtk}
42 {$DEFINE BGRA_DRAW}
43{$ELSE}
44 {$IFDEF LCLgtk2}
45 {$DEFINE BGRA_DRAW}
46 {$ENDIF}
47{$ENDIF}
48
49type
50
51 { TBGRASpeedButton }
52
53 TBGRASpeedButton = class(TSpeedButton)
54 private
55 { Private declarations }
56 {$IFDEF BGRA_DRAW}
57 FBGRA: TBGRABitmap;
58 {$ENDIF}
59 protected
60 { Protected declarations }
61 {$IFDEF BGRA_DRAW}
62 function DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
63 const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
64 BiDiFlags: longint): TRect; override;
65 {$ENDIF}
66 public
67 { Public declarations }
68 {$IFDEF BGRA_DRAW}
69 constructor Create(AOwner: TComponent); override;
70 destructor Destroy; override;
71 {$ENDIF}
72 published
73 { Published declarations }
74 end;
75
76procedure Register;
77
78implementation
79
80procedure Register;
81begin
82 {$I bgraspeedbutton_icon.lrs}
83 RegisterComponents('BGRA Controls', [TBGRASpeedButton]);
84end;
85
86{$IFDEF BGRA_DRAW}
87{ TBGRASpeedButton }
88
89function TBGRASpeedButton.DrawGlyph(ACanvas: TCanvas; const AClient: TRect;
90 const AOffset: TPoint; AState: TButtonState; ATransparent: boolean;
91 BiDiFlags: longint): TRect;
92begin
93 {*** We are using BGRABitmap drawing only ***}
94 {Result := inherited DrawGlyph(ACanvas, AClient, AOffset, AState,
95 ATransparent, BiDiFlags); }
96
97 if Glyph = nil then
98 Exit;
99 { It's not good solution assigning glyph on each draw call but FGlyph and SetGlyph is
100 in private section }
101 FBGRA.Assign(Glyph);
102
103 if Assigned(Glyph) then
104 begin
105 if (AState = bsDown) or (Down = True) then
106 FBGRA.Draw(ACanvas, AOffset.x + 1, AOffset.y + 1, False)
107 else
108 FBGRA.Draw(ACanvas, AOffset.x, AOffset.y, False);
109 end;
110end;
111
112constructor TBGRASpeedButton.Create(AOwner: TComponent);
113begin
114 inherited Create(AOwner);
115 FBGRA := TBGRABitmap.Create;
116end;
117
118destructor TBGRASpeedButton.Destroy;
119begin
120 FBGRA.Free;
121 inherited Destroy;
122end;
123
124{$ENDIF}
125
126end.
Note: See TracBrowser for help on using the repository browser.