hedgewars/uMisc.pas
branchhedgeroid
changeset 5932 5164d17b6374
parent 5912 d31eba29e706
child 6267 be5d40bb1e86
equal deleted inserted replaced
5828:667fb58d7f18 5932:5164d17b6374
    23 
    23 
    24 uses SDLh, uConsts, GLunit, uTypes;
    24 uses SDLh, uConsts, GLunit, uTypes;
    25 
    25 
    26 procedure movecursor(dx, dy: LongInt);
    26 procedure movecursor(dx, dy: LongInt);
    27 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    27 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    28 procedure MakeScreenshot(filename: shortstring);
    28 function  MakeScreenshot(filename: shortstring): boolean;
    29 function  GetTeamStatString(p: PTeam): shortstring;
    29 function  GetTeamStatString(p: PTeam): shortstring;
    30 
    30 
    31 procedure initModule;
    31 procedure initModule;
    32 procedure freeModule;
    32 procedure freeModule;
    33 
    33 
    34 implementation
    34 implementation
    35 uses typinfo, sysutils, uVariables;
    35 uses typinfo, sysutils, uVariables, uUtils;
    36 
    36 
    37 procedure movecursor(dx, dy: LongInt);
    37 procedure movecursor(dx, dy: LongInt);
    38 var x, y: LongInt;
    38 var x, y: LongInt;
    39 begin
    39 begin
    40 if (dx = 0) and (dy = 0) then exit;
    40 if (dx = 0) and (dy = 0) then exit;
    43 Inc(x, dx);
    43 Inc(x, dx);
    44 Inc(y, dy);
    44 Inc(y, dy);
    45 SDL_WarpMouse(x, y);
    45 SDL_WarpMouse(x, y);
    46 end;
    46 end;
    47 
    47 
    48 
    48 // captures and saves the screen. returns true on success.
    49 procedure MakeScreenshot(filename: shortstring);
    49 function MakeScreenshot(filename: shortstring): Boolean;
    50 var p: Pointer;
    50 var success: boolean;
    51     size: Longword;
    51     p: Pointer;
       
    52     size: QWord;
    52     f: file;
    53     f: file;
    53     // Windows Bitmap Header
    54     // Windows Bitmap Header
    54     head: array[0..53] of Byte = (
    55     head: array[0..53] of Byte = (
    55     $42, $4D, // identifier ("BM")
    56     $42, $4D, // identifier ("BM")
    56     0, 0, 0, 0, // file size
    57     0, 0, 0, 0, // file size
    72 // flash
    73 // flash
    73 ScreenFade:= sfFromWhite;
    74 ScreenFade:= sfFromWhite;
    74 ScreenFadeValue:= sfMax;
    75 ScreenFadeValue:= sfMax;
    75 ScreenFadeSpeed:= 5;
    76 ScreenFadeSpeed:= 5;
    76 
    77 
    77 size:= cScreenWidth * cScreenHeight * 3;
    78 size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 3;
    78 p:= GetMem(size);
    79 p:= GetMem(size);
       
    80 
       
    81 // memory could not be allocated
       
    82 if p = nil then
       
    83 begin
       
    84     AddFileLog('Error: Could not allocate memory for screenshot.');
       
    85     exit(false);
       
    86 end;
    79 
    87 
    80 // update header information and file name
    88 // update header information and file name
    81 
    89 
    82 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    90 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    83 
    91 
   100 
   108 
   101 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
   109 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
   102 //glReadBuffer(GL_FRONT);
   110 //glReadBuffer(GL_FRONT);
   103 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
   111 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
   104 
   112 
   105 {$I-}
   113 {$IOCHECKS OFF}
   106 Assign(f, filename);
   114 Assign(f, filename);
   107 Rewrite(f, 1);
   115 Rewrite(f, 1);
   108 if IOResult = 0 then
   116 if IOResult = 0 then
   109     begin
   117     begin
   110     BlockWrite(f, head, sizeof(head));
   118     BlockWrite(f, head, sizeof(head));
   111     BlockWrite(f, p^, size);
   119     BlockWrite(f, p^, size);
   112     Close(f);
   120     Close(f);
       
   121     success:= true;
       
   122     end
       
   123 else
       
   124     begin
       
   125     AddFileLog('Error: Could not write to ' + filename);
       
   126     success:= false;
   113     end;
   127     end;
   114 {$I+}
   128 {$IOCHECKS ON}
   115 
   129 
   116 FreeMem(p)
   130 FreeMem(p, size);
       
   131 
       
   132 MakeScreenshot:= success;
   117 end;
   133 end;
   118 
   134 
   119 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   135 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   120 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   136 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   121 var convertedSurf: PSDL_Surface;
   137 var convertedSurf: PSDL_Surface;