Skip to content

Commit 084dc47

Browse files
committedFeb 19, 2025·
Tweaks
1 parent bdf1933 commit 084dc47

6 files changed

+35
-72
lines changed
 

‎Examples/form_imagebox.simba

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ begin
3030
ImgBox := TImageBox.Create(Form);
3131
ImgBox.Parent := Form;
3232
ImgBox.Align := ELazAlign.Client;
33-
ImgBox.SetBackgroundFromTarget(Target);
33+
ImgBox.SetImage(TImage.CreateFromTarget());
3434
ImgBox.OnImgPaint := @ImgBoxPaint;
3535
ImgBox.OnImgMouseMove := @ImgBoxMouseMove;
3636

‎Source/script/imports/lcl/simba.import_lcl_misc.pas

+3-9
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,9 @@ procedure _LapeMenu_Parent_Write(const Params: PParamArray); LAPE_WRAPPER_CALLIN
401401
PMenu(Params^[0])^.Parent := PComponent(Params^[1])^;
402402
end;
403403

404-
procedure _LapeMenu_Count(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
404+
procedure _LapeMenu_Items_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
405405
begin
406-
PInteger(Result)^ := PMenu(Params^[0])^.Items.Count;
407-
end;
408-
409-
procedure _LapeMenu_Item_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
410-
begin
411-
PMenuItem(Result)^ := PMenu(Params^[0])^.Items[PInteger(Params^[1])^];
406+
PMenuItem(Result)^ := PMenu(Params^[0])^.Items;
412407
end;
413408

414409
procedure _LapeMenu_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
@@ -669,8 +664,7 @@ procedure ImportLCLMisc(Script: TSimbaScript);
669664
addGlobalFunc('function TLazMenu.DispatchCommand(ACommand: Int16): Boolean;', @_LapeMenu_DispatchCommand);
670665
addGlobalFunc('function TLazMenu.AddMenu(Name: string): TLazMenuItem;', @_LapeMenu_AddMenu);
671666
addProperty('TLazMenu', 'Parent', 'TLazComponent', @_LapeMenu_Parent_Read, @_LapeMenu_Parent_Write);
672-
addProperty('TLazMenu', 'Count', 'Integer', @_LapeMenu_Count);
673-
addPropertyIndexed('TLazMenu', 'Item', 'Index: Integer', 'TLazMenuItem', @_LapeMenu_Item_Read);
667+
addProperty('TLazMenu', 'Items', 'TLazMenuItem', @_LapeMenu_Items_Read);
674668
addClassConstructor('TLazMenu', '(AOwner: TLazComponent)', @_LapeMenu_Create);
675669

676670
addClass('TLazPopupMenu', 'TLazMenu');

‎Source/script/imports/simba.import_imagebox.pas

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ implementation
2323
type
2424
PComponent = ^TComponent;
2525
PBitmap = ^TBitmap;
26+
PSimbaImageBox = ^TSimbaImageBox;
2627

2728
procedure _LapeSimbaImageBox_FindDTM(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
2829
begin

‎Source/script/imports/simba.import_shapebox.pas

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ implementation
2222
PButton = ^TButton;
2323
PNotifyEvent = ^TNotifyEvent;
2424
PListBox = ^TListBox;
25-
PPopupMenu = ^TPopupMenu;
2625

2726
procedure _LapeSimbaShapeBox_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
2827
begin

‎Source/simba.component_imagebox.pas

+13-14
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ interface
1212
uses
1313
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
1414
ATScrollBar, LCLType, LMessages,
15-
simba.base, simba.component_statusbar, simba.image_lazbridge, simba.component_imageboxcanvas,
16-
simba.image, simba.dtm, simba.colormath, simba.target;
15+
simba.base,
16+
simba.component_statusbar,
17+
simba.component_scrollbar,
18+
simba.image_lazbridge,
19+
simba.component_imageboxcanvas,
20+
simba.image,
21+
simba.dtm,
22+
simba.colormath,
23+
simba.target;
1724

1825
const
1926
ZOOM_LEVELS: TIntegerArray = (
@@ -40,8 +47,8 @@ TSimbaImageScrollBox = class(TCustomControl)
4047
FZoomLevel: Integer;
4148
FZoomPixels: Integer;
4249

43-
FVertScroll: TATScrollbar;
44-
FHorzScroll: TATScrollbar;
50+
FVertScroll: TSimbaScrollBar;
51+
FHorzScroll: TSimbaScrollBar;
4552

4653
FDragging: record
4754
X, Y: Integer;
@@ -50,8 +57,6 @@ TSimbaImageScrollBox = class(TCustomControl)
5057

5158
FPaintTime: Double;
5259

53-
procedure MyInvalidate(Data: PtrInt);
54-
5560
procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;
5661

5762
function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
@@ -99,7 +104,6 @@ TSimbaImageScrollBox = class(TCustomControl)
99104
TImageBoxMouseEvent = procedure(Sender: TSimbaImageBox; Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object;
100105
TImageBoxMouseMoveEvent = procedure(Sender: TSimbaImageBox; Shift: TShiftState; X, Y: Integer) of object;
101106

102-
PSimbaImageBox = ^TSimbaImageBox;
103107
TSimbaImageBox = class(TCustomControl)
104108
protected
105109
FImageScrollBox: TSimbaImageScrollBox;
@@ -317,11 +321,6 @@ function TSimbaImageScrollBox.VisibleTopY: Integer;
317321
Result := Max(0, FVertScroll.Position + ((FZoomPixels - FVertScroll.Position) mod FZoomPixels));
318322
end;
319323

320-
procedure TSimbaImageScrollBox.MyInvalidate(Data: PtrInt);
321-
begin
322-
Invalidate;
323-
end;
324-
325324
procedure TSimbaImageScrollBox.WMEraseBkgnd(var Message: TLMEraseBkgnd);
326325
begin
327326
Message.Result := 1;
@@ -734,13 +733,13 @@ constructor TSimbaImageScrollBox.Create(AOwner: TComponent);
734733
FZoomLevel := 100;
735734
FZoomPixels := 1;
736735

737-
FVertScroll := TATScrollbar.Create(Self);
736+
FVertScroll := TSimbaScrollBar.Create(Self);
738737
FVertScroll.Parent := Self;
739738
FVertScroll.Kind := sbVertical;
740739
FVertScroll.Align := alRight;
741740
FVertScroll.OnChange := @DoScrollChange;
742741

743-
FHorzScroll := TATScrollbar.Create(Self);
742+
FHorzScroll := TSimbaScrollBar.Create(Self);
744743
FHorzScroll.Parent := Self;
745744
FHorzScroll.Kind := sbHorizontal;
746745
FHorzScroll.Align := alBottom;

‎Source/simba.settings.pas

+17-47
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
interface
1212

1313
uses
14-
classes, sysutils, inifiles, lazmethodlist, variants, fgl, controls, graphics;
15-
16-
const
17-
SETTINGS_VERSION = 2; // Increase if settings become incompatible
14+
Classes, SysUtils, IniFiles, LazMethodList, Variants, Controls,
15+
simba.containers;
1816

1917
type
2018
TSimbaSettings = class;
@@ -79,11 +77,10 @@ TSimbaSetting_Integer = class(TSimbaSetting)
7977
TSimbaSettings = class
8078
protected
8179
type
82-
TSettingList = specialize TFPGObjectList<TSimbaSetting>;
80+
TSettingList = specialize TSimbaObjectList<TSimbaSetting>;
8381
protected
8482
FList: TSettingList;
8583
FFirstLaunch: Boolean;
86-
FIsLoading: Boolean;
8784
public
8885
General: record
8986
TrayIconVisible: TSimbaSetting;
@@ -173,7 +170,6 @@ TSimbaSettings = class
173170
end;
174171

175172
property FirstLaunch: Boolean read FFirstLaunch;
176-
property IsLoading: Boolean read FIsLoading;
177173

178174
class function GetINIFile: TINIFile;
179175
class procedure SetSimpleSetting(AName, Value: String);
@@ -226,7 +222,7 @@ procedure TSimbaSetting_Integer.CheckValue(AValue: Variant);
226222

227223
procedure TSimbaSetting_Integer.ReadValue(INI: TINIFile);
228224
begin
229-
Value := INI.ReadInt64(FSection, FName, Value);
225+
FValue := INI.ReadInt64(FSection, FName, Value);
230226
end;
231227

232228
procedure TSimbaSetting_Integer.WriteValue(INI: TINIFile);
@@ -242,7 +238,7 @@ procedure TSimbaSetting_BinaryString.CheckValue(AValue: Variant);
242238

243239
procedure TSimbaSetting_BinaryString.ReadValue(INI: TINIFile);
244240
begin
245-
Value := BaseDecode(EBaseEncoding.b64, INI.ReadString(FSection, FName, Value));
241+
FValue := BaseDecode(EBaseEncoding.b64, INI.ReadString(FSection, FName, Value));
246242
end;
247243

248244
procedure TSimbaSetting_BinaryString.WriteValue(INI: TINIFile);
@@ -258,7 +254,7 @@ procedure TSimbaSetting_String.CheckValue(AValue: Variant);
258254

259255
procedure TSimbaSetting_String.ReadValue(INI: TINIFile);
260256
begin
261-
Value := INI.ReadString(FSection, FName, Value);
257+
FValue := INI.ReadString(FSection, FName, Value);
262258
end;
263259

264260
procedure TSimbaSetting_String.WriteValue(INI: TINIFile);
@@ -274,7 +270,7 @@ procedure TSimbaSetting_Boolean.CheckValue(AValue: Variant);
274270

275271
procedure TSimbaSetting_Boolean.ReadValue(INI: TINIFile);
276272
begin
277-
Value := INI.ReadBool(FSection, FName, Value);
273+
FValue := INI.ReadBool(FSection, FName, Value);
278274
end;
279275

280276
procedure TSimbaSetting_Boolean.WriteValue(INI: TINIFile);
@@ -325,11 +321,6 @@ procedure TSimbaSetting.Changed;
325321
var
326322
I: Integer;
327323
begin
328-
if FSettings.IsLoading then
329-
Exit;
330-
331-
// DebugLn('[TSimbaSettings] Setting changed: ' + FName);
332-
333324
I := FChangeEventList.Count;
334325
while FChangeEventList.NextDownIndex(I) do
335326
TSimbaSettingChangedEvent(FChangeEventList.Items[I])(Self);
@@ -390,34 +381,21 @@ procedure TSimbaSettings.Load;
390381
INI: TIniFile;
391382
Setting: TSimbaSetting;
392383
begin
393-
FIsLoading := True;
394-
395384
INI := GetINIFile();
396385
try
397-
if (INI.ReadInteger('Settings', 'Version', 0) <> SETTINGS_VERSION) then
398-
begin
399-
DeleteFile(INI.FileName + '.old');
400-
RenameFile(INI.FileName, INI.FileName + '.old');
401-
402-
Exit;
403-
end;
404-
405386
if FileExists(SimbaSettingFileName) then
406387
begin
407388
FFirstLaunch := False;
408389

409-
for Setting in FList do
410-
begin
411-
if not INI.ValueExists(Setting.FSection, Setting.FName) then
412-
Continue;
413-
414-
Setting.ReadValue(INI);
415-
end;
390+
for Setting in FList.ToArray() do
391+
if INI.ValueExists(Setting.FSection, Setting.FName) then
392+
Setting.ReadValue(INI);
416393
end;
417-
finally
418-
INI.Free();
419-
FIsLoading := False;
394+
except
395+
on E: Exception do
396+
DebugLn('TSimbaSettings.Load: %s', [E.Message]);
420397
end;
398+
INI.Free();
421399
end;
422400

423401
procedure TSimbaSettings.Save;
@@ -426,16 +404,13 @@ procedure TSimbaSettings.Save;
426404
Setting: TSimbaSetting;
427405
begin
428406
INI := GetINIFile();
429-
INI.WriteInteger('Settings', 'Version', SETTINGS_VERSION);
430-
431-
for Setting in FList do
407+
for Setting in FList.ToArray() do
432408
Setting.WriteValue(INI);
433409

434410
try
435411
INI.UpdateFile();
436412
except
437413
end;
438-
439414
INI.Free();
440415
end;
441416

@@ -484,7 +459,7 @@ constructor TSimbaSettings.Create;
484459
SynDefaultFontSize := SynDefaultFontSize + 1;
485460

486461
FFirstLaunch := True;
487-
FList := TSettingList.Create();
462+
FList := TSettingList.Create(True);
488463

489464
// General
490465
General.TrayIconVisible := TSimbaSetting_Boolean.Create(Self, 'General', 'TrayIconVisible', True);
@@ -573,14 +548,9 @@ destructor TSimbaSettings.Destroy;
573548
inherited Destroy();
574549
end;
575550

576-
procedure CreateSimbaSettings;
577-
begin
551+
initialization
578552
SimbaSettingsInstance := TSimbaSettings.Create();
579553
SimbaSettingsInstance.Load();
580-
end;
581-
582-
initialization
583-
SimbaIDEInitialization_AddBeforeCreate(@CreateSimbaSettings, 'Create SimbaSettings');
584554

585555
finalization
586556
if (SimbaSettingsInstance <> nil) then

0 commit comments

Comments
 (0)
Please sign in to comment.