Skip to content

Commit

Permalink
Add a fix for the renamed field in SDL2.
Browse files Browse the repository at this point in the history
The unused field in SDL_Color has been renamed to a.
  • Loading branch information
mordante committed Feb 22, 2014
1 parent 2551700 commit 3d6b6b4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/font.hpp
Expand Up @@ -136,7 +136,11 @@ class floating_label
void set_color(const SDL_Color& color) {color_ = color;}
void set_bg_color(const SDL_Color& bg_color) {
bgcolor_ = bg_color;
#if SDL_VERSION_ATLEAST(2,0,0)
bgalpha_ = bg_color.a;
#else
bgalpha_ = bg_color.unused;
#endif
}
void set_border_size(int border) {border_ = border;}
// set width for word wrapping (use -1 to disable it)
Expand Down
5 changes: 5 additions & 0 deletions src/image_modifications.cpp
Expand Up @@ -451,8 +451,13 @@ surface darken_modification::operator()(const surface &src) const
surface background_modification::operator()(const surface &src) const
{
surface ret = make_neutral_surface(src);
#if SDL_VERSION_ATLEAST(2,0,0)
SDL_FillRect(ret, NULL, SDL_MapRGBA(ret->format, color_.r, color_.g,
color_.b, color_.a));
#else
SDL_FillRect(ret, NULL, SDL_MapRGBA(ret->format, color_.r, color_.g,
color_.b, color_.unused));
#endif
SDL_SetAlpha(src, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
SDL_BlitSurface(src, NULL, ret, NULL);
return ret;
Expand Down
4 changes: 4 additions & 0 deletions src/map_label.cpp
Expand Up @@ -408,7 +408,11 @@ std::string terrain_label::cfg_color() const
const unsigned int red = static_cast<unsigned int>(color_.r);
const unsigned int green = static_cast<unsigned int>(color_.g);
const unsigned int blue = static_cast<unsigned int>(color_.b);
#if SDL_VERSION_ATLEAST(2,0,0)
const unsigned int alpha = static_cast<unsigned int>(color_.a);
#else
const unsigned int alpha = static_cast<unsigned int>(color_.unused);
#endif
buf << red << "," << green << "," << blue << "," << alpha;
return buf.str();
}
Expand Down
16 changes: 16 additions & 0 deletions src/sdl_utils.cpp
Expand Up @@ -62,7 +62,11 @@ SDL_Color int_to_color(const Uint32 rgb)
result.r = (0x00FF0000 & rgb )>> 16;
result.g = (0x0000FF00 & rgb) >> 8;
result.b = (0x000000FF & rgb);
#if SDL_VERSION_ATLEAST(2,0,0)
result.a = 0;
#else
result.unused = 0;
#endif
return result;
}

Expand All @@ -75,7 +79,11 @@ SDL_Color create_color(const unsigned char red
result.r = red;
result.g = green;
result.b = blue;
#if SDL_VERSION_ATLEAST(2,0,0)
result.a = alpha;
#else
result.unused = alpha;
#endif

return result;
}
Expand Down Expand Up @@ -2197,7 +2205,11 @@ SDL_Color inverse(const SDL_Color& color) {
inverse.r = 255 - color.r;
inverse.g = 255 - color.g;
inverse.b = 255 - color.b;
#if SDL_VERSION_ATLEAST(2,0,0)
inverse.a = 0;
#else
inverse.unused = 0;
#endif
return inverse;
}

Expand Down Expand Up @@ -2279,7 +2291,11 @@ void draw_centered_on_background(surface surf, const SDL_Rect& rect, const SDL_C
{
clip_rect_setter clip_setter(target, &rect);

#if SDL_VERSION_ATLEAST(2,0,0)
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.a);
#else
Uint32 col = SDL_MapRGBA(target->format, color.r, color.g, color.b, color.unused);
#endif
//TODO: only draw background outside the image
SDL_Rect r = rect;
sdl_fill_rect(target, &r, col);
Expand Down
20 changes: 20 additions & 0 deletions src/tests/test_image_modifications.cpp
Expand Up @@ -898,7 +898,11 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_no_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 0);
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
#endif

delete mod;
}
Expand All @@ -920,7 +924,11 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_1_arg)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 0);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
#endif

delete mod;
}
Expand All @@ -942,7 +950,11 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_2_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 0);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
#endif

delete mod;
}
Expand All @@ -964,7 +976,11 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_3_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 3);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 255);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 255);
#endif

delete mod;
}
Expand All @@ -986,7 +1002,11 @@ BOOST_AUTO_TEST_CASE(test_bg_modification_decoding_4_args)
BOOST_CHECK_EQUAL(mod->get_color().r, 1);
BOOST_CHECK_EQUAL(mod->get_color().g, 2);
BOOST_CHECK_EQUAL(mod->get_color().b, 3);
#if SDL_VERSION_ATLEAST(2,0,0)
BOOST_CHECK_EQUAL(mod->get_color().a, 4);
#else
BOOST_CHECK_EQUAL(mod->get_color().unused, 4);
#endif

delete mod;
}
Expand Down

0 comments on commit 3d6b6b4

Please sign in to comment.