hedgewars/uMisc.pas
author Stepan777
Thu, 12 Apr 2012 23:05:46 +0400
changeset 6881 ee01eeaa1281
parent 6857 b34288c8fafa
child 6884 85e810230372
permissions -rw-r--r--
png screenshots
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
     1
(*
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     2
* Hedgewars, a free turn based strategy game
6700
e04da46ee43c the most important commit of the year
koda
parents: 6695
diff changeset
     3
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com>
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     4
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     5
* This program is free software; you can redistribute it and/or modify
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     6
* it under the terms of the GNU General Public License as published by
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     7
* the Free Software Foundation; version 2 of the License
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     8
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
     9
* This program is distributed in the hope that it will be useful,
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    12
* GNU General Public License for more details.
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    13
*
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    14
* You should have received a copy of the GNU General Public License
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    15
* along with this program; if not, write to the Free Software
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    17
*)
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    18
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    19
{$INCLUDE "options.inc"}
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    20
{$DEFINE PNG_SCREENSHOTS}
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    21
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    22
unit uMisc;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    23
interface
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
    24
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
    25
uses SDLh, uConsts, GLunit, uTypes;
1054
80225c6af656 - Prepare for sudden death implementation
unc0rr
parents: 988
diff changeset
    26
3169
c8c6ac44f51b prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents: 3165
diff changeset
    27
procedure movecursor(dx, dy: LongInt);
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
    28
function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
5912
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
    29
function  MakeScreenshot(filename: shortstring): boolean;
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
    30
function  GetTeamStatString(p: PTeam): shortstring;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    31
{$IFDEF SDL13}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    32
function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    33
{$ELSE}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    34
function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
    35
{$ENDIF}
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    36
procedure initModule;
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
    37
procedure freeModule;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    38
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
    39
