Skip to content

Commit

Permalink
Update ImageToStringForm
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 26, 2023
1 parent a961fc8 commit 2f604e3
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 168 deletions.
4 changes: 2 additions & 2 deletions Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@
<ResourceBaseClass Value="Form"/>
</Unit2>
<Unit3>
<Filename Value="forms/simba.bitmaptostringform.pas"/>
<Filename Value="forms/simba.imagetostringform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SimbaBitmapConversionForm"/>
<ComponentName Value="SimbaImageToStringForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit3>
Expand Down
4 changes: 2 additions & 2 deletions Source/Simba.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
simba.init,
Classes, SysUtils, Interfaces, Forms, LazLogger,
simba.mufasatypes, simba.main,
simba.aboutform, simba.debugimageform, simba.bitmaptostringform,
simba.aboutform, simba.debugimageform, simba.imagetostringform,
simba.functionlistform, simba.scripttabsform, simba.outputform,
simba.colorpickerhistoryform, simba.filebrowserform, simba.notesform,
simba.settingsform, simba.associate, simba.openexampleform,
Expand Down Expand Up @@ -110,7 +110,7 @@
Application.CreateForm(TSimbaFileBrowserForm, SimbaFileBrowserForm);
Application.CreateForm(TSimbaAboutForm, SimbaAboutForm);
Application.CreateForm(TSimbaSettingsForm, SimbaSettingsForm);
Application.CreateForm(TSimbaBitmapConversionForm, SimbaBitmapConversionForm);
Application.CreateForm(TSimbaImageToStringForm, SimbaImageToStringForm);
Application.CreateForm(TSimbaOpenExampleForm, SimbaOpenExampleForm);
Application.CreateForm(TSimbaColorPickerHistoryForm, SimbaColorPickerHistoryForm);
Application.CreateForm(TSimbaPackageForm, SimbaPackageForm);
Expand Down
132 changes: 0 additions & 132 deletions Source/forms/simba.bitmaptostringform.pas

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
object SimbaBitmapConversionForm: TSimbaBitmapConversionForm
object SimbaImageToStringForm: TSimbaImageToStringForm
Left = 2712
Height = 466
Height = 600
Top = 537
Width = 755
AutoSize = True
Caption = 'Bitmap conversion'
ClientHeight = 466
ClientWidth = 755
Constraints.MinHeight = 360
Constraints.MinWidth = 560
Width = 1000
AllowDropFiles = True
Caption = 'Image To String'
ClientHeight = 600
ClientWidth = 1000
Constraints.MinHeight = 250
Constraints.MinWidth = 350
DesignTimePPI = 120
OnCreate = FormCreate
OnDropFiles = FormDropFiles
Position = poMainFormCenter
LCLVersion = '2.2.2.0'
LCLVersion = '2.2.4.0'
object ToStringButton: TButton
AnchorSideTop.Control = ClipboardButton
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 622
Left = 867
Height = 30
Top = 428
Top = 562
Width = 125
Anchors = [akTop, akRight]
AutoSize = True
Expand All @@ -34,9 +36,9 @@ object SimbaBitmapConversionForm: TSimbaBitmapConversionForm
AnchorSideRight.Control = ToStringButton
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = ToStringButton
Left = 636
Left = 881
Height = 24
Top = 396
Top = 530
Width = 97
Anchors = [akLeft, akBottom]
BorderSpacing.Top = 10
Expand All @@ -55,7 +57,7 @@ object SimbaBitmapConversionForm: TSimbaBitmapConversionForm
AnchorSideBottom.Control = ClipboardButton
Left = 8
Height = 30
Top = 393
Top = 527
Width = 213
Anchors = [akLeft, akRight, akBottom]
AutoSize = True
Expand All @@ -68,24 +70,24 @@ object SimbaBitmapConversionForm: TSimbaBitmapConversionForm
object GroupBox: TGroupBox
AnchorSideBottom.Control = OpenButton
Left = 8
Height = 377
Height = 511
Top = 8
Width = 739
Width = 984
Align = alTop
Anchors = [akBottom]
AutoSize = True
BorderSpacing.Left = 8
BorderSpacing.Top = 8
BorderSpacing.Right = 8
Caption = 'Image'
ClientHeight = 352
ClientWidth = 735
ClientHeight = 486
ClientWidth = 980
TabOrder = 3
object ImagePreview: TImage
Left = 0
Height = 352
Height = 486
Top = 0
Width = 735
Width = 980
Align = alClient
Center = True
Proportional = True
Expand All @@ -100,7 +102,7 @@ object SimbaBitmapConversionForm: TSimbaBitmapConversionForm
AnchorSideBottom.Side = asrBottom
Left = 8
Height = 30
Top = 428
Top = 562
Width = 213
Anchors = [akLeft, akBottom]
AutoSize = True
Expand Down
129 changes: 129 additions & 0 deletions Source/forms/simba.imagetostringform.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.imagetostringform;

