source: branches/AlphaChannel/Packages/CevoComponents/ButtonBase.pas

Last change on this file was 135, checked in by chronos, 7 years ago
  • Fixed: Reduced compiler warnings.
File size: 3.3 KB
Line 
1unit ButtonBase;
2
3interface
4
5uses
6 Classes, Graphics, Controls;
7
8type
9 TButtonBase = class(TGraphicControl)
10 protected
11 FDown, FPermanent: boolean;
12 FGraphic: TBitmap;
13 // FDownSound, FUpSound: string;
14 ClickProc: TNotifyEvent;
15 DownChangedProc: TNotifyEvent;
16 procedure SetDown(x: boolean);
17 // procedure PlayDownSound;
18 // procedure PlayUpSound;
19 procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
20 x, y: integer); override;
21 procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
22 x, y: integer); override;
23 procedure MouseMove(Shift: TShiftState; x, y: integer); override;
24 private
25 Active: boolean;
26 public
27 constructor Create(aOwner: TComponent); override;
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
37 write DownChangedProc;
38 end;
39
40implementation
41
42// uses
43// MMSystem;
44
45constructor TButtonBase.Create(aOwner: TComponent);
46begin
47 inherited;
48 // FDownSound:='';
49 // FUpSound:='';
50 FGraphic := nil;
51 Active := false;
52 FDown := false;
53 FPermanent := false;
54 ClickProc := nil;
55end;
56
57procedure TButtonBase.MouseDown(Button: TMouseButton; Shift: TShiftState;
58 x, y: integer);
59begin
60 Active := true;
61 MouseMove(Shift, x, y)
62end;
63
64procedure TButtonBase.MouseUp(Button: TMouseButton; Shift: TShiftState;
65 x, y: integer);
66begin
67 if ssLeft in Shift then
68 exit;
69 MouseMove(Shift, x, y);
70 if Active and FDown then
71 begin
72 // PlayUpSound;
73 Active := false;
74 if FDown <> FPermanent then
75 begin
76 FDown := FPermanent;
77 Invalidate;
78 if @DownChangedProc <> nil then
79 DownChangedProc(self);
80 end;
81 if (Button = mbLeft) and (@ClickProc <> nil) then
82 ClickProc(self)
83 end
84 else
85 begin
86 // if FDown then PlayUpSound;
87 Active := false;
88 if FDown then
89 begin
90 FDown := false;
91 Invalidate;
92 if @DownChangedProc <> nil then
93 DownChangedProc(self);
94 end;
95 end
96end;
97
98procedure TButtonBase.MouseMove(Shift: TShiftState; x, y: integer);
99begin
100 if Active then
101 if (x >= 0) and (x < Width) and (y >= 0) and (y < Height) then
102 if (ssLeft in Shift) and not FDown then
103 begin
104 { PlayDownSound; }
105 FDown := true;
106 Paint;
107 if @DownChangedProc <> nil then
108 DownChangedProc(self);
109 end
110 else
111 else if FDown and not FPermanent then
112 begin
113 { PlayUpSound; }
114 FDown := false;
115 Paint;
116 if @DownChangedProc <> nil then
117 DownChangedProc(self);
118 end
119end;
120
121procedure TButtonBase.SetDown(x: boolean);
122begin
123 FDown := x;
124 Invalidate;
125end;
126
127// procedure TButtonBase.PlayDownSound;
128// begin
129// if DownSound<>'' then SndPlaySound(pchar(DownSound),SND_ASYNC)
130// end;
131
132// procedure TButtonBase.PlayUpSound;
133// begin
134// if UpSound<>'' then SndPlaySound(pchar(UpSound),SND_ASYNC)
135// end;
136
137end.
Note: See TracBrowser for help on using the repository browser.