aboutsummaryrefslogtreecommitdiff
path: root/src/gui/StyleSpec.h
diff options
context:
space:
mode:
authorv-rob <robinsonvincent89@gmail.com>2020-07-12 00:48:50 -0700
committerGitHub <noreply@github.com>2020-07-12 09:48:50 +0200
commit2bec83eec0dc2de2d6b8fb0b827e94807ed9b0b8 (patch)
tree591ae4dcce087d2fa2f4f295bdc2e4ab3725694d /src/gui/StyleSpec.h
parent1dd6c8ed7fc8b56385546437baa54d53b43a385f (diff)
downloadminetest-2bec83eec0dc2de2d6b8fb0b827e94807ed9b0b8.tar.gz
minetest-2bec83eec0dc2de2d6b8fb0b827e94807ed9b0b8.tar.bz2
minetest-2bec83eec0dc2de2d6b8fb0b827e94807ed9b0b8.zip
Add FormSpec font styling options (#9763)
* Add FormSpec font styling options * Change multiplication to stof * Remove extraneous check
Diffstat (limited to 'src/gui/StyleSpec.h')
-rw-r--r--src/gui/StyleSpec.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/gui/StyleSpec.h b/src/gui/StyleSpec.h
index 3e842e826..67caf4f7b 100644
--- a/src/gui/StyleSpec.h
+++ b/src/gui/StyleSpec.h
@@ -18,9 +18,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "client/tile.h" // ITextureSource
+#include "client/fontengine.h"
#include "debug.h"
#include "irrlichttypes_extrabloated.h"
#include "util/string.h"
+#include <algorithm>
#include <array>
#pragma once
@@ -46,6 +48,8 @@ public:
ALPHA,
CONTENT_OFFSET,
PADDING,
+ FONT,
+ FONT_SIZE,
NUM_PROPERTIES,
NONE
};
@@ -98,6 +102,10 @@ public:
return CONTENT_OFFSET;
} else if (name == "padding") {
return PADDING;
+ } else if (name == "font") {
+ return FONT;
+ } else if (name == "font_size") {
+ return FONT_SIZE;
} else {
return NONE;
}
@@ -225,6 +233,47 @@ public:
return vec;
}
+ gui::IGUIFont *getFont() const
+ {
+ FontSpec spec(FONT_SIZE_UNSPECIFIED, FM_Standard, false, false);
+
+ const std::string &font = properties[FONT];
+ const std::string &size = properties[FONT_SIZE];
+
+ if (font.empty() && size.empty())
+ return nullptr;
+
+ std::vector<std::string> modes = split(font, ',');
+
+ for (size_t i = 0; i < modes.size(); i++) {
+ if (modes[i] == "normal")
+ spec.mode = FM_Standard;
+ else if (modes[i] == "mono")
+ spec.mode = FM_Mono;
+ else if (modes[i] == "bold")
+ spec.bold = true;
+ else if (modes[i] == "italic")
+ spec.italic = true;
+ }
+
+ if (!size.empty()) {
+ int calc_size = 1;
+
+ if (size[0] == '*') {
+ std::string new_size = size.substr(1); // Remove '*' (invalid for stof)
+ calc_size = stof(new_size) * g_fontengine->getFontSize(spec.mode);
+ } else if (size[0] == '+' || size[0] == '-') {
+ calc_size = stoi(size) + g_fontengine->getFontSize(spec.mode);
+ } else {
+ calc_size = stoi(size);
+ }
+
+ spec.size = (unsigned)std::min(std::max(calc_size, 1), 999);
+ }
+
+ return g_fontengine->getFont(spec);
+ }
+
video::ITexture *getTexture(Property prop, ISimpleTextureSource *tsrc,
video::ITexture *def) const
{