hedgewars/uStore.pas
changeset 2677 83ad68ceef72
parent 2674 2fce032f2f95
child 2679 b61d25fa6c53
equal deleted inserted replaced
2676:03bf7a96400a 2677:83ad68ceef72
    43 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    43 procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real);
    44 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    44 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    45 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    45 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    46 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    46 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    47 procedure DrawFillRect(r: TSDL_Rect);
    47 procedure DrawFillRect(r: TSDL_Rect);
       
    48 function  CheckCJKFont(s: string; font: THWFont): THWFont;
    48 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
    49 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
    49 function  RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture;
    50 function  RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture;
    50 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
    51 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
    51 //procedure rotateSurface(Surface: PSDL_Surface);
    52 //procedure rotateSurface(Surface: PSDL_Surface);
    52 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    53 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
   751     end;
   752     end;
   752 
   753 
   753 FreeTexture(HHTexture)
   754 FreeTexture(HHTexture)
   754 end;
   755 end;
   755 
   756 
       
   757 
       
   758 function CheckCJKFont(s: string; font: THWFont): THWFont;
       
   759 var l, i, u : LongInt;
       
   760     tmpstr: array[0..256] of WideChar;
       
   761 begin
       
   762 if font >= CJKfntSmall then exit(font);
       
   763 
       
   764 l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), 255);
       
   765 i:= 0;
       
   766 while i < l do
       
   767     begin
       
   768     u:= LongInt(tmpstr[i]);
       
   769     //AddFileLog(IntToStr(u));
       
   770     if (($2E80  <= u) and (u >= $2FDF))  or // CJK Radicals Supplement / Kangxi Radicals
       
   771        (($2FF0  <= u) and (u >= $303F))  or // Ideographic Description Characters / CJK Radicals Supplement
       
   772        (($31C0  <= u) and (u >= $31EF))  or // CJK Strokes
       
   773        (($3200  <= u) and (u >= $4DBF))  or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A
       
   774        (($4E00  <= u) and (u >= $9FFF))  or // CJK Unified Ideographs
       
   775        (($F900  <= u) and (u >= $FAFF))  or // CJK Compatibility Ideographs
       
   776        (($FE30  <= u) and (u >= $FE4F))  or // CJK Compatibility Forms
       
   777        (($20000 <= u) and (u >= $2A6DF)) or // CJK Unified Ideographs Extension B
       
   778        (($2F800 <= u) and (u >= $2FA1F))    // CJK Compatibility Ideographs Supplement
       
   779        then exit(THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) ));
       
   780     inc(i)
       
   781     end;
       
   782 exit(font);
       
   783 end;
       
   784 
   756 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
   785 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
   757 var w, h: LongInt;
   786 var w, h : LongInt;
   758     Result: PSDL_Surface;
   787     Result: PSDL_Surface;
   759 begin
   788 begin
   760 if length(s) = 0 then s:= ' ';
   789 if length(s) = 0 then s:= ' ';
       
   790 font:= CheckCJKFont(s, font);
   761 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   791 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   762 
   792 
   763 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   793 Result:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   764          32, RMask, GMask, BMask, AMask);
   794          32, RMask, GMask, BMask, AMask);
   765 
   795 
   810 //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... ';
   840 //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... ';
   811 
   841 
   812 numLines:= 0;
   842 numLines:= 0;
   813 
   843 
   814 if length(s) = 0 then s:= '...';
   844 if length(s) = 0 then s:= '...';
       
   845 font:= CheckCJKFont(s, font);
   815 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   846 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   816 if w<8 then w:= 8;
   847 if w<8 then w:= 8;
   817 j:= 0;
   848 j:= 0;
   818 if (length(s) > 20) then
   849 if (length(s) > 20) then
   819     begin
   850     begin