mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Add gradients and borders to FormSpec boxes (#8676)
This commit is contained in:
parent
471497fa91
commit
83d0c360cc
5 changed files with 220 additions and 49 deletions
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "util/string.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -50,6 +51,9 @@ public:
|
|||
PADDING,
|
||||
FONT,
|
||||
FONT_SIZE,
|
||||
COLORS,
|
||||
BORDERCOLORS,
|
||||
BORDERWIDTHS,
|
||||
NUM_PROPERTIES,
|
||||
NONE
|
||||
};
|
||||
|
@ -106,6 +110,12 @@ public:
|
|||
return FONT;
|
||||
} else if (name == "font_size") {
|
||||
return FONT_SIZE;
|
||||
} else if (name == "colors") {
|
||||
return COLORS;
|
||||
} else if (name == "bordercolors") {
|
||||
return BORDERCOLORS;
|
||||
} else if (name == "borderwidths") {
|
||||
return BORDERWIDTHS;
|
||||
} else {
|
||||
return NONE;
|
||||
}
|
||||
|
@ -187,6 +197,42 @@ public:
|
|||
return color;
|
||||
}
|
||||
|
||||
std::array<video::SColor, 4> getColorArray(Property prop,
|
||||
std::array<video::SColor, 4> def) const
|
||||
{
|
||||
const auto &val = properties[prop];
|
||||
if (val.empty())
|
||||
return def;
|
||||
|
||||
std::vector<std::string> strs;
|
||||
if (!parseArray(val, strs))
|
||||
return def;
|
||||
|
||||
for (size_t i = 0; i <= 3; i++) {
|
||||
video::SColor color;
|
||||
if (parseColorString(strs[i], color, false, 0xff))
|
||||
def[i] = color;
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
std::array<s32, 4> getIntArray(Property prop, std::array<s32, 4> def) const
|
||||
{
|
||||
const auto &val = properties[prop];
|
||||
if (val.empty())
|
||||
return def;
|
||||
|
||||
std::vector<std::string> strs;
|
||||
if (!parseArray(val, strs))
|
||||
return def;
|
||||
|
||||
for (size_t i = 0; i <= 3; i++)
|
||||
def[i] = stoi(strs[i]);
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
irr::core::rect<s32> getRect(Property prop, irr::core::rect<s32> def) const
|
||||
{
|
||||
const auto &val = properties[prop];
|
||||
|
@ -334,6 +380,24 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
bool parseArray(const std::string &value, std::vector<std::string> &arr) const
|
||||
{
|
||||
std::vector<std::string> strs = split(value, ',');
|
||||
|
||||
if (strs.size() == 1) {
|
||||
arr = {strs[0], strs[0], strs[0], strs[0]};
|
||||
} else if (strs.size() == 2) {
|
||||
arr = {strs[0], strs[1], strs[0], strs[1]};
|
||||
} else if (strs.size() == 4) {
|
||||
arr = strs;
|
||||
} else {
|
||||
warningstream << "Invalid array size (" << strs.size()
|
||||
<< " arguments): \"" << value << "\"" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parseRect(const std::string &value, irr::core::rect<s32> *parsed_rect) const
|
||||
{
|
||||
irr::core::rect<s32> rect;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue