Files
Dreierpack-Manager/src/modern/ui/nation_flags.inc
T

36 lines
3.5 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
namespace {
// Small UI flags, sharing the muted palette of the HTML reference. Unknown
// identifiers deliberately return no image; callers retain a neutral label.
std::string ui_nation_flag_svg(const std::string &value) {
std::string code=value.starts_with("nation:")?value.substr(7):value;
for(auto &c:code)if(c>='A'&&c<='Z')c=char(c-'A'+'a');
const std::map<std::string,std::string> aliases{{"x-eng","en"},{"eng","en"},{"ger","de"},{"deu","de"},{"fra","fr"},{"ita","it"},{"esp","es"},{"ned","nl"},{"nld","nl"},{"jpn","jp"},{"swe","se"},{"den","dk"},{"dnk","dk"},{"nga","ng"},{"bra","br"},{"mar","ma"},{"alg","dz"},{"dza","dz"}};
if(auto it=aliases.find(code);it!=aliases.end())code=it->second;
const auto rect=[](double x,double y,double w,double h,const char*fill){return "<rect x=\""+scalar(x)+"\" y=\""+scalar(y)+"\" width=\""+scalar(w)+"\" height=\""+scalar(h)+"\" fill=\""+fill+"\"/>";};
std::string body;
const std::map<std::string,std::array<const char*,3>> bars{
{"de",{"#262b30","#c85a52","#d9bf65"}},{"fr",{"#5685b6","#e6ebee","#c7625b"}},
{"it",{"#679b83","#e6ebee","#c7625b"}},{"es",{"#c75b50","#e3c66b","#c75b50"}},
{"nl",{"#bf5c56","#e6ebee","#5b83b1"}},{"be",{"#262b30","#e3c66b","#c7625b"}},
{"ie",{"#679b83","#e6ebee","#d69455"}},{"ro",{"#5685b6","#e3c66b","#c7625b"}},
{"ng",{"#38865d","#e6ebee","#38865d"}},{"at",{"#c7625b","#e6ebee","#c7625b"}},
{"ru",{"#e6ebee","#5685b6","#c7625b"}},{"hu",{"#c7625b","#e6ebee","#679b83"}}};
if(auto it=bars.find(code);it!=bars.end()){
const bool vertical=code=="fr"||code=="it"||code=="be"||code=="ie"||code=="ro"||code=="ng";
for(int i=0;i<3;++i)body+=rect(vertical?i*10.:0,vertical?0:i*20./3,vertical?10:30,vertical?20:20./3,it->second[size_t(i)]);
}else if(code=="pl"||code=="ua")body=rect(0,0,30,10,code=="pl"?"#e6ebee":"#5685b6")+rect(0,10,30,10,code=="pl"?"#c7625b":"#e3c66b");
else if(code=="jp")body=rect(0,0,30,20,"#e6ebee")+"<circle cx=\"15\" cy=\"10\" r=\"6\" fill=\"#c7625b\"/>";
else if(code=="en"||code=="dk"||code=="se"||code=="fi"){
const auto bg=code=="dk"?"#c7625b":code=="se"?"#5685b6":"#e6ebee";
const auto cross=code=="en"?"#c7625b":code=="se"?"#e3c66b":code=="fi"?"#5685b6":"#e6ebee";
body=rect(0,0,30,20,bg)+rect(code=="en"?13:8,0,4,20,cross)+rect(0,8,30,4,cross);
}else if(code=="ch")body=rect(0,0,30,20,"#c7625b")+rect(13,4,4,12,"#e6ebee")+rect(9,8,12,4,"#e6ebee");
else if(code=="ma")body=rect(0,0,30,20,"#c7625b")+"<path d=\"M15 4L18.5 15L9.3 8.2H20.7L11.5 15Z\" fill=\"none\" stroke=\"#266747\" stroke-width=\"1\"/>";
else if(code=="dz")body=rect(0,0,15,20,"#38865d")+rect(15,0,15,20,"#e6ebee")+"<defs><mask id=\"crescent\"><rect width=\"30\" height=\"20\" fill=\"white\"/><circle cx=\"17\" cy=\"10\" r=\"5\" fill=\"black\"/></mask></defs><circle cx=\"15\" cy=\"10\" r=\"6\" fill=\"#c7625b\" mask=\"url(#crescent)\"/><path d=\"M18 7L18.7 9.1L21 9.1L19.2 10.5L19.9 12.7L18 11.3L16.1 12.7L16.8 10.5L15 9.1H17.3Z\" fill=\"#c7625b\"/>";
else if(code=="br")body=rect(0,0,30,20,"#38865d")+"<path d=\"M15 1.6L28 10L15 18.4L2 10Z\" fill=\"#e3c66b\"/><circle cx=\"15\" cy=\"10\" r=\"5.5\" fill=\"#40658d\"/><path d=\"M10 8Q15 6.5 20 11\" stroke=\"#e6ebee\" stroke-width=\"1\" fill=\"none\"/><g fill=\"#e6ebee\"><circle cx=\"12\" cy=\"11\" r=\".3\"/><circle cx=\"15\" cy=\"13\" r=\".3\"/><circle cx=\"18\" cy=\"12\" r=\".3\"/><circle cx=\"14\" cy=\"10\" r=\".3\"/></g>";
else return {};
return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"20\" viewBox=\"0 0 30 20\">"+body+"</svg>";
}
} // namespace