| 1 | unit ButtonN;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, Graphics, Controls, LCLIntf, LCLType, ScreenTools;
|
|---|
| 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('C-evo', [TButtonN]);
|
|---|
| 43 | end;
|
|---|
| 44 |
|
|---|
| 45 | constructor TButtonN.Create(aOwner: TComponent);
|
|---|
| 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 | BitBltCanvas(Canvas, 1, 1, 40, 40, FBackGraphic.Canvas,
|
|---|
| 65 | 1 + 80 * BackIndex + 40 * byte(FPossible and FLit), 176);
|
|---|
| 66 | if FPossible then
|
|---|
| 67 | begin
|
|---|
| 68 | BitBltCanvas(Canvas, 3, 3, 36, 36, FMask.Canvas,
|
|---|
| 69 | 195 + 37 * (FIndex mod 3), 21 + 37 * (FIndex div 3), SRCAND);
|
|---|
| 70 | BitBltCanvas(Canvas, 3, 3, 36, 36, FGraphic.Canvas,
|
|---|
| 71 | 195 + 37 * (FIndex mod 3), 21 + 37 * (FIndex div 3), SRCPAINT);
|
|---|
| 72 | end;
|
|---|
| 73 | end;
|
|---|
| 74 | MoveTo(0, 41);
|
|---|
| 75 | Pen.Color := $B0B0B0;
|
|---|
| 76 | LineTo(0, 0);
|
|---|
| 77 | LineTo(41, 0);
|
|---|
| 78 | Pen.Color := $FFFFFF;
|
|---|
| 79 | LineTo(41, 41);
|
|---|
| 80 | LineTo(0, 41);
|
|---|
| 81 | end;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | procedure TButtonN.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|---|
| 85 | x, y: integer);
|
|---|
| 86 | begin
|
|---|
| 87 | if FPossible and (Button = mbLeft) and (@ChangeProc <> nil) then
|
|---|
| 88 | ChangeProc(Self);
|
|---|
| 89 | end;
|
|---|
| 90 |
|
|---|
| 91 | procedure TButtonN.SetPossible(x: boolean);
|
|---|
| 92 | begin
|
|---|
| 93 | if x <> FPossible then
|
|---|
| 94 | begin
|
|---|
| 95 | FPossible := x;
|
|---|
| 96 | if x then
|
|---|
| 97 | Hint := FSmartHint
|
|---|
| 98 | else
|
|---|
| 99 | Hint := '';
|
|---|
| 100 | Invalidate;
|
|---|
| 101 | end;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | procedure TButtonN.SetLit(x: boolean);
|
|---|
| 105 | begin
|
|---|
| 106 | if x <> FLit then
|
|---|
| 107 | begin
|
|---|
| 108 | FLit := x;
|
|---|
| 109 | Invalidate;
|
|---|
| 110 | end;
|
|---|
| 111 | end;
|
|---|
| 112 |
|
|---|
| 113 | procedure TButtonN.SetIndex(x: integer);
|
|---|
| 114 | begin
|
|---|
| 115 | if x <> FIndex then
|
|---|
| 116 | begin
|
|---|
| 117 | FIndex := x;
|
|---|
| 118 | if x < 6 then
|
|---|
| 119 | BackIndex := 1
|
|---|
| 120 | else
|
|---|
| 121 | BackIndex := 0;
|
|---|
| 122 | Invalidate;
|
|---|
| 123 | end;
|
|---|
| 124 | end;
|
|---|
| 125 |
|
|---|
| 126 | procedure TButtonN.SetSmartHint(x: string);
|
|---|
| 127 | begin
|
|---|
| 128 | if x <> FSmartHint then
|
|---|
| 129 | begin
|
|---|
| 130 | FSmartHint := x;
|
|---|
| 131 | if FPossible then
|
|---|
| 132 | Hint := x;
|
|---|
| 133 | end;
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | end.
|
|---|