Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Feb 14, 2024
1 parent c694d12 commit 0022a5c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Examples/form_imagebox.simba
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

procedure ImgBoxPaint(Sender: TImageBox; Canvas: TImageBoxCanvas; R: TLazRect);
begin
Canvas.DrawCircle(Sender.MousePoint, 5, Colors.YELLOW);
Canvas.DrawCircleFilled(Sender.MousePoint, 5, Colors.YELLOW);

// if 300,300 is visible in the paint rect
if (300 >= R.Left) and (300 >= R.Top) and (300 <= R.Right) and (300 <= R.Bottom) then
Expand Down
Binary file modified Source/Simba.res
Binary file not shown.
6 changes: 3 additions & 3 deletions Source/forms/simba.aca.pas
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ procedure TSimbaACAForm.ButtonMatchColorClick(Sender: TObject);
FDebugTPA := [];
FDebugMat := FImageBox.MatchColor(Color, ColorSpace, Multipliers).NormMinMax(0, 1);

FImageBox.Paint();
FImageBox.Repaint();
end;
end;

Expand All @@ -392,7 +392,7 @@ procedure TSimbaACAForm.ButtonFindColorClick(Sender: TObject);
FDebugTPA := FImageBox.FindColor(Color, Tolerance, ColorSpace, Multipliers);

FImageBox.Status := Format('Found %.0n matches', [Double(Length(FDebugTPA))]);
FImageBox.Paint();
FImageBox.RePaint();
end;
end;

Expand Down Expand Up @@ -446,7 +446,7 @@ procedure TSimbaACAForm.DoButtonClearImageClick(Sender: TObject);
FDebugTPA := [];
FDebugMat := [];

FImageBox.Paint();
FImageBox.RePaint();
end;

constructor TSimbaACAForm.Create(Window: TWindowHandle);
Expand Down
10 changes: 5 additions & 5 deletions Source/forms/simba.dtmeditor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ procedure TSimbaDTMEditorForm.DrawDTM;
FDebugColor := [];
FDebugDTM := [];

FImageBox.Paint();
FImageBox.RePaint();
end;

function TSimbaDTMEditorForm.GetPointAt(X, Y: Integer): Integer;
Expand Down Expand Up @@ -248,14 +248,14 @@ procedure TSimbaDTMEditorForm.DoImgPaint(Sender: TSimbaImageBox; ACanvas: TSimba

with Points[I] do
ACanvas.DrawBoxFilled(
TBox.Create(TPoint.Create(X,Y), AreaSize+1, AreaSize+1), clYellow, 0.75
TBox.Create(TPoint.Create(X,Y), AreaSize+1, AreaSize+1), clYellow, 0.65
);
end;

if Length(Points) > 0 then
with Points[0] do
ACanvas.DrawBoxFilled(
TBox.Create(X - AreaSize, Y - AreaSize, X + AreaSize, Y + AreaSize), clYellow, 0.75
TBox.Create(X - AreaSize, Y - AreaSize, X + AreaSize, Y + AreaSize), clYellow, 0.65
);

if ListBox.ItemIndex > -1 then
Expand Down Expand Up @@ -366,7 +366,7 @@ procedure TSimbaDTMEditorForm.FindDTMClick(Sender: TObject);
FDebugColor := [];
FDebugDTM := FImageBox.FindDTM(GetDTM());

FImageBox.Paint();
FImageBox.RePaint();
end;

procedure TSimbaDTMEditorForm.ButtonPrintDTMClick(Sender: TObject);
Expand Down Expand Up @@ -412,7 +412,7 @@ procedure TSimbaDTMEditorForm.ButtonDebugColorClick(Sender: TObject);
FDebugDTM := [];
FDebugColor := FImageBox.FindColor(Color, Tolerance, EColorSpace.RGB, DefaultMultipliers);

FImageBox.Paint();
FImageBox.RePaint();
end;
end;

Expand Down
66 changes: 36 additions & 30 deletions Source/imagebox/simba.imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,35 @@ TSimbaImageScrollBox = class(TCustomControl)
Active: Boolean;
end;

function topLeft: TPoint;

procedure WMEraseBkgnd(var Message: TLMEraseBkgnd); message LM_ERASEBKGND;

function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;

procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;

procedure MouseLeave; override;
procedure MouseEnter; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;

procedure Click; override;
procedure DblClick; override;

procedure Paint; override;
procedure Resize; override;

procedure DoBackgroundChange(Sender: TObject);
procedure DoScrollChange(Sender: TObject);
procedure UpdateScrollBars;

procedure UpdateScrollBars;
procedure ChangeZoom(ZoomIndex: Integer);
procedure IncreaseZoom(Inc: Boolean);

procedure Paint; override;
procedure Resize; override;
function VisibleTopX: Integer;
function VisibleTopY: Integer;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
Expand Down Expand Up @@ -118,6 +119,8 @@ TSimbaImageBox = class(TCustomControl)
FOnImgDoubleClick: TImageBoxClickEvent;
FOnImgPaint: TImageBoxPaintEvent;

procedure Paint; override;

procedure ImgKeyDown(var Key: Word; Shift: TShiftState); virtual;
procedure ImgKeyUp(var Key: Word; Shift: TShiftState); virtual;
procedure ImgMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); virtual;
Expand All @@ -137,8 +140,6 @@ TSimbaImageBox = class(TCustomControl)
public
constructor Create(AOwner: TComponent); override;

