Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Feb 26, 2024
1 parent 470a655 commit 7406c4b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@
<ResourceBaseClass Value="Frame"/>
</Unit49>
<Unit50>
<Filename Value="simba.scriptbackup.pas"/>
<Filename Value="simba.ide_scriptbackup.pas"/>
<IsPartOfProject Value="True"/>
</Unit50>
<Unit51>
Expand Down
32 changes: 16 additions & 16 deletions Source/forms/simba.aca.lfm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
object SimbaACAForm: TSimbaACAForm
Left = 3110
Height = 886
Top = 360
Left = 500
Height = 888
Top = 314
Width = 1076
Caption = 'Auto Color Aid'
ClientHeight = 0
ClientWidth = 0
ClientHeight = 888
ClientWidth = 1076
Constraints.MinHeight = 400
Constraints.MinWidth = 500
DesignTimePPI = 120
Expand All @@ -19,7 +19,7 @@ object SimbaACAForm: TSimbaACAForm
LCLVersion = '3.0.0.3'
object PanelMain: TPanel
Left = 0
Height = 886
Height = 888
Top = 0
Width = 713
Align = alClient
Expand All @@ -30,13 +30,13 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideLeft.Control = LabelMulti1
AnchorSideLeft.Side = asrBottom
Left = 713
Height = 886
Height = 888
Top = 0
Width = 363
Align = alRight
Anchors = [akTop, akRight]
AutoSize = True
ClientHeight = 886
ClientHeight = 888
ClientWidth = 363
TabOrder = 1
object ColorListBox: TColorListBox
Expand All @@ -47,7 +47,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ButtonRemoveColor
Left = 7
Height = 451
Height = 453
Top = 7
Width = 349
Style = []
Expand All @@ -70,7 +70,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideBottom.Control = Panel2
Left = 1
Height = 25
Top = 818
Top = 820
Width = 361
Anchors = [akLeft, akRight, akBottom]
BevelStyle = bsRaised
Expand Down Expand Up @@ -108,7 +108,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideBottom.Control = Divider2
Left = 7
Height = 292
Top = 526
Top = 528
Width = 349
Anchors = [akLeft, akRight, akBottom]
AutoSize = True
Expand Down Expand Up @@ -400,7 +400,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideBottom.Control = Divider1
Left = 7
Height = 35
Top = 464
Top = 466
Width = 172
Anchors = [akLeft, akRight, akBottom]
AutoSize = True
Expand All @@ -419,7 +419,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideBottom.Control = Divider1
Left = 185
Height = 35
Top = 464
Top = 466
Width = 171
Anchors = [akLeft, akRight, akBottom]
AutoSize = True
Expand All @@ -435,7 +435,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideTop.Side = asrBottom
Left = 181
Height = 1
Top = 464
Top = 466
Width = 1
BevelOuter = bvNone
TabOrder = 6
Expand All @@ -448,7 +448,7 @@ object SimbaACAForm: TSimbaACAForm
AnchorSideBottom.Control = Panel1
Left = 1
Height = 25
Top = 501
Top = 503
Width = 361
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Top = 2
Expand All @@ -459,7 +459,7 @@ object SimbaACAForm: TSimbaACAForm
object Panel2: TPanel
Left = 1
Height = 42
Top = 843
Top = 845
Width = 361
Align = alBottom
AutoSize = True
Expand Down
26 changes: 18 additions & 8 deletions Source/forms/simba.aca.pas
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,29 @@ TSimbaACAForm = class(TForm)

implementation

{$R *.lfm}

uses
Clipbrd, TypInfo, LCLType,
simba.windowhandle, simba.image, simba.colormath_aca, simba.matrix_float, simba.dialog;

function FormatColor(Color: TColor): String; overload;
begin
Result := '$' + IntToHex(Color, 6);
end;

function FormatColor(Color: String): String; overload;
begin
Result := FormatColor(StrToIntDef(Color, 0));
end;

procedure TSimbaACAForm.ClientImageMouseMove(Sender: TSimbaImageBox; Shift: TShiftState; X, Y: Integer);
begin
FImageZoom.SetTempColor(-1);
FImageZoom.Move(FImageBox.Background.Canvas, X, Y);

with FImageBox.Background.Canvas.Pixels[X, Y].ToRGB(), FImageBox.Background.Canvas.Pixels[X, Y].ToHSL() do
FZoomInfo.Caption := Format('Color: %d', [FImageBox.Background.Canvas.Pixels[X, Y]]) + LineEnding +
Format('RGB: %d, %d, %d', [R, G, B]) + LineEnding +
Format('HSL: %.2f, %.2f, %.2f', [H, S, L]) + LineEnding;
FZoomInfo.Caption := Format('Color: %s', [FormatColor(FImageBox.Background.Canvas.Pixels[X, Y])]) + LineEnding +
Format('RGB: %d, %d, %d', [R, G, B]) + LineEnding +
Format('HSL: %.2f, %.2f, %.2f', [H, S, L]) + LineEnding;
end;

