Ejemplo n.º 1
0
static void interpret_text_settings(const ds::cfg::Settings &s, std::unordered_map<std::string, ds::cfg::Text>& out) {
	// Do the name first, because that determines whether an entry exists.
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && right == "name") {
			std::string		v = s.getText(key, 0, ds::EMPTY_SZ);
			if (!v.empty()) {
				if (out.empty()) {
					out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
				} else {
					auto	found = out.find(left);
					if (found != out.end()) {
						found->second.mFont = v;
					} else {
						out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
					}
				}
			}
		}
	});

	// Floats (size, leading)
	s.forEachFloatKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "size") found->second.mSize = s.getFloat(key, 0, found->second.mSize);
				else if (right == "leading") found->second.mLeading = s.getFloat(key, 0, found->second.mLeading);
			}
		}
	});

	// Color (color)
	s.forEachColorAKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "color") found->second.mColor = s.getColorA(key, 0, found->second.mColor);
			}
		}
	});

	// Text (alignment)
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "alignment") {
					found->second.mAlignment = ds::ui::Alignment::fromString(s.getText(key, 0, ""));
				}
			}
		}
	});

}