From 50b37068affc976d9f84857da6aa803379a33383 Mon Sep 17 00:00:00 2001 From: hoangfitus Date: Mon, 6 Nov 2023 22:12:10 +0700 Subject: [PATCH] Fix color opacity and shape scale --- src/Parser.cpp | 21 ++++++++++++--------- src/graphics/Circle.hpp | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index a5a61d57..3f7cfb0a 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -29,15 +29,18 @@ sf::Color Parser::parseColor(pugi::xml_node node, std::string name) { for (auto& c : color) c = tolower(c); if (color == "none") return sf::Color::Transparent; - else if (color.find("rgb") == std::string::npos) { - auto color_code = color_map.find(color); - if (color_code == color_map.end()) exit(-1); - return color_code->second; - } else { - unsigned int r = 0, g = 0, b = 0, a; - sscanf(color.c_str(), "rgb(%u,%u,%u)", &r, &g, &b); - a = stof(getAttribute(node, name + "-opacity")) * 255; - return sf::Color(r, g, b, a); + else { + sf::Color result; + if (color.find("rgb") == std::string::npos) { + auto color_code = color_map.find(color); + if (color_code == color_map.end()) exit(-1); + result = color_code->second; + } else + sscanf(color.c_str(), "rgb(%u,%u,%u)", &result.r, &result.g, + &result.b); + + result.a = stof(getAttribute(node, name + "-opacity")) * 255; + return result; } } diff --git a/src/graphics/Circle.hpp b/src/graphics/Circle.hpp index 52065150..487438aa 100644 --- a/src/graphics/Circle.hpp +++ b/src/graphics/Circle.hpp @@ -2,7 +2,7 @@ #define CIRCLE_HPP_ #include "Shape.hpp" -#define SCALE 1000000 +#define SCALE 100000 class Circle : public Shape { private: