Skip to content

Commit

Permalink
TSimbaImageBox > TImageBox
Browse files Browse the repository at this point in the history
TSimbaShapeBox > TShapeBox
  • Loading branch information
ollydev committed Nov 28, 2023
1 parent dd619e3 commit f2ec31e
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 152 deletions.
6 changes: 3 additions & 3 deletions Source/forms/simba.aca.pas
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ procedure TSimbaACAForm.ButtonUpdateImageClick(Sender: TObject);
begin
if (not FWindow.IsValid()) then
FWindow := GetDesktopWindow();
FImageBox.SetBackground(FWindow);
FImageBox.SetBackgroundFromWindow(FWindow);
end;

procedure TSimbaACAForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
Expand Down Expand Up @@ -406,7 +406,7 @@ procedure TSimbaACAForm.ButtonLoadImageClick(Sender: TObject);
try
InitialDir := Application.Location;
if Execute() then
FImageBox.SetBackground(FileName);
FImageBox.SetBackgroundFromFile(FileName);
finally
Free();
end;
Expand Down Expand Up @@ -455,7 +455,7 @@ constructor TSimbaACAForm.Create(Window: TWindowHandle);
FImageBox.OnMouseDown := @ClientImageMouseDown;
FImageBox.OnMouseMove := @ClientImageMouseMove;
FImageBox.OnPaintArea := @DoPaintArea;
FImageBox.SetBackground(FWindow);
FImageBox.SetBackgroundFromWindow(FWindow);

FImageZoom := TSimbaImageBoxZoom.Create(Self);
FImageZoom.Parent := PanelTop;
Expand Down
6 changes: 3 additions & 3 deletions Source/forms/simba.dtmeditor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ procedure TSimbaDTMEditorForm.ButtonUpdateImageClick(Sender: TObject);
begin
if (not FWindow.IsValid()) then
FWindow := GetDesktopWindow();
FImageBox.SetBackground(FWindow);
FImageBox.SetBackgroundFromWindow(FWindow);

DrawDTM();
end;
Expand Down Expand Up @@ -502,7 +502,7 @@ procedure TSimbaDTMEditorForm.MenuItemLoadImageClick(Sender: TObject);

if Execute() then
try
FImageBox.SetBackground(FileName);
FImageBox.SetBackgroundFromFile(FileName);
except
end;
finally
Expand Down Expand Up @@ -569,7 +569,7 @@ constructor TSimbaDTMEditorForm.Create(Window: TWindowHandle);
FImageBox.OnMouseDown := @ClientImageMouseDown;
FImageBox.OnMouseMove := @ClientImageMouseMove;
FImageBox.OnMouseUp := @ClientImageMouseUp;
FImageBox.SetBackground(FWindow);
FImageBox.SetBackgroundFromWindow(FWindow);

