/* * call-seq: * set_alpha(alpha, flags=Rubygame::SRC_ALPHA) * * Set the per-surface alpha (opacity; non-transparency) of the surface. * * This function takes these arguments: * alpha:: requested opacity of the surface. Alpha must be from 0 * (fully transparent) to 255 (fully opaque). * flags:: 0 or Rubygame::SRC_ALPHA (default). Most people will want the * default, in which case this argument can be omitted. For advanced * users: this flag affects the surface as described in the docs for * the SDL C function, SDL_SetAlpha. */ VALUE rbgm_surface_set_alpha(int argc, VALUE *argv, VALUE self) { SDL_Surface *surf; Uint8 alpha; Uint32 flags = SDL_SRCALPHA; switch(argc) { case 2: flags = NUM2UINT(argv[1]); /* no break */ case 1: { int temp; temp = NUM2INT(argv[0]); if(temp<0) alpha = 0; else if(temp>255) alpha = 255; else alpha = (Uint8) temp; break; } default: rb_raise(rb_eArgError,\ "Wrong number of args to set mode (%d for 1)",argc); } Data_Get_Struct(self,SDL_Surface,surf); if(SDL_SetAlpha(surf,flags,alpha)!=0) rb_raise(eSDLError,"%s",SDL_GetError()); return self; }