Reimplement string_to_color, using map label implementation

This commit is contained in:
Charles Dang 2015-12-12 01:42:01 +11:00
parent ac374909a3
commit 9eb6e66e7b
4 changed files with 17 additions and 8 deletions

View file

@ -288,7 +288,7 @@ void help_text_area::handle_format_cfg(const config &cfg)
bool bold = cfg["bold"].to_bool();
bool italic = cfg["italic"].to_bool();
int font_size = cfg["font_size"].to_int(normal_font_size);
SDL_Color color = string_to_color(cfg["color"]);
SDL_Color color = help::string_to_color(cfg["color"]);
add_text_item(text, "", false, font_size, bold, italic, color);
}

View file

@ -397,13 +397,7 @@ void terrain_label::read(const config &cfg)
team_name_ = utils::interpolate_variables_into_string(team_name_, vs);
tmp_color = utils::interpolate_variables_into_string(tmp_color, vs);
if(!tmp_color.empty()) {
std::vector<Uint32> temp_rgb;
if(string2rgb(tmp_color, temp_rgb) && !temp_rgb.empty()) {
color = int_to_color(temp_rgb[0]);
}
}
color_ = color;
color_ = (color = string_to_color(tmp_color));
}
void terrain_label::write(config& cfg) const

View file

@ -18,6 +18,7 @@
*/
#include "global.hpp"
#include "color_range.hpp"
#include "sdl/utils.hpp"
#include "sdl/alpha.hpp"
@ -75,6 +76,18 @@ SDL_Color int_to_color(const Uint32 rgb)
return result;
}
SDL_Color string_to_color(const std::string& color_string)
{
SDL_Color color;
std::vector<Uint32> temp_rgb;
if(string2rgb(color_string, temp_rgb) && !temp_rgb.empty()) {
color = int_to_color(temp_rgb[0]);
}
return color;
}
SDL_Color create_color(const unsigned char red
, unsigned char green
, unsigned char blue

View file

@ -432,8 +432,10 @@ SDL_Rect get_non_transparent_portion(const surface &surf);
bool operator==(const SDL_Color& a, const SDL_Color& b);
bool operator!=(const SDL_Color& a, const SDL_Color& b);
SDL_Color inverse(const SDL_Color& color);
SDL_Color int_to_color(const Uint32 rgb);
SDL_Color string_to_color(const std::string& color_string);
SDL_Color create_color(const unsigned char red
, unsigned char green