procedure Paint; reintroduce; override;

function FindDTM(DTM: TDTM): TPointArray;
function FindColor(AColor: TColor; Tolerance: Single; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers): TPointArray;
function MatchColor(AColor: TColor; ColorSpace: EColorSpace; Multipliers: TChannelMultipliers): TSingleMatrix;
Expand Down Expand Up @@ -293,10 +294,14 @@ procedure TSimbaImageScrollBox.ChangeZoom(ZoomIndex: Integer);
FImageBox.StatusBar.PanelText[2] := Format('%d%s', [FZoomLevel, '%']);
end;

function TSimbaImageScrollBox.topLeft: TPoint;
function TSimbaImageScrollBox.VisibleTopX: Integer;
begin
Result := Max(0, FHorzScroll.Position + ((FZoomPixels - FHorzScroll.Position) mod FZoomPixels));
end;

function TSimbaImageScrollBox.VisibleTopY: Integer;
begin
Result.X := Max(0, FHorzScroll.Position + ((FZoomPixels - FHorzScroll.Position) mod FZoomPixels));
Result.Y := Max(0, FVertScroll.Position + ((FZoomPixels - FVertScroll.Position) mod FZoomPixels));
Result := Max(0, FVertScroll.Position + ((FZoomPixels - FVertScroll.Position) mod FZoomPixels));
end;

procedure TSimbaImageScrollBox.WMEraseBkgnd(var Message: TLMEraseBkgnd);
Expand Down Expand Up @@ -343,8 +348,8 @@ procedure TSimbaImageScrollBox.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;

X += topLeft.X;
Y += topLeft.Y;
X += VisibleTopX;
Y += VisibleTopY;

