Skip to content

Commit

Permalink
Reimplement string_to_color, using map label implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 15, 2015
1 parent ac37490 commit 9eb6e66
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/help/help_text_area.cpp
Expand Up @@ -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);
}

Expand Down
8 changes: 1 addition & 7 deletions src/map_label.cpp
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/sdl/utils.cpp
Expand Up @@ -18,6 +18,7 @@
*/

#include "global.hpp"
#include "color_range.hpp"

#include "sdl/utils.hpp"
#include "sdl/alpha.hpp"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sdl/utils.hpp
Expand Up @@ -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
Expand Down

0 comments on commit 9eb6e66

Please sign in to comment.