mirror of
https://github.com/whoahq/whoa.git
synced 2026-08-04 16:04:30 +03:00
chore(ui): fix style nits in StringTo functions
Some checks are pending
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Waiting to run
Some checks are pending
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:cl compiler_name:MSVC cxx:cl os:windows-latest system_name:Windows test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:clang compiler_name:Clang cxx:clang++ os:macos-latest system_name:macOS test_path:WhoaTest]) (push) Waiting to run
Push / ${{ matrix.build.system_name }} / ${{ matrix.build.build_type }} / ${{ matrix.build.compiler_name }} (map[build_type:Release cc:gcc compiler_name:GCC cxx:g++ os:ubuntu-latest system_name:Linux test_path:WhoaTest]) (push) Waiting to run
This commit is contained in:
parent
7ed3475059
commit
57fbf42475
168
src/ui/Util.cpp
168
src/ui/Util.cpp
@ -1,6 +1,5 @@
|
|||||||
#include "ui/Util.hpp"
|
#include "ui/Util.hpp"
|
||||||
#include "util/Lua.hpp"
|
#include "util/Lua.hpp"
|
||||||
#include <type_traits>
|
|
||||||
#include <storm/String.hpp>
|
#include <storm/String.hpp>
|
||||||
|
|
||||||
const char* LanguageProcess(const char* string) {
|
const char* LanguageProcess(const char* string) {
|
||||||
@ -10,30 +9,30 @@ const char* LanguageProcess(const char* string) {
|
|||||||
|
|
||||||
int32_t StringToBlendMode(const char* string, EGxBlend& blend) {
|
int32_t StringToBlendMode(const char* string, EGxBlend& blend) {
|
||||||
struct BlendEntry {
|
struct BlendEntry {
|
||||||
EGxBlend value;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
EGxBlend value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static BlendEntry blendMap[] = {
|
static BlendEntry blendMap[] = {
|
||||||
{ GxBlend_Opaque, "DISABLE" },
|
{ "DISABLE", GxBlend_Opaque },
|
||||||
{ GxBlend_Alpha, "BLEND" },
|
{ "BLEND", GxBlend_Alpha },
|
||||||
{ GxBlend_AlphaKey, "ALPHAKEY" },
|
{ "ALPHAKEY", GxBlend_AlphaKey },
|
||||||
{ GxBlend_Add, "ADD" },
|
{ "ADD", GxBlend_Add },
|
||||||
{ GxBlend_Mod, "MOD" }
|
{ "MOD", GxBlend_Mod },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int32_t i = 0; i < std::extent<decltype(blendMap)>::value; i++) {
|
for (const auto& entry : blendMap) {
|
||||||
if (!SStrCmpI(blendMap[i].string, string, 0x7FFFFFFFu)) {
|
if (!SStrCmpI(entry.string, string)) {
|
||||||
blend = blendMap[i].value;
|
blend = entry.value;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToBOOL(const char* string) {
|
int32_t StringToBOOL(const char* string) {
|
||||||
return StringToBOOL(string, 0);
|
return StringToBOOL(string, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringToBOOL(const char* string, int32_t def) {
|
bool StringToBOOL(const char* string, int32_t def) {
|
||||||
@ -65,11 +64,11 @@ bool StringToBOOL(const char* string, int32_t def) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!SStrCmpI(string, "off", 0x7FFFFFFFu) || !SStrCmpI(string, "disabled", 0x7FFFFFFFu)) {
|
if (!SStrCmpI(string, "off") || !SStrCmpI(string, "disabled")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "on", 0x7FFFFFFFu) || !SStrCmpI(string, "enabled", 0x7FFFFFFFu)) {
|
if (!SStrCmpI(string, "on") || !SStrCmpI(string, "enabled")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,33 +77,22 @@ bool StringToBOOL(const char* string, int32_t def) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool StringToBOOL(lua_State* L, int32_t idx, int32_t def) {
|
bool StringToBOOL(lua_State* L, int32_t idx, int32_t def) {
|
||||||
bool result;
|
|
||||||
const char* str;
|
|
||||||
|
|
||||||
switch (lua_type(L, idx)) {
|
switch (lua_type(L, idx)) {
|
||||||
case LUA_TNIL:
|
case LUA_TNIL:
|
||||||
result = false;
|
return false;
|
||||||
break;
|
|
||||||
|
|
||||||
case LUA_TBOOLEAN:
|
case LUA_TBOOLEAN:
|
||||||
result = lua_toboolean(L, idx);
|
return lua_toboolean(L, idx);
|
||||||
break;
|
|
||||||
|
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
result = lua_tonumber(L, idx) != 0;
|
return lua_tonumber(L, idx) != 0;
|
||||||
break;
|
|
||||||
|
|
||||||
case LUA_TSTRING:
|
case LUA_TSTRING:
|
||||||
str = lua_tostring(L, idx);
|
return StringToBOOL(lua_tostring(L, idx), def);
|
||||||
result = StringToBOOL(str, def);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
result = def;
|
return def;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t StringToClickAction(const char* string) {
|
uint64_t StringToClickAction(const char* string) {
|
||||||
@ -112,27 +100,27 @@ uint64_t StringToClickAction(const char* string) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "LeftButtonDown", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "LeftButtonDown")) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "LeftButtonUp", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "LeftButtonUp")) {
|
||||||
return 0x80000000;
|
return 0x80000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "MiddleButtonDown", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "MiddleButtonDown")) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "MiddleButtonUp", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "MiddleButtonUp")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "RightButtonDown", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "RightButtonDown")) {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SStrCmpI(string, "RightButtonUp", STORM_MAX_STR)) {
|
if (!SStrCmpI(string, "RightButtonUp")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,126 +131,126 @@ uint64_t StringToClickAction(const char* string) {
|
|||||||
|
|
||||||
int32_t StringToDrawLayer(const char* string, int32_t& layer) {
|
int32_t StringToDrawLayer(const char* string, int32_t& layer) {
|
||||||
struct LayerEntry {
|
struct LayerEntry {
|
||||||
int32_t layer;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
int32_t layer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static LayerEntry layerMap[] = {
|
static LayerEntry layerMap[] = {
|
||||||
{ 0, "BACKGROUND" },
|
{ "BACKGROUND", DRAWLAYER_BACKGROUND },
|
||||||
{ 1, "BORDER" },
|
{ "BORDER", DRAWLAYER_BACKGROUND_BORDER },
|
||||||
{ 2, "ARTWORK" },
|
{ "ARTWORK", DRAWLAYER_ARTWORK },
|
||||||
{ 3, "OVERLAY" },
|
{ "OVERLAY", DRAWLAYER_ARTWORK_OVERLAY },
|
||||||
{ 4, "HIGHLIGHT" }
|
{ "HIGHLIGHT", DRAWLAYER_HIGHLIGHT },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto& entry : layerMap) {
|
for (const auto& entry : layerMap) {
|
||||||
if (!SStrCmpI(entry.string, string)) {
|
if (!SStrCmpI(string, entry.string)) {
|
||||||
layer = entry.layer;
|
layer = entry.layer;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToFramePoint(const char* string, FRAMEPOINT& point) {
|
int32_t StringToFramePoint(const char* string, FRAMEPOINT& point) {
|
||||||
struct FramePointEntry {
|
struct FramePointEntry {
|
||||||
FRAMEPOINT value;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
FRAMEPOINT value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static FramePointEntry framePointMap[] = {
|
static FramePointEntry framePointMap[] = {
|
||||||
{ FRAMEPOINT_BOTTOM, "BOTTOM" },
|
{ "BOTTOM", FRAMEPOINT_BOTTOM },
|
||||||
{ FRAMEPOINT_BOTTOMLEFT, "BOTTOMLEFT" },
|
{ "BOTTOMLEFT", FRAMEPOINT_BOTTOMLEFT },
|
||||||
{ FRAMEPOINT_BOTTOMRIGHT, "BOTTOMRIGHT" },
|
{ "BOTTOMRIGHT", FRAMEPOINT_BOTTOMRIGHT },
|
||||||
{ FRAMEPOINT_CENTER, "CENTER" },
|
{ "CENTER", FRAMEPOINT_CENTER },
|
||||||
{ FRAMEPOINT_TOP, "TOP" },
|
{ "TOP", FRAMEPOINT_TOP },
|
||||||
{ FRAMEPOINT_TOPRIGHT, "TOPRIGHT" },
|
{ "TOPRIGHT", FRAMEPOINT_TOPRIGHT },
|
||||||
{ FRAMEPOINT_TOPLEFT, "TOPLEFT" },
|
{ "TOPLEFT", FRAMEPOINT_TOPLEFT },
|
||||||
{ FRAMEPOINT_LEFT, "LEFT" },
|
{ "LEFT", FRAMEPOINT_LEFT },
|
||||||
{ FRAMEPOINT_RIGHT, "RIGHT" }
|
{ "RIGHT", FRAMEPOINT_RIGHT },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int32_t i = 0; i < std::extent<decltype(framePointMap)>::value; i++) {
|
for (const auto& entry : framePointMap) {
|
||||||
if (!SStrCmpI(framePointMap[i].string, string, 0x7FFFFFFFu)) {
|
if (!SStrCmpI(entry.string, string)) {
|
||||||
point = framePointMap[i].value;
|
point = entry.value;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata) {
|
int32_t StringToFrameStrata(const char* string, FRAME_STRATA& strata) {
|
||||||
struct FrameStrataEntry {
|
struct FrameStrataEntry {
|
||||||
FRAME_STRATA value;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
FRAME_STRATA value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FRAME_STRATA_WORLD is hardcoded
|
// FRAME_STRATA_WORLD is hardcoded
|
||||||
static FrameStrataEntry frameStrataMap[] = {
|
static FrameStrataEntry frameStrataMap[] = {
|
||||||
{ FRAME_STRATA_BACKGROUND, "BACKGROUND" },
|
{ "BACKGROUND", FRAME_STRATA_BACKGROUND },
|
||||||
{ FRAME_STRATA_LOW, "LOW" },
|
{ "LOW", FRAME_STRATA_LOW },
|
||||||
{ FRAME_STRATA_MEDIUM, "MEDIUM" },
|
{ "MEDIUM", FRAME_STRATA_MEDIUM },
|
||||||
{ FRAME_STRATA_HIGH, "HIGH" },
|
{ "HIGH", FRAME_STRATA_HIGH },
|
||||||
{ FRAME_STRATA_DIALOG, "DIALOG" },
|
{ "DIALOG", FRAME_STRATA_DIALOG },
|
||||||
{ FRAME_STRATA_FULLSCREEN, "FULLSCREEN" },
|
{ "FULLSCREEN", FRAME_STRATA_FULLSCREEN },
|
||||||
{ FRAME_STRATA_FULLSCREEN_DIALOG, "FULLSCREEN_DIALOG" },
|
{ "FULLSCREEN_DIALOG", FRAME_STRATA_FULLSCREEN_DIALOG },
|
||||||
{ FRAME_STRATA_TOOLTIP, "TOOLTIP" }
|
{ "TOOLTIP", FRAME_STRATA_TOOLTIP },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (int32_t i = 0; i < std::extent<decltype(frameStrataMap)>::value; i++) {
|
for (const auto& entry : frameStrataMap) {
|
||||||
if (!SStrCmpI(frameStrataMap[i].string, string, 0x7FFFFFFFu)) {
|
if (!SStrCmpI(entry.string, string)) {
|
||||||
strata = frameStrataMap[i].value;
|
strata = entry.value;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToJustify(const char* string, uint32_t& justify) {
|
int32_t StringToJustify(const char* string, uint32_t& justify) {
|
||||||
struct JustifyEntry {
|
struct JustifyEntry {
|
||||||
uint32_t value;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
uint32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static JustifyEntry justifyMap[] = {
|
static JustifyEntry justifyMap[] = {
|
||||||
{ 0x1, "LEFT" },
|
{ "LEFT", 0x1 },
|
||||||
{ 0x2, "CENTER" },
|
{ "CENTER", 0x2 },
|
||||||
{ 0x4, "RIGHT" },
|
{ "RIGHT", 0x4 },
|
||||||
{ 0x8, "TOP" },
|
{ "TOP", 0x8 },
|
||||||
{ 0x10, "MIDDLE" },
|
{ "MIDDLE", 0x10 },
|
||||||
{ 0x20, "BOTTOM" }
|
{ "BOTTOM", 0x20 },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto& entry : justifyMap) {
|
for (const auto& entry : justifyMap) {
|
||||||
if (!SStrCmpI(entry.string, string)) {
|
if (!SStrCmpI(entry.string, string)) {
|
||||||
justify = entry.value;
|
justify = entry.value;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t StringToOrientation(const char* string, ORIENTATION& orientation) {
|
int32_t StringToOrientation(const char* string, ORIENTATION& orientation) {
|
||||||
struct OrientationEntry {
|
struct OrientationEntry {
|
||||||
ORIENTATION value;
|
|
||||||
const char* string;
|
const char* string;
|
||||||
|
ORIENTATION value;
|
||||||
};
|
};
|
||||||
|
|
||||||
static OrientationEntry orientationMap[] = {
|
static OrientationEntry orientationMap[] = {
|
||||||
{ ORIENTATION_HORIZONTAL, "HORIZONTAL" },
|
{ "HORIZONTAL", ORIENTATION_HORIZONTAL },
|
||||||
{ ORIENTATION_VERTICAL, "VERTICAL" },
|
{ "VERTICAL", ORIENTATION_VERTICAL },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& entry : orientationMap) {
|
for (const auto& entry : orientationMap) {
|
||||||
if (!SStrCmpI(entry.string, string)) {
|
if (!SStrCmpI(entry.string, string)) {
|
||||||
orientation = entry.value;
|
orientation = entry.value;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user