hedgewars/uStore.pas
changeset 2022 9bbf8af42ace
parent 2019 b3f1eda8865f
child 2023 41d3afaa20c7
equal deleted inserted replaced
2021:a591afb43768 2022:9bbf8af42ace
   706 edgeHeight:= SpritesData[edge].Height;
   706 edgeHeight:= SpritesData[edge].Height;
   707 edgeWidth:= SpritesData[edge].Width;
   707 edgeWidth:= SpritesData[edge].Width;
   708 cornerWidth:= SpritesData[corner].Width;
   708 cornerWidth:= SpritesData[corner].Width;
   709 cornerHeight:= SpritesData[corner].Height;
   709 cornerHeight:= SpritesData[corner].Height;
   710 // This one screws it up
   710 // This one screws it up
   711 s:= 'This is the song that never ends.  ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...';
   711 //s:= 'This is the song that never ends.  ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...';
   712 // This one doesn't
   712 // This one doesn't
   713 //s:= 'This is the song that never ends.  cause it goes on and on my friends. Some people, started singing it not knowing what it was. And theyll just go on singing it forever just because... This is the song that never ends... ';
   713 //s:= 'This is the song that never ends.  cause it goes on and on my friends. Some people, started singing it not knowing what it was. And theyll just go on singing it forever just because... This is the song that never ends... ';
   714 // Also screws up, but only action
   714 // Also screws up, but only action
   715 //s:= 'This is the song that never ends.  cause it goes on and on .';
   715 //s:= 'This is the song that never ends.  cause it goes on and on .';
   716 // ok in all
   716 // ok in all
   717 // s:= 'This is the song that never ends.  cause it goes on .';
   717 // s:= 'This is the song that never ends.  cause it goes on .';
   718 numLines:= 1;
   718 numLines:= 0;
   719 
   719 
   720 if length(s) = 0 then s:= '...';
   720 if length(s) = 0 then s:= '...';
   721 
   721 
   722 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   722 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   723 textWidth:= w;
   723 textWidth:= w;
   728     s:= WrapText(s, #1, chars, i);
   728     s:= WrapText(s, #1, chars, i);
   729     for pos:= 1 to length(s) do
   729     for pos:= 1 to length(s) do
   730         if (s[pos] = #1) or (pos = length(s)) then
   730         if (s[pos] = #1) or (pos = length(s)) then
   731             inc(numLines);
   731             inc(numLines);
   732 
   732 
   733     // TODO - find out why this calc doesn't do what I expect
   733     textWidth:= round(w/(numLines)) + 12;
   734     if numLines = 2 then textWidth:= w div 2
       
   735     else if numlines > 2 then textWidth:= w div (numLines-1);
       
   736     end;
   734     end;
   737 
   735 
   738 textWidth:=((textWidth-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth;
   736 textWidth:=((textWidth-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth;
   739 textHeight:=(((numlines * h)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth+edgeWidth;
   737 textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth;
   740 
   738 
       
   739 textHeight:=max(textHeight,edgeWidth);
   741 //textWidth:=max(textWidth,SpritesData[tail].Width);
   740 //textWidth:=max(textWidth,SpritesData[tail].Width);
   742 rect.x:= 0;
   741 rect.x:= 0;
   743 rect.y:= 0;
   742 rect.y:= 0;
   744 rect.w:= textWidth + cornerWidth * 2;
   743 rect.w:= textWidth + (cornerWidth * 2);
   745 rect.h:= textHeight + cornerHeight * 2 - edgeHeight + SpritesData[tail].Height;
   744 rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height;
   746 //s:= inttostr(h) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h) + ' ' + s;
   745 //s:= inttostr(h) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h) + ' ' + s;
   747 
   746 
   748 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask);
   747 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask);
   749 
   748 
   750 TryDo(Result <> nil, 'RenderString: fail to create surface', true);
   749 TryDo(Result <> nil, 'RenderString: fail to create surface', true);
   826         while s[prevpos+1] = ' 'do inc(prevpos);
   825         while s[prevpos+1] = ' 'do inc(prevpos);
   827         substr:= copy(s, prevpos+1, pos-prevpos-1);
   826         substr:= copy(s, prevpos+1, pos-prevpos-1);
   828         if Length(substr) <> 0 then
   827         if Length(substr) <> 0 then
   829            begin
   828            begin
   830            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack);
   829            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack);
   831            rect.x:= edgeHeight;
   830            rect.x:= edgeHeight+4;
   832            rect.y:= edgeHeight + line * h;
   831            // trying to more evenly position the text, vertically
       
   832            rect.y:= max(edgeHeight,3+(rect.h-(numLines*h)) div 2) + line * h;
   833            SDLTry(tmpsurf <> nil, true);
   833            SDLTry(tmpsurf <> nil, true);
   834            SDL_UpperBlit(tmpsurf, nil, Result, @rect);
   834            SDL_UpperBlit(tmpsurf, nil, Result, @rect);
   835            SDL_FreeSurface(tmpsurf);
   835            SDL_FreeSurface(tmpsurf);
   836            inc(line);
   836            inc(line);
   837            prevpos:= pos;
   837            prevpos:= pos;