hedgewars/uStore.pas
changeset 2905 f3c79f7193a9
parent 2874 3c7c2bf1ba38
child 2910 d5051cc8a313
equal deleted inserted replaced
2904:209a0c573917 2905:f3c79f7193a9
    60 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    60 procedure DrawCentered(X, Top: LongInt; Source: PTexture);
    61 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    61 procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
    62 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    62 procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real);
    63 procedure DrawFillRect(r: TSDL_Rect);
    63 procedure DrawFillRect(r: TSDL_Rect);
    64 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    64 procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean);
    65 function  CheckCJKFont(s: string; font: THWFont): THWFont;
    65 function  CheckCJKFont(s: ansistring; font: THWFont): THWFont;
    66 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
    66 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
    67 function  RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture;
    67 function  RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
    68 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
    68 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);
    69 //procedure rotateSurface(Surface: PSDL_Surface);
    69 //procedure rotateSurface(Surface: PSDL_Surface);
    70 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    70 procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL
    71 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer);
    71 procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer);
    72 procedure RenderHealth(var Hedgehog: THedgehog);
    72 procedure RenderHealth(var Hedgehog: THedgehog);
    73 procedure AddProgress;
    73 procedure AddProgress;
    74 procedure FinishProgress;
    74 procedure FinishProgress;
    75 function  LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface;
    75 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
    76 procedure SetupOpenGL;
    76 procedure SetupOpenGL;
    77 procedure SetScale(f: GLfloat);
    77 procedure SetScale(f: GLfloat);
    78 function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    78 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
    79 procedure RenderWeaponTooltip(atype: TAmmoType);
    79 procedure RenderWeaponTooltip(atype: TAmmoType);
    80 procedure ShowWeaponTooltip(x, y: LongInt);
    80 procedure ShowWeaponTooltip(x, y: LongInt);
    81 procedure FreeWeaponTooltip;
    81 procedure FreeWeaponTooltip;
    82 
    82 
    83 implementation
    83 implementation
   116 r.w:= rect^.w - 2;
   116 r.w:= rect^.w - 2;
   117 r.h:= rect^.h - 4;
   117 r.h:= rect^.h - 4;
   118 SDL_FillRect(Surface, @r, FillColor)
   118 SDL_FillRect(Surface, @r, FillColor)
   119 end;
   119 end;
   120 
   120 
   121 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
   121 function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
   122 var w, h: LongInt;
   122 var w, h: LongInt;
   123     tmpsurf: PSDL_Surface;
   123     tmpsurf: PSDL_Surface;
   124     clr: TSDL_Color;
   124     clr: TSDL_Color;
   125     finalRect: TSDL_Rect;
   125     finalRect: TSDL_Rect;
   126 begin
   126 begin
   144 finalRect.w:= w + FontBorder * 2 + 4;
   144 finalRect.w:= w + FontBorder * 2 + 4;
   145 finalRect.h:= h + FontBorder * 2;
   145 finalRect.h:= h + FontBorder * 2;
   146 WriteInRoundRect:= finalRect;
   146 WriteInRoundRect:= finalRect;
   147 end;
   147 end;
   148 
   148 
   149 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect;
   149 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
   150 var w, h: LongInt;
   150 var w, h: LongInt;
   151     tmpsurf: PSDL_Surface;
   151     tmpsurf: PSDL_Surface;
   152     clr: TSDL_Color;
   152     clr: TSDL_Color;
   153     finalRect: TSDL_Rect;
   153     finalRect: TSDL_Rect;
   154 begin
   154 begin
   171 finalRect.h:= h + FontBorder * 2;
   171 finalRect.h:= h + FontBorder * 2;
   172 WriteInRect:= finalRect
   172 WriteInRect:= finalRect
   173 end;
   173 end;
   174 
   174 
   175 procedure StoreLoad;
   175 procedure StoreLoad;
   176 var s: string;
   176 var s: shortstring;
   177 
   177 
   178 	procedure WriteNames(Font: THWFont);
   178 	procedure WriteNames(Font: THWFont);
   179 	var t: LongInt;
   179 	var t: LongInt;
   180 		i: LongInt;
   180 		i: LongInt;
   181 		r, rr: TSDL_Rect;
   181 		r, rr: TSDL_Rect;
   793 FreeTexture(ropeIconTex);
   793 FreeTexture(ropeIconTex);
   794 FreeTexture(HHTexture)
   794 FreeTexture(HHTexture)
   795 end;
   795 end;
   796 
   796 
   797 
   797 
   798 function CheckCJKFont(s: string; font: THWFont): THWFont;
   798 function CheckCJKFont(s: ansistring; font: THWFont): THWFont;
   799 var l, i : LongInt;
   799 var l, i : LongInt;
   800     u: WideChar;
   800     u: WideChar;
   801     tmpstr: array[0..256] of WideChar;
   801     tmpstr: array[0..256] of WideChar;
   802 begin
   802 begin
   803 if (font >= CJKfnt16) or (length(s) = 0)  then exit(font);
   803 if (font >= CJKfnt16) or (length(s) = 0)  then exit(font);
   822 (* two more to check. pascal WideChar is only 16 bit though
   822 (* two more to check. pascal WideChar is only 16 bit though
   823        ((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B
   823        ((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B
   824        ((#$2F800 <= u) and (u >= #$2FA1F)))   // CJK Compatibility Ideographs Supplement *)
   824        ((#$2F800 <= u) and (u >= #$2FA1F)))   // CJK Compatibility Ideographs Supplement *)
   825 end;
   825 end;
   826 
   826 
   827 function  RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture;
   827 function  RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture;
   828 var w, h : LongInt;
   828 var w, h : LongInt;
   829     finalSurface: PSDL_Surface;
   829     finalSurface: PSDL_Surface;
   830 begin
   830 begin
   831 if length(s) = 0 then s:= ' ';
   831 if length(s) = 0 then s:= ' ';
   832 font:= CheckCJKFont(s, font);
   832 font:= CheckCJKFont(s, font);
   844 RenderStringTex:= Surface2Tex(finalSurface, false);
   844 RenderStringTex:= Surface2Tex(finalSurface, false);
   845 
   845 
   846 SDL_FreeSurface(finalSurface);
   846 SDL_FreeSurface(finalSurface);
   847 end;
   847 end;
   848 
   848 
   849 function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture;
   849 function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture;
   850 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   850 var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt;
   851     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   851     finalSurface, tmpsurf, rotatedEdge: PSDL_Surface;
   852     rect: TSDL_Rect;
   852     rect: TSDL_Rect;
   853     chars: TSysCharSet = [#9,' ','.',';',':','?','!',','];
   853     chars: TSysCharSet = [#9,' ','.',';',':','?','!',','];
   854     substr: shortstring;
   854     substr: shortstring;
  1036 	if Hedgehog.HealthTagTex <> nil then
  1036 	if Hedgehog.HealthTagTex <> nil then
  1037 		FreeTexture(Hedgehog.HealthTagTex);
  1037 		FreeTexture(Hedgehog.HealthTagTex);
  1038 	Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
  1038 	Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
  1039 end;
  1039 end;
  1040 
  1040 
  1041 function  LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface;
  1041 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
  1042 var tmpsurf: PSDL_Surface;
  1042 var tmpsurf: PSDL_Surface;
  1043     s: shortstring;
  1043     s: shortstring;
  1044 begin
  1044 begin
  1045 	WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
  1045 	WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
  1046 
  1046 
  1093 	WriteLnToConsole(msgOK);
  1093 	WriteLnToConsole(msgOK);
  1094 
  1094 
  1095 	LoadImage:= tmpsurf //Result
  1095 	LoadImage:= tmpsurf //Result
  1096 end;
  1096 end;
  1097 
  1097 
  1098 function glLoadExtension(extension : string) : boolean;
  1098 function glLoadExtension(extension : shortstring) : boolean;
  1099 begin
  1099 begin
  1100 {$IFDEF IPHONEOS}
  1100 {$IFDEF IPHONEOS}
  1101 	glLoadExtension:= false;
  1101 	glLoadExtension:= false;
  1102 {$ELSE}
  1102 {$ELSE}
  1103 	glLoadExtension:= glext_LoadExtension(extension);
  1103 	glLoadExtension:= glext_LoadExtension(extension);
  1136 		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  1136 		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
  1137 {$ENDIF}
  1137 {$ENDIF}
  1138 
  1138 
  1139 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1139 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
  1140 
  1140 
  1141 	vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
  1141 	vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
  1142 {$IFDEF DEBUGFILE}
  1142 {$IFDEF DEBUGFILE}
  1143 	AddFileLog('OpenGL-- Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
  1143 	AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
  1144 	AddFileLog('  |----- Vendor: ' + vendor);
  1144 	AddFileLog('  |----- Vendor: ' + vendor);
  1145 	AddFileLog('  |----- Version: ' + string(pchar(glGetString(GL_VERSION))));
  1145 	AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
  1146 	AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1146 	AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1147 {$ENDIF}
  1147 {$ENDIF}
  1148 
  1148 
  1149 	if MaxTextureSize <= 0 then
  1149 	if MaxTextureSize <= 0 then
  1150 	begin
  1150 	begin
  1343         destPixels^[j]:= srcPixels^[i];
  1343         destPixels^[j]:= srcPixels^[i];
  1344         inc(j)
  1344         inc(j)
  1345         end;
  1345         end;
  1346 end;
  1346 end;
  1347 
  1347 
  1348 function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
  1348 function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture;
  1349 var tmpsurf: PSDL_SURFACE;
  1349 var tmpsurf: PSDL_SURFACE;
  1350 	w, h, i, j: LongInt;
  1350 	w, h, i, j: LongInt;
  1351 	font: THWFont;
  1351 	font: THWFont;
  1352 	r, r2: TSDL_Rect;
  1352 	r, r2: TSDL_Rect;
  1353 	wa, ha: LongInt;
  1353 	wa, ha: LongInt;
  1354 	tmpline, tmpline2, tmpdesc: shortstring;
  1354 	tmpline, tmpline2, tmpdesc: ansistring;
  1355 begin
  1355 begin
  1356 // make sure there is a caption as well as a sub caption - description is optional
  1356 // make sure there is a caption as well as a sub caption - description is optional
  1357 if caption = '' then caption:= '???';
  1357 if caption = '' then caption:= '???';
  1358 if subcaption = '' then subcaption:= ' ';
  1358 if subcaption = '' then subcaption:= ' ';
  1359 
  1359 
  1456 
  1456 
  1457 procedure RenderWeaponTooltip(atype: TAmmoType);
  1457 procedure RenderWeaponTooltip(atype: TAmmoType);
  1458 {$IFNDEF IPHONEOS}
  1458 {$IFNDEF IPHONEOS}
  1459 var r: TSDL_Rect;
  1459 var r: TSDL_Rect;
  1460 	i: LongInt;
  1460 	i: LongInt;
  1461 	extra: string;
  1461 	extra: ansistring;
  1462 	extracolor: LongInt;
  1462 	extracolor: LongInt;
  1463 begin
  1463 begin
  1464 // don't do anything if the window shouldn't be shown
  1464 // don't do anything if the window shouldn't be shown
  1465 if not cWeaponTooltips then
  1465 if not cWeaponTooltips then
  1466 	begin
  1466 	begin