if FDragging.Active then
begin
Expand Down Expand Up @@ -397,8 +402,8 @@ procedure TSimbaImageScrollBox.MouseDown(Button: TMouseButton; Shift: TShiftStat
if CanSetFocus() then
SetFocus();

X += topLeft.X;
Y += topLeft.Y;
X += VisibleTopX;
Y += VisibleTopY;

if (Button = mbRight) then
begin
Expand All @@ -422,8 +427,8 @@ procedure TSimbaImageScrollBox.MouseUp(Button: TMouseButton; Shift: TShiftState;
begin
inherited;

X += topLeft.X;
Y += topLeft.Y;
X += VisibleTopX;
Y += VisibleTopY;

if (Button = mbRight) then
begin
Expand Down Expand Up @@ -478,7 +483,8 @@ procedure TSimbaImageScrollBox.DoBackgroundChange(Sender: TObject);
FImageWidth := FBackground.Width;
FImageHeight := FBackground.Height;

ChangeZoom(3);
FZoomLevel := 100;
FZoomPixels := 1;

FHorzScroll.Position := 0;
FVertScroll.Position := 0;
Expand Down Expand Up @@ -530,8 +536,8 @@ PixelRGBA = record R,G,B,A: Byte; end;
Canvas.Brush.Color := clBlack;
Canvas.FillRect(ClientRect);

ScreenRect.Left := topLeft.X;
ScreenRect.Top := topLeft.Y;
ScreenRect.Left := VisibleTopX;
ScreenRect.Top := VisibleTopY;
ScreenRect.Right := ScreenRect.Left + ClientWidth + FZoomPixels;
ScreenRect.Bottom := ScreenRect.Top + ClientHeight + FZoomPixels;

Expand Down Expand Up @@ -657,20 +663,20 @@ procedure TSimbaImageScrollBox.IncreaseZoom(Inc: Boolean);
UpdateScrollBars();

if MouseInClient then
MoveTo(OldImagePoint);
MoveTo(OldImagePoint{%H-});
end;
end;

function TSimbaImageScrollBox.ScreenToImage(ScreenXY: TPoint): TPoint;
begin
Result.X := (topLeft.X + ScreenXY.X) div FZoomPixels;
Result.Y := (topLeft.Y + ScreenXY.Y) div FZoomPixels;
Result.X := (VisibleTopX + ScreenXY.X) div FZoomPixels;
Result.Y := (VisibleTopY + ScreenXY.Y) div FZoomPixels;
end;

function TSimbaImageScrollBox.ImageToScreen(ImageXY: TPoint): TPoint;
begin
Result.X := IfThen(FZoomLevel >= 100, ImageXY.X * FZoomPixels, ImageXY.X div FZoomPixels) - topLeft.X;
Result.Y := IfThen(FZoomLevel >= 100, ImageXY.Y * FZoomPixels, ImageXY.Y div FZoomPixels) - topLeft.Y;
Result.X := IfThen(FZoomLevel >= 100, ImageXY.X * FZoomPixels, ImageXY.X div FZoomPixels) - VisibleTopX;
Result.Y := IfThen(FZoomLevel >= 100, ImageXY.Y * FZoomPixels, ImageXY.Y div FZoomPixels) - VisibleTopY;
end;

procedure TSimbaImageScrollBox.MoveTo(ImageXY: TPoint);
Expand All @@ -694,11 +700,10 @@ constructor TSimbaImageScrollBox.Create(AOwner: TComponent);

FImageBox := AOwner as TSimbaImageBox;

FZoomLevel := 100;
FZoomPixels := 1;

FZoomMin := ZOOM_LEVELS[Low(ZOOM_LEVELS)];
FZoomMax := ZOOM_LEVELS[High(ZOOM_LEVELS)];
FZoomLevel := 100;
FZoomPixels := 1;

FVertScroll := TATScrollbar.Create(Self);
FVertScroll.Parent := Self;
Expand All @@ -723,6 +728,7 @@ destructor TSimbaImageScrollBox.Destroy;
begin
FreeAndNil(FCanvas);
FreeAndNil(FBackground);
FreeAndNil(FResizeBuffer);

inherited Destroy();
end;
Expand Down
2 changes: 1 addition & 1 deletion Source/script/imports/simba.import_imagebox.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils, Controls, ComCtrls, Graphics,
Classes, SysUtils, Controls, Graphics,
simba.base, simba.script_compiler;

procedure ImportSimbaImageBox(Compiler: TSimbaScript_Compiler);
Expand Down

0 comments on commit 0022a5c

Please sign in to comment.