FImageZoom := TSimbaImageBoxZoom.Create(Self);
FImageZoom.Parent := PanelTop;
Expand Down
84 changes: 42 additions & 42 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ object SimbaForm: TSimbaForm
Top = 623
Width = 798
Caption = 'Simba'
ClientHeight = 539
ClientWidth = 798
ClientHeight = 0
ClientWidth = 0
DesignTimePPI = 120
KeyPreview = True
OnClose = FormClose
Expand All @@ -16,19 +16,19 @@ object SimbaForm: TSimbaForm
LCLVersion = '3.0.0.2'
object DockPanel: TAnchorDockPanel
Left = 0
Height = 511
Top = 28
Width = 798
Height = 0
Top = 0
Width = 0
Align = alClient
BevelOuter = bvNone
ParentFont = False
TabOrder = 0
end
object ToolBar: TToolBar
Left = 0
Height = 28
Height = 504
Top = 0
Width = 798
Width = 0
AutoSize = True
ButtonHeight = 28
ButtonWidth = 0
Expand All @@ -42,59 +42,59 @@ object SimbaForm: TSimbaForm
TabOrder = 1
OnPaintButton = ToolBarPaintButton
object ToolbarButtonRun: TToolButton
Left = 123
Left = 0
Hint = 'Run Script (Alt + R)'
Top = 0
Top = 196
Caption = '&Run'
ImageIndex = 1
OnClick = MenuItemScriptStateClick
end
object ToolbarButtonPause: TToolButton
Left = 143
Left = 0
Hint = 'Pause Script'
Top = 0
Top = 224
Caption = '&Pause'
Enabled = False
ImageIndex = 2
OnClick = MenuItemScriptStateClick
end
object ToolbarButtonStop: TToolButton
Left = 163
Left = 0
Hint = 'Stop Script (Alt + S)'
Top = 0
Top = 252
Caption = '&Stop'
Enabled = False
ImageIndex = 3
OnClick = MenuItemScriptStateClick
end
object ToolbarButtonClearOutput: TToolButton
Left = 253
Left = 0
Hint = 'Clear Output Box'
Top = 0
Top = 420
Caption = 'Clear'
ImageIndex = 13
OnClick = MenuClearOutputClick
end
object ToolbarButtonColorPicker: TToolButton
Left = 188
Left = 0
Hint = 'Color Picker'
Top = 0
Top = 308
Caption = 'ToolbarButtonColorPicker'
ImageIndex = 11
OnClick = ToolbarButtonColorPickerClick
end
object ToolbarButtonTargetSelector: TToolButton
Left = 208
Left = 0
Hint = 'Target Selector'
Top = 0
Top = 336
Caption = 'ToolbarButtonTargetSelector'
ImageIndex = 10
OnMouseDown = ToolbarButtonSelectTargetClick
end
object ToolbarButtonOpen: TToolButton
Left = 20
Left = 0
Hint = 'Open Script (Ctrl + O)'
Top = 0
Top = 28
Caption = '&Open'
DropdownMenu = RecentFilesPopup
ImageIndex = 6
Expand All @@ -104,40 +104,40 @@ object SimbaForm: TSimbaForm
Style = tbsButtonDrop
end
object ToolbarButtonSave: TToolButton
Left = 53
Left = 0
Hint = 'Save Script (Ctrl + S)'
Top = 0
Top = 56
Caption = '&Save'
ImageIndex = 8
OnClick = MenuSaveClick
end
object ToolbarButtonSaveAll: TToolButton
Left = 73
Left = 0
Hint = 'Save All'
Top = 0
Top = 84
Caption = 'Save All'
ImageIndex = 9
OnClick = ToolbarButtonSaveAllClick
end
object ToolbarButtonCompile: TToolButton
Left = 98
Left = 0
Hint = 'Compile Script (Alt + C)'
Top = 0
Top = 140
ImageIndex = 0
OnClick = MenuItemScriptStateClick
end
object ToolbarButtonPackages: TToolButton
Left = 278
Left = 0
Hint = 'Open Packages'
Top = 0
Top = 476
Caption = 'ToolbarButtonPackages'
ImageIndex = 14
OnClick = ToolbarButtonPackagesClick
end
object ToolButtonAreaSelector: TToolButton
Left = 228
Left = 0
Hint = 'Area Selector'
Top = 0
Top = 364
ImageIndex = 12
OnClick = ToolButtonAreaSelectorClick
ShowCaption = False
Expand All @@ -150,37 +150,37 @@ object SimbaForm: TSimbaForm
OnClick = MenuNewClick
end
object ToolButton1: TToolButton
Left = 93
Left = 0
Height = 28
Top = 0
Top = 112
Caption = 'ToolButton1'
Style = tbsDivider
end
object ToolButton2: TToolButton
Left = 118
Left = 0
Height = 28
Top = 0
Top = 168
Caption = 'ToolButton2'
Style = tbsDivider
end
object ToolButton3: TToolButton
Left = 183
Left = 0
Height = 28
Top = 0
Top = 280
Caption = 'ToolButton3'
Style = tbsDivider
end
object ToolButton4: TToolButton
Left = 248
Left = 0
Height = 28
Top = 0
Top = 392
Caption = 'ToolButton4'
Style = tbsDivider
end
object ToolButton5: TToolButton
Left = 273
Left = 0
Height = 28
Top = 0
Top = 448
Caption = 'ToolButton5'
Style = tbsDivider
end
Expand All @@ -189,7 +189,7 @@ object SimbaForm: TSimbaForm
Left = 0
Height = 0
Top = 0
Width = 798
Width = 0
Align = alTop
AutoSize = True
BevelOuter = bvNone
Expand Down
2 changes: 1 addition & 1 deletion Source/forms/simba.shapeboxform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ procedure TSimbaShapeBoxForm.MenuItemLoadImageClick(Sender: TObject);
begin
if OpenDialog.Execute() then
begin
ShapeBox.SetBackground(OpenDialog.FileName);
ShapeBox.SetBackgroundFromFile(OpenDialog.FileName);

