source: trunk/Packages/CevoComponents/ButtonN.pas

Last change on this file was 554, checked in by chronos, 3 weeks ago
  • Added: TButtonG class as a button class component referencing TGraphicSet item.
  • Modified: Code cleanup.
File size: 3.2 KB
Line 
1unit ButtonN;
2
3interface
4
5uses
6 Classes, LCLIntf, LCLType, ScreenTools,
7 {$IFDEF DPI}Dpi.Graphics, Dpi.Controls{$ELSE}Graphics, Controls{$ENDIF};
8
9type
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
37procedure Register;
38
39
40implementation
41
42procedure Register;
43begin
44 RegisterComponents('C-evo', [TButtonN]);
45end;
46
47constructor TButtonN.Create(AOwner: TComponent);
48begin
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);
58end;
59
60procedure TButtonN.Paint;
61begin
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;
84end;
85
86procedure TButtonN.MouseDown(Button: TMouseButton; Shift: TShiftState;
87 X, Y: Integer);
88begin
89 if FPossible and (Button = TMouseButton.mbLeft) and (@ChangeProc <> nil) then
90 ChangeProc(Self);
91end;
92
93procedure TButtonN.SetPossible(X: Boolean);
94begin
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;
104end;
105
106procedure TButtonN.SetLit(X: Boolean);
107begin
108 if X <> FLit then
109 begin
110 FLit := X;
111 Invalidate;
112 end;
113end;
114
115procedure TButtonN.SetIndex(X: Integer);
116begin
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;
126end;
127
128procedure TButtonN.SetSmartHint(X: string);
129begin
130 if X <> FSmartHint then
131 begin
132 FSmartHint := X;
133 if FPossible then
134 Hint := X;
135 end;
136end;
137
138end.
Note: See TracBrowser for help on using the repository browser.