source: branches/delphi/EOTButton.pas

Last change on this file was 2, checked in by chronos, 7 years ago
File size: 3.5 KB
Line 
1unit EOTButton;
2
3interface
4
5uses
6 ButtonBase,
7 WinProcs, Classes, Graphics;
8
9const
10eotBlinkOff=-1; eotCancel=0; eotGray=1; eotBlinkOn=2; eotBackToNego=3;
11
12type
13 TEOTButton = class(TButtonBase)
14 constructor Create(aOwner: TComponent); override;
15 destructor Destroy; override;
16 procedure SetButtonIndexFast(x: integer);
17 procedure SetBack(ca: TCanvas; x,y: integer);
18 private
19 FTemplate: TBitmap;
20 FIndex: integer;
21 procedure SetIndex(x: integer);
22 public
23 property Template: TBitmap read FTemplate write FTemplate;
24 published
25 property Visible;
26 property ButtonIndex: integer read FIndex write SetIndex;
27 property OnClick;
28 protected
29 Buffer, Back: TBitmap;
30 procedure Paint; override;
31 end;
32
33procedure Register;
34
35implementation
36
37procedure Register;
38begin
39RegisterComponents('Samples', [TEOTButton]);
40end;
41
42procedure ImageOp_CBC(Dst,Src: TBitmap; xDst,yDst,xSrc,ySrc,w,h,Color0,Color2: integer);
43// Src is template
44// B channel = Color0 amp
45// G channel = background amp (old Dst content), 128=original brightness
46// R channel = Color2 amp
47type
48TLine=array[0..9999,0..2] of Byte;
49var
50ix,iy,amp0,amp1,trans,Value: integer;
51SrcLine,DstLine: ^TLine;
52begin
53for iy:=0 to h-1 do
54 begin
55 SrcLine:=Src.ScanLine[ySrc+iy];
56 DstLine:=Dst.ScanLine[yDst+iy];
57 for ix:=0 to w-1 do
58 begin
59 trans:=SrcLine[xSrc+ix,0]*2; // green channel = transparency
60 amp0:=SrcLine[xSrc+ix,1]*2;
61 amp1:=SrcLine[xSrc+ix,2]*2;
62 if trans<>$FF then
63 begin
64 Value:=(DstLine[xDst+ix][0]*trans+(Color2 shr 16 and $FF)*amp1+(Color0 shr 16 and $FF)*amp0) div $FF;
65 if Value<256 then
66 DstLine[xDst+ix][0]:=Value
67 else DstLine[xDst+ix][0]:=255;
68 Value:=(DstLine[xDst+ix][1]*trans+(Color2 shr 8 and $FF)*amp1+(Color0 shr 8 and $FF)*amp0) div $FF;
69 if Value<256 then
70 DstLine[xDst+ix][1]:=Value
71 else DstLine[xDst+ix][1]:=255;
72 Value:=(DstLine[xDst+ix][2]*trans+(Color2 and $FF)*amp1+(Color0 and $FF)*amp0) div $FF;
73 if Value<256 then
74 DstLine[xDst+ix][2]:=Value
75 else DstLine[xDst+ix][2]:=255;
76 end
77 end
78 end;
79end;
80
81constructor TEOTButton.Create;
82begin
83inherited Create(aOwner);
84Buffer:=TBitmap.Create;
85Buffer.PixelFormat:=pf24bit;
86Buffer.Width:=48;
87Buffer.Height:=48;
88Back:=TBitmap.Create;
89Back.PixelFormat:=pf24bit;
90Back.Width:=48;
91Back.Height:=48;
92ShowHint:=true;
93SetBounds(0,0,48,48);
94end;
95
96destructor TEOTButton.Destroy;
97begin
98Buffer.Free;
99Back.Free;
100inherited Destroy;
101end;
102
103procedure TEOTButton.Paint;
104begin
105with Canvas do
106 if FGraphic<>nil then
107 begin
108 BitBlt(Buffer.Canvas.Handle,0,0,48,48,Back.Canvas.Handle,0,0,SRCCOPY);
109 ImageOp_CBC(Buffer, Template, 0, 0, 133, 149+48*byte(FDown), 48, 48, $000000, $FFFFFF);
110 if FIndex>=0 then
111 ImageOp_CBC(Buffer, Template, 8, 8, 1+32*byte(FIndex), 246, 32, 32, $000000, $FFFFFF);
112 BitBlt(Canvas.Handle,0,0,48,48,Buffer.Canvas.Handle,0,0,SRCCOPY);
113 end
114 else begin Brush.Color:=$0000FF; FrameRect(Rect(0,0,48,48)) end
115end;
116
117procedure TEOTButton.SetIndex(x: integer);
118begin
119if x<>FIndex then
120 begin
121 FIndex:=x;
122 Invalidate
123 end
124end;
125
126procedure TEOTButton.SetButtonIndexFast(x: integer);
127begin
128if Visible and (x<>FIndex) then
129 begin
130 FIndex:=x;
131 try
132 Paint
133 except
134 end
135 end
136end;
137
138procedure TEOTButton.SetBack(ca: TCanvas; x,y: integer);
139begin
140BitBlt(Back.Canvas.Handle,0,0,48,48,ca.Handle,x,y,SRCCOPY);
141end;
142
143end.
144
Note: See TracBrowser for help on using the repository browser.