10
10
*****************************************************************************/
11
11
12
12
#include " StdInc.h"
13
- #include < lua/CLuaFunctionParser.h>
13
+ #include " CLuaDefs.h"
14
+ #include " lua/CLuaFunctionParser.h"
15
+
14
16
#define MIN_CLIENT_REQ_DXSETRENDERTARGET_CALL_RESTRICTIONS " 1.3.0-9.04431"
15
17
extern bool g_bAllowAspectRatioAdjustment;
16
18
@@ -31,8 +33,8 @@ void CLuaDrawingDefs::LoadFunctions()
31
33
{" dxDrawMaterialPrimitive" , DxDrawMaterialPrimitive},
32
34
{" dxDrawMaterialPrimitive3D" , DxDrawMaterialPrimitive3D},
33
35
{" dxDrawWiredSphere" , ArgumentParser<DxDrawWiredSphere>},
34
- {" dxGetTextWidth" , DxGetTextWidth},
35
- {" dxGetTextSize" , DxGetTextSize},
36
+ {" dxGetTextWidth" , ArgumentParser< DxGetTextWidth> },
37
+ {" dxGetTextSize" , ArgumentParser< DxGetTextSize> },
36
38
{" dxGetFontHeight" , DxGetFontHeight},
37
39
{" dxCreateFont" , DxCreateFont},
38
40
{" dxCreateTexture" , DxCreateTexture},
@@ -107,7 +109,7 @@ void CLuaDrawingDefs::AddDxFontClass(lua_State* luaVM)
107
109
108
110
lua_classfunction (luaVM, " getHeight" , OOP_DxGetFontHeight);
109
111
lua_classfunction (luaVM, " getTextWidth" , OOP_DxGetTextWidth);
110
- lua_classfunction (luaVM, " getTextSize" , OOP_DxGetTextSize);
112
+ lua_classfunction (luaVM, " getTextSize" , ArgumentParser< OOP_DxGetTextSize> );
111
113
112
114
// lua_classvariable ( luaVM, "height", NULL, "dxGetFontHeight"); // swap arguments, .height[scale] = int(height);
113
115
@@ -855,98 +857,27 @@ int CLuaDrawingDefs::OOP_DxGetTextWidth(lua_State* luaVM)
855
857
return 1 ;
856
858
}
857
859
858
- int CLuaDrawingDefs::DxGetTextSize (lua_State* luaVM)
860
+ CVector2D CLuaDrawingDefs::OOP_DxGetTextSize (std::variant<CClientDxFont*, eFontType> variantFont, const std::string text, const std::optional<float > optWidth,
861
+ const std::optional<float > optScaleXY, const std::optional<float > optScaleY,
862
+ const std::optional<bool > optWordBreak, const std::optional<bool > optColorCoded)
859
863
{
860
- // float, float dxGetTextSize ( string text, [float width=0, float scaleXY=1.0, float=scaleY=1.0, mixed font="default",
861
- // bool wordBreak=false, bool colorCoded=false] )
862
- SString strText;
863
- float fWidth ;
864
- float fScaleX ;
865
- float fScaleY ;
866
- eFontType fontType;
867
- CClientDxFont* pDxFontElement;
868
- bool bWordBreak;
869
- bool bColorCoded;
864
+ // float dxGetTextHeight ( string text, [float width, float scaleXY=1.0, float=scaleY=1.0, mixed font="default", bool wordBreak=false, bool
865
+ // colorCoded=false] )
866
+ CGraphicsInterface* const graphics = g_pCore->GetGraphics ();
870
867
871
- CScriptArgReader argStream (luaVM);
872
- argStream.ReadString (strText);
873
- argStream.ReadNumber (fWidth , 0 );
874
- if (argStream.NextIsUserDataOfType <CLuaVector2D>())
875
- {
876
- CVector2D vecScale;
877
- argStream.ReadVector2D (vecScale);
878
- fScaleX = vecScale.fX ;
879
- fScaleY = vecScale.fY ;
880
- }
881
- else
868
+ // resolve scale (use X as Y value, if optScaleY is empty)
869
+ CVector2D scale (1 .0f , 1 .0f );
870
+ if (optScaleXY.has_value ())
882
871
{
883
- argStream.ReadNumber (fScaleX , 1 );
884
- if (argStream.NextIsNumber ())
885
- argStream.ReadNumber (fScaleY );
886
- else
887
- fScaleY = fScaleX ;
872
+ scale.fX = optScaleXY.value ();
873
+ scale.fY = optScaleY.has_value () ? optScaleY.value () : scale.fX ;
888
874
}
889
- MixedReadDxFontString (argStream, fontType, FONT_DEFAULT, pDxFontElement);
890
- argStream.ReadBool (bWordBreak, false );
891
- argStream.ReadBool (bColorCoded, false );
892
-
893
- if (argStream.HasErrors ())
894
- return luaL_error (luaVM, argStream.GetFullErrorMessage ());
895
-
896
- // Get DX font
897
- ID3DXFont* pD3DXFont = CStaticFunctionDefinitions::ResolveD3DXFont (fontType, pDxFontElement);
898
875
899
876
CVector2D vecSize;
900
- g_pCore->GetGraphics ()->GetDXTextSize (vecSize, strText.c_str (), fWidth , fScaleX , fScaleY , pD3DXFont, bWordBreak, bColorCoded);
901
- lua_pushnumber (luaVM, vecSize.fX );
902
- lua_pushnumber (luaVM, vecSize.fY );
903
- return 2 ;
904
- }
905
-
906
- int CLuaDrawingDefs::OOP_DxGetTextSize (lua_State* luaVM)
907
- {
908
- // vector2 DxFont:getTextSize ( string text, [float width=0, float scaleXY=1.0, float=scaleY=1.0,
909
- // bool wordBreak=false, bool colorCoded=false] )
910
- SString strText;
911
- float fWidth ;
912
- float fScaleX ;
913
- float fScaleY ;
914
- CClientDxFont* pDxFontElement;
915
- bool bWordBreak;
916
- bool bColorCoded;
917
-
918
- CScriptArgReader argStream (luaVM);
919
- argStream.ReadUserData (pDxFontElement);
920
- argStream.ReadString (strText);
921
- argStream.ReadNumber (fWidth , 0 );
922
- if (argStream.NextIsUserDataOfType <CLuaVector2D>())
923
- {
924
- CVector2D vecScale;
925
- argStream.ReadVector2D (vecScale);
926
- fScaleX = vecScale.fX ;
927
- fScaleY = vecScale.fY ;
928
- }
929
- else
930
- {
931
- argStream.ReadNumber (fScaleX , 1 );
932
- if (argStream.NextIsNumber ())
933
- argStream.ReadNumber (fScaleY );
934
- else
935
- fScaleY = fScaleX ;
936
- }
937
- argStream.ReadBool (bWordBreak, false );
938
- argStream.ReadBool (bColorCoded, false );
877
+ graphics->GetDXTextSize (vecSize, text.c_str (), optWidth.value_or (0 .0f ), scale.fX , scale.fY , CStaticFunctionDefinitions::ResolveD3DXFont (variantFont),
878
+ optWordBreak.value_or (false ), optColorCoded.value_or (false ));
939
879
940
- if (argStream.HasErrors ())
941
- return luaL_error (luaVM, argStream.GetFullErrorMessage ());
942
-
943
- // Get DX font
944
- ID3DXFont* pD3DXFont = CStaticFunctionDefinitions::ResolveD3DXFont (FONT_DEFAULT, pDxFontElement);
945
-
946
- CVector2D vecSize;
947
- g_pCore->GetGraphics ()->GetDXTextSize (vecSize, strText.c_str (), fWidth , fScaleX , fScaleY , pD3DXFont, bWordBreak, bColorCoded);
948
- lua_pushvector (luaVM, vecSize);
949
- return 1 ;
880
+ return vecSize;
950
881
}
951
882
952
883
int CLuaDrawingDefs::DxGetFontHeight (lua_State* luaVM)
0 commit comments