diff --git a/Source/script/imports/simba.externalcanvas.pas b/Source/script/imports/simba.externalcanvas.pas new file mode 100644 index 000000000..e1a994cdb --- /dev/null +++ b/Source/script/imports/simba.externalcanvas.pas @@ -0,0 +1,895 @@ +{ + 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) + -------------------------------------------------------------------------- + + Provides a way to draw on an image which data is externally allocated. +} +unit simba.externalcanvas; + +{$i simba.inc} + +interface + +uses + Classes, SysUtils, Graphics, + simba.base, simba.baseclass, simba.image, simba.image_utils, simba.image_textdrawer, + simba.threading; + +type + TSimbaExternalCanvas = class(TSimbaBaseClass) + protected + FData: PColorBGRA; + FWidth, FHeight: Integer; + FImg: TSimbaImage; // pointed to above data + FLock: TEnterableLock; + FUserData: Pointer; + + FDoubleBuffered: Boolean; + FInUpdate: Integer; + FInvalidateNeeded: Boolean; + FInvalidateBox: TBox; + + procedure Invalidate(b: TBox); + procedure InvalidateAll; + + procedure Flush; + + function GetFontAntialiasing: Boolean; + function GetFontBold: Boolean; + function GetFontItalic: Boolean; + function GetFontName: String; + function GetFontSize: Single; + function GetPixel(const X, Y: Integer): TColor; + function GetAlpha(const X, Y: Integer): Byte; + function GetDefaultPixel: TColorBGRA; + function GetDrawAlpha: Byte; + function GetDrawColor: TColor; + + procedure SetDoubleBuffered(AValue: Boolean); + procedure SetFontAntialiasing(Value: Boolean); + procedure SetFontBold(Value: Boolean); + procedure SetFontItalic(Value: Boolean); + procedure SetFontName(Value: String); + procedure SetFontSize(Value: Single); + procedure SetPixel(const X, Y: Integer; const Color: TColor); + procedure SetAlpha(const X, Y: Integer; const Value: Byte); + procedure SetDefaultPixel(AValue: TColorBGRA); + procedure SetDrawAlpha(const AValue: Byte); + procedure SetDrawColor(const AValue: TColor); + public + UserData: Pointer; + AutoResize: Boolean; + + constructor Create; reintroduce; + destructor Destroy; override; + + property DefaultPixel: TColorBGRA read GetDefaultPixel write SetDefaultPixel; + property Width: Integer read FWidth; + property Height: Integer read FHeight; + property DoubleBuffered: Boolean read FDoubleBuffered write SetDoubleBuffered; + + property Pixel[X, Y: Integer]: TColor read GetPixel write SetPixel; default; + property Alpha[X, Y: Integer]: Byte read GetAlpha write SetAlpha; + + procedure SetPixels(Points: TPointArray; Color: TColor); overload; + procedure SetPixels(Points: TPointArray; Colors: TColorArray); overload; + + property DrawColor: TColor read GetDrawColor write SetDrawColor; + property DrawAlpha: Byte read GetDrawAlpha write SetDrawAlpha; + + property FontName: String read GetFontName write SetFontName; + property FontSize: Single read GetFontSize write SetFontSize; + property FontAntialiasing: Boolean read GetFontAntialiasing write SetFontAntialiasing; + property FontBold: Boolean read GetFontBold write SetFontBold; + property FontItalic: Boolean read GetFontItalic write SetFontItalic; + + procedure SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer); + procedure Resize(NewWidth, NewHeight: Integer); + + procedure BeginUpdate; + procedure EndUpdate; + + procedure Fill(Color: TColor); + procedure FillWithAlpha(Value: Byte); + + procedure Clear; overload; + procedure Clear(Box: TBox); overload; + procedure ClearInverted(Box: TBox); + + function TextWidth(Text: String): Integer; + function TextHeight(Text: String): Integer; + function TextSize(Text: String): TPoint; + + procedure DrawText(Text: String; Position: TPoint); overload; + procedure DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); overload; + procedure DrawTextLines(Text: TStringArray; Position: TPoint); + + // Image + procedure DrawImage(Image: TSimbaImage; Location: TPoint); + + // Point + procedure DrawATPA(ATPA: T2DPointArray); + procedure DrawTPA(TPA: TPointArray); + + // Line + procedure DrawCrosshairs(ACenter: TPoint; Size: Integer); + procedure DrawCross(ACenter: TPoint; Radius: Integer); + procedure DrawLine(Start, Stop: TPoint); + procedure DrawLineGap(Start, Stop: TPoint; GapSize: Integer); + + // Box + procedure DrawBox(Box: TBox); + procedure DrawBoxFilled(Box: TBox); + procedure DrawBoxInverted(Box: TBox); + + // Poly + procedure DrawPolygon(Points: TPointArray); + procedure DrawPolygonFilled(Points: TPointArray); + procedure DrawPolygonInverted(Points: TPointArray); + + // Quad + procedure DrawQuad(Quad: TQuad); + procedure DrawQuadFilled(Quad: TQuad); + procedure DrawQuadInverted(Quad: TQuad); + + // Circle + procedure DrawCircle(ACenter: TPoint; Radius: Integer); + procedure DrawCircleFilled(ACenter: TPoint; Radius: Integer); + procedure DrawCircleInverted(ACenter: TPoint; Radius: Integer); + + // Antialiased + procedure DrawLineAA(Start, Stop: TPoint; Thickness: Single = 1.5); + procedure DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single = 1.5); + procedure DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single = 1.5); + + // Arrays + procedure DrawQuadArray(Quads: TQuadArray; Filled: Boolean); + procedure DrawBoxArray(Boxes: TBoxArray; Filled: Boolean); + procedure DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean); + procedure DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean); + procedure DrawCrossArray(Points: TPointArray; Radius: Integer); + end; + +implementation + +uses + Math, + simba.vartype_box, simba.vartype_quad, simba.vartype_pointarray, simba.vartype_boxarray; + +procedure TSimbaExternalCanvas.Invalidate(b: TBox); +begin + if (FInUpdate <= 0) then + SimbaException('Not in BeginUpdate/EndUpdate'); + + if FInvalidateNeeded then + FInvalidateBox := FInvalidateBox.Combine(b.Normalize()) + else + begin + FInvalidateNeeded := True; + FInvalidateBox := b.Normalize(); + end; +end; + +procedure TSimbaExternalCanvas.InvalidateAll; +begin + if (FInUpdate <= 0) then + SimbaException('Not in BeginUpdate/EndUpdate'); + + FInvalidateNeeded := True; + FInvalidateBox.X1 := -$FFFFFF; + FInvalidateBox.Y1 := -$FFFFFF; + FInvalidateBox.X2 := $FFFFFF; + FInvalidateBox.Y2 := $FFFFFF; +end; + +procedure TSimbaExternalCanvas.Flush; +var + Y: Integer; +begin + if FInvalidateNeeded then + begin + FInvalidateNeeded := False; + FInvalidateBox := FInvalidateBox.Expand(1).Clip(TBox.Create(0, 0, FWidth-1, FHeight-1)); + for Y := FInvalidateBox.Y1 to FInvalidateBox.Y2 do + Move(FImg.Data[Y * FWidth + FInvalidateBox.X1], FData[Y * FWidth + FInvalidateBox.X1], (FInvalidateBox.X2 - FInvalidateBox.X1) * SizeOf(TColorBGRA)); + end; +end; + +function TSimbaExternalCanvas.GetFontAntialiasing: Boolean; +begin + Result := FImg.FontAntialiasing; +end; + +function TSimbaExternalCanvas.GetFontBold: Boolean; +begin + Result := FImg.FontBold; +end; + +function TSimbaExternalCanvas.GetFontItalic: Boolean; +begin + Result := FImg.FontItalic; +end; + +function TSimbaExternalCanvas.GetFontName: String; +begin + Result := FImg.FontName; +end; + +function TSimbaExternalCanvas.GetFontSize: Single; +begin + Result := FImg.FontSize; +end; + +function TSimbaExternalCanvas.GetPixel(const X, Y: Integer): TColor; +begin + Result := FImg.Pixel[X, Y]; +end; + +function TSimbaExternalCanvas.GetAlpha(const X, Y: Integer): Byte; +begin + Result := FImg.Alpha[X, Y]; +end; + +function TSimbaExternalCanvas.GetDrawAlpha: Byte; +begin + Result := FImg.DrawAlpha; +end; + +function TSimbaExternalCanvas.GetDrawColor: TColor; +begin + Result := FImg.DrawColor; +end; + +function TSimbaExternalCanvas.GetDefaultPixel: TColorBGRA; +begin + Result := FImg.DefaultPixel; +end; + +procedure TSimbaExternalCanvas.SetPixel(const X, Y: Integer; const Color: TColor); +begin + FImg.Pixel[X, Y] := Color; +end; + +procedure TSimbaExternalCanvas.SetAlpha(const X, Y: Integer; const Value: Byte); +begin + FImg.Alpha[X, Y] := Value; +end; + +procedure TSimbaExternalCanvas.SetDrawAlpha(const AValue: Byte); +begin + FImg.DrawAlpha := AValue; +end; + +procedure TSimbaExternalCanvas.SetDrawColor(const AValue: TColor); +begin + FImg.DrawColor := AValue; +end; + +procedure TSimbaExternalCanvas.SetDefaultPixel(AValue: TColorBGRA); +begin + FImg.DefaultPixel := AValue; +end; + +procedure TSimbaExternalCanvas.SetDoubleBuffered(AValue: Boolean); +begin + if (FDoubleBuffered = AValue) then + Exit; + + FDoubleBuffered := AValue; + if FDoubleBuffered then + FImg.ResetExternalData(FWidth, FHeight) + else + FImg.SetExternalData(FData, FWidth, FHeight); +end; + +procedure TSimbaExternalCanvas.SetFontAntialiasing(Value: Boolean); +begin + FImg.FontAntialiasing := Value; +end; + +procedure TSimbaExternalCanvas.SetFontBold(Value: Boolean); +begin + FImg.FontBold := Value; +end; + +procedure TSimbaExternalCanvas.SetFontItalic(Value: Boolean); +begin + FImg.FontItalic := Value; +end; + +procedure TSimbaExternalCanvas.SetFontName(Value: String); +begin + FImg.FontName := Value; +end; + +procedure TSimbaExternalCanvas.SetFontSize(Value: Single); +begin + FImg.FontSize := Value; +end; + +constructor TSimbaExternalCanvas.Create; +begin + inherited Create(); + + FImg := TSimbaImage.Create(); + FImg.DefaultPixel.A := ALPHA_TRANSPARENT; +end; + +destructor TSimbaExternalCanvas.Destroy; +begin + if Assigned(FImg) then + FreeAndNil(FImg); + + inherited Destroy(); +end; + +procedure TSimbaExternalCanvas.SetPixels(Points: TPointArray; Color: TColor); +begin + FLock.Enter(); + try + FImg.SetPixels(Points, Color); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.SetPixels(Points: TPointArray; Colors: TColorArray); +begin + FLock.Enter(); + try + FImg.SetPixels(Points, Colors); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer); +begin + FLock.Enter(); + try + FData := Data; + FWidth := AWidth; + FHeight := AHeight; + + if FDoubleBuffered then + FImg.ResetExternalData(FWidth, FHeight) + else + FImg.SetExternalData(FData, FWidth, FHeight); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.Resize(NewWidth, NewHeight: Integer); +var + Y: Integer; +begin + if (FWidth = NewWidth) and (FHeight = NewHeight) then + Exit; + + FLock.Enter(); + try + FWidth := NewWidth; + FHeight := NewHeight; + + FImg.SetSize(FWidth, FHeight); + for Y := 0 to FHeight - 1 do + Move(FImg.Data[Y * FWidth], FData[Y * FWidth], FWidth * SizeOf(TColorBGRA)); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.BeginUpdate; +begin + if (not FDoubleBuffered) then + Exit; + FLock.Enter(); + + Inc(FInUpdate); + if (FInUpdate > 1) then + Exit; + + FInvalidateNeeded := False; +end; + +procedure TSimbaExternalCanvas.EndUpdate; +begin + if (not FDoubleBuffered) then + Exit; + if (FInUpdate <= 0) then + SimbaException('Not in BeginUpdate'); + + Dec(FInUpdate); + if (FInUpdate > 0) then + Exit; + + Flush(); + + FLock.Leave(); +end; + +procedure TSimbaExternalCanvas.FillWithAlpha(Value: Byte); +begin + FLock.Enter(); + try + InvalidateAll(); + + FImg.FillWithAlpha(Value); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawATPA(ATPA: T2DPointArray); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(ATPA.Bounds); + + FImg.DrawATPA(ATPA); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawTPA(TPA: TPointArray); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TPA.Bounds); + + FImg.DrawTPA(TPA); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCrosshairs(ACenter: TPoint; Size: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Size, Size)); + + FImg.DrawCrosshairs(ACenter, Size); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCross(ACenter: TPoint; Radius: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Radius, Radius)); + + FImg.DrawCross(ACenter, Radius); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawLine(Start, Stop: TPoint); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(Start.X, Start.Y, Stop.X, Stop.Y)); + + FImg.DrawLine(Start, Stop); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawLineGap(Start, Stop: TPoint; GapSize: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(Start.X, Start.Y, Stop.X, Stop.Y)); + + FImg.DrawLineGap(Start, Stop, GapSize); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.Clear; +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.Clear(); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.Clear(Box: TBox); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Box); + + FImg.Clear(); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.ClearInverted(Box: TBox); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.ClearInverted(Box); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.Fill(Color: TColor); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.Fill(Color); + finally + FLock.Leave(); + end; +end; + +function TSimbaExternalCanvas.TextWidth(Text: String): Integer; +begin + Result := FImg.TextWidth(Text); +end; + +function TSimbaExternalCanvas.TextHeight(Text: String): Integer; +begin + Result := FImg.TextHeight(Text); +end; + +function TSimbaExternalCanvas.TextSize(Text: String): TPoint; +begin + Result := FImg.TextSize(Text); +end; + +type + TSimbaImageProtected = class(TSimbaImage); + +procedure TSimbaExternalCanvas.DrawText(Text: String; Position: TPoint); +begin + FLock.Enter(); + try + FImg.DrawText(Text, Position); + if FDoubleBuffered then + Invalidate(TSimbaImageProtected(FImg).FTextDrawer.DrawnBox); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); +begin + FLock.Enter(); + try + FImg.DrawText(Text, Box, Alignments); + if FDoubleBuffered then + Invalidate(TSimbaImageProtected(FImg).FTextDrawer.DrawnBox); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawTextLines(Text: TStringArray; Position: TPoint); +begin + FLock.Enter(); + try + FImg.DrawTextLines(Text, Position); + if FDoubleBuffered then + Invalidate(TSimbaImageProtected(FImg).FTextDrawer.DrawnBox); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawImage(Image: TSimbaImage; Location: TPoint); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(Location.X, Location.Y, Location.X + Image.Width, Location.Y + Image.Height)); + + FImg.DrawImage(Image, Location); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawBox(Box: TBox); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Box); + + FImg.DrawBox(Box); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawBoxFilled(Box: TBox); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Box); + + FImg.DrawBoxFilled(Box); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawBoxInverted(Box: TBox); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.DrawBoxInverted(Box); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawPolygon(Points: TPointArray); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Points.Bounds); + + FImg.DrawPolygon(Points); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawPolygonFilled(Points: TPointArray); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Points.Bounds); + + FImg.DrawPolygonFilled(Points); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawPolygonInverted(Points: TPointArray); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.DrawPolygonInverted(Points); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawQuad(Quad: TQuad); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Quad.Bounds); + + FImg.DrawQuad(Quad); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawQuadFilled(Quad: TQuad); +begin + FLock.Enter(); + try + Invalidate(Quad.Bounds); + + FImg.DrawQuadFilled(Quad); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawQuadInverted(Quad: TQuad); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.DrawQuadInverted(Quad); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCircle(ACenter: TPoint; Radius: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Radius, Radius)); + + FImg.DrawCircle(ACenter, Radius); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCircleFilled(ACenter: TPoint; Radius: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Radius, Radius)); + + FImg.DrawCircleFilled(ACenter, Radius); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCircleInverted(ACenter: TPoint; Radius: Integer); +begin + FLock.Enter(); + try + if FDoubleBuffered then + InvalidateAll(); + + FImg.DrawCircleInverted(ACenter, Radius); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawLineAA(Start, Stop: TPoint; Thickness: Single); +begin + FLock.Enter(); + try + if FDoubleBuffered then + begin + Invalidate(TBox.Create(Ceil(Start.X - Thickness), Ceil(Start.Y - Thickness), Ceil(Stop.X - Thickness), Ceil(Stop.Y - Thickness))); + Invalidate(TBox.Create(Ceil(Start.X + Thickness), Ceil(Start.Y + Thickness), Ceil(Stop.X + Thickness), Ceil(Stop.Y + Thickness))); + end; + + FImg.DrawLineAA(Start, Stop, Thickness); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Ceil(XRadius + Thickness), Ceil(YRadius + Thickness))); + + FImg.DrawEllipseAA(ACenter, XRadius, YRadius, Thickness); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(TBox.Create(ACenter, Ceil(Radius + Thickness), Ceil(Radius + Thickness))); + + FImg.DrawCircleAA(ACenter, Radius, Thickness); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawQuadArray(Quads: TQuadArray; Filled: Boolean); +var + I: Integer; +begin + FLock.Enter(); + try + if FDoubleBuffered then + for I := 0 to High(Quads) do + Invalidate(Quads[I].Bounds); + + FImg.DrawQuadArray(Quads, Filled); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawBoxArray(Boxes: TBoxArray; Filled: Boolean); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Boxes.Merge()); + + FImg.DrawBoxArray(Boxes, Filled); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean); +begin + FLock.Enter(); + try + if FDoubleBuffered then + Invalidate(Polygons.Bounds); + + FImg.DrawPolygonArray(Polygons, Filled); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean); +var + I: Integer; +begin + FLock.Enter(); + try + if FDoubleBuffered then + for I := 0 to High(Centers) do + Invalidate(TBox.Create(Centers[I], Radius, Radius)); + + FImg.DrawCircleArray(Centers, Radius, Filled); + finally + FLock.Leave(); + end; +end; + +procedure TSimbaExternalCanvas.DrawCrossArray(Points: TPointArray; Radius: Integer); +var + I: Integer; +begin + FLock.Enter(); + try + if FDoubleBuffered then + for I := 0 to High(Points) do + Invalidate(TBox.Create(Points[I], Radius, Radius)); + + FImg.DrawCrossArray(Points, Radius); + finally + FLock.Leave(); + end; +end; + +end. + diff --git a/Source/script/imports/simba.import_externalcanvas.pas b/Source/script/imports/simba.import_externalcanvas.pas new file mode 100644 index 000000000..3a347cd36 --- /dev/null +++ b/Source/script/imports/simba.import_externalcanvas.pas @@ -0,0 +1,642 @@ +unit simba.import_externalcanvas; + +{$i simba.inc} + +interface + +uses + Classes, SysUtils, Graphics, + simba.base, simba.script_compiler; + +procedure ImportExternalCanvas(Compiler: TSimbaScript_Compiler); + +implementation + +uses + lptypes, + simba.image, simba.image_textdrawer, simba.externalcanvas; + +type + PSimbaExternalCanvas = ^TSimbaExternalCanvas; + +procedure _LapeExternalCanvas_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPointer(Result)^ := TSimbaExternalCanvas.Create(); +end; + +procedure _LapeExternalCanvas_Free(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Free(); +end; + +(* +TExternalCanvas.Width +-------------------- +> property TExternalCanvas.Width: Integer; +*) +procedure _LapeExternalCanvas_Width_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PInteger(Result)^ := PSimbaExternalCanvas(Params^[0])^.Width; +end; + +(* +TExternalCanvas.Height +--------------------- +> property TExternalCanvas.Height: Integer; +*) +procedure _LapeExternalCanvas_Height_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PInteger(Result)^ := PSimbaExternalCanvas(Params^[0])^.Height; +end; + +(* +TExternalCanvas.GetDefaultPixel +------------------------------ +> function TExternalCanvas.GetDefaultPixel: TColorBGRA; +*) +procedure _LapeExternalCanvas_DefaultPixel_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PColorBGRA(Result)^ := PSimbaExternalCanvas(Params^[0])^.DefaultPixel; +end; + +(* +TExternalCanvas.SetDefaultPixel +------------------------------ +> procedure TExternalCanvas.SetDefaultPixel(Value: TColorBGRA); +*) +procedure _LapeExternalCanvas_DefaultPixel_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DefaultPixel := PColorBGRA(Params^[1])^; +end; + +(* +TExternalCanvas.GetFontName +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.GetFontName: String; +*) +procedure _LapeExternalCanvas_FontName_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PString(Result)^ := PSimbaExternalCanvas(Params^[0])^.FontName; +end; + +(* +TExternalCanvas.SetFontName +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.SetFontName(Value: String); +*) +procedure _LapeExternalCanvas_FontName_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FontName := PString(Params^[1])^; +end; + +(* +TExternalCanvas.GetFontSize +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.GetFontSize: Single; +*) +procedure _LapeExternalCanvas_FontSize_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PSingle(Result)^ := PSimbaExternalCanvas(Params^[0])^.FontSize; +end; + +(* +TExternalCanvas.SetFontSize +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.SetFontSize(Value: Single); +*) +procedure _LapeExternalCanvas_FontSize_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FontSize := PSingle(Params^[1])^; +end; + +(* +TExternalCanvas.GetFontAntialiasing +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.GetFontAntialiasing: Boolean; +*) +procedure _LapeExternalCanvas_FontAntialiasing_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PBoolean(Result)^ := PSimbaExternalCanvas(Params^[0])^.FontAntialiasing; +end; + +(* +TExternalCanvas.SetFontAntialiasing +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.SetFontAntialiasing(Value: Boolean); +*) +procedure _LapeExternalCanvas_FontAntialiasing_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FontAntialiasing := PBoolean(Params^[1])^; +end; + +(* +TExternalCanvas.GetFontBold +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.GetFontBold: Boolean; +*) +procedure _LapeExternalCanvas_FontBold_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PBoolean(Result)^ := PSimbaExternalCanvas(Params^[0])^.FontBold; +end; + +(* +TExternalCanvas.SetFontBold +~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.SetFontBold(Value: Boolean); +*) +procedure _LapeExternalCanvas_FontBold_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FontBold := PBoolean(Params^[1])^; +end; + +(* +TExternalCanvas.GetFontItalic +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.GetFontItalic: Boolean; +*) +procedure _LapeExternalCanvas_FontItalic_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PBoolean(Result)^ := PSimbaExternalCanvas(Params^[0])^.FontItalic; +end; + +(* +TExternalCanvas.SetFontItalic +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.SetFontItalic(Value: Boolean); +*) +procedure _LapeExternalCanvas_FontItalic_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FontItalic := PBoolean(Params^[1])^; +end; + +(* +TExternalCanvas.TextWidth +~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.TextWidth(Text: String): Integer; +*) +procedure _LapeExternalCanvas_TextWidth(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PInteger(Result)^ := PSimbaExternalCanvas(Params^[0])^.TextWidth(PString(Params^[1])^); +end; + +(* +TExternalCanvas.TextHeight +~~~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.TextHeight(Text: String): Integer; +*) +procedure _LapeExternalCanvas_TextHeight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PInteger(Result)^ := PSimbaExternalCanvas(Params^[0])^.TextHeight(PString(Params^[1])^); +end; + +procedure _LapeExternalCanvas_Clear1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Clear(); +end; + +procedure _LapeExternalCanvas_Clear2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Clear(PBox(Params^[1])^); +end; + +procedure _LapeExternalCanvas_ClearInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.ClearInverted(PBox(Params^[1])^); +end; + +(* +TExternalCanvas.TextSize +~~~~~~~~~~~~~~~~~~~~~~~ +> function TExternalCanvas.TextSize(Text: String): TPoint; +*) +procedure _LapeExternalCanvas_TextSize(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPoint(Result)^ := PSimbaExternalCanvas(Params^[0])^.TextSize(PString(Params^[1])^); +end; + +(* +TExternalCanvas.GetAlpha +----------------------- +> function TExternalCanvas.GetAlpha(X, Y: Integer): Byte; +*) +procedure _LapeExternalCanvas_Alpha_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PByte(Result)^ := PSimbaExternalCanvas(Params^[0])^.Alpha[PInteger(Params^[1])^, PInteger(Params^[2])^]; +end; + +(* +TExternalCanvas.SetAlpha +----------------------- +> procedure TExternalCanvas.SetAlpha(X, Y: Integer; Alpha: Byte); +*) +procedure _LapeExternalCanvas_Alpha_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Alpha[PInteger(Params^[1])^, PInteger(Params^[2])^] := PByte(Params^[3])^; +end; + +(* +TExternalCanvas.GetPixel +----------------------- +> function TExternalCanvas.GetPixel(X, Y: Integer): TColor; +*) +procedure _LapeExternalCanvas_Pixel_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PColor(Result)^ := PSimbaExternalCanvas(Params^[0])^.Pixel[PInteger(Params^[1])^, PInteger(Params^[2])^]; +end; + +(* +TExternalCanvas.SetPixel +----------------------- +> procedure TExternalCanvas.SetPixel(X, Y: Integer; Color: TColor); +*) +procedure _LapeExternalCanvas_Pixel_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Pixel[PInteger(Params^[1])^, PInteger(Params^[2])^] := PColor(Params^[3])^; +end; + +(* +TExternalCanvas.SetPixels +------------------------ +> procedure TExternalCanvas.SetPixels(Points: TPointArray; Color: TColor); +*) +procedure _LapeExternalCanvas_SetPixels1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.SetPixels(PPointArray(Params^[1])^, PColor(Params^[2])^); +end; + +(* +TExternalCanvas.SetPixels +------------------------ +> procedure TExternalCanvas.SetPixels(Points: TPointArray; Colors: TColorArray); +*) +procedure _LapeExternalCanvas_SetPixels2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.SetPixels(PPointArray(Params^[1])^, PIntegerArray(Params^[2])^); +end; + +(* +TExternalCanvas.GetDrawColor +--------------------------- +> function TExternalCanvas.GetDrawColor: TColor; + +Returns the current drawing color. + +```{note} +Red is the default value. +``` +*) +procedure _LapeExternalCanvas_DrawColor_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PColor(Result)^ := PSimbaExternalCanvas(Params^[0])^.DrawColor; +end; + +(* +TExternalCanvas.SetDrawColor +--------------------------- +> procedure TExternalCanvas.SetDrawColor(Color: TColor); + +Sets the current draw color. + +```{note} +Red is the default value. +``` +*) +procedure _LapeExternalCanvas_DrawColor_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawColor := PColor(Params^[1])^; +end; + +(* +TExternalCanvas.GetDrawAlpha +--------------------------- +> function TExternalCanvas.GetDrawAlpha: Byte; + +Returns the current draw alpha. +0 is completely transparent and 255 is completely opauge. + +```{note} +255 is the default value. +``` +*) +procedure _LapeExternalCanvas_DrawAlpha_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PByte(Result)^ := PSimbaExternalCanvas(Params^[0])^.DrawAlpha; +end; + +(* +TExternalCanvas.SetDrawAlpha +--------------------------- +> procedure TExternalCanvas.SetDrawAlpha(Value: Byte); + +Sets the current draw color. This determines how transparent something is drawn. + +```{note} +255 is the default value. +``` +*) +procedure _LapeExternalCanvas_DrawAlpha_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawAlpha := PByte(Params^[1])^; +end; + +(* +TExternalCanvas.DrawText +~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.DrawText(Text: String; Position: TPoint); +*) +procedure _LapeExternalCanvas_DrawText(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawText(PString(Params^[1])^, PPoint(Params^[2])^); +end; + +(* +TExternalCanvas.DrawText +~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); +*) +procedure _LapeExternalCanvas_DrawTextEx(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawText(PString(Params^[1])^, PBox(Params^[2])^, EImageTextAlign(Params^[3]^)); +end; + +(* +TExternalCanvas.DrawTextLines +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +> procedure TExternalCanvas.DrawTextLines(Text: TStringArray; Position: TPoint); +*) +procedure _LapeExternalCanvas_DrawTextLines(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawTextLines(PStringArray(Params^[1])^, PPoint(Params^[2])^); +end; + +procedure _LapeExternalCanvas_Fill(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.Fill(PColor(Params^[1])^); +end; + +procedure _LapeExternalCanvas_SetMemory(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.SetMemory(PPointer(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^); +end; + +procedure _LapeExternalCanvas_UserData_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPointer(Result)^ := PSimbaExternalCanvas(Params^[0])^.UserData +end; + +procedure _LapeExternalCanvas_UserData_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.UserData := PPointer(Params^[1])^; +end; + +procedure _LapeExternalCanvas_DoubleBuffered_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PBoolean(Result)^ := PSimbaExternalCanvas(Params^[0])^.DoubleBuffered; +end; + +procedure _LapeExternalCanvas_DoubleBuffered_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DoubleBuffered := PBoolean(Params^[1])^; +end; + +procedure _LapeExternalCanvas_DrawCircleAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCircleAA(PPoint(Params^[1])^, PInteger(Params^[2])^, PSingle(Params^[3])^); +end; + +procedure _LapeExternalCanvas_DrawLineAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawLineAA(PPoint(Params^[1])^, PPoint(Params^[2])^, PSingle(Params^[3])^); +end; + +procedure _LapeExternalCanvas_DrawEllipseAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawEllipseAA(PPoint(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^, PSingle(Params^[4])^); +end; + +procedure _LapeExternalCanvas_DrawImage(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawImage(PSimbaImage(Params^[1])^, PPoint(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawBox(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawBox(PBox(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawBoxFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawBoxFilled(PBox(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawBoxInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawBoxInverted(PBox(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawPolygon(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawPolygon(PPointArray(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawPolygonFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawPolygonFilled(PPointArray(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawPolygonInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawPolygonInverted(PPointArray(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawQuad(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawQuad(PQuad(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawQuadFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawQuadFilled(PQuad(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawQuadInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawQuadInverted(PQuad(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawCircle(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCircle(PPoint(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawCircleFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCircleFilled(PPoint(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawCircleInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCircleInverted(PPoint(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawCrosshairs(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCrosshairs(PPoint(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawCross(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCross(PPoint(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawLine(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawLine(PPoint(Params^[1])^, PPoint(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawLineGap(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawLineGap(PPoint(Params^[1])^, PPoint(Params^[2])^, PInteger(Params^[3])^); +end; + +procedure _LapeExternalCanvas_FillWithAlpha(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.FillWithAlpha(PByte(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawATPA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawATPA(P2DPointArray(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawTPA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawTPA(PPointArray(Params^[1])^); +end; + +procedure _LapeExternalCanvas_DrawQuadArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawQuadArray(PQuadArray(Params^[1])^, PBoolean(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawBoxArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawBoxArray(PBoxArray(Params^[1])^, PBoolean(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawPolygonArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawPolygonArray(P2DPointArray(Params^[1])^, PBoolean(Params^[2])^); +end; + +procedure _LapeExternalCanvas_DrawCircleArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCircleArray(PPointArray(Params^[1])^, PInteger(Params^[2])^, PBoolean(Params^[3])^); +end; + +procedure _LapeExternalCanvas_DrawCrossArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.DrawCrossArray(PPointArray(Params^[1])^, PInteger(Params^[2])^); +end; + +procedure _LapeExternalCanvas_BeginUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.BeginUpdate(); +end; + +procedure _LapeExternalCanvas_EndUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV +begin + PSimbaExternalCanvas(Params^[0])^.EndUpdate(); +end; + +procedure ImportExternalCanvas(Compiler: TSimbaScript_Compiler); +begin + with Compiler do + begin + addClass('TExternalCanvas', 'TBaseClass'); + + addGlobalFunc('function TExternalCanvas.Create: TExternalCanvas; static;', @_LapeExternalCanvas_Create); + addGlobalFunc('procedure TExternalCanvas.Free;', @_LapeExternalCanvas_Free); + addGlobalFunc('procedure TExternalCanvas.SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer);', @_LapeExternalCanvas_SetMemory); + + addProperty('TExternalCanvas', 'UserData', 'Pointer', @_LapeExternalCanvas_UserData_Read, @_LapeExternalCanvas_UserData_Write); + addProperty('TExternalCanvas', 'DoubleBuffered', 'Boolean', @_LapeExternalCanvas_DoubleBuffered_Read, @_LapeExternalCanvas_DoubleBuffered_Write); + + addProperty('TExternalCanvas', 'Width', 'Integer', @_LapeExternalCanvas_Width_Read); + addProperty('TExternalCanvas', 'Height', 'Integer', @_LapeExternalCanvas_Height_Read); + addProperty('TExternalCanvas', 'DefaultPixel', 'TColorBGRA', @_LapeExternalCanvas_DefaultPixel_Read, @_LapeExternalCanvas_DefaultPixel_Write); + + addProperty('TExternalCanvas', 'FontName', 'String', @_LapeExternalCanvas_FontName_Read, @_LapeExternalCanvas_FontName_Write); + addProperty('TExternalCanvas', 'FontSize', 'Single', @_LapeExternalCanvas_FontSize_Read, @_LapeExternalCanvas_FontSize_Write); + addProperty('TExternalCanvas', 'FontAntialiasing', 'Boolean', @_LapeExternalCanvas_FontAntialiasing_Read, @_LapeExternalCanvas_FontAntialiasing_Write); + addProperty('TExternalCanvas', 'FontBold', 'Boolean', @_LapeExternalCanvas_FontBold_Read, @_LapeExternalCanvas_FontBold_Write); + addProperty('TExternalCanvas', 'FontItalic', 'Boolean', @_LapeExternalCanvas_FontItalic_Read, @_LapeExternalCanvas_FontItalic_Write); + + addProperty('TExternalCanvas', 'DrawColor', 'TColor', @_LapeExternalCanvas_DrawColor_Read, @_LapeExternalCanvas_DrawColor_Write); + addProperty('TExternalCanvas', 'DrawAlpha', 'Byte', @_LapeExternalCanvas_DrawAlpha_Read, @_LapeExternalCanvas_DrawAlpha_Write); + + addPropertyIndexed('TExternalCanvas', 'Alpha', 'X, Y: Integer', 'Byte', @_LapeExternalCanvas_Alpha_Read, @_LapeExternalCanvas_Alpha_Write); + addPropertyIndexed('TExternalCanvas', 'Pixel', 'X, Y: Integer', 'TColor', @_LapeExternalCanvas_Pixel_Read, @_LapeExternalCanvas_Pixel_Write); + + addGlobalFunc('function TExternalCanvas.TextWidth(Text: String): Integer;', @_LapeExternalCanvas_TextWidth); + addGlobalFunc('function TExternalCanvas.TextHeight(Text: String): Integer;', @_LapeExternalCanvas_TextHeight); + addGlobalFunc('function TExternalCanvas.TextSize(Text: String): TPoint;', @_LapeExternalCanvas_TextSize); + + addGlobalFunc('procedure TExternalCanvas.SetPixels(Points: TPointArray; Color: TColor); overload', @_LapeExternalCanvas_SetPixels1); + addGlobalFunc('procedure TExternalCanvas.SetPixels(Points: TPointArray; Colors: TColorArray); overload', @_LapeExternalCanvas_SetPixels2); + + addGlobalFunc('procedure TExternalCanvas.DrawText(Text: String; Position: TPoint); overload', @_LapeExternalCanvas_DrawText); + addGlobalFunc('procedure TExternalCanvas.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); overload', @_LapeExternalCanvas_DrawTextEx); + addGlobalFunc('procedure TExternalCanvas.DrawTextLines(Text: TStringArray; Position: TPoint);', @_LapeExternalCanvas_DrawTextLines); + + addGlobalFunc('procedure TExternalCanvas.Fill(Color: TColor)', @_LapeExternalCanvas_Fill); + addGlobalFunc('procedure TExternalCanvas.FillWithAlpha(Value: Byte);', @_LapeExternalCanvas_FillWithAlpha); + + addGlobalFunc('procedure TExternalCanvas.Clear; overload', @_LapeExternalCanvas_Clear1); + addGlobalFunc('procedure TExternalCanvas.Clear(Box: TBox); overload;', @_LapeExternalCanvas_Clear2); + addGlobalFunc('procedure TExternalCanvas.ClearInverted(Box: TBox);', @_LapeExternalCanvas_ClearInverted); + + addGlobalFunc('procedure TExternalCanvas.DrawATPA(ATPA: T2DPointArray)', @_LapeExternalCanvas_DrawATPA); + addGlobalFunc('procedure TExternalCanvas.DrawTPA(TPA: TPointArray)', @_LapeExternalCanvas_DrawTPA); + + addGlobalFunc('procedure TExternalCanvas.DrawImage(Image: TImage; Position: TPoint);', @_LapeExternalCanvas_DrawImage); + + addGlobalFunc('procedure TExternalCanvas.DrawBox(B: TBox);', @_LapeExternalCanvas_DrawBox); + addGlobalFunc('procedure TExternalCanvas.DrawBoxFilled(B: TBox);', @_LapeExternalCanvas_DrawBoxFilled); + addGlobalFunc('procedure TExternalCanvas.DrawBoxInverted(B: TBox);', @_LapeExternalCanvas_DrawBoxInverted); + + addGlobalFunc('procedure TExternalCanvas.DrawPolygon(Points: TPointArray);', @_LapeExternalCanvas_DrawPolygon); + addGlobalFunc('procedure TExternalCanvas.DrawPolygonFilled(Points: TPointArray);', @_LapeExternalCanvas_DrawPolygonFilled); + addGlobalFunc('procedure TExternalCanvas.DrawPolygonInverted(Points: TPointArray);', @_LapeExternalCanvas_DrawPolygonInverted); + + addGlobalFunc('procedure TExternalCanvas.DrawQuad(Quad: TQuad);', @_LapeExternalCanvas_DrawQuad); + addGlobalFunc('procedure TExternalCanvas.DrawQuadFilled(Quad: TQuad);', @_LapeExternalCanvas_DrawQuadFilled); + addGlobalFunc('procedure TExternalCanvas.DrawQuadInverted(Quad: TQuad);', @_LapeExternalCanvas_DrawQuadInverted); + + addGlobalFunc('procedure TExternalCanvas.DrawCircle(Center: TPoint; Radius: Integer)', @_LapeExternalCanvas_DrawCircle); + addGlobalFunc('procedure TExternalCanvas.DrawCircleFilled(Center: TPoint; Radius: Integer)', @_LapeExternalCanvas_DrawCircleFilled); + addGlobalFunc('procedure TExternalCanvas.DrawCircleInverted(Center: TPoint; Radius: Integer)', @_LapeExternalCanvas_DrawCircleInverted); + + addGlobalFunc('procedure TExternalCanvas.DrawCrosshairs(ACenter: TPoint; Size: Integer);', @_LapeExternalCanvas_DrawCrosshairs); + addGlobalFunc('procedure TExternalCanvas.DrawCross(ACenter: TPoint; Radius: Integer);', @_LapeExternalCanvas_DrawCross); + + addGlobalFunc('procedure TExternalCanvas.DrawLine(Start, Stop: TPoint);', @_LapeExternalCanvas_DrawLine); + addGlobalFunc('procedure TExternalCanvas.DrawLineGap(Start, Stop: TPoint; GapSize: Integer);', @_LapeExternalCanvas_DrawLineGap); + + addGlobalFunc('procedure TExternalCanvas.DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single = 1.5)', @_LapeExternalCanvas_DrawCircleAA); + addGlobalFunc('procedure TExternalCanvas.DrawLineAA(Start, Stop: TPoint; Thickness: Single = 1.5)', @_LapeExternalCanvas_DrawLineAA); + addGlobalFunc('procedure TExternalCanvas.DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single = 1.5)', @_LapeExternalCanvas_DrawEllipseAA); + + addGlobalFunc('procedure TExternalCanvas.DrawQuadArray(Quads: TQuadArray; Filled: Boolean);', @_LapeExternalCanvas_DrawQuadArray); + addGlobalFunc('procedure TExternalCanvas.DrawBoxArray(Boxes: TBoxArray; Filled: Boolean);', @_LapeExternalCanvas_DrawBoxArray); + addGlobalFunc('procedure TExternalCanvas.DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean);', @_LapeExternalCanvas_DrawPolygonArray); + addGlobalFunc('procedure TExternalCanvas.DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean);', @_LapeExternalCanvas_DrawCircleArray); + addGlobalFunc('procedure TExternalCanvas.DrawCrossArray(Points: TPointArray; Radius: Integer);', @_LapeExternalCanvas_DrawCrossArray); + + addGlobalFunc('procedure TExternalCanvas.BeginUpdate;', @_LapeExternalCanvas_BeginUpdate); + addGlobalFunc('procedure TExternalCanvas.EndUpdate;', @_LapeExternalCanvas_EndUpdate); + end; +end; + +end. + diff --git a/Source/script/imports/simba.import_externalimage.pas b/Source/script/imports/simba.import_externalimage.pas deleted file mode 100644 index 3d276023d..000000000 --- a/Source/script/imports/simba.import_externalimage.pas +++ /dev/null @@ -1,653 +0,0 @@ -unit simba.import_externalimage; - -{$i simba.inc} - -interface - -uses - Classes, SysUtils, Graphics, - simba.base, simba.script_compiler; - -procedure ImportSimbaExternalImage(Compiler: TSimbaScript_Compiler); - -implementation - -uses - lptypes, - simba.image, simba.image_textdrawer, simba.externalimage; - -procedure _LapeExternalImage_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PPointer(Result)^ := TSimbaExternalImage.Create(); -end; - -procedure _LapeExternalImage_FreeOnTerminate(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FreeOnTerminate := PBoolean(Params^[1])^; -end; - -procedure _LapeExternalImage_Width(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PInteger(Result)^ := PSimbaExternalImage(Params^[0])^.Width; -end; - -procedure _LapeExternalImage_Height(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PInteger(Result)^ := PSimbaExternalImage(Params^[0])^.Height; -end; - -(* -TExternalImage.GetName ----------------------- -> function TExternalImage.GetName: String; -*) -procedure _LapeExternalImage_Name_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PString(Result)^ := PSimbaExternalImage(Params^[0])^.Name; -end; - -(* -TExternalImage.SetName ----------------------- -> procedure TExternalImage.SetName(Value: String); -*) -procedure _LapeExternalImage_Name_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Name := PString(Params^[1])^; -end; - -(* -TExternalImage.GetDefaultPixel ------------------------------- -> function TExternalImage.GetDefaultPixel: TColorBGRA; -*) -procedure _LapeExternalImage_DefaultPixel_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PColorBGRA(Result)^ := PSimbaExternalImage(Params^[0])^.DefaultPixel; -end; - -(* -TExternalImage.SetDefaultPixel ------------------------------- -> procedure TExternalImage.SetDefaultPixel(Value: TColorBGRA); -*) -procedure _LapeExternalImage_DefaultPixel_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DefaultPixel := PColorBGRA(Params^[1])^; -end; - -(* -TExternalImage.GetFontName -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.GetFontName: String; -*) -procedure _LapeExternalImage_FontName_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PString(Result)^ := PSimbaExternalImage(Params^[0])^.FontName; -end; - -(* -TExternalImage.SetFontName -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.SetFontName(Value: String); -*) -procedure _LapeExternalImage_FontName_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FontName := PString(Params^[1])^; -end; - -(* -TExternalImage.GetFontSize -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.GetFontSize: Single; -*) -procedure _LapeExternalImage_FontSize_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PSingle(Result)^ := PSimbaExternalImage(Params^[0])^.FontSize; -end; - -(* -TExternalImage.SetFontSize -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.SetFontSize(Value: Single); -*) -procedure _LapeExternalImage_FontSize_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FontSize := PSingle(Params^[1])^; -end; - -(* -TExternalImage.GetFontAntialiasing -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.GetFontAntialiasing: Boolean; -*) -procedure _LapeExternalImage_FontAntialiasing_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PBoolean(Result)^ := PSimbaExternalImage(Params^[0])^.FontAntialiasing; -end; - -(* -TExternalImage.SetFontAntialiasing -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.SetFontAntialiasing(Value: Boolean); -*) -procedure _LapeExternalImage_FontAntialiasing_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FontAntialiasing := PBoolean(Params^[1])^; -end; - -(* -TExternalImage.GetFontBold -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.GetFontBold: Boolean; -*) -procedure _LapeExternalImage_FontBold_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PBoolean(Result)^ := PSimbaExternalImage(Params^[0])^.FontBold; -end; - -(* -TExternalImage.SetFontBold -~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.SetFontBold(Value: Boolean); -*) -procedure _LapeExternalImage_FontBold_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FontBold := PBoolean(Params^[1])^; -end; - -(* -TExternalImage.GetFontItalic -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.GetFontItalic: Boolean; -*) -procedure _LapeExternalImage_FontItalic_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PBoolean(Result)^ := PSimbaExternalImage(Params^[0])^.FontItalic; -end; - -(* -TExternalImage.SetFontItalic -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.SetFontItalic(Value: Boolean); -*) -procedure _LapeExternalImage_FontItalic_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FontItalic := PBoolean(Params^[1])^; -end; - -(* -TExternalImage.TextWidth -~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.TextWidth(Text: String): Integer; -*) -procedure _LapeExternalImage_TextWidth(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PInteger(Result)^ := PSimbaExternalImage(Params^[0])^.TextWidth(PString(Params^[1])^); -end; - -(* -TExternalImage.TextHeight -~~~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.TextHeight(Text: String): Integer; -*) -procedure _LapeExternalImage_TextHeight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PInteger(Result)^ := PSimbaExternalImage(Params^[0])^.TextHeight(PString(Params^[1])^); -end; - -procedure _LapeExternalImage_Clear1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Clear(); -end; - -procedure _LapeExternalImage_Clear2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Clear(PBox(Params^[1])^); -end; - -procedure _LapeExternalImage_ClearInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.ClearInverted(PBox(Params^[1])^); -end; - -(* -TExternalImage.TextSize -~~~~~~~~~~~~~~~~~~~~~~~ -> function TExternalImage.TextSize(Text: String): TPoint; -*) -procedure _LapeExternalImage_TextSize(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PPoint(Result)^ := PSimbaExternalImage(Params^[0])^.TextSize(PString(Params^[1])^); -end; - -(* -TExternalImage.GetPixel ------------------------ -> function TExternalImage.GetPixel(X, Y: Integer): TColor; -*) -procedure _LapeExternalImage_GetPixel(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PColor(Result)^ := PSimbaExternalImage(Params^[0])^.Pixel[PInteger(Params^[1])^, PInteger(Params^[2])^]; -end; - -(* -TExternalImage.GetAlpha ------------------------ -> function TExternalImage.GetAlpha(X, Y: Integer): Byte; -*) -procedure _LapeExternalImage_GetAlpha(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PByte(Result)^ := PSimbaExternalImage(Params^[0])^.Alpha[PInteger(Params^[1])^, PInteger(Params^[2])^]; -end; - -(* -TExternalImage.SetAlpha ------------------------ -> procedure TExternalImage.SetAlpha(X, Y: Integer; Alpha: Byte); -*) -procedure _LapeExternalImage_SetAlpha(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Alpha[PInteger(Params^[1])^, PInteger(Params^[2])^] := PByte(Params^[3])^; -end; - -(* -TExternalImage.SetPixel ------------------------ -> procedure TExternalImage.SetPixel(X, Y: Integer; Color: TColor); -*) -procedure _LapeExternalImage_SetPixel(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Pixel[PInteger(Params^[1])^, PInteger(Params^[2])^] := PColor(Params^[3])^; -end; - -(* -TExternalImage.SetPixels ------------------------- -> procedure TExternalImage.SetPixels(Points: TPointArray; Color: TColor); -*) -procedure _LapeExternalImage_SetPixels1(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.SetPixels(PPointArray(Params^[1])^, PColor(Params^[2])^); -end; - -(* -TExternalImage.SetPixels ------------------------- -> procedure TExternalImage.SetPixels(Points: TPointArray; Colors: TColorArray); -*) -procedure _LapeExternalImage_SetPixels2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.SetPixels(PPointArray(Params^[1])^, PIntegerArray(Params^[2])^); -end; - -(* -TExternalImage.GetPixels ------------------------- -> function TExternalImage.GetPixels(Points: TPointArray): TColorArray; -*) -procedure _LapeExternalImage_GetPixels(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PColorArray(Result)^ := PSimbaExternalImage(Params^[0])^.GetPixels(PPointArray(Params^[1])^); -end; - -(* -TExternalImage.GetDrawColor ---------------------------- -> function TExternalImage.GetDrawColor: TColor; - -Returns the current drawing color. - -```{note} -Red is the default value. -``` -*) -procedure _LapeExternalImage_DrawColor_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PColor(Result)^ := PSimbaExternalImage(Params^[0])^.DrawColor; -end; - -(* -TExternalImage.SetDrawColor ---------------------------- -> procedure TExternalImage.SetDrawColor(Color: TColor); - -Sets the current draw color. - -```{note} -Red is the default value. -``` -*) -procedure _LapeExternalImage_DrawColor_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawColor := PColor(Params^[1])^; -end; - -(* -TExternalImage.GetDrawAlpha ---------------------------- -> function TExternalImage.GetDrawAlpha: Byte; - -Returns the current draw alpha. -0 is completely transparent and 255 is completely opauge. - -```{note} -255 is the default value. -``` -*) -procedure _LapeExternalImage_DrawAlpha_Read(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PByte(Result)^ := PSimbaExternalImage(Params^[0])^.DrawAlpha; -end; - -(* -TExternalImage.SetDrawAlpha ---------------------------- -> procedure TExternalImage.SetDrawAlpha(Value: Byte); - -Sets the current draw color. This determines how transparent something is drawn. - -```{note} -255 is the default value. -``` -*) -procedure _LapeExternalImage_DrawAlpha_Write(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawAlpha := PByte(Params^[1])^; -end; - -(* -TExternalImage.DrawText -~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.DrawText(Text: String; Position: TPoint); -*) -procedure _LapeExternalImage_DrawText(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawText(PString(Params^[1])^, PPoint(Params^[2])^); -end; - -(* -TExternalImage.DrawText -~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); -*) -procedure _LapeExternalImage_DrawTextEx(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawText(PString(Params^[1])^, PBox(Params^[2])^, EImageTextAlign(Params^[3]^)); -end; - -(* -TExternalImage.DrawTextLines -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -> procedure TExternalImage.DrawTextLines(Text: TStringArray; Position: TPoint); -*) -procedure _LapeExternalImage_DrawTextLines(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawTextLines(PStringArray(Params^[1])^, PPoint(Params^[2])^); -end; - -procedure _LapeExternalImage_Fill(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.Fill(PColor(Params^[1])^); -end; - -procedure _LapeExternalImage_SetMemory(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.SetMemory(PPointer(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^); -end; - -procedure _LapeExternalImage_GetUserData(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV -begin - PPointer(Result)^ := PSimbaExternalImage(Params^[0])^.UserData -end; - -procedure _LapeExternalImage_SetUserData(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.UserData := PPointer(Params^[1])^; -end; - -procedure _LapeExternalImage_DrawCircleAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCircleAA(PPoint(Params^[1])^, PInteger(Params^[2])^, PSingle(Params^[3])^); -end; - -procedure _LapeExternalImage_DrawLineAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawLineAA(PPoint(Params^[1])^, PPoint(Params^[2])^, PSingle(Params^[3])^); -end; - -procedure _LapeExternalImage_DrawEllipseAA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawEllipseAA(PPoint(Params^[1])^, PInteger(Params^[2])^, PInteger(Params^[3])^, PSingle(Params^[4])^); -end; - -procedure _LapeExternalImage_BeginUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.BeginUpdate(); -end; - -procedure _LapeExternalImage_EndUpdate(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.EndUpdate(); -end; - -procedure _LapeExternalImage_DrawImage(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawImage(PSimbaImage(Params^[1])^, PPoint(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawBox(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawBox(PBox(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawBoxFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawBoxFilled(PBox(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawBoxInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawBoxInverted(PBox(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawPolygon(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawPolygon(PPointArray(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawPolygonFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawPolygonFilled(PPointArray(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawPolygonInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawPolygonInverted(PPointArray(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawQuad(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawQuad(PQuad(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawQuadFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawQuadFilled(PQuad(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawQuadInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawQuadInverted(PQuad(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawCircle(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCircle(PPoint(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawCircleFilled(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCircleFilled(PPoint(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawCircleInverted(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCircleInverted(PPoint(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawCrosshairs(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCrosshairs(PPoint(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawCross(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCross(PPoint(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawLine(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawLine(PPoint(Params^[1])^, PPoint(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawLineGap(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawLineGap(PPoint(Params^[1])^, PPoint(Params^[2])^, PInteger(Params^[3])^); -end; - -procedure _LapeExternalImage_FillWithAlpha(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.FillWithAlpha(PByte(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawATPA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawATPA(P2DPointArray(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawTPA(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawTPA(PPointArray(Params^[1])^); -end; - -procedure _LapeExternalImage_DrawQuadArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawQuadArray(PQuadArray(Params^[1])^, PBoolean(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawBoxArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawBoxArray(PBoxArray(Params^[1])^, PBoolean(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawPolygonArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawPolygonArray(P2DPointArray(Params^[1])^, PBoolean(Params^[2])^); -end; - -procedure _LapeExternalImage_DrawCircleArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCircleArray(PPointArray(Params^[1])^, PInteger(Params^[2])^, PBoolean(Params^[3])^); -end; - -procedure _LapeExternalImage_DrawCrossArray(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV -begin - PSimbaExternalImage(Params^[0])^.DrawCrossArray(PPointArray(Params^[1])^, PInteger(Params^[2])^); -end; - -procedure ImportSimbaExternalImage(Compiler: TSimbaScript_Compiler); -begin - with Compiler do - begin - addClass('TExternalImage'); - - addGlobalFunc('function TExternalImage.Create: TExternalImage; static;', @_LapeExternalImage_Create); - addGlobalFunc('procedure TExternalImage.FreeOnTerminate(Value: Boolean);', @_LapeExternalImage_FreeOnTerminate); - - addGlobalFunc('procedure TExternalImage.SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer);', @_LapeExternalImage_SetMemory); - addGlobalFunc('procedure TExternalImage.BeginUpdate', @_LapeExternalImage_BeginUpdate); - addGlobalFunc('procedure TExternalImage.EndUpdate', @_LapeExternalImage_EndUpdate); - - addGlobalFunc('function TExternalImage.Width: Integer;', @_LapeExternalImage_Width); - addGlobalFunc('function TExternalImage.Height: Integer;', @_LapeExternalImage_Height); - - addProperty('TExternalImage', 'UserData', 'Pointer', @_LapeExternalImage_GetUserData, @_LapeExternalImage_SetUserData); - - addProperty('TExternalImage', 'Name', 'String', @_LapeExternalImage_Name_Read, @_LapeExternalImage_Name_Write); - addProperty('TExternalImage', 'DefaultPixel', 'TColorBGRA', @_LapeExternalImage_DefaultPixel_Read, @_LapeExternalImage_DefaultPixel_Write); - addProperty('TExternalImage', 'FontName', 'String', @_LapeExternalImage_FontName_Read, @_LapeExternalImage_FontName_Write); - addProperty('TExternalImage', 'FontSize', 'Single', @_LapeExternalImage_FontSize_Read, @_LapeExternalImage_FontSize_Write); - addProperty('TExternalImage', 'FontAntialiasing', 'Boolean', @_LapeExternalImage_FontAntialiasing_Read, @_LapeExternalImage_FontAntialiasing_Write); - addProperty('TExternalImage', 'FontBold', 'Boolean', @_LapeExternalImage_FontBold_Read, @_LapeExternalImage_FontBold_Write); - addProperty('TExternalImage', 'FontItalic', 'Boolean', @_LapeExternalImage_FontItalic_Read, @_LapeExternalImage_FontItalic_Write); - - addGlobalFunc('function TExternalImage.TextWidth(Text: String): Integer;', @_LapeExternalImage_TextWidth); - addGlobalFunc('function TExternalImage.TextHeight(Text: String): Integer;', @_LapeExternalImage_TextHeight); - addGlobalFunc('function TExternalImage.TextSize(Text: String): TPoint;', @_LapeExternalImage_TextSize); - - addGlobalFunc('function TExternalImage.GetAlpha(X, Y: Integer): Byte;', @_LapeExternalImage_GetAlpha); - addGlobalFunc('procedure TExternalImage.SetAlpha(X, Y: Integer; Alpha: Byte);', @_LapeExternalImage_SetAlpha); - - addGlobalFunc('function TExternalImage.GetPixel(X, Y: Integer): TColor;', @_LapeExternalImage_GetPixel); - addGlobalFunc('procedure TExternalImage.SetPixel(X, Y: Integer; Color: TColor);', @_LapeExternalImage_SetPixel); - - addGlobalFunc('function TExternalImage.GetPixels(Points: TPointArray): TColorArray;', @_LapeExternalImage_GetPixels); - addGlobalFunc('procedure TExternalImage.SetPixels(Points: TPointArray; Color: TColor); overload', @_LapeExternalImage_SetPixels1); - addGlobalFunc('procedure TExternalImage.SetPixels(Points: TPointArray; Colors: TColorArray); overload', @_LapeExternalImage_SetPixels2); - - addProperty('TExternalImage', 'DrawColor', 'TColor', @_LapeExternalImage_DrawColor_Read, @_LapeExternalImage_DrawColor_Write); - addProperty('TExternalImage', 'DrawAlpha', 'Byte', @_LapeExternalImage_DrawAlpha_Read, @_LapeExternalImage_DrawAlpha_Write); - - addGlobalFunc('procedure TExternalImage.DrawText(Text: String; Position: TPoint); overload', @_LapeExternalImage_DrawText); - addGlobalFunc('procedure TExternalImage.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); overload', @_LapeExternalImage_DrawTextEx); - addGlobalFunc('procedure TExternalImage.DrawTextLines(Text: TStringArray; Position: TPoint);', @_LapeExternalImage_DrawTextLines); - - addGlobalFunc('procedure TExternalImage.Fill(Color: TColor)', @_LapeExternalImage_Fill); - addGlobalFunc('procedure TExternalImage.FillWithAlpha(Value: Byte);', @_LapeExternalImage_FillWithAlpha); - - addGlobalFunc('procedure TExternalImage.Clear; overload', @_LapeExternalImage_Clear1); - addGlobalFunc('procedure TExternalImage.Clear(Box: TBox); overload;', @_LapeExternalImage_Clear2); - addGlobalFunc('procedure TExternalImage.ClearInverted(Box: TBox);', @_LapeExternalImage_ClearInverted); - - addGlobalFunc('procedure TExternalImage.DrawATPA(ATPA: T2DPointArray)', @_LapeExternalImage_DrawATPA); - addGlobalFunc('procedure TExternalImage.DrawTPA(TPA: TPointArray)', @_LapeExternalImage_DrawTPA); - - addGlobalFunc('procedure TExternalImage.DrawImage(Image: TImage; Position: TPoint);', @_LapeExternalImage_DrawImage); - - addGlobalFunc('procedure TExternalImage.DrawBox(B: TBox);', @_LapeExternalImage_DrawBox); - addGlobalFunc('procedure TExternalImage.DrawBoxFilled(B: TBox);', @_LapeExternalImage_DrawBoxFilled); - addGlobalFunc('procedure TExternalImage.DrawBoxInverted(B: TBox);', @_LapeExternalImage_DrawBoxInverted); - - addGlobalFunc('procedure TExternalImage.DrawPolygon(Points: TPointArray);', @_LapeExternalImage_DrawPolygon); - addGlobalFunc('procedure TExternalImage.DrawPolygonFilled(Points: TPointArray);', @_LapeExternalImage_DrawPolygonFilled); - addGlobalFunc('procedure TExternalImage.DrawPolygonInverted(Points: TPointArray);', @_LapeExternalImage_DrawPolygonInverted); - - addGlobalFunc('procedure TExternalImage.DrawQuad(Quad: TQuad);', @_LapeExternalImage_DrawQuad); - addGlobalFunc('procedure TExternalImage.DrawQuadFilled(Quad: TQuad);', @_LapeExternalImage_DrawQuadFilled); - addGlobalFunc('procedure TExternalImage.DrawQuadInverted(Quad: TQuad);', @_LapeExternalImage_DrawQuadInverted); - - addGlobalFunc('procedure TExternalImage.DrawCircle(Center: TPoint; Radius: Integer)', @_LapeExternalImage_DrawCircle); - addGlobalFunc('procedure TExternalImage.DrawCircleFilled(Center: TPoint; Radius: Integer)', @_LapeExternalImage_DrawCircleFilled); - addGlobalFunc('procedure TExternalImage.DrawCircleInverted(Center: TPoint; Radius: Integer)', @_LapeExternalImage_DrawCircleInverted); - - addGlobalFunc('procedure TExternalImage.DrawCrosshairs(ACenter: TPoint; Size: Integer);', @_LapeExternalImage_DrawCrosshairs); - addGlobalFunc('procedure TExternalImage.DrawCross(ACenter: TPoint; Radius: Integer);', @_LapeExternalImage_DrawCross); - - addGlobalFunc('procedure TExternalImage.DrawLine(Start, Stop: TPoint);', @_LapeExternalImage_DrawLine); - addGlobalFunc('procedure TExternalImage.DrawLineGap(Start, Stop: TPoint; GapSize: Integer);', @_LapeExternalImage_DrawLineGap); - - addGlobalFunc('procedure TExternalImage.DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single = 1.5)', @_LapeExternalImage_DrawCircleAA); - addGlobalFunc('procedure TExternalImage.DrawLineAA(Start, Stop: TPoint; Thickness: Single = 1.5)', @_LapeExternalImage_DrawLineAA); - addGlobalFunc('procedure TExternalImage.DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single = 1.5)', @_LapeExternalImage_DrawEllipseAA); - - addGlobalFunc('procedure TExternalImage.DrawQuadArray(Quads: TQuadArray; Filled: Boolean);', @_LapeExternalImage_DrawQuadArray); - addGlobalFunc('procedure TExternalImage.DrawBoxArray(Boxes: TBoxArray; Filled: Boolean);', @_LapeExternalImage_DrawBoxArray); - addGlobalFunc('procedure TExternalImage.DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean);', @_LapeExternalImage_DrawPolygonArray); - addGlobalFunc('procedure TExternalImage.DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean);', @_LapeExternalImage_DrawCircleArray); - addGlobalFunc('procedure TExternalImage.DrawCrossArray(Points: TPointArray; Radius: Integer);', @_LapeExternalImage_DrawCrossArray); - end; -end; - -end. - diff --git a/Source/script/imports/simba.import_target.pas b/Source/script/imports/simba.import_target.pas index f896c4238..391cd54e4 100644 --- a/Source/script/imports/simba.import_target.pas +++ b/Source/script/imports/simba.import_target.pas @@ -16,7 +16,7 @@ implementation TypInfo, lptypes, lpvartypes, ffi, simba.colormath, simba.dtm, simba.misc, - simba.image, simba.target, simba.externalimage, simba.finder_image, simba.finder_color; + simba.image, simba.target, simba.externalcanvas, simba.finder_image, simba.finder_color; type PMouseButton = ^EMouseButton; @@ -107,14 +107,14 @@ procedure _LapeTarget_SetPlugin1(const Params: PParamArray); LAPE_WRAPPER_CALLIN TTarget.SetPlugin ----------------- ``` -procedure TTarget.SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalImage); +procedure TTarget.SetPlugin(FileName, Args: String; out DebugImage: TExternalCanvas); ``` -Overloaded version that returns a external image to draw on. +Overloaded version that returns a "external canvas" to draw on. *) procedure _LapeTarget_SetPlugin2(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV begin - PSimbaTarget(Params^[0])^.SetPlugin(PString(Params^[1])^, PString(Params^[2])^, PSimbaExternalImage(Params^[3])^); + PSimbaTarget(Params^[0])^.SetPlugin(PString(Params^[1])^, PString(Params^[2])^, TSimbaExternalCanvas(Params^[3]^)); end; (* @@ -1160,7 +1160,7 @@ procedure ImportTarget(Compiler: TSimbaScript_Compiler); addGlobalFunc('procedure TTarget.SetWindow(Window: TWindowHandle)', @_LapeTarget_SetWindow); addGlobalFunc('procedure TTarget.SetEIOS(Plugin, Args: String)', @_LapeTarget_SetEIOS); addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String); overload', @_LapeTarget_SetPlugin1); - addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String; out DebugImage: TExternalImage); overload', @_LapeTarget_SetPlugin2); + addGlobalFunc('procedure TTarget.SetPlugin(Plugin, Args: String; out DebugImage: TExternalCanvas); overload', @_LapeTarget_SetPlugin2); addGlobalFunc('function TTarget.AddTargetChangeEvent(Event: TTargetEvent): TTargetEvent', @_Lape_Target_AddTargetChangeEvent); addGlobalFunc('function TTarget.AddTargetInvalidEvent(Event: TTargetEvent): TTargetEvent', @_Lape_Target_AddTargetInvalidEvent); @@ -1307,4 +1307,4 @@ procedure ImportTarget(Compiler: TSimbaScript_Compiler); end; end; -end. \ No newline at end of file +end. diff --git a/Source/script/simba.script_imports.pas b/Source/script/simba.script_imports.pas index cabdcb235..a22ac7d09 100644 --- a/Source/script/simba.script_imports.pas +++ b/Source/script/simba.script_imports.pas @@ -27,7 +27,7 @@ implementation simba.import_pointbuffer, simba.import_async, // Simba classes - simba.import_image, simba.import_externalimage, simba.import_dtm, simba.import_matchtemplate, + simba.import_image, simba.import_externalcanvas, simba.import_dtm, simba.import_matchtemplate, simba.import_json, simba.import_imagebox, simba.import_shapebox, // LCL @@ -58,7 +58,7 @@ procedure AddSimbaImports(Compiler: TSimbaScript_Compiler); ImportDTM(Compiler); ImportSimbaImage(Compiler); - ImportSimbaExternalImage(Compiler); + ImportExternalCanvas(Compiler); ImportMatchTemplate(Compiler); ImportJSON(Compiler); diff --git a/Source/script/simba.script_pluginmethods.pas b/Source/script/simba.script_pluginmethods.pas index 02277e905..eacb9f48d 100644 --- a/Source/script/simba.script_pluginmethods.pas +++ b/Source/script/simba.script_pluginmethods.pas @@ -13,7 +13,7 @@ interface uses Classes, SysUtils, - simba.base, simba.externalimage, + simba.base, simba.externalcanvas, lpcompiler; type @@ -270,35 +270,35 @@ function Plugin_GetArrayLength(Arr: Pointer): NativeInt; cdecl; function Plugin_ExternalImage_Create(AutoResize: Boolean): Pointer; cdecl; begin - Result := TSimbaExternalImage.Create(); + Result := TSimbaExternalCanvas.Create(); - TSimbaExternalImage(Result).FreeOnTerminate := True; - TSimbaExternalImage(Result).AutoResize := AutoResize; + TSimbaExternalCanvas(Result).AutoResize := AutoResize; + TSimbaExternalCanvas(Result).FreeOnTerminate := True; end; procedure Plugin_ExternalImage_SetMemory(Img: Pointer; Data: PColorBGRA; AWidth, AHeight: Integer); cdecl; begin - TSimbaExternalImage(Img).SetMemory(Data, AWidth, AHeight); + TSimbaExternalCanvas(Img).SetMemory(Data, AWidth, AHeight); end; procedure Plugin_ExternalImage_Resize(Img: Pointer; NewWidth, NewHeight: Integer); cdecl; begin - TSimbaExternalImage(Img).Resize(NewWidth, NewHeight); + TSimbaExternalCanvas(Img).Resize(NewWidth, NewHeight); end; procedure Plugin_ExternalImage_SetUserData(Img: Pointer; UserData: Pointer); cdecl; begin - TSimbaExternalImage(Img).UserData := UserData; + TSimbaExternalCanvas(Img).UserData := UserData; end; function Plugin_ExternalImage_GetUserData(Img: Pointer): Pointer; cdecl; begin - Result := TSimbaExternalImage(Img).UserData; + Result := TSimbaExternalCanvas(Img).UserData; end; procedure Plugin_ExternalImage_SetName(Img: Pointer; Name: PChar); cdecl; begin - TSimbaExternalImage(Img).Name := Name; + TSimbaExternalCanvas(Img).Name := Name; end; initialization diff --git a/Source/simba.baseclass.pas b/Source/simba.baseclass.pas index 7bc8111a7..4871e7a5d 100644 --- a/Source/simba.baseclass.pas +++ b/Source/simba.baseclass.pas @@ -62,19 +62,22 @@ implementation procedure PrintUnfreedObjects; var NeedHeader: Boolean = True; - I: Integer; begin TrackedObjects.Lock(); try - for I := 0 to TrackedObjects.Count - 1 do - if not TrackedObjects[I].FreeOnTerminate then + while (TrackedObjects.Count > 0) do + begin + if not TrackedObjects.First.FreeOnTerminate then begin if NeedHeader then DebugLn([EDebugLn.YELLOW], 'The following objects were not freed:'); NeedHeader := False; - TrackedObjects[I].NotifyUnfreed(); + TrackedObjects.First.NotifyUnfreed(); end; + + TrackedObjects.First.Free(); + end; finally TrackedObjects.Unlock(); end; @@ -104,19 +107,25 @@ procedure PrintUnfinishedThreads; procedure PrintUnfreedThreads; var NeedHeader: Boolean = True; - I: Integer; begin TrackedThreads.Lock(); try - for I := 0 to TrackedThreads.Count - 1 do - if TrackedThreads[I].Finished and (not TrackedThreads[I].FreeOnTerminate) then + while (TrackedThreads.Count > 0) do + begin + if TrackedThreads.First.Finished and (not TrackedThreads.First.FreeOnTerminate) then begin if NeedHeader then DebugLn([EDebugLn.YELLOW], 'The following threads were not freed:'); NeedHeader := False; - TrackedThreads[I].NotifyUnfreed(); + TrackedThreads.First.NotifyUnfreed(); end; + + if TrackedThreads.First.FreeOnTerminate then + TrackedThreads.Delete(TrackedThreads.First) + else + TrackedThreads.First.Free(); + end; finally TrackedThreads.Unlock(); end; @@ -179,40 +188,13 @@ destructor TSimbaBaseThread.Destroy; TrackedThreads.Delete(Self); end; -procedure FreeObjects; -var - List: TTrackedObjects; - Thread: TSimbaBaseThread; - I: Integer; -begin - List := TrackedObjects; - TrackedObjects := nil; - for I := 0 to List.Count - 1 do - List[I].Free(); -end; - -procedure FreeThreads; -var - List: TTrackedThreads; - Thread: TSimbaBaseThread; - I: Integer; -begin - List := TrackedThreads; - TrackedThreads := nil; - for I := 0 to List.Count - 1 do - if List[I].FreeOnTerminate then - List[I].Terminate() - else - List[I].Free(); -end; - initialization TrackedObjects := TTrackedObjects.Create(); TrackedThreads := TTrackedThreads.Create(); finalization - FreeObjects(); - FreeThreads(); + while (TrackedObjects.Count > 0) do + TrackedObjects.First.Free(); end. diff --git a/Source/simba.externalimage.pas b/Source/simba.externalimage.pas deleted file mode 100644 index 2d6b95fe0..000000000 --- a/Source/simba.externalimage.pas +++ /dev/null @@ -1,684 +0,0 @@ -{ - 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) - -------------------------------------------------------------------------- - - Provides a way to draw on an image which data is externally allocated. -} -unit simba.externalimage; - -{$i simba.inc} - -interface - -uses - Classes, SysUtils, Graphics, - simba.base, simba.baseclass, simba.image, simba.image_utils, simba.image_textdrawer, - simba.threading; - -type - PSimbaExternalImage = ^TSimbaExternalImage; - TSimbaExternalImage = class(TSimbaBaseClass) - protected - FLock: TEnterableLock; - - FBackBuffer: TSimbaImage; - - FData: PColorBGRA; - FWidth, FHeight: Integer; - FUserData: Pointer; - FInUpdate: Integer; - - FDirty: Boolean; - FDirtyBox: TBox; - - FAutoResize: Boolean; - - procedure CheckInUpdate; inline; - - procedure addDirty(b: TBox); inline; - procedure addAllDirty; inline; - - procedure Flush; - - function GetFontAntialiasing: Boolean; - function GetFontBold: Boolean; - function GetFontItalic: Boolean; - function GetFontName: String; - function GetFontSize: Single; - function GetUserData: Pointer; - function GetPixel(const X, Y: Integer): TColor; - function GetAlpha(const X, Y: Integer): Byte; - function GetDefaultPixel: TColorBGRA; - function GetDrawAlpha: Byte; - function GetDrawColor: TColor; - - procedure SetUserData(UserData: Pointer); - procedure SetFontAntialiasing(Value: Boolean); - procedure SetFontBold(Value: Boolean); - procedure SetFontItalic(Value: Boolean); - procedure SetFontName(Value: String); - procedure SetFontSize(Value: Single); - procedure SetPixel(const X, Y: Integer; const Color: TColor); - procedure SetAlpha(const X, Y: Integer; const Value: Byte); - procedure SetDefaultPixel(AValue: TColorBGRA); - procedure SetDrawAlpha(const AValue: Byte); - procedure SetDrawColor(const AValue: TColor); - public - constructor Create; reintroduce; - destructor Destroy; override; - - procedure BeginUpdate; - procedure EndUpdate; - - property DefaultPixel: TColorBGRA read GetDefaultPixel write SetDefaultPixel; - property Width: Integer read FWidth; - property Height: Integer read FHeight; - property UserData: Pointer read GetUserData write SetUserData; - property AutoResize: Boolean read FAutoResize write FAutoResize; - - property Pixel[X, Y: Integer]: TColor read GetPixel write SetPixel; default; - property Alpha[X, Y: Integer]: Byte read GetAlpha write SetAlpha; - - function GetPixels(Points: TPointArray): TColorArray; - procedure SetPixels(Points: TPointArray; Color: TColor); overload; - procedure SetPixels(Points: TPointArray; Colors: TColorArray); overload; - - property DrawColor: TColor read GetDrawColor write SetDrawColor; - property DrawAlpha: Byte read GetDrawAlpha write SetDrawAlpha; - - property FontName: String read GetFontName write SetFontName; - property FontSize: Single read GetFontSize write SetFontSize; - property FontAntialiasing: Boolean read GetFontAntialiasing write SetFontAntialiasing; - property FontBold: Boolean read GetFontBold write SetFontBold; - property FontItalic: Boolean read GetFontItalic write SetFontItalic; - - procedure SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer); - procedure Resize(NewWidth, NewHeight: Integer); - - procedure Fill(Color: TColor); - procedure FillWithAlpha(Value: Byte); - - procedure Clear; overload; - procedure Clear(Box: TBox); overload; - procedure ClearInverted(Box: TBox); - - function TextWidth(Text: String): Integer; - function TextHeight(Text: String): Integer; - function TextSize(Text: String): TPoint; - - procedure DrawText(Text: String; Position: TPoint); overload; - procedure DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); overload; - procedure DrawTextLines(Text: TStringArray; Position: TPoint); - - // Image - procedure DrawImage(Image: TSimbaImage; Location: TPoint); - - // Point - procedure DrawATPA(ATPA: T2DPointArray); - procedure DrawTPA(TPA: TPointArray); - - // Line - procedure DrawCrosshairs(ACenter: TPoint; Size: Integer); - procedure DrawCross(ACenter: TPoint; Radius: Integer); - procedure DrawLine(Start, Stop: TPoint); - procedure DrawLineGap(Start, Stop: TPoint; GapSize: Integer); - - // Box - procedure DrawBox(Box: TBox); - procedure DrawBoxFilled(Box: TBox); - procedure DrawBoxInverted(Box: TBox); - - // Poly - procedure DrawPolygon(Points: TPointArray); - procedure DrawPolygonFilled(Points: TPointArray); - procedure DrawPolygonInverted(Points: TPointArray); - - // Quad - procedure DrawQuad(Quad: TQuad); - procedure DrawQuadFilled(Quad: TQuad); - procedure DrawQuadInverted(Quad: TQuad); - - // Circle - procedure DrawCircle(ACenter: TPoint; Radius: Integer); - procedure DrawCircleFilled(ACenter: TPoint; Radius: Integer); - procedure DrawCircleInverted(ACenter: TPoint; Radius: Integer); - - // Antialiased - procedure DrawLineAA(Start, Stop: TPoint; Thickness: Single = 1.5); - procedure DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single = 1.5); - procedure DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single = 1.5); - - // Arrays - procedure DrawQuadArray(Quads: TQuadArray; Filled: Boolean); - procedure DrawBoxArray(Boxes: TBoxArray; Filled: Boolean); - procedure DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean); - procedure DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean); - procedure DrawCrossArray(Points: TPointArray; Radius: Integer); - end; - -implementation - -uses - Math, - simba.vartype_box, simba.vartype_quad, simba.vartype_pointarray, simba.vartype_boxarray; - -function TSimbaExternalImage.GetPixel(const X, Y: Integer): TColor; -begin - Result := FBackBuffer.Pixel[X, Y]; -end; - -function TSimbaExternalImage.GetAlpha(const X, Y: Integer): Byte; -begin - Result := FBackBuffer.Alpha[X, Y]; -end; - -function TSimbaExternalImage.GetDrawAlpha: Byte; -begin - Result := FBackBuffer.DrawAlpha; -end; - -function TSimbaExternalImage.GetDrawColor: TColor; -begin - Result := FBackBuffer.DrawColor; -end; - -procedure TSimbaExternalImage.SetPixel(const X, Y: Integer; const Color: TColor); -begin - FBackBuffer.Pixel[X, Y] := Color; -end; - -procedure TSimbaExternalImage.SetAlpha(const X, Y: Integer; const Value: Byte); -begin - FBackBuffer.Alpha[X, Y] := Value; -end; - -procedure TSimbaExternalImage.SetDrawAlpha(const AValue: Byte); -begin - FBackBuffer.DrawAlpha := AValue; -end; - -procedure TSimbaExternalImage.SetDrawColor(const AValue: TColor); -begin - FBackBuffer.DrawColor := AValue; -end; - -function TSimbaExternalImage.GetDefaultPixel: TColorBGRA; -begin - Result := FBackBuffer.DefaultPixel; -end; - -procedure TSimbaExternalImage.SetDefaultPixel(AValue: TColorBGRA); -begin - FBackBuffer.DefaultPixel := AValue; -end; - -procedure TSimbaExternalImage.CheckInUpdate; -begin - if (FInUpdate <= 0) then - SimbaException('Not in BeginUpdate/EndUpdate'); -end; - -procedure TSimbaExternalImage.addDirty(b: TBox); -begin - if (FInUpdate <= 0) then - SimbaException('Not in BeginUpdate/EndUpdate'); - - if FDirty then - FDirtyBox := FDirtyBox.Combine(b.Normalize()) - else - begin - FDirty := True; - FDirtyBox := b.Normalize(); - end; -end; - -procedure TSimbaExternalImage.addAllDirty; -begin - if (FInUpdate <= 0) then - SimbaException('Not in BeginUpdate/EndUpdate'); - - FDirty := True; - FDirtyBox.X1 := -$FFFFFF; - FDirtyBox.Y1 := -$FFFFFF; - FDirtyBox.X2 := $FFFFFF; - FDirtyBox.Y2 := $FFFFFF; -end; - -procedure TSimbaExternalImage.Flush; -var - Y: Integer; -begin - if not FDirty then - Exit; - - FDirty := False; - FDirtyBox := FDirtyBox.Expand(1).Clip(TBox.Create(0, 0, FWidth-1, FHeight-1)); - - for Y := FDirtyBox.Y1 to FDirtyBox.Y2 do - Move(FBackBuffer.Data[Y * FWidth + FDirtyBox.X1], FData[Y * FWidth + FDirtyBox.X1], (FDirtyBox.X2 - FDirtyBox.X1) * SizeOf(TColorBGRA)); -end; - -function TSimbaExternalImage.GetFontAntialiasing: Boolean; -begin - Result := FBackBuffer.FontAntialiasing; -end; - -function TSimbaExternalImage.GetFontBold: Boolean; -begin - Result := FBackBuffer.FontBold; -end; - -function TSimbaExternalImage.GetFontItalic: Boolean; -begin - Result := FBackBuffer.FontItalic; -end; - -function TSimbaExternalImage.GetFontName: String; -begin - Result := FBackBuffer.FontName; -end; - -function TSimbaExternalImage.GetFontSize: Single; -begin - Result := FBackBuffer.FontSize; -end; - -procedure TSimbaExternalImage.SetFontAntialiasing(Value: Boolean); -begin - FBackBuffer.FontAntialiasing := Value; -end; - -procedure TSimbaExternalImage.SetFontBold(Value: Boolean); -begin - FBackBuffer.FontBold := Value; -end; - -procedure TSimbaExternalImage.SetFontItalic(Value: Boolean); -begin - FBackBuffer.FontItalic := Value; -end; - -procedure TSimbaExternalImage.SetFontName(Value: String); -begin - FBackBuffer.FontName := Value; -end; - -procedure TSimbaExternalImage.SetFontSize(Value: Single); -begin - FBackBuffer.FontSize := Value; -end; - -constructor TSimbaExternalImage.Create; -begin - inherited Create(); - - FBackBuffer := TSimbaImage.Create(); - FBackBuffer.DefaultPixel.A := ALPHA_TRANSPARENT; -end; - -destructor TSimbaExternalImage.Destroy; -begin - if Assigned(FBackBuffer) then - FreeAndNil(FBackBuffer); - - inherited Destroy(); -end; - -procedure TSimbaExternalImage.BeginUpdate; -begin - FLock.Enter(); - - Inc(FInUpdate); - if (FInUpdate > 1) then - Exit; - - FDirty := False; -end; - -procedure TSimbaExternalImage.EndUpdate; -begin - if (FInUpdate <= 0) then - SimbaException('Not in BeginUpdate'); - - Dec(FInUpdate); - if (FInUpdate > 0) then - Exit; - - Flush(); - - FLock.Leave(); -end; - -function TSimbaExternalImage.GetPixels(Points: TPointArray): TColorArray; -begin - Result := FBackBuffer.GetPixels(Points); -end; - -procedure TSimbaExternalImage.SetPixels(Points: TPointArray; Color: TColor); -begin - FBackBuffer.SetPixels(Points, Color); -end; - -procedure TSimbaExternalImage.SetPixels(Points: TPointArray; Colors: TColorArray); -begin - FBackBuffer.SetPixels(Points, Colors); -end; - -procedure TSimbaExternalImage.SetMemory(Data: PColorBGRA; AWidth, AHeight: Integer); -begin - BeginUpdate(); - try - FData := Data; - FWidth := AWidth; - FHeight := AHeight; - - FBackBuffer.SetSize(AWidth, AHeight); - finally - EndUpdate(); - end; -end; - -procedure TSimbaExternalImage.Resize(NewWidth, NewHeight: Integer); -var - Y: Integer; -begin - if (FWidth = NewWidth) and (FHeight = NewHeight) then - Exit; - - BeginUpdate(); - try - FWidth := NewWidth; - FHeight := NewHeight; - - FBackBuffer.SetSize(FWidth, FHeight); - for Y := 0 to FHeight - 1 do - Move(FBackBuffer.Data[Y * FWidth], FData[Y * FWidth], FWidth * SizeOf(TColorBGRA)); - finally - EndUpdate(); - end; -end; - -procedure TSimbaExternalImage.FillWithAlpha(Value: Byte); -begin - addAllDirty(); - - FBackBuffer.FillWithAlpha(Value); -end; - -procedure TSimbaExternalImage.DrawATPA(ATPA: T2DPointArray); -begin - addDirty(ATPA.Bounds()); - - FBackBuffer.DrawATPA(ATPA); -end; - -procedure TSimbaExternalImage.DrawTPA(TPA: TPointArray); -begin - addDirty(TPA.Bounds()); - - FBackBuffer.DrawTPA(TPA); -end; - -procedure TSimbaExternalImage.DrawCrosshairs(ACenter: TPoint; Size: Integer); -begin - addDirty(TBox.Create(ACenter, Size, Size)); - - FBackBuffer.DrawCrosshairs(ACenter, Size); -end; - -procedure TSimbaExternalImage.DrawCross(ACenter: TPoint; Radius: Integer); -begin - addDirty(TBox.Create(ACenter, Radius, Radius)); - - FBackBuffer.DrawCross(ACenter, Radius); -end; - -procedure TSimbaExternalImage.DrawLine(Start, Stop: TPoint); -begin - addDirty(TBox.Create(Start.X, Start.Y, Stop.X, Stop.Y)); - - FBackBuffer.DrawLine(Start, Stop); -end; - -procedure TSimbaExternalImage.DrawLineGap(Start, Stop: TPoint; GapSize: Integer); -begin - addDirty(TBox.Create(Start.X, Start.Y, Stop.X, Stop.Y)); - - FBackBuffer.DrawLineGap(Start, Stop, GapSize); -end; - -procedure TSimbaExternalImage.Clear; -begin - addAllDirty(); - - FBackBuffer.Clear(); -end; - -procedure TSimbaExternalImage.Clear(Box: TBox); -begin - addDirty(Box); - - FBackBuffer.Clear(Box); -end; - -procedure TSimbaExternalImage.ClearInverted(Box: TBox); -begin - addAllDirty(); - - FBackBuffer.ClearInverted(Box); -end; - -procedure TSimbaExternalImage.Fill(Color: TColor); -begin - addAllDirty(); - - FBackBuffer.Fill(Color); -end; - -procedure TSimbaExternalImage.SetUserData(UserData: Pointer); -begin - FUserData := UserData; -end; - -function TSimbaExternalImage.GetUserData: Pointer; -begin - Result := FUserData; -end; - -function TSimbaExternalImage.TextWidth(Text: String): Integer; -begin - Result := FBackBuffer.TextWidth(Text); -end; - -function TSimbaExternalImage.TextHeight(Text: String): Integer; -begin - Result := FBackBuffer.TextHeight(Text); -end; - -function TSimbaExternalImage.TextSize(Text: String): TPoint; -begin - Result := FBackBuffer.TextSize(Text); -end; - -type - TSimbaImageProtected = class(TSimbaImage); - -procedure TSimbaExternalImage.DrawText(Text: String; Position: TPoint); -begin - CheckInUpdate(); - - FBackBuffer.DrawText(Text, Position); - addDirty(TSimbaImageProtected(FBackBuffer).FTextDrawer.DrawnBox); -end; - -procedure TSimbaExternalImage.DrawText(Text: String; Box: TBox; Alignments: EImageTextAlign); -begin - CheckInUpdate(); - - FBackBuffer.DrawText(Text, Box, Alignments); - addDirty(TSimbaImageProtected(FBackBuffer).FTextDrawer.DrawnBox); -end; - -procedure TSimbaExternalImage.DrawTextLines(Text: TStringArray; Position: TPoint); -begin - CheckInUpdate(); - - FBackBuffer.DrawTextLines(Text, Position); - addDirty(TSimbaImageProtected(FBackBuffer).FTextDrawer.DrawnBox); -end; - -procedure TSimbaExternalImage.DrawImage(Image: TSimbaImage; Location: TPoint); -begin - addDirty(TBox.Create(Location.X, Location.Y, Location.X + Image.Width, Location.Y + Image.Height)); - - FBackBuffer.DrawImage(Image, Location); -end; - -procedure TSimbaExternalImage.DrawBox(Box: TBox); -begin - addDirty(Box); - - FBackBuffer.DrawBox(Box); -end; - -procedure TSimbaExternalImage.DrawBoxFilled(Box: TBox); -begin - addDirty(Box); - - FBackBuffer.DrawBoxFilled(Box); -end; - -procedure TSimbaExternalImage.DrawBoxInverted(Box: TBox); -begin - addAllDirty(); - - FBackBuffer.DrawBoxInverted(Box); -end; - -procedure TSimbaExternalImage.DrawPolygon(Points: TPointArray); -begin - addDirty(Points.Bounds); - - FBackBuffer.DrawPolygon(Points); -end; - -procedure TSimbaExternalImage.DrawPolygonFilled(Points: TPointArray); -begin - addDirty(Points.Bounds); - - FBackBuffer.DrawPolygonFilled(Points); -end; - -procedure TSimbaExternalImage.DrawPolygonInverted(Points: TPointArray); -begin - addAllDirty(); - - FBackBuffer.DrawPolygonInverted(Points); -end; - -procedure TSimbaExternalImage.DrawQuad(Quad: TQuad); -begin - addDirty(Quad.Bounds); - - FBackBuffer.DrawQuad(Quad); -end; - -procedure TSimbaExternalImage.DrawQuadFilled(Quad: TQuad); -begin - addDirty(Quad.Bounds); - - FBackBuffer.DrawQuadFilled(Quad); -end; - -procedure TSimbaExternalImage.DrawQuadInverted(Quad: TQuad); -begin - addAllDirty(); - - FBackBuffer.DrawQuadInverted(Quad); -end; - -procedure TSimbaExternalImage.DrawCircle(ACenter: TPoint; Radius: Integer); -begin - addDirty(TBox.Create(ACenter, Radius, Radius)); - - FBackBuffer.DrawCircle(ACenter, Radius); -end; - -procedure TSimbaExternalImage.DrawCircleFilled(ACenter: TPoint; Radius: Integer); -begin - addDirty(TBox.Create(ACenter, Radius, Radius)); - - FBackBuffer.DrawCircleFilled(ACenter, Radius); -end; - -procedure TSimbaExternalImage.DrawCircleInverted(ACenter: TPoint; Radius: Integer); -begin - addAllDirty(); - - FBackBuffer.DrawCircleInverted(ACenter, Radius); -end; - -procedure TSimbaExternalImage.DrawLineAA(Start, Stop: TPoint; Thickness: Single); -begin - addDirty(TBox.Create(Ceil(Start.X - Thickness), Ceil(Start.Y - Thickness), Ceil(Stop.X - Thickness), Ceil(Stop.Y - Thickness))); - addDirty(TBox.Create(Ceil(Start.X + Thickness), Ceil(Start.Y + Thickness), Ceil(Stop.X + Thickness), Ceil(Stop.Y + Thickness))); - - FBackBuffer.DrawLineAA(Start, Stop, Thickness); -end; - -procedure TSimbaExternalImage.DrawEllipseAA(ACenter: TPoint; XRadius, YRadius: Integer; Thickness: Single); -begin - addDirty(TBox.Create(ACenter, Ceil(XRadius + Thickness), Ceil(YRadius + Thickness))); - - FBackBuffer.DrawEllipseAA(ACenter, XRadius, YRadius, Thickness); -end; - -procedure TSimbaExternalImage.DrawCircleAA(ACenter: TPoint; Radius: Integer; Thickness: Single); -begin - addDirty(TBox.Create(ACenter, Ceil(Radius + Thickness), Ceil(Radius + Thickness))); - - FBackBuffer.DrawCircleAA(ACenter, Radius, Thickness); -end; - -procedure TSimbaExternalImage.DrawQuadArray(Quads: TQuadArray; Filled: Boolean); -var - I: Integer; -begin - for I := 0 to High(Quads) do - addDirty(Quads[I].Bounds); - - FBackBuffer.DrawQuadArray(Quads, Filled); -end; - -procedure TSimbaExternalImage.DrawBoxArray(Boxes: TBoxArray; Filled: Boolean); -begin - addDirty(Boxes.Merge()); - - FBackBuffer.DrawBoxArray(Boxes, Filled); -end; - -procedure TSimbaExternalImage.DrawPolygonArray(Polygons: T2DPointArray; Filled: Boolean); -begin - addDirty(Polygons.Bounds()); - - FBackBuffer.DrawPolygonArray(Polygons, Filled); -end; - -procedure TSimbaExternalImage.DrawCircleArray(Centers: TPointArray; Radius: Integer; Filled: Boolean); -begin - addDirty(Centers.Bounds().Expand(Radius)); - - FBackBuffer.DrawCircleArray(Centers, Radius, Filled); -end; - -procedure TSimbaExternalImage.DrawCrossArray(Points: TPointArray; Radius: Integer); -begin - addDirty(Points.Bounds().Expand(Radius)); - - FBackBuffer.DrawCrossArray(Points, Radius); -end; - -end. - diff --git a/Source/simba.target.pas b/Source/simba.target.pas index d709109c8..ffe676cb7 100644 --- a/Source/simba.target.pas +++ b/Source/simba.target.pas @@ -11,7 +11,7 @@ interface uses Classes, SysUtils, - simba.base, simba.image, simba.image_utils, simba.externalimage, + simba.base, simba.image, simba.image_utils, simba.externalcanvas, simba.target_eios, simba.target_window, simba.target_image, simba.target_plugin, simba.colormath, simba.dtm; @@ -131,7 +131,7 @@ TSimbaTarget = record procedure SetImage(Image: TSimbaImage); procedure SetEIOS(FileName, Args: String); procedure SetPlugin(FileName, Args: String); overload; - procedure SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalImage); overload; + procedure SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalCanvas); overload; function AddTargetChangeEvent(Event: TTargetEvent): TTargetEvent; function AddTargetInvalidEvent(Event: TTargetEvent): TTargetEvent; @@ -1035,7 +1035,7 @@ procedure TSimbaTarget.SetPlugin(FileName, Args: String); TargetChanged(); end; -procedure TSimbaTarget.SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalImage); +procedure TSimbaTarget.SetPlugin(FileName, Args: String; out DebugImage: TSimbaExternalCanvas); begin ChangeTarget(ESimbaTargetKind.PLUGIN); diff --git a/Source/simba.target_plugin.pas b/Source/simba.target_plugin.pas index 325e8ff4b..aa3527324 100644 --- a/Source/simba.target_plugin.pas +++ b/Source/simba.target_plugin.pas @@ -13,7 +13,7 @@ interface uses Classes, SysUtils, DynLibs, - simba.base, simba.externalimage; + simba.base, simba.externalcanvas; type PSimbaPluginTarget = ^TSimbaPluginTarget; @@ -24,7 +24,7 @@ TSimbaPluginTarget = record DebugImageThread: TThread; Request: function(Args: PChar): Pointer; cdecl; - RequestWithDebugImage: function(Args: PChar; out DebugImage: TSimbaExternalImage): Pointer; cdecl; + RequestWithDebugImage: function(Args: PChar; out DebugImage: TSimbaExternalCanvas): Pointer; cdecl; Release: procedure(Target: Pointer); cdecl; GetDimensions: procedure(Target: Pointer; out W, H: Int32); cdecl; @@ -44,7 +44,7 @@ TSimbaPluginTarget = record end; function LoadPluginTarget(FileName, Args: String): TSimbaPluginTarget; overload; -function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternalImage): TSimbaPluginTarget; overload; +function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternalCanvas): TSimbaPluginTarget; overload; procedure PluginTarget_GetDimensions(Target: Pointer; out W, H: Integer); function PluginTarget_GetImageData(Target: Pointer; X, Y, Width, Height: Integer; var Data: PColorBGRA; var DataWidth: Integer): Boolean; @@ -72,11 +72,11 @@ implementation TUpdateDebugImageThread = class(TThread) protected FTarget: TSimbaPluginTarget; - FImg: TSimbaExternalImage; + FImg: TSimbaExternalCanvas; procedure Execute; override; public - constructor Create(Target: TSimbaPluginTarget; Img: TSimbaExternalImage); reintroduce; + constructor Create(Target: TSimbaPluginTarget; Img: TSimbaExternalCanvas); reintroduce; end; procedure TUpdateDebugImageThread.Execute; @@ -102,7 +102,7 @@ procedure TUpdateDebugImageThread.Execute; end; end; -constructor TUpdateDebugImageThread.Create(Target: TSimbaPluginTarget; Img: TSimbaExternalImage); +constructor TUpdateDebugImageThread.Create(Target: TSimbaPluginTarget; Img: TSimbaExternalCanvas); begin inherited Create(False, 512*512); @@ -163,7 +163,7 @@ function LoadPluginTarget(FileName, Args: String): TSimbaPluginTarget; end; end; -function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternalImage): TSimbaPluginTarget; +function LoadPluginTarget(FileName, Args: String; out DebugImage: TSimbaExternalCanvas): TSimbaPluginTarget; begin Result := Load(FileName); with Result do diff --git a/Tests/externalcanvas.simba b/Tests/externalcanvas.simba new file mode 100644 index 000000000..a3cc1fc90 --- /dev/null +++ b/Tests/externalcanvas.simba @@ -0,0 +1,30 @@ +{$assertions on} + +var Img: TImage; +var ExternalCanvas: TExternalCanvas; + +begin + Img := TImage.Create(100,100); + + ExternalCanvas := TExternalCanvas.Create(); + ExternalCanvas.DefaultPixel := [0,0,0,255]; + ExternalCanvas.SetMemory(Img.Data, Img.Width, Img.Height); + + ExternalCanvas.BeginUpdate(); + + Assert(ExternalCanvas.Width=100); + Assert(ExternalCanvas.Height=100); + + ExternalCanvas.DrawColor := Colors.WHITE; + ExternalCanvas.DrawBox([10,10,90,90]); + ExternalCanvas.DrawAlpha := 127; + ExternalCanvas.DrawBox([5,5,95,95]); + + ExternalCanvas.EndUpdate(); + + Assert(Img.FindColor($FFFFFF, 0).Bounds() = [10,10,90,90]); + Assert(Img.FindColor($7F7F7F, 0).Bounds() = [5,5,95,95]); + + ExternalCanvas.Free(); + Img.Free(); +end; diff --git a/Tests/externalimage.simba b/Tests/externalimage.simba deleted file mode 100644 index a7c9e4e11..000000000 --- a/Tests/externalimage.simba +++ /dev/null @@ -1,30 +0,0 @@ -{$assertions on} - -var Img: TImage; -var ExternalImage: TExternalImage; - -begin - Img := TImage.Create(100,100); - - ExternalImage := TExternalImage.Create(); - ExternalImage.DefaultPixel := [0,0,0,255]; - ExternalImage.SetMemory(Img.Data, Img.Width, Img.Height); - - ExternalImage.BeginUpdate(); - - Assert(ExternalImage.Width=100); - Assert(ExternalImage.Height=100); - - ExternalImage.DrawColor := Colors.WHITE; - ExternalImage.DrawBox([10,10,90,90]); - ExternalImage.DrawAlpha := 127; - ExternalImage.DrawBox([5,5,95,95]); - - ExternalImage.EndUpdate(); - - Assert(Img.FindColor($FFFFFF, 0).Bounds() = [10,10,90,90]); - Assert(Img.FindColor($7F7F7F, 0).Bounds() = [5,5,95,95]); - - ExternalImage.Free(); - Img.Free(); -end;