1 | unit ButtonBase;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | WinProcs, Classes, Graphics, Controls;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TButtonBase = class(TGraphicControl)
|
---|
10 | constructor Create(aOwner: TComponent); override;
|
---|
11 | protected
|
---|
12 | FDown,FPermanent: boolean;
|
---|
13 | FGraphic: TBitmap;
|
---|
14 | // FDownSound, FUpSound: string;
|
---|
15 | ClickProc: TNotifyEvent;
|
---|
16 | DownChangedProc: TNotifyEvent;
|
---|
17 | procedure SetDown(x: boolean);
|
---|
18 | // procedure PlayDownSound;
|
---|
19 | // procedure PlayUpSound;
|
---|
20 | procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
---|
21 | x, y: integer); override;
|
---|
22 | procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
|
---|
23 | x, y: integer); override;
|
---|
24 | procedure MouseMove(Shift: TShiftState; x, y: integer); override;
|
---|
25 | private
|
---|
26 | Active: boolean;
|
---|
27 | public
|
---|
28 | property Graphic: TBitmap read FGraphic write FGraphic;
|
---|
29 | // property DownSound: string read FDownSound write FDownSound;
|
---|
30 | // property UpSound: string read FUpSound write FUpSound;
|
---|
31 | published
|
---|
32 | property Visible;
|
---|
33 | property Down: boolean read FDown write SetDown;
|
---|
34 | property Permanent: boolean read FPermanent write FPermanent;
|
---|
35 | property OnClick: TNotifyEvent read ClickProc write ClickProc;
|
---|
36 | property OnDownChanged: TNotifyEvent read DownChangedProc write DownChangedProc;
|
---|
37 | end;
|
---|
38 |
|
---|
39 | implementation
|
---|
40 |
|
---|
41 | //uses
|
---|
42 | // MMSystem;
|
---|
43 |
|
---|
44 | constructor TButtonBase.Create;
|
---|
45 | begin
|
---|
46 | inherited Create(aOwner);
|
---|
47 | //FDownSound:='';
|
---|
48 | //FUpSound:='';
|
---|
49 | FGraphic:=nil; Active:=false; FDown:=false; FPermanent:=false;
|
---|
50 | ClickProc:=nil;
|
---|
51 | end;
|
---|
52 |
|
---|
53 | procedure TButtonBase.MouseDown;
|
---|
54 | begin
|
---|
55 | Active:=true;
|
---|
56 | MouseMove(Shift,x,y)
|
---|
57 | end;
|
---|
58 |
|
---|
59 | procedure TButtonBase.MouseUp;
|
---|
60 | begin
|
---|
61 | if ssLeft in Shift then exit;
|
---|
62 | MouseMove(Shift,x,y);
|
---|
63 | if Active and FDown then
|
---|
64 | begin
|
---|
65 | // PlayUpSound;
|
---|
66 | Active:=false;
|
---|
67 | if FDown<>FPermanent then
|
---|
68 | begin
|
---|
69 | FDown:=FPermanent;
|
---|
70 | Invalidate;
|
---|
71 | if @DownChangedProc<>nil then DownChangedProc(self);
|
---|
72 | end;
|
---|
73 | if (Button=mbLeft) and (@ClickProc<>nil) then ClickProc(self)
|
---|
74 | end
|
---|
75 | else
|
---|
76 | begin
|
---|
77 | // if FDown then PlayUpSound;
|
---|
78 | Active:=false;
|
---|
79 | if FDown then
|
---|
80 | begin
|
---|
81 | FDown:=false;
|
---|
82 | Invalidate;
|
---|
83 | if @DownChangedProc<>nil then DownChangedProc(self);
|
---|
84 | end;
|
---|
85 | end
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure TButtonBase.MouseMove;
|
---|
89 | begin
|
---|
90 | if Active then
|
---|
91 | if (x>=0) and (x<Width) and (y>=0) and (y<Height) then
|
---|
92 | if (ssLeft in Shift) and not FDown then
|
---|
93 | begin
|
---|
94 | {PlayDownSound;}
|
---|
95 | FDown:=true;
|
---|
96 | Paint;
|
---|
97 | if @DownChangedProc<>nil then DownChangedProc(self);
|
---|
98 | end
|
---|
99 | else else if FDown and not FPermanent then
|
---|
100 | begin
|
---|
101 | {PlayUpSound;}
|
---|
102 | FDown:=false;
|
---|
103 | Paint;
|
---|
104 | if @DownChangedProc<>nil then DownChangedProc(self);
|
---|
105 | end
|
---|
106 | end;
|
---|
107 |
|
---|
108 | procedure TButtonBase.SetDown(x: boolean);
|
---|
109 | begin
|
---|
110 | FDown:=x;
|
---|
111 | Invalidate
|
---|
112 | end;
|
---|
113 |
|
---|
114 | //procedure TButtonBase.PlayDownSound;
|
---|
115 | //begin
|
---|
116 | //if DownSound<>'' then SndPlaySound(pchar(DownSound),SND_ASYNC)
|
---|
117 | //end;
|
---|
118 |
|
---|
119 | //procedure TButtonBase.PlayUpSound;
|
---|
120 | //begin
|
---|
121 | //if UpSound<>'' then SndPlaySound(pchar(UpSound),SND_ASYNC)
|
---|
122 | //end;
|
---|
123 |
|
---|
124 | end.
|
---|
125 |
|
---|