@@ -26,12 +26,13 @@ begin
2626 Exit(True);
2727end;
2828
29- function TRSButton.WaitEnabled(time: Integer; interval: Integer = 50 ): Boolean;
29+ function TRSButton.WaitEnabled(const time: Integer; interval: Integer = -1 ): Boolean;
3030begin
31+ if interval < 0 then interval := RandomMode(100, 50, 1500);
3132 Result := SleepUntil(Self.Enabled(), interval, time);
3233end;
3334
34- procedure TRSButton.Click(button: EMouseButton = EMouseButton.LEFT);
35+ procedure TRSButton.Click(const button: EMouseButton = EMouseButton.LEFT);
3536begin
3637 Mouse.Click(Self.Bounds, button);
3738end;
@@ -136,7 +137,7 @@ begin
136137 Result := (tpa.Mean().X - Self.Bounds.X1) * 100 div Self.Width;
137138end;
138139
139- function TRSSlider.SetLevel(level: Integer): Boolean;
140+ function TRSSlider.SetLevel(const level: Integer): Boolean;
140141var
141142 current: Integer;
142143 p: TPoint;
@@ -159,3 +160,104 @@ begin
159160 Mouse.Click(p, EMouseButton.LEFT);
160161 Result := SleepUntil(Abs(Self.GetLevel()-level) < 2, RandomMode(100, 50, 1500), 600);
161162end;
163+
164+
165+ type
166+ TRSScrollBar = record
167+ ScrollArea, Up, Down: TBox;
168+ Bounds: TBox;
169+ Width, Height: Integer;
170+ end;
171+
172+ procedure TRSScrollBar.Setup();
173+ begin
174+ if Self.ScrollArea = Default(TBox) then
175+ raise GetDebugLn('ScrollBar', 'You need to set a ScrollArea to use the TRSScrollBar.Setup() method.');
176+
177+ Self.Bounds.X1 := Self.ScrollArea.X2 + 1;
178+ Self.Bounds.Y1 := Self.ScrollArea.Y1 + 16;
179+ Self.Bounds.X2 := Self.Bounds.X1 + 15;
180+ Self.Bounds.Y2 := Self.ScrollArea.Y2 - 16;
181+
182+ Self.Width := Self.Bounds.Width;
183+ Self.Height := Self.Bounds.Height;
184+
185+ Self.Up.X1 := Self.Bounds.X1;
186+ Self.Up.Y1 := Self.ScrollArea.Y1;
187+ Self.Up.X2 := Self.Bounds.X2;
188+ Self.Up.Y2 := Self.Bounds.Y1 - 1;
189+
190+ Self.Down.X1 := Self.Bounds.X1;
191+ Self.Down.Y1 := Self.Bounds.Y2 + 1;
192+ Self.Down.X2 := Self.Bounds.X2;
193+ Self.Down.Y2 := Self.ScrollArea.Y2;
194+ end;
195+
196+ function TRSScrollBar.IsVisible(): Boolean;
197+ begin
198+ Result := Target.HasColor(ColorTolerance($16091C, 16.971, EColorSpace.HSV, [0.277, 0.671, 2.054]), 1, Self.Up)
199+ and
200+ Target.HasColor(ColorTolerance($16091C, 16.971, EColorSpace.HSV, [0.277, 0.671, 2.054]), 1, Self.Down);
201+ end;
202+
203+ function TRSScrollBar.GetSlider(): TBox;
204+ var
205+ p: TPoint;
206+ tpa: TPointArray;
207+ begin
208+ p.X := Self.Bounds.X1 + Self.Width div 2;
209+ tpa := Target.FindColor(RSColors.INTERFACE_BORDER, 0, [p.X, Self.Bounds.Y1, p.X + 1, Self.Bounds.Y2]);
210+ if tpa = [] then Exit;
211+ Result.X1 := Self.Bounds.X1+1;
212+ Result.Y1 := tpa.First.Y;
213+ Result.X2 := Self.Bounds.X2-1;
214+ Result.Y2 := tpa.Last.Y;
215+ end;
216+
217+ function TRSScrollBar.CanScroll(): Boolean;
218+ begin
219+ Result := Self.IsVisible() and (Self.GetSlider() <> Self.Bounds);
220+ end;
221+
222+
223+ function TRSScrollBar.GetLevel(): Integer;
224+ begin
225+ with Self.GetSlider() do
226+ Result := Round((Y1 - Self.Bounds.Y1) * 100 / (Self.Height - Height));
227+ end;
228+
229+ function TRSScrollBar.SetLevel(value: Integer): Integer;
230+ begin
231+ if not Self.CanScroll() then Exit;
232+ value := EnsureRange(value, 0, 100);
233+ end;
234+
235+
236+
237+ procedure ShowOnClient(scroll: TRSScrollBar); overload;
238+ var
239+ img: TImage;
240+ bounds: TBox;
241+ begin
242+ img := TImage.CreateFromTarget();
243+
244+ img.DrawColor := $FFFF00;
245+ img.DrawBox(scroll.Bounds);
246+
247+ img.DrawColor := $FFFFFF;
248+ bounds := scroll.GetSlider();
249+ img.DrawBox(bounds);
250+
251+ img.DrawColor := $FF;
252+ img.FontSize := 12;
253+ bounds.X2 := bounds.X1 - 2;
254+ bounds.X1 -= 30;
255+ img.DrawText(ToStr(scroll.GetLevel()), bounds, [EImageTextAlign.CENTER]);
256+
257+ img.DrawColor := $00FFFF;
258+ img.DrawBoxArray([scroll.Up, scroll.Down], False);
259+
260+ img.Show();
261+ img.Free();
262+ end;
263+
0 commit comments