/*
* 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;
VALUE vsize, vangle, vzoom;
rb_scan_args(argc,argv,"3", &vsize, &vangle, &vzoom);
vsize = convert_to_array(vsize);
w = NUM2INT(rb_ary_entry(argv[0],0));
h = NUM2INT(rb_ary_entry(argv[0],0));
angle = NUM2DBL(vangle);
switch( TYPE(vzoom) )
{
case 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(vzoom,0));
zoomy = NUM2DBL(rb_ary_entry(vzoom,1));
rotozoomSurfaceSizeXY(w, h, angle, zoomx, zoomy, &dstw, &dsth);
#else
/* Return nil, because it's not supported. */
return Qnil;
#endif
break;
}
case T_FLOAT:
case T_FIXNUM: {
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);
break;
}
default: {
rb_raise(rb_eArgError,
"wrong zoom factor type (expected Array or Numeric)");
break;
}
}
/* if(dstw == NULL || dsth == NULL)
rb_raise(eSDLError,"Could not rotozoom surface: %s",SDL_GetError());*/
return rb_ary_new3(2,INT2NUM(dstw),INT2NUM(dsth));
}