449 |
449 |
450 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
450 procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
451 begin |
451 begin |
452 glPushMatrix; |
452 glPushMatrix; |
453 glTranslatef(X, Y, 0); |
453 glTranslatef(X, Y, 0); |
454 glRotatef(Angle, 0, 0, 1); |
454 |
455 |
455 if Dir < 0 then |
|
456 glRotatef(Angle, 0, 0, -1) |
|
457 else |
|
458 glRotatef(Angle, 0, 0, 1); |
456 if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
459 if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
457 |
460 |
458 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
461 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
459 |
462 |
460 glPopMatrix |
463 glPopMatrix |
676 |
679 |
677 SDL_FreeSurface(Result) |
680 SDL_FreeSurface(Result) |
678 end; |
681 end; |
679 |
682 |
680 function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
683 function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
681 var textWidth, textHeight, x, y, w, h, i, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
684 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
682 Result, tmpsurf, rotatedEdge: PSDL_Surface; |
685 Result, tmpsurf, rotatedEdge: PSDL_Surface; |
683 rect: TSDL_Rect; |
686 rect: TSDL_Rect; |
684 chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
687 chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
685 substr: shortstring; |
688 substr: shortstring; |
686 edge, corner, tail: TSPrite; |
689 edge, corner, tail: TSPrite; |
705 end; |
708 end; |
706 edgeHeight:= SpritesData[edge].Height; |
709 edgeHeight:= SpritesData[edge].Height; |
707 edgeWidth:= SpritesData[edge].Width; |
710 edgeWidth:= SpritesData[edge].Width; |
708 cornerWidth:= SpritesData[corner].Width; |
711 cornerWidth:= SpritesData[corner].Width; |
709 cornerHeight:= SpritesData[corner].Height; |
712 cornerHeight:= SpritesData[corner].Height; |
710 // This one screws it up |
713 // This one screws up WrapText |
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...'; |
714 //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 |
715 // 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... '; |
716 //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 will go on singing it forever just because... This is the song that never ends... '; |
714 // Also screws up, but only action |
717 |
715 //s:= 'This is the song that never ends. cause it goes on and on .'; |
|
716 // ok in all |
|
717 // s:= 'This is the song that never ends. cause it goes on .'; |
|
718 numLines:= 0; |
718 numLines:= 0; |
719 |
719 |
720 if length(s) = 0 then s:= '...'; |
720 if length(s) = 0 then s:= '...'; |
721 |
|
722 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
721 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
723 textWidth:= w; |
722 j:= 0; |
724 textHeight:= h; |
|
725 if (length(s) > 20) then |
723 if (length(s) > 20) then |
726 begin |
724 begin |
|
725 w:= 0; |
727 i:= round(Sqrt(length(s)) * 2); |
726 i:= round(Sqrt(length(s)) * 2); |
728 s:= WrapText(s, #1, chars, i); |
727 s:= WrapText(s, #1, chars, i); |
729 for pos:= 1 to length(s) do |
728 pos:= 1; prevpos:= 0; line:= 0; |
|
729 // Find the longest line for the purposes of centring the text. Font dependant. |
|
730 while pos <= length(s) do |
|
731 begin |
730 if (s[pos] = #1) or (pos = length(s)) then |
732 if (s[pos] = #1) or (pos = length(s)) then |
731 inc(numLines); |
733 begin |
732 |
734 inc(numlines); |
733 textWidth:= round(w/(numLines)) + 12; |
735 if s[pos] <> #1 then inc(pos); |
734 end; |
736 while s[prevpos+1] = ' ' do inc(prevpos); |
735 |
737 substr:= copy(s, prevpos+1, pos-prevpos-1); |
736 textWidth:=((textWidth-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
738 i:= 0; j:= 0; |
|
739 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j); |
|
740 if i > w then w:= i; |
|
741 prevpos:= pos; |
|
742 end; |
|
743 inc(pos); |
|
744 end; |
|
745 end |
|
746 else numLines := 1; |
|
747 |
|
748 textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
737 textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
749 textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
738 |
750 |
739 textHeight:=max(textHeight,edgeWidth); |
751 textHeight:=max(textHeight,edgeWidth); |
740 //textWidth:=max(textWidth,SpritesData[tail].Width); |
752 //textWidth:=max(textWidth,SpritesData[tail].Width); |
741 rect.x:= 0; |
753 rect.x:= 0; |
742 rect.y:= 0; |
754 rect.y:= 0; |
743 rect.w:= textWidth + (cornerWidth * 2); |
755 rect.w:= textWidth + (cornerWidth * 2); |
744 rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
756 rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
745 //s:= inttostr(h) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h) + ' ' + s; |
757 //s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
746 |
758 |
747 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
759 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
748 |
760 |
749 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
761 TryDo(Result <> nil, 'RenderString: fail to create surface', true); |
750 |
762 |
825 while s[prevpos+1] = ' 'do inc(prevpos); |
839 while s[prevpos+1] = ' 'do inc(prevpos); |
826 substr:= copy(s, prevpos+1, pos-prevpos-1); |
840 substr:= copy(s, prevpos+1, pos-prevpos-1); |
827 if Length(substr) <> 0 then |
841 if Length(substr) <> 0 then |
828 begin |
842 begin |
829 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack); |
843 tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cColorNearBlack); |
830 rect.x:= edgeHeight+4; |
844 rect.x:= edgeHeight + 1 + ((i - w) div 2); |
831 // trying to more evenly position the text, vertically |
845 // trying to more evenly position the text, vertically |
832 rect.y:= max(edgeHeight,3+(rect.h-(numLines*h)) div 2) + line * h; |
846 rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
833 SDLTry(tmpsurf <> nil, true); |
847 SDLTry(tmpsurf <> nil, true); |
834 SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
848 SDL_UpperBlit(tmpsurf, nil, Result, @rect); |
835 SDL_FreeSurface(tmpsurf); |
849 SDL_FreeSurface(tmpsurf); |
836 inc(line); |
850 inc(line); |
837 prevpos:= pos; |
851 prevpos:= pos; |