diff --git a/Source/script/imports/simba.import_box.pas b/Source/script/imports/simba.import_box.pas index 5aa3d308a..38eae5355 100644 --- a/Source/script/imports/simba.import_box.pas +++ b/Source/script/imports/simba.import_box.pas @@ -311,7 +311,7 @@ procedure _LapeBox_Normalize(const Params: PParamArray; const Result: Pointer); TBox.Width ---------- ``` -function TBox.Width: Integer; +property TBox.Width: Integer; ``` *) procedure _LapeBox_Width(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV @@ -323,7 +323,7 @@ procedure _LapeBox_Width(const Params: PParamArray; const Result: Pointer); LAPE TBox.Height ----------- ``` -function TBox.Height: Integer; +property TBox.Height: Integer; ``` *) procedure _LapeBox_Height(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV @@ -335,7 +335,7 @@ procedure _LapeBox_Height(const Params: PParamArray; const Result: Pointer); LAP TBox.Center ----------- ``` -function TBox.Center: TPoint; +property TBox.Center: TPoint; ``` *) procedure _LapeBox_Center(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV @@ -397,6 +397,54 @@ procedure _LapeBox_RandomPointCenter(const Params: PParamArray; const Result: Po PPoint(Result)^ := PBox(Params^[0])^.RandomPointCenter(); end; +(* +TBox.TopLeft +------------ +``` +property TBox.TopLeft: TPoint; +``` +*) +procedure _LapeBox_TopLeft(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPoint(Result)^ := PBox(Params^[0])^.TopLeft; +end; + +(* +TBox.TopRight +------------- +``` +property TBox.TopRight: TPoint; +``` +*) +procedure _LapeBox_TopRight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPoint(Result)^ := PBox(Params^[0])^.TopRight; +end; + +(* +TBox.BottomLeft +--------------- +``` +property TBox.BottomLeft: TPoint; +``` +*) +procedure _LapeBox_BottomLeft(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPoint(Result)^ := PBox(Params^[0])^.BottomLeft; +end; + +(* +TBox.BottomRight +---------------- +``` +property TBox.BottomRight: TPoint; +``` +*) +procedure _LapeBox_BottomRight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV +begin + PPoint(Result)^ := PBox(Params^[0])^.BottomRight; +end; + procedure ImportBox(Compiler: TSimbaScript_Compiler); begin with Compiler do @@ -440,8 +488,13 @@ procedure ImportBox(Compiler: TSimbaScript_Compiler); addGlobalFunc('function TBox.RandomPoint: TPoint', @_LapeBox_RandomPoint); addGlobalFunc('function TBox.RandomPointCenter: TPoint', @_LapeBox_RandomPointCenter); + addGlobalFunc('property TBox.TopLeft: TPoint;', @_LapeBox_TopLeft); + addGlobalFunc('property TBox.TopRight: TPoint;', @_LapeBox_TopRight); + addGlobalFunc('property TBox.BottomLeft: TPoint;', @_LapeBox_BottomLeft); + addGlobalFunc('property TBox.BottomRight: TPoint;', @_LapeBox_BottomRight); + ImportingSection := ''; end; end; -end. \ No newline at end of file +end. diff --git a/Source/simba.vartype_box.pas b/Source/simba.vartype_box.pas index 622a544c8..04e3a1d9a 100644 --- a/Source/simba.vartype_box.pas +++ b/Source/simba.vartype_box.pas @@ -19,6 +19,8 @@ interface type TBoxHelper = record helper for TBox private + function GetTopRight: TPoint; inline; + function GetBottomLeft: TPoint; inline; function GetCenter: TPoint; inline; function GetWidth: Integer; inline; function GetHeight: Integer; inline; @@ -57,6 +59,8 @@ TBoxHelper = record helper for TBox function Clip(Other: TBox): TBox; function Normalize: TBox; + property TopRight: TPoint read GetTopRight; + property BottomLeft: TPoint read GetBottomLeft; property Width: Integer read GetWidth; property Height: Integer read GetHeight; property Center: TPoint read GetCenter; @@ -72,6 +76,18 @@ implementation Math, simba.random, simba.containers, simba.geometry; +function TBoxHelper.GetTopRight: TPoint; +begin + Result.X := X2; + Result.Y := Y1; +end; + +function TBoxHelper.GetBottomLeft: TPoint; +begin + Result.X := X1; + Result.Y := Y2; +end; + function TBoxHelper.GetCenter: TPoint; begin Result.X := (Self.X2 + Self.X1 + 1) div 2; diff --git a/Tests/box.simba b/Tests/box.simba index 4dfa2a560..5b3fe6f5f 100644 --- a/Tests/box.simba +++ b/Tests/box.simba @@ -21,4 +21,9 @@ begin Assert(b.Expand(50, 100) = [50,0,250,300]); Assert(b.Offset([-10, 10]) = [90, 110, 190, 210]); + + Assert(b.TopLeft = [100,100]); + Assert(b.TopRight = [200,100]); + Assert(b.BottomLeft = [100,200]); + Assert(b.BottomRight = [200,200]); end.