dialogxml parseColor use a map built from Colours constants
parseColor() was doing a big if-else with string comparisons, and returning values that differed from our Colours constants. Since I couldn't find an instance of the colour attribute in our existing xml, it should be safe to do away with those conflicting values and refactor parseColor() to match the constants and use cleaner code.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
#include "dialog.hpp"
|
#include "dialog.hpp"
|
||||||
#include "gfx/tiling.hpp" // for bg
|
#include "gfx/tiling.hpp" // for bg
|
||||||
#include "fileio/resmgr/res_dialog.hpp"
|
#include "fileio/resmgr/res_dialog.hpp"
|
||||||
@@ -45,6 +46,8 @@ cDialog* cDialog::topWindow = nullptr;
|
|||||||
void (*cDialog::redraw_everything)() = nullptr;
|
void (*cDialog::redraw_everything)() = nullptr;
|
||||||
std::mt19937 cDialog::ui_rand;
|
std::mt19937 cDialog::ui_rand;
|
||||||
|
|
||||||
|
extern std::map<std::string,sf::Color> colour_map;
|
||||||
|
|
||||||
extern bool check_for_interrupt(std::string);
|
extern bool check_for_interrupt(std::string);
|
||||||
|
|
||||||
std::string cDialog::generateRandomString(){
|
std::string cDialog::generateRandomString(){
|
||||||
@@ -86,39 +89,9 @@ sf::Color cControl::parseColor(string what){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
clr.r = r, clr.g = g, clr.b = b;
|
clr.r = r, clr.g = g, clr.b = b;
|
||||||
}else if(what == "black")
|
}else if(colour_map.find(what) != colour_map.end()){
|
||||||
clr.r = 0x00, clr.g = 0x00, clr.b = 0x00;
|
return colour_map[what];
|
||||||
else if(what == "red")
|
}else throw -1;
|
||||||
clr.r = 0xFF, clr.g = 0x00, clr.b = 0x00;
|
|
||||||
else if(what == "lime")
|
|
||||||
clr.r = 0x00, clr.g = 0xFF, clr.b = 0x00;
|
|
||||||
else if(what == "blue")
|
|
||||||
clr.r = 0x00, clr.g = 0x00, clr.b = 0xFF;
|
|
||||||
else if(what == "yellow")
|
|
||||||
clr.r = 0xFF, clr.g = 0xFF, clr.b = 0x00;
|
|
||||||
else if(what == "aqua")
|
|
||||||
clr.r = 0x00, clr.g = 0xFF, clr.b = 0xFF;
|
|
||||||
else if(what == "fuchsia")
|
|
||||||
clr.r = 0xFF, clr.g = 0x00, clr.b = 0xFF;
|
|
||||||
else if(what == "white")
|
|
||||||
clr.r = 0xFF, clr.g = 0xFF, clr.b = 0xFF;
|
|
||||||
else if(what == "gray" || what == "grey")
|
|
||||||
clr.r = 0x80, clr.g = 0x80, clr.b = 0x80;
|
|
||||||
else if(what == "maroon")
|
|
||||||
clr.r = 0x80, clr.g = 0x00, clr.b = 0x00;
|
|
||||||
else if(what == "green")
|
|
||||||
clr.r = 0x00, clr.g = 0x80, clr.b = 0x00;
|
|
||||||
else if(what == "navy")
|
|
||||||
clr.r = 0x00, clr.g = 0x00, clr.b = 0x80;
|
|
||||||
else if(what == "olive")
|
|
||||||
clr.r = 0x80, clr.g = 0x80, clr.b = 0x00;
|
|
||||||
else if(what == "teal")
|
|
||||||
clr.r = 0x00, clr.g = 0x80, clr.b = 0x80;
|
|
||||||
else if(what == "purple")
|
|
||||||
clr.r = 0x80, clr.g = 0x00, clr.b = 0x80;
|
|
||||||
else if(what == "silver")
|
|
||||||
clr.r = 0xC0, clr.g = 0xC0, clr.b = 0xC0;
|
|
||||||
else throw -1;
|
|
||||||
return clr;
|
return clr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,27 @@
|
|||||||
using boost::math::constants::pi;
|
using boost::math::constants::pi;
|
||||||
using pt_idx_t = decltype(((sf::Shape*)nullptr)->getPointCount());
|
using pt_idx_t = decltype(((sf::Shape*)nullptr)->getPointCount());
|
||||||
|
|
||||||
|
std::map<std::string,sf::Color> colour_map = {
|
||||||
|
{"white", Colours::WHITE},
|
||||||
|
{"black", Colours::BLACK},
|
||||||
|
{"grey", Colours::GREY},
|
||||||
|
{"gray", Colours::GREY},
|
||||||
|
{"red", Colours::RED},
|
||||||
|
{"green", Colours::GREEN},
|
||||||
|
{"blue", Colours::BLUE},
|
||||||
|
{"teal", Colours::TEAL},
|
||||||
|
{"pink", Colours::PINK},
|
||||||
|
{"yellow", Colours::YELLOW},
|
||||||
|
{"orange", Colours::ORANGE},
|
||||||
|
{"shadow", Colours::SHADOW},
|
||||||
|
{"title_blue", Colours::TITLE_BLUE},
|
||||||
|
{"navy", Colours::NAVY},
|
||||||
|
{"dark_blue", Colours::DARK_BLUE},
|
||||||
|
{"dark_green", Colours::DARK_GREEN},
|
||||||
|
{"light_green", Colours::LIGHT_GREEN},
|
||||||
|
{"dark_red", Colours::DARK_RED}
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Put these classes in a header?
|
// TODO: Put these classes in a header?
|
||||||
class EllipseShape : public sf::Shape {
|
class EllipseShape : public sf::Shape {
|
||||||
float divSz;
|
float divSz;
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
#include <SFML/Graphics/Shape.hpp>
|
||||||
#include "location.hpp"
|
#include "location.hpp"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user