/* call-seq:
* render_unicode(string, aa, fg, bg) -> Surface
*
* Renders a string to a Surface with the font's style and the given color(s).
*
* This method takes these arguments:
* string:: the text string to render
* aa:: Use anti-aliasing if true. Enabling this makes the text
* look much nicer (smooth curves), but is much slower.
* fg:: the color to render the text, in the form [r,g,b]
* bg:: the color to use as a background for the text. This option can
* be omitted to have a transparent background.
*/
VALUE rbgm_ttf_render_unicode(int argc, VALUE *argv, VALUE self)
{
/* TODO:... ->unicode */
SDL_Surface *surf;
TTF_Font *font;
SDL_Color fore, back; /* foreground and background colors */
VALUE vstring, vaa, vfg, vbg;
rb_scan_args(argc, argv, "31", &vstring, &vaa, &vfg, &vbg);
Data_Get_Struct(self,TTF_Font,font);
fore = make_sdl_color(vfg);
if( RTEST(vbg) )
{
back = make_sdl_color(vbg);
}
if( RTEST(vaa) ) /* anti-aliasing enabled */
{
if( RTEST(vbg) ) /* background color provided */
surf = TTF_RenderUNICODE_Shaded(font,(Uint16*)StringValuePtr(vstring),fore,back);
else /* no background color */
surf = TTF_RenderUNICODE_Blended(font,(Uint16*)StringValuePtr(vstring),fore);
}
else /* anti-aliasing not enabled */
{
if( RTEST(vbg) ) /* background color provided */
{
/* remove colorkey, set color index 0 to background color */
surf = TTF_RenderUNICODE_Solid(font,(Uint16*)StringValuePtr(vstring),fore);
SDL_SetColors(surf,&back,0,1);
SDL_SetColorKey(surf,0,0);
}
else /* no background color */
{
surf = TTF_RenderUNICODE_Solid(font,(Uint16*)StringValuePtr(vstring),fore);
}
}
if(surf==NULL)
rb_raise(eSDLError,"could not render font object: %s",TTF_GetError());
return Data_Wrap_Struct(cSurface,0,SDL_FreeSurface,surf);
}