{$i simba.inc}

interface

uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtDlgs, ExtCtrls, ClipBrd;

type
TSimbaImageToStringForm = class(TForm)
ClipboardButton: TButton;
GroupBox: TGroupBox;
ToStringButton: TButton;
OpenButton: TButton;
PadOutput: TCheckBox;
ImagePreview: TImage;
OpenPictureDialog: TOpenPictureDialog;
procedure ClipboardButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
procedure OpenButtonClick(Sender: TObject);
procedure ToStringButtonClick(Sender: TObject);
end;

var
SimbaImageToStringForm: TSimbaImageToStringForm;

implementation

{$R *.lfm}

uses
simba.mufasatypes, simba.bitmap, simba.bitmap_utils, simba.stringbuilder;

procedure TSimbaImageToStringForm.OpenButtonClick(Sender: TObject);
begin
if OpenPictureDialog.Execute() then
try
ImagePreview.Picture.LoadFromFile(OpenPictureDialog.FileName);

GroupBox.Caption := Format('(%d,%d)', [ImagePreview.Picture.Width, ImagePreview.Picture.Height]);
except
ImagePreview.Picture.Clear();
end;
end;

procedure TSimbaImageToStringForm.ClipboardButtonClick(Sender: TObject);
begin
if (Clipboard.HasPictureFormat()) then
try
ImagePreview.Picture.Bitmap.LoadFromClipboardFormat(CF_Bitmap);

GroupBox.Caption := Format('(%d,%d)', [ImagePreview.Picture.Width, ImagePreview.Picture.Height]);
except
ImagePreview.Picture.Clear();
end;
end;

procedure TSimbaImageToStringForm.FormCreate(Sender: TObject);
begin
Width := Scale96ToScreen(500);
Height := Scale96ToScreen(300);
end;

procedure TSimbaImageToStringForm.FormDropFiles(Sender: TObject; const FileNames: array of string);
begin
if (Length(FileNames) > 0) then
try
ImagePreview.Picture.LoadFromFile(FileNames[0]);

GroupBox.Caption := Format('(%d,%d)', [ImagePreview.Picture.Width, ImagePreview.Picture.Height]);
except
ImagePreview.Picture.Clear();
end;
end;

procedure TSimbaImageToStringForm.ToStringButtonClick(Sender: TObject);
const
PAD_WIDTH = 65;
var
ImageString: String;
Builder: TSimbaStringBuilder;
begin
if Assigned(ImagePreview.Picture.Bitmap) and (ImagePreview.Picture.Bitmap.Width > 0) and (ImagePreview.Picture.Bitmap.Height > 0) then
begin
with ImagePreview.Picture.Bitmap.ToMufasaBitmap() do
try
ImageString := SaveToString();
finally
Free();
end;

if PadOutput.Checked then
begin
Builder.Append('Image := TSimbaImage.CreateFromString(');
Builder.Append(IntToStr(ImagePreview.Picture.Bitmap.Width));
Builder.Append(', ');
Builder.Append(IntToStr(ImagePreview.Picture.Bitmap.Height));
Builder.Append(', ');
Builder.AppendLine();

while (ImageString <> '') do
begin
Builder.AppendLine(' ' + #39 + Copy(ImageString, 1, PAD_WIDTH) + #39 + ' +');

Delete(ImageString, 1, PAD_WIDTH);
end;

ImageString := Copy(Builder.Str, 1, Builder.Count - Length(LineEnding) - 2) + ');';
end else
ImageString := 'Image := TSimbaImage.CreateFromString(' + IntToStr(ImagePreview.Picture.Bitmap.Width) + ',' + IntToStr(ImagePreview.Picture.Bitmap.Height) + ', ' + #39 + ImageString + #39 + ');';

try
Clipboard.AsText := ImageString;
except
end;

SimbaDebugLn([EDebugLn.FOCUS], ImageString);
end;
end;

end.

Loading

0 comments on commit 2f604e3

Please sign in to comment.