1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
{Trackbar}
type
pAWKTrackbar = ^tAWKTrackbar;
tAWKTrackbar = object(TObj)
total:integer;
UpdInterval:integer;
OldMouseDown,
OldMouseUp:TOnMouse;
procedure CtrlResize(Sender: PObj);
procedure Erase(Sender: PControl; DC: HDC);
procedure Paint(Sender: PControl; DC: HDC);
procedure Scroll(Sender:PTrackbar; Code:integer);
procedure PressButton (Sender: PControl;var Mouse: TMouseEventData);
procedure UnPressButton(Sender: PControl;var Mouse: TMouseEventData);
procedure DragButton (Sender: PControl;var Mouse: TMouseEventData);
end;
procedure ResetTrackbar(Trackbar:PControl);
begin
if Trackbar=nil then exit;
with pTrackbar(Trackbar)^ do
begin
RangeMin:=0;
RangeMax:=0;
Position:=0;
end;
end;
procedure TrackbarSetRange(Trackbar:PTrackbar;timer:integer;total:integer=-1);
var
D:pAWKTrackbar;
lpercent:real;
begin
if Trackbar=nil then exit;
with Trackbar^ do
begin
D:=pointer(CustomObj);
if total<0 then // changing timer only
begin
total:=D.total;
if RangeMax>0 then
lpercent:=position/RangeMax
else
lpercent:=0;
end
else // for new track
begin
D.total:=total;
lpercent:=0;
end;
D.UpdInterval:=timer;
total:=(total*1000) div timer;
RangeMax:=total;
LineSize:=total div 100;
PageSize:=total div 10;
Position:=round(lpercent*total);
end;
end;
procedure SetTrackbarPosition(Trackbar:PTrackbar;pos:integer);
begin
if Trackbar=nil then exit;
//?? if Sender.ChildCount=0 then exit;
if pIcoButton(Trackbar.Children[0]).State<>AST_PRESSED then
Trackbar.Position:=pos;
Trackbar.Update;
end;
function CoordToPos(Trackbar:PTrackbar;x:integer):integer;
var
range:integer;
rmin,rmax:integer;
offsetthumb,width:integer;
rc:TRect;
begin
result:=0;
if Trackbar=nil then exit;
rmin:=Trackbar.RangeMin;
rmax:=Trackbar.RangeMax;
range:=rmax-rmin; // logic width
offsetthumb:=Trackbar.ThumbLen div 2;
rc:=Trackbar.ChannelRect;
width:= (rc.right-rc.left)-(offsetthumb*2)-1;
result:=(range*(x-rc.left-offsetthumb)) div width;
inc(result,rmin);
if result>rmax then
result:=rmax
else if result<rmin then
result:=rmin;
end;
procedure tAWKTrackbar.PressButton(Sender: PControl;var Mouse: TMouseEventData);
begin
pAWKTrackbar(Sender.Parent.CustomObj).OldMouseDown(Sender,Mouse);
pIcoButton(Sender)^.Action:=PTrackbar(Sender.Parent).Position;
end;
procedure tAWKTrackbar.UnPressButton(Sender: PControl;var Mouse: TMouseEventData);
begin
pAWKTrackbar(Sender.Parent.CustomObj).OldMouseUp(Sender,Mouse);
CallService(MS_WAT_PRESSBUTTON,WAT_CTRL_SEEK,
pIcoButton(Sender)^.Action*pAWKTrackbar(Sender.Parent.CustomObj).UpdInterval div 1000);
pIcoButton(Sender)^.Action:=-1;
end;
procedure tAWKTrackbar.DragButton(Sender: PControl;var Mouse: TMouseEventData);
var
pos:integer;
begin
with pIcoButton(Sender)^ do
if State=AST_PRESSED then
begin
pos:=CoordToPos(PTrackbar(Sender.Parent),Sender.Left+Mouse.X);
if Action<>pos then
begin
Action:=pos;
PTrackbar(Sender.Parent).Position:=pos;
end;
end;
end;
procedure tAWKTrackbar.Scroll(Sender:PTrackbar; Code:integer);
begin
if code=TB_ENDTRACK then
begin
CallService(MS_WAT_PRESSBUTTON,WAT_CTRL_SEEK,
Sender.Position*pAWKTrackbar(Sender.CustomObj).UpdInterval div 1000);
end;
end;
procedure tAWKTrackbar.CtrlResize(Sender: PObj);
var
tmp:integer;
begin
tmp:=PControl(Sender).Parent.Width-16;
if (PTrackbar(Sender)^.Width)>tmp then
PTrackbar(Sender)^.Width:=tmp;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// need to move slider here
// PControl(Sender).Update;
end;
procedure tAWKTrackbar.Erase(Sender: PControl; DC: HDC);
begin
// Sender.Parent.Update;
end;
procedure tAWKTrackbar.Paint(Sender: PControl; DC: HDC);
var
rc, rc1:TRECT;
w:integer;
begin
SendMessage(Sender.Handle,TBM_GETTHUMBRECT,0,tlparam(@rc));
w:=rc.right-rc.left;
if w<>16 then
rc.left:=rc.left+(w div 2)-8;
copyRect(rc1,Sender.BoundsRect);
rc1.Right :=rc1.Right-rc1.Left-8;
rc1.Left :=4;
rc1.Top :=7{((rc1.Bottom-rc1.Top) div 2)-2};
rc1.Bottom:=rc1.Top+4;
DrawEdge(DC,rc1,EDGE_SUNKEN,BF_RECT or BF_ADJUST);
if Sender.ChildCount>0 then
Sender.Children[0].Left:=rc.Left
else
begin
rc.right:=rc.left+8;
DrawFrameControl(DC,rc,DFC_BUTTON,DFCS_BUTTONPUSH);
end;
end;
procedure RefreshTrackbarIcons(Owner:PControl);
begin
if Owner.ChildCount>0 then
pIcoButton(Owner.Children[0]).RefreshIcon;
end;
function MakeNewTrackBar(AOwner:PControl):PTrackbar;
var
D:pAWKTrackbar;
btn:pIcoButton;
begin
New(D, Create);
result:=NewTrackbar(AOwner,[trbNoTicks,trbBoth,trbNoBorder],D.Scroll);
with result^ do
begin
Transparent:=true;
CustomObj:=D;
SetSize(AOwner.Width-16,18);
SetPosition({AOwner.Left+}8,{AOwner.Top+}AOwner.Height-18);
Anchor(true,false,true,true);
ThumbLen:=16;
RangeMin:=0;
RangeMax:=100;
btn:=CreateIcoButton(result,GetIcon,DoAction,WAT_CTRL_SEEK);
if btn<>nil then
begin
btn.ResetEvent(idx_fOnClick);
D.OldMouseDown:=btn.OnMouseDown;
btn.OnMouseDown:=D.PressButton;
D.OldMouseUp:=btn.OnMouseUp;
btn.OnMouseUp :=D.UnPressButton;
btn.OnMouseMove:=D.DragButton;
end;
OnResize :=D.CtrlResize;
OnEraseBkGnd:=D.Erase;
OnPaint :=D.Paint;
// OnScroll :=D.Scroll;
end;
end;
|