source: branches/delphi/ButtonBase.pas

Last change on this file was 2, checked in by chronos, 7 years ago
File size: 3.0 KB
Line 
1unit ButtonBase;
2
3interface
4
5uses
6 WinProcs, Classes, Graphics, Controls;
7
8type
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
39implementation
40
41//uses
42// MMSystem;
43
44constructor TButtonBase.Create;
45begin
46inherited Create(aOwner);
47//FDownSound:='';
48//FUpSound:='';
49FGraphic:=nil; Active:=false; FDown:=false; FPermanent:=false;
50ClickProc:=nil;
51end;
52
53procedure TButtonBase.MouseDown;
54begin
55Active:=true;
56MouseMove(Shift,x,y)
57end;
58
59procedure TButtonBase.MouseUp;
60begin
61if ssLeft in Shift then exit;
62MouseMove(Shift,x,y);
63if 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
75else
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
86end;
87
88procedure TButtonBase.MouseMove;
89begin
90if 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
106end;
107
108procedure TButtonBase.SetDown(x: boolean);
109begin
110FDown:=x;
111Invalidate
112end;
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
124end.
125
Note: See TracBrowser for help on using the repository browser.