HasBackground := True;
end;
Expand Down
45 changes: 29 additions & 16 deletions Source/imagebox/simba.imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Graphics, GraphType, ComCtrls, LCLType,
simba.mufasatypes, simba.image, simba.dtm, simba.imagebox_image,
simba.colormath;
simba.colormath, simba.target;

type
TSimbaImageBox_ScrollBox = class(TScrollBox)
Expand Down Expand Up @@ -98,10 +98,11 @@ TSimbaImageBox = class(TWinControl)
function FindColor(AColor: TColor; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers): TPointArray;
function MatchColor(AColor: TColor; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers): TSingleMatrix;

procedure SetBackground(Data: PColorBGRA; AWidth, AHeight: Integer); overload;
procedure SetBackground(FileName: String); overload;
procedure SetBackground(Bitmap: TSimbaImage); overload;
procedure SetBackground(Window: TWindowHandle); overload;
procedure SetBackground(Image: TSimbaImage);
procedure SetBackgroundFromFile(FileName: String);
procedure SetBackgroundFromWindow(Window: TWindowHandle);
procedure SetBackgroundFromTarget(Target: TSimbaTarget; Bounds: TBox); overload;
procedure SetBackgroundFromTarget(Target: TSimbaTarget); overload;

procedure Paint;

Expand Down Expand Up @@ -427,8 +428,8 @@ procedure TSimbaImageBox.FontChanged(Sender: TObject);
Canvas.Font.Size := Round(-GetFontData(Canvas.Font.Reference.Handle).Height * 72 / Canvas.Font.PixelsPerInch) + 6;

FMousePanel.Width := Canvas.TextWidth('(1000, 1000)');
FDimensionsPanel.Width := Canvas.TextWidth('1000x1000');
FZoomPanel.Width := Canvas.TextWidth('100%');
FDimensionsPanel.Width := Canvas.TextWidth('1000x1000');
FZoomPanel.Width := Canvas.TextWidth('100%');

FStatusBar.Height := Round(Canvas.TextHeight('Taylor Swift') * 0.8);
FStatusBar.Font := Self.Font;
Expand Down Expand Up @@ -660,22 +661,17 @@ function TSimbaImageBox.MatchColor(AColor: TColor; ColorSpace: EColorSpace; Mult
end;
end;

procedure TSimbaImageBox.SetBackground(Data: PColorBGRA; AWidth, AHeight: Integer);
begin
LazImage_FromData(FBackground, Data, AWidth, AHeight);
end;

procedure TSimbaImageBox.SetBackground(FileName: String);
procedure TSimbaImageBox.SetBackgroundFromFile(FileName: String);
begin
FBackground.LoadFromFile(FileName);
end;

procedure TSimbaImageBox.SetBackground(Bitmap: TSimbaImage);
procedure TSimbaImageBox.SetBackground(Image: TSimbaImage);
begin
SetBackground(Bitmap.Data, Bitmap.Width, Bitmap.Height);
LazImage_FromData(FBackground, Image.Data, Image.Width, Image.Height);
end;

procedure TSimbaImageBox.SetBackground(Window: TWindowHandle);
procedure TSimbaImageBox.SetBackgroundFromWindow(Window: TWindowHandle);
var
Image: TSimbaImage;
begin
Expand All @@ -690,6 +686,23 @@ procedure TSimbaImageBox.SetBackground(Window: TWindowHandle);
end;
end;

procedure TSimbaImageBox.SetBackgroundFromTarget(Target: TSimbaTarget; Bounds: TBox);
var
Image: TSimbaImage;
begin
Image := Target.GetImage(Bounds);
try
SetBackground(Image);
finally
Image.Free();
end;
end;

procedure TSimbaImageBox.SetBackgroundFromTarget(Target: TSimbaTarget);
begin
SetBackgroundFromTarget(Target, TBox.Create(-1,-1,-1,-1));
end;

constructor TSimbaImageBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Expand Down
Loading

0 comments on commit f2ec31e

Please sign in to comment.