Skip to content

Commit bef9886

Browse files
committed
fix(formutils): improved custom DPI support
1 parent 2a21a7a commit bef9886

File tree

3 files changed

+107
-44
lines changed

3 files changed

+107
-44
lines changed

osrs/interfaces/mainscreen/shop.simba

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,6 @@ WriteLn Shop.Buy('Gold ore', ERSShopQuantity.FIFTY);
213213
```
214214
*)
215215
function TRSShop.Buy(item: TRSItem; quantity: ERSShopQuantity = ERSShopQuantity.ONE): Boolean;
216-
var
217-
i: Integer;
218216
begin
219217
Result := False;
220218
if not Self.IsOpen() then Exit;
@@ -237,32 +235,6 @@ begin
237235
Result := True;
238236
end;
239237

240-
(*
241-
## Shop.BuyAtValue
242-
```pascal
243-
function TRSShop.BuyAtValue(item: TRSItem; quantity: Integer; price: Integer): Boolean;
244-
```
245-
Attempts to buy the specified item from the shop at a specific price using the value option.
246-
247-
Example:
248-
```pascal
249-
WriteLn Shop.BuyAtValue('Gold ore', 10, 100);
250-
```
251-
*)
252-
function TRSShop.BuyAtValue(item: TRSItem; quantity: Integer; price: Integer): Boolean;
253-
var
254-
slot, i: Integer;
255-
begin
256-
// TODO
257-
if not Self.IsOpen() then Exit;
258-
if not Self.Items.Contains(item) then Exit;
259-
260-
Self.Items.Interact(item, 'Value');
261-
Biometrics.Sleep(50, 200);
262-
263-
Result := True;
264-
end;
265-
266238
(*
267239
## Shop.Sell
268240
```pascal
@@ -310,8 +282,6 @@ WriteLn Shop.GetPrice('Gold ore');
310282
```
311283
*)
312284
function TRSShop.GetPrice(item: TRSItem): Integer;
313-
var
314-
slot: Integer;
315285
begin
316286
if not Self.IsOpen() then Exit;
317287
if not Self.Items.Contains(item) then Exit;

utils/forms/formutils.simba

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,95 @@ begin
176176
Lapify(checkbox.OnChange)(checkbox);
177177
end;
178178

179-
180-
181-
182179
var
183180
FormUtils: TFormUtils;
184181

185-
186182
property TLazControl.Left(value: Integer); override;
187183
begin
188184
inherited(Round(value * FormUtils.Scale));
189185
end;
190186

187+
property TLazControl.Left: Integer; override;
188+
begin
189+
Result := Round(inherited / FormUtils.Scale);
190+
end;
191+
192+
191193
property TLazControl.Top(value: Integer); override;
192194
begin
193195
inherited(Round(value * FormUtils.Scale));
194196
end;
195197

198+
property TLazControl.Top: Integer; override;
199+
begin
200+
Result := Round(inherited / FormUtils.Scale);
201+
end;
202+
203+
196204
property TLazControl.Width(value: Integer); override;
197205
begin
198206
inherited(Round(value * FormUtils.Scale));
199207
end;
200208

209+
property TLazControl.Width: Integer; override;
210+
begin
211+
Result := Round(inherited / FormUtils.Scale);
212+
end;
213+
201214
property TLazControl.Height(value: Integer); override;
202215
begin
203216
inherited(Round(value * FormUtils.Scale));
204217
end;
205218

219+
property TLazControl.Height: Integer; override;
220+
begin
221+
Result := Round(inherited / FormUtils.Scale);
222+
end;
223+
224+
225+
226+
property TLazSizeConstraints.MinWidth(value: Integer); override;
227+
begin
228+
inherited(Round(value * FormUtils.Scale));
229+
end;
230+
231+
property TLazSizeConstraints.MinWidth: Integer; override;
232+
begin
233+
Result := Round(inherited / FormUtils.Scale);
234+
end;
235+
236+
property TLazSizeConstraints.MaxWidth(value: Integer); override;
237+
begin
238+
inherited(Round(value * FormUtils.Scale));
239+
end;
240+
241+
property TLazSizeConstraints.MaxWidth: Integer; override;
242+
begin
243+
Result := Round(inherited / FormUtils.Scale);
244+
end;
245+
246+
247+
property TLazSizeConstraints.MinHeight(value: Integer); override;
248+
begin
249+
inherited(Round(value * FormUtils.Scale));
250+
end;
251+
252+
property TLazSizeConstraints.MinHeight: Integer; override;
253+
begin
254+
Result := Round(inherited / FormUtils.Scale);
255+
end;
256+
257+
property TLazSizeConstraints.MaxHeight(value: Integer); override;
258+
begin
259+
inherited(Round(value * FormUtils.Scale));
260+
end;
261+
262+
property TLazSizeConstraints.MaxHeight: Integer; override;
263+
begin
264+
Result := Round(inherited / FormUtils.Scale);
265+
end;
266+
267+
206268

207269
property TLazControlBorderSpacing.Left(value: Integer); override;
208270
begin
@@ -834,6 +896,41 @@ begin
834896
end;
835897

836898

899+
function TLazImage.CreateEx(owner: Pointer): TLazImage; static;
900+
begin
901+
Result := TLazImage.Create(TLazControl(owner));
902+
Result.Parent := TLazComponent(owner);
903+
end;
904+
905+
function TLazImage.CreateEx(owner: Pointer; caption: String; hint: String = ''; left, top, width, height: Integer = 0): TLazImage; static; overload;
906+
var
907+
lbl: TLazLabel;
908+
begin
909+
Result := TLazImage.CreateEx(owner);
910+
911+
if left > 0 then Result.Left := left;
912+
if top > 0 then Result.Top := top;
913+
if width > 0 then Result.Width := width;
914+
if height > 0 then Result.Height := height;
915+
916+
if caption <> '' then
917+
begin
918+
lbl := TLazLabel.CreateEx(owner, caption, hint);
919+
lbl.AnchorSideBottom.Control := Result;
920+
lbl.AnchorSideBottom.Side := ELazAnchorSideReference.Top;
921+
lbl.AnchorSideLeft.Control := Result;
922+
lbl.AnchorSideLeft.Side := ELazAnchorSideReference.Top;
923+
lbl.Anchors := [ELazAnchorKind.Bottom, ELazAnchorKind.Left];
924+
end;
925+
926+
if hint <> '' then
927+
begin
928+
Result.Hint := hint;
929+
Result.ShowHint := True;
930+
end;
931+
end;
932+
933+
837934
function TImageBox.CreateEx(owner: Pointer): TImageBox; static;
838935
begin
839936
Result := TImageBox.Create(TLazControl(owner));

utils/forms/scriptform.simba

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ begin
146146

147147
Self.PageControl := TLazPageControl.CreateEx(Self.Form);
148148
Self.PageControl.Align := ELazAlign.Client;
149-
Self.PageControl.Width := 800;
150-
Self.PageControl.Height := 570;
149+
150+
Self.PageControl.Width := Self.Form.Width;
151+
Self.PageControl.Height := Self.Form.Height - 40;
151152

152153
panel := TLazPanel.CreateEx(Self.Form);
153154
panel.Align := ELazAlign.Bottom;
@@ -156,7 +157,7 @@ begin
156157
ProfileForm.SetupUI(panel);
157158

158159
// Start button
159-
Self.Start := TLazButton.CreateEx(panel, 'Start', '', 0, 0, Floor(80 * FormUtils.Scale));
160+
Self.Start := TLazButton.CreateEx(panel, 'Start', '', 0, 0, 80, 30);
160161
Self.Start.Align := ELazAlign.Right;
161162
Self.Start.OnClick := @Self.OnStart;
162163
Self.Start.BorderSpacing.Top := 3;
@@ -194,16 +195,11 @@ end.
194195
```
195196
*)
196197
function TScriptForm.CreateTab(caption: String): TLazTabSheet;
197-
var
198-
w, h: Integer;
199198
begin
200-
w := Round(Self.PageControl.Width / FormUtils.Scale);
201-
h := Round(Self.PageControl.Height / FormUtils.Scale);
202-
203199
Result := Self.PageControl.AddTab();
204200
Result.Caption := caption;
205-
Result.Width := w;
206-
Result.Height := h;
201+
Result.Width := Self.PageControl.Width;
202+
Result.Height := Self.PageControl.Height;
207203

208204
Self.PageControl.ActiveTabIndex := 0;
209205
end;

0 commit comments

Comments
 (0)