Changeset 14 for trunk/Components/EOTButton.pas
- Timestamp:
- Jan 7, 2017, 8:54:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Components/EOTButton.pas
r10 r14 8 8 9 9 const 10 eotBlinkOff=-1; eotCancel=0; eotGray=1; eotBlinkOn=2; eotBackToNego=3; 10 eotBlinkOff = -1; 11 eotCancel = 0; 12 eotGray = 1; 13 eotBlinkOn = 2; 14 eotBackToNego = 3; 11 15 12 16 type … … 15 19 destructor Destroy; override; 16 20 procedure SetButtonIndexFast(x: integer); 17 procedure SetBack(ca: TCanvas; x, y: integer);21 procedure SetBack(ca: TCanvas; x, y: integer); 18 22 private 19 23 FTemplate: TBitmap; … … 37 41 procedure Register; 38 42 begin 39 RegisterComponents('Samples', [TEOTButton]);43 RegisterComponents('Samples', [TEOTButton]); 40 44 end; 41 45 42 procedure ImageOp_CBC(Dst,Src: TBitmap; xDst,yDst,xSrc,ySrc,w,h,Color0,Color2: integer); 46 procedure ImageOp_CBC(Dst, Src: TBitmap; xDst, yDst, xSrc, ySrc, w, h, Color0, 47 Color2: integer); 43 48 // Src is template 44 49 // B channel = Color0 amp … … 46 51 // R channel = Color2 amp 47 52 type 48 TLine=array[0..9999,0..2] of Byte;53 TLine = array [0 .. 9999, 0 .. 2] of Byte; 49 54 var 50 ix,iy,amp0,amp1,trans,Value: integer;51 SrcLine,DstLine: ^TLine;55 ix, iy, amp0, amp1, trans, Value: integer; 56 SrcLine, DstLine: ^TLine; 52 57 begin 53 for iy:=0 to h-1 do58 for iy := 0 to h - 1 do 54 59 begin 55 SrcLine:=Src.ScanLine[ySrc+iy];56 DstLine:=Dst.ScanLine[yDst+iy];57 for ix:=0 to w-1 do60 SrcLine := Src.ScanLine[ySrc + iy]; 61 DstLine := Dst.ScanLine[yDst + iy]; 62 for ix := 0 to w - 1 do 58 63 begin 59 trans:=SrcLine[xSrc+ix,0]*2; // green channel = transparency60 amp0:=SrcLine[xSrc+ix,1]*2;61 amp1:=SrcLine[xSrc+ix,2]*2;62 if trans<>$FF then64 trans := SrcLine[xSrc + ix, 0] * 2; // green channel = transparency 65 amp0 := SrcLine[xSrc + ix, 1] * 2; 66 amp1 := SrcLine[xSrc + ix, 2] * 2; 67 if trans <> $FF then 63 68 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; 69 Value := (DstLine[xDst + ix][0] * trans + (Color2 shr 16 and $FF) * amp1 70 + (Color0 shr 16 and $FF) * amp0) div $FF; 71 if Value < 256 then 72 DstLine[xDst + ix][0] := Value 73 else 74 DstLine[xDst + ix][0] := 255; 75 Value := (DstLine[xDst + ix][1] * trans + (Color2 shr 8 and $FF) * amp1 76 + (Color0 shr 8 and $FF) * amp0) div $FF; 77 if Value < 256 then 78 DstLine[xDst + ix][1] := Value 79 else 80 DstLine[xDst + ix][1] := 255; 81 Value := (DstLine[xDst + ix][2] * trans + (Color2 and $FF) * amp1 + 82 (Color0 and $FF) * amp0) div $FF; 83 if Value < 256 then 84 DstLine[xDst + ix][2] := Value 85 else 86 DstLine[xDst + ix][2] := 255; 76 87 end 77 88 end … … 81 92 constructor TEOTButton.Create; 82 93 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 inherited Create(aOwner); 95 Buffer := TBitmap.Create; 96 Buffer.PixelFormat := pf24bit; 97 Buffer.Width := 48; 98 Buffer.Height := 48; 99 Back := TBitmap.Create; 100 Back.PixelFormat := pf24bit; 101 Back.Width := 48; 102 Back.Height := 48; 103 ShowHint := true; 104 SetBounds(0, 0, 48, 48); 94 105 end; 95 106 96 107 destructor TEOTButton.Destroy; 97 108 begin 98 Buffer.Free;99 Back.Free;100 inherited Destroy;109 Buffer.Free; 110 Back.Free; 111 inherited Destroy; 101 112 end; 102 113 103 114 procedure TEOTButton.Paint; 104 115 begin 105 with Canvas do106 if FGraphic<>nil then116 with Canvas do 117 if FGraphic <> nil then 107 118 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); 119 BitBlt(Buffer.Canvas.Handle, 0, 0, 48, 48, Back.Canvas.Handle, 0, 120 0, SRCCOPY); 121 ImageOp_CBC(Buffer, Template, 0, 0, 133, 149 + 48 * Byte(FDown), 48, 48, 122 $000000, $FFFFFF); 123 if FIndex >= 0 then 124 ImageOp_CBC(Buffer, Template, 8, 8, 1 + 32 * Byte(FIndex), 246, 32, 32, 125 $000000, $FFFFFF); 126 BitBlt(Canvas.Handle, 0, 0, 48, 48, Buffer.Canvas.Handle, 0, 0, SRCCOPY); 113 127 end 114 else begin Brush.Color:=$0000FF; FrameRect(Rect(0,0,48,48)) end 128 else 129 begin 130 Brush.Color := $0000FF; 131 FrameRect(Rect(0, 0, 48, 48)) 132 end 115 133 end; 116 134 117 135 procedure TEOTButton.SetIndex(x: integer); 118 136 begin 119 if x<>FIndex then137 if x <> FIndex then 120 138 begin 121 FIndex:=x;122 Invalidate139 FIndex := x; 140 Invalidate 123 141 end 124 142 end; … … 126 144 procedure TEOTButton.SetButtonIndexFast(x: integer); 127 145 begin 128 if Visible and (x<>FIndex) then146 if Visible and (x <> FIndex) then 129 147 begin 130 FIndex:=x;131 try132 Paint133 except148 FIndex := x; 149 try 150 Paint 151 except 134 152 end 135 153 end 136 154 end; 137 155 138 procedure TEOTButton.SetBack(ca: TCanvas; x, y: integer);156 procedure TEOTButton.SetBack(ca: TCanvas; x, y: integer); 139 157 begin 140 BitBlt(Back.Canvas.Handle,0,0,48,48,ca.Handle,x,y,SRCCOPY);158 BitBlt(Back.Canvas.Handle, 0, 0, 48, 48, ca.Handle, x, y, SRCCOPY); 141 159 end; 142 160 143 161 end. 144
Note:
See TracChangeset
for help on using the changeset viewer.