implementation
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    40
uses typinfo, sysutils, uVariables, uUtils
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    41
     {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    42
     {$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF};
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    43
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    44
type PScreenshot = ^TScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    45
     TScreenshot = record
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    46
         buffer: PByte;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    47
         filename: shortstring;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    48
         width, height: LongInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    49
         size: QWord;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    50
         end;
3756
d42571e2e6c9 lua function SetEffect to set and remove THogEffects
burp
parents: 3709
diff changeset
    51
3169
c8c6ac44f51b prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents: 3165
diff changeset
    52
procedure movecursor(dx, dy: LongInt);
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    53
var x, y: LongInt;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    54
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    55
if (dx = 0) and (dy = 0) then exit;
2671
7e0f88013fe8 smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents: 2670
diff changeset
    56
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    57
SDL_GetMouseState(@x, @y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    58
Inc(x, dx);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    59
Inc(y, dy);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    60
SDL_WarpMouse(x, y);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    61
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2392
diff changeset
    62
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    63
{$IFDEF PNG_SCREENSHOTS}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    64
// this funtion will be executed in separate thread
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    65
function SaveScreenshot(screenshot: pointer): PtrInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    66
var i: LongInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    67
    png_ptr: ^png_struct;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    68
    info_ptr: ^png_info;
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
    69
    f: file;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    70
    image: PScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    71
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    72
image:= PScreenshot(screenshot);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    73
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    74
png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    75
if png_ptr = nil then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    76
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    77
    // AddFileLog('Error: Could not create png write struct.');
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    78
    exit(0);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    79
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    80
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    81
info_ptr := png_create_info_struct(png_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    82
if info_ptr = nil then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    83
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    84
    png_destroy_write_struct(@png_ptr, nil);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    85
    // AddFileLog('Error: Could not create png info struct.');
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    86
    exit(0);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    87
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    88
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    89
{$IOCHECKS OFF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    90
Assign(f, image^.filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    91
Rewrite(f, 1);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    92
if IOResult = 0 then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    93
    begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    94
    png_init_pascal_io(png_ptr,@f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    95
    png_set_IHDR(png_ptr, info_ptr, image^.width, image^.height,
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    96
                 8, // bit depth
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    97
                 PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    98
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
    99
    png_write_info(png_ptr, info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   100
    // glReadPixels and libpng number rows in different order
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   101
    for i:= image^.height-1 downto 0 do
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   102
        png_write_row(png_ptr, image^.buffer + i*4*image^.width);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   103
    png_write_end(png_ptr, info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   104
    Close(f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   105
    end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   106
{$IOCHECKS ON}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   107
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   108
// free everything
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   109
png_destroy_write_struct(@png_ptr, @info_ptr);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   110
FreeMem(image^.buffer, image^.size);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   111
Dispose(image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   112
SaveScreenshot:= 0;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   113
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   114
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   115
{$ELSE} // no PNG_SCREENSHOTS
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   116
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   117
// this funtion will be executed in separate thread
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   118
function SaveScreenshot(screenshot: pointer): PtrInt;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   119
var f: file;
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   120
    // Windows Bitmap Header
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   121
    head: array[0..53] of Byte = (
6267
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   122
    $42, $4D,       // identifier ("BM")
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   123
    0, 0, 0, 0,     // file size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   124
    0, 0, 0, 0,     // reserved
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   125
    54, 0, 0, 0,    // starting offset
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   126
    40, 0, 0, 0,    // header size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   127
    0, 0, 0, 0,     // width
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   128
    0, 0, 0, 0,     // height
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   129
    1, 0,           // color planes
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   130
    32, 0,          // bit depth
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   131
    0, 0, 0, 0,     // compression method (uncompressed)
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   132
    0, 0, 0, 0,     // image size
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   133
    96, 0, 0, 0,    // horizontal resolution
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   134
    96, 0, 0, 0,    // vertical resolution
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   135
    0, 0, 0, 0,     // number of colors (all)
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   136
    0, 0, 0, 0      // number of important colors
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   137
    );
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   138
    image: PScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   139
    size: QWord;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   140
begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   141
image:= PScreenshot(screenshot);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   142
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   143
size:= image^.Width*image^.Height*4;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   144
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   145
head[$02]:= (size + 54) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   146
head[$03]:= ((size + 54) shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   147
head[$04]:= ((size + 54) shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   148
head[$05]:= ((size + 54) shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   149
head[$12]:= image^.Width and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   150
head[$13]:= (image^.Width shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   151
head[$14]:= (image^.Width shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   152
head[$15]:= (image^.Width shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   153
head[$16]:= image^.Height and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   154
head[$17]:= (image^.Height shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   155
head[$18]:= (image^.Height shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   156
head[$19]:= (image^.Height shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   157
head[$22]:= size and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   158
head[$23]:= (size shr 8) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   159
head[$24]:= (size shr 16) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   160
head[$25]:= (size shr 24) and $ff;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   161
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   162
{$IOCHECKS OFF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   163
Assign(f, image^.filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   164
Rewrite(f, 1);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   165
if IOResult = 0 then
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   166
    begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   167
    BlockWrite(f, head, sizeof(head));
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   168
    BlockWrite(f, image^.buffer^, size);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   169
    Close(f);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   170
    end
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   171
else
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   172
    begin
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   173
    //AddFileLog('Error: Could not write to ' + filename);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   174
    end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   175
{$IOCHECKS ON}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   176
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   177
// free everything
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   178
FreeMem(image^.buffer, image^.size);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   179
Dispose(image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   180
SaveScreenshot:= 0;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   181
end;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   182
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   183
{$ENDIF} // no PNG_SCREENSHOTS
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   184
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   185
// captures and saves the screen. returns true on success.
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   186
function MakeScreenshot(filename: shortstring): Boolean;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   187
var p: Pointer;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   188
    size: QWord;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   189
    image: PScreenshot;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   190
    format: GLenum;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   191
    ext: string[4];
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   192
begin
3107
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   193
// flash
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   194
ScreenFade:= sfFromWhite;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   195
ScreenFadeValue:= sfMax;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   196
ScreenFadeSpeed:= 5;
1fa539758c10 Engine:
smxx
parents: 3066
diff changeset
   197
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   198
{$IFDEF PNG_SCREENSHOTS}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   199
format:= GL_RGBA;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   200
ext:= '.png';
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   201
{$ELSE}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   202
format:= GL_BGRA;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   203
ext:= '.bmp';
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   204
{$ENDIF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   205
6267
be5d40bb1e86 make screenshots with 32bits of depths, so that they are more opengles friendly
koda
parents: 5912
diff changeset
   206
size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4;
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   207
p:= GetMem(size); // will be freed in SaveScreenshot()
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   208
5910
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   209
// memory could not be allocated
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   210
if p = nil then
5912
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   211
begin
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   212
    AddFileLog('Error: Could not allocate memory for screenshot.');
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   213
    exit(false);
d31eba29e706 screenshots: display a msg on failure and log causative error
sheepluva
parents: 5911
diff changeset
   214
end;
5910
c9a4de51b5a0 cleaned up the screenshot procedure a little.
sheepluva
parents: 5239
diff changeset
   215
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   216
// read pixel from the front buffer
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   217
glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p);
2163
12730f5e79b9 koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents: 2162
diff changeset
   218
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   219
// allocate and fill structure that will be passed to new thread
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   220
New(image); // will be disposed in SaveScreenshot()
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   221
image^.filename:= UserPathPrefix + '/Screenshots/' + filename + ext;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   222
image^.width:= cScreenWidth;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   223
image^.height:= cScreenHeight;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   224
image^.size:= size;
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   225
image^.buffer:= p;
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   226
6881
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   227
{$IFDEF USE_SDLTHREADS}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   228
SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, nil{$ENDIF}, image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   229
{$ELSE}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   230
BeginThread(@SaveScreenshot, image);
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   231
{$ENDIF}
ee01eeaa1281 png screenshots
Stepan777
parents: 6857
diff changeset
   232
MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
1080
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   233
end;
8735046fc698 Repair screenshots capture on 'C' key press
unc0rr
parents: 1066
diff changeset
   234
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   235
// http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   236
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   237
var convertedSurf: PSDL_Surface;
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   238
begin
5004
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   239
    if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
2efa6a414518 update some sdl-1.3 bindings (working up to rev 5296)
koda
parents: 4976
diff changeset
   240
       (tmpsurf^.format^.bitsperpixel = 24) then
4578
f3cf226fad16 Snowball weapon
nemo
parents: 4413
diff changeset
   241
        begin
5046
fc6639d56799 this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents: 5004
diff changeset
   242
        convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   243
        SDL_FreeSurface(tmpsurf);
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   244
        exit(convertedSurf);
4578
f3cf226fad16 Snowball weapon
nemo
parents: 4413
diff changeset
   245
        end;
2705
2b5625c4ec16 fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents: 2699
diff changeset
   246
2947
803b277e4894 hate Smaxx (tested)
unc0rr
parents: 2915
diff changeset
   247
    exit(tmpsurf);
2619
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   248
end;
bc2786a00fb8 fix wrong ttf blending in ppc
koda
parents: 2607
diff changeset
   249
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   250
{$IFDEF SDL13}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   251
function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   252
{$ELSE}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   253
function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   254
{$ENDIF}
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   255
begin
6857
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   256
    SDL_RectMake.x:= x;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   257
    SDL_RectMake.y:= y;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   258
    SDL_RectMake.w:= width;
b34288c8fafa Make function more pascal-ish
unc0rr
parents: 6843
diff changeset
   259
    SDL_RectMake.h:= height;
6695
32de8965c62c refactored a few types involved in the touch interface and corrected a few invisible mistakes
koda
parents: 6267
diff changeset
   260
end;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   261
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   262
function GetTeamStatString(p: PTeam): shortstring;
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   263
var s: ansistring;
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
   264
begin
4413
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   265
    s:= p^.TeamName + ':' + IntToStr(p^.TeamHealth) + ':';
46caab3a8f84 uCommandHandlers
unc0rr
parents: 4377
diff changeset
   266
    GetTeamStatString:= s;
2670
1b327b7515ed regression, powerpc colors working again
koda
parents: 2666
diff changeset
   267
end;
2630
079ef82eac75 revamped file access and debug display
koda
parents: 2622
diff changeset
   268
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   269
procedure initModule;
6843
59da15acb2f2 Finally fix the bug with pointer declarations polluting namespace with bad records
unc0rr
parents: 6700
diff changeset
   270
const SDL_PIXELFORMAT_ABGR8888 = (1 shl 31) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   271
begin
5052
74a81c276d67 fix a couple of loose ends
koda
parents: 5050
diff changeset
   272
    conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   273
end;
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   274
3038
4e48c276a468 In pascal unit is a namespace
unc0rr
parents: 2948
diff changeset
   275
procedure freeModule;
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   276
begin
3626
19f78afa0188 fix the multitouch shooting and moving
koda
parents: 3613
diff changeset
   277
    recordFileName:= '';
5046
fc6639d56799 this brings compatibility up with SDL HEAD (5504), but maybe breaks compatibility with sdl 1.2 so please test! still has problems with keyboard input and rendered ttf textures
koda
parents: 5004
diff changeset
   278
    SDL_FreeFormat(conversionFormat);
2699
249adefa9c1c replace initialization/finalization statements with custom init functions
koda
parents: 2698
diff changeset
   279
end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   280
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 2
diff changeset
   281
end.