Complete.Org:
Mailing Lists:
Archives:
freeciv-dev:
February 2003: [Freeciv-Dev] (PR#3480) New Buffer Code |
[Freeciv-Dev] (PR#3480) New Buffer Code[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This code is big with lot of changes ( touch almost entire SDLClient) Some change : - new buffer system. - partial support for waste in city dlg. ( no place for waste string ) - animated unit sellector ( replace blinking unit ) - porting new dlg options ( dont ask for city name and don't open city dlg for new cities) - default Civ3 city desc. text. - fix network connection check. - support for meta servers. - fix for sellect races dlg. - lot of fix and cleans. this code requ. : - patch to SDL_ttf lib ( attached - blended_shaded3.diff is targeted t cvs version of SDL_ttf2 lib) - patch to freeciv : new flush code - patch to freeciv : clear_city_desc. - new graphics ( attached - must be copy to theme dir) Rafal
new_buffer_code.diff.bz2 diff -u -r SDL_ttf2a/SDL_ttf.c SDL_ttf2/SDL_ttf.c --- SDL_ttf2a/SDL_ttf.c Mon Feb 10 15:29:09 2003 +++ SDL_ttf2/SDL_ttf.c Sun Feb 16 01:27:10 2003 @@ -1603,6 +1603,276 @@ return(textbuf); } +/* Convert the Latin-1 text to UNICODE and render it +*/ +SDL_Surface *TTF_RenderText_Blended_Shaded(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg) +{ + SDL_Surface *textbuf; + Uint16 *unicode_text; + int unicode_len; + + /* Copy the Latin-1 text to a UNICODE text buffer */ + unicode_len = strlen(text); + unicode_text = (Uint16 *)ALLOCA((1+unicode_len+1)*(sizeof *unicode_text)); + if ( unicode_text == NULL ) { + TTF_SetError("Out of memory"); + return(NULL); + } + *unicode_text = UNICODE_BOM_NATIVE; + LATIN1_to_UNICODE(unicode_text+1, text, unicode_len); + + /* Render the new text */ + textbuf = TTF_RenderUNICODE_Blended_Shaded(font, unicode_text, fg, bg); + + /* Free the text buffer and return */ + free(unicode_text); + return(textbuf); +} + +/* Convert the UTF-8 text to UNICODE and render it +*/ +SDL_Surface *TTF_RenderUTF8_Blended_Shaded(TTF_Font *font, + const char *text, SDL_Color fg, SDL_Color bg) +{ + SDL_Surface *textbuf; + Uint16 *unicode_text; + int unicode_len; + + /* Copy the UTF-8 text to a UNICODE text buffer */ + unicode_len = strlen(text); + unicode_text = (Uint16 *)ALLOCA((1+unicode_len+1)*(sizeof *unicode_text)); + if ( unicode_text == NULL ) { + TTF_SetError("Out of memory"); + return(NULL); + } + *unicode_text = UNICODE_BOM_NATIVE; + UTF8_to_UNICODE(unicode_text+1, text, unicode_len); + + /* Render the new text */ + textbuf = TTF_RenderUNICODE_Blended_Shaded(font, unicode_text, fg, bg); + + /* Free the text buffer and return */ + free(unicode_text); + return(textbuf); +} + +SDL_Surface *TTF_RenderUNICODE_Blended_Shaded(TTF_Font *font, + const Uint16 *text, SDL_Color fg, SDL_Color bg) +{ + int xstart; + int width, height; + SDL_Surface *textbuf; + Uint32 alpha; + Uint32 dst_pixel; + Uint32 pixel; + Uint32 buf1, buf2; + const Uint16 *ch; + Uint8 *src; + Uint32 *dst; + int row, col; + int swapped; + c_glyph *glyph; + FT_Error error; + + if(!bg.unused) { /* background ALPHA = 0 */ + return TTF_RenderUNICODE_Blended(font, text, fg); + } + + /* Get the dimensions of the text surface */ + if ( (TTF_SizeUNICODE(font, text, &width, NULL) < 0) || !width ) { + TTF_SetError("Text has zero width"); + return(NULL); + } + height = font->height; + + textbuf = SDL_AllocSurface(SDL_SWSURFACE, width, height, 32, + 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + if ( textbuf == NULL ) { + return(NULL); + } + + /* Load and render each character */ + xstart = 0; + swapped = TTF_byteswapped; + pixel = (fg.r<<16)|(fg.g<<8)|fg.b|0xFF000000; + dst_pixel = (bg.unused<<24)|(bg.r<<16)|(bg.g<<8)|bg.b; + + buf1 = (pixel & 0x00FF00FF) - (dst_pixel & 0x00FF00FF); + buf2 = ((pixel & 0xFF00FF00) >> 8) - ((dst_pixel & 0xFF00FF00) >> 8); + + SDL_FillRect(textbuf, NULL , dst_pixel); + + for ( ch=text; *ch; ++ch ) { + Uint16 c = *ch; + if ( c == UNICODE_BOM_NATIVE ) { + swapped = 0; + if ( text == ch ) { + ++text; + } + continue; + } + if ( c == UNICODE_BOM_SWAPPED ) { + swapped = 1; + if ( text == ch ) { + ++text; + } + continue; + } + if ( swapped ) { + c = SDL_Swap16(c); + } + + error = Find_Glyph(font, *ch, CACHED_METRICS|CACHED_PIXMAP); + if( error ) { + SDL_FreeSurface( textbuf ); + return NULL; + } + glyph = font->current; + width = glyph->pixmap.width; + + /* Compensate for the wrap around bug with negative minx's */ + if ( (ch == text) && (glyph->minx < 0) ) { + xstart -= glyph->minx; + } + + for ( row = 0; row < glyph->pixmap.rows; ++row ) { + /* Make sure we don't go over the limit */ + if ( row+glyph->yoffset >= textbuf->h ) { + continue; + } + dst = (Uint32*) textbuf->pixels + + (row+glyph->yoffset) * textbuf->pitch/4 + + xstart + glyph->minx; + /* Added code to adjust src pointer for pixmaps to + * account for pitch. + * */ + src = (Uint8*) (glyph->pixmap.buffer + glyph->pixmap.pitch * row); + + for ( col=width; col>0; --col ) { + alpha = *src++; + if(alpha) + { + if(alpha == SDL_ALPHA_OPAQUE) + { + *dst = pixel; + } else { + *dst = (((dst_pixel & 0x00FF00FF) + + (buf1 * alpha >> 8)) & 0x00FF00FF) | + (((((dst_pixel & 0xFF00FF00) >> 8) + + (buf2 * alpha >> 8)) & 0x00FF00FF) << 8); + } + } + dst++; + } + } + + xstart += glyph->advance; + if ( font->style & TTF_STYLE_BOLD ) { + xstart += font->glyph_overhang; + } + } + + /* Handle the underline style */ + if( font->style & TTF_STYLE_UNDERLINE ) { + row = font->ascent - font->underline_offset - 1; + if ( row >= textbuf->h) { + row = (textbuf->h-1) - font->underline_height; + } + dst = (Uint32 *)textbuf->pixels + row * textbuf->pitch/4; + pixel |= 0xFF000000; /* Amask */ + for ( row=font->underline_height; row>0; --row ) { + for ( col=0; col < textbuf->w; ++col ) { + dst[col] = pixel; + } + dst += textbuf->pitch/4; + } + } + return(textbuf); +} + +SDL_Surface *TTF_RenderGlyph_Blended_Shaded(TTF_Font *font, + Uint16 ch, SDL_Color fg, SDL_Color bg) +{ + SDL_Surface *textbuf; + Uint32 alpha; + Uint32 dst_pixel; + Uint32 pixel; + Uint32 buf1, buf2; + Uint8 *src; + Uint32 *dst; + int row, col; + FT_Error error; + c_glyph *glyph; + + if(!bg.unused) { + return TTF_RenderGlyph_Blended(font, ch, fg); + } + + /* Get the glyph itself */ + error = Find_Glyph(font, ch, CACHED_METRICS|CACHED_PIXMAP); + if ( error ) { + return(NULL); + } + glyph = font->current; + + textbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, + glyph->pixmap.width, glyph->pixmap.rows, 32, + 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); + if ( ! textbuf ) { + return(NULL); + } + + /* Copy the character from the pixmap */ + pixel = (fg.r<<16)|(fg.g<<8)|fg.b|0xFF000000; + dst_pixel = (bg.unused<<24)|(bg.r<<16)|(bg.g<<8)|bg.b; + + buf1 = (pixel & 0x00FF00FF) - (dst_pixel & 0x00FF00FF); + buf2 = ((pixel & 0xFF00FF00) >> 8) - ((dst_pixel & 0xFF00FF00) >> 8); + + SDL_FillRect(textbuf, NULL , dst_pixel); + + for ( row=0; row<textbuf->h; ++row ) { + /* Changed src to take pitch into account, not just width */ + src = glyph->pixmap.buffer + row * glyph->pixmap.pitch; + dst = (Uint32 *)textbuf->pixels + row * textbuf->pitch/4; + for ( col=0; col<glyph->pixmap.width; ++col ) { + alpha = *src++; + if(alpha) + { + if(alpha == SDL_ALPHA_OPAQUE) + { + *dst = pixel; + } else { + *dst = (((dst_pixel & 0x00FF00FF) + + (buf1 * alpha >> 8)) & 0x00FF00FF) | + (((((dst_pixel & 0xFF00FF00) >> 8) + + (buf2 * alpha >> 8)) & 0x00FF00FF) << 8); + } + } + dst++; + } + } + + /* Handle the underline style */ + if( font->style & TTF_STYLE_UNDERLINE ) { + row = font->ascent - font->underline_offset - 1; + if ( row >= textbuf->h) { + row = (textbuf->h-1) - font->underline_height; + } + dst = (Uint32 *)textbuf->pixels + row * textbuf->pitch/4; + pixel |= 0xFF000000; /* Amask */ + for ( row=font->underline_height; row>0; --row ) { + for ( col=0; col < textbuf->w; ++col ) { + dst[col] = pixel; + } + dst += textbuf->pitch/4; + } + } + return(textbuf); +} + + void TTF_SetFontStyle( TTF_Font* font, int style ) { font->style = style; diff -u -r SDL_ttf2a/SDL_ttf.h SDL_ttf2/SDL_ttf.h --- SDL_ttf2a/SDL_ttf.h Mon Feb 10 15:29:09 2003 +++ SDL_ttf2/SDL_ttf.h Sun Feb 16 00:26:09 2003 @@ -195,6 +195,19 @@ extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended(TTF_Font *font, Uint16 ch, SDL_Color fg); + +/* */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Shaded( + TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg); +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended_Shaded( + TTF_Font *font, const char *text, SDL_Color fg, SDL_Color bg); +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended_Shaded( + TTF_Font *font, const Uint16 *text, SDL_Color fg, SDL_Color bg); + +/* */ +extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderGlyph_Blended_Shaded( + TTF_Font *font, Uint16 ch, SDL_Color fg, SDL_Color bg); + /* For compatibility with previous versions, here are the old functions */ #define TTF_RenderText(font, text, fg, bg) \ TTF_RenderText_Shaded(font, text, fg, bg)
anim1.png
anim2.png
anim3.png
anim4.png
order_nuke_buttons.png
order_paradrop_buttons.png
order_pillage_buttons.png
order_railroads_buttons.png
|