Skip to content

Commit 7fd8aca

Browse files
Merge pull request #94 from Blitz54/track-color
Track draw color for tooltip stuff
2 parents 1389b1f + 7c01722 commit 7fd8aca

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

engine/render.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class r_IRenderer {
9696
virtual void SetBlendMode(int mode) = 0;
9797
virtual void DrawColor(const col4_t col = NULL) = 0;
9898
virtual void DrawColor(dword col) = 0;
99+
virtual void GetDrawColor(col4_t color) = 0;
99100
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;
100101
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;
101102
virtual void DrawString(float x, float y, int align, int height, const col4_t col, int font, const char* str) = 0;

engine/render/r_main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,14 @@ void r_renderer_c::DrawColor(dword col)
17491749
drawColor[3] = (col >> 24) / 255.0f;
17501750
}
17511751

1752+
void r_renderer_c::GetDrawColor(col4_t color)
1753+
{
1754+
color[0] = drawColor[0];
1755+
color[1] = drawColor[1];
1756+
color[2] = drawColor[2];
1757+
color[3] = drawColor[3];
1758+
}
1759+
17521760
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)
17531761
{
17541762
DrawImageQuad(hnd,

engine/render/r_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class r_renderer_c: public r_IRenderer, public conCmdHandler_c {
8989
void SetBlendMode(int mode);
9090
void DrawColor(const col4_t col = NULL);
9191
void DrawColor(dword col);
92+
void GetDrawColor(col4_t color);
9293
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 = {});
9394
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 = {});
9495
void DrawString(float x, float y, int align, int height, const col4_t col, int font, const char* str);

ui_api.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
857879
static 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);

ui_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class ui_main_c: public ui_IMain {
5252
bool hasActiveCoroutine = false;
5353
int ioOpenf = LUA_NOREF;
5454

55+
float lastColor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
56+
5557
static int InitAPI(lua_State* L);
5658

5759
void RenderInit(r_featureFlag_e features);

0 commit comments

Comments
 (0)