source: trunk/Packages/CevoComponents/ButtonB.pas

Last change on this file was 734, checked in by chronos, 11 days ago
  • Fixed: Some buttons were not paint correctly with Qt5 widgetset.
File size: 2.0 KB
Line 
1unit ButtonB;
2
3interface
4
5uses
6 ButtonBase, Classes, LCLIntf, LCLType, SysUtils,
7 {$IFDEF DPI}Dpi.Graphics{$ELSE}Graphics{$ENDIF};
8
9type
10
11 { TButtonB }
12
13 TButtonB = class(TButtonBase)
14 private
15 FMask: TBitmap;
16 FIndex: Integer;
17 FBuffer: TBitmap;
18 procedure SetIndex(Text: Integer);
19 protected
20 procedure Paint; override;
21 public
22 constructor Create(AOwner: TComponent); override;
23 destructor Destroy; override;
24 property Mask: TBitmap read FMask write FMask;
25 published
26 property Visible;
27 property ButtonIndex: Integer read FIndex write SetIndex;
28 property OnClick;
29 end;
30
31procedure Register;
32
33
34implementation
35
36uses
37 ScreenTools;
38
39procedure Register;
40begin
41 RegisterComponents('C-evo', [TButtonB]);
42end;
43
44constructor TButtonB.Create;
45begin
46 inherited;
47 ShowHint := True;
48 SetBounds(0, 0, 25, 25);
49 FBuffer := TBitmap.Create;
50 FBuffer.PixelFormat := TPixelFormat.pf24bit;
51 FBuffer.SetSize(Width, Height);
52 FBuffer.Canvas.FillRect(0, 0, FBuffer.Width, FBuffer.Height);
53end;
54
55destructor TButtonB.Destroy;
56begin
57 FreeAndNil(FBuffer);
58 inherited;
59end;
60
61procedure TButtonB.Paint;
62begin
63 with Canvas do
64 if FGraphic <> nil then begin
65 UnshareBitmap(FBuffer);
66 BitBltBitmap(FBuffer, 0, 0, Width, Height, FGraphic, 169,
67 243 + 26 * Byte(FDown));
68 if FIndex >= 0 then begin
69 BitBltBitmap(FBuffer, 0, 0, Width, Height, FMask,
70 1 + FIndex mod 12 * 26, 337 + FIndex div 12 * 26, SRCAND);
71 BitBltBitmap(FBuffer, 0, 0, Width, Height, FGraphic,
72 1 + FIndex mod 12 * 26, 337 + FIndex div 12 * 26, SRCPAINT);
73 end;
74 BitBltCanvas(Canvas, 0, 0, Width, Height, FBuffer.Canvas, 0, 0);
75 end else begin
76 Brush.Color := $0000FF;
77 FrameRect(Rect(0, 0, Width, Height));
78 end;
79 inherited;
80end;
81
82procedure TButtonB.SetIndex(Text: Integer);
83begin
84 if Text <> FIndex then begin
85 FIndex := Text;
86 Invalidate;
87 end;
88end;
89
90end.
Note: See TracBrowser for help on using the repository browser.