mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-10-26 22:06:06 +03:00
feat(ui): implement font-related CSimpleFontString script methods
This commit is contained in:
parent
f0634dded2
commit
f3cfac1764
@ -947,3 +947,12 @@ void CSimpleFontString::UpdateString() {
|
||||
|
||||
this->OnRegionChanged();
|
||||
}
|
||||
|
||||
bool CSimpleFontString::SetAlphaGradient(int32_t startChar, int32_t length) {
|
||||
this->m_alphaGradientStart = startChar;
|
||||
this->m_alphaGradientLength = length;
|
||||
if (this->m_string) {
|
||||
// TODO: return TextBlockSetGradient()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -87,6 +87,7 @@ class CSimpleFontString : public CSimpleRegion, public CSimpleFontable {
|
||||
void SetTextLength(uint32_t a2);
|
||||
int32_t Sub482AC0();
|
||||
void UpdateString();
|
||||
bool SetAlphaGradient(int32_t startChar, int32_t length);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "util/Lua.hpp"
|
||||
#include "util/Unimplemented.hpp"
|
||||
#include "util/StringTo.hpp"
|
||||
#include "gx/Coordinate.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
int32_t CSimpleFontString_IsObjectType(lua_State* L) {
|
||||
@ -72,15 +73,47 @@ int32_t CSimpleFontString_SetVertexColor(lua_State* L) {
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_GetAlpha(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleFontString::GetObjectType();
|
||||
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
CImVector color;
|
||||
string->GetVertexColor(color);
|
||||
lua_pushnumber(L, color.a / 255.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_SetAlpha(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleFontString::GetObjectType();
|
||||
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
if (!lua_isnumber(L, 2)) {
|
||||
return luaL_error(L, "Usage: %s:SetAlpha(alpha)", string->GetDisplayName());
|
||||
}
|
||||
|
||||
CImVector color;
|
||||
string->GetVertexColor(color);
|
||||
|
||||
color.a = lua_tonumber(L, 2) * 255.0;
|
||||
string->SetVertexColor(color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_SetAlphaGradient(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleFontString::GetObjectType();
|
||||
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3)) {
|
||||
return luaL_error(L, "Usage: %s:SetAlphaGradient(start, length)", string->GetDisplayName());
|
||||
}
|
||||
|
||||
auto start = lua_tonumber(L, 2);
|
||||
auto length = lua_tonumber(L, 3);
|
||||
if (string->SetAlphaGradient(start, length)) {
|
||||
lua_pushnumber(L, 1.0);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_Show(lua_State* L) {
|
||||
@ -124,7 +157,17 @@ int32_t CSimpleFontString_IsShown(lua_State* L) {
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_GetFontObject(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleFontString::GetObjectType();
|
||||
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||
if (string->m_fontObject) {
|
||||
if (!string->m_fontObject->lua_registered) {
|
||||
string->m_fontObject->RegisterScriptObject(nullptr);
|
||||
}
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, string->m_fontObject->lua_objectRef);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_SetFontObject(lua_State* L) {
|
||||
@ -162,7 +205,20 @@ int32_t CSimpleFontString_SetFontObject(lua_State* L) {
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_GetFont(lua_State* L) {
|
||||
WHOA_UNIMPLEMENTED(0);
|
||||
auto type = CSimpleFontString::GetObjectType();
|
||||
auto string = static_cast<CSimpleFontString*>(FrameScript_GetObjectThis(L, type));
|
||||
|
||||
lua_pushstring(L, string->GetFontName());
|
||||
|
||||
auto height = string->GetFontHeight(false);
|
||||
height *= CoordinateGetAspectCompensation() * 1024.0f;
|
||||
height = DDCToNDCWidth(height);
|
||||
lua_pushnumber(L, height);
|
||||
|
||||
auto flags = FontFlagsToString(string->GetFontFlags());
|
||||
lua_pushstring(L, flags);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int32_t CSimpleFontString_SetFont(lua_State* L) {
|
||||
|
||||
@ -143,3 +143,28 @@ const char* DrawLayerToString(int32_t layer) {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
const char* FontFlagsToString(uint32_t flags) {
|
||||
struct FlagEntry {
|
||||
uint32_t flag;
|
||||
const char* string;
|
||||
};
|
||||
|
||||
static FlagEntry table[3] = {
|
||||
{ 1, "OUTLINE" },
|
||||
{ 4, "THICKOUTLINE" },
|
||||
{ 2, "MONOCHROME" },
|
||||
};
|
||||
|
||||
static char result[64] = {};
|
||||
result[0] = '\0';
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
if (flags & table[i].flag) {
|
||||
if (result[0]) {
|
||||
SStrPack(result, ", ", sizeof(result));
|
||||
}
|
||||
SStrPack(result, table[i].string, sizeof(result));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -19,4 +19,6 @@ const char* AnchorPointToString(int32_t point);
|
||||
|
||||
const char* DrawLayerToString(int32_t layer);
|
||||
|
||||
const char* FontFlagsToString(uint32_t flags);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user