Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

RenderCopyEx,rotation and flipping for all hardware/software backends…

… (#1308)
  • Loading branch information
gabomdq committed Jun 1, 2012
1 parent fc741e4 commit 1b873da0c5e1a5e1f8009667b2759d93bf52d21d
@@ -104,6 +104,16 @@ typedef enum
SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
} SDL_TextureModulate;

/**
* \brief Flip constants for SDL_RenderCopyEx
*/
typedef enum
{
SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
} SDL_RendererFlip;

/**
* \brief A structure representing rendering state
*/
@@ -599,6 +609,27 @@ extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);

/**
* \brief Copy a portion of the source texture to the current rendering target, rotating it by angle around the given center
*
* \param texture The source texture.
* \param srcrect A pointer to the source rectangle, or NULL for the entire
* texture.
* \param dstrect A pointer to the destination rectangle, or NULL for the
* entire rendering target.
* \param angle An angle in degrees that indicates the rotation that will be applied to dstrect
* \param center A pointer to a point indicating the point around which dstrect will be rotated (if NULL, rotation will be done aroud dstrect.w/2, dstrect.h/2)
* \param flip A SFL_Flip value stating which flipping actions should be performed on the texture
*
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderCopyEx(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect,
const double angle,
const SDL_Point *center,
const SDL_RendererFlip flip);

/**
* \brief Read pixels from the current rendering target.
@@ -1231,6 +1231,62 @@ SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
&real_dstrect);
}


int
SDL_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect,
const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
{
SDL_Window *window;
SDL_Rect real_srcrect, real_dstrect;
SDL_Point real_center;

CHECK_RENDERER_MAGIC(renderer, -1);
CHECK_TEXTURE_MAGIC(texture, -1);

if (renderer != texture->renderer) {
SDL_SetError("Texture was not created with this renderer");
return -1;
}
if (!renderer->RenderCopyEx) {
SDL_SetError("Renderer does not support RenderCopyEx");
return -1;
}

window = renderer->window;

real_srcrect.x = 0;
real_srcrect.y = 0;
real_srcrect.w = texture->w;
real_srcrect.h = texture->h;
if (srcrect) {
if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
return 0;
}
}

/* We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we? */
if (dstrect) real_dstrect = *dstrect;
else {
real_srcrect.x = 0;
real_srcrect.y = 0;
real_srcrect.w = renderer->viewport.w;
real_srcrect.h = renderer->viewport.h;
}

if (texture->native) {
texture = texture->native;
}

if(center) real_center = *center;
else {
real_center.x = real_dstrect.w/2;
real_center.y = real_dstrect.h/2;
}

return renderer->RenderCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip);
}

int
SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
@@ -88,6 +88,9 @@ struct SDL_Renderer
int count);
int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
int (*RenderCopyEx) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcquad, const SDL_Rect * dstrect,
const double angle, const SDL_Point *center, const SDL_RendererFlip flip);
int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
void (*RenderPresent) (SDL_Renderer * renderer);

0 comments on commit 1b873da

Please sign in to comment.