3 Copyright (C) 2019 rubenwardy
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "client/tile.h" // ITextureSource
21 #include "irrlichttypes_extrabloated.h"
22 #include "util/string.h"
50 std::array<bool, NUM_PROPERTIES> property_set;
51 std::array<std::string, NUM_PROPERTIES> properties;
54 static Property GetPropertyByName(const std::string &name)
56 if (name == "textcolor") {
58 } else if (name == "bgcolor") {
60 } else if (name == "bgcolor_hovered") {
61 return BGCOLOR_HOVERED;
62 } else if (name == "bgcolor_pressed") {
63 return BGCOLOR_PRESSED;
64 } else if (name == "noclip") {
66 } else if (name == "border") {
68 } else if (name == "bgimg") {
70 } else if (name == "bgimg_hovered") {
72 } else if (name == "bgimg_pressed") {
74 } else if (name == "fgimg") {
76 } else if (name == "fgimg_hovered") {
78 } else if (name == "fgimg_pressed") {
80 } else if (name == "alpha") {
87 std::string get(Property prop, std::string def) const
89 const auto &val = properties[prop];
90 return val.empty() ? def : val;
93 void set(Property prop, const std::string &value)
95 properties[prop] = value;
96 property_set[prop] = true;
99 video::SColor getColor(Property prop, video::SColor def) const
101 const auto &val = properties[prop];
106 parseColorString(val, def, false, 0xFF);
110 video::SColor getColor(Property prop) const
112 const auto &val = properties[prop];
113 FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
116 parseColorString(val, color, false, 0xFF);
120 video::ITexture *getTexture(Property prop, ISimpleTextureSource *tsrc,
121 video::ITexture *def) const
123 const auto &val = properties[prop];
128 video::ITexture *texture = tsrc->getTexture(val);
133 video::ITexture *getTexture(Property prop, ISimpleTextureSource *tsrc) const
135 const auto &val = properties[prop];
136 FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
138 video::ITexture *texture = tsrc->getTexture(val);
143 bool getBool(Property prop, bool def) const
145 const auto &val = properties[prop];
153 inline bool isNotDefault(Property prop) const
155 return !properties[prop].empty();
158 inline bool hasProperty(Property prop) const { return property_set[prop]; }
160 StyleSpec &operator|=(const StyleSpec &other)
162 for (size_t i = 0; i < NUM_PROPERTIES; i++) {
163 auto prop = (Property)i;
164 if (other.hasProperty(prop)) {
165 set(prop, other.get(prop, ""));
172 StyleSpec operator|(const StyleSpec &other) const
174 StyleSpec newspec = *this;