From: Laszlo T. <ave...@us...> - 2004-10-10 13:27:33
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18499 Modified Files: Font.cpp Font.h Log Message: Implemented rendering of initials (in text) Index: Font.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Font.cpp,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Font.cpp 11 Sep 2004 07:43:55 -0000 1.35 --- Font.cpp 10 Oct 2004 13:26:18 -0000 1.36 *************** *** 106,140 **** count++; lastX += w; - /*if(count == 0) { - palette = core->GetVideoDriver()->GetPalette(spr); - } - if(maxHeight < spr->YPos) - maxHeight = spr->YPos; - //chars.push_back(spr); - chars[count++] = spr;*/ } - bool written = false; - void Font::PrintFromLine(int startrow, Region rgn, unsigned char* string, ! Color* hicolor, unsigned char Alignment, bool /*anchor*/, Font* /*initials*/, Color* initcolor, Sprite2D* cursor, unsigned int curpos) { - Color* pal = NULL, * ipal = NULL; unsigned int psx = PARAGRAPH_START_X; ! pal = hicolor; ! if (ipal != NULL) { ! ipal = initcolor; ! } else { ! ipal = pal; ! } if (!pal) { pal = palette; } ! /*for(int i = 0; i < 255; i++) { ! core->GetVideoDriver()->SetPalette(chars[i], pal); ! }*/ ! core->GetVideoDriver()->SetPalette( sprBuffer, pal ); Video* video = core->GetVideoDriver(); size_t len = strlen( ( char* ) string ); char* tmp = ( char* ) malloc( len + 1 ); --- 106,126 ---- count++; lastX += w; } void Font::PrintFromLine(int startrow, Region rgn, unsigned char* string, ! Color* hicolor, unsigned char Alignment, bool anchor, Font* initials, Color* initcolor, Sprite2D* cursor, unsigned int curpos) { unsigned int psx = PARAGRAPH_START_X; ! Color *pal = hicolor; if (!pal) { pal = palette; } ! if (startrow || (initials==this) ) { ! initials = NULL; ! } ! Video* video = core->GetVideoDriver(); + video->SetPalette( sprBuffer, pal ); size_t len = strlen( ( char* ) string ); char* tmp = ( char* ) malloc( len + 1 ); *************** *** 144,154 **** if (Alignment & IE_FONT_SINGLE_LINE) { for (size_t i = 0; i < len; i++) { ! if (tmp[i] != 0) ! if (ystep < yPos[( unsigned char ) tmp[i] - 1])//chars[(unsigned char)tmp[i]-1]->YPos) ! ystep = yPos[( unsigned char ) tmp[i] - 1];//chars[(unsigned char)tmp[i]-1]->YPos; } } else { ystep = size[1].h; ! }//chars[1]->Height; int x = psx, y = ystep; if (Alignment & IE_FONT_ALIGN_CENTER) { --- 130,140 ---- if (Alignment & IE_FONT_SINGLE_LINE) { for (size_t i = 0; i < len; i++) { ! if (tmp[i] == 0) continue; ! if (ystep < yPos[( unsigned char ) tmp[i] - 1]) ! ystep = yPos[( unsigned char ) tmp[i] - 1]; } } else { ystep = size[1].h; ! } int x = psx, y = ystep; if (Alignment & IE_FONT_ALIGN_CENTER) { *************** *** 194,204 **** continue; Color c = {r,g, b, 0}, back = {0, 0, 0, 0}; ! Color* newPal = core->GetVideoDriver()->CreatePalette( c, ! back ); ! core->GetVideoDriver()->SetPalette( sprBuffer, newPal ); free( newPal ); } else { if (stricmp( tag, "/color" ) == 0) { ! core->GetVideoDriver()->SetPalette( sprBuffer, pal ); } else { if (stricmp( "p", tag ) == 0) { --- 180,189 ---- continue; Color c = {r,g, b, 0}, back = {0, 0, 0, 0}; ! Color* newPal = video->CreatePalette( c, back ); ! video->SetPalette( sprBuffer, newPal ); free( newPal ); } else { if (stricmp( tag, "/color" ) == 0) { ! video->SetPalette( sprBuffer, pal ); } else { if (stricmp( "p", tag ) == 0) { *************** *** 232,247 **** } unsigned char currChar = ( unsigned char ) tmp[i] - 1; ! x += xPos[currChar];//spr->XPos; video->BlitSpriteRegion( sprBuffer, size[currChar], ! x + rgn.x - xPos[currChar], y + rgn.y - yPos[currChar], true, ! &rgn ); ! if (cursor && ( i == curpos )) ! video->BlitSprite( cursor, x - xPos[currChar] + rgn.x, y + rgn.y, ! true, &rgn ); x += size[currChar].w - xPos[currChar]; } if (cursor && ( curpos == len )) { ! video->BlitSprite( cursor, x - xPos[tmp[len] - 1] + rgn.x, y + rgn.y, ! true, &rgn ); } free( tmp ); --- 217,239 ---- } unsigned char currChar = ( unsigned char ) tmp[i] - 1; ! if (initials) { ! x = initials->PrintInitial( x, y, rgn, currChar, ! initcolor, anchor ); ! initials = NULL; ! continue; ! } ! x += xPos[currChar]; video->BlitSpriteRegion( sprBuffer, size[currChar], ! x + rgn.x - xPos[currChar], y + rgn.y - yPos[currChar], ! true, &rgn ); ! if (cursor && ( i == curpos )) { ! video->BlitSprite( cursor, x - xPos[currChar] + rgn.x, ! y + rgn.y, true, &rgn ); ! } x += size[currChar].w - xPos[currChar]; } if (cursor && ( curpos == len )) { ! video->BlitSprite( cursor, x - xPos[tmp[len] - 1] + rgn.x, ! y + rgn.y, true, &rgn ); } free( tmp ); *************** *** 249,269 **** void Font::Print(Region rgn, unsigned char* string, Color* hicolor, ! unsigned char Alignment, bool anchor, Font* /*initials*/, Color* initcolor, ! Sprite2D* cursor, unsigned int curpos) { - Color* pal = NULL, * ipal = NULL; unsigned int psx = PARAGRAPH_START_X; ! pal = hicolor; ! if (ipal != NULL) { ! ipal = initcolor; ! } else { ! ipal = pal; ! } if (!pal) { pal = palette; } - core->GetVideoDriver()->SetPalette( sprBuffer, pal ); Video* video = core->GetVideoDriver(); size_t len = strlen( ( char* ) string ); char* tmp = ( char* ) malloc( len + 1 ); --- 241,258 ---- void Font::Print(Region rgn, unsigned char* string, Color* hicolor, ! unsigned char Alignment, bool anchor, Font* initials, ! Color* initcolor, Sprite2D* cursor, unsigned int curpos) { unsigned int psx = PARAGRAPH_START_X; ! Color* pal = hicolor; if (!pal) { pal = palette; } + if (initials==this) { + initials = NULL; + } Video* video = core->GetVideoDriver(); + video->SetPalette( sprBuffer, pal ); size_t len = strlen( ( char* ) string ); char* tmp = ( char* ) malloc( len + 1 ); *************** *** 273,283 **** if (Alignment & IE_FONT_SINGLE_LINE) { for (size_t i = 0; i < len; i++) { ! if (tmp[i] != 0) ! if (ystep < yPos[( unsigned char ) tmp[i] - 1])//chars[(unsigned char)tmp[i]-1]->YPos) ! ystep = yPos[( unsigned char ) tmp[i] - 1];//chars[(unsigned char)tmp[i]-1]->YPos; } } else { ystep = size[1].h; ! }//chars[1]->Height; int x = psx, y = ystep; if (Alignment & IE_FONT_ALIGN_CENTER) { --- 262,272 ---- if (Alignment & IE_FONT_SINGLE_LINE) { for (size_t i = 0; i < len; i++) { ! if (tmp[i] == 0) continue; ! if (ystep < yPos[( unsigned char ) tmp[i] - 1]) ! ystep = yPos[( unsigned char ) tmp[i] - 1]; } } else { ystep = size[1].h; ! } int x = psx, y = ystep; if (Alignment & IE_FONT_ALIGN_CENTER) { *************** *** 323,333 **** continue; Color c = {r,g, b, 0}, back = {0, 0, 0, 0}; ! Color* newPal = core->GetVideoDriver()->CreatePalette( c, ! back ); ! core->GetVideoDriver()->SetPalette( sprBuffer, newPal ); free( newPal ); } else { if (stricmp( tag, "/color" ) == 0) { ! core->GetVideoDriver()->SetPalette( sprBuffer, pal ); } else { if (stricmp( "p", tag ) == 0) { --- 312,321 ---- continue; Color c = {r,g, b, 0}, back = {0, 0, 0, 0}; ! Color* newPal = video->CreatePalette( c, back ); ! video->SetPalette( sprBuffer, newPal ); free( newPal ); } else { if (stricmp( tag, "/color" ) == 0) { ! video->SetPalette( sprBuffer, pal ); } else { if (stricmp( "p", tag ) == 0) { *************** *** 355,374 **** } unsigned char currChar = ( unsigned char ) tmp[i] - 1; ! x += xPos[currChar];//spr->XPos; video->BlitSpriteRegion( sprBuffer, size[currChar], ! x + rgn.x - xPos[currChar], y + rgn.y - yPos[currChar], ! anchor, &rgn ); if (cursor && ( curpos == i )) ! video->BlitSprite( cursor, x - xPos[currChar] + rgn.x, y + rgn.y, ! anchor, &rgn ); ! x += size[currChar].w - xPos[currChar];//spr->Width-spr->XPos; } if (cursor && ( curpos == len )) { ! video->BlitSprite( cursor, x - xPos[tmp[len] - 1] + rgn.x, y + rgn.y, ! anchor, &rgn ); } free( tmp ); } int Font::CalcStringWidth(char* string) { --- 343,381 ---- } unsigned char currChar = ( unsigned char ) tmp[i] - 1; ! if (initials) { ! x = initials->PrintInitial( x, y, rgn, currChar, ! initcolor, anchor ); ! initials = NULL; ! continue; ! } ! x += xPos[currChar]; video->BlitSpriteRegion( sprBuffer, size[currChar], ! x + rgn.x - xPos[currChar], y + rgn.y - yPos[currChar], ! anchor, &rgn ); if (cursor && ( curpos == i )) ! video->BlitSprite( cursor, x - xPos[currChar] + rgn.x, y + rgn.y, anchor, &rgn ); ! x += size[currChar].w - xPos[currChar]; } if (cursor && ( curpos == len )) { ! video->BlitSprite( cursor, x - xPos[tmp[len] - 1] + rgn.x, y + rgn.y, anchor, &rgn ); } free( tmp ); } + int Font::PrintInitial(int x, int y, Region rgn, char currChar, Color *ipal, + bool anchor) + { + Video *video = core->GetVideoDriver(); + if (!ipal) + ipal = palette; + video->SetPalette( sprBuffer, ipal ); + x += xPos[currChar]; + video->BlitSpriteRegion( sprBuffer, size[currChar], + x + rgn.x - xPos[currChar], y + rgn.y - yPos[currChar], + anchor, &rgn ); + x += size[currChar].w - xPos[currChar]; + return x; + } + int Font::CalcStringWidth(char* string) { Index: Font.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Font.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Font.h 11 Sep 2004 07:43:55 -0000 1.16 --- Font.h 10 Oct 2004 13:26:19 -0000 1.17 *************** *** 67,76 **** void AddChar(void* spr, int w, int h, short xPos, short yPos); void Print(Region rgn, unsigned char* string, Color* color, ! unsigned char Alignment, bool anchor = false, Font* initials = NULL, ! Color* initcolor = NULL, Sprite2D* cursor = NULL, unsigned int curpos = 0); void PrintFromLine(int startrow, Region rgn, unsigned char* string, Color* color, unsigned char Alignment, bool anchor = false, Font* initials = NULL, Color* initcolor = NULL, Sprite2D* cursor = NULL, unsigned int curpos = 0); void* GetPalette(); char ResRef[9]; --- 67,79 ---- void AddChar(void* spr, int w, int h, short xPos, short yPos); void Print(Region rgn, unsigned char* string, Color* color, ! unsigned char Alignment, bool anchor = false, ! Font* initials = NULL, Color* initcolor = NULL, ! Sprite2D* cursor = NULL, unsigned int curpos = 0); void PrintFromLine(int startrow, Region rgn, unsigned char* string, Color* color, unsigned char Alignment, bool anchor = false, Font* initials = NULL, Color* initcolor = NULL, Sprite2D* cursor = NULL, unsigned int curpos = 0); + int PrintInitial(int x, int y, Region rgn, char currChar, + Color *ipal=NULL, bool anchor = false); void* GetPalette(); char ResRef[9]; |