@@ -851,9 +851,31 @@ static int l_SetDrawColor(lua_State* L)
851851 }
852852 }
853853 ui->renderer ->DrawColor (color);
854+
855+ // Store last applied color from renderer
856+ col4_t finalColor;
857+ ui->renderer ->GetDrawColor (finalColor);
858+ ui->lastColor [0 ] = finalColor[0 ];
859+ ui->lastColor [1 ] = finalColor[1 ];
860+ ui->lastColor [2 ] = finalColor[2 ];
861+ ui->lastColor [3 ] = finalColor[3 ];
862+
854863 return 0 ;
855864}
856865
866+ static int l_GetDrawColor (lua_State* L)
867+ {
868+ ui_main_c* ui = GetUIPtr (L);
869+ ui->LAssert (L, ui->renderer != NULL , " Renderer is not initialised" );
870+
871+ lua_pushnumber (L, ui->lastColor [0 ]);
872+ lua_pushnumber (L, ui->lastColor [1 ]);
873+ lua_pushnumber (L, ui->lastColor [2 ]);
874+ lua_pushnumber (L, ui->lastColor [3 ]);
875+
876+ return 4 ; // returning r,g,b,a
877+ }
878+
857879static int l_DrawImage (lua_State* L)
858880{
859881 ui_main_c* ui = GetUIPtr (L);
@@ -1068,7 +1090,7 @@ static int l_DrawString(lua_State* L)
10681090 ui->LAssert (L, lua_isstring (L, 5 ), " DrawString() argument 5: expected string, got %s" , luaL_typename (L, 5 ));
10691091 ui->LAssert (L, lua_isstring (L, 6 ), " DrawString() argument 6: expected string, got %s" , luaL_typename (L, 6 ));
10701092 static const char * alignMap[6 ] = { " LEFT" , " CENTER" , " RIGHT" , " CENTER_X" , " RIGHT_X" , NULL };
1071- static const char * fontMap[8 ] = { " FIXED" , " VAR" , " VAR BOLD" , " FONTIN SC" , " FONTIN SC ITALIC" , " FONTIN" , " FONTIN ITALIC" , NULL };
1093+ static const char * fontMap[8 ] = { " FIXED" , " VAR" , " VAR BOLD" , " FONTIN SC" , " FONTIN SC ITALIC" , " FONTIN" , " FONTIN ITALIC" , NULL };
10721094 const float dpiScale = ui->renderer ->VirtualScreenScaleFactor ();
10731095 const float left = lua_tonumber (L, 1 ) * dpiScale;
10741096 const float top = lua_tonumber (L, 2 ) * dpiScale;
@@ -1089,6 +1111,15 @@ static int l_DrawString(lua_State* L)
10891111 luaL_checkoption (L, 5 , " FIXED" , fontMap),
10901112 lua_tostring (L, 6 )
10911113 );
1114+
1115+ // Get the final color from the renderer after DrawString processes color codes
1116+ col4_t finalColor;
1117+ ui->renderer ->GetDrawColor (finalColor);
1118+ ui->lastColor [0 ] = finalColor[0 ];
1119+ ui->lastColor [1 ] = finalColor[1 ];
1120+ ui->lastColor [2 ] = finalColor[2 ];
1121+ ui->lastColor [3 ] = finalColor[3 ];
1122+
10921123 return 0 ;
10931124}
10941125
@@ -2186,6 +2217,7 @@ int ui_main_c::InitAPI(lua_State* L)
21862217 ADDFUNC (SetViewport);
21872218 ADDFUNC (SetBlendMode);
21882219 ADDFUNC (SetDrawColor);
2220+ ADDFUNC (GetDrawColor);
21892221 ADDFUNC (SetDPIScaleOverridePercent);
21902222 ADDFUNC (GetDPIScaleOverridePercent);
21912223 ADDFUNC (DrawImage);
0 commit comments