procedure TSimbaACAForm.ClientImageMouseDown(Sender: TSimbaImageBox; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Expand All @@ -144,13 +152,13 @@ procedure TSimbaACAForm.ClientImageMouseDown(Sender: TSimbaImageBox; Button: TMo
Pixel := FImageBox.Background.Canvas.Pixels[X, Y];

if ColorListBox.Items.IndexOf(Pixel.ToString()) = -1 then
ColorListBox.ItemIndex := ColorListBox.Items.AddObject(Pixel.ToString(), TObject(PtrUInt(Pixel)));
ColorListBox.ItemIndex := ColorListBox.Items.AddObject(FormatColor(Pixel), TObject(PtrUInt(Pixel)));
end;
end;

procedure TSimbaACAForm.MenuItemCopyBestColorClick(Sender: TObject);
begin
Clipboard.AsText := Format('ColorTolerance($%s, %s, %s, [%s, %s, %s])', [IntToHex(StrToIntDef(BestColorEdit.Text, 0), 6), BestToleranceEdit.Text, GetColorSpaceStr(), BestMulti1Edit.Text, BestMulti2Edit.Text, BestMulti3Edit.Text]);
Clipboard.AsText := Format('ColorTolerance(%s, %s, %s, [%s, %s, %s])', [FormatColor(StrToIntDef(BestColorEdit.Text, 0)), BestToleranceEdit.Text, GetColorSpaceStr(), BestMulti1Edit.Text, BestMulti2Edit.Text, BestMulti3Edit.Text]);
end;

procedure TSimbaACAForm.MenuItemLoadHSLCircleClick(Sender: TObject);
Expand Down Expand Up @@ -332,7 +340,7 @@ procedure TSimbaACAForm.CalculateBestColor;
begin
Best := GetBestColor(GetColorSpace(), Colors);

BestColorEdit.Text := '$' + IntToHex(Best.Color, 6);
BestColorEdit.Text := FormatColor(Best.Color);
BestToleranceEdit.Text := Format('%.3f', [Best.Tolerance]);
BestMulti1Edit.Text := Format('%.3f', [Best.Mods[0]]);
BestMulti2Edit.Text := Format('%.3f', [Best.Mods[1]]);
Expand Down Expand Up @@ -491,4 +499,6 @@ constructor TSimbaACAForm.Create(Window: TWindowHandle);
end;
end;

{$R *.lfm}

end.
3 changes: 2 additions & 1 deletion Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ implementation

simba.ide_initialization, simba.ide_events, simba.ide_utils,
simba.ide_mainstatusbar, simba.ide_mainmenubar, simba.ide_maintoolbar,
simba.ide_scriptbackup,

simba.shapeboxform, simba.openexampleform, simba.colorpickerhistoryform,
simba.debugimageform, simba.imagetostringform, simba.aboutform,
Expand All @@ -271,7 +272,7 @@ implementation

simba.scripttab, simba.associate,
simba.aca, simba.dtmeditor, simba.env, simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.theme, simba.scriptbackup,
simba.scriptformatter, simba.theme,
simba.threading, simba.editor;

procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);
Expand Down
13 changes: 9 additions & 4 deletions Source/script/simba.script_compiler_imagefromstring.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,15 @@ function TLapeTree_InternalMethod_ImageFromString.Evaluate: TLapeGlobalVar;
if (Param.BaseType <> ltAnsiString) then
LapeExceptionFmt(lpeExpected, ['String parameter'], DocPos);

Result := resType().NewGlobalVarP();

PSimbaImage(Result.Ptr)^ := TSimbaImage.CreateFromString(PAnsiString(Param.Ptr)^);
PSimbaImage(Result.Ptr)^.FreeOnTerminate := True;
try
Result := resType().NewGlobalVarP();

PSimbaImage(Result.Ptr)^ := TSimbaImage.CreateFromString(PAnsiString(Param.Ptr)^);
PSimbaImage(Result.Ptr)^.FreeOnTerminate := True;
except
on E: Exception do
LapeException(E.Message, DocPos);
end;
end;

constructor TLapeTree_InternalMethod_ImageFromString.Create(ACompiler: TLapeCompilerBase; ADocPos: PDocPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Automatically save copies of editor contents to a zipped file.
}
unit simba.scriptbackup;
unit simba.ide_scriptbackup;

{$i simba.inc}

Expand Down Expand Up @@ -66,18 +66,28 @@ procedure TSimbaScriptBackup.DoFileCollecting(Sender: TObject);
procedure TSimbaScriptBackup.DoFileBackuping;
var
I: Integer;
ZipPath: String;
ZipPath, ScriptTitle: String;
begin
for I := 0 to High(FFiles) do
begin
ZipPath := TSimbaPath.PathJoin([SimbaEnv.BackupsPath, TSimbaPath.PathExtractNameWithoutExt(FFiles[I].FileName) + '.zip']);
try
if (FFiles[I].Contents = '') then
Continue;

ScriptTitle := TSimbaPath.PathExtractName(FFiles[I].FileName);
if ScriptTitle.EndsWith('.simba') then
ScriptTitle := ScriptTitle.Before('.simba');

ZipPath := TSimbaPath.PathJoin([SimbaEnv.BackupsPath, ScriptTitle + '.zip']);
if ZipHasEntryCrc(ZipPath, Crc32String(FFiles[I].Contents)) then
Continue;

if ZipAppend(ZipPath, '', FFiles[I].Contents) then
DebugLn('[SimbaScriptBackup]: Backed up %s', [FFiles[I].FileName])
else
DebugLn('[SimbaScriptBackup]: Failed to backup %s', [FFiles[I].FileName]);
except
on E: Exception do
DebugLn('[SimbaScriptBackup]: Exception "%s"', [E.Message]);
end;
end;

Expand Down

0 comments on commit 7406c4b

Please sign in to comment.