void API_SDLAGG::Gfx_Initialize() { // Open a screen with the specified properties int width = 320; int height = 240; int bpp = 32; // We stored our image in RGBA32 format. We have to create a mask // for this format to tell SDL about our data layout. Uint32 rmask = 0xff000000; Uint32 gmask = 0x00ff0000; Uint32 bmask = 0x0000ff00; Uint32 amask = 0x000000ff; #if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks rmask = 0x000000FF; gmask = 0x0000FF00; bmask = 0x00FF0000; amask = 0xFF000000; #else rmask = 0xFF000000; gmask = 0x00FF0000; bmask = 0x0000FF00; amask = 0x000000FF; #endif SurfaceContainer* targetCont = new SurfaceContainer; targetCont->sdl = SDL_SetVideoMode(width, height, bpp, SDL_HWSURFACE); if (targetCont->sdl == NULL) { Log("[Error] Unable to set %ix%i video: %s\n", width,height, SDL_GetError()); exit(1); } _targetScreen = (GfxSurface*)targetCont; SurfaceContainer* gfxCont = new SurfaceContainer; gfxCont->sdl = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE,width, height, bpp, rmask, gmask, bmask, amask)); if (gfxCont->sdl == NULL) return; _gfxSurface = (GfxSurface*)gfxCont; SDL_WM_SetCaption("MGame",NULL); sge_TTF_Init(); font = sge_TTF_OpenFont("arial.ttf",10); sge_Update_OFF(); sge_TTF_AAOff(); //sge_TTF_AA_Alpha(); //void* rBuffer = ((SDL_Surface*)_gfxSurface)->sdl->pixels; //unsigned char* renderBuffer = (unsigned char*)rBuffer; //agg::rendering_buffer rbuf(renderBuffer, width, height, bpp/8); m_graphics.attach((unsigned char*)((SurfaceContainer*)_gfxSurface)->sdl->pixels, width, height, width*(bpp/8));//rbuf.buf() m_graphics.blendMode(Agg2D::BlendAlpha); _gfxImage.attach((unsigned char*)((SurfaceContainer*)_gfxSurface)->sdl->pixels, width, height, width*(bpp/8)); }
int DrawTextMSZ( const char* string, _sge_TTFont* font, int x, int y, int flags, int fg, SDL_Surface* target, bool a_bTranslate ) { int retval = 0; if (!string || !*string) return retval; if ( a_bTranslate ) { string = Translate( string ); } if (flags & UseTilde) { char *str2 = strdup( string ); char onechar[2]; char *c1, *c2; int w = 0; int i, j; bool notend; if (flags & AlignHCenter) { // Determine width of the string without the stupid tildes c1 = c2 = str2; notend = true; while (notend) { c2 = c1; // c1: start of this run while (*c2 && (*c2!='~')) c2++; // c2: end of this run notend = *c2 != 0; *c2 = 0; sge_TTF_SizeText( font, c1, &i, &j); w += i; if (notend) { *c2='~'; c1=c2+1; } // next run.. } x -= w/2; } flags &= ~(UseTilde | AlignHCenter); c1 = str2; onechar[1]=0; notend = true; while (1) { c2 = c1; while (*c2 && (*c2!='~')) c2++; // c2: end of this run notend = *c2 != 0; *c2 = 0; sge_TTF_SizeText( font, c1, &i, &j); DrawTextMSZ( c1, font, x, y, flags, fg, target, false ); x += i; // At this point, we're either at a ~ or end of the text (notend) if (!notend) break; onechar[0]= *++c2; // Could be 0, if ~ at end. if (!onechar[0]) break; sge_TTF_SizeText( font, onechar, &i, &j); DrawTextMSZ( onechar, font, x, y, flags, C_LIGHTCYAN, target, false ); x += i; retval += i; c1 = c2+1; if (!*c1) break; // ~X was end of string } delete( str2 ); return retval; } SDL_Rect dest; int w, h; sge_TTF_SizeText( font, string, &w, &h ); dest.w = retval = w; dest.h = h; dest.x = flags & AlignHCenter ? x-dest.w/2 : x; dest.y = flags & AlignVCenter ? y-dest.h/2 : y; //debug( "X: %d, Y: %d, W: %d, H: %d\n", dest.x, dest.y, dest.w, dest.h ); CSurfaceLocker oLock; if ( flags & UseShadow ) { #ifdef MSZ_USES_UTF8 sge_tt_textout_UTF8( target, font, string, dest.x+2, dest.y+2+sge_TTF_FontAscent(font), C_BLACK, C_BLACK, 255 ); #else sge_tt_textout( target, font, string, dest.x+2, dest.y+2+sge_TTF_FontAscent(font), C_BLACK, C_BLACK, 255 ); #endif } sge_TTF_AAOn(); #ifdef MSZ_USES_UTF8 dest = sge_tt_textout_UTF8( target, font, string, dest.x, dest.y+sge_TTF_FontAscent(font), fg, C_BLACK, 255 ); #else dest = sge_tt_textout( target, font, string, dest.x, dest.y+sge_TTF_FontAscent(font), fg, C_BLACK, 255 ); #endif sge_TTF_AAOff(); return dest.w; }