Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class r_IRenderer {
virtual void SetBlendMode(int mode) = 0;
virtual void DrawColor(const col4_t col = NULL) = 0;
virtual void DrawColor(dword col) = 0;
virtual void GetDrawColor(col4_t color) = 0;
virtual void DrawImage(r_shaderHnd_c* hnd, glm::vec2 pos, glm::vec2 extent, glm::vec2 uv1 = { 0, 0 }, glm::vec2 uv2 = { 1, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {}) = 0;
virtual void DrawImageQuad(r_shaderHnd_c* hnd, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2, glm::vec2 p3, glm::vec2 uv0 = { 0, 0 }, glm::vec2 uv1 = { 1, 0 }, glm::vec2 uv2 = { 1, 1 }, glm::vec2 uv3 = { 0, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {}) = 0;
virtual void DrawString(float x, float y, int align, int height, const col4_t col, int font, const char* str) = 0;
Expand Down
8 changes: 8 additions & 0 deletions engine/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,14 @@ void r_renderer_c::DrawColor(dword col)
drawColor[3] = (col >> 24) / 255.0f;
}

void r_renderer_c::GetDrawColor(col4_t color)
{
color[0] = drawColor[0];
color[1] = drawColor[1];
color[2] = drawColor[2];
color[3] = drawColor[3];
}

void r_renderer_c::DrawImage(r_shaderHnd_c* hnd, glm::vec2 pos, glm::vec2 extent, glm::vec2 uv1, glm::vec2 uv2, int stackLayer, std::optional<int> maskLayer)
{
DrawImageQuad(hnd,
Expand Down
1 change: 1 addition & 0 deletions engine/render/r_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
void SetBlendMode(int mode);
void DrawColor(const col4_t col = NULL);
void DrawColor(dword col);
void GetDrawColor(col4_t color);
void DrawImage(r_shaderHnd_c* hnd, glm::vec2 pos, glm::vec2 extent, glm::vec2 uv1 = { 0, 0 }, glm::vec2 uv2 = { 1, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {});
void DrawImageQuad(r_shaderHnd_c* hnd, glm::vec2 p0, glm::vec2 p1, glm::vec2 p2, glm::vec2 p3, glm::vec2 uv0 = { 0, 0 }, glm::vec2 uv1 = { 1, 0 }, glm::vec2 uv2 = { 1, 1 }, glm::vec2 uv3 = { 0, 1 }, int stackLayer = 0, std::optional<int> maskLayer = {});
void DrawString(float x, float y, int align, int height, const col4_t col, int font, const char* str);
Expand Down
34 changes: 33 additions & 1 deletion ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,31 @@ static int l_SetDrawColor(lua_State* L)
}
}
ui->renderer->DrawColor(color);

// Store last applied color from renderer
col4_t finalColor;
ui->renderer->GetDrawColor(finalColor);
ui->lastColor[0] = finalColor[0];
ui->lastColor[1] = finalColor[1];
ui->lastColor[2] = finalColor[2];
ui->lastColor[3] = finalColor[3];

return 0;
}

static int l_GetDrawColor(lua_State* L)
{
ui_main_c* ui = GetUIPtr(L);
ui->LAssert(L, ui->renderer != NULL, "Renderer is not initialised");

lua_pushnumber(L, ui->lastColor[0]);
lua_pushnumber(L, ui->lastColor[1]);
lua_pushnumber(L, ui->lastColor[2]);
lua_pushnumber(L, ui->lastColor[3]);

return 4; // returning r,g,b,a
}

static int l_DrawImage(lua_State* L)
{
ui_main_c* ui = GetUIPtr(L);
Expand Down Expand Up @@ -1068,7 +1090,7 @@ static int l_DrawString(lua_State* L)
ui->LAssert(L, lua_isstring(L, 5), "DrawString() argument 5: expected string, got %s", luaL_typename(L, 5));
ui->LAssert(L, lua_isstring(L, 6), "DrawString() argument 6: expected string, got %s", luaL_typename(L, 6));
static const char* alignMap[6] = { "LEFT", "CENTER", "RIGHT", "CENTER_X", "RIGHT_X", NULL };
static const char* fontMap[8] = { "FIXED", "VAR", "VAR BOLD", "FONTIN SC", "FONTIN SC ITALIC", "FONTIN", "FONTIN ITALIC", NULL};
static const char* fontMap[8] = { "FIXED", "VAR", "VAR BOLD", "FONTIN SC", "FONTIN SC ITALIC", "FONTIN", "FONTIN ITALIC", NULL };
const float dpiScale = ui->renderer->VirtualScreenScaleFactor();
const float left = lua_tonumber(L, 1) * dpiScale;
const float top = lua_tonumber(L, 2) * dpiScale;
Expand All @@ -1089,6 +1111,15 @@ static int l_DrawString(lua_State* L)
luaL_checkoption(L, 5, "FIXED", fontMap),
lua_tostring(L, 6)
);

// Get the final color from the renderer after DrawString processes color codes
col4_t finalColor;
ui->renderer->GetDrawColor(finalColor);
ui->lastColor[0] = finalColor[0];
ui->lastColor[1] = finalColor[1];
ui->lastColor[2] = finalColor[2];
ui->lastColor[3] = finalColor[3];

return 0;
}

Expand Down Expand Up @@ -2186,6 +2217,7 @@ int ui_main_c::InitAPI(lua_State* L)
ADDFUNC(SetViewport);
ADDFUNC(SetBlendMode);
ADDFUNC(SetDrawColor);
ADDFUNC(GetDrawColor);
ADDFUNC(SetDPIScaleOverridePercent);
ADDFUNC(GetDPIScaleOverridePercent);
ADDFUNC(DrawImage);
Expand Down
2 changes: 2 additions & 0 deletions ui_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ui_main_c: public ui_IMain {
bool hasActiveCoroutine = false;
int ioOpenf = LUA_NOREF;

float lastColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};

static int InitAPI(lua_State* L);

void RenderInit(r_featureFlag_e features);
Expand Down
Loading