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 "irrlichttypes_extrabloated.h"
42 std::array<bool, NUM_PROPERTIES> property_set;
43 std::array<std::string, NUM_PROPERTIES> properties;
46 static Property GetPropertyByName(const std::string &name)
48 if (name == "textcolor") {
50 } else if (name == "bgcolor") {
52 } else if (name == "noclip") {
54 } else if (name == "border") {
56 } else if (name == "bgimg") {
58 } else if (name == "bgimg_pressed") {
60 } else if (name == "alpha") {
67 std::string get(Property prop, std::string def) const
69 const auto &val = properties[prop];
70 return val.empty() ? def : val;
73 void set(Property prop, const std::string &value)
75 properties[prop] = value;
76 property_set[prop] = true;
79 video::SColor getColor(Property prop, video::SColor def) const
81 const auto &val = properties[prop];
86 parseColorString(val, def, false, 0xFF);
90 video::SColor getColor(Property prop) const
92 const auto &val = properties[prop];
93 FATAL_ERROR_IF(val.empty(), "Unexpected missing property");
96 parseColorString(val, color, false, 0xFF);
100 bool getBool(Property prop, bool def) const
102 const auto &val = properties[prop];
110 inline bool isNotDefault(Property prop) const
112 return !properties[prop].empty();
115 inline bool hasProperty(Property prop) const { return property_set[prop]; }
117 StyleSpec &operator|=(const StyleSpec &other)
119 for (size_t i = 0; i < NUM_PROPERTIES; i++) {
120 auto prop = (Property)i;
121 if (other.hasProperty(prop)) {
122 set(prop, other.get(prop, ""));
129 StyleSpec operator|(const StyleSpec &other) const
131 StyleSpec newspec = *this;