hedgewars/uStore.pas
changeset 3407 dcc129c4352e
parent 3405 8fdb08497bf1
child 3445 1ce844170014
equal deleted inserted replaced
3406:f4bdebced042 3407:dcc129c4352e
    18 
    18 
    19 {$INCLUDE "options.inc"}
    19 {$INCLUDE "options.inc"}
    20 
    20 
    21 unit uStore;
    21 unit uStore;
    22 interface
    22 interface
    23 uses sysutils, uConsts, uTeams, SDLh, uFloat, GLunit;
    23 uses sysutils, uConsts, uTeams, SDLh, GLunit;
    24 
    24 
    25 
    25 
    26 var PixelFormat: PSDL_PixelFormat;
    26 var PixelFormat: PSDL_PixelFormat;
    27     SDLPrimSurface: PSDL_Surface;
    27     SDLPrimSurface: PSDL_Surface;
    28     PauseTexture,
    28     PauseTexture,
    81 procedure ShowWeaponTooltip(x, y: LongInt);
    81 procedure ShowWeaponTooltip(x, y: LongInt);
    82 procedure FreeWeaponTooltip;
    82 procedure FreeWeaponTooltip;
    83 procedure Tint(r, g, b, a: Byte); inline;
    83 procedure Tint(r, g, b, a: Byte); inline;
    84 
    84 
    85 implementation
    85 implementation
    86 uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF};
    86 uses uMisc, uConsole, uLocale{$IFDEF IPHONEOS}, PascalExports{$ENDIF};
    87 
    87 
    88 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    88 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    89 
    89 
    90 var HHTexture: PTexture;
    90 var HHTexture: PTexture;
    91     MaxTextureSize: LongInt;
    91     MaxTextureSize: LongInt;
   135 var w, h: LongInt;
   135 var w, h: LongInt;
   136     tmpsurf: PSDL_Surface;
   136     tmpsurf: PSDL_Surface;
   137     clr: TSDL_Color;
   137     clr: TSDL_Color;
   138     finalRect: TSDL_Rect;
   138     finalRect: TSDL_Rect;
   139 begin
   139 begin
       
   140 w:= 0; h:= 0; // avoid compiler hints
   140 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
   141 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
   141 finalRect.x:= X;
   142 finalRect.x:= X;
   142 finalRect.y:= Y;
   143 finalRect.y:= Y;
   143 finalRect.w:= w + FontBorder * 2 + 4;
   144 finalRect.w:= w + FontBorder * 2 + 4;
   144 finalRect.h:= h + FontBorder * 2;
   145 finalRect.h:= h + FontBorder * 2;
   163 var w, h: LongInt;
   164 var w, h: LongInt;
   164     tmpsurf: PSDL_Surface;
   165     tmpsurf: PSDL_Surface;
   165     clr: TSDL_Color;
   166     clr: TSDL_Color;
   166     finalRect: TSDL_Rect;
   167     finalRect: TSDL_Rect;
   167 begin
   168 begin
       
   169 w:= 0; h:= 0; // avoid compiler hints
   168 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
   170 TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h);
   169 finalRect.x:= X + FontBorder + 2;
   171 finalRect.x:= X + FontBorder + 2;
   170 finalRect.y:= Y + FontBorder;
   172 finalRect.y:= Y + FontBorder;
   171 finalRect.w:= w + FontBorder * 2 + 4;
   173 finalRect.w:= w + FontBorder * 2 + 4;
   172 finalRect.h:= h + FontBorder * 2;
   174 finalRect.h:= h + FontBorder * 2;
   843        ((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B
   845        ((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B
   844        ((#$2F800 <= u) and (u >= #$2FA1F)))   // CJK Compatibility Ideographs Supplement *)
   846        ((#$2F800 <= u) and (u >= #$2FA1F)))   // CJK Compatibility Ideographs Supplement *)
   845 end;
   847 end;
   846 
   848 
   847 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
   849 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
   848 var w, h : LongInt;
   850 var w, h: LongInt;
   849     finalSurface: PSDL_Surface;
   851     finalSurface: PSDL_Surface;
   850 begin
   852 begin
   851 if length(s) = 0 then s:= ' ';
   853 if length(s) = 0 then s:= ' ';
   852 font:= CheckCJKFont(s, font);
   854 font:= CheckCJKFont(s, font);
       
   855 w:= 0; h:= 0; // avoid compiler hints
   853 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   856 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   854 
   857 
   855 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   858 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2,
   856          32, RMask, GMask, BMask, AMask);
   859          32, RMask, GMask, BMask, AMask);
   857 
   860 
   903 
   906 
   904 numLines:= 0;
   907 numLines:= 0;
   905 
   908 
   906 if length(s) = 0 then s:= '...';
   909 if length(s) = 0 then s:= '...';
   907 font:= CheckCJKFont(s, font);
   910 font:= CheckCJKFont(s, font);
       
   911 w:= 0; h:= 0; // avoid compiler hints
   908 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   912 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h);
   909 if w<8 then w:= 8;
   913 if w<8 then w:= 8;
   910 j:= 0;
   914 j:= 0;
   911 if (length(s) > 20) then
   915 if (length(s) > 20) then
   912     begin
   916     begin
  1060 
  1064 
  1061 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
  1065 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
  1062 var tmpsurf: PSDL_Surface;
  1066 var tmpsurf: PSDL_Surface;
  1063     s: shortstring;
  1067     s: shortstring;
  1064 begin
  1068 begin
  1065     WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
  1069     WriteToConsole(msgLoading + filename + '.png [flags:');
       
  1070     if imageFlags = ifNone then
       
  1071         WriteToConsole(' None')
       
  1072     else
       
  1073         begin
       
  1074         if (imageFlags and ifAlpha) <> 0 then WriteToConsole(' Alpha');
       
  1075         if (imageFlags and ifCritical) <> 0 then WriteToConsole(' Critical');
       
  1076         if (imageFlags and ifTransparent) <> 0 then WriteToConsole(' Transparent');
       
  1077         if (imageFlags and ifIgnoreCaps) <> 0 then WriteToConsole(' IgnoreCaps');
       
  1078         if (imageFlags and ifLowRes) <> 0 then WriteToConsole(' LowRes');
       
  1079         end;
       
  1080     WriteToConsole('] ');
  1066 
  1081 
  1067     s:= filename + '.png';
  1082     s:= filename + '.png';
  1068     tmpsurf:= IMG_Load(Str2PChar(s));
  1083     tmpsurf:= IMG_Load(Str2PChar(s));
  1069 
  1084 
  1070     if (imageFlags and ifLowRes) <> 0 then
  1085     if (imageFlags and ifLowRes) <> 0 then
  1107     tmpsurf:= doSurfaceConversion(tmpsurf);
  1122     tmpsurf:= doSurfaceConversion(tmpsurf);
  1108 
  1123 
  1109     if (imageFlags and ifTransparent) <> 0 then
  1124     if (imageFlags and ifTransparent) <> 0 then
  1110         TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
  1125         TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
  1111 
  1126 
  1112     WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
  1127     WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')');
  1113     WriteLnToConsole(msgOK);
       
  1114 
  1128 
  1115     LoadImage:= tmpsurf //Result
  1129     LoadImage:= tmpsurf //Result
  1116 end;
  1130 end;
  1117 
  1131 
  1118 function glLoadExtension(extension : shortstring) : boolean;
  1132 function glLoadExtension(extension : shortstring) : boolean;
  1351       j:= srcY * (src^.pitch div 4) + srcX;
  1365       j:= srcY * (src^.pitch div 4) + srcX;
  1352       if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then
  1366       if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then
  1353          begin
  1367          begin
  1354          SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0);
  1368          SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0);
  1355          SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1);
  1369          SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1);
  1356          destPixels^[i]:= SDL_MapRGBA(dest^.format, (r0 * (255 - a1) + r1 * a1) div 255, (g0 * (255 - a1) + g1 * a1) div 255, (b0 * (255 - a1) + b1 * a1) div 255, (a0 * (255 - a1) + a1 * a1) div 255);
  1370          r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255;
       
  1371          g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255;
       
  1372          b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255;
       
  1373          a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255;
       
  1374          destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0);
  1357          end;
  1375          end;
  1358       end;
  1376       end;
  1359 end;
  1377 end;
  1360 
  1378 
  1361 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
  1379 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently
  1398 w:= 0;
  1416 w:= 0;
  1399 h:= 0;
  1417 h:= 0;
  1400 wa:= FontBorder * 2 + 4;
  1418 wa:= FontBorder * 2 + 4;
  1401 ha:= FontBorder * 2;
  1419 ha:= FontBorder * 2;
  1402 
  1420 
       
  1421 i:= 0; j:= 0; // avoid compiler hints
       
  1422 
  1403 // TODO: Recheck height/position calculation
  1423 // TODO: Recheck height/position calculation
  1404 
  1424 
  1405 // get caption's dimensions
  1425 // get caption's dimensions
  1406 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j);
  1426 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j);
  1407 // width adds 36 px (image + space)
  1427 // width adds 36 px (image + space)
  1465     if tmpline <> '' then
  1485     if tmpline <> '' then
  1466         begin
  1486         begin
  1467         r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline);
  1487         r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline);
  1468         
  1488         
  1469         // render highlighted caption (if there's a ':')
  1489         // render highlighted caption (if there's a ':')
       
  1490         tmpline2:= '';
  1470         SplitByChar(tmpline, tmpline2, ':');
  1491         SplitByChar(tmpline, tmpline2, ':');
  1471         if tmpline2 <> '' then
  1492         if tmpline2 <> '' then
  1472             WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':');
  1493             WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':');
  1473         end
  1494         end
  1474     end;
  1495     end;