Skip to content

Commit

Permalink
Turned DrawingEffect into a proper bitset, used to be a mix of enum/b…
Browse files Browse the repository at this point in the history
…itset before. Fixes #569
  • Loading branch information
Grumbel committed Aug 11, 2014
1 parent 3eec32a commit 5b68905
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/badguy/badguy.cpp
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/supertux/flip_level_transformer.cpp
Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/supertux/sector.cpp
Expand Up @@ -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);

Expand Down
24 changes: 13 additions & 11 deletions src/video/sdl/sdl_painter.cpp
Expand Up @@ -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<SDL_RendererFlip>(flip | SDL_FLIP_HORIZONTAL);
}
else if (request.drawing_effect == VERTICAL_FLIP)

if (request.drawing_effect & VERTICAL_FLIP)
{
flip = SDL_FLIP_VERTICAL;
flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_VERTICAL);
}

SDL_RenderCopyEx(renderer, sdltexture->get_texture(), NULL, &dst_rect, request.angle, NULL, flip);
Expand Down Expand Up @@ -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<SDL_RendererFlip>(flip | SDL_FLIP_HORIZONTAL);
}
else if (request.drawing_effect == VERTICAL_FLIP)

if (request.drawing_effect & VERTICAL_FLIP)
{
flip = SDL_FLIP_VERTICAL;
flip = static_cast<SDL_RendererFlip>(flip | SDL_FLIP_VERTICAL);
}

SDL_RenderCopyEx(renderer, sdltexture->get_texture(), &src_rect, &dst_rect, request.angle, NULL, flip);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -256,7 +258,7 @@ SDLPainter::draw_inverse_ellipse(SDL_Renderer* renderer, const DrawingRequest& r
int slices = std::min(static_cast<int>(ellipse->size.y), max_slices);
for(int i = 0; i < slices; ++i)
{
float p = ((static_cast<float>(i) + 0.5f) / static_cast<float>(slices)) * 2.0f - 1.0f;
float p = ((static_cast<float>(i) + 0.5f) / static_cast<float>(slices)) * 2.0f - 1.0f;
int xoff = static_cast<int>(sqrtf(1.0f - p*p) * w / 2);

SDL_Rect& left = rects[2*i+0];
Expand Down
10 changes: 6 additions & 4 deletions src/video/texture.hpp
Expand Up @@ -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
Expand Down

0 comments on commit 5b68905

Please sign in to comment.