Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Please use the GitHub issue tracker for bug reports.
See part Enums on the [Cheat sheet](CHEATSHEET.md) for reference.
- (Continously) Check FPC/Delphi compatibility.
- (Continously) Adapt comments to [PasDoc format](https://pasdoc.github.io). (See issue [#22](https://github.com/PascalGameDevelopment/SDL2-for-Pascal/issues/22))
- Update sdlthread.inc

## Code style guidelines

Expand Down
6 changes: 6 additions & 0 deletions units/ctypes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ type
cuint32 = LongWord;
{$EXTERNALSYM cuint32}

culong = LongWord;
{$EXTERNALSYM culong}

cuint = LongWord;
{$EXTERNALSYM cuint}

{$IFNDEF Has_Int64}
pcint64 = ^cint64;
cint64 = record
Expand Down
80 changes: 25 additions & 55 deletions units/sdl2.pas
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,21 @@ interface
{$ENDIF}


{$I ctypes.inc} // C data types
{$I ctypes.inc} // C data types

{SDL2 version of the represented header file}
{$I sdlstdinc.inc}
{$I sdlversion.inc}
{$I sdlerror.inc}
{$I sdlplatform.inc}
{$I sdlpower.inc}
{$I sdlversion.inc} // 2.0.14
{$I sdlerror_c.inc} // 2.0.14
{$I sdlerror.inc} // 2.0.14
{$I sdlplatform.inc} // 2.0.14
{$I sdlpower.inc} // 2.0.14
{$I sdlthread.inc}
{$I sdlmutex.inc}
{$I sdltimer.inc}
{$I sdlpixels.inc}
{$I sdlrect.inc}
{$I sdlrwops.inc}
{$I sdlmutex.inc} // 2.0.14 WIP
{$I sdltimer.inc} // 2.0.14
{$I sdlpixels.inc} // 2.0.14 WIP
{$I sdlrect.inc} // 2.0.14
{$I sdlrwops.inc} // 2.0.14
{$I sdlaudio.inc}
{$I sdlblendmode.inc}
{$I sdlsurface.inc}
Expand Down Expand Up @@ -183,15 +186,15 @@ interface

implementation

//from "sdl_version.h"
// Macros from "sdl_version.h"
procedure SDL_VERSION(out x: TSDL_Version);
begin
x.major := SDL_MAJOR_VERSION;
x.minor := SDL_MINOR_VERSION;
x.patch := SDL_PATCHLEVEL;
end;

function SDL_VERSIONNUM(X,Y,Z: cuint32): Cardinal;
function SDL_VERSIONNUM(X,Y,Z: cuint8): Cardinal;
begin
Result := X*1000 + Y*100 + Z;
end;
Expand All @@ -203,7 +206,7 @@ function SDL_COMPILEDVERSION: Cardinal;
SDL_PATCHLEVEL);
end;

function SDL_VERSION_ATLEAST(X,Y,Z: Cardinal): Boolean;
function SDL_VERSION_ATLEAST(X,Y,Z: cuint8): Boolean;
begin
Result := SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X,Y,Z);
end;
Expand All @@ -225,54 +228,22 @@ function SDL_CreateThread(fn: TSDL_ThreadFunction; name: PAnsiChar; data: Pointe
{$ENDIF}

//from "sdl_rect.h"
function SDL_RectEmpty(const r: PSDL_Rect): Boolean;
begin
Result := (r^.w <= 0) or (r^.h <= 0);
end;

function SDL_RectEquals(const a, b: PSDL_Rect): Boolean;
begin
Result := (a^.x = b^.x) and (a^.y = b^.y) and (a^.w = b^.w) and (a^.h = b^.h);
end;

function SDL_PointInRect(const p: PSDL_Point; const r: PSDL_Rect): Boolean;
begin
Result :=
(p^.x >= r^.x) and (p^.x < (r^.x + r^.w))
and
Result :=
(p^.x >= r^.x) and (p^.x < (r^.x + r^.w))
and
(p^.y >= r^.y) and (p^.y < (r^.y + r^.h))
end;

//from "sdl_rwops.h"

function SDL_RWsize(ctx: PSDL_RWops): cint64;
begin
Result := ctx^.size(ctx);
end;

function SDL_RWseek(ctx: PSDL_RWops; offset: cint64; whence: cint32): cint64;
begin
Result := ctx^.seek(ctx,offset,whence);
end;

function SDL_RWtell(ctx: PSDL_RWops): cint64;
begin
Result := ctx^.seek(ctx, 0, RW_SEEK_CUR);
end;

function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t;
begin
Result := ctx^.read(ctx, ptr, size, n);
end;

function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: csize_t; n: csize_t): csize_t;
function SDL_RectEmpty(const r: PSDL_Rect): Boolean;
begin
Result := ctx^.write(ctx, ptr, size, n);
Result := (r^.w <= 0) or (r^.h <= 0);
end;

function SDL_RWclose(ctx: PSDL_RWops): cint32;
function SDL_RectEquals(const a, b: PSDL_Rect): Boolean;
begin
Result := ctx^.close(ctx);
Result := (a^.x = b^.x) and (a^.y = b^.y) and (a^.w = b^.w) and (a^.h = b^.h);
end;

//from "sdl_audio.h"
Expand Down Expand Up @@ -346,7 +317,6 @@ function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;

