From: Ingo Ruhnke Date: Mon, 11 Aug 2014 22:46:45 +0000 (+0200) Subject: Turned DrawingEffect into a proper bitset, used to be a mix of enum/bitset before... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5b6890533e6c4d070a0954952ac9b93d1a5c6cbb;p=supertux.git Turned DrawingEffect into a proper bitset, used to be a mix of enum/bitset before. Fixes #569 --- diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index 8f08ea787..1901ccf31 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -127,7 +127,7 @@ BadGuy::draw(DrawingContext& context) return; if(state == STATE_FALLING) { DrawingEffect old_effect = context.get_drawing_effect(); - context.set_drawing_effect((DrawingEffect) (old_effect | VERTICAL_FLIP)); + context.set_drawing_effect(old_effect | VERTICAL_FLIP); sprite->draw(context, get_pos(), layer); context.set_drawing_effect(old_effect); } else { diff --git a/src/supertux/flip_level_transformer.cpp b/src/supertux/flip_level_transformer.cpp index 4bed1f901..53f285ab6 100644 --- a/src/supertux/flip_level_transformer.cpp +++ b/src/supertux/flip_level_transformer.cpp @@ -78,10 +78,10 @@ FlipLevelTransformer::transform_sector(Sector* sector) DrawingEffect FlipLevelTransformer::transform_drawing_effect(DrawingEffect effect) { - if(effect != 0) { - return NO_EFFECT; + if (effect & VERTICAL_FLIP) { + return effect & ~VERTICAL_FLIP; } else { - return VERTICAL_FLIP; + return effect | VERTICAL_FLIP; } } diff --git a/src/supertux/sector.cpp b/src/supertux/sector.cpp index 4be93298d..ac5f76def 100644 --- a/src/supertux/sector.cpp +++ b/src/supertux/sector.cpp @@ -1013,7 +1013,7 @@ Sector::collision_tilemap(collision::Constraints* constraints, if(tile->is_slope ()) { // slope tile AATriangle triangle; int slope_data = tile->getData(); - if (solids->get_drawing_effect() == VERTICAL_FLIP) + if (solids->get_drawing_effect() & VERTICAL_FLIP) slope_data = AATriangle::vertical_flip(slope_data); triangle = AATriangle(tile_bbox, slope_data); diff --git a/src/video/sdl/sdl_painter.cpp b/src/video/sdl/sdl_painter.cpp index b6dbbe0b5..6ba8f4225 100644 --- a/src/video/sdl/sdl_painter.cpp +++ b/src/video/sdl/sdl_painter.cpp @@ -76,13 +76,14 @@ SDLPainter::draw_surface(SDL_Renderer* renderer, const DrawingRequest& request) SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend)); SDL_RendererFlip flip = SDL_FLIP_NONE; - if (surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP) + if (surface->get_flipx() || request.drawing_effect & HORIZONTAL_FLIP) { - flip = SDL_FLIP_HORIZONTAL; + flip = static_cast(flip | SDL_FLIP_HORIZONTAL); } - else if (request.drawing_effect == VERTICAL_FLIP) + + if (request.drawing_effect & VERTICAL_FLIP) { - flip = SDL_FLIP_VERTICAL; + flip = static_cast(flip | SDL_FLIP_VERTICAL); } SDL_RenderCopyEx(renderer, sdltexture->get_texture(), NULL, &dst_rect, request.angle, NULL, flip); @@ -118,13 +119,14 @@ SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& requ SDL_SetTextureBlendMode(sdltexture->get_texture(), blend2sdl(request.blend)); SDL_RendererFlip flip = SDL_FLIP_NONE; - if (surface->surface->get_flipx() || request.drawing_effect == HORIZONTAL_FLIP) + if (surface->surface->get_flipx() || request.drawing_effect & HORIZONTAL_FLIP) { - flip = SDL_FLIP_HORIZONTAL; + flip = static_cast(flip | SDL_FLIP_HORIZONTAL); } - else if (request.drawing_effect == VERTICAL_FLIP) + + if (request.drawing_effect & VERTICAL_FLIP) { - flip = SDL_FLIP_VERTICAL; + flip = static_cast(flip | SDL_FLIP_VERTICAL); } SDL_RenderCopyEx(renderer, sdltexture->get_texture(), &src_rect, &dst_rect, request.angle, NULL, flip); @@ -133,7 +135,7 @@ SDLPainter::draw_surface_part(SDL_Renderer* renderer, const DrawingRequest& requ void SDLPainter::draw_gradient(SDL_Renderer* renderer, const DrawingRequest& request) { - const GradientRequest* gradientrequest + const GradientRequest* gradientrequest = (GradientRequest*) request.request_data; const Color& top = gradientrequest->top; const Color& bottom = gradientrequest->bottom; @@ -244,7 +246,7 @@ void SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& request) { const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data; - + float x = request.pos.x; float w = ellipse->size.x; float h = ellipse->size.y; @@ -256,7 +258,7 @@ SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& r int slices = std::min(static_cast(ellipse->size.y), max_slices); for(int i = 0; i < slices; ++i) { - float p = ((static_cast(i) + 0.5f) / static_cast(slices)) * 2.0f - 1.0f; + float p = ((static_cast(i) + 0.5f) / static_cast(slices)) * 2.0f - 1.0f; int xoff = static_cast(sqrtf(1.0f - p*p) * w / 2); SDL_Rect& left = rects[2*i+0]; diff --git a/src/video/texture.hpp b/src/video/texture.hpp index e814547f3..ca0b68c79 100644 --- a/src/video/texture.hpp +++ b/src/video/texture.hpp @@ -26,16 +26,18 @@ #include "video/texture_manager.hpp" /// bitset for drawing effects -enum DrawingEffect { +enum { /** Don't apply anything */ - NO_EFFECT, + NO_EFFECT = 0, /** Draw the Surface upside down */ - VERTICAL_FLIP, + VERTICAL_FLIP = (1<<1), /** Draw the Surface from left to down */ - HORIZONTAL_FLIP, + HORIZONTAL_FLIP = (1<<2), NUM_EFFECTS }; +typedef unsigned int DrawingEffect; + /** * This class is a wrapper around a texture handle. It stores the texture width * and height and provides convenience functions for uploading SDL_Surfaces