| 1 | unit ButtonN;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | WinProcs, Classes, Graphics, Controls;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TButtonN = class(TGraphicControl)
|
|---|
| 10 | constructor Create(aOwner: TComponent); override;
|
|---|
| 11 | private
|
|---|
| 12 | FPossible, FLit: boolean;
|
|---|
| 13 | FGraphic, FMask, FBackGraphic: TBitmap;
|
|---|
| 14 | FIndex,BackIndex: integer;
|
|---|
| 15 | FSmartHint: string;
|
|---|
| 16 | ChangeProc: TNotifyEvent;
|
|---|
| 17 | procedure SetPossible(x: boolean);
|
|---|
| 18 | procedure SetLit(x: boolean);
|
|---|
| 19 | procedure SetIndex(x: integer);
|
|---|
| 20 | procedure SetSmartHint(x: string);
|
|---|
| 21 | published
|
|---|
| 22 | property Possible: boolean read FPossible write SetPossible;
|
|---|
| 23 | property Lit: boolean read FLit write SetLit;
|
|---|
| 24 | property SmartHint: string read FSmartHint write SetSmartHint;
|
|---|
| 25 | property Graphic: TBitmap read FGraphic write FGraphic;
|
|---|
| 26 | property Mask: TBitmap read FMask write FMask;
|
|---|
| 27 | property BackGraphic: TBitmap read FBackGraphic write FBackGraphic;
|
|---|
| 28 | property ButtonIndex: integer read FIndex write SetIndex;
|
|---|
| 29 | property OnClick: TNotifyEvent read ChangeProc write ChangeProc;
|
|---|
| 30 | protected
|
|---|
| 31 | procedure Paint; override;
|
|---|
| 32 | procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|---|
| 33 | x, y: integer); override;
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | procedure Register;
|
|---|
| 37 |
|
|---|
| 38 | implementation
|
|---|
| 39 |
|
|---|
| 40 | procedure Register;
|
|---|
| 41 | begin
|
|---|
| 42 | RegisterComponents('Samples', [TButtonN]);
|
|---|
| 43 | end;
|
|---|
| 44 |
|
|---|
| 45 | constructor TButtonN.Create;
|
|---|
| 46 | begin
|
|---|
| 47 | inherited Create(aOwner);
|
|---|
| 48 | ShowHint:=true;
|
|---|
| 49 | FGraphic:=nil;
|
|---|
| 50 | FBackGraphic:=nil;
|
|---|
| 51 | FPossible:=true;
|
|---|
| 52 | FLit:=false;
|
|---|
| 53 | FIndex:=-1;
|
|---|
| 54 | ChangeProc:=nil;
|
|---|
| 55 | SetBounds(0,0,42,42);
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | procedure TButtonN.Paint;
|
|---|
| 59 | begin
|
|---|
| 60 | with Canvas do
|
|---|
| 61 | begin
|
|---|
| 62 | if FGraphic<>nil then
|
|---|
| 63 | begin
|
|---|
| 64 | BitBlt(Canvas.Handle,1,1,40,40,FBackGraphic.Canvas.Handle,
|
|---|
| 65 | 1+80*BackIndex+40*byte(FPossible and FLit),176,SRCCOPY);
|
|---|
| 66 | if FPossible then
|
|---|
| 67 | begin
|
|---|
| 68 | BitBlt(Canvas.Handle,3,3,36,36,FMask.Canvas.Handle,
|
|---|
| 69 | 195+37*(FIndex mod 3),21+37*(FIndex div 3),SRCAND);
|
|---|
| 70 | BitBlt(Canvas.Handle,3,3,36,36,FGraphic.Canvas.Handle,
|
|---|
| 71 | 195+37*(FIndex mod 3),21+37*(FIndex div 3),SRCPAINT);
|
|---|
| 72 | end
|
|---|
| 73 | end;
|
|---|
| 74 | MoveTo(0,41);
|
|---|
| 75 | Pen.Color:=$B0B0B0;LineTo(0,0);LineTo(41,0);
|
|---|
| 76 | Pen.Color:=$FFFFFF;LineTo(41,41);LineTo(0,41);
|
|---|
| 77 | end
|
|---|
| 78 | end;
|
|---|
| 79 |
|
|---|
| 80 | procedure TButtonN.MouseDown;
|
|---|
| 81 | begin
|
|---|
| 82 | if FPossible and (Button=mbLeft) and (@ChangeProc<>nil) then
|
|---|
| 83 | ChangeProc(Self)
|
|---|
| 84 | end;
|
|---|
| 85 |
|
|---|
| 86 | procedure TButtonN.SetPossible(x: boolean);
|
|---|
| 87 | begin
|
|---|
| 88 | if x<>FPossible then
|
|---|
| 89 | begin
|
|---|
| 90 | FPossible:=x;
|
|---|
| 91 | if x then Hint:=FSmartHint
|
|---|
| 92 | else Hint:='';
|
|---|
| 93 | Invalidate
|
|---|
| 94 | end
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TButtonN.SetLit(x: boolean);
|
|---|
| 98 | begin
|
|---|
| 99 | if x<>FLit then
|
|---|
| 100 | begin
|
|---|
| 101 | FLit:=x;
|
|---|
| 102 | Invalidate
|
|---|
| 103 | end
|
|---|
| 104 | end;
|
|---|
| 105 |
|
|---|
| 106 | procedure TButtonN.SetIndex(x: integer);
|
|---|
| 107 | begin
|
|---|
| 108 | if x<>FIndex then
|
|---|
| 109 | begin
|
|---|
| 110 | FIndex:=x;
|
|---|
| 111 | if x<6 then BackIndex:=1
|
|---|
| 112 | else BackIndex:=0;
|
|---|
| 113 | Invalidate
|
|---|
| 114 | end
|
|---|
| 115 | end;
|
|---|
| 116 |
|
|---|
| 117 | procedure TButtonN.SetSmartHint(x: string);
|
|---|
| 118 | begin
|
|---|
| 119 | if x<>FSmartHint then
|
|---|
| 120 | begin
|
|---|
| 121 | FSmartHint:=x;
|
|---|
| 122 | if FPossible then Hint:=x;
|
|---|
| 123 | end
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | end.
|
|---|
| 127 |
|
|---|