function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
begin
{* The flag is set to 1 because 0x1? is not in the printable ASCII range *}
Result := format and SDL_PIXELFLAG(format) <> 1;
end;

Expand Down Expand Up @@ -407,9 +377,9 @@ function SDL_GetEventState(type_: TSDL_EventType): cuint8;
end;

// from "sdl_timer.h"
function SDL_TICKS_PASSED(const A, B: cuint32): Boolean;
function SDL_TICKS_PASSED(const A, B: cint32): Boolean;
begin
Result := ((cint64(B) - cint64(A)) <= 0)
Result := ((B - A) <= 0);
end;

// from "sdl_gamecontroller.h"
Expand Down
97 changes: 59 additions & 38 deletions units/sdlerror.inc
Original file line number Diff line number Diff line change
@@ -1,26 +1,68 @@
//from "sdl_error.h"
const
ERR_MAX_STRLEN = 128;
ERR_MAX_ARGS = 5;
// based on "sdl_error.h" (2.0.14)

{* Public functions *}
{**
* \file SDL_error.h
*
* Simple error message routines for SDL.
*}

{* SDL_SetError() unconditionally returns -1. *}
function SDL_SetError(const fmt: PAnsiChar): cint32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetError' {$ENDIF} {$ENDIF};
function SDL_GetError: PAnsiChar cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetError' {$ENDIF} {$ENDIF};
{* Public functions *}

{**
* \brief Set the error message for the current thread
*
* \return -1, there is no error handling for this function
*}
function SDL_SetError(const fmt: PAnsiChar): cint; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetError' {$ENDIF} {$ENDIF};

{**
* \brief Get the last error message that was set
*
* SDL API functions may set error messages and then succeed, so you should
* only use the error value if a function fails.
*
* This returns a pointer to a static buffer for convenience and should not
* be called by multiple threads simultaneously.
*
* \return a pointer to the last error message that was set
*}
function SDL_GetError: PAnsiChar; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetError' {$ENDIF} {$ENDIF};

{**
* \brief Get the last error message that was set for the current thread
*
* SDL API functions may set error messages and then succeed, so you should
* only use the error value if a function fails.
*
* \param errstr A buffer to fill with the last error message that was set
* for the current thread
* \param maxlen The size of the buffer pointed to by the errstr parameter
*
* \return errstr
*}
function SDL_GetErrorMsg(const errstr: PAnsiChar; maxlen: cint): PAnsiChar; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetErrorMsg' {$ENDIF} {$ENDIF};

{**
* \brief Clear the error message for the current thread
*}
procedure SDL_ClearError cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ClearError' {$ENDIF} {$ENDIF};
{*Internal error functions*}
{**
* Internal error functions
*
* Private error reporting function - used internally.
*}

{*Internal error functions*}
{**
* Internal error functions
*
* Private error reporting function - used internally.
*}
{
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
}


type
TSDL_ErrorCode = (SDL_ENOMEM,
SDL_EFREAD,
Expand All @@ -29,27 +71,6 @@ type
SDL_UNSUPPORTED,
SDL_LASTERROR);

TSDL_Error = record
{* This is a numeric value corresponding to the current error *}
error: cint32;

{* This is a key used to index into a language hashtable containing
internationalized versions of the SDL error messages. If the key
is not in the hashtable, or no hashtable is available, the key is
used directly as an error message format string.
*}
key: String[ERR_MAX_STRLEN];

{* These are the arguments for the error functions *}
argc: cint32;
case cint32 of
{* What is a character anyway? (UNICODE issues) *}
0: (value_c: Byte;);
1: (value_ptr: Pointer;);
2: (value_i: cint32;);
3: (value_f: Double;);
4: (buf: String[ERR_MAX_STRLEN];);
end;

{* SDL_Error() unconditionally returns -1. *}
function SDL_Error(code: TSDL_ErrorCode): cint32 cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Error' {$ENDIF} {$ENDIF};
{* SDL_Error() unconditionally returns -1. *}
function SDL_Error(code: TSDL_ErrorCode): cint; cdecl;
external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Error' {$ENDIF} {$ENDIF};
41 changes: 41 additions & 0 deletions units/sdlerror_c.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// based on "sdl_error_c.h" (2.0.14)

{* This file defines a structure that carries language-independent
error messages
*}

const
ERR_MAX_STRLEN = 128;
//ERR_MAX_ARGS = 5; { Obsolete in 2.0.14? }

type

TSDL_Error = record
{* This is a numeric value corresponding to the current error *}
error: cint;
str: String[ERR_MAX_STRLEN];
end;

{ Seems the error structure has changed drastically by SDL2 ver. 2.0.14?!
For ref. the old structure: (Can be deleted in later versions) }
//TSDL_Error = record
// {* This is a numeric value corresponding to the current error *}
// error: cint;
//
// {* This is a key used to index into a language hashtable containing
// internationalized versions of the SDL error messages. If the key
// is not in the hashtable, or no hashtable is available, the key is
// used directly as an error message format string.
// *}
// key: String[ERR_MAX_STRLEN];
//
// {* These are the arguments for the error functions *}
// argc: cint32;
// case cint32 of
// {* What is a character anyway? (UNICODE issues) *}
// 0: (value_c: Byte;);
// 1: (value_ptr: Pointer;);
// 2: (value_i: cint32;);
// 3: (value_f: Double;);
// 4: (buf: String[ERR_MAX_STRLEN];);
//end;
Loading