source: branches/delphi/ButtonN.pas

Last change on this file was 2, checked in by chronos, 7 years ago
File size: 2.8 KB
Line 
1unit ButtonN;
2
3interface
4
5uses
6 WinProcs, Classes, Graphics, Controls;
7
8type
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
36procedure Register;
37
38implementation
39
40procedure Register;
41begin
42RegisterComponents('Samples', [TButtonN]);
43end;
44
45constructor TButtonN.Create;
46begin
47inherited Create(aOwner);
48ShowHint:=true;
49FGraphic:=nil;
50FBackGraphic:=nil;
51FPossible:=true;
52FLit:=false;
53FIndex:=-1;
54ChangeProc:=nil;
55SetBounds(0,0,42,42);
56end;
57
58procedure TButtonN.Paint;
59begin
60with 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
78end;
79
80procedure TButtonN.MouseDown;
81begin
82if FPossible and (Button=mbLeft) and (@ChangeProc<>nil) then
83 ChangeProc(Self)
84end;
85
86procedure TButtonN.SetPossible(x: boolean);
87begin
88if x<>FPossible then
89 begin
90 FPossible:=x;
91 if x then Hint:=FSmartHint
92 else Hint:='';
93 Invalidate
94 end
95end;
96
97procedure TButtonN.SetLit(x: boolean);
98begin
99if x<>FLit then
100 begin
101 FLit:=x;
102 Invalidate
103 end
104end;
105
106procedure TButtonN.SetIndex(x: integer);
107begin
108if x<>FIndex then
109 begin
110 FIndex:=x;
111 if x<6 then BackIndex:=1
112 else BackIndex:=0;
113 Invalidate
114 end
115end;
116
117procedure TButtonN.SetSmartHint(x: string);
118begin
119if x<>FSmartHint then
120 begin
121 FSmartHint:=x;
122 if FPossible then Hint:=x;
123 end
124end;
125
126end.
127
Note: See TracBrowser for help on using the repository browser.