source: trunk/Packages/bgracontrols/bgraimagelist.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 3.8 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 BGRAImageList;
32
33{$mode objfpc}{$H+}
34
35interface
36
37uses
38 Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
39 GraphType, BGRABitmap, BGRABitmapTypes, ImgList;
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 { TBGRAImageList }
52
53 TBGRAImageList = class(TImageList)
54 private
55 { Private declarations }
56 {$IFDEF BGRA_DRAW}
57 FBGRA: TBGRABitmap;
58 FBmp: TBitmap;
59 {$ENDIF}
60 protected
61 { Protected declarations }
62 public
63 { Public declarations }
64 {$IFDEF BGRA_DRAW}
65 constructor Create(AOwner: TComponent); override;
66 destructor Destroy; override;
67
68 procedure Draw(ACanvas: TCanvas; AX, AY, AIndex: integer;
69 ADrawingStyle: TDrawingStyle; AImageType: TImageType;
70 ADrawEffect: TGraphicsDrawEffect); override;
71 {$ENDIF}
72 published
73 { Published declarations }
74 end;
75
76procedure Register;
77
78implementation
79
80procedure Register;
81begin
82 {$I bgraimagelist_icon.lrs}
83 RegisterComponents('BGRA Controls', [TBGRAImageList]);
84end;
85
86{$IFDEF BGRA_DRAW}
87{ TBGRAImageList }
88constructor TBGRAImageList.Create(AOwner: TComponent);
89begin
90 inherited Create(AOwner);
91 FBGRA := TBGRABitmap.Create;
92 FBmp := TBitmap.Create;
93end;
94
95destructor TBGRAImageList.Destroy;
96begin
97 FBGRA.Free;
98 FBmp.Free;
99 inherited Destroy;
100end;
101
102{ Problem with no alpha is only on GTK so on Windows we use default drawing }
103procedure TBGRAImageList.Draw(ACanvas: TCanvas; AX, AY, AIndex: integer;
104 ADrawingStyle: TDrawingStyle; AImageType: TImageType;
105 ADrawEffect: TGraphicsDrawEffect);
106begin
107 //inherited; - We use TBGRABitmap drawing only
108
109 // This is required part from TImageList.Draw
110 if (AIndex < 0) or (AIndex >= Count) then
111 Exit;
112 ReferenceNeeded;
113
114 {*** BGRA Drawing *** }
115 case ADrawEffect of
116 gdeDisabled:
117 begin
118 GetBitmap(AIndex, FBmp, gdeNormal);
119 FBGRA.Assign(FBmp);
120 BGRAReplace(FBGRA, FBGRA.FilterGrayscale);
121 end;
122 else
123 begin
124 GetBitmap(AIndex, FBmp, ADrawEffect);
125 FBGRA.Assign(FBmp);
126 end;
127 end;
128 if ADrawingStyle in [dsFocus, dsSelected] then
129 FBGRA.ApplyGlobalOpacity(128);
130 FBGRA.Draw(ACanvas, AX, AY, False);
131end;
132
133{$ENDIF}
134
135end.
Note: See TracBrowser for help on using the repository browser.