| 1 | unit ButtonB;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | ButtonBase,
|
|---|
| 7 | WinProcs, Classes, Graphics;
|
|---|
| 8 |
|
|---|
| 9 | type
|
|---|
| 10 | TButtonB = class(TButtonBase)
|
|---|
| 11 | constructor Create(aOwner: TComponent); override;
|
|---|
| 12 | private
|
|---|
| 13 | FMask: TBitmap;
|
|---|
| 14 | FIndex: integer;
|
|---|
| 15 | procedure SetIndex(x: integer);
|
|---|
| 16 | public
|
|---|
| 17 | property Mask: TBitmap read FMask write FMask;
|
|---|
| 18 | published
|
|---|
| 19 | property Visible;
|
|---|
| 20 | property ButtonIndex: integer read FIndex write SetIndex;
|
|---|
| 21 | property OnClick;
|
|---|
| 22 | protected
|
|---|
| 23 | procedure Paint; override;
|
|---|
| 24 | end;
|
|---|
| 25 |
|
|---|
| 26 | procedure Register;
|
|---|
| 27 |
|
|---|
| 28 | implementation
|
|---|
| 29 |
|
|---|
| 30 | procedure Register;
|
|---|
| 31 | begin
|
|---|
| 32 | RegisterComponents('Samples', [TButtonB]);
|
|---|
| 33 | end;
|
|---|
| 34 |
|
|---|
| 35 | constructor TButtonB.Create;
|
|---|
| 36 | begin
|
|---|
| 37 | inherited Create(aOwner);
|
|---|
| 38 | ShowHint:=true;
|
|---|
| 39 | SetBounds(0,0,25,25);
|
|---|
| 40 | end;
|
|---|
| 41 |
|
|---|
| 42 | procedure TButtonB.Paint;
|
|---|
| 43 | begin
|
|---|
| 44 | with Canvas do
|
|---|
| 45 | if FGraphic<>nil then
|
|---|
| 46 | begin
|
|---|
| 47 | BitBlt(Canvas.Handle,0,0,25,25,FGraphic.Canvas.Handle,
|
|---|
| 48 | 169,243+26*Byte(FDown),SRCCOPY);
|
|---|
| 49 | if FIndex>=0 then
|
|---|
| 50 | begin
|
|---|
| 51 | BitBlt(Canvas.Handle,0,0,25,25,FMask.Canvas.Handle,
|
|---|
| 52 | 1+FIndex mod 12 *26,337+FIndex div 12 *26,SRCAND);
|
|---|
| 53 | BitBlt(Canvas.Handle,0,0,25,25,FGraphic.Canvas.Handle,
|
|---|
| 54 | 1+FIndex mod 12 *26,337+FIndex div 12 *26,SRCPAINT);
|
|---|
| 55 | end
|
|---|
| 56 | end
|
|---|
| 57 | else begin Brush.Color:=$0000FF; FrameRect(Rect(0,0,25,25)) end
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | procedure TButtonB.SetIndex(x: integer);
|
|---|
| 61 | begin
|
|---|
| 62 | if x<>FIndex then
|
|---|
| 63 | begin
|
|---|
| 64 | FIndex:=x;
|
|---|
| 65 | Invalidate
|
|---|
| 66 | end
|
|---|
| 67 | end;
|
|---|
| 68 |
|
|---|
| 69 | end.
|
|---|
| 70 |
|
|---|