| 1 | unit EOTButton;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | ButtonBase,
|
|---|
| 7 | WinProcs, Classes, Graphics;
|
|---|
| 8 |
|
|---|
| 9 | const
|
|---|
| 10 | eotBlinkOff=-1; eotCancel=0; eotGray=1; eotBlinkOn=2; eotBackToNego=3;
|
|---|
| 11 |
|
|---|
| 12 | type
|
|---|
| 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 |
|
|---|
| 33 | procedure Register;
|
|---|
| 34 |
|
|---|
| 35 | implementation
|
|---|
| 36 |
|
|---|
| 37 | procedure Register;
|
|---|
| 38 | begin
|
|---|
| 39 | RegisterComponents('Samples', [TEOTButton]);
|
|---|
| 40 | end;
|
|---|
| 41 |
|
|---|
| 42 | procedure 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
|
|---|
| 47 | type
|
|---|
| 48 | TLine=array[0..9999,0..2] of Byte;
|
|---|
| 49 | var
|
|---|
| 50 | ix,iy,amp0,amp1,trans,Value: integer;
|
|---|
| 51 | SrcLine,DstLine: ^TLine;
|
|---|
| 52 | begin
|
|---|
| 53 | for 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;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | constructor TEOTButton.Create;
|
|---|
| 82 | begin
|
|---|
| 83 | inherited Create(aOwner);
|
|---|
| 84 | Buffer:=TBitmap.Create;
|
|---|
| 85 | Buffer.PixelFormat:=pf24bit;
|
|---|
| 86 | Buffer.Width:=48;
|
|---|
| 87 | Buffer.Height:=48;
|
|---|
| 88 | Back:=TBitmap.Create;
|
|---|
| 89 | Back.PixelFormat:=pf24bit;
|
|---|
| 90 | Back.Width:=48;
|
|---|
| 91 | Back.Height:=48;
|
|---|
| 92 | ShowHint:=true;
|
|---|
| 93 | SetBounds(0,0,48,48);
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 | destructor TEOTButton.Destroy;
|
|---|
| 97 | begin
|
|---|
| 98 | Buffer.Free;
|
|---|
| 99 | Back.Free;
|
|---|
| 100 | inherited Destroy;
|
|---|
| 101 | end;
|
|---|
| 102 |
|
|---|
| 103 | procedure TEOTButton.Paint;
|
|---|
| 104 | begin
|
|---|
| 105 | with 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
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | procedure TEOTButton.SetIndex(x: integer);
|
|---|
| 118 | begin
|
|---|
| 119 | if x<>FIndex then
|
|---|
| 120 | begin
|
|---|
| 121 | FIndex:=x;
|
|---|
| 122 | Invalidate
|
|---|
| 123 | end
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TEOTButton.SetButtonIndexFast(x: integer);
|
|---|
| 127 | begin
|
|---|
| 128 | if Visible and (x<>FIndex) then
|
|---|
| 129 | begin
|
|---|
| 130 | FIndex:=x;
|
|---|
| 131 | try
|
|---|
| 132 | Paint
|
|---|
| 133 | except
|
|---|
| 134 | end
|
|---|
| 135 | end
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 | procedure TEOTButton.SetBack(ca: TCanvas; x,y: integer);
|
|---|
| 139 | begin
|
|---|
| 140 | BitBlt(Back.Canvas.Handle,0,0,48,48,ca.Handle,x,y,SRCCOPY);
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | end.
|
|---|
| 144 |
|
|---|