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