/*
* call-seq:
* rotozoom_size( size, angle, zoom ) -> [width, height] or nil
*
* Return the dimensions of the surface that would be returned if
* #rotozoom() were called on a Surface of the given size, with
* the same angle and zoom factors.
*
* If Rubygame was compiled with SDL_gfx-2.0.13 or greater, +zoom+ can be
* an Array of 2 Numerics for separate X and Y scaling. Also, it can be
* negative to indicate flipping horizontally or vertically.
*
* Will return +nil+ if you attempt to use separate X and Y zoom factors
* or negative zoom factors with an unsupported version of SDL_gfx.
*
* This method takes these arguments:
* size:: an Array with the hypothetical Surface width and height (pixels)
* angle:: degrees to rotate counter-clockwise (negative for clockwise).
* zoom:: scaling factor(s). A single positive Numeric, unless you have
* SDL_gfx-2.0.13 or greater (see above).
*/
VALUE rbgm_transform_rzsize(int argc, VALUE *argv, VALUE module)
{
int w,h, dstw,dsth;
double angle, zoomx, zoomy;
if(argc < 3)
rb_raise(rb_eArgError,"wrong number of arguments (%d for 3)",argc);
w = NUM2INT(rb_ary_entry(argv[0],0));
h = NUM2INT(rb_ary_entry(argv[0],0));
angle = NUM2DBL(argv[1]);
if(TYPE(argv[2])==T_ARRAY)
{
/* Separate X/Y rotozoom scaling was not supported prior to 2.0.13. */
/* Check if we have at least version 2.0.13 of SDL_gfxPrimitives */
#ifdef HAVE_ROTOZOOMXY
/* Do the real function. */
zoomx = NUM2DBL(rb_ary_entry(argv[1],0));
zoomy = NUM2DBL(rb_ary_entry(argv[1],1));
rotozoomSurfaceSizeXY(w, h, angle, zoomx, zoomy, &dstw, &dsth);
#else
/* Return nil, because it's not supported. */
return Qnil;
#endif
}
else if(FIXNUM_P(argv[1]) || TYPE(argv[1])==T_FLOAT)
{
zoomx = NUM2DBL(argv[1]);
#ifndef HAVE_ROTOZOOMXY
if(zoomx < 0) /* negative zoom (for flipping) */
{
/* Return nil, because it's not supported. */
return Qnil;
}
#endif
rotozoomSurfaceSize(w, h, angle, zoomx, &dstw, &dsth);
}
else
rb_raise(rb_eArgError,"wrong zoom factor type (expected Array or Numeric)");
/* if(dstw == NULL || dsth == NULL)
rb_raise(eSDLError,"Could not rotozoom surface: %s",SDL_GetError());*/
return rb_ary_new3(2,INT2NUM(dstw),INT2NUM(dsth));
}