hedgewars/uStore.pas
branchqmlfrontend
changeset 10748 dc587913987c
parent 10744 205cbe137461
child 10869 f23763bbac1b
equal deleted inserted replaced
10616:20a2d5e6930a 10748:dc587913987c
    48 
    48 
    49 procedure SetupOpenGL;
    49 procedure SetupOpenGL;
    50 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    50 function  RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    51 procedure RenderWeaponTooltip(atype: TAmmoType);
    51 procedure RenderWeaponTooltip(atype: TAmmoType);
    52 procedure ShowWeaponTooltip(x, y: LongInt);
    52 procedure ShowWeaponTooltip(x, y: LongInt);
    53 procedure FreeWeaponTooltip;
       
    54 procedure MakeCrossHairs;
    53 procedure MakeCrossHairs;
    55 {$IFDEF USE_VIDEO_RECORDING}
    54 {$IFDEF USE_VIDEO_RECORDING}
    56 procedure InitOffscreenOpenGL;
    55 procedure InitOffscreenOpenGL;
    57 {$ENDIF}
    56 {$ENDIF}
    58 
    57 
    95 end;
    94 end;
    96 
    95 
    97 procedure InitZoom(zoom: real);
    96 procedure InitZoom(zoom: real);
    98 begin
    97 begin
    99     SetScale(zoom);
    98     SetScale(zoom);
   100     UpdateViewLimits();
    99     // make sure view limits are updated
       
   100     // because SetScale() doesn't do it, if zoom=cScaleFactor
       
   101     updateViewLimits();
   101 end;
   102 end;
   102 
   103 
   103 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   104 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;
   104 var w, h: LongInt;
   105 var w, h: LongInt;
   105     tmpsurf: PSDL_Surface;
   106     tmpsurf: PSDL_Surface;
   473             begin
   474             begin
   474             TryDo(length(trAmmo[NameId]) > 0,'No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
   475             TryDo(length(trAmmo[NameId]) > 0,'No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true);
   475             tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, PChar(trAmmo[NameId]), cWhiteColorChannels);
   476             tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, PChar(trAmmo[NameId]), cWhiteColorChannels);
   476             TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
   477             TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true);
   477             tmpsurf:= doSurfaceConversion(tmpsurf);
   478             tmpsurf:= doSurfaceConversion(tmpsurf);
   478             FreeTexture(NameTex);
   479             FreeAndNilTexture(NameTex);
   479             NameTex:= Surface2Tex(tmpsurf, false);
   480             NameTex:= Surface2Tex(tmpsurf, false);
   480             SDL_FreeSurface(tmpsurf)
   481             SDL_FreeSurface(tmpsurf)
   481             end;
   482             end;
   482 
   483 
   483     // number of weapons in ammo menu
   484     // number of weapons in ammo menu
   484     for i:= Low(CountTexz) to High(CountTexz) do
   485     for i:= Low(CountTexz) to High(CountTexz) do
   485         begin
   486         begin
   486         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   487         tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
   487         tmpsurf:= doSurfaceConversion(tmpsurf);
   488         tmpsurf:= doSurfaceConversion(tmpsurf);
   488         FreeTexture(CountTexz[i]);
   489         FreeAndNilTexture(CountTexz[i]);
   489         CountTexz[i]:= Surface2Tex(tmpsurf, false);
   490         CountTexz[i]:= Surface2Tex(tmpsurf, false);
   490         SDL_FreeSurface(tmpsurf)
   491         SDL_FreeSurface(tmpsurf)
   491         end;
   492         end;
   492 
   493 
   493     if not reload then
   494     if not reload then
   578 
   579 
   579 procedure RenderHealth(var Hedgehog: THedgehog);
   580 procedure RenderHealth(var Hedgehog: THedgehog);
   580 var s: shortstring;
   581 var s: shortstring;
   581 begin
   582 begin
   582 str(Hedgehog.Gear^.Health, s);
   583 str(Hedgehog.Gear^.Health, s);
   583 FreeTexture(Hedgehog.HealthTagTex);
   584 FreeAndNilTexture(Hedgehog.HealthTagTex);
   584 Hedgehog.HealthTagTex:= RenderStringTex(ansistring(s), Hedgehog.Team^.Clan^.Color, fnt16)
   585 Hedgehog.HealthTagTex:= RenderStringTex(ansistring(s), Hedgehog.Team^.Clan^.Color, fnt16)
   585 end;
   586 end;
   586 
   587 
   587 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   588 function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
   588 var tmpsurf: PSDL_Surface;
   589 var tmpsurf: PSDL_Surface;
   608         end;
   609         end;
   609 
   610 
   610     // loading failed
   611     // loading failed
   611     if tmpsurf = nil then
   612     if tmpsurf = nil then
   612         begin
   613         begin
   613 
       
   614         // anounce that loading failed
       
   615         OutError(msgFailed, false);
       
   616 
       
   617         // output sdl error if loading failed when data source was available
   614         // output sdl error if loading failed when data source was available
   618         if rwops <> nil then
   615         if rwops <> nil then
   619             begin
   616             begin
       
   617             // anounce that loading failed
       
   618             OutError(msgFailed, false);
       
   619 
   620             SDLTry(false, (imageFlags and ifCritical) <> 0);
   620             SDLTry(false, (imageFlags and ifCritical) <> 0);
   621             // rwops was already freed by IMG_Load_RW
   621             // rwops was already freed by IMG_Load_RW
   622             rwops:= nil;
   622             rwops:= nil;
   623             end;
   623             end else
       
   624             OutError(msgFailed, (imageFlags and ifCritical) <> 0);
   624         exit;
   625         exit;
   625         end;
   626         end;
   626 
   627 
   627     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
   628     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
   628         begin
   629         begin
   695 
   696 
   696 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
   697 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
   697 begin
   698 begin
   698     // free the mem of any previously assigned texture.  This was previously only if the new one could be loaded, but, NoHat is usually a better choice
   699     // free the mem of any previously assigned texture.  This was previously only if the new one could be loaded, but, NoHat is usually a better choice
   699     if HH.HatTex <> nil then
   700     if HH.HatTex <> nil then
   700         begin
   701         FreeAndNilTexture(HH.HatTex);
   701         FreeTexture(HH.HatTex);
       
   702         HH.HatTex:= nil
       
   703         end;
       
   704 
   702 
   705     // load new hat surface if this hat is different than the one already loaded
   703     // load new hat surface if this hat is different than the one already loaded
   706     if newHat <> prevHat then
   704     if newHat <> prevHat then
   707         begin
   705         begin
   708         freeTmpHatSurf();
   706         freeTmpHatSurf();
   841     with mobileRecord do
   839     with mobileRecord do
   842         if GameLoaded <> nil then
   840         if GameLoaded <> nil then
   843             GameLoaded();
   841             GameLoaded();
   844     {$ENDIF}
   842     {$ENDIF}
   845     WriteLnToConsole('Freeing progress surface... ');
   843     WriteLnToConsole('Freeing progress surface... ');
   846     FreeTexture(ProgrTex);
   844     FreeAndNilTexture(ProgrTex);
   847     ProgrTex:= nil;
       
   848     Step:= 0
   845     Step:= 0
   849 end;
   846 end;
   850 
   847 
   851 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
   848 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
   852 var tmpsurf: PSDL_SURFACE;
   849 var tmpsurf: PSDL_SURFACE;
   980         WeaponTooltipTex:= nil;
   977         WeaponTooltipTex:= nil;
   981         exit
   978         exit
   982         end;
   979         end;
   983 
   980 
   984 // free old texture
   981 // free old texture
   985 FreeWeaponTooltip;
   982 FreeAndNilTexture(WeaponTooltipTex);
   986 
   983 
   987 // image region
   984 // image region
   988 i:= LongInt(atype) - 1;
   985 i:= LongInt(atype) - 1;
   989 r.x:= (i shr 4) * 32;
   986 r.x:= (i shr 4) * 32;
   990 r.y:= (i mod 16) * 32;
   987 r.y:= (i mod 16) * 32;
  1018 procedure ShowWeaponTooltip(x, y: LongInt);
  1015 procedure ShowWeaponTooltip(x, y: LongInt);
  1019 begin
  1016 begin
  1020 // draw the texture if it exists
  1017 // draw the texture if it exists
  1021 if WeaponTooltipTex <> nil then
  1018 if WeaponTooltipTex <> nil then
  1022     DrawTexture(x, y, WeaponTooltipTex)
  1019     DrawTexture(x, y, WeaponTooltipTex)
  1023 end;
       
  1024 
       
  1025 procedure FreeWeaponTooltip;
       
  1026 begin
       
  1027 // free the existing texture (if there is any)
       
  1028 FreeTexture(WeaponTooltipTex);
       
  1029 WeaponTooltipTex:= nil
       
  1030 end;
  1020 end;
  1031 
  1021 
  1032 {$IFDEF USE_VIDEO_RECORDING}
  1022 {$IFDEF USE_VIDEO_RECORDING}
  1033 {$IFDEF SDL2}
  1023 {$IFDEF SDL2}
  1034 procedure InitOffscreenOpenGL;
  1024 procedure InitOffscreenOpenGL;
  1268     prevHat:= 'NoHat';
  1258     prevHat:= 'NoHat';
  1269     tmpHatSurf:= nil;
  1259     tmpHatSurf:= nil;
  1270 end;
  1260 end;
  1271 
  1261 
  1272 procedure freeModule;
  1262 procedure freeModule;
       
  1263 var fi: THWFont;
  1273 begin
  1264 begin
  1274     StoreRelease(false);
  1265     StoreRelease(false);
       
  1266     // make sure fonts are cleaned up
       
  1267     for fi:= Low(THWFont) to High(THWFont) do
       
  1268         with Fontz[fi] do
       
  1269             begin
       
  1270             if Handle <> nil then
       
  1271                 begin
       
  1272                 TTF_CloseFont(Handle);
       
  1273                 Handle:= nil;
       
  1274                 end;
       
  1275             end;
       
  1276 
  1275     TTF_Quit();
  1277     TTF_Quit();
  1276 {$IFDEF SDL2}
  1278 {$IFDEF SDL2}
  1277     SDL_GL_DeleteContext(SDLGLcontext);
  1279     SDL_GL_DeleteContext(SDLGLcontext);
  1278     SDL_DestroyWindow(SDLwindow);
  1280     SDL_DestroyWindow(SDLwindow);
  1279 {$ENDIF}
  1281 {$ENDIF}