diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2009-06-08 08:06:25 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2009-06-08 08:06:25 +0200 |
commit | 4d4b3b1c04d41868ebb58bd9ccba7b303007e900 (patch) | |
tree | 909ed0aad0b145733521f4ac2bfb938dd4b43785 /lib/wrappers/sdl | |
parent | ce88dc3e67436939b03f97e624c11ca6058fedce (diff) | |
download | Nim-4d4b3b1c04d41868ebb58bd9ccba7b303007e900.tar.gz |
version0.7.10
Diffstat (limited to 'lib/wrappers/sdl')
-rw-r--r-- | lib/wrappers/sdl/sdl.nim | 2522 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_gfx.nim | 421 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_image.nim | 227 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_mixer.nim | 737 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_mixer_nosmpeg.nim | 572 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_net.nim | 431 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdl_ttf.nim | 346 | ||||
-rw-r--r-- | lib/wrappers/sdl/sdlutils.pas | 4354 | ||||
-rw-r--r-- | lib/wrappers/sdl/smpeg.nim | 319 |
9 files changed, 9929 insertions, 0 deletions
diff --git a/lib/wrappers/sdl/sdl.nim b/lib/wrappers/sdl/sdl.nim new file mode 100644 index 000000000..7d2b6ba26 --- /dev/null +++ b/lib/wrappers/sdl/sdl.nim @@ -0,0 +1,2522 @@ + +#****************************************************************************** +# +# JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer +# Conversion of the Simple DirectMedia Layer Headers +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997-2004 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : SDL.h +# SDL_main.h +# SDL_types.h +# SDL_rwops.h +# SDL_timer.h +# SDL_audio.h +# SDL_cdrom.h +# SDL_joystick.h +# SDL_mouse.h +# SDL_keyboard.h +# SDL_events.h +# SDL_video.h +# SDL_byteorder.h +# SDL_version.h +# SDL_active.h +# SDL_thread.h +# SDL_mutex .h +# SDL_getenv.h +# SDL_loadso.h +# +# The initial developer of this Pascal code was : +# Dominique Louis <Dominique@SavageSoftware.com.au> +# +# Portions created by Dominique Louis are +# Copyright (C) 2000 - 2004 Dominique Louis. +# +# +# Contributor(s) +# -------------- +# Tom Jones <tigertomjones@gmx.de> His Project inspired this conversion +# Matthias Thoma <ma.thoma@gmx.de> +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# +# +# +# +# +# +# +# Requires +# -------- +# The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so +# They are available from... +# http://www.libsdl.org . +# +# Programming Notes +# ----------------- +# +# +# +# +# Revision History +# ---------------- +# May 08 2001 - DL : Added Keyboard State Array ( See demos for how to +# use ) +# PKeyStateArr = ^TKeyStateArr; +# TKeyStateArr = array[0..65000] of UInt8; +# As most games will need it. +# +# April 02 2001 - DL : Added SDL_getenv.h definitions and tested version +# 1.2.0 compatability. +# +# March 13 2001 - MT : Added Linux compatibility. +# +# March 10 2001 - MT : Added externalsyms for DEFINES +# Changed the license header +# +# March 09 2001 - MT : Added Kylix Ifdefs/Deleted the uses mmsystem +# +# March 01 2001 - DL : Update conversion of version 1.1.8 +# +# July 22 2001 - DL : Added TUInt8Array and PUIntArray after suggestions +# from Matthias Thoma and Eric Grange. +# +# October 12 2001 - DL : Various changes as suggested by Matthias Thoma and +# David Acklam +# +# October 24 2001 - DL : Added FreePascal support as per suggestions from +# Dean Ellis. +# +# October 27 2001 - DL : Added SDL_BUTTON macro +# +# November 08 2001 - DL : Bug fix as pointed out by Puthoon. +# +# November 29 2001 - DL : Bug fix of SDL_SetGammaRamp as pointed out by Simon +# Rushton. +# +# November 30 2001 - DL : SDL_NOFRAME added as pointed out by Simon Rushton. +# +# December 11 2001 - DL : Added $WEAKPACKAGEUNIT ON to facilitate useage in +# Components +# +# January 05 2002 - DL : Added SDL_Swap32 function as suggested by Matthias +# Thoma and also made sure the _getenv from +# MSVCRT.DLL uses the right calling convention +# +# January 25 2002 - DL : Updated conversion of SDL_AddTimer & +# SDL_RemoveTimer as per suggestions from Matthias +# Thoma. +# +# January 27 2002 - DL : Commented out exported function putenv and getenv +# So that developers get used to using SDL_putenv +# SDL_getenv, as they are more portable +# +# March 05 2002 - DL : Added FreeAnNil procedure for Delphi 4 users. +# +# October 23 2002 - DL : Added Delphi 3 Define of Win32. +# If you intend to you Delphi 3... +# ( which is officially unsupported ) make sure you +# remove references to $EXTERNALSYM in this and other +# SDL files. +# +# November 29 2002 - DL : Fixed bug in Declaration of SDL_GetRGBA that was +# pointed out by Todd Lang +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 08 2003 - MK : Aka Mr Kroket - Added Better FPC support +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# +# Revision 1.31 2007/05/29 21:30:48 savage +# Changes as suggested by Almindor for 64bit compatibility. +# +# Revision 1.30 2007/05/29 19:31:03 savage +# Fix to TSDL_Overlay structure - thanks David Pethes (aka imcold) +# +# Revision 1.29 2007/05/20 20:29:11 savage +# Initial Changes to Handle 64 Bits +# +# Revision 1.26 2007/02/11 13:38:04 savage +# Added Nintendo DS support - Thanks Dean. +# +# Revision 1.25 2006/12/02 00:12:52 savage +# Updated to latest version +# +# Revision 1.24 2006/05/18 21:10:04 savage +# Added 1.2.10 Changes +# +# Revision 1.23 2005/12/04 23:17:52 drellis +# Added declaration of SInt8 and PSInt8 +# +# Revision 1.22 2005/05/24 21:59:03 savage +# Re-arranged uses clause to work on Win32 and Linux, Thanks again Michalis. +# +# Revision 1.21 2005/05/22 18:42:31 savage +# Changes as suggested by Michalis Kamburelis. Thanks again. +# +# Revision 1.20 2005/04/10 11:48:33 savage +# Changes as suggested by Michalis, thanks. +# +# Revision 1.19 2005/01/05 01:47:06 savage +# Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively. +# +# Revision 1.18 2005/01/04 23:14:41 savage +# Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively. +# +# Revision 1.17 2005/01/03 18:40:59 savage +# Updated Version number to reflect latest one +# +# Revision 1.16 2005/01/01 02:02:06 savage +# Updated to v1.2.8 +# +# Revision 1.15 2004/12/24 18:57:11 savage +# forgot to apply Michalis Kamburelis' patch to the implementation section. now fixed +# +# Revision 1.14 2004/12/23 23:42:18 savage +# Applied Patches supplied by Michalis Kamburelis ( THANKS! ), for greater FreePascal compatability. +# +# Revision 1.13 2004/09/30 22:31:59 savage +# Updated with slightly different header comments +# +# Revision 1.12 2004/09/12 21:52:58 savage +# Slight changes to fix some issues with the sdl classes. +# +# Revision 1.11 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.10 2004/07/20 23:57:33 savage +# Thanks to Paul Toth for spotting an error in the SDL Audio Convertion structures. +# In TSDL_AudioCVT the filters variable should point to and array of pointers and not what I had there previously. +# +# Revision 1.9 2004/07/03 22:07:22 savage +# Added Bitwise Manipulation Functions for TSDL_VideoInfo struct. +# +# Revision 1.8 2004/05/10 14:10:03 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.7 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.6 2004/04/01 20:53:23 savage +# Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.5 2004/02/22 15:32:10 savage +# SDL_GetEnv Fix so it also works on FPC/Linux. Thanks to Rodrigo for pointing this out. +# +# Revision 1.4 2004/02/21 23:24:29 savage +# SDL_GetEnv Fix so that it is not define twice for FPC. Thanks to Rene Hugentobler for pointing out this bug, +# +# Revision 1.3 2004/02/18 22:35:51 savage +# Brought sdl.pas up to 1.2.7 compatability +# Thus... +# Added SDL_GL_STEREO, +# SDL_GL_MULTISAMPLEBUFFERS, +# SDL_GL_MULTISAMPLESAMPLES +# +# Add DLL/Shared object functions +# function SDL_LoadObject( const sofile : PChar ) : Pointer; +# +# function SDL_LoadFunction( handle : Pointer; const name : PChar ) : Pointer; +# +# procedure SDL_UnloadObject( handle : Pointer ); +# +# Added function to create RWops from const memory: SDL_RWFromConstMem() +# function SDL_RWFromConstMem(const mem: Pointer; size: Integer) : PSDL_RWops; +# +# Ported SDL_cpuinfo.h so Now you can test for Specific CPU types. +# +# Revision 1.2 2004/02/17 21:37:12 savage +# Tidying up of units +# +# Revision 1.1 2004/02/05 00:08:20 savage +# Module 1.0 release +# +# + +{.deadCodeElim: on.} + +when defined(windows): + const SDLLibName = "SDL.dll" +elif defined(macosx): + const SDLLibName = "libSDL-1.2.0.dylib" +else: + const SDLLibName = "libSDL.so" + +const + SDL_MAJOR_VERSION* = 1'i8 + SDL_MINOR_VERSION* = 2'i8 + SDL_PATCHLEVEL* = 11'i8 # SDL.h constants + SDL_INIT_TIMER* = 0x00000001 + SDL_INIT_AUDIO* = 0x00000010 + SDL_INIT_VIDEO* = 0x00000020 + SDL_INIT_CDROM* = 0x00000100 + SDL_INIT_JOYSTICK* = 0x00000200 + SDL_INIT_NOPARACHUTE* = 0x00100000 # Don't catch fatal signals + SDL_INIT_EVENTTHREAD* = 0x01000000 # Not supported on all OS's + SDL_INIT_EVERYTHING* = 0x0000FFFF # SDL_error.h constants + ERR_MAX_STRLEN* = 128 + ERR_MAX_ARGS* = 5 # SDL_types.h constants + SDL_PRESSED* = 0x00000001 + SDL_RELEASED* = 0x00000000 # SDL_timer.h constants + # This is the OS scheduler timeslice, in milliseconds + SDL_TIMESLICE* = 10 # This is the maximum resolution of the SDL timer on all platforms + TIMER_RESOLUTION* = 10 # Experimentally determined + # SDL_audio.h constants + AUDIO_U8* = 0x00000008 # Unsigned 8-bit samples + AUDIO_S8* = 0x00008008 # Signed 8-bit samples + AUDIO_U16LSB* = 0x00000010 # Unsigned 16-bit samples + AUDIO_S16LSB* = 0x00008010 # Signed 16-bit samples + AUDIO_U16MSB* = 0x00001010 # As above, but big-endian byte order + AUDIO_S16MSB* = 0x00009010 # As above, but big-endian byte order + AUDIO_U16* = AUDIO_U16LSB + AUDIO_S16* = AUDIO_S16LSB # SDL_cdrom.h constants + # The maximum number of CD-ROM tracks on a disk + SDL_MAX_TRACKS* = 99 # The types of CD-ROM track possible + SDL_AUDIO_TRACK* = 0x00000000 + SDL_DATA_TRACK* = 0x00000004 # Conversion functions from frames to Minute/Second/Frames and vice versa + CD_FPS* = 75 # SDL_byteorder.h constants + # The two types of endianness + SDL_LIL_ENDIAN* = 1234 + SDL_BIG_ENDIAN* = 4321 + +when cpuEndian == littleEndian: + const + SDL_BYTEORDER* = SDL_LIL_ENDIAN # Native audio byte ordering + AUDIO_U16SYS* = AUDIO_U16LSB + AUDIO_S16SYS* = AUDIO_S16LSB +else: + const + SDL_BYTEORDER* = SDL_BIG_ENDIAN # Native audio byte ordering + AUDIO_U16SYS* = AUDIO_U16MSB + AUDIO_S16SYS* = AUDIO_S16MSB +const + SDL_MIX_MAXVOLUME* = 128 # SDL_joystick.h constants + MAX_JOYSTICKS* = 2 # only 2 are supported in the multimedia API + MAX_AXES* = 6 # each joystick can have up to 6 axes + MAX_BUTTONS* = 32 # and 32 buttons + AXIS_MIN* = - 32768 # minimum value for axis coordinate + AXIS_MAX* = 32767 # maximum value for axis coordinate + JOY_AXIS_THRESHOLD* = (toFloat((AXIS_MAX) - (AXIS_MIN)) / 100.0) # 1% motion + SDL_HAT_CENTERED* = 0x00000000 + SDL_HAT_UP* = 0x00000001 + SDL_HAT_RIGHT* = 0x00000002 + SDL_HAT_DOWN* = 0x00000004 + SDL_HAT_LEFT* = 0x00000008 + SDL_HAT_RIGHTUP* = SDL_HAT_RIGHT or SDL_HAT_UP + SDL_HAT_RIGHTDOWN* = SDL_HAT_RIGHT or SDL_HAT_DOWN + SDL_HAT_LEFTUP* = SDL_HAT_LEFT or SDL_HAT_UP + SDL_HAT_LEFTDOWN* = SDL_HAT_LEFT or SDL_HAT_DOWN # SDL_events.h constants + +type + TSDL_EventKind* = enum # kind of an SDL event + SDL_NOEVENT = 0, # Unused (do not remove) + SDL_ACTIVEEVENT = 1, # Application loses/gains visibility + SDL_KEYDOWN = 2, # Keys pressed + SDL_KEYUP = 3, # Keys released + SDL_MOUSEMOTION = 4, # Mouse moved + SDL_MOUSEBUTTONDOWN = 5, # Mouse button pressed + SDL_MOUSEBUTTONUP = 6, # Mouse button released + SDL_JOYAXISMOTION = 7, # Joystick axis motion + SDL_JOYBALLMOTION = 8, # Joystick trackball motion + SDL_JOYHATMOTION = 9, # Joystick hat position change + SDL_JOYBUTTONDOWN = 10, # Joystick button pressed + SDL_JOYBUTTONUP = 11, # Joystick button released + SDL_QUITEV = 12, # User-requested quit ( Changed due to procedure conflict ) + SDL_SYSWMEVENT = 13, # System specific event + SDL_EVENT_RESERVEDA = 14, # Reserved for future use.. + SDL_EVENT_RESERVED = 15, # Reserved for future use.. + SDL_VIDEORESIZE = 16, # User resized video mode + SDL_VIDEOEXPOSE = 17, # Screen needs to be redrawn + SDL_EVENT_RESERVED2 = 18, # Reserved for future use.. + SDL_EVENT_RESERVED3 = 19, # Reserved for future use.. + SDL_EVENT_RESERVED4 = 20, # Reserved for future use.. + SDL_EVENT_RESERVED5 = 21, # Reserved for future use.. + SDL_EVENT_RESERVED6 = 22, # Reserved for future use.. + SDL_EVENT_RESERVED7 = 23, # Reserved for future use.. + # Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use + SDL_USEREVENT = 24 # This last event is only for bounding internal arrays + # It is the number of bits in the event mask datatype -- UInt32 + +const + SDL_NUMEVENTS* = 32 + SDL_ALLEVENTS* = 0xFFFFFFFF + SDL_ACTIVEEVENTMASK* = 1 shl ord(SDL_ACTIVEEVENT) + SDL_KEYDOWNMASK* = 1 shl ord(SDL_KEYDOWN) + SDL_KEYUPMASK* = 1 shl ord(SDL_KEYUP) + SDL_MOUSEMOTIONMASK* = 1 shl ord(SDL_MOUSEMOTION) + SDL_MOUSEBUTTONDOWNMASK* = 1 shl ord(SDL_MOUSEBUTTONDOWN) + SDL_MOUSEBUTTONUPMASK* = 1 shl ord(SDL_MOUSEBUTTONUP) + SDL_MOUSEEVENTMASK* = 1 shl ord(SDL_MOUSEMOTION) or 1 shl ord(SDL_MOUSEBUTTONDOWN) or + 1 shl ord(SDL_MOUSEBUTTONUP) + SDL_JOYAXISMOTIONMASK* = 1 shl ord(SDL_JOYAXISMOTION) + SDL_JOYBALLMOTIONMASK* = 1 shl ord(SDL_JOYBALLMOTION) + SDL_JOYHATMOTIONMASK* = 1 shl ord(SDL_JOYHATMOTION) + SDL_JOYBUTTONDOWNMASK* = 1 shl ord(SDL_JOYBUTTONDOWN) + SDL_JOYBUTTONUPMASK* = 1 shl ord(SDL_JOYBUTTONUP) + SDL_JOYEVENTMASK* = 1 shl ord(SDL_JOYAXISMOTION) or 1 shl ord(SDL_JOYBALLMOTION) or + 1 shl ord(SDL_JOYHATMOTION) or 1 shl ord(SDL_JOYBUTTONDOWN) or + 1 shl ord(SDL_JOYBUTTONUP) + SDL_VIDEORESIZEMASK* = 1 shl ord(SDL_VIDEORESIZE) + SDL_QUITMASK* = 1 shl ord(SDL_QUITEV) + SDL_SYSWMEVENTMASK* = 1 shl ord(SDL_SYSWMEVENT) + SDL_QUERY* = - 1 + SDL_IGNORE* = 0 + SDL_DISABLE* = 0 + SDL_ENABLE* = 1 #SDL_keyboard.h constants + # This is the mask which refers to all hotkey bindings + SDL_ALL_HOTKEYS* = 0xFFFFFFFF # Enable/Disable keyboard repeat. Keyboard repeat defaults to off. + # 'delay' is the initial delay in ms between the time when a key is + # pressed, and keyboard repeat begins. + # 'interval' is the time in ms between keyboard repeat events. + SDL_DEFAULT_REPEAT_DELAY* = 500 + SDL_DEFAULT_REPEAT_INTERVAL* = 30 # The keyboard syms have been cleverly chosen to map to ASCII + SDLK_UNKNOWN* = 0 + SDLK_FIRST* = 0 + SDLK_BACKSPACE* = 8 + SDLK_TAB* = 9 + SDLK_CLEAR* = 12 + SDLK_RETURN* = 13 + SDLK_PAUSE* = 19 + SDLK_ESCAPE* = 27 + SDLK_SPACE* = 32 + SDLK_EXCLAIM* = 33 + SDLK_QUOTEDBL* = 34 + SDLK_HASH* = 35 + SDLK_DOLLAR* = 36 + SDLK_AMPERSAND* = 38 + SDLK_QUOTE* = 39 + SDLK_LEFTPAREN* = 40 + SDLK_RIGHTPAREN* = 41 + SDLK_ASTERISK* = 42 + SDLK_PLUS* = 43 + SDLK_COMMA* = 44 + SDLK_MINUS* = 45 + SDLK_PERIOD* = 46 + SDLK_SLASH* = 47 + SDLK_0* = 48 + SDLK_1* = 49 + SDLK_2* = 50 + SDLK_3* = 51 + SDLK_4* = 52 + SDLK_5* = 53 + SDLK_6* = 54 + SDLK_7* = 55 + SDLK_8* = 56 + SDLK_9* = 57 + SDLK_COLON* = 58 + SDLK_SEMICOLON* = 59 + SDLK_LESS* = 60 + SDLK_EQUALS* = 61 + SDLK_GREATER* = 62 + SDLK_QUESTION* = 63 + SDLK_AT* = 64 # Skip uppercase letters + SDLK_LEFTBRACKET* = 91 + SDLK_BACKSLASH* = 92 + SDLK_RIGHTBRACKET* = 93 + SDLK_CARET* = 94 + SDLK_UNDERSCORE* = 95 + SDLK_BACKQUOTE* = 96 + SDLK_a* = 97 + SDLK_b* = 98 + SDLK_c* = 99 + SDLK_d* = 100 + SDLK_e* = 101 + SDLK_f* = 102 + SDLK_g* = 103 + SDLK_h* = 104 + SDLK_i* = 105 + SDLK_j* = 106 + SDLK_k* = 107 + SDLK_l* = 108 + SDLK_m* = 109 + SDLK_n* = 110 + SDLK_o* = 111 + SDLK_p* = 112 + SDLK_q* = 113 + SDLK_r* = 114 + SDLK_s* = 115 + SDLK_t* = 116 + SDLK_u* = 117 + SDLK_v* = 118 + SDLK_w* = 119 + SDLK_x* = 120 + SDLK_y* = 121 + SDLK_z* = 122 + SDLK_DELETE* = 127 # End of ASCII mapped keysyms + # International keyboard syms + SDLK_WORLD_0* = 160 # 0xA0 + SDLK_WORLD_1* = 161 + SDLK_WORLD_2* = 162 + SDLK_WORLD_3* = 163 + SDLK_WORLD_4* = 164 + SDLK_WORLD_5* = 165 + SDLK_WORLD_6* = 166 + SDLK_WORLD_7* = 167 + SDLK_WORLD_8* = 168 + SDLK_WORLD_9* = 169 + SDLK_WORLD_10* = 170 + SDLK_WORLD_11* = 171 + SDLK_WORLD_12* = 172 + SDLK_WORLD_13* = 173 + SDLK_WORLD_14* = 174 + SDLK_WORLD_15* = 175 + SDLK_WORLD_16* = 176 + SDLK_WORLD_17* = 177 + SDLK_WORLD_18* = 178 + SDLK_WORLD_19* = 179 + SDLK_WORLD_20* = 180 + SDLK_WORLD_21* = 181 + SDLK_WORLD_22* = 182 + SDLK_WORLD_23* = 183 + SDLK_WORLD_24* = 184 + SDLK_WORLD_25* = 185 + SDLK_WORLD_26* = 186 + SDLK_WORLD_27* = 187 + SDLK_WORLD_28* = 188 + SDLK_WORLD_29* = 189 + SDLK_WORLD_30* = 190 + SDLK_WORLD_31* = 191 + SDLK_WORLD_32* = 192 + SDLK_WORLD_33* = 193 + SDLK_WORLD_34* = 194 + SDLK_WORLD_35* = 195 + SDLK_WORLD_36* = 196 + SDLK_WORLD_37* = 197 + SDLK_WORLD_38* = 198 + SDLK_WORLD_39* = 199 + SDLK_WORLD_40* = 200 + SDLK_WORLD_41* = 201 + SDLK_WORLD_42* = 202 + SDLK_WORLD_43* = 203 + SDLK_WORLD_44* = 204 + SDLK_WORLD_45* = 205 + SDLK_WORLD_46* = 206 + SDLK_WORLD_47* = 207 + SDLK_WORLD_48* = 208 + SDLK_WORLD_49* = 209 + SDLK_WORLD_50* = 210 + SDLK_WORLD_51* = 211 + SDLK_WORLD_52* = 212 + SDLK_WORLD_53* = 213 + SDLK_WORLD_54* = 214 + SDLK_WORLD_55* = 215 + SDLK_WORLD_56* = 216 + SDLK_WORLD_57* = 217 + SDLK_WORLD_58* = 218 + SDLK_WORLD_59* = 219 + SDLK_WORLD_60* = 220 + SDLK_WORLD_61* = 221 + SDLK_WORLD_62* = 222 + SDLK_WORLD_63* = 223 + SDLK_WORLD_64* = 224 + SDLK_WORLD_65* = 225 + SDLK_WORLD_66* = 226 + SDLK_WORLD_67* = 227 + SDLK_WORLD_68* = 228 + SDLK_WORLD_69* = 229 + SDLK_WORLD_70* = 230 + SDLK_WORLD_71* = 231 + SDLK_WORLD_72* = 232 + SDLK_WORLD_73* = 233 + SDLK_WORLD_74* = 234 + SDLK_WORLD_75* = 235 + SDLK_WORLD_76* = 236 + SDLK_WORLD_77* = 237 + SDLK_WORLD_78* = 238 + SDLK_WORLD_79* = 239 + SDLK_WORLD_80* = 240 + SDLK_WORLD_81* = 241 + SDLK_WORLD_82* = 242 + SDLK_WORLD_83* = 243 + SDLK_WORLD_84* = 244 + SDLK_WORLD_85* = 245 + SDLK_WORLD_86* = 246 + SDLK_WORLD_87* = 247 + SDLK_WORLD_88* = 248 + SDLK_WORLD_89* = 249 + SDLK_WORLD_90* = 250 + SDLK_WORLD_91* = 251 + SDLK_WORLD_92* = 252 + SDLK_WORLD_93* = 253 + SDLK_WORLD_94* = 254 + SDLK_WORLD_95* = 255 # 0xFF + # Numeric keypad + SDLK_KP0* = 256 + SDLK_KP1* = 257 + SDLK_KP2* = 258 + SDLK_KP3* = 259 + SDLK_KP4* = 260 + SDLK_KP5* = 261 + SDLK_KP6* = 262 + SDLK_KP7* = 263 + SDLK_KP8* = 264 + SDLK_KP9* = 265 + SDLK_KP_PERIOD* = 266 + SDLK_KP_DIVIDE* = 267 + SDLK_KP_MULTIPLY* = 268 + SDLK_KP_MINUS* = 269 + SDLK_KP_PLUS* = 270 + SDLK_KP_ENTER* = 271 + SDLK_KP_EQUALS* = 272 # Arrows + Home/End pad + SDLK_UP* = 273 + SDLK_DOWN* = 274 + SDLK_RIGHT* = 275 + SDLK_LEFT* = 276 + SDLK_INSERT* = 277 + SDLK_HOME* = 278 + SDLK_END* = 279 + SDLK_PAGEUP* = 280 + SDLK_PAGEDOWN* = 281 # Function keys + SDLK_F1* = 282 + SDLK_F2* = 283 + SDLK_F3* = 284 + SDLK_F4* = 285 + SDLK_F5* = 286 + SDLK_F6* = 287 + SDLK_F7* = 288 + SDLK_F8* = 289 + SDLK_F9* = 290 + SDLK_F10* = 291 + SDLK_F11* = 292 + SDLK_F12* = 293 + SDLK_F13* = 294 + SDLK_F14* = 295 + SDLK_F15* = 296 # Key state modifier keys + SDLK_NUMLOCK* = 300 + SDLK_CAPSLOCK* = 301 + SDLK_SCROLLOCK* = 302 + SDLK_RSHIFT* = 303 + SDLK_LSHIFT* = 304 + SDLK_RCTRL* = 305 + SDLK_LCTRL* = 306 + SDLK_RALT* = 307 + SDLK_LALT* = 308 + SDLK_RMETA* = 309 + SDLK_LMETA* = 310 + SDLK_LSUPER* = 311 # Left "Windows" key + SDLK_RSUPER* = 312 # Right "Windows" key + SDLK_MODE* = 313 # "Alt Gr" key + SDLK_COMPOSE* = 314 # Multi-key compose key + # Miscellaneous function keys + SDLK_HELP* = 315 + SDLK_PRINT* = 316 + SDLK_SYSREQ* = 317 + SDLK_BREAK* = 318 + SDLK_MENU* = 319 + SDLK_POWER* = 320 # Power Macintosh power key + SDLK_EURO* = 321 # Some european keyboards + SDLK_GP2X_UP* = 0 + SDLK_GP2X_UPLEFT* = 1 + SDLK_GP2X_LEFT* = 2 + SDLK_GP2X_DOWNLEFT* = 3 + SDLK_GP2X_DOWN* = 4 + SDLK_GP2X_DOWNRIGHT* = 5 + SDLK_GP2X_RIGHT* = 6 + SDLK_GP2X_UPRIGHT* = 7 + SDLK_GP2X_START* = 8 + SDLK_GP2X_SELECT* = 9 + SDLK_GP2X_L* = 10 + SDLK_GP2X_R* = 11 + SDLK_GP2X_A* = 12 + SDLK_GP2X_B* = 13 + SDLK_GP2X_Y* = 14 + SDLK_GP2X_X* = 15 + SDLK_GP2X_VOLUP* = 16 + SDLK_GP2X_VOLDOWN* = 17 + SDLK_GP2X_CLICK* = 18 + +const # Enumeration of valid key mods (possibly OR'd together) + KMOD_NONE* = 0x00000000 + KMOD_LSHIFT* = 0x00000001 + KMOD_RSHIFT* = 0x00000002 + KMOD_LCTRL* = 0x00000040 + KMOD_RCTRL* = 0x00000080 + KMOD_LALT* = 0x00000100 + KMOD_RALT* = 0x00000200 + KMOD_LMETA* = 0x00000400 + KMOD_RMETA* = 0x00000800 + KMOD_NUM* = 0x00001000 + KMOD_CAPS* = 0x00002000 + KMOD_MODE* = 44000 + KMOD_RESERVED* = 0x00008000 + KMOD_CTRL* = (KMOD_LCTRL or KMOD_RCTRL) + KMOD_SHIFT* = (KMOD_LSHIFT or KMOD_RSHIFT) + KMOD_ALT* = (KMOD_LALT or KMOD_RALT) + KMOD_META* = (KMOD_LMETA or KMOD_RMETA) #SDL_video.h constants + # Transparency definitions: These define alpha as the opacity of a surface */ + SDL_ALPHA_OPAQUE* = 255 + SDL_ALPHA_TRANSPARENT* = 0 # These are the currently supported flags for the SDL_surface + # Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() + SDL_SWSURFACE* = 0x00000000 # Surface is in system memory + SDL_HWSURFACE* = 0x00000001 # Surface is in video memory + SDL_ASYNCBLIT* = 0x00000004 # Use asynchronous blits if possible + # Available for SDL_SetVideoMode() + SDL_ANYFORMAT* = 0x10000000 # Allow any video depth/pixel-format + SDL_HWPALETTE* = 0x20000000 # Surface has exclusive palette + SDL_DOUBLEBUF* = 0x40000000 # Set up double-buffered video mode + SDL_FULLSCREEN* = 0x80000000 # Surface is a full screen display + SDL_OPENGL* = 0x00000002 # Create an OpenGL rendering context + SDL_OPENGLBLIT* = 0x00000002 # Create an OpenGL rendering context + SDL_RESIZABLE* = 0x00000010 # This video mode may be resized + SDL_NOFRAME* = 0x00000020 # No window caption or edge frame + # Used internally (read-only) + SDL_HWACCEL* = 0x00000100 # Blit uses hardware acceleration + SDL_SRCCOLORKEY* = 0x00001000 # Blit uses a source color key + SDL_RLEACCELOK* = 0x00002000 # Private flag + SDL_RLEACCEL* = 0x00004000 # Colorkey blit is RLE accelerated + SDL_SRCALPHA* = 0x00010000 # Blit uses source alpha blending + SDL_SRCCLIPPING* = 0x00100000 # Blit uses source clipping + SDL_PREALLOC* = 0x01000000 # Surface uses preallocated memory + # The most common video overlay formats. + # For an explanation of these pixel formats, see: + # http://www.webartz.com/fourcc/indexyuv.htm + # + # For information on the relationship between color spaces, see: + # + # http://www.neuro.sfc.keio.ac.jp/~aly/polygon/info/color-space-faq.html + SDL_YV12_OVERLAY* = 0x32315659 # Planar mode: Y + V + U (3 planes) + SDL_IYUV_OVERLAY* = 0x56555949 # Planar mode: Y + U + V (3 planes) + SDL_YUY2_OVERLAY* = 0x32595559 # Packed mode: Y0+U0+Y1+V0 (1 plane) + SDL_UYVY_OVERLAY* = 0x59565955 # Packed mode: U0+Y0+V0+Y1 (1 plane) + SDL_YVYU_OVERLAY* = 0x55595659 # Packed mode: Y0+V0+Y1+U0 (1 plane) + # flags for SDL_SetPalette() + SDL_LOGPAL* = 0x00000001 + SDL_PHYSPAL* = 0x00000002 #SDL_mouse.h constants + # Used as a mask when testing buttons in buttonstate + # Button 1: Left mouse button + # Button 2: Middle mouse button + # Button 3: Right mouse button + # Button 4: Mouse Wheel Up + # Button 5: Mouse Wheel Down + # + SDL_BUTTON_LEFT* = 1 + SDL_BUTTON_MIDDLE* = 2 + SDL_BUTTON_RIGHT* = 3 + SDL_BUTTON_WHEELUP* = 4 + SDL_BUTTON_WHEELDOWN* = 5 + SDL_BUTTON_LMASK* = SDL_PRESSED shl (SDL_BUTTON_LEFT - 1) + SDL_BUTTON_MMASK* = SDL_PRESSED shl (SDL_BUTTON_MIDDLE - 1) + SDL_BUTTON_RMask* = SDL_PRESSED shl (SDL_BUTTON_RIGHT - 1) # SDL_active.h constants + # The available application states + SDL_APPMOUSEFOCUS* = 0x00000001 # The app has mouse coverage + SDL_APPINPUTFOCUS* = 0x00000002 # The app has input focus + SDL_APPACTIVE* = 0x00000004 # The application is active + # SDL_mutex.h constants + # Synchronization functions which can time out return this value + # they time out. + SDL_MUTEX_TIMEDOUT* = 1 # This is the timeout value which corresponds to never time out + SDL_MUTEX_MAXWAIT* = not int(0) + SDL_GRAB_QUERY* = - 1 + SDL_GRAB_OFF* = 0 + SDL_GRAB_ON* = 1 #SDL_GRAB_FULLSCREEN // Used internally + +type + THandle* = int #SDL_types.h types + # Basic data types + TSDL_Bool* = enum + SDL_FALSE, SDL_TRUE + PUInt8Array* = ptr TUInt8Array + PUInt8* = ptr UInt8 + PPUInt8* = ptr PUInt8 + UInt8* = int8 + TUInt8Array* = array[0..high(int) shr 1, UInt8] + PUInt16* = ptr UInt16 + UInt16* = int16 + PSInt8* = ptr SInt8 + SInt8* = int8 + PSInt16* = ptr SInt16 + SInt16* = int16 + PUInt32* = ptr UInt32 + UInt32* = int + SInt32* = int + PInt* = ptr int + PShortInt* = ptr int8 + PUInt64* = ptr UInt64 + UInt64*{.final.} = object + hi*: UInt32 + lo*: UInt32 + + PSInt64* = ptr SInt64 + SInt64*{.final.} = object + hi*: UInt32 + lo*: UInt32 + + TSDL_GrabMode* = int # SDL_error.h types + TSDL_errorcode* = enum + SDL_ENOMEM, SDL_EFREAD, SDL_EFWRITE, SDL_EFSEEK, SDL_LASTERROR + SDL_errorcode* = TSDL_errorcode + TArg*{.final.} = object + buf*: array[0..ERR_MAX_STRLEN - 1, int8] + + PSDL_error* = ptr TSDL_error + TSDL_error*{.final.} = object # This is a numeric value corresponding to the current error + # SDL_rwops.h types + # This is the read/write operation structure -- very basic + # some helper types to handle the unions + # "packed" is only guessed + error*: int # 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*: array[0..ERR_MAX_STRLEN - 1, int8] # These are the arguments for the error functions + argc*: int + args*: array[0..ERR_MAX_ARGS - 1, TArg] + + TStdio*{.final.} = object + autoclose*: int # FILE * is only defined in Kylix so we use a simple Pointer + fp*: Pointer + + TMem*{.final.} = object + base*: PUInt8 + here*: PUInt8 + stop*: PUInt8 + + TUnknown*{.final.} = object # first declare the pointer type + data1*: Pointer + + PSDL_RWops* = ptr TSDL_RWops # now the pointer to function types + TSeek* = proc (context: PSDL_RWops, offset: int, whence: int): int{.cdecl.} + TRead* = proc (context: PSDL_RWops, thePtr: Pointer, size: int, maxnum: int): int{. + cdecl.} + TWrite* = proc (context: PSDL_RWops, thePtr: Pointer, size: int, num: int): int{. + cdecl.} + TClose* = proc (context: PSDL_RWops): int{.cdecl.} # the variant record itself + trange010 = range[0..2] + TSDL_RWops*{.final.} = object + seek*: TSeek + read*: TRead + write*: TWrite + closeFile*: TClose # a keyword as name is not allowed + # be warned! structure alignment may arise at this point + case theType*: trange010 + of trange010(0): + stdio*: TStdio + of trange010(1): + mem*: TMem + of trange010(2): + unknown*: TUnknown + + + SDL_RWops* = TSDL_RWops # SDL_timer.h types + # Function prototype for the timer callback function + TSDL_TimerCallback* = proc (interval: UInt32): UInt32{.cdecl.} # New timer API, supports multiple timers + # Written by Stephane Peter + # <megastep@lokigames.com> + # Function prototype for the new timer callback function. + # The callback function is passed the current timer interval and returns + # the next timer interval. If the returned value is the same as the one + # passed in, the periodic alarm continues, otherwise a new alarm is + # scheduled. If the callback returns 0, the periodic alarm is cancelled. + TSDL_NewTimerCallback* = proc (interval: UInt32, param: Pointer): UInt32{. + cdecl.} # Definition of the timer ID type + PSDL_TimerID* = ptr TSDL_TimerID + TSDL_TimerID*{.final.} = object + interval*: UInt32 + callback*: TSDL_NewTimerCallback + param*: Pointer + last_alarm*: UInt32 + next*: PSDL_TimerID + + TSDL_AudioSpecCallback* = proc (userdata: Pointer, stream: PUInt8, length: int){. + cdecl.} # SDL_audio.h types + # The calculated values in this structure are calculated by SDL_OpenAudio() + PSDL_AudioSpec* = ptr TSDL_AudioSpec + TSDL_AudioSpec*{.final.} = object # A structure to hold a set of audio conversion filters and buffers + freq*: int # DSP frequency -- samples per second + format*: UInt16 # Audio data format + channels*: UInt8 # Number of channels: 1 mono, 2 stereo + silence*: UInt8 # Audio buffer silence value (calculated) + samples*: UInt16 # Audio buffer size in samples + padding*: UInt16 # Necessary for some compile environments + size*: UInt32 # Audio buffer size in bytes (calculated) + # This function is called when the audio device needs more data. + # 'stream' is a pointer to the audio data buffer + # 'len' is the length of that buffer in bytes. + # Once the callback returns, the buffer will no longer be valid. + # Stereo samples are stored in a LRLRLR ordering. + callback*: TSDL_AudioSpecCallback + userdata*: Pointer + + PSDL_AudioCVT* = ptr TSDL_AudioCVT + PSDL_AudioCVTFilter* = ptr TSDL_AudioCVTFilter + TSDL_AudioCVTFilter*{.final.} = object + cvt*: PSDL_AudioCVT + format*: UInt16 + + PSDL_AudioCVTFilterArray* = ptr TSDL_AudioCVTFilterArray + TSDL_AudioCVTFilterArray* = array[0..9, PSDL_AudioCVTFilter] + TSDL_AudioCVT*{.final.} = object + needed*: int # Set to 1 if conversion possible + src_format*: UInt16 # Source audio format + dst_format*: UInt16 # Target audio format + rate_incr*: float64 # Rate conversion increment + buf*: PUInt8 # Buffer to hold entire audio data + length*: int # Length of original audio buffer + len_cvt*: int # Length of converted audio buffer + len_mult*: int # buffer must be len*len_mult big + len_ratio*: float64 # Given len, final size is len*len_ratio + filters*: TSDL_AudioCVTFilterArray + filter_index*: int # Current audio conversion function + + TSDL_Audiostatus* = enum # SDL_cdrom.h types + SDL_AUDIO_STOPPED, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED + TSDL_CDStatus* = enum + CD_ERROR, CD_TRAYEMPTY, CD_STOPPED, CD_PLAYING, CD_PAUSED + PSDL_CDTrack* = ptr TSDL_CDTrack + TSDL_CDTrack*{.final.} = object # This structure is only current as of the last call to SDL_CDStatus() + id*: UInt8 # Track number + theType*: UInt8 # Data or audio track + unused*: UInt16 + len*: UInt32 # Length, in frames, of this track + offset*: UInt32 # Offset, in frames, from start of disk + + PSDL_CD* = ptr TSDL_CD + TSDL_CD*{.final.} = object #SDL_joystick.h types + id*: int # Private drive identifier + status*: TSDL_CDStatus # Current drive status + # The rest of this structure is only valid if there's a CD in drive + numtracks*: int # Number of tracks on disk + cur_track*: int # Current track position + cur_frame*: int # Current frame offset within current track + track*: array[0..SDL_MAX_TRACKS, TSDL_CDTrack] + + PTransAxis* = ptr TTransAxis + TTransAxis*{.final.} = object # The private structure used to keep track of a joystick + offset*: int + scale*: float32 + + PJoystick_hwdata* = ptr TJoystick_hwdata + TJoystick_hwdata*{.final.} = object # joystick ID + id*: int # values used to translate device-specific coordinates into SDL-standard ranges + transaxis*: array[0..5, TTransAxis] + + PBallDelta* = ptr TBallDelta + TBallDelta*{.final.} = object # Current ball motion deltas + # The SDL joystick structure + dx*: int + dy*: int + + PSDL_Joystick* = ptr TSDL_Joystick + TSDL_Joystick*{.final.} = object # SDL_verion.h types + index*: UInt8 # Device index + name*: cstring # Joystick name - system dependent + naxes*: int # Number of axis controls on the joystick + axes*: PUInt16 # Current axis states + nhats*: int # Number of hats on the joystick + hats*: PUInt8 # Current hat states + nballs*: int # Number of trackballs on the joystick + balls*: PBallDelta # Current ball motion deltas + nbuttons*: int # Number of buttons on the joystick + buttons*: PUInt8 # Current button states + hwdata*: PJoystick_hwdata # Driver dependent information + ref_count*: int # Reference count for multiple opens + + PSDL_version* = ptr TSDL_version + TSDL_version*{.final.} = object # SDL_keyboard.h types + major*: UInt8 + minor*: UInt8 + patch*: UInt8 + + TSDLKey* = int32 + TSDLMod* = int32 + PSDL_KeySym* = ptr TSDL_KeySym + TSDL_KeySym*{.final.} = object # SDL_events.h types + #Checks the event queue for messages and optionally returns them. + # If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to + # the back of the event queue. + # If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front + # of the event queue, matching 'mask', will be returned and will not + # be removed from the queue. + # If 'action' is SDL_GETEVENT, up to 'numevents' events at the front + # of the event queue, matching 'mask', will be returned and will be + # removed from the queue. + # This function returns the number of events actually stored, or -1 + # if there was an error. This function is thread-safe. + scancode*: UInt8 # hardware specific scancode + sym*: TSDLKey # SDL virtual keysym + modifier*: TSDLMod # current key modifiers + unicode*: UInt16 # translated character + + TSDL_EventAction* = enum # Application visibility event structure + SDL_ADDEVENT, SDL_PEEKEVENT, SDL_GETEVENT + TSDL_ActiveEvent*{.final.} = object # SDL_ACTIVEEVENT + # Keyboard event structure + gain*: UInt8 # Whether given states were gained or lost (1/0) + state*: UInt8 # A mask of the focus states + + TSDL_KeyboardEvent*{.final.} = object # SDL_KEYDOWN or SDL_KEYUP + # Mouse motion event structure + which*: UInt8 # The keyboard device index + state*: UInt8 # SDL_PRESSED or SDL_RELEASED + keysym*: TSDL_KeySym + + TSDL_MouseMotionEvent*{.final.} = object # SDL_MOUSEMOTION + # Mouse button event structure + which*: UInt8 # The mouse device index + state*: UInt8 # The current button state + x*, y*: UInt16 # The X/Y coordinates of the mouse + xrel*: SInt16 # The relative motion in the X direction + yrel*: SInt16 # The relative motion in the Y direction + + TSDL_MouseButtonEvent*{.final.} = object # SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP + # Joystick axis motion event structure + which*: UInt8 # The mouse device index + button*: UInt8 # The mouse button index + state*: UInt8 # SDL_PRESSED or SDL_RELEASED + x*: UInt16 # The X coordinates of the mouse at press time + y*: UInt16 # The Y coordinates of the mouse at press time + + TSDL_JoyAxisEvent*{.final.} = object # SDL_JOYAXISMOTION + # Joystick trackball motion event structure + which*: UInt8 # The joystick device index + axis*: UInt8 # The joystick axis index + value*: SInt16 # The axis value (range: -32768 to 32767) + + TSDL_JoyBallEvent*{.final.} = object # SDL_JOYAVBALLMOTION + # Joystick hat position change event structure + which*: UInt8 # The joystick device index + ball*: UInt8 # The joystick trackball index + xrel*: SInt16 # The relative motion in the X direction + yrel*: SInt16 # The relative motion in the Y direction + + TSDL_JoyHatEvent*{.final.} = object # SDL_JOYHATMOTION */ + # Joystick button event structure + which*: UInt8 # The joystick device index */ + hat*: UInt8 # The joystick hat index */ + value*: UInt8 # The hat position value: + # 8 1 2 + # 7 0 3 + # 6 5 4 + # Note that zero means the POV is centered. + + TSDL_JoyButtonEvent*{.final.} = object # SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP + # The "window resized" event + # When you get this event, you are responsible for setting a new video + # mode with the new width and height. + which*: UInt8 # The joystick device index + button*: UInt8 # The joystick button index + state*: UInt8 # SDL_PRESSED or SDL_RELEASED + + TSDL_ResizeEvent*{.final.} = object # SDL_VIDEORESIZE + # A user-defined event type + w*: int # New width + h*: int # New height + + PSDL_UserEvent* = ptr TSDL_UserEvent + TSDL_UserEvent*{.final.} = object # SDL_USEREVENT through SDL_NUMEVENTS-1 + code*: int # User defined event code */ + data1*: Pointer # User defined data pointer */ + data2*: Pointer # User defined data pointer */ + + +when defined(Unix): + type #These are the various supported subsystems under UNIX + TSDL_SysWm* = enum + SDL_SYSWM_X11 +# The windows custom event structure + +when defined(WINDOWS): + type + PSDL_SysWMmsg* = ptr TSDL_SysWMmsg + TSDL_SysWMmsg*{.final.} = object + version*: TSDL_version + hwnd*: THandle # The window for the message + msg*: int # The type of message + w_Param*: int32 # WORD message parameter + lParam*: int32 # LONG message parameter + +elif defined(Unix): + type # The Linux custom event structure + PSDL_SysWMmsg* = ptr TSDL_SysWMmsg + TSDL_SysWMmsg*{.final.} = object + version*: TSDL_version + subsystem*: TSDL_SysWm + when false: + event*: TXEvent +else: + type # The generic custom event structure + PSDL_SysWMmsg* = ptr TSDL_SysWMmsg + TSDL_SysWMmsg*{.final.} = object + version*: TSDL_version + data*: int + +# The Windows custom window manager information structure + +when defined(WINDOWS): + type + PSDL_SysWMinfo* = ptr TSDL_SysWMinfo + TSDL_SysWMinfo*{.final.} = object + version*: TSDL_version + window*: THandle # The display window + +elif defined(Unix): + type + TX11*{.final.} = object + when false: + display*: PDisplay # The X11 display + window*: TWindow # The X11 display window + # These locking functions should be called around + # any X11 functions using the display variable. + # They lock the event thread, so should not be + # called around event functions or from event filters. + lock_func*: Pointer + unlock_func*: Pointer # Introduced in SDL 1.0.2 + fswindow*: TWindow # The X11 fullscreen window + wmwindow*: TWindow # The X11 managed input window + + type + PSDL_SysWMinfo* = ptr TSDL_SysWMinfo + TSDL_SysWMinfo*{.final.} = object + version*: TSDL_version + subsystem*: TSDL_SysWm + X11*: TX11 +else: + type # The generic custom window manager information structure + PSDL_SysWMinfo* = ptr TSDL_SysWMinfo + TSDL_SysWMinfo*{.final.} = object + version*: TSDL_version + data*: int + +type + PSDL_SysWMEvent* = ptr TSDL_SysWMEvent + TSDL_SysWMEvent*{.final.} = object + msg*: PSDL_SysWMmsg + + PSDL_Event* = ptr TSDL_Event + TSDL_Event*{.final.} = object # This function sets up a filter to process all events before they + # change internal state and are posted to the internal event queue. + # + # The filter is protypted as: + case theType*: TSDL_EventKind # SDL_NOEVENT, SDL_QUITEV: (); + of SDL_ACTIVEEVENT: + active*: TSDL_ActiveEvent + of SDL_KEYDOWN, SDL_KEYUP: + key*: TSDL_KeyboardEvent + of SDL_MOUSEMOTION: + motion*: TSDL_MouseMotionEvent + of SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP: + button*: TSDL_MouseButtonEvent + of SDL_JOYAXISMOTION: + jaxis*: TSDL_JoyAxisEvent + of SDL_JOYBALLMOTION: + jball*: TSDL_JoyBallEvent + of SDL_JOYHATMOTION: + jhat*: TSDL_JoyHatEvent + of SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP: + jbutton*: TSDL_JoyButtonEvent + of SDL_VIDEORESIZE: + resize*: TSDL_ResizeEvent + of SDL_USEREVENT: + user*: TSDL_UserEvent + of SDL_SYSWMEVENT: + syswm*: TSDL_SysWMEvent + else: + nil + + TSDL_EventFilter* = proc (event: PSDL_Event): int{.cdecl.} # SDL_video.h types + # Useful data types + PPSDL_Rect* = ptr PSDL_Rect + PSDL_Rect* = ptr TSDL_Rect + TSDL_Rect*{.final.} = object + x*, y*: SInt16 + w*, h*: UInt16 + + SDL_Rect* = TSDL_Rect + PSDL_Color* = ptr TSDL_Color + TSDL_Color*{.final.} = object + r*: UInt8 + g*: UInt8 + b*: UInt8 + unused*: UInt8 + + PSDL_ColorArray* = ptr TSDL_ColorArray + TSDL_ColorArray* = array[0..65000, TSDL_Color] + PSDL_Palette* = ptr TSDL_Palette + TSDL_Palette*{.final.} = object # Everything in the pixel format structure is read-only + ncolors*: int + colors*: PSDL_ColorArray + + PSDL_PixelFormat* = ptr TSDL_PixelFormat + TSDL_PixelFormat*{.final.} = object # The structure passed to the low level blit functions + palette*: PSDL_Palette + BitsPerPixel*: UInt8 + BytesPerPixel*: UInt8 + Rloss*: UInt8 + Gloss*: UInt8 + Bloss*: UInt8 + Aloss*: UInt8 + Rshift*: UInt8 + Gshift*: UInt8 + Bshift*: UInt8 + Ashift*: UInt8 + RMask*: UInt32 + GMask*: UInt32 + BMask*: UInt32 + AMask*: UInt32 + colorkey*: UInt32 # RGB color key information + alpha*: UInt8 # Alpha value information (per-surface alpha) + + PSDL_BlitInfo* = ptr TSDL_BlitInfo + TSDL_BlitInfo*{.final.} = object # typedef for private surface blitting functions + s_pixels*: PUInt8 + s_width*: int + s_height*: int + s_skip*: int + d_pixels*: PUInt8 + d_width*: int + d_height*: int + d_skip*: int + aux_data*: Pointer + src*: PSDL_PixelFormat + table*: PUInt8 + dst*: PSDL_PixelFormat + + PSDL_Surface* = ptr TSDL_Surface + TSDL_Blit* = proc (src: PSDL_Surface, srcrect: PSDL_Rect, dst: PSDL_Surface, + dstrect: PSDL_Rect): int{.cdecl.} + TSDL_Surface*{.final.} = object # Useful for determining the video hardware capabilities + flags*: UInt32 # Read-only + format*: PSDL_PixelFormat # Read-only + w*, h*: int # Read-only + pitch*: UInt16 # Read-only + pixels*: Pointer # Read-write + offset*: int # Private + hwdata*: Pointer #TPrivate_hwdata; Hardware-specific surface info + # clipping information: + clip_rect*: TSDL_Rect # Read-only + unused1*: UInt32 # for binary compatibility + # Allow recursive locks + locked*: UInt32 # Private + # info for fast blit mapping to other surfaces + Blitmap*: Pointer # PSDL_BlitMap; // Private + # format version, bumped at every change to invalidate blit maps + format_version*: int # Private + refcount*: int + + PSDL_VideoInfo* = ptr TSDL_VideoInfo + TSDL_VideoInfo*{.final.} = object # The YUV hardware video overlay + hw_available*: UInt8 # Hardware and WindowManager flags in first 2 bits ( see below ) + #hw_available: 1; // Can you create hardware surfaces + # wm_available: 1; // Can you talk to a window manager? + # UnusedBits1: 6; + blit_hw*: UInt8 # Blit Hardware flags. See below for which bits do what + #UnusedBits2: 1; + # blit_hw: 1; // Flag:UInt32 Accelerated blits HW --> HW + # blit_hw_CC: 1; // Flag:UInt32 Accelerated blits with Colorkey + # blit_hw_A: 1; // Flag:UInt32 Accelerated blits with Alpha + # blit_sw: 1; // Flag:UInt32 Accelerated blits SW --> HW + # blit_sw_CC: 1; // Flag:UInt32 Accelerated blits with Colorkey + # blit_sw_A: 1; // Flag:UInt32 Accelerated blits with Alpha + # blit_fill: 1; // Flag:UInt32 Accelerated color fill + UnusedBits3*: UInt8 # Unused at this point + video_mem*: UInt32 # The total amount of video memory (in K) + vfmt*: PSDL_PixelFormat # Value: The format of the video surface + current_w*: SInt32 # Value: The current video mode width + current_h*: SInt32 # Value: The current video mode height + + PSDL_Overlay* = ptr TSDL_Overlay + TSDL_Overlay*{.final.} = object # Public enumeration for setting the OpenGL window attributes. + format*: UInt32 # Overlay format + w*, h*: int # Width and height of overlay + planes*: int # Number of planes in the overlay. Usually either 1 or 3 + pitches*: PUInt16 # An array of pitches, one for each plane. Pitch is the length of a row in bytes. + pixels*: PPUInt8 # An array of pointers to the data of each plane. The overlay should be locked before these pointers are used. + hw_overlay*: UInt32 # This will be set to 1 if the overlay is hardware accelerated. + + TSDL_GLAttr* = enum + SDL_GL_RED_SIZE, SDL_GL_GREEN_SIZE, SDL_GL_BLUE_SIZE, SDL_GL_ALPHA_SIZE, + SDL_GL_BUFFER_SIZE, SDL_GL_DOUBLEBUFFER, SDL_GL_DEPTH_SIZE, + SDL_GL_STENCIL_SIZE, SDL_GL_ACCUM_RED_SIZE, SDL_GL_ACCUM_GREEN_SIZE, + SDL_GL_ACCUM_BLUE_SIZE, SDL_GL_ACCUM_ALPHA_SIZE, SDL_GL_STEREO, + SDL_GL_MULTISAMPLEBUFFERS, SDL_GL_MULTISAMPLESAMPLES, + SDL_GL_ACCELERATED_VISUAL, SDL_GL_SWAP_CONTROL + PSDL_Cursor* = ptr TSDL_Cursor + TSDL_Cursor*{.final.} = object # SDL_mutex.h types + area*: TSDL_Rect # The area of the mouse cursor + hot_x*, hot_y*: SInt16 # The "tip" of the cursor + data*: PUInt8 # B/W cursor data + mask*: PUInt8 # B/W cursor mask + save*: array[1..2, PUInt8] # Place to save cursor area + wm_cursor*: Pointer # Window-manager cursor + + +type + PSDL_Mutex* = ptr TSDL_Mutex + TSDL_Mutex*{.final.} = object + PSDL_semaphore* = ptr TSDL_semaphore + TSDL_semaphore*{.final.} = object + PSDL_Sem* = ptr TSDL_Sem + TSDL_Sem* = TSDL_Semaphore + PSDL_Cond* = ptr TSDL_Cond + TSDL_Cond*{.final.} = object # SDL_thread.h types + +when defined(WINDOWS): + type + TSYS_ThreadHandle* = THandle +when defined(Unix): + type + TSYS_ThreadHandle* = pointer +type # This is the system-independent thread info structure + PSDL_Thread* = ptr TSDL_Thread + TSDL_Thread*{.final.} = object # Helper Types + # Keyboard State Array ( See demos for how to use ) + threadid*: UInt32 + handle*: TSYS_ThreadHandle + status*: int + errbuf*: TSDL_Error + data*: Pointer + + PKeyStateArr* = ptr TKeyStateArr + TKeyStateArr* = array[0..65000, UInt8] # Types required so we don't need to use Windows.pas + PInteger* = ptr int + PByte* = ptr int8 + PWord* = ptr int16 + PLongWord* = ptr int32 # General arrays + PByteArray* = ptr TByteArray + TByteArray* = array[0..32767, int8] + PWordArray* = ptr TWordArray + TWordArray* = array[0..16383, int16] # Generic procedure pointer + TProcedure* = proc () #------------------------------------------------------------------------------ + # initialization + #------------------------------------------------------------------------------ + # This function loads the SDL dynamically linked library and initializes + # the subsystems specified by 'flags' (and those satisfying dependencies) + # Unless the SDL_INIT_NOPARACHUTE flag is set, it will install cleanup + # signal handlers for some commonly ignored fatal signals (like SIGSEGV) + +proc SDL_Init*(flags: UInt32): int{.cdecl, importc, dynlib: SDLLibName.} + # This function initializes specific SDL subsystems +proc SDL_InitSubSystem*(flags: UInt32): int{.cdecl, importc, dynlib: SDLLibName.} + # This function cleans up specific SDL subsystems +proc SDL_QuitSubSystem*(flags: UInt32){.cdecl, importc, dynlib: SDLLibName.} + # This function returns mask of the specified subsystems which have + # been initialized. + # If 'flags' is 0, it returns a mask of all initialized subsystems. +proc SDL_WasInit*(flags: UInt32): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # This function cleans up all initialized subsystems and unloads the + # dynamically linked library. You should call it upon all exit conditions. +proc SDL_Quit*(){.cdecl, importc, dynlib: SDLLibName.} +when defined(WINDOWS): + # This should be called from your WinMain() function, if any + proc SDL_RegisterApp*(name: cstring, style: UInt32, h_Inst: Pointer): int{. + cdecl, importc, dynlib: SDLLibName.} +#------------------------------------------------------------------------------ +# types +#------------------------------------------------------------------------------ +# The number of elements in a table + +proc SDL_TableSize*(table: cstring): int + #------------------------------------------------------------------------------ + # error-handling + #------------------------------------------------------------------------------ + # Public functions +proc SDL_GetError*(): cstring{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_SetError*(fmt: cstring){.cdecl, importc, dynlib: SDLLibName.} +proc SDL_ClearError*(){.cdecl, importc, dynlib: SDLLibName.} +when not(defined(WINDOWS)): + proc SDL_Error*(Code: TSDL_errorcode){.cdecl, importc, dynlib: SDLLibName.} +# Private error message function - used internally + +proc SDL_OutOfMemory*() + #------------------------------------------------------------------------------ + # io handling + #------------------------------------------------------------------------------ + # Functions to create SDL_RWops structures from various data sources +proc SDL_RWFromFile*(filename, mode: cstring): PSDL_RWops{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_FreeRW*(area: PSDL_RWops){.cdecl, importc, dynlib: SDLLibName.} + #fp is FILE *fp ??? +proc SDL_RWFromFP*(fp: Pointer, autoclose: int): PSDL_RWops{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_RWFromMem*(mem: Pointer, size: int): PSDL_RWops{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_RWFromConstMem*(mem: Pointer, size: int): PSDL_RWops{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_AllocRW*(): PSDL_RWops{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_RWSeek*(context: PSDL_RWops, offset: int, whence: int): int +proc SDL_RWTell*(context: PSDL_RWops): int +proc SDL_RWRead*(context: PSDL_RWops, theptr: Pointer, size: int, n: int): int +proc SDL_RWWrite*(context: PSDL_RWops, theptr: Pointer, size: int, n: int): int +proc SDL_RWClose*(context: PSDL_RWops): int + #------------------------------------------------------------------------------ + # time-handling + #------------------------------------------------------------------------------ + # Get the number of milliseconds since the SDL library initialization. + # Note that this value wraps if the program runs for more than ~49 days. +proc SDL_GetTicks*(): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # Wait a specified number of milliseconds before returning +proc SDL_Delay*(msec: UInt32){.cdecl, importc, dynlib: SDLLibName.} + # Add a new timer to the pool of timers already running. + # Returns a timer ID, or NULL when an error occurs. +proc SDL_AddTimer*(interval: UInt32, callback: TSDL_NewTimerCallback, + param: Pointer): PSDL_TimerID{.cdecl, importc, dynlib: SDLLibName.} + # Remove one of the multiple timers knowing its ID. + # Returns a boolean value indicating success. +proc SDL_RemoveTimer*(t: PSDL_TimerID): TSDL_Bool{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_SetTimer*(interval: UInt32, callback: TSDL_TimerCallback): int{.cdecl, + importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # audio-routines + #------------------------------------------------------------------------------ + # These functions are used internally, and should not be used unless you + # have a specific need to specify the audio driver you want to use. + # You should normally use SDL_Init() or SDL_InitSubSystem(). +proc SDL_AudioInit*(driver_name: cstring): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_AudioQuit*(){.cdecl, importc, dynlib: SDLLibName.} + # This function fills the given character buffer with the name of the + # current audio driver, and returns a Pointer to it if the audio driver has + # been initialized. It returns NULL if no driver has been initialized. +proc SDL_AudioDriverName*(namebuf: cstring, maxlen: int): cstring{.cdecl, + importc, dynlib: SDLLibName.} + # This function opens the audio device with the desired parameters, and + # returns 0 if successful, placing the actual hardware parameters in the + # structure pointed to by 'obtained'. If 'obtained' is NULL, the audio + # data passed to the callback function will be guaranteed to be in the + # requested format, and will be automatically converted to the hardware + # audio format if necessary. This function returns -1 if it failed + # to open the audio device, or couldn't set up the audio thread. + # + # When filling in the desired audio spec structure, + # 'desired->freq' should be the desired audio frequency in samples-per-second. + # 'desired->format' should be the desired audio format. + # 'desired->samples' is the desired size of the audio buffer, in samples. + # This number should be a power of two, and may be adjusted by the audio + # driver to a value more suitable for the hardware. Good values seem to + # range between 512 and 8096 inclusive, depending on the application and + # CPU speed. Smaller values yield faster response time, but can lead + # to underflow if the application is doing heavy processing and cannot + # fill the audio buffer in time. A stereo sample consists of both right + # and left channels in LR ordering. + # Note that the number of samples is directly related to time by the + # following formula: ms = (samples*1000)/freq + # 'desired->size' is the size in bytes of the audio buffer, and is + # calculated by SDL_OpenAudio(). + # 'desired->silence' is the value used to set the buffer to silence, + # and is calculated by SDL_OpenAudio(). + # 'desired->callback' should be set to a function that will be called + # when the audio device is ready for more data. It is passed a pointer + # to the audio buffer, and the length in bytes of the audio buffer. + # This function usually runs in a separate thread, and so you should + # protect data structures that it accesses by calling SDL_LockAudio() + # and SDL_UnlockAudio() in your code. + # 'desired->userdata' is passed as the first parameter to your callback + # function. + # + # The audio device starts out playing silence when it's opened, and should + # be enabled for playing by calling SDL_PauseAudio(0) when you are ready + # for your audio callback function to be called. Since the audio driver + # may modify the requested size of the audio buffer, you should allocate + # any local mixing buffers after you open the audio device. +proc SDL_OpenAudio*(desired, obtained: PSDL_AudioSpec): int{.cdecl, + importc, dynlib: SDLLibName.} + # Get the current audio state: +proc SDL_GetAudioStatus*(): TSDL_Audiostatus{.cdecl, importc, dynlib: SDLLibName.} + # This function pauses and unpauses the audio callback processing. + # It should be called with a parameter of 0 after opening the audio + # device to start playing sound. This is so you can safely initialize + # data for your callback function after opening the audio device. + # Silence will be written to the audio device during the pause. +proc SDL_PauseAudio*(pause_on: int){.cdecl, importc, dynlib: SDLLibName.} + # This function loads a WAVE from the data source, automatically freeing + # that source if 'freesrc' is non-zero. For example, to load a WAVE file, + # you could do: + # SDL_LoadWAV_RW(SDL_RWFromFile("sample.wav", "rb"), 1, ...); + # + # If this function succeeds, it returns the given SDL_AudioSpec, + # filled with the audio data format of the wave data, and sets + # 'audio_buf' to a malloc()'d buffer containing the audio data, + # and sets 'audio_len' to the length of that audio buffer, in bytes. + # You need to free the audio buffer with SDL_FreeWAV() when you are + # done with it. + # + # This function returns NULL and sets the SDL error message if the + # wave file cannot be opened, uses an unknown data format, or is + # corrupt. Currently raw and MS-ADPCM WAVE files are supported. +proc SDL_LoadWAV_RW*(src: PSDL_RWops, freesrc: int, spec: PSDL_AudioSpec, + audio_buf: PUInt8, audiolen: PUInt32): PSDL_AudioSpec{. + cdecl, importc, dynlib: SDLLibName.} + # Compatibility convenience function -- loads a WAV from a file +proc SDL_LoadWAV*(filename: cstring, spec: PSDL_AudioSpec, audio_buf: PUInt8, + audiolen: PUInt32): PSDL_AudioSpec + # This function frees data previously allocated with SDL_LoadWAV_RW() +proc SDL_FreeWAV*(audio_buf: PUInt8){.cdecl, importc, dynlib: SDLLibName.} + # This function takes a source format and rate and a destination format + # and rate, and initializes the 'cvt' structure with information needed + # by SDL_ConvertAudio() to convert a buffer of audio data from one format + # to the other. + # This function returns 0, or -1 if there was an error. +proc SDL_BuildAudioCVT*(cvt: PSDL_AudioCVT, src_format: UInt16, + src_channels: UInt8, src_rate: int, dst_format: UInt16, + dst_channels: UInt8, dst_rate: int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Once you have initialized the 'cvt' structure using SDL_BuildAudioCVT(), + # created an audio buffer cvt->buf, and filled it with cvt->len bytes of + # audio data in the source format, this function will convert it in-place + # to the desired format. + # The data conversion may expand the size of the audio data, so the buffer + # cvt->buf should be allocated after the cvt structure is initialized by + # SDL_BuildAudioCVT(), and should be cvt->len*cvt->len_mult bytes long. +proc SDL_ConvertAudio*(cvt: PSDL_AudioCVT): int{.cdecl, importc, dynlib: SDLLibName.} + # This takes two audio buffers of the playing audio format and mixes + # them, performing addition, volume adjustment, and overflow clipping. + # The volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME + # for full audio volume. Note this does not change hardware volume. + # This is provided for convenience -- you can mix your own audio data. +proc SDL_MixAudio*(dst, src: PUInt8, length: UInt32, volume: int){.cdecl, + importc, dynlib: SDLLibName.} + # The lock manipulated by these functions protects the callback function. + # During a LockAudio/UnlockAudio pair, you can be guaranteed that the + # callback function is not running. Do not call these from the callback + # function or you will cause deadlock. +proc SDL_LockAudio*(){.cdecl, importc, dynlib: SDLLibName.} +proc SDL_UnlockAudio*(){.cdecl, importc, dynlib: SDLLibName.} + # This function shuts down audio processing and closes the audio device. +proc SDL_CloseAudio*(){.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # CD-routines + #------------------------------------------------------------------------------ + # Returns the number of CD-ROM drives on the system, or -1 if + # SDL_Init() has not been called with the SDL_INIT_CDROM flag. +proc SDL_CDNumDrives*(): int{.cdecl, importc, dynlib: SDLLibName.} + # Returns a human-readable, system-dependent identifier for the CD-ROM. + # Example: + # "/dev/cdrom" + # "E:" + # "/dev/disk/ide/1/master" +proc SDL_CDName*(drive: int): cstring{.cdecl, importc, dynlib: SDLLibName.} + # Opens a CD-ROM drive for access. It returns a drive handle on success, + # or NULL if the drive was invalid or busy. This newly opened CD-ROM + # becomes the default CD used when other CD functions are passed a NULL + # CD-ROM handle. + # Drives are numbered starting with 0. Drive 0 is the system default CD-ROM. +proc SDL_CDOpen*(drive: int): PSDL_CD{.cdecl, importc, dynlib: SDLLibName.} + # This function returns the current status of the given drive. + # If the drive has a CD in it, the table of contents of the CD and current + # play position of the CD will be stored in the SDL_CD structure. +proc SDL_CDStatus*(cdrom: PSDL_CD): TSDL_CDStatus{.cdecl, importc, dynlib: SDLLibName.} + # Play the given CD starting at 'start_track' and 'start_frame' for 'ntracks' + # tracks and 'nframes' frames. If both 'ntrack' and 'nframe' are 0, play + # until the end of the CD. This function will skip data tracks. + # This function should only be called after calling SDL_CDStatus() to + # get track information about the CD. + # + # For example: + # // Play entire CD: + # if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) then + # SDL_CDPlayTracks(cdrom, 0, 0, 0, 0); + # // Play last track: + # if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) then + # begin + # SDL_CDPlayTracks(cdrom, cdrom->numtracks-1, 0, 0, 0); + # end; + # + # // Play first and second track and 10 seconds of third track: + # if ( CD_INDRIVE(SDL_CDStatus(cdrom)) ) + # SDL_CDPlayTracks(cdrom, 0, 0, 2, 10); + # + # This function returns 0, or -1 if there was an error. +proc SDL_CDPlayTracks*(cdrom: PSDL_CD, start_track: int, start_frame: int, + ntracks: int, nframes: int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Play the given CD starting at 'start' frame for 'length' frames. + # It returns 0, or -1 if there was an error. +proc SDL_CDPlay*(cdrom: PSDL_CD, start: int, len: int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Pause play -- returns 0, or -1 on error +proc SDL_CDPause*(cdrom: PSDL_CD): int{.cdecl, importc, dynlib: SDLLibName.} + # Resume play -- returns 0, or -1 on error +proc SDL_CDResume*(cdrom: PSDL_CD): int{.cdecl, importc, dynlib: SDLLibName.} + # Stop play -- returns 0, or -1 on error +proc SDL_CDStop*(cdrom: PSDL_CD): int{.cdecl, importc, dynlib: SDLLibName.} + # Eject CD-ROM -- returns 0, or -1 on error +proc SDL_CDEject*(cdrom: PSDL_CD): int{.cdecl, importc, dynlib: SDLLibName.} + # Closes the handle for the CD-ROM drive +proc SDL_CDClose*(cdrom: PSDL_CD){.cdecl, importc, dynlib: SDLLibName.} + # Given a status, returns true if there's a disk in the drive +proc SDL_CDInDrive*(status: TSDL_CDStatus): bool + # Conversion functions from frames to Minute/Second/Frames and vice versa +proc FRAMES_TO_MSF*(frames: int, M: var int, S: var int, F: var int) +proc MSF_TO_FRAMES*(M: int, S: int, F: int): int + #------------------------------------------------------------------------------ + # JoyStick-routines + #------------------------------------------------------------------------------ + # Count the number of joysticks attached to the system +proc SDL_NumJoysticks*(): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the implementation dependent name of a joystick. + # This can be called before any joysticks are opened. + # If no name can be found, this function returns NULL. +proc SDL_JoystickName*(index: int): cstring{.cdecl, importc, dynlib: SDLLibName.} + # Open a joystick for use - the index passed as an argument refers to + # the N'th joystick on the system. This index is the value which will + # identify this joystick in future joystick events. + # + # This function returns a joystick identifier, or NULL if an error occurred. +proc SDL_JoystickOpen*(index: int): PSDL_Joystick{.cdecl, importc, dynlib: SDLLibName.} + # Returns 1 if the joystick has been opened, or 0 if it has not. +proc SDL_JoystickOpened*(index: int): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the device index of an opened joystick. +proc SDL_JoystickIndex*(joystick: PSDL_Joystick): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the number of general axis controls on a joystick +proc SDL_JoystickNumAxes*(joystick: PSDL_Joystick): int{.cdecl, + importc, dynlib: SDLLibName.} + # Get the number of trackballs on a joystick + # Joystick trackballs have only relative motion events associated + # with them and their state cannot be polled. +proc SDL_JoystickNumBalls*(joystick: PSDL_Joystick): int{.cdecl, + importc, dynlib: SDLLibName.} + # Get the number of POV hats on a joystick +proc SDL_JoystickNumHats*(joystick: PSDL_Joystick): int{.cdecl, + importc, dynlib: SDLLibName.} + # Get the number of buttons on a joystick +proc SDL_JoystickNumButtons*(joystick: PSDL_Joystick): int{.cdecl, + importc, dynlib: SDLLibName.} + # Update the current state of the open joysticks. + # This is called automatically by the event loop if any joystick + # events are enabled. +proc SDL_JoystickUpdate*(){.cdecl, importc, dynlib: SDLLibName.} + # Enable/disable joystick event polling. + # If joystick events are disabled, you must call SDL_JoystickUpdate() + # yourself and check the state of the joystick when you want joystick + # information. + # The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE. +proc SDL_JoystickEventState*(state: int): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the current state of an axis control on a joystick + # The state is a value ranging from -32768 to 32767. + # The axis indices start at index 0. +proc SDL_JoystickGetAxis*(joystick: PSDL_Joystick, axis: int): SInt16{.cdecl, + importc, dynlib: SDLLibName.} + # The hat indices start at index 0. +proc SDL_JoystickGetHat*(joystick: PSDL_Joystick, hat: int): UInt8{.cdecl, + importc, dynlib: SDLLibName.} + # Get the ball axis change since the last poll + # This returns 0, or -1 if you passed it invalid parameters. + # The ball indices start at index 0. +proc SDL_JoystickGetBall*(joystick: PSDL_Joystick, ball: int, dx: var int, + dy: var int): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the current state of a button on a joystick + # The button indices start at index 0. +proc SDL_JoystickGetButton*(joystick: PSDL_Joystick, Button: int): UInt8{.cdecl, + importc, dynlib: SDLLibName.} + # Close a joystick previously opened with SDL_JoystickOpen() +proc SDL_JoystickClose*(joystick: PSDL_Joystick){.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # event-handling + #------------------------------------------------------------------------------ + # Pumps the event loop, gathering events from the input devices. + # This function updates the event queue and internal input device state. + # This should only be run in the thread that sets the video mode. +proc SDL_PumpEvents*(){.cdecl, importc, dynlib: SDLLibName.} + # Checks the event queue for messages and optionally returns them. + # If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to + # the back of the event queue. + # If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front + # of the event queue, matching 'mask', will be returned and will not + # be removed from the queue. + # If 'action' is SDL_GETEVENT, up to 'numevents' events at the front + # of the event queue, matching 'mask', will be returned and will be + # removed from the queue. + # This function returns the number of events actually stored, or -1 + # if there was an error. This function is thread-safe. +proc SDL_PeepEvents*(events: PSDL_Event, numevents: int, + action: TSDL_eventaction, mask: UInt32): int{.cdecl, + importc, dynlib: SDLLibName.} + # Polls for currently pending events, and returns 1 if there are any pending + # events, or 0 if there are none available. If 'event' is not NULL, the next + # event is removed from the queue and stored in that area. +proc SDL_PollEvent*(event: PSDL_Event): int{.cdecl, importc, dynlib: SDLLibName.} + # Waits indefinitely for the next available event, returning 1, or 0 if there + # was an error while waiting for events. If 'event' is not NULL, the next + # event is removed from the queue and stored in that area. +proc SDL_WaitEvent*(event: PSDL_Event): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_PushEvent*(event: PSDL_Event): int{.cdecl, importc, dynlib: SDLLibName.} + # If the filter returns 1, then the event will be added to the internal queue. + # If it returns 0, then the event will be dropped from the queue, but the + # internal state will still be updated. This allows selective filtering of + # dynamically arriving events. + # + # WARNING: Be very careful of what you do in the event filter function, as + # it may run in a different thread! + # + # There is one caveat when dealing with the SDL_QUITEVENT event type. The + # event filter is only called when the window manager desires to close the + # application window. If the event filter returns 1, then the window will + # be closed, otherwise the window will remain open if possible. + # If the quit event is generated by an interrupt signal, it will bypass the + # internal queue and be delivered to the application at the next event poll. +proc SDL_SetEventFilter*(filter: TSDL_EventFilter){.cdecl, importc, dynlib: SDLLibName.} + # Return the current event filter - can be used to "chain" filters. + # If there is no event filter set, this function returns NULL. +proc SDL_GetEventFilter*(): TSDL_EventFilter{.cdecl, importc, dynlib: SDLLibName.} + # This function allows you to set the state of processing certain events. + # If 'state' is set to SDL_IGNORE, that event will be automatically dropped + # from the event queue and will not event be filtered. + # If 'state' is set to SDL_ENABLE, that event will be processed normally. + # If 'state' is set to SDL_QUERY, SDL_EventState() will return the + # current processing state of the specified event. +proc SDL_EventState*(theType: UInt8, state: int): UInt8{.cdecl, + importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # Version Routines + #------------------------------------------------------------------------------ + # This macro can be used to fill a version structure with the compile-time + # version of the SDL library. +proc SDL_VERSION*(X: var TSDL_Version) + # This macro turns the version numbers into a numeric value: + # (1,2,3) -> (1203) + # This assumes that there will never be more than 100 patchlevels +proc SDL_VERSIONNUM*(X, Y, Z: int): int + # This is the version number macro for the current SDL version +proc SDL_COMPILEDVERSION*(): int + # This macro will evaluate to true if compiled with SDL at least X.Y.Z +proc SDL_VERSION_ATLEAST*(X: int, Y: int, Z: int): bool + # This function gets the version of the dynamically linked SDL library. + # it should NOT be used to fill a version structure, instead you should + # use the SDL_Version() macro. +proc SDL_Linked_Version*(): PSDL_version{.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # video + #------------------------------------------------------------------------------ + # These functions are used internally, and should not be used unless you + # have a specific need to specify the video driver you want to use. + # You should normally use SDL_Init() or SDL_InitSubSystem(). + # + # SDL_VideoInit() initializes the video subsystem -- sets up a connection + # to the window manager, etc, and determines the current video mode and + # pixel format, but does not initialize a window or graphics mode. + # Note that event handling is activated by this routine. + # + # If you use both sound and video in your application, you need to call + # SDL_Init() before opening the sound device, otherwise under Win32 DirectX, + # you won't be able to set full-screen display modes. +proc SDL_VideoInit*(driver_name: cstring, flags: UInt32): int{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_VideoQuit*(){.cdecl, importc, dynlib: SDLLibName.} + # This function fills the given character buffer with the name of the + # video driver, and returns a pointer to it if the video driver has + # been initialized. It returns NULL if no driver has been initialized. +proc SDL_VideoDriverName*(namebuf: cstring, maxlen: int): cstring{.cdecl, + importc, dynlib: SDLLibName.} + # This function returns a pointer to the current display surface. + # If SDL is doing format conversion on the display surface, this + # function returns the publicly visible surface, not the real video + # surface. +proc SDL_GetVideoSurface*(): PSDL_Surface{.cdecl, importc, dynlib: SDLLibName.} + # This function returns a read-only pointer to information about the + # video hardware. If this is called before SDL_SetVideoMode(), the 'vfmt' + # member of the returned structure will contain the pixel format of the + # "best" video mode. +proc SDL_GetVideoInfo*(): PSDL_VideoInfo{.cdecl, importc, dynlib: SDLLibName.} + # Check to see if a particular video mode is supported. + # It returns 0 if the requested mode is not supported under any bit depth, + # or returns the bits-per-pixel of the closest available mode with the + # given width and height. If this bits-per-pixel is different from the + # one used when setting the video mode, SDL_SetVideoMode() will succeed, + # but will emulate the requested bits-per-pixel with a shadow surface. + # + # The arguments to SDL_VideoModeOK() are the same ones you would pass to + # SDL_SetVideoMode() +proc SDL_VideoModeOK*(width, height, bpp: int, flags: UInt32): int{.cdecl, + importc, importc, dynlib: SDLLibName.} + # Return a pointer to an array of available screen dimensions for the + # given format and video flags, sorted largest to smallest. Returns + # NULL if there are no dimensions available for a particular format, + # or (SDL_Rect **)-1 if any dimension is okay for the given format. + # + # if 'format' is NULL, the mode list will be for the format given + # by SDL_GetVideoInfo( ) - > vfmt +proc SDL_ListModes*(format: PSDL_PixelFormat, flags: UInt32): PPSDL_Rect{.cdecl, + importc, dynlib: SDLLibName.} + # Set up a video mode with the specified width, height and bits-per-pixel. + # + # If 'bpp' is 0, it is treated as the current display bits per pixel. + # + # If SDL_ANYFORMAT is set in 'flags', the SDL library will try to set the + # requested bits-per-pixel, but will return whatever video pixel format is + # available. The default is to emulate the requested pixel format if it + # is not natively available. + # + # If SDL_HWSURFACE is set in 'flags', the video surface will be placed in + # video memory, if possible, and you may have to call SDL_LockSurface() + # in order to access the raw framebuffer. Otherwise, the video surface + # will be created in system memory. + # + # If SDL_ASYNCBLIT is set in 'flags', SDL will try to perform rectangle + # updates asynchronously, but you must always lock before accessing pixels. + # SDL will wait for updates to complete before returning from the lock. + # + # If SDL_HWPALETTE is set in 'flags', the SDL library will guarantee + # that the colors set by SDL_SetColors() will be the colors you get. + # Otherwise, in 8-bit mode, SDL_SetColors() may not be able to set all + # of the colors exactly the way they are requested, and you should look + # at the video surface structure to determine the actual palette. + # If SDL cannot guarantee that the colors you request can be set, + # i.e. if the colormap is shared, then the video surface may be created + # under emulation in system memory, overriding the SDL_HWSURFACE flag. + # + # If SDL_FULLSCREEN is set in 'flags', the SDL library will try to set + # a fullscreen video mode. The default is to create a windowed mode + # if the current graphics system has a window manager. + # If the SDL library is able to set a fullscreen video mode, this flag + # will be set in the surface that is returned. + # + # If SDL_DOUBLEBUF is set in 'flags', the SDL library will try to set up + # two surfaces in video memory and swap between them when you call + # SDL_Flip(). This is usually slower than the normal single-buffering + # scheme, but prevents "tearing" artifacts caused by modifying video + # memory while the monitor is refreshing. It should only be used by + # applications that redraw the entire screen on every update. + # + # This function returns the video framebuffer surface, or NULL if it fails. +proc SDL_SetVideoMode*(width, height, bpp: int, flags: UInt32): PSDL_Surface{. + cdecl, importc, dynlib: SDLLibName.} + # Makes sure the given list of rectangles is updated on the given screen. + # If 'x', 'y', 'w' and 'h' are all 0, SDL_UpdateRect will update the entire + # screen. + # These functions should not be called while 'screen' is locked. +proc SDL_UpdateRects*(screen: PSDL_Surface, numrects: int, rects: PSDL_Rect){. + cdecl, importc, dynlib: SDLLibName.} +proc SDL_UpdateRect*(screen: PSDL_Surface, x, y: SInt32, w, h: UInt32){.cdecl, + importc, dynlib: SDLLibName.} + # On hardware that supports double-buffering, this function sets up a flip + # and returns. The hardware will wait for vertical retrace, and then swap + # video buffers before the next video surface blit or lock will return. + # On hardware that doesn not support double-buffering, this is equivalent + # to calling SDL_UpdateRect(screen, 0, 0, 0, 0); + # The SDL_DOUBLEBUF flag must have been passed to SDL_SetVideoMode() when + # setting the video mode for this function to perform hardware flipping. + # This function returns 0 if successful, or -1 if there was an error. +proc SDL_Flip*(screen: PSDL_Surface): int{.cdecl, importc, dynlib: SDLLibName.} + # Set the gamma correction for each of the color channels. + # The gamma values range (approximately) between 0.1 and 10.0 + # + # If this function isn't supported directly by the hardware, it will + # be emulated using gamma ramps, if available. If successful, this + # function returns 0, otherwise it returns -1. +proc SDL_SetGamma*(redgamma: float32, greengamma: float32, bluegamma: float32): int{. + cdecl, importc, dynlib: SDLLibName.} + # Set the gamma translation table for the red, green, and blue channels + # of the video hardware. Each table is an array of 256 16-bit quantities, + # representing a mapping between the input and output for that channel. + # The input is the index into the array, and the output is the 16-bit + # gamma value at that index, scaled to the output color precision. + # + # You may pass NULL for any of the channels to leave it unchanged. + # If the call succeeds, it will return 0. If the display driver or + # hardware does not support gamma translation, or otherwise fails, + # this function will return -1. +proc SDL_SetGammaRamp*(redtable: PUInt16, greentable: PUInt16, + bluetable: PUInt16): int{.cdecl, importc, dynlib: SDLLibName.} + # Retrieve the current values of the gamma translation tables. + # + # You must pass in valid pointers to arrays of 256 16-bit quantities. + # Any of the pointers may be NULL to ignore that channel. + # If the call succeeds, it will return 0. If the display driver or + # hardware does not support gamma translation, or otherwise fails, + # this function will return -1. +proc SDL_GetGammaRamp*(redtable: PUInt16, greentable: PUInt16, + bluetable: PUInt16): int{.cdecl, importc, dynlib: SDLLibName.} + # Sets a portion of the colormap for the given 8-bit surface. If 'surface' + # is not a palettized surface, this function does nothing, returning 0. + # If all of the colors were set as passed to SDL_SetColors(), it will + # return 1. If not all the color entries were set exactly as given, + # it will return 0, and you should look at the surface palette to + # determine the actual color palette. + # + # When 'surface' is the surface associated with the current display, the + # display colormap will be updated with the requested colors. If + # SDL_HWPALETTE was set in SDL_SetVideoMode() flags, SDL_SetColors() + # will always return 1, and the palette is guaranteed to be set the way + # you desire, even if the window colormap has to be warped or run under + # emulation. +proc SDL_SetColors*(surface: PSDL_Surface, colors: PSDL_Color, firstcolor: int, + ncolors: int): int{.cdecl, importc, dynlib: SDLLibName.} + # Sets a portion of the colormap for a given 8-bit surface. + # 'flags' is one or both of: + # SDL_LOGPAL -- set logical palette, which controls how blits are mapped + # to/from the surface, + # SDL_PHYSPAL -- set physical palette, which controls how pixels look on + # the screen + # Only screens have physical palettes. Separate change of physical/logical + # palettes is only possible if the screen has SDL_HWPALETTE set. + # + # The return value is 1 if all colours could be set as requested, and 0 + # otherwise. + # + # SDL_SetColors() is equivalent to calling this function with + # flags = (SDL_LOGPAL or SDL_PHYSPAL). +proc SDL_SetPalette*(surface: PSDL_Surface, flags: int, colors: PSDL_Color, + firstcolor: int, ncolors: int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Maps an RGB triple to an opaque pixel value for a given pixel format +proc SDL_MapRGB*(format: PSDL_PixelFormat, r: UInt8, g: UInt8, b: UInt8): UInt32{. + cdecl, importc, dynlib: SDLLibName.} + # Maps an RGBA quadruple to a pixel value for a given pixel format +proc SDL_MapRGBA*(format: PSDL_PixelFormat, r: UInt8, g: UInt8, b: UInt8, + a: UInt8): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # Maps a pixel value into the RGB components for a given pixel format +proc SDL_GetRGB*(pixel: UInt32, fmt: PSDL_PixelFormat, r: PUInt8, g: PUInt8, + b: PUInt8){.cdecl, importc, dynlib: SDLLibName.} + # Maps a pixel value into the RGBA components for a given pixel format +proc SDL_GetRGBA*(pixel: UInt32, fmt: PSDL_PixelFormat, r: PUInt8, g: PUInt8, + b: PUInt8, a: PUInt8){.cdecl, importc, dynlib: SDLLibName.} + # Allocate and free an RGB surface (must be called after SDL_SetVideoMode) + # If the depth is 4 or 8 bits, an empty palette is allocated for the surface. + # If the depth is greater than 8 bits, the pixel format is set using the + # flags '[RGB]mask'. + # If the function runs out of memory, it will return NULL. + # + # The 'flags' tell what kind of surface to create. + # SDL_SWSURFACE means that the surface should be created in system memory. + # SDL_HWSURFACE means that the surface should be created in video memory, + # with the same format as the display surface. This is useful for surfaces + # that will not change much, to take advantage of hardware acceleration + # when being blitted to the display surface. + # SDL_ASYNCBLIT means that SDL will try to perform asynchronous blits with + # this surface, but you must always lock it before accessing the pixels. + # SDL will wait for current blits to finish before returning from the lock. + # SDL_SRCCOLORKEY indicates that the surface will be used for colorkey blits. + # If the hardware supports acceleration of colorkey blits between + # two surfaces in video memory, SDL will try to place the surface in + # video memory. If this isn't possible or if there is no hardware + # acceleration available, the surface will be placed in system memory. + # SDL_SRCALPHA means that the surface will be used for alpha blits and + # if the hardware supports hardware acceleration of alpha blits between + # two surfaces in video memory, to place the surface in video memory + # if possible, otherwise it will be placed in system memory. + # If the surface is created in video memory, blits will be _much_ faster, + # but the surface format must be identical to the video surface format, + # and the only way to access the pixels member of the surface is to use + # the SDL_LockSurface() and SDL_UnlockSurface() calls. + # If the requested surface actually resides in video memory, SDL_HWSURFACE + # will be set in the flags member of the returned surface. If for some + # reason the surface could not be placed in video memory, it will not have + # the SDL_HWSURFACE flag set, and will be created in system memory instead. +proc SDL_AllocSurface*(flags: UInt32, width, height, depth: int, + RMask, GMask, BMask, AMask: UInt32): PSDL_Surface +proc SDL_CreateRGBSurface*(flags: UInt32, width, height, depth: int, + RMask, GMask, BMask, AMask: UInt32): PSDL_Surface{. + cdecl, importc, dynlib: SDLLibName.} +proc SDL_CreateRGBSurfaceFrom*(pixels: Pointer, + width, height, depth, pitch: int, + RMask, GMask, BMask, AMask: UInt32): PSDL_Surface{. + cdecl, importc, dynlib: SDLLibName.} +proc SDL_FreeSurface*(surface: PSDL_Surface){.cdecl, importc, dynlib: SDLLibName.} +proc SDL_MustLock*(Surface: PSDL_Surface): bool + # SDL_LockSurface() sets up a surface for directly accessing the pixels. + # Between calls to SDL_LockSurface()/SDL_UnlockSurface(), you can write + # to and read from 'surface->pixels', using the pixel format stored in + # 'surface->format'. Once you are done accessing the surface, you should + # use SDL_UnlockSurface() to release it. + # + # Not all surfaces require locking. If SDL_MUSTLOCK(surface) evaluates + # to 0, then you can read and write to the surface at any time, and the + # pixel format of the surface will not change. In particular, if the + # SDL_HWSURFACE flag is not given when calling SDL_SetVideoMode(), you + # will not need to lock the display surface before accessing it. + # + # No operating system or library calls should be made between lock/unlock + # pairs, as critical system locks may be held during this time. + # + # SDL_LockSurface() returns 0, or -1 if the surface couldn't be locked. +proc SDL_LockSurface*(surface: PSDL_Surface): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_UnlockSurface*(surface: PSDL_Surface){.cdecl, importc, dynlib: SDLLibName.} + # Load a surface from a seekable SDL data source (memory or file.) + # If 'freesrc' is non-zero, the source will be closed after being read. + # Returns the new surface, or NULL if there was an error. + # The new surface should be freed with SDL_FreeSurface(). +proc SDL_LoadBMP_RW*(src: PSDL_RWops, freesrc: int): PSDL_Surface{.cdecl, + importc, dynlib: SDLLibName.} + # Convenience macro -- load a surface from a file +proc SDL_LoadBMP*(filename: cstring): PSDL_Surface + # Save a surface to a seekable SDL data source (memory or file.) + # If 'freedst' is non-zero, the source will be closed after being written. + # Returns 0 if successful or -1 if there was an error. +proc SDL_SaveBMP_RW*(surface: PSDL_Surface, dst: PSDL_RWops, freedst: int): int{. + cdecl, importc, dynlib: SDLLibName.} + # Convenience macro -- save a surface to a file +proc SDL_SaveBMP*(surface: PSDL_Surface, filename: cstring): int + # Sets the color key (transparent pixel) in a blittable surface. + # If 'flag' is SDL_SRCCOLORKEY (optionally OR'd with SDL_RLEACCEL), + # 'key' will be the transparent pixel in the source image of a blit. + # SDL_RLEACCEL requests RLE acceleration for the surface if present, + # and removes RLE acceleration if absent. + # If 'flag' is 0, this function clears any current color key. + # This function returns 0, or -1 if there was an error. +proc SDL_SetColorKey*(surface: PSDL_Surface, flag, key: UInt32): int{.cdecl, + importc, dynlib: SDLLibName.} + # This function sets the alpha value for the entire surface, as opposed to + # using the alpha component of each pixel. This value measures the range + # of transparency of the surface, 0 being completely transparent to 255 + # being completely opaque. An 'alpha' value of 255 causes blits to be + # opaque, the source pixels copied to the destination (the default). Note + # that per-surface alpha can be combined with colorkey transparency. + # + # If 'flag' is 0, alpha blending is disabled for the surface. + # If 'flag' is SDL_SRCALPHA, alpha blending is enabled for the surface. + # OR:ing the flag with SDL_RLEACCEL requests RLE acceleration for the + # surface; if SDL_RLEACCEL is not specified, the RLE accel will be removed. +proc SDL_SetAlpha*(surface: PSDL_Surface, flag: UInt32, alpha: UInt8): int{. + cdecl, importc, dynlib: SDLLibName.} + # Sets the clipping rectangle for the destination surface in a blit. + # + # If the clip rectangle is NULL, clipping will be disabled. + # If the clip rectangle doesn't intersect the surface, the function will + # return SDL_FALSE and blits will be completely clipped. Otherwise the + # function returns SDL_TRUE and blits to the surface will be clipped to + # the intersection of the surface area and the clipping rectangle. + # + # Note that blits are automatically clipped to the edges of the source + # and destination surfaces. +proc SDL_SetClipRect*(surface: PSDL_Surface, rect: PSDL_Rect){.cdecl, + importc, dynlib: SDLLibName.} + # Gets the clipping rectangle for the destination surface in a blit. + # 'rect' must be a pointer to a valid rectangle which will be filled + # with the correct values. +proc SDL_GetClipRect*(surface: PSDL_Surface, rect: PSDL_Rect){.cdecl, + importc, dynlib: SDLLibName.} + # Creates a new surface of the specified format, and then copies and maps + # the given surface to it so the blit of the converted surface will be as + # fast as possible. If this function fails, it returns NULL. + # + # The 'flags' parameter is passed to SDL_CreateRGBSurface() and has those + # semantics. You can also pass SDL_RLEACCEL in the flags parameter and + # SDL will try to RLE accelerate colorkey and alpha blits in the resulting + # surface. + # + # This function is used internally by SDL_DisplayFormat(). +proc SDL_ConvertSurface*(src: PSDL_Surface, fmt: PSDL_PixelFormat, flags: UInt32): PSDL_Surface{. + cdecl, importc, dynlib: SDLLibName.} + # + # This performs a fast blit from the source surface to the destination + # surface. It assumes that the source and destination rectangles are + # the same size. If either 'srcrect' or 'dstrect' are NULL, the entire + # surface (src or dst) is copied. The final blit rectangles are saved + # in 'srcrect' and 'dstrect' after all clipping is performed. + # If the blit is successful, it returns 0, otherwise it returns -1. + # + # The blit function should not be called on a locked surface. + # + # The blit semantics for surfaces with and without alpha and colorkey + # are defined as follows: + # + # RGBA->RGB: + # SDL_SRCALPHA set: + # alpha-blend (using alpha-channel). + # SDL_SRCCOLORKEY ignored. + # SDL_SRCALPHA not set: + # copy RGB. + # if SDL_SRCCOLORKEY set, only copy the pixels matching the + # RGB values of the source colour key, ignoring alpha in the + # comparison. + # + # RGB->RGBA: + # SDL_SRCALPHA set: + # alpha-blend (using the source per-surface alpha value); + # set destination alpha to opaque. + # SDL_SRCALPHA not set: + # copy RGB, set destination alpha to opaque. + # both: + # if SDL_SRCCOLORKEY set, only copy the pixels matching the + # source colour key. + # + # RGBA->RGBA: + # SDL_SRCALPHA set: + # alpha-blend (using the source alpha channel) the RGB values; + # leave destination alpha untouched. [Note: is this correct?] + # SDL_SRCCOLORKEY ignored. + # SDL_SRCALPHA not set: + # copy all of RGBA to the destination. + # if SDL_SRCCOLORKEY set, only copy the pixels matching the + # RGB values of the source colour key, ignoring alpha in the + # comparison. + # + # RGB->RGB: + # SDL_SRCALPHA set: + # alpha-blend (using the source per-surface alpha value). + # SDL_SRCALPHA not set: + # copy RGB. + # both: + # if SDL_SRCCOLORKEY set, only copy the pixels matching the + # source colour key. + # + # If either of the surfaces were in video memory, and the blit returns -2, + # the video memory was lost, so it should be reloaded with artwork and + # re-blitted: + # while ( SDL_BlitSurface(image, imgrect, screen, dstrect) = -2 ) do + # begin + # while ( SDL_LockSurface(image) < 0 ) do + # Sleep(10); + # -- Write image pixels to image->pixels -- + # SDL_UnlockSurface(image); + # end; + # + # This happens under DirectX 5.0 when the system switches away from your + # fullscreen application. The lock will also fail until you have access + # to the video memory again. + # You should call SDL_BlitSurface() unless you know exactly how SDL + # blitting works internally and how to use the other blit functions. +proc SDL_BlitSurface*(src: PSDL_Surface, srcrect: PSDL_Rect, dst: PSDL_Surface, + dstrect: PSDL_Rect): int + # This is the public blit function, SDL_BlitSurface(), and it performs + # rectangle validation and clipping before passing it to SDL_LowerBlit() +proc SDL_UpperBlit*(src: PSDL_Surface, srcrect: PSDL_Rect, dst: PSDL_Surface, + dstrect: PSDL_Rect): int{.cdecl, importc, dynlib: SDLLibName.} + # This is a semi-private blit function and it performs low-level surface + # blitting only. +proc SDL_LowerBlit*(src: PSDL_Surface, srcrect: PSDL_Rect, dst: PSDL_Surface, + dstrect: PSDL_Rect): int{.cdecl, importc, dynlib: SDLLibName.} + # This function performs a fast fill of the given rectangle with 'color' + # The given rectangle is clipped to the destination surface clip area + # and the final fill rectangle is saved in the passed in pointer. + # If 'dstrect' is NULL, the whole surface will be filled with 'color' + # The color should be a pixel of the format used by the surface, and + # can be generated by the SDL_MapRGB() function. + # This function returns 0 on success, or -1 on error. +proc SDL_FillRect*(dst: PSDL_Surface, dstrect: PSDL_Rect, color: UInt32): int{. + cdecl, importc, dynlib: SDLLibName.} + # This function takes a surface and copies it to a new surface of the + # pixel format and colors of the video framebuffer, suitable for fast + # blitting onto the display surface. It calls SDL_ConvertSurface() + # + # If you want to take advantage of hardware colorkey or alpha blit + # acceleration, you should set the colorkey and alpha value before + # calling this function. + # + # If the conversion fails or runs out of memory, it returns NULL +proc SDL_DisplayFormat*(surface: PSDL_Surface): PSDL_Surface{.cdecl, + importc, dynlib: SDLLibName.} + # This function takes a surface and copies it to a new surface of the + # pixel format and colors of the video framebuffer (if possible), + # suitable for fast alpha blitting onto the display surface. + # The new surface will always have an alpha channel. + # + # If you want to take advantage of hardware colorkey or alpha blit + # acceleration, you should set the colorkey and alpha value before + # calling this function. + # + # If the conversion fails or runs out of memory, it returns NULL +proc SDL_DisplayFormatAlpha*(surface: PSDL_Surface): PSDL_Surface{.cdecl, + importc, dynlib: SDLLibName.} + #* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #* YUV video surface overlay functions */ + #* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + # This function creates a video output overlay + # Calling the returned surface an overlay is something of a misnomer because + # the contents of the display surface underneath the area where the overlay + # is shown is undefined - it may be overwritten with the converted YUV data. +proc SDL_CreateYUVOverlay*(width: int, height: int, format: UInt32, + display: PSDL_Surface): PSDL_Overlay{.cdecl, + importc, dynlib: SDLLibName.} + # Lock an overlay for direct access, and unlock it when you are done +proc SDL_LockYUVOverlay*(Overlay: PSDL_Overlay): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_UnlockYUVOverlay*(Overlay: PSDL_Overlay){.cdecl, importc, dynlib: SDLLibName.} + # Blit a video overlay to the display surface. + # The contents of the video surface underneath the blit destination are + # not defined. + # The width and height of the destination rectangle may be different from + # that of the overlay, but currently only 2x scaling is supported. +proc SDL_DisplayYUVOverlay*(Overlay: PSDL_Overlay, dstrect: PSDL_Rect): int{. + cdecl, importc, dynlib: SDLLibName.} + # Free a video overlay +proc SDL_FreeYUVOverlay*(Overlay: PSDL_Overlay){.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # OpenGL Routines + #------------------------------------------------------------------------------ + # Dynamically load a GL driver, if SDL is built with dynamic GL. + # + # SDL links normally with the OpenGL library on your system by default, + # but you can compile it to dynamically load the GL driver at runtime. + # If you do this, you need to retrieve all of the GL functions used in + # your program from the dynamic library using SDL_GL_GetProcAddress(). + # + # This is disabled in default builds of SDL. +proc SDL_GL_LoadLibrary*(filename: cstring): int{.cdecl, importc, dynlib: SDLLibName.} + # Get the address of a GL function (for extension functions) +proc SDL_GL_GetProcAddress*(procname: cstring): Pointer{.cdecl, + importc, dynlib: SDLLibName.} + # Set an attribute of the OpenGL subsystem before intialization. +proc SDL_GL_SetAttribute*(attr: TSDL_GLAttr, value: int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Get an attribute of the OpenGL subsystem from the windowing + # interface, such as glX. This is of course different from getting + # the values from SDL's internal OpenGL subsystem, which only + # stores the values you request before initialization. + # + # Developers should track the values they pass into SDL_GL_SetAttribute + # themselves if they want to retrieve these values. +proc SDL_GL_GetAttribute*(attr: TSDL_GLAttr, value: var int): int{.cdecl, + importc, dynlib: SDLLibName.} + # Swap the OpenGL buffers, if double-buffering is supported. +proc SDL_GL_SwapBuffers*(){.cdecl, importc, dynlib: SDLLibName.} + # Internal functions that should not be called unless you have read + # and understood the source code for these functions. +proc SDL_GL_UpdateRects*(numrects: int, rects: PSDL_Rect){.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_GL_Lock*(){.cdecl, importc, dynlib: SDLLibName.} +proc SDL_GL_Unlock*(){.cdecl, importc, dynlib: SDLLibName.} + #* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + #* These functions allow interaction with the window manager, if any. * + #* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Sets/Gets the title and icon text of the display window +proc SDL_WM_GetCaption*(title: var cstring, icon: var cstring){.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_WM_SetCaption*(title: cstring, icon: cstring){.cdecl, + importc, dynlib: SDLLibName.} + # Sets the icon for the display window. + # This function must be called before the first call to SDL_SetVideoMode(). + # It takes an icon surface, and a mask in MSB format. + # If 'mask' is NULL, the entire icon surface will be used as the icon. +proc SDL_WM_SetIcon*(icon: PSDL_Surface, mask: UInt8){.cdecl, importc, dynlib: SDLLibName.} + # This function iconifies the window, and returns 1 if it succeeded. + # If the function succeeds, it generates an SDL_APPACTIVE loss event. + # This function is a noop and returns 0 in non-windowed environments. +proc SDL_WM_IconifyWindow*(): int{.cdecl, importc, dynlib: SDLLibName.} + # Toggle fullscreen mode without changing the contents of the screen. + # If the display surface does not require locking before accessing + # the pixel information, then the memory pointers will not change. + # + # If this function was able to toggle fullscreen mode (change from + # running in a window to fullscreen, or vice-versa), it will return 1. + # If it is not implemented, or fails, it returns 0. + # + # The next call to SDL_SetVideoMode() will set the mode fullscreen + # attribute based on the flags parameter - if SDL_FULLSCREEN is not + # set, then the display will be windowed by default where supported. + # + # This is currently only implemented in the X11 video driver. +proc SDL_WM_ToggleFullScreen*(surface: PSDL_Surface): int{.cdecl, + importc, dynlib: SDLLibName.} + # Grabbing means that the mouse is confined to the application window, + # and nearly all keyboard input is passed directly to the application, + # and not interpreted by a window manager, if any. +proc SDL_WM_GrabInput*(mode: TSDL_GrabMode): TSDL_GrabMode{.cdecl, + importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # mouse-routines + #------------------------------------------------------------------------------ + # Retrieve the current state of the mouse. + # The current button state is returned as a button bitmask, which can + # be tested using the SDL_BUTTON(X) macros, and x and y are set to the + # current mouse cursor position. You can pass NULL for either x or y. +proc SDL_GetMouseState*(x: var int, y: var int): UInt8{.cdecl, + importc, dynlib: SDLLibName.} + # Retrieve the current state of the mouse. + # The current button state is returned as a button bitmask, which can + # be tested using the SDL_BUTTON(X) macros, and x and y are set to the + # mouse deltas since the last call to SDL_GetRelativeMouseState(). +proc SDL_GetRelativeMouseState*(x: var int, y: var int): UInt8{.cdecl, + importc, dynlib: SDLLibName.} + # Set the position of the mouse cursor (generates a mouse motion event) +proc SDL_WarpMouse*(x, y: UInt16){.cdecl, importc, dynlib: SDLLibName.} + # Create a cursor using the specified data and mask (in MSB format). + # The cursor width must be a multiple of 8 bits. + # + # The cursor is created in black and white according to the following: + # data mask resulting pixel on screen + # 0 1 White + # 1 1 Black + # 0 0 Transparent + # 1 0 Inverted color if possible, black if not. + # + # Cursors created with this function must be freed with SDL_FreeCursor(). +proc SDL_CreateCursor*(data, mask: PUInt8, w, h, hot_x, hot_y: int): PSDL_Cursor{. + cdecl, importc, dynlib: SDLLibName.} + # Set the currently active cursor to the specified one. + # If the cursor is currently visible, the change will be immediately + # represented on the display. +proc SDL_SetCursor*(cursor: PSDL_Cursor){.cdecl, importc, dynlib: SDLLibName.} + # Returns the currently active cursor. +proc SDL_GetCursor*(): PSDL_Cursor{.cdecl, importc, dynlib: SDLLibName.} + # Deallocates a cursor created with SDL_CreateCursor(). +proc SDL_FreeCursor*(cursor: PSDL_Cursor){.cdecl, importc, dynlib: SDLLibName.} + # Toggle whether or not the cursor is shown on the screen. + # The cursor start off displayed, but can be turned off. + # SDL_ShowCursor() returns 1 if the cursor was being displayed + # before the call, or 0 if it was not. You can query the current + # state by passing a 'toggle' value of -1. +proc SDL_ShowCursor*(toggle: int): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_BUTTON*(Button: int): int + #------------------------------------------------------------------------------ + # Keyboard-routines + #------------------------------------------------------------------------------ + # Enable/Disable UNICODE translation of keyboard input. + # This translation has some overhead, so translation defaults off. + # If 'enable' is 1, translation is enabled. + # If 'enable' is 0, translation is disabled. + # If 'enable' is -1, the translation state is not changed. + # It returns the previous state of keyboard translation. +proc SDL_EnableUNICODE*(enable: int): int{.cdecl, importc, dynlib: SDLLibName.} + # If 'delay' is set to 0, keyboard repeat is disabled. +proc SDL_EnableKeyRepeat*(delay: int, interval: int): int{.cdecl, + importc, dynlib: SDLLibName.} +proc SDL_GetKeyRepeat*(delay: PInteger, interval: PInteger){.cdecl, + importc, dynlib: SDLLibName.} + # Get a snapshot of the current state of the keyboard. + # Returns an array of keystates, indexed by the SDLK_* syms. + # Used: + # + # UInt8 *keystate = SDL_GetKeyState(NULL); + # if ( keystate[SDLK_RETURN] ) ... <RETURN> is pressed +proc SDL_GetKeyState*(numkeys: PInt): PUInt8{.cdecl, importc, dynlib: SDLLibName.} + # Get the current key modifier state +proc SDL_GetModState*(): TSDLMod{.cdecl, importc, dynlib: SDLLibName.} + # Set the current key modifier state + # This does not change the keyboard state, only the key modifier flags. +proc SDL_SetModState*(modstate: TSDLMod){.cdecl, importc, dynlib: SDLLibName.} + # Get the name of an SDL virtual keysym +proc SDL_GetKeyName*(key: TSDLKey): cstring{.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # Active Routines + #------------------------------------------------------------------------------ + # This function returns the current state of the application, which is a + # bitwise combination of SDL_APPMOUSEFOCUS, SDL_APPINPUTFOCUS, and + # SDL_APPACTIVE. If SDL_APPACTIVE is set, then the user is able to + # see your application, otherwise it has been iconified or disabled. +proc SDL_GetAppState*(): UInt8{.cdecl, importc, dynlib: SDLLibName.} + # Mutex functions + # Create a mutex, initialized unlocked +proc SDL_CreateMutex*(): PSDL_Mutex{.cdecl, importc, dynlib: SDLLibName.} + # Lock the mutex (Returns 0, or -1 on error) +proc SDL_mutexP*(mutex: PSDL_mutex): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_LockMutex*(mutex: PSDL_mutex): int + # Unlock the mutex (Returns 0, or -1 on error) +proc SDL_mutexV*(mutex: PSDL_mutex): int{.cdecl, importc, dynlib: SDLLibName.} +proc SDL_UnlockMutex*(mutex: PSDL_mutex): int + # Destroy a mutex +proc SDL_DestroyMutex*(mutex: PSDL_mutex){.cdecl, importc, dynlib: SDLLibName.} + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Semaphore functions + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Create a semaphore, initialized with value, returns NULL on failure. +proc SDL_CreateSemaphore*(initial_value: UInt32): PSDL_Sem{.cdecl, + importc, dynlib: SDLLibName.} + # Destroy a semaphore +proc SDL_DestroySemaphore*(sem: PSDL_sem){.cdecl, importc, dynlib: SDLLibName.} + # This function suspends the calling thread until the semaphore pointed + # to by sem has a positive count. It then atomically decreases the semaphore + # count. +proc SDL_SemWait*(sem: PSDL_sem): int{.cdecl, importc, dynlib: SDLLibName.} + # Non-blocking variant of SDL_SemWait(), returns 0 if the wait succeeds, + # SDL_MUTEX_TIMEDOUT if the wait would block, and -1 on error. +proc SDL_SemTryWait*(sem: PSDL_sem): int{.cdecl, importc, dynlib: SDLLibName.} + # Variant of SDL_SemWait() with a timeout in milliseconds, returns 0 if + # the wait succeeds, SDL_MUTEX_TIMEDOUT if the wait does not succeed in + # the allotted time, and -1 on error. + # On some platforms this function is implemented by looping with a delay + # of 1 ms, and so should be avoided if possible. +proc SDL_SemWaitTimeout*(sem: PSDL_sem, ms: UInt32): int{.cdecl, + importc, dynlib: SDLLibName.} + # Atomically increases the semaphore's count (not blocking), returns 0, + # or -1 on error. +proc SDL_SemPost*(sem: PSDL_sem): int{.cdecl, importc, dynlib: SDLLibName.} + # Returns the current count of the semaphore +proc SDL_SemValue*(sem: PSDL_sem): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Condition variable functions + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Create a condition variable +proc SDL_CreateCond*(): PSDL_Cond{.cdecl, importc, dynlib: SDLLibName.} + # Destroy a condition variable +proc SDL_DestroyCond*(cond: PSDL_Cond){.cdecl, importc, dynlib: SDLLibName.} + # Restart one of the threads that are waiting on the condition variable, + # returns 0 or -1 on error. +proc SDL_CondSignal*(cond: PSDL_cond): int{.cdecl, importc, dynlib: SDLLibName.} + # Restart all threads that are waiting on the condition variable, + # returns 0 or -1 on error. +proc SDL_CondBroadcast*(cond: PSDL_cond): int{.cdecl, importc, dynlib: SDLLibName.} + # Wait on the condition variable, unlocking the provided mutex. + # The mutex must be locked before entering this function! + # Returns 0 when it is signaled, or -1 on error. +proc SDL_CondWait*(cond: PSDL_cond, mut: PSDL_mutex): int{.cdecl, + importc, dynlib: SDLLibName.} + # Waits for at most 'ms' milliseconds, and returns 0 if the condition + # variable is signaled, SDL_MUTEX_TIMEDOUT if the condition is not + # signaled in the allotted time, and -1 on error. + # On some platforms this function is implemented by looping with a delay + # of 1 ms, and so should be avoided if possible. +proc SDL_CondWaitTimeout*(cond: PSDL_cond, mut: PSDL_mutex, ms: UInt32): int{. + cdecl, importc, dynlib: SDLLibName.} + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Condition variable functions + # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + # Create a thread +proc SDL_CreateThread*(fn: PInt, data: Pointer): PSDL_Thread{.cdecl, + importc, dynlib: SDLLibName.} + # Get the 32-bit thread identifier for the current thread +proc SDL_ThreadID*(): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # Get the 32-bit thread identifier for the specified thread, + # equivalent to SDL_ThreadID() if the specified thread is NULL. +proc SDL_GetThreadID*(thread: PSDL_Thread): UInt32{.cdecl, importc, dynlib: SDLLibName.} + # Wait for a thread to finish. + # The return code for the thread function is placed in the area + # pointed to by 'status', if 'status' is not NULL. +proc SDL_WaitThread*(thread: PSDL_Thread, status: var int){.cdecl, + importc, dynlib: SDLLibName.} + # Forcefully kill a thread without worrying about its state +proc SDL_KillThread*(thread: PSDL_Thread){.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + # Get Environment Routines + #------------------------------------------------------------------------------ + #* + # * This function gives you custom hooks into the window manager information. + # * It fills the structure pointed to by 'info' with custom information and + # * returns 1 if the function is implemented. If it's not implemented, or + # * the version member of the 'info' structure is invalid, it returns 0. + # * +proc SDL_GetWMInfo*(info: PSDL_SysWMinfo): int{.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ + #SDL_loadso.h + #* This function dynamically loads a shared object and returns a pointer + # * to the object handle (or NULL if there was an error). + # * The 'sofile' parameter is a system dependent name of the object file. + # * +proc SDL_LoadObject*(sofile: cstring): Pointer{.cdecl, importc, dynlib: SDLLibName.} + #* Given an object handle, this function looks up the address of the + # * named function in the shared object and returns it. This address + # * is no longer valid after calling SDL_UnloadObject(). + # * +proc SDL_LoadFunction*(handle: Pointer, name: cstring): Pointer{.cdecl, + importc, dynlib: SDLLibName.} + #* Unload a shared object from memory * +proc SDL_UnloadObject*(handle: Pointer){.cdecl, importc, dynlib: SDLLibName.} + #------------------------------------------------------------------------------ +proc SDL_Swap32*(D: Uint32): Uint32 + # Bitwise Checking functions +proc IsBitOn*(value: int, bit: int8): bool +proc TurnBitOn*(value: int, bit: int8): int +proc TurnBitOff*(value: int, bit: int8): int +# implementation + +proc SDL_TABLESIZE(table: cstring): int = + Result = SizeOf(table) div SizeOf(table[0]) + +proc SDL_OutOfMemory() = + when not(defined(WINDOWS)): SDL_Error(SDL_ENOMEM) + +proc SDL_RWSeek(context: PSDL_RWops, offset: int, whence: int): int = + Result = context.seek(context, offset, whence) + +proc SDL_RWTell(context: PSDL_RWops): int = + Result = context.seek(context, 0, 1) + +proc SDL_RWRead(context: PSDL_RWops, theptr: Pointer, size: int, n: int): int = + Result = context.read(context, theptr, size, n) + +proc SDL_RWWrite(context: PSDL_RWops, theptr: Pointer, size: int, n: int): int = + Result = context.write(context, theptr, size, n) + +proc SDL_RWClose(context: PSDL_RWops): int = + Result = context.closeFile(context) + +proc SDL_LoadWAV(filename: cstring, spec: PSDL_AudioSpec, audio_buf: PUInt8, + audiolen: PUInt32): PSDL_AudioSpec = + Result = SDL_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1, spec, audio_buf, + audiolen) + +proc SDL_CDInDrive(status: TSDL_CDStatus): bool = + Result = ord(status) > ord(CD_ERROR) + +proc FRAMES_TO_MSF(frames: int, M: var int, S: var int, F: var int) = + var value: int + value = frames + F = value mod CD_FPS + value = value div CD_FPS + S = value mod 60 + value = value div 60 + M = value + +proc MSF_TO_FRAMES(M: int, S: int, F: int): int = + Result = M * 60 * CD_FPS + S * CD_FPS + F + +proc SDL_VERSION(X: var TSDL_Version) = + X.major = SDL_MAJOR_VERSION + X.minor = SDL_MINOR_VERSION + X.patch = SDL_PATCHLEVEL + +proc SDL_VERSIONNUM(X, Y, Z: int): int = + Result = X * 1000 + Y * 100 + Z + +proc SDL_COMPILEDVERSION(): int = + Result = SDL_VERSIONNUM(SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL) + +proc SDL_VERSION_ATLEAST(X, Y, Z: int): bool = + Result = (SDL_COMPILEDVERSION() >= SDL_VERSIONNUM(X, Y, Z)) + +proc SDL_LoadBMP(filename: cstring): PSDL_Surface = + Result = SDL_LoadBMP_RW(SDL_RWFromFile(filename, "rb"), 1) + +proc SDL_SaveBMP(surface: PSDL_Surface, filename: cstring): int = + Result = SDL_SaveBMP_RW(surface, SDL_RWFromFile(filename, "wb"), 1) + +proc SDL_BlitSurface(src: PSDL_Surface, srcrect: PSDL_Rect, dst: PSDL_Surface, + dstrect: PSDL_Rect): int = + Result = SDL_UpperBlit(src, srcrect, dst, dstrect) + +proc SDL_AllocSurface(flags: UInt32, width, height, depth: int, + RMask, GMask, BMask, AMask: UInt32): PSDL_Surface = + Result = SDL_CreateRGBSurface(flags, width, height, depth, RMask, GMask, + BMask, AMask) + +proc SDL_MustLock(Surface: PSDL_Surface): bool = + Result = ((surface^ .offset != 0) or + ((surface^ .flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) != + 0)) + +proc SDL_LockMutex(mutex: PSDL_mutex): int = + Result = SDL_mutexP(mutex) + +proc SDL_UnlockMutex(mutex: PSDL_mutex): int = + Result = SDL_mutexV(mutex) + +proc SDL_BUTTON(Button: int): int = + Result = SDL_PRESSED shl (Button - 1) + +proc SDL_Swap32(D: Uint32): Uint32 = + Result = ((D shl 24) or ((D shl 8) and 0x00FF0000) or + ((D shr 8) and 0x0000FF00) or (D shr 24)) + +proc IsBitOn(value: int, bit: int8): bool = + result = ((value and (1 shl ze(bit))) != 0) + +proc TurnBitOn(value: int, bit: int8): int = + result = (value or (1 shl ze(bit))) + +proc TurnBitOff(value: int, bit: int8): int = + result = (value and not (1 shl ze(bit))) diff --git a/lib/wrappers/sdl/sdl_gfx.nim b/lib/wrappers/sdl/sdl_gfx.nim new file mode 100644 index 000000000..8ae8eca0b --- /dev/null +++ b/lib/wrappers/sdl/sdl_gfx.nim @@ -0,0 +1,421 @@ + +# +# $Id: sdl_gfx.pas,v 1.3 2007/05/29 21:31:04 savage Exp $ +# +# +# +# $Log: sdl_gfx.pas,v $ +# Revision 1.3 2007/05/29 21:31:04 savage +# Changes as suggested by Almindor for 64bit compatibility. +# +# Revision 1.2 2007/05/20 20:30:18 savage +# Initial Changes to Handle 64 Bits +# +# Revision 1.1 2005/01/03 19:08:32 savage +# Header for the SDL_Gfx library. +# +# +# +# + +import + sdl + +when defined(windows): + const SDLgfxLibName = "SDL_gfx.dll" +elif defined(macosx): + const SDLgfxLibName = "libSDL_gfx.dylib" +else: + const SDLgfxLibName = "libSDL_gfx.so" + +const # Some rates in Hz + FPS_UPPER_LIMIT* = 200 + FPS_LOWER_LIMIT* = 1 + FPS_DEFAULT* = 30 # ---- Defines + SMOOTHING_OFF* = 0 + SMOOTHING_ON* = 1 + +type + PFPSmanager* = ptr TFPSmanager + TFPSmanager*{.final.} = object # ---- Structures + framecount*: Uint32 + rateticks*: float32 + lastticks*: Uint32 + rate*: Uint32 + + PColorRGBA* = ptr TColorRGBA + TColorRGBA*{.final.} = object + r*: Uint8 + g*: Uint8 + b*: Uint8 + a*: Uint8 + + PColorY* = ptr TColorY + TColorY*{.final.} = object # + # + # SDL_framerate: framerate manager + # + # LGPL (c) A. Schiffler + # + # + y*: Uint8 + + +proc SDL_initFramerate*(manager: PFPSmanager){.cdecl, importc, dynlib: SDLgfxLibName.} +proc SDL_setFramerate*(manager: PFPSmanager, rate: int): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc SDL_getFramerate*(manager: PFPSmanager): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc SDL_framerateDelay*(manager: PFPSmanager){.cdecl, importc, dynlib: SDLgfxLibName.} + # + # + # SDL_gfxPrimitives: graphics primitives for SDL + # + # LGPL (c) A. Schiffler + # + # + # Note: all ___Color routines expect the color to be in format 0xRRGGBBAA + # Pixel +proc pixelColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, color: Uint32): int{. + cdecl, importc, dynlib: SDLgfxLibName.} +proc pixelRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, r: Uint8, g: Uint8, + b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Horizontal line +proc hlineColor*(dst: PSDL_Surface, x1: Sint16, x2: Sint16, y: Sint16, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc hlineRGBA*(dst: PSDL_Surface, x1: Sint16, x2: Sint16, y: Sint16, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Vertical line +proc vlineColor*(dst: PSDL_Surface, x: Sint16, y1: Sint16, y2: Sint16, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc vlineRGBA*(dst: PSDL_Surface, x: Sint16, y1: Sint16, y2: Sint16, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Rectangle +proc rectangleColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, color: Uint32): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc rectangleRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Filled rectangle (Box) +proc boxColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc boxRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, y2: Sint16, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Line +proc lineColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc lineRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # AA Line +proc aalineColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc aalineRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Circle +proc circleColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, r: Sint16, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc circleRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # AA Circle +proc aacircleColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, r: Sint16, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc aacircleRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Filled Circle +proc filledCircleColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, r: Sint16, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc filledCircleRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Ellipse +proc ellipseColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, rx: Sint16, + ry: Sint16, color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc ellipseRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rx: Sint16, + ry: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # AA Ellipse +proc aaellipseColor*(dst: PSDL_Surface, xc: Sint16, yc: Sint16, rx: Sint16, + ry: Sint16, color: Uint32): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc aaellipseRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rx: Sint16, + ry: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Filled Ellipse +proc filledEllipseColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, rx: Sint16, + ry: Sint16, color: Uint32): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc filledEllipseRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rx: Sint16, + ry: Sint16, r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Pie +proc pieColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + start: Sint16, finish: Sint16, color: Uint32): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc pieRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + start: Sint16, finish: Sint16, r: Uint8, g: Uint8, b: Uint8, + a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Filled Pie +proc filledPieColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + start: Sint16, finish: Sint16, color: Uint32): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc filledPieRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, rad: Sint16, + start: Sint16, finish: Sint16, r: Uint8, g: Uint8, b: Uint8, + a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Trigon +proc trigonColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, color: Uint32): int{. + cdecl, importc, dynlib: SDLgfxLibName.} +proc trigonRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, r: Uint8, g: Uint8, + b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # AA-Trigon +proc aatrigonColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, color: Uint32): int{. + cdecl, importc, dynlib: SDLgfxLibName.} +proc aatrigonRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, r: Uint8, g: Uint8, + b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Filled Trigon +proc filledTrigonColor*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, color: Uint32): int{. + cdecl, importc, dynlib: SDLgfxLibName.} +proc filledTrigonRGBA*(dst: PSDL_Surface, x1: Sint16, y1: Sint16, x2: Sint16, + y2: Sint16, x3: Sint16, y3: Sint16, r: Uint8, g: Uint8, + b: Uint8, a: Uint8): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Polygon +proc polygonColor*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc polygonRGBA*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # AA-Polygon +proc aapolygonColor*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc aapolygonRGBA*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Filled Polygon +proc filledPolygonColor*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc filledPolygonRGBA*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Bezier + # s = number of steps +proc bezierColor*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, s: int, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc bezierRGBA*(dst: PSDL_Surface, vx: PSint16, vy: PSint16, n: int, s: int, + r: Uint8, g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Characters/Strings +proc characterColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, c: char, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc characterRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, c: char, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc stringColor*(dst: PSDL_Surface, x: Sint16, y: Sint16, c: cstring, + color: Uint32): int{.cdecl, importc, dynlib: SDLgfxLibName.} +proc stringRGBA*(dst: PSDL_Surface, x: Sint16, y: Sint16, c: cstring, r: Uint8, + g: Uint8, b: Uint8, a: Uint8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} +proc gfxPrimitivesSetFont*(fontdata: Pointer, cw: int, ch: int){.cdecl, + importc, dynlib: SDLgfxLibName.} + # + # + # SDL_imageFilter - bytes-image "filter" routines + # (uses inline x86 MMX optimizations if available) + # + # LGPL (c) A. Schiffler + # + # + # Comments: + # 1.) MMX functions work best if all data blocks are aligned on a 32 bytes boundary. + # 2.) Data that is not within an 8 byte boundary is processed using the C routine. + # 3.) Convolution routines do not have C routines at this time. + # Detect MMX capability in CPU +proc SDL_imageFilterMMXdetect*(): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # Force use of MMX off (or turn possible use back on) +proc SDL_imageFilterMMXoff*(){.cdecl, importc, dynlib: SDLgfxLibName.} +proc SDL_imageFilterMMXon*(){.cdecl, importc, dynlib: SDLgfxLibName.} + # + # All routines return: + # 0 OK + # -1 Error (internal error, parameter error) + # + # SDL_imageFilterAdd: D = saturation255(S1 + S2) +proc SDL_imageFilterAdd*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMean: D = S1/2 + S2/2 +proc SDL_imageFilterMean*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterSub: D = saturation0(S1 - S2) +proc SDL_imageFilterSub*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterAbsDiff: D = | S1 - S2 | +proc SDL_imageFilterAbsDiff*(Src1: cstring, Src2: cstring, Dest: cstring, + len: int): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMult: D = saturation(S1 * S2) +proc SDL_imageFilterMult*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMultNor: D = S1 * S2 (non-MMX) +proc SDL_imageFilterMultNor*(Src1: cstring, Src2: cstring, Dest: cstring, + len: int): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMultDivby2: D = saturation255(S1/2 * S2) +proc SDL_imageFilterMultDivby2*(Src1: cstring, Src2: cstring, Dest: cstring, + len: int): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMultDivby4: D = saturation255(S1/2 * S2/2) +proc SDL_imageFilterMultDivby4*(Src1: cstring, Src2: cstring, Dest: cstring, + len: int): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterBitAnd: D = S1 & S2 +proc SDL_imageFilterBitAnd*(Src1: cstring, Src2: cstring, Dest: cstring, + len: int): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterBitOr: D = S1 | S2 +proc SDL_imageFilterBitOr*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterDiv: D = S1 / S2 (non-MMX) +proc SDL_imageFilterDiv*(Src1: cstring, Src2: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterBitNegation: D = !S +proc SDL_imageFilterBitNegation*(Src1: cstring, Dest: cstring, len: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterAddByte: D = saturation255(S + C) +proc SDL_imageFilterAddByte*(Src1: cstring, Dest: cstring, len: int, C: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterAddUint: D = saturation255(S + (uint)C) +proc SDL_imageFilterAddUint*(Src1: cstring, Dest: cstring, len: int, C: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterAddByteToHalf: D = saturation255(S/2 + C) +proc SDL_imageFilterAddByteToHalf*(Src1: cstring, Dest: cstring, len: int, + C: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterSubByte: D = saturation0(S - C) +proc SDL_imageFilterSubByte*(Src1: cstring, Dest: cstring, len: int, C: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterSubUint: D = saturation0(S - (uint)C) +proc SDL_imageFilterSubUint*(Src1: cstring, Dest: cstring, len: int, C: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftRight: D = saturation0(S >> N) +proc SDL_imageFilterShiftRight*(Src1: cstring, Dest: cstring, len: int, N: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftRightUint: D = saturation0((uint)S >> N) +proc SDL_imageFilterShiftRightUint*(Src1: cstring, Dest: cstring, len: int, + N: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterMultByByte: D = saturation255(S * C) +proc SDL_imageFilterMultByByte*(Src1: cstring, Dest: cstring, len: int, C: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftRightAndMultByByte: D = saturation255((S >> N) * C) +proc SDL_imageFilterShiftRightAndMultByByte*(Src1: cstring, Dest: cstring, + len: int, N: char, C: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftLeftByte: D = (S << N) +proc SDL_imageFilterShiftLeftByte*(Src1: cstring, Dest: cstring, len: int, + N: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftLeftUint: D = ((uint)S << N) +proc SDL_imageFilterShiftLeftUint*(Src1: cstring, Dest: cstring, len: int, + N: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterShiftLeft: D = saturation255(S << N) +proc SDL_imageFilterShiftLeft*(Src1: cstring, Dest: cstring, len: int, N: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterBinarizeUsingThreshold: D = S >= T ? 255:0 +proc SDL_imageFilterBinarizeUsingThreshold*(Src1: cstring, Dest: cstring, + len: int, T: char): int{.cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterClipToRange: D = (S >= Tmin) & (S <= Tmax) 255:0 +proc SDL_imageFilterClipToRange*(Src1: cstring, Dest: cstring, len: int, + Tmin: int8, Tmax: int8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterNormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin) +proc SDL_imageFilterNormalizeLinear*(Src1: cstring, Dest: cstring, len: int, + Cmin: int, Cmax: int, Nmin: int, Nmax: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # !!! NO C-ROUTINE FOR THESE FUNCTIONS YET !!! + # SDL_imageFilterConvolveKernel3x3Divide: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel3x3Divide*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, Divisor: int8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel5x5Divide: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel5x5Divide*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, Divisor: int8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel7x7Divide: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel7x7Divide*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, Divisor: int8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel9x9Divide: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel9x9Divide*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, Divisor: int8): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel3x3ShiftRight: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel3x3ShiftRight*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, NRightShift: char): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel5x5ShiftRight: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel5x5ShiftRight*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, NRightShift: char): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel7x7ShiftRight: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel7x7ShiftRight*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, NRightShift: char): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterConvolveKernel9x9ShiftRight: Dij = saturation0and255( ... ) +proc SDL_imageFilterConvolveKernel9x9ShiftRight*(Src: cstring, Dest: cstring, + rows: int, columns: int, Kernel: PShortInt, NRightShift: char): int{.cdecl, + importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterSobelX: Dij = saturation255( ... ) +proc SDL_imageFilterSobelX*(Src: cstring, Dest: cstring, rows: int, columns: int): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # SDL_imageFilterSobelXShiftRight: Dij = saturation255( ... ) +proc SDL_imageFilterSobelXShiftRight*(Src: cstring, Dest: cstring, rows: int, + columns: int, NRightShift: char): int{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Align/restore stack to 32 byte boundary -- Functionality untested! -- +proc SDL_imageFilterAlignStack*(){.cdecl, importc, dynlib: SDLgfxLibName.} +proc SDL_imageFilterRestoreStack*(){.cdecl, importc, dynlib: SDLgfxLibName.} + # + # + # SDL_rotozoom - rotozoomer + # + # LGPL (c) A. Schiffler + # + # + # + # + # rotozoomSurface() + # + # Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + # 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 + # then the destination 32bit surface is anti-aliased. If the surface is not 8bit + # or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + # + # +proc rotozoomSurface*(src: PSDL_Surface, angle: float64, zoom: float64, + smooth: int): PSDL_Surface{.cdecl, importc, dynlib: SDLgfxLibName.} +proc rotozoomSurfaceXY*(src: PSDL_Surface, angle: float64, zoomx: float64, + zoomy: float64, smooth: int): PSDL_Surface{.cdecl, + importc, dynlib: SDLgfxLibName.} + # Returns the size of the target surface for a rotozoomSurface() call +proc rotozoomSurfaceSize*(width: int, height: int, angle: float64, + zoom: float64, dstwidth: var int, dstheight: var int){. + cdecl, importc, dynlib: SDLgfxLibName.} +proc rotozoomSurfaceSizeXY*(width: int, height: int, angle: float64, + zoomx: float64, zoomy: float64, dstwidth: var int, + dstheight: var int){.cdecl, importc, dynlib: SDLgfxLibName.} + # + # + # zoomSurface() + # + # Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. + # 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 + # then the destination 32bit surface is anti-aliased. If the surface is not 8bit + # or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. + # + # +proc zoomSurface*(src: PSDL_Surface, zoomx: float64, zoomy: float64, smooth: int): PSDL_Surface{. + cdecl, importc, dynlib: SDLgfxLibName.} + # Returns the size of the target surface for a zoomSurface() call +proc zoomSurfaceSize*(width: int, height: int, zoomx: float64, zoomy: float64, + dstwidth: var int, dstheight: var int){.cdecl, + importc, dynlib: SDLgfxLibName.} +# implementation diff --git a/lib/wrappers/sdl/sdl_image.nim b/lib/wrappers/sdl/sdl_image.nim new file mode 100644 index 000000000..a15afd575 --- /dev/null +++ b/lib/wrappers/sdl/sdl_image.nim @@ -0,0 +1,227 @@ + +# +# $Id: sdl_image.pas,v 1.14 2007/05/29 21:31:13 savage Exp $ +# +# +#****************************************************************************** +# +# Borland Delphi SDL_Image - An example image loading library for use +# with SDL +# Conversion of the Simple DirectMedia Layer Image Headers +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : SDL_image.h +# +# The initial developer of this Pascal code was : +# Matthias Thoma <ma.thoma@gmx.de> +# +# Portions created by Matthias Thoma are +# Copyright (C) 2000 - 2001 Matthias Thoma. +# +# +# Contributor(s) +# -------------- +# Dominique Louis <Dominique@SavageSoftware.com.au> +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# A simple library to load images of various formats as SDL surfaces +# +# Requires +# -------- +# SDL.pas in your search path. +# +# Programming Notes +# ----------------- +# See the Aliens Demo on how to make use of this libaray +# +# Revision History +# ---------------- +# April 02 2001 - MT : Initial Translation +# +# May 08 2001 - DL : Added ExternalSym derectives and copyright header +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 08 2003 - MK : Aka Mr Kroket - Added Better FPC support +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# $Log: sdl_image.pas,v $ +# Revision 1.14 2007/05/29 21:31:13 savage +# Changes as suggested by Almindor for 64bit compatibility. +# +# Revision 1.13 2007/05/20 20:30:54 savage +# Initial Changes to Handle 64 Bits +# +# Revision 1.12 2006/12/02 00:14:40 savage +# Updated to latest version +# +# Revision 1.11 2005/04/10 18:22:59 savage +# Changes as suggested by Michalis, thanks. +# +# Revision 1.10 2005/04/10 11:48:33 savage +# Changes as suggested by Michalis, thanks. +# +# Revision 1.9 2005/01/05 01:47:07 savage +# Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively. +# +# Revision 1.8 2005/01/04 23:14:44 savage +# Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively. +# +# Revision 1.7 2005/01/01 02:03:12 savage +# Updated to v1.2.4 +# +# Revision 1.6 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.5 2004/05/10 14:10:04 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.4 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.3 2004/04/01 20:53:23 savage +# Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.2 2004/03/30 20:23:28 savage +# Tidied up use of UNIX compiler directive. +# +# Revision 1.1 2004/02/14 23:35:42 savage +# version 1 of sdl_image, sdl_mixer and smpeg. +# +# +# +#****************************************************************************** + +import + sdl + +when defined(windows): + const SDL_ImageLibName = "SDL_Image.dll" +elif defined(macosx): + const SDL_ImageLibName = "libSDL_image-1.2.0.dylib" +else: + const SDL_ImageLibName = "libSDL_image.so" + +const + SDL_IMAGE_MAJOR_VERSION* = 1'i8 + SDL_IMAGE_MINOR_VERSION* = 2'i8 + SDL_IMAGE_PATCHLEVEL* = 5'i8 + +# This macro can be used to fill a version structure with the compile-time +# version of the SDL_image library. + +proc SDL_IMAGE_VERSION*(X: var TSDL_Version) + # This function gets the version of the dynamically linked SDL_image library. + # it should NOT be used to fill a version structure, instead you should + # use the SDL_IMAGE_VERSION() macro. + # +proc IMG_Linked_Version*(): PSDL_version{.importc, dynlib: SDL_ImageLibName.} + # Load an image from an SDL data source. + # The 'type' may be one of: "BMP", "GIF", "PNG", etc. + # + # If the image format supports a transparent pixel, SDL will set the + # colorkey for the surface. You can enable RLE acceleration on the + # surface afterwards by calling: + # SDL_SetColorKey(image, SDL_RLEACCEL, image.format.colorkey); + # +proc IMG_LoadTyped_RW*(src: PSDL_RWops, freesrc: int, theType: cstring): PSDL_Surface{. + cdecl, importc, dynlib: SDL_ImageLibName.} + # Convenience functions +proc IMG_Load*(theFile: cstring): PSDL_Surface{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_Load_RW*(src: PSDL_RWops, freesrc: int): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} + # Invert the alpha of a surface for use with OpenGL + # This function is now a no-op, and only provided for backwards compatibility. +proc IMG_InvertAlpha*(theOn: int): int{.cdecl, importc, dynlib: SDL_ImageLibName.} + # Functions to detect a file type, given a seekable source +proc IMG_isBMP*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isGIF*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isJPG*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isLBM*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isPCX*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isPNG*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isPNM*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isTIF*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isXCF*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isXPM*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} +proc IMG_isXV*(src: PSDL_RWops): int{.cdecl, importc, dynlib: SDL_ImageLibName.} + # Individual loading functions +proc IMG_LoadBMP_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadGIF_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadJPG_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadLBM_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadPCX_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadPNM_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadPNG_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadTGA_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadTIF_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadXCF_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadXPM_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_LoadXV_RW*(src: PSDL_RWops): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} +proc IMG_ReadXPMFromArray*(xpm: cstringArray): PSDL_Surface{.cdecl, + importc, dynlib: SDL_ImageLibName.} + # Error Macros + # We'll use SDL for reporting errors +proc IMG_SetError*(fmt: cstring) +proc IMG_GetError*(): cstring +# implementation + +proc SDL_IMAGE_VERSION(X: var TSDL_Version) = + X.major = SDL_IMAGE_MAJOR_VERSION + X.minor = SDL_IMAGE_MINOR_VERSION + X.patch = SDL_IMAGE_PATCHLEVEL + +proc IMG_SetError(fmt: cstring) = + SDL_SetError(fmt) + +proc IMG_GetError(): cstring = + result = SDL_GetError() diff --git a/lib/wrappers/sdl/sdl_mixer.nim b/lib/wrappers/sdl/sdl_mixer.nim new file mode 100644 index 000000000..f840dc52a --- /dev/null +++ b/lib/wrappers/sdl/sdl_mixer.nim @@ -0,0 +1,737 @@ + +#****************************************************************************** +# +# $Id: sdl_mixer.pas,v 1.18 2007/05/29 21:31:44 savage Exp $ +# +# +# +# Borland Delphi SDL_Mixer - Simple DirectMedia Layer Mixer Library +# Conversion of the Simple DirectMedia Layer Headers +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : SDL_mixer.h +# music_cmd.h +# wavestream.h +# timidity.h +# playmidi.h +# music_ogg.h +# mikmod.h +# +# The initial developer of this Pascal code was : +# Dominqiue Louis <Dominique@SavageSoftware.com.au> +# +# Portions created by Dominqiue Louis are +# Copyright (C) 2000 - 2001 Dominqiue Louis. +# +# +# Contributor(s) +# -------------- +# Matthias Thoma <ma.thoma@gmx.de> +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# +# +# +# +# +# +# +# Requires +# -------- +# SDL.pas & SMPEG.pas somewhere within your search path. +# +# Programming Notes +# ----------------- +# See the Aliens Demo to see how this library is used +# +# Revision History +# ---------------- +# April 02 2001 - DL : Initial Translation +# +# February 02 2002 - DL : Update to version 1.2.1 +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# $Log: sdl_mixer.pas,v $ +# Revision 1.18 2007/05/29 21:31:44 savage +# Changes as suggested by Almindor for 64bit compatibility. +# +# Revision 1.17 2007/05/20 20:31:17 savage +# Initial Changes to Handle 64 Bits +# +# Revision 1.16 2006/12/02 00:16:17 savage +# Updated to latest version +# +# Revision 1.15 2005/04/10 11:48:33 savage +# Changes as suggested by Michalis, thanks. +# +# Revision 1.14 2005/02/24 20:20:07 savage +# Changed definition of MusicType and added GetMusicType function +# +# Revision 1.13 2005/01/05 01:47:09 savage +# Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively. +# +# Revision 1.12 2005/01/04 23:14:56 savage +# Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively. +# +# Revision 1.11 2005/01/01 02:05:19 savage +# Updated to v1.2.6 +# +# Revision 1.10 2004/09/12 21:45:17 savage +# Robert Reed spotted that Mix_SetMusicPosition was missing from the conversion, so this has now been added. +# +# Revision 1.9 2004/08/27 21:48:24 savage +# IFDEFed out Smpeg support on MacOS X +# +# Revision 1.8 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.7 2004/05/10 14:10:04 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.6 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.5 2004/04/01 20:53:23 savage +# Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.4 2004/03/31 22:20:02 savage +# Windows unit not used in this file, so it was removed to keep the code tidy. +# +# Revision 1.3 2004/03/31 10:05:08 savage +# Better defines for Endianess under FreePascal and Borland compilers. +# +# Revision 1.2 2004/03/30 20:23:28 savage +# Tidied up use of UNIX compiler directive. +# +# Revision 1.1 2004/02/14 23:35:42 savage +# version 1 of sdl_image, sdl_mixer and smpeg. +# +# +# +#****************************************************************************** + +import + sdl, smpeg + +when defined(windows): + const SDL_MixerLibName = "SDL_mixer.dll" +elif defined(macosx): + const SDL_MixerLibName = "libSDL_mixer-1.2.0.dylib" +else: + const SDL_MixerLibName = "libSDL_mixer.so" + +const + SDL_MIXER_MAJOR_VERSION* = 1'i8 + SDL_MIXER_MINOR_VERSION* = 2'i8 + SDL_MIXER_PATCHLEVEL* = 7'i8 # Backwards compatibility + MIX_MAJOR_VERSION* = SDL_MIXER_MAJOR_VERSION + MIX_MINOR_VERSION* = SDL_MIXER_MINOR_VERSION + MIX_PATCHLEVEL* = SDL_MIXER_PATCHLEVEL # SDL_Mixer.h constants + # The default mixer has 8 simultaneous mixing channels + MIX_CHANNELS* = 8 # Good default values for a PC soundcard + MIX_DEFAULT_FREQUENCY* = 22050 + +when defined(IA32): + const + MIX_DEFAULT_FORMAT* = AUDIO_S16LSB +else: + const + MIX_DEFAULT_FORMAT* = AUDIO_S16MSB +const + MIX_DEFAULT_CHANNELS* = 2 + MIX_MAX_VOLUME* = 128 # Volume of a chunk + PATH_MAX* = 255 # mikmod.h constants + #* + # * Library version + # * + LIBMIKMOD_VERSION_MAJOR* = 3 + LIBMIKMOD_VERSION_MINOR* = 1 + LIBMIKMOD_REVISION* = 8 + LIBMIKMOD_VERSION* = ((LIBMIKMOD_VERSION_MAJOR shl 16) or + (LIBMIKMOD_VERSION_MINOR shl 8) or (LIBMIKMOD_REVISION)) + +type #music_cmd.h types + PMusicCMD* = ptr TMusicCMD + TMusicCMD*{.final.} = object #wavestream.h types + filename*: array[0..PATH_MAX - 1, char] + cmd*: array[0..PATH_MAX - 1, char] + pid*: TSYS_ThreadHandle + + PWAVStream* = ptr TWAVStream + TWAVStream*{.final.} = object #playmidi.h types + wavefp*: Pointer + start*: int32 + stop*: int32 + cvt*: TSDL_AudioCVT + + PMidiEvent* = ptr TMidiEvent + TMidiEvent*{.final.} = object + time*: int32 + channel*: uint8 + type_*: uint8 + a*: uint8 + b*: uint8 + + PMidiSong* = ptr TMidiSong + TMidiSong*{.final.} = object #music_ogg.h types + samples*: int32 + events*: PMidiEvent + + POGG_Music* = ptr TOGG_Music + TOGG_Music*{.final.} = object # mikmod.h types + #* + # * Error codes + # * + playing*: int + volume*: int #vf: OggVorbis_File; + section*: int + cvt*: TSDL_AudioCVT + len_available*: int + snd_available*: PUint8 + + TErrorEnum* = enum + MMERR_OPENING_FILE, MMERR_OUT_OF_MEMORY, MMERR_DYNAMIC_LINKING, + MMERR_SAMPLE_TOO_BIG, MMERR_OUT_OF_HANDLES, MMERR_UNKNOWN_WAVE_TYPE, + MMERR_LOADING_PATTERN, MMERR_LOADING_TRACK, MMERR_LOADING_HEADER, + MMERR_LOADING_SAMPLEINFO, MMERR_NOT_A_MODULE, MMERR_NOT_A_STREAM, + MMERR_MED_SYNTHSAMPLES, MMERR_ITPACK_INVALID_DATA, MMERR_DETECTING_DEVICE, + MMERR_INVALID_DEVICE, MMERR_INITIALIZING_MIXER, MMERR_OPENING_AUDIO, + MMERR_8BIT_ONLY, MMERR_16BIT_ONLY, MMERR_STEREO_ONLY, MMERR_ULAW, + MMERR_NON_BLOCK, MMERR_AF_AUDIO_PORT, MMERR_AIX_CONFIG_INIT, + MMERR_AIX_CONFIG_CONTROL, MMERR_AIX_CONFIG_START, MMERR_GUS_SETTINGS, + MMERR_GUS_RESET, MMERR_GUS_TIMER, MMERR_HP_SETSAMPLESIZE, MMERR_HP_SETSPEED, + MMERR_HP_CHANNELS, MMERR_HP_AUDIO_OUTPUT, MMERR_HP_AUDIO_DESC, + MMERR_HP_BUFFERSIZE, MMERR_OSS_SETFRAGMENT, MMERR_OSS_SETSAMPLESIZE, + MMERR_OSS_SETSTEREO, MMERR_OSS_SETSPEED, MMERR_SGI_SPEED, MMERR_SGI_16BIT, + MMERR_SGI_8BIT, MMERR_SGI_STEREO, MMERR_SGI_MONO, MMERR_SUN_INIT, + MMERR_OS2_MIXSETUP, MMERR_OS2_SEMAPHORE, MMERR_OS2_TIMER, MMERR_OS2_THREAD, + MMERR_DS_PRIORITY, MMERR_DS_BUFFER, MMERR_DS_FORMAT, MMERR_DS_NOTIFY, + MMERR_DS_EVENT, MMERR_DS_THREAD, MMERR_DS_UPDATE, MMERR_WINMM_HANDLE, + MMERR_WINMM_ALLOCATED, MMERR_WINMM_DEVICEID, MMERR_WINMM_FORMAT, + MMERR_WINMM_UNKNOWN, MMERR_MAC_SPEED, MMERR_MAC_START, MMERR_MAX + PMODULE* = ptr TMODULE + TMODULE*{.final.} = object + PUNIMOD* = ptr TUNIMOD + TUNIMOD* = TMODULE #SDL_mixer.h types + # The internal format for an audio chunk + PMix_Chunk* = ptr TMix_Chunk + TMix_Chunk*{.final.} = object + allocated*: int + abuf*: PUint8 + alen*: Uint32 + volume*: Uint8 # Per-sample volume, 0-128 + + Mix_Chunk* = TMix_Chunk # The different fading types supported + TMix_Fading* = enum + MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN + Mix_Fading* = TMix_Fading + TMix_MusicType* = enum + MUS_NONE, MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG, MUS_MP3 + Mix_MusicType* = TMix_MusicType # + # TMusicUnion = record + # case XXX: Byte of + # 0 : ( cmd : PMusicCMD ); + # 1 : ( wave : PWAVStream ); + # 2 : ( module : PUNIMOD ); + # 3 : ( midi : TMidiSong ); + # 4 : ( ogg : POGG_music ); + # {$IFNDEF DARWIN} + # 5 : ( mp3 : PSMPEG ); + # {$ENDIF} + # end; + PMix_Music* = ptr TMix_Music + TMix_Music*{.final.} = object # The internal format for a music chunk interpreted via mikmod + type_*: TMix_MusicType # other fields are not aviable + # data : TMusicUnion; + # fading : TMix_Fading; + # fade_volume : integer; + # fade_step : integer; + # fade_steps : integer; + # error : integer; + + TMixFunction* = proc (udata: Pointer, stream: PUint8, length: int): Pointer{. + cdecl.} # This macro can be used to fill a version structure with the compile-time + # version of the SDL_mixer library. + +proc SDL_MIXER_VERSION*(X: var TSDL_Version) + # This function gets the version of the dynamically linked SDL_mixer library. + # It should NOT be used to fill a version structure, instead you should use the + # SDL_MIXER_VERSION() macro. +proc Mix_Linked_Version*(): PSDL_version{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Open the mixer with a certain audio format +proc Mix_OpenAudio*(frequency: int, format: Uint16, channels: int, + chunksize: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Dynamically change the number of channels managed by the mixer. + # If decreasing the number of channels, the upper channels are + # stopped. + # This function returns the new number of allocated channels. + # +proc Mix_AllocateChannels*(numchannels: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Find out what the actual audio device parameters are. + # This function returns 1 if the audio has been opened, 0 otherwise. + # +proc Mix_QuerySpec*(frequency: var int, format: var Uint16, channels: var int): int{. + cdecl, importc, dynlib: SDL_MixerLibName.} + # Load a wave file or a music (.mod .s3m .it .xm) file +proc Mix_LoadWAV_RW*(src: PSDL_RWops, freesrc: int): PMix_Chunk{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_LoadWAV*(filename: cstring): PMix_Chunk +proc Mix_LoadMUS*(filename: cstring): PMix_Music{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Load a wave file of the mixer format from a memory buffer +proc Mix_QuickLoad_WAV*(mem: PUint8): PMix_Chunk{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Free an audio chunk previously loaded +proc Mix_FreeChunk*(chunk: PMix_Chunk){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FreeMusic*(music: PMix_Music){.cdecl, importc, dynlib: SDL_MixerLibName.} + # Find out the music format of a mixer music, or the currently playing + # music, if 'music' is NULL. +proc Mix_GetMusicType*(music: PMix_Music): TMix_MusicType{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Set a function that is called after all mixing is performed. + # This can be used to provide real-time visual display of the audio stream + # or add a custom mixer filter for the stream data. + # +proc Mix_SetPostMix*(mix_func: TMixFunction, arg: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Add your own music player or additional mixer function. + # If 'mix_func' is NULL, the default music player is re-enabled. + # +proc Mix_HookMusic*(mix_func: TMixFunction, arg: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Add your own callback when the music has finished playing. + # +proc Mix_HookMusicFinished*(music_finished: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Get a pointer to the user data for the current music hook +proc Mix_GetMusicHookData*(): Pointer{.cdecl, importc, dynlib: SDL_MixerLibName.} + #* Add your own callback when a channel has finished playing. NULL + # * to disable callback.* +type + TChannel_finished* = proc (channel: int){.cdecl.} + +proc Mix_ChannelFinished*(channel_finished: TChannel_finished){.cdecl, + importc, dynlib: SDL_MixerLibName.} +const + MIX_CHANNEL_POST* = - 2 + # This is the format of a special effect callback: + # myeffect(int chan, void *stream, int len, void *udata); + # + # (chan) is the channel number that your effect is affecting. (stream) is + # the buffer of data to work upon. (len) is the size of (stream), and + # (udata) is a user-defined bit of data, which you pass as the last arg of + # Mix_RegisterEffect(), and is passed back unmolested to your callback. + # Your effect changes the contents of (stream) based on whatever parameters + # are significant, or just leaves it be, if you prefer. You can do whatever + # you like to the buffer, though, and it will continue in its changed state + # down the mixing pipeline, through any other effect functions, then finally + # to be mixed with the rest of the channels and music for the final output + # stream. + # + +type + TMix_EffectFunc* = proc (chan: int, stream: Pointer, length: int, + udata: Pointer): Pointer{.cdecl.} + # * This is a callback that signifies that a channel has finished all its + # * loops and has completed playback. This gets called if the buffer + # * plays out normally, or if you call Mix_HaltChannel(), implicitly stop + # * a channel via Mix_AllocateChannels(), or unregister a callback while + # * it's still playing. + TMix_EffectDone* = proc (chan: int, udata: Pointer): Pointer{.cdecl.} + #* Register a special effect function. At mixing time, the channel data is + # * copied into a buffer and passed through each registered effect function. + # * After it passes through all the functions, it is mixed into the final + # * output stream. The copy to buffer is performed once, then each effect + # * function performs on the output of the previous effect. Understand that + # * this extra copy to a buffer is not performed if there are no effects + # * registered for a given chunk, which saves CPU cycles, and any given + # * effect will be extra cycles, too, so it is crucial that your code run + # * fast. Also note that the data that your function is given is in the + # * format of the sound device, and not the format you gave to Mix_OpenAudio(), + # * although they may in reality be the same. This is an unfortunate but + # * necessary speed concern. Use Mix_QuerySpec() to determine if you can + # * handle the data before you register your effect, and take appropriate + # * actions. + # * You may also specify a callback (Mix_EffectDone_t) that is called when + # * the channel finishes playing. This gives you a more fine-grained control + # * than Mix_ChannelFinished(), in case you need to free effect-specific + # * resources, etc. If you don't need this, you can specify NULL. + # * You may set the callbacks before or after calling Mix_PlayChannel(). + # * Things like Mix_SetPanning() are just internal special effect functions, + # * so if you are using that, you've already incurred the overhead of a copy + # * to a separate buffer, and that these effects will be in the queue with + # * any functions you've registered. The list of registered effects for a + # * channel is reset when a chunk finishes playing, so you need to explicitly + # * set them with each call to Mix_PlayChannel*(). + # * You may also register a special effect function that is to be run after + # * final mixing occurs. The rules for these callbacks are identical to those + # * in Mix_RegisterEffect, but they are run after all the channels and the + # * music have been mixed into a single stream, whereas channel-specific + # * effects run on a given channel before any other mixing occurs. These + # * global effect callbacks are call "posteffects". Posteffects only have + # * their Mix_EffectDone_t function called when they are unregistered (since + # * the main output stream is never "done" in the same sense as a channel). + # * You must unregister them manually when you've had enough. Your callback + # * will be told that the channel being mixed is (MIX_CHANNEL_POST) if the + # * processing is considered a posteffect. + # * + # * After all these effects have finished processing, the callback registered + # * through Mix_SetPostMix() runs, and then the stream goes to the audio + # * device. + # * + # * returns zero if error (no such channel), nonzero if added. + # * Error messages can be retrieved from Mix_GetError(). + # * + +proc Mix_RegisterEffect*(chan: int, f: TMix_EffectFunc, d: TMix_EffectDone, + arg: Pointer): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + #* You may not need to call this explicitly, unless you need to stop an + # * effect from processing in the middle of a chunk's playback. + # * Posteffects are never implicitly unregistered as they are for channels, + # * but they may be explicitly unregistered through this function by + # * specifying MIX_CHANNEL_POST for a channel. + # * returns zero if error (no such channel or effect), nonzero if removed. + # * Error messages can be retrieved from Mix_GetError(). + # * +proc Mix_UnregisterEffect*(channel: int, f: TMix_EffectFunc): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + #* You may not need to call this explicitly, unless you need to stop all + # * effects from processing in the middle of a chunk's playback. Note that + # * this will also shut off some internal effect processing, since + # * Mix_SetPanning( ) and others may use this API under the hood.This is + # * called internally when a channel completes playback. + # * Posteffects are never implicitly unregistered as they are for channels, + # * but they may be explicitly unregistered through this function by + # * specifying MIX_CHANNEL_POST for a channel. + # * returns zero if error( no such channel ), nonzero if all effects removed. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_UnregisterAllEffects*(channel: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +const + MIX_EFFECTSMAXSPEED* = "MIX_EFFECTSMAXSPEED" + # * These are the internally - defined mixing effects.They use the same API that + # * effects defined in the application use, but are provided here as a + # * convenience.Some effects can reduce their quality or use more memory in + # * the name of speed; to enable this, make sure the environment variable + # * MIX_EFFECTSMAXSPEED( see above ) is defined before you call + # * Mix_OpenAudio( ). + # * + #* set the panning of a channel.The left and right channels are specified + # * as integers between 0 and 255, quietest to loudest, respectively. + # * + # * Technically, this is just individual volume control for a sample with + # * two( stereo )channels, so it can be used for more than just panning. + # * if you want real panning, call it like this : + # * + # * Mix_SetPanning( channel, left, 255 - left ); + # * + # * ...which isn't so hard. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the panning will be done to the final mixed stream before passing it on + # * to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally, and returns without + # * registering the effect function if the audio device is not configured + # * for stereo output.Setting both( left ) and ( right ) to 255 causes this + # * effect to be unregistered, since that is the data's normal state. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if panning effect enabled.Note that an audio device in mono + # * mode is a no - op, but this call will return successful in that case . + # * Error messages can be retrieved from Mix_GetError( ). + # * + +proc Mix_SetPanning*(channel: int, left: Uint8, right: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # * set the position ofa channel.( angle ) is an integer from 0 to 360, that + # * specifies the location of the sound in relation to the listener.( angle ) + # * will be reduced as neccesary( 540 becomes 180 degrees, -100 becomes 260 ). + # * Angle 0 is due north, and rotates clockwise as the value increases. + # * for efficiency, the precision of this effect may be limited( angles 1 + # * through 7 might all produce the same effect, 8 through 15 are equal, etc ). + # * ( distance ) is an integer between 0 and 255 that specifies the space + # * between the sound and the listener.The larger the number, the further + # * away the sound is .Using 255 does not guarantee that the channel will be + # * culled from the mixing process or be completely silent.For efficiency, + # * the precision of this effect may be limited( distance 0 through 5 might + # * all produce the same effect, 6 through 10 are equal, etc ).Setting( angle ) + # * and ( distance ) to 0 unregisters this effect, since the data would be + # * unchanged. + # * + # * if you need more precise positional audio, consider using OpenAL for + # * spatialized effects instead of SDL_mixer.This is only meant to be a + # * basic effect for simple "3D" games. + # * + # * if the audio device is configured for mono output, then you won't get + # * any effectiveness from the angle; however, distance attenuation on the + # * channel will still occur.While this effect will function with stereo + # * voices, it makes more sense to use voices with only one channel of sound, + # * so when they are mixed through this effect, the positioning will sound + # * correct.You can convert them to mono through SDL before giving them to + # * the mixer in the first place if you like. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the positioning will be done to the final mixed stream before passing it + # * on to the audio device. + # * + # * This is a convenience wrapper over Mix_SetDistance( ) and Mix_SetPanning( ). + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if position effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetPosition*(channel: int, angle: Sint16, distance: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + #* set the "distance" of a channel.( distance ) is an integer from 0 to 255 + # * that specifies the location of the sound in relation to the listener. + # * Distance 0 is overlapping the listener, and 255 is as far away as possible + # * A distance of 255 does not guarantee silence; in such a case , you might + # * want to try changing the chunk's volume, or just cull the sample from the + # * mixing process with Mix_HaltChannel( ). + # * for efficiency, the precision of this effect may be limited( distances 1 + # * through 7 might all produce the same effect, 8 through 15 are equal, etc ). + # * ( distance ) is an integer between 0 and 255 that specifies the space + # * between the sound and the listener.The larger the number, the further + # * away the sound is . + # * Setting( distance ) to 0 unregisters this effect, since the data would be + # * unchanged. + # * if you need more precise positional audio, consider using OpenAL for + # * spatialized effects instead of SDL_mixer.This is only meant to be a + # * basic effect for simple "3D" games. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the distance attenuation will be done to the final mixed stream before + # * passing it on to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if position effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetDistance*(channel: int, distance: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # * + # * !!! FIXME : Haven't implemented, since the effect goes past the + # * end of the sound buffer.Will have to think about this. + # * - -ryan. + # * / + # { if 0 + # { * Causes an echo effect to be mixed into a sound.( echo ) is the amount + # * of echo to mix.0 is no echo, 255 is infinite( and probably not + # * what you want ). + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the reverbing will be done to the final mixed stream before passing it on + # * to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally.If you specify an echo + # * of zero, the effect is unregistered, as the data is already in that state. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if reversing effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * + # extern no_parse_DECLSPEC int Mix_SetReverb( int channel, Uint8 echo ); + # #E ndif + # * Causes a channel to reverse its stereo.This is handy if the user has his + # * speakers hooked up backwards, or you would like to have a minor bit of + # * psychedelia in your sound code. : )Calling this function with ( flip ) + # * set to non - zero reverses the chunks's usual channels. If (flip) is zero, + # * the effect is unregistered. + # * + # * This uses the Mix_RegisterEffect( )API internally, and thus is probably + # * more CPU intensive than having the user just plug in his speakers + # * correctly.Mix_SetReverseStereo( )returns without registering the effect + # * function if the audio device is not configured for stereo output. + # * + # * if you specify MIX_CHANNEL_POST for ( channel ), then this the effect is used + # * on the final mixed stream before sending it on to the audio device( a + # * posteffect ). + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if reversing effect is enabled.Note that an audio device in mono + # * mode is a no - op, but this call will return successful in that case . + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetReverseStereo*(channel: int, flip: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # end of effects API. - -ryan. * + # Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate + # them dynamically to the next sample if requested with a -1 value below. + # Returns the number of reserved channels. + # +proc Mix_ReserveChannels*(num: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Channel grouping functions + # Attach a tag to a channel. A tag can be assigned to several mixer + # channels, to form groups of channels. + # If 'tag' is -1, the tag is removed (actually -1 is the tag used to + # represent the group of all the channels). + # Returns true if everything was OK. + # +proc Mix_GroupChannel*(which: int, tag: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Assign several consecutive channels to a group +proc Mix_GroupChannels*(`from`: int, `to`: int, tag: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Finds the first available channel in a group of channels +proc Mix_GroupAvailable*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Returns the number of channels in a group. This is also a subtle + # way to get the total number of channels when 'tag' is -1 + # +proc Mix_GroupCount*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Finds the "oldest" sample playing in a group of channels +proc Mix_GroupOldest*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Finds the "most recent" (i.e. last) sample playing in a group of channels +proc Mix_GroupNewer*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # The same as above, but the sound is played at most 'ticks' milliseconds +proc Mix_PlayChannelTimed*(channel: int, chunk: PMix_Chunk, loops: int, + ticks: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Play an audio chunk on a specific channel. + # If the specified channel is -1, play on the first free channel. + # If 'loops' is greater than zero, loop the sound that many times. + # If 'loops' is -1, loop inifinitely (~65000 times). + # Returns which channel was used to play the sound. + # +proc Mix_PlayChannel*(channel: int, chunk: PMix_Chunk, loops: int): int +proc Mix_PlayMusic*(music: PMix_Music, loops: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Fade in music or a channel over "ms" milliseconds, same semantics as the "Play" functions +proc Mix_FadeInMusic*(music: PMix_Music, loops: int, ms: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeInChannelTimed*(channel: int, chunk: PMix_Chunk, loops: int, + ms: int, ticks: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeInChannel*(channel: int, chunk: PMix_Chunk, loops: int, ms: int): int + # Set the volume in the range of 0-128 of a specific channel or chunk. + # If the specified channel is -1, set volume for all channels. + # Returns the original volume. + # If the specified volume is -1, just return the current volume. + # +proc Mix_Volume*(channel: int, volume: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_VolumeChunk*(chunk: PMix_Chunk, volume: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_VolumeMusic*(volume: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Halt playing of a particular channel +proc Mix_HaltChannel*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_HaltGroup*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_HaltMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Change the expiration delay for a particular channel. + # The sample will stop playing after the 'ticks' milliseconds have elapsed, + # or remove the expiration if 'ticks' is -1 + # +proc Mix_ExpireChannel*(channel: int, ticks: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Halt a channel, fading it out progressively till it's silent + # The ms parameter indicates the number of milliseconds the fading + # will take. + # +proc Mix_FadeOutChannel*(which: int, ms: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeOutGroup*(tag: int, ms: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeOutMusic*(ms: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Query the fading status of a channel +proc Mix_FadingMusic*(): TMix_Fading{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FadingChannel*(which: int): TMix_Fading{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Pause/Resume a particular channel +proc Mix_Pause*(channel: int){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_Resume*(channel: int){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_Paused*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Pause/Resume the music stream +proc Mix_PauseMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_ResumeMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_RewindMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_PausedMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Set the current position in the music stream. + # This returns 0 if successful, or -1 if it failed or isn't implemented. + # This function is only implemented for MOD music formats (set pattern + # order number) and for OGG music (set position in seconds), at the + # moment. + # +proc Mix_SetMusicPosition*(position: float64): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Check the status of a specific channel. + # If the specified channel is -1, check all channels. + # +proc Mix_Playing*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_PlayingMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Stop music and set external music playback command +proc Mix_SetMusicCMD*(command: cstring): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Synchro value is set by MikMod from modules while playing +proc Mix_SetSynchroValue*(value: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_GetSynchroValue*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # + # Get the Mix_Chunk currently associated with a mixer channel + # Returns nil if it's an invalid channel, or there's no chunk associated. + # +proc Mix_GetChunk*(channel: int): PMix_Chunk{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Close the mixer, halting all playing audio +proc Mix_CloseAudio*(){.cdecl, importc, dynlib: SDL_MixerLibName.} + # We'll use SDL for reporting errors +proc Mix_SetError*(fmt: cstring) +proc Mix_GetError*(): cstring +# implementation + +proc SDL_MIXER_VERSION(X: var TSDL_version) = + X.major = SDL_MIXER_MAJOR_VERSION + X.minor = SDL_MIXER_MINOR_VERSION + X.patch = SDL_MIXER_PATCHLEVEL + +proc Mix_LoadWAV(filename: cstring): PMix_Chunk = + result = Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1) + +proc Mix_PlayChannel(channel: int, chunk: PMix_Chunk, loops: int): int = + result = Mix_PlayChannelTimed(channel, chunk, loops, - 1) + +proc Mix_FadeInChannel(channel: int, chunk: PMix_Chunk, loops: int, ms: int): int = + result = Mix_FadeInChannelTimed(channel, chunk, loops, ms, - 1) + +proc Mix_SetError(fmt: cstring) = + SDL_SetError(fmt) + +proc Mix_GetError(): cstring = + result = SDL_GetError() diff --git a/lib/wrappers/sdl/sdl_mixer_nosmpeg.nim b/lib/wrappers/sdl/sdl_mixer_nosmpeg.nim new file mode 100644 index 000000000..6282b5edc --- /dev/null +++ b/lib/wrappers/sdl/sdl_mixer_nosmpeg.nim @@ -0,0 +1,572 @@ + +#****************************************************************************** +# Copy of SDL_Mixer without smpeg dependency and mp3 support +#****************************************************************************** + +import + sdl + +when defined(windows): + const SDL_MixerLibName = "SDL_mixer.dll" +elif defined(macosx): + const SDL_MixerLibName = "libSDL_mixer-1.2.0.dylib" +else: + const SDL_MixerLibName = "libSDL_mixer.so" + +const + SDL_MIXER_MAJOR_VERSION* = 1'i8 + SDL_MIXER_MINOR_VERSION* = 2'i8 + SDL_MIXER_PATCHLEVEL* = 7'i8 # Backwards compatibility + MIX_MAJOR_VERSION* = SDL_MIXER_MAJOR_VERSION + MIX_MINOR_VERSION* = SDL_MIXER_MINOR_VERSION + MIX_PATCHLEVEL* = SDL_MIXER_PATCHLEVEL # SDL_Mixer.h constants + # The default mixer has 8 simultaneous mixing channels + MIX_CHANNELS* = 8 # Good default values for a PC soundcard + MIX_DEFAULT_FREQUENCY* = 22050 + +when defined(IA32): + const + MIX_DEFAULT_FORMAT* = AUDIO_S16LSB +else: + const + MIX_DEFAULT_FORMAT* = AUDIO_S16MSB +const + MIX_DEFAULT_CHANNELS* = 2 + MIX_MAX_VOLUME* = 128 # Volume of a chunk + PATH_MAX* = 255 # mikmod.h constants + #* + # * Library version + # * + LIBMIKMOD_VERSION_MAJOR* = 3 + LIBMIKMOD_VERSION_MINOR* = 1 + LIBMIKMOD_REVISION* = 8 + LIBMIKMOD_VERSION* = ((LIBMIKMOD_VERSION_MAJOR shl 16) or + (LIBMIKMOD_VERSION_MINOR shl 8) or (LIBMIKMOD_REVISION)) + +type #music_cmd.h types + PMusicCMD* = ptr TMusicCMD + TMusicCMD*{.final.} = object #wavestream.h types + filename*: array[0..PATH_MAX - 1, char] + cmd*: array[0..PATH_MAX - 1, char] + pid*: TSYS_ThreadHandle + + PWAVStream* = ptr TWAVStream + TWAVStream*{.final.} = object #playmidi.h types + wavefp*: Pointer + start*: int32 + stop*: int32 + cvt*: TSDL_AudioCVT + + PMidiEvent* = ptr TMidiEvent + TMidiEvent*{.final.} = object + time*: int32 + channel*: uint8 + type_*: uint8 + a*: uint8 + b*: uint8 + + PMidiSong* = ptr TMidiSong + TMidiSong*{.final.} = object #music_ogg.h types + samples*: int32 + events*: PMidiEvent + + POGG_Music* = ptr TOGG_Music + TOGG_Music*{.final.} = object # mikmod.h types + #* + # * Error codes + # * + playing*: int + volume*: int #vf: OggVorbis_File; + section*: int + cvt*: TSDL_AudioCVT + len_available*: int + snd_available*: PUint8 + + TErrorEnum* = enum + MMERR_OPENING_FILE, MMERR_OUT_OF_MEMORY, MMERR_DYNAMIC_LINKING, + MMERR_SAMPLE_TOO_BIG, MMERR_OUT_OF_HANDLES, MMERR_UNKNOWN_WAVE_TYPE, + MMERR_LOADING_PATTERN, MMERR_LOADING_TRACK, MMERR_LOADING_HEADER, + MMERR_LOADING_SAMPLEINFO, MMERR_NOT_A_MODULE, MMERR_NOT_A_STREAM, + MMERR_MED_SYNTHSAMPLES, MMERR_ITPACK_INVALID_DATA, MMERR_DETECTING_DEVICE, + MMERR_INVALID_DEVICE, MMERR_INITIALIZING_MIXER, MMERR_OPENING_AUDIO, + MMERR_8BIT_ONLY, MMERR_16BIT_ONLY, MMERR_STEREO_ONLY, MMERR_ULAW, + MMERR_NON_BLOCK, MMERR_AF_AUDIO_PORT, MMERR_AIX_CONFIG_INIT, + MMERR_AIX_CONFIG_CONTROL, MMERR_AIX_CONFIG_START, MMERR_GUS_SETTINGS, + MMERR_GUS_RESET, MMERR_GUS_TIMER, MMERR_HP_SETSAMPLESIZE, MMERR_HP_SETSPEED, + MMERR_HP_CHANNELS, MMERR_HP_AUDIO_OUTPUT, MMERR_HP_AUDIO_DESC, + MMERR_HP_BUFFERSIZE, MMERR_OSS_SETFRAGMENT, MMERR_OSS_SETSAMPLESIZE, + MMERR_OSS_SETSTEREO, MMERR_OSS_SETSPEED, MMERR_SGI_SPEED, MMERR_SGI_16BIT, + MMERR_SGI_8BIT, MMERR_SGI_STEREO, MMERR_SGI_MONO, MMERR_SUN_INIT, + MMERR_OS2_MIXSETUP, MMERR_OS2_SEMAPHORE, MMERR_OS2_TIMER, MMERR_OS2_THREAD, + MMERR_DS_PRIORITY, MMERR_DS_BUFFER, MMERR_DS_FORMAT, MMERR_DS_NOTIFY, + MMERR_DS_EVENT, MMERR_DS_THREAD, MMERR_DS_UPDATE, MMERR_WINMM_HANDLE, + MMERR_WINMM_ALLOCATED, MMERR_WINMM_DEVICEID, MMERR_WINMM_FORMAT, + MMERR_WINMM_UNKNOWN, MMERR_MAC_SPEED, MMERR_MAC_START, MMERR_MAX + PMODULE* = ptr TMODULE + TMODULE*{.final.} = object + PUNIMOD* = ptr TUNIMOD + TUNIMOD* = TMODULE #SDL_mixer.h types + # The internal format for an audio chunk + PMix_Chunk* = ptr TMix_Chunk + TMix_Chunk*{.final.} = object + allocated*: int + abuf*: PUint8 + alen*: Uint32 + volume*: Uint8 # Per-sample volume, 0-128 + + Mix_Chunk* = TMix_Chunk # The different fading types supported + TMix_Fading* = enum + MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN + Mix_Fading* = TMix_Fading + TMix_MusicType* = enum + MUS_NONE, MUS_CMD, MUS_WAV, MUS_MOD, MUS_MID, MUS_OGG + PMix_Music* = ptr TMix_Music + TMix_Music*{.final.} = object + type_*: TMix_MusicType + + TMixFunction* = proc (udata: Pointer, stream: PUint8, length: int): Pointer{. + cdecl.} # This macro can be used to fill a version structure with the compile-time + # version of the SDL_mixer library. + +proc SDL_MIXER_VERSION*(X: var TSDL_Version) + # This function gets the version of the dynamically linked SDL_mixer library. + # It should NOT be used to fill a version structure, instead you should use the + # SDL_MIXER_VERSION() macro. +proc Mix_Linked_Version*(): PSDL_version{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Open the mixer with a certain audio format +proc Mix_OpenAudio*(frequency: int, format: Uint16, channels: int, + chunksize: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Dynamically change the number of channels managed by the mixer. + # If decreasing the number of channels, the upper channels are + # stopped. + # This function returns the new number of allocated channels. + # +proc Mix_AllocateChannels*(numchannels: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Find out what the actual audio device parameters are. + # This function returns 1 if the audio has been opened, 0 otherwise. + # +proc Mix_QuerySpec*(frequency: var int, format: var Uint16, channels: var int): int{. + cdecl, importc, dynlib: SDL_MixerLibName.} + # Load a wave file or a music (.mod .s3m .it .xm) file +proc Mix_LoadWAV_RW*(src: PSDL_RWops, freesrc: int): PMix_Chunk{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_LoadWAV*(filename: cstring): PMix_Chunk +proc Mix_LoadMUS*(filename: cstring): PMix_Music{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Load a wave file of the mixer format from a memory buffer +proc Mix_QuickLoad_WAV*(mem: PUint8): PMix_Chunk{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Free an audio chunk previously loaded +proc Mix_FreeChunk*(chunk: PMix_Chunk){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FreeMusic*(music: PMix_Music){.cdecl, importc, dynlib: SDL_MixerLibName.} + # Find out the music format of a mixer music, or the currently playing + # music, if 'music' is NULL. +proc Mix_GetMusicType*(music: PMix_Music): TMix_MusicType{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Set a function that is called after all mixing is performed. + # This can be used to provide real-time visual display of the audio stream + # or add a custom mixer filter for the stream data. + # +proc Mix_SetPostMix*(mix_func: TMixFunction, arg: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Add your own music player or additional mixer function. + # If 'mix_func' is NULL, the default music player is re-enabled. + # +proc Mix_HookMusic*(mix_func: TMixFunction, arg: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Add your own callback when the music has finished playing. + # +proc Mix_HookMusicFinished*(music_finished: Pointer){.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Get a pointer to the user data for the current music hook +proc Mix_GetMusicHookData*(): Pointer{.cdecl, importc, dynlib: SDL_MixerLibName.} + #* Add your own callback when a channel has finished playing. NULL + # * to disable callback.* +type + TChannel_finished* = proc (channel: int){.cdecl.} + +proc Mix_ChannelFinished*(channel_finished: TChannel_finished){.cdecl, + importc, dynlib: SDL_MixerLibName.} +const + MIX_CHANNEL_POST* = - 2 #* This is the format of a special effect callback: + # * + # * myeffect(int chan, void *stream, int len, void *udata); + # * + # * (chan) is the channel number that your effect is affecting. (stream) is + # * the buffer of data to work upon. (len) is the size of (stream), and + # * (udata) is a user-defined bit of data, which you pass as the last arg of + # * Mix_RegisterEffect(), and is passed back unmolested to your callback. + # * Your effect changes the contents of (stream) based on whatever parameters + # * are significant, or just leaves it be, if you prefer. You can do whatever + # * you like to the buffer, though, and it will continue in its changed state + # * down the mixing pipeline, through any other effect functions, then finally + # * to be mixed with the rest of the channels and music for the final output + # * stream. + # * + +type + TMix_EffectFunc* = proc (chan: int, stream: Pointer, length: int, + udata: Pointer): Pointer{.cdecl.} + # * This is a callback that signifies that a channel has finished all its + # * loops and has completed playback. This gets called if the buffer + # * plays out normally, or if you call Mix_HaltChannel(), implicitly stop + # * a channel via Mix_AllocateChannels(), or unregister a callback while + # * it's still playing. + TMix_EffectDone* = proc (chan: int, udata: Pointer): Pointer{.cdecl.} + #* Register a special effect function. At mixing time, the channel data is + # * copied into a buffer and passed through each registered effect function. + # * After it passes through all the functions, it is mixed into the final + # * output stream. The copy to buffer is performed once, then each effect + # * function performs on the output of the previous effect. Understand that + # * this extra copy to a buffer is not performed if there are no effects + # * registered for a given chunk, which saves CPU cycles, and any given + # * effect will be extra cycles, too, so it is crucial that your code run + # * fast. Also note that the data that your function is given is in the + # * format of the sound device, and not the format you gave to Mix_OpenAudio(), + # * although they may in reality be the same. This is an unfortunate but + # * necessary speed concern. Use Mix_QuerySpec() to determine if you can + # * handle the data before you register your effect, and take appropriate + # * actions. + # * You may also specify a callback (Mix_EffectDone_t) that is called when + # * the channel finishes playing. This gives you a more fine-grained control + # * than Mix_ChannelFinished(), in case you need to free effect-specific + # * resources, etc. If you don't need this, you can specify NULL. + # * You may set the callbacks before or after calling Mix_PlayChannel(). + # * Things like Mix_SetPanning() are just internal special effect functions, + # * so if you are using that, you've already incurred the overhead of a copy + # * to a separate buffer, and that these effects will be in the queue with + # * any functions you've registered. The list of registered effects for a + # * channel is reset when a chunk finishes playing, so you need to explicitly + # * set them with each call to Mix_PlayChannel*(). + # * You may also register a special effect function that is to be run after + # * final mixing occurs. The rules for these callbacks are identical to those + # * in Mix_RegisterEffect, but they are run after all the channels and the + # * music have been mixed into a single stream, whereas channel-specific + # * effects run on a given channel before any other mixing occurs. These + # * global effect callbacks are call "posteffects". Posteffects only have + # * their Mix_EffectDone_t function called when they are unregistered (since + # * the main output stream is never "done" in the same sense as a channel). + # * You must unregister them manually when you've had enough. Your callback + # * will be told that the channel being mixed is (MIX_CHANNEL_POST) if the + # * processing is considered a posteffect. + # * + # * After all these effects have finished processing, the callback registered + # * through Mix_SetPostMix() runs, and then the stream goes to the audio + # * device. + # * + # * returns zero if error (no such channel), nonzero if added. + # * Error messages can be retrieved from Mix_GetError(). + +proc Mix_RegisterEffect*(chan: int, f: TMix_EffectFunc, d: TMix_EffectDone, + arg: Pointer): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + #* You may not need to call this explicitly, unless you need to stop an + # * effect from processing in the middle of a chunk's playback. + # * Posteffects are never implicitly unregistered as they are for channels, + # * but they may be explicitly unregistered through this function by + # * specifying MIX_CHANNEL_POST for a channel. + # * returns zero if error (no such channel or effect), nonzero if removed. + # * Error messages can be retrieved from Mix_GetError(). + # * +proc Mix_UnregisterEffect*(channel: int, f: TMix_EffectFunc): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + #* You may not need to call this explicitly, unless you need to stop all + # * effects from processing in the middle of a chunk's playback. Note that + # * this will also shut off some internal effect processing, since + # * Mix_SetPanning( ) and others may use this API under the hood.This is + # * called internally when a channel completes playback. + # * Posteffects are never implicitly unregistered as they are for channels, + # * but they may be explicitly unregistered through this function by + # * specifying MIX_CHANNEL_POST for a channel. + # * returns zero if error( no such channel ), nonzero if all effects removed. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_UnregisterAllEffects*(channel: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +const + MIX_EFFECTSMAXSPEED* = "MIX_EFFECTSMAXSPEED" + # * These are the internally - defined mixing effects.They use the same API that + # * effects defined in the application use, but are provided here as a + # * convenience.Some effects can reduce their quality or use more memory in + # * the name of speed; to enable this, make sure the environment variable + # * MIX_EFFECTSMAXSPEED( see above ) is defined before you call + # * Mix_OpenAudio( ). + # * + #* set the panning of a channel.The left and right channels are specified + # * as integers between 0 and 255, quietest to loudest, respectively. + # * + # * Technically, this is just individual volume control for a sample with + # * two( stereo )channels, so it can be used for more than just panning. + # * if you want real panning, call it like this : + # * + # * Mix_SetPanning( channel, left, 255 - left ); + # * + # * ...which isn't so hard. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the panning will be done to the final mixed stream before passing it on + # * to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally, and returns without + # * registering the effect function if the audio device is not configured + # * for stereo output.Setting both( left ) and ( right ) to 255 causes this + # * effect to be unregistered, since that is the data's normal state. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if panning effect enabled.Note that an audio device in mono + # * mode is a no - op, but this call will return successful in that case . + # * Error messages can be retrieved from Mix_GetError( ). + + +proc Mix_SetPanning*(channel: int, left: Uint8, right: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # * set the position ofa channel.( angle ) is an integer from 0 to 360, that + # * specifies the location of the sound in relation to the listener.( angle ) + # * will be reduced as neccesary( 540 becomes 180 degrees, -100 becomes 260 ). + # * Angle 0 is due north, and rotates clockwise as the value increases. + # * for efficiency, the precision of this effect may be limited( angles 1 + # * through 7 might all produce the same effect, 8 through 15 are equal, etc ). + # * ( distance ) is an integer between 0 and 255 that specifies the space + # * between the sound and the listener.The larger the number, the further + # * away the sound is .Using 255 does not guarantee that the channel will be + # * culled from the mixing process or be completely silent.For efficiency, + # * the precision of this effect may be limited( distance 0 through 5 might + # * all produce the same effect, 6 through 10 are equal, etc ).Setting( angle ) + # * and ( distance ) to 0 unregisters this effect, since the data would be + # * unchanged. + # * + # * if you need more precise positional audio, consider using OpenAL for + # * spatialized effects instead of SDL_mixer.This is only meant to be a + # * basic effect for simple "3D" games. + # * + # * if the audio device is configured for mono output, then you won't get + # * any effectiveness from the angle; however, distance attenuation on the + # * channel will still occur.While this effect will function with stereo + # * voices, it makes more sense to use voices with only one channel of sound, + # * so when they are mixed through this effect, the positioning will sound + # * correct.You can convert them to mono through SDL before giving them to + # * the mixer in the first place if you like. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the positioning will be done to the final mixed stream before passing it + # * on to the audio device. + # * + # * This is a convenience wrapper over Mix_SetDistance( ) and Mix_SetPanning( ). + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if position effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetPosition*(channel: int, angle: Sint16, distance: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + #* set the "distance" of a channel.( distance ) is an integer from 0 to 255 + # * that specifies the location of the sound in relation to the listener. + # * Distance 0 is overlapping the listener, and 255 is as far away as possible + # * A distance of 255 does not guarantee silence; in such a case , you might + # * want to try changing the chunk's volume, or just cull the sample from the + # * mixing process with Mix_HaltChannel( ). + # * for efficiency, the precision of this effect may be limited( distances 1 + # * through 7 might all produce the same effect, 8 through 15 are equal, etc ). + # * ( distance ) is an integer between 0 and 255 that specifies the space + # * between the sound and the listener.The larger the number, the further + # * away the sound is . + # * Setting( distance ) to 0 unregisters this effect, since the data would be + # * unchanged. + # * if you need more precise positional audio, consider using OpenAL for + # * spatialized effects instead of SDL_mixer.This is only meant to be a + # * basic effect for simple "3D" games. + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the distance attenuation will be done to the final mixed stream before + # * passing it on to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if position effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetDistance*(channel: int, distance: Uint8): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # * + # * !!! FIXME : Haven't implemented, since the effect goes past the + # * end of the sound buffer.Will have to think about this. + # * - -ryan. + # * / + # { if 0 + # { * Causes an echo effect to be mixed into a sound.( echo ) is the amount + # * of echo to mix.0 is no echo, 255 is infinite( and probably not + # * what you want ). + # * + # * Setting( channel ) to MIX_CHANNEL_POST registers this as a posteffect, and + # * the reverbing will be done to the final mixed stream before passing it on + # * to the audio device. + # * + # * This uses the Mix_RegisterEffect( )API internally.If you specify an echo + # * of zero, the effect is unregistered, as the data is already in that state. + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if reversing effect is enabled. + # * Error messages can be retrieved from Mix_GetError( ). + # * + # extern no_parse_DECLSPEC int Mix_SetReverb( int channel, Uint8 echo ); + # #E ndif + # * Causes a channel to reverse its stereo.This is handy if the user has his + # * speakers hooked up backwards, or you would like to have a minor bit of + # * psychedelia in your sound code. : )Calling this function with ( flip ) + # * set to non - zero reverses the chunks's usual channels. If (flip) is zero, + # * the effect is unregistered. + # * + # * This uses the Mix_RegisterEffect( )API internally, and thus is probably + # * more CPU intensive than having the user just plug in his speakers + # * correctly.Mix_SetReverseStereo( )returns without registering the effect + # * function if the audio device is not configured for stereo output. + # * + # * if you specify MIX_CHANNEL_POST for ( channel ), then this the effect is used + # * on the final mixed stream before sending it on to the audio device( a + # * posteffect ). + # * + # * returns zero if error( no such channel or Mix_RegisterEffect( )fails ), + # * nonzero if reversing effect is enabled.Note that an audio device in mono + # * mode is a no - op, but this call will return successful in that case . + # * Error messages can be retrieved from Mix_GetError( ). + # * +proc Mix_SetReverseStereo*(channel: int, flip: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # end of effects API. - -ryan. * + # Reserve the first channels (0 -> n-1) for the application, i.e. don't allocate + # them dynamically to the next sample if requested with a -1 value below. + # Returns the number of reserved channels. + # +proc Mix_ReserveChannels*(num: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Channel grouping functions + # Attach a tag to a channel. A tag can be assigned to several mixer + # channels, to form groups of channels. + # If 'tag' is -1, the tag is removed (actually -1 is the tag used to + # represent the group of all the channels). + # Returns true if everything was OK. + # +proc Mix_GroupChannel*(which: int, tag: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Assign several consecutive channels to a group +proc Mix_GroupChannels*(`from`: int, `to`: int, tag: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Finds the first available channel in a group of channels +proc Mix_GroupAvailable*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Returns the number of channels in a group. This is also a subtle + # way to get the total number of channels when 'tag' is -1 + # +proc Mix_GroupCount*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Finds the "oldest" sample playing in a group of channels +proc Mix_GroupOldest*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Finds the "most recent" (i.e. last) sample playing in a group of channels +proc Mix_GroupNewer*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # The same as above, but the sound is played at most 'ticks' milliseconds +proc Mix_PlayChannelTimed*(channel: int, chunk: PMix_Chunk, loops: int, + ticks: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Play an audio chunk on a specific channel. + # If the specified channel is -1, play on the first free channel. + # If 'loops' is greater than zero, loop the sound that many times. + # If 'loops' is -1, loop inifinitely (~65000 times). + # Returns which channel was used to play the sound. + # +proc Mix_PlayChannel*(channel: int, chunk: PMix_Chunk, loops: int): int +proc Mix_PlayMusic*(music: PMix_Music, loops: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Fade in music or a channel over "ms" milliseconds, same semantics as the "Play" functions +proc Mix_FadeInMusic*(music: PMix_Music, loops: int, ms: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeInChannelTimed*(channel: int, chunk: PMix_Chunk, loops: int, + ms: int, ticks: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeInChannel*(channel: int, chunk: PMix_Chunk, loops: int, ms: int): int + # Set the volume in the range of 0-128 of a specific channel or chunk. + # If the specified channel is -1, set volume for all channels. + # Returns the original volume. + # If the specified volume is -1, just return the current volume. + # +proc Mix_Volume*(channel: int, volume: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_VolumeChunk*(chunk: PMix_Chunk, volume: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_VolumeMusic*(volume: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Halt playing of a particular channel +proc Mix_HaltChannel*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_HaltGroup*(tag: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_HaltMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Change the expiration delay for a particular channel. + # The sample will stop playing after the 'ticks' milliseconds have elapsed, + # or remove the expiration if 'ticks' is -1 + # +proc Mix_ExpireChannel*(channel: int, ticks: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Halt a channel, fading it out progressively till it's silent + # The ms parameter indicates the number of milliseconds the fading + # will take. + # +proc Mix_FadeOutChannel*(which: int, ms: int): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeOutGroup*(tag: int, ms: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FadeOutMusic*(ms: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Query the fading status of a channel +proc Mix_FadingMusic*(): TMix_Fading{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_FadingChannel*(which: int): TMix_Fading{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Pause/Resume a particular channel +proc Mix_Pause*(channel: int){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_Resume*(channel: int){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_Paused*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Pause/Resume the music stream +proc Mix_PauseMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_ResumeMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_RewindMusic*(){.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_PausedMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Set the current position in the music stream. + # This returns 0 if successful, or -1 if it failed or isn't implemented. + # This function is only implemented for MOD music formats (set pattern + # order number) and for OGG music (set position in seconds), at the + # moment. + # +proc Mix_SetMusicPosition*(position: float64): int{.cdecl, + importc, dynlib: SDL_MixerLibName.} + # Check the status of a specific channel. + # If the specified channel is -1, check all channels. + # +proc Mix_Playing*(channel: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_PlayingMusic*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Stop music and set external music playback command +proc Mix_SetMusicCMD*(command: cstring): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Synchro value is set by MikMod from modules while playing +proc Mix_SetSynchroValue*(value: int): int{.cdecl, importc, dynlib: SDL_MixerLibName.} +proc Mix_GetSynchroValue*(): int{.cdecl, importc, dynlib: SDL_MixerLibName.} + # + # Get the Mix_Chunk currently associated with a mixer channel + # Returns nil if it's an invalid channel, or there's no chunk associated. + # +proc Mix_GetChunk*(channel: int): PMix_Chunk{.cdecl, importc, dynlib: SDL_MixerLibName.} + # Close the mixer, halting all playing audio +proc Mix_CloseAudio*(){.cdecl, importc, dynlib: SDL_MixerLibName.} + # We'll use SDL for reporting errors +proc Mix_SetError*(fmt: cstring) +proc Mix_GetError*(): cstring +# implementation + +proc SDL_MIXER_VERSION(X: var TSDL_version) = + X.major = SDL_MIXER_MAJOR_VERSION + X.minor = SDL_MIXER_MINOR_VERSION + X.patch = SDL_MIXER_PATCHLEVEL + +proc Mix_LoadWAV(filename: cstring): PMix_Chunk = + result = Mix_LoadWAV_RW(SDL_RWFromFile(filename, "rb"), 1) + +proc Mix_PlayChannel(channel: int, chunk: PMix_Chunk, loops: int): int = + result = Mix_PlayChannelTimed(channel, chunk, loops, - 1) + +proc Mix_FadeInChannel(channel: int, chunk: PMix_Chunk, loops: int, ms: int): int = + result = Mix_FadeInChannelTimed(channel, chunk, loops, ms, - 1) + +proc Mix_SetError(fmt: cstring) = + SDL_SetError(fmt) + +proc Mix_GetError(): cstring = + result = SDL_GetError() diff --git a/lib/wrappers/sdl/sdl_net.nim b/lib/wrappers/sdl/sdl_net.nim new file mode 100644 index 000000000..f27a674ae --- /dev/null +++ b/lib/wrappers/sdl/sdl_net.nim @@ -0,0 +1,431 @@ + +#****************************************************************************** +# +# $Id: sdl_net.pas,v 1.7 2005/01/01 02:14:21 savage Exp $ +# +# +# +# Borland Delphi SDL_Net - A x-platform network library for use with SDL. +# Conversion of the Simple DirectMedia Layer Network Headers +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : SDL_net.h +# +# The initial developer of this Pascal code was : +# Dominqiue Louis <Dominique@SavageSoftware.com.au> +# +# Portions created by Dominqiue Louis are +# Copyright (C) 2000 - 2001 Dominqiue Louis. +# +# +# Contributor(s) +# -------------- +# Matthias Thoma <ma.thoma@gmx.de> +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# +# +# +# +# +# +# +# Requires +# -------- +# SDL.pas somehere in your search path +# +# Programming Notes +# ----------------- +# +# +# +# +# Revision History +# ---------------- +# April 09 2001 - DL : Initial Translation +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# $Log: sdl_net.pas,v $ +# Revision 1.7 2005/01/01 02:14:21 savage +# Updated to v1.2.5 +# +# Revision 1.6 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.5 2004/05/10 14:10:04 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.4 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.3 2004/04/01 20:53:23 savage +# Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.2 2004/03/30 20:23:28 savage +# Tidied up use of UNIX compiler directive. +# +# Revision 1.1 2004/02/16 22:16:40 savage +# v1.0 changes +# +# +# +#****************************************************************************** + +import + sdl + +when defined(windows): + const SDLNetLibName = "SDL_net.dll" +elif defined(macosx): + const SDLNetLibName = "libSDL_net.dylib" +else: + const SDLNetLibName = "libSDL_net.so" + +const #* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL * + SDL_NET_MAJOR_VERSION* = 1'i8 + SDL_NET_MINOR_VERSION* = 2'i8 + SDL_NET_PATCHLEVEL* = 5'i8 # SDL_Net.h constants + #* Resolve a host name and port to an IP address in network form. + # If the function succeeds, it will return 0. + # If the host couldn't be resolved, the host portion of the returned + # address will be INADDR_NONE, and the function will return -1. + # If 'host' is NULL, the resolved host will be set to INADDR_ANY. + # * + INADDR_ANY* = 0x00000000 + INADDR_NONE* = 0xFFFFFFFF #*********************************************************************** + #* UDP network API * + #*********************************************************************** + #* The maximum channels on a a UDP socket * + SDLNET_MAX_UDPCHANNELS* = 32 #* The maximum addresses bound to a single UDP socket channel * + SDLNET_MAX_UDPADDRESSES* = 4 + +type # SDL_net.h types + #*********************************************************************** + #* IPv4 hostname resolution API * + #*********************************************************************** + PIPAddress* = ptr TIPAddress + TIPAddress*{.final.} = object #* TCP network API + host*: Uint32 # 32-bit IPv4 host address */ + port*: Uint16 # 16-bit protocol port */ + + PTCPSocket* = ptr TTCPSocket + TTCPSocket*{.final.} = object #*********************************************************************** + #* UDP network API * + #*********************************************************************** + ready*: int + channel*: int + remoteAddress*: TIPaddress + localAddress*: TIPaddress + sflag*: int + + PUDP_Channel* = ptr TUDP_Channel + TUDP_Channel*{.final.} = object + numbound*: int + address*: array[0..SDLNET_MAX_UDPADDRESSES - 1, TIPAddress] + + PUDPSocket* = ptr TUDPSocket + TUDPSocket*{.final.} = object + ready*: int + channel*: int + address*: TIPAddress + binding*: array[0..SDLNET_MAX_UDPCHANNELS - 1, TUDP_Channel] + + PUDPpacket* = ptr TUDPpacket + PPUDPpacket* = ptr PUDPpacket + TUDPpacket*{.final.} = object #*********************************************************************** + #* Hooks for checking sockets for available data * + #*********************************************************************** + channel*: int #* The src/dst channel of the packet * + data*: PUint8 #* The packet data * + length*: int #* The length of the packet data * + maxlen*: int #* The size of the data buffer * + status*: int #* packet status after sending * + address*: TIPAddress #* The source/dest address of an incoming/outgoing packet * + + PSDLNet_Socket* = ptr TSDLNet_Socket + TSDLNet_Socket*{.final.} = object + ready*: int + channel*: int + + PSDLNet_SocketSet* = ptr TSDLNet_SocketSet + TSDLNet_SocketSet*{.final.} = object #* Any network socket can be safely cast to this socket type * + numsockets*: int + maxsockets*: int + sockets*: PSDLNet_Socket + + PSDLNet_GenericSocket* = ptr TSDLNet_GenericSocket + TSDLNet_GenericSocket*{.final.} = object # This macro can be used to fill a version structure with the compile-time + # version of the SDL_net library. + ready*: int + + +proc SDL_NET_VERSION*(X: var TSDL_version) + #* Initialize/Cleanup the network API + # SDL must be initialized before calls to functions in this library, + # because this library uses utility functions from the SDL library. + #* +proc SDLNet_Init*(): int{.cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_Quit*(){.cdecl, importc, dynlib: SDLNetLibName.} + #* Resolve a host name and port to an IP address in network form. + # If the function succeeds, it will return 0. + # If the host couldn't be resolved, the host portion of the returned + # address will be INADDR_NONE, and the function will return -1. + # If 'host' is NULL, the resolved host will be set to INADDR_ANY. + # * +proc SDLNet_ResolveHost*(address: var TIPaddress, host: cstring, port: Uint16): int{. + cdecl, importc, dynlib: SDLNetLibName.} + #* Resolve an ip address to a host name in canonical form. + # If the ip couldn't be resolved, this function returns NULL, + # otherwise a pointer to a static buffer containing the hostname + # is returned. Note that this function is not thread-safe. + #* +proc SDLNet_ResolveIP*(ip: var TIPaddress): cstring{.cdecl, + importc, dynlib: SDLNetLibName.} + #*********************************************************************** + #* TCP network API * + #*********************************************************************** + #* Open a TCP network socket + # If ip.host is INADDR_NONE, this creates a local server socket on the + # given port, otherwise a TCP connection to the remote host and port is + # attempted. The address passed in should already be swapped to network + # byte order (addresses returned from SDLNet_ResolveHost() are already + # in the correct form). + # The newly created socket is returned, or NULL if there was an error. + #* +proc SDLNet_TCP_Open*(ip: var TIPaddress): PTCPSocket{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Accept an incoming connection on the given server socket. + # The newly created socket is returned, or NULL if there was an error. + #* +proc SDLNet_TCP_Accept*(server: PTCPsocket): PTCPSocket{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Get the IP address of the remote system associated with the socket. + # If the socket is a server socket, this function returns NULL. + #* +proc SDLNet_TCP_GetPeerAddress*(sock: PTCPsocket): PIPAddress{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Send 'len' bytes of 'data' over the non-server socket 'sock' + # This function returns the actual amount of data sent. If the return value + # is less than the amount of data sent, then either the remote connection was + # closed, or an unknown socket error occurred. + #* +proc SDLNet_TCP_Send*(sock: PTCPsocket, data: Pointer, length: int): int{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Receive up to 'maxlen' bytes of data over the non-server socket 'sock', + # and store them in the buffer pointed to by 'data'. + # This function returns the actual amount of data received. If the return + # value is less than or equal to zero, then either the remote connection was + # closed, or an unknown socket error occurred. + #* +proc SDLNet_TCP_Recv*(sock: PTCPsocket, data: Pointer, maxlen: int): int{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Close a TCP network socket * +proc SDLNet_TCP_Close*(sock: PTCPsocket){.cdecl, importc, dynlib: SDLNetLibName.} + #*********************************************************************** + #* UDP network API * + #*********************************************************************** + #* Allocate/resize/free a single UDP packet 'size' bytes long. + # The new packet is returned, or NULL if the function ran out of memory. + # * +proc SDLNet_AllocPacket*(size: int): PUDPpacket{.cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_ResizePacket*(packet: PUDPpacket, newsize: int): int{.cdecl, + importc, dynlib: SDLNetLibName.} +proc SDLNet_FreePacket*(packet: PUDPpacket){.cdecl, importc, dynlib: SDLNetLibName.} + #* Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets, + # each 'size' bytes long. + # A pointer to the first packet in the array is returned, or NULL if the + # function ran out of memory. + # * +proc SDLNet_AllocPacketV*(howmany: int, size: int): PUDPpacket{.cdecl, + importc, dynlib: SDLNetLibName.} +proc SDLNet_FreePacketV*(packetV: PUDPpacket){.cdecl, importc, dynlib: SDLNetLibName.} + #* Open a UDP network socket + # If 'port' is non-zero, the UDP socket is bound to a local port. + # This allows other systems to send to this socket via a known port. + #* +proc SDLNet_UDP_Open*(port: Uint16): PUDPsocket{.cdecl, importc, dynlib: SDLNetLibName.} + #* Bind the address 'address' to the requested channel on the UDP socket. + # If the channel is -1, then the first unbound channel will be bound with + # the given address as it's primary address. + # If the channel is already bound, this new address will be added to the + # list of valid source addresses for packets arriving on the channel. + # If the channel is not already bound, then the address becomes the primary + # address, to which all outbound packets on the channel are sent. + # This function returns the channel which was bound, or -1 on error. + #* +proc SDLNet_UDP_Bind*(sock: PUDPsocket, channel: int, address: var TIPaddress): int{. + cdecl, importc, dynlib: SDLNetLibName.} + #* Unbind all addresses from the given channel * +proc SDLNet_UDP_Unbind*(sock: PUDPsocket, channel: int){.cdecl, + importc, dynlib: SDLNetLibName.} + #* Get the primary IP address of the remote system associated with the + # socket and channel. If the channel is -1, then the primary IP port + # of the UDP socket is returned -- this is only meaningful for sockets + # opened with a specific port. + # If the channel is not bound and not -1, this function returns NULL. + # * +proc SDLNet_UDP_GetPeerAddress*(sock: PUDPsocket, channel: int): PIPAddress{. + cdecl, importc, dynlib: SDLNetLibName.} + #* Send a vector of packets to the the channels specified within the packet. + # If the channel specified in the packet is -1, the packet will be sent to + # the address in the 'src' member of the packet. + # Each packet will be updated with the status of the packet after it has + # been sent, -1 if the packet send failed. + # This function returns the number of packets sent. + #* +proc SDLNet_UDP_SendV*(sock: PUDPsocket, packets: PPUDPpacket, npackets: int): int{. + cdecl, importc, dynlib: SDLNetLibName.} + #* Send a single packet to the specified channel. + # If the channel specified in the packet is -1, the packet will be sent to + # the address in the 'src' member of the packet. + # The packet will be updated with the status of the packet after it has + # been sent. + # This function returns 1 if the packet was sent, or 0 on error. + #* +proc SDLNet_UDP_Send*(sock: PUDPsocket, channel: int, packet: PUDPpacket): int{. + cdecl, importc, dynlib: SDLNetLibName.} + #* Receive a vector of pending packets from the UDP socket. + # The returned packets contain the source address and the channel they arrived + # on. If they did not arrive on a bound channel, the the channel will be set + # to -1. + # The channels are checked in highest to lowest order, so if an address is + # bound to multiple channels, the highest channel with the source address + # bound will be returned. + # This function returns the number of packets read from the network, or -1 + # on error. This function does not block, so can return 0 packets pending. + #* +proc SDLNet_UDP_RecvV*(sock: PUDPsocket, packets: PPUDPpacket): int{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Receive a single packet from the UDP socket. + # The returned packet contains the source address and the channel it arrived + # on. If it did not arrive on a bound channel, the the channel will be set + # to -1. + # The channels are checked in highest to lowest order, so if an address is + # bound to multiple channels, the highest channel with the source address + # bound will be returned. + # This function returns the number of packets read from the network, or -1 + # on error. This function does not block, so can return 0 packets pending. + #* +proc SDLNet_UDP_Recv*(sock: PUDPsocket, packet: PUDPpacket): int{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Close a UDP network socket * +proc SDLNet_UDP_Close*(sock: PUDPsocket){.cdecl, importc, dynlib: SDLNetLibName.} + #*********************************************************************** + #* Hooks for checking sockets for available data * + #*********************************************************************** + #* Allocate a socket set for use with SDLNet_CheckSockets() + # This returns a socket set for up to 'maxsockets' sockets, or NULL if + # the function ran out of memory. + # * +proc SDLNet_AllocSocketSet*(maxsockets: int): PSDLNet_SocketSet{.cdecl, + importc, dynlib: SDLNetLibName.} + #* Add a socket to a set of sockets to be checked for available data * +proc SDLNet_AddSocket*(theSet: PSDLNet_SocketSet, sock: PSDLNet_GenericSocket): int{. + cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_TCP_AddSocket*(theSet: PSDLNet_SocketSet, sock: PTCPSocket): int +proc SDLNet_UDP_AddSocket*(theSet: PSDLNet_SocketSet, sock: PUDPSocket): int + #* Remove a socket from a set of sockets to be checked for available data * +proc SDLNet_DelSocket*(theSet: PSDLNet_SocketSet, sock: PSDLNet_GenericSocket): int{. + cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_TCP_DelSocket*(theSet: PSDLNet_SocketSet, sock: PTCPSocket): int + # SDLNet_DelSocket(set, (SDLNet_GenericSocket)sock) +proc SDLNet_UDP_DelSocket*(theSet: PSDLNet_SocketSet, sock: PUDPSocket): int + #SDLNet_DelSocket(set, (SDLNet_GenericSocket)sock) + #* This function checks to see if data is available for reading on the + # given set of sockets. If 'timeout' is 0, it performs a quick poll, + # otherwise the function returns when either data is available for + # reading, or the timeout in milliseconds has elapsed, which ever occurs + # first. This function returns the number of sockets ready for reading, + # or -1 if there was an error with the select() system call. + #* +proc SDLNet_CheckSockets*(theSet: PSDLNet_SocketSet, timeout: Sint32): int{. + cdecl, importc, dynlib: SDLNetLibName.} + #* After calling SDLNet_CheckSockets(), you can use this function on a + # socket that was in the socket set, to find out if data is available + # for reading. + #* +proc SDLNet_SocketReady*(sock: PSDLNet_GenericSocket): bool + #* Free a set of sockets allocated by SDL_NetAllocSocketSet() * +proc SDLNet_FreeSocketSet*(theSet: PSDLNet_SocketSet){.cdecl, + importc, dynlib: SDLNetLibName.} + #*********************************************************************** + #* Platform-independent data conversion functions * + #*********************************************************************** + #* Write a 16/32 bit value to network packet buffer * +proc SDLNet_Write16*(value: Uint16, area: Pointer){.cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_Write32*(value: Uint32, area: Pointer){.cdecl, importc, dynlib: SDLNetLibName.} + #* Read a 16/32 bit value from network packet buffer * +proc SDLNet_Read16*(area: Pointer): Uint16{.cdecl, importc, dynlib: SDLNetLibName.} +proc SDLNet_Read32*(area: Pointer): Uint32{.cdecl, importc, dynlib: SDLNetLibName.} + #*********************************************************************** + #* Error reporting functions * + #*********************************************************************** + #* We'll use SDL's functions for error reporting * +proc SDLNet_SetError*(fmt: cstring) +proc SDLNet_GetError*(): cstring +# implementation + +proc SDL_NET_VERSION(X: var TSDL_version) = + X.major = SDL_NET_MAJOR_VERSION + X.minor = SDL_NET_MINOR_VERSION + X.patch = SDL_NET_PATCHLEVEL + +proc SDLNet_TCP_AddSocket(theSet: PSDLNet_SocketSet, sock: PTCPSocket): int = + result = SDLNet_AddSocket(theSet, cast[PSDLNet_GenericSocket](sock)) + +proc SDLNet_UDP_AddSocket(theSet: PSDLNet_SocketSet, sock: PUDPSocket): int = + result = SDLNet_AddSocket(theSet, cast[PSDLNet_GenericSocket](sock)) + +proc SDLNet_TCP_DelSocket(theSet: PSDLNet_SocketSet, sock: PTCPSocket): int = + result = SDLNet_DelSocket(theSet, cast[PSDLNet_GenericSocket](sock)) + +proc SDLNet_UDP_DelSocket(theSet: PSDLNet_SocketSet, sock: PUDPSocket): int = + result = SDLNet_DelSocket(theSet, cast[PSDLNet_GenericSocket](sock)) + +proc SDLNet_SocketReady(sock: PSDLNet_GenericSocket): bool = + result = ((sock != nil) and (sock.ready == 1)) + +proc SDLNet_SetError(fmt: cstring) = + SDL_SetError(fmt) + +proc SDLNet_GetError(): cstring = + result = SDL_GetError() diff --git a/lib/wrappers/sdl/sdl_ttf.nim b/lib/wrappers/sdl/sdl_ttf.nim new file mode 100644 index 000000000..724c2f634 --- /dev/null +++ b/lib/wrappers/sdl/sdl_ttf.nim @@ -0,0 +1,346 @@ + +# +# $Id: sdl_ttf.pas,v 1.18 2007/06/01 11:16:33 savage Exp $ +# +# +#****************************************************************************** +# +# JEDI-SDL : Pascal units for SDL - Simple DirectMedia Layer +# Conversion of the Simple DirectMedia Layer Headers +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : SDL_ttf.h +# +# The initial developer of this Pascal code was : +# Dominqiue Louis <Dominique@SavageSoftware.com.au> +# +# Portions created by Dominqiue Louis are +# Copyright (C) 2000 - 2001 Dominqiue Louis. +# +# +# Contributor(s) +# -------------- +# Tom Jones <tigertomjones@gmx.de> His Project inspired this conversion +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# +# +# +# +# +# +# +# Requires +# -------- +# The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL.so +# They are available from... +# http://www.libsdl.org . +# +# Programming Notes +# ----------------- +# +# +# +# +# Revision History +# ---------------- +# December 08 2002 - DL : Fixed definition of TTF_RenderUnicode_Solid +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# $Log: sdl_ttf.pas,v $ +# Revision 1.18 2007/06/01 11:16:33 savage +# Added IFDEF UNIX for Workaround. +# +# Revision 1.17 2007/06/01 08:38:21 savage +# Added TTF_RenderText_Solid workaround as suggested by Michalis Kamburelis +# +# Revision 1.16 2007/05/29 21:32:14 savage +# Changes as suggested by Almindor for 64bit compatibility. +# +# Revision 1.15 2007/05/20 20:32:45 savage +# Initial Changes to Handle 64 Bits +# +# Revision 1.14 2006/12/02 00:19:01 savage +# Updated to latest version +# +# Revision 1.13 2005/04/10 11:48:33 savage +# Changes as suggested by Michalis, thanks. +# +# Revision 1.12 2005/01/05 01:47:14 savage +# Changed LibName to reflect what MacOS X should have. ie libSDL*-1.2.0.dylib respectively. +# +# Revision 1.11 2005/01/04 23:14:57 savage +# Changed LibName to reflect what most Linux distros will have. ie libSDL*-1.2.so.0 respectively. +# +# Revision 1.10 2005/01/02 19:07:32 savage +# Slight bug fix to use LongInt instead of Long ( Thanks Michalis Kamburelis ) +# +# Revision 1.9 2005/01/01 02:15:20 savage +# Updated to v2.0.7 +# +# Revision 1.8 2004/10/07 21:02:32 savage +# Fix for FPC +# +# Revision 1.7 2004/09/30 22:39:50 savage +# Added a true type font class which contains a wrap text function. +# Changed the sdl_ttf.pas header to reflect the future of jedi-sdl. +# +# Revision 1.6 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.5 2004/05/10 14:10:04 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.4 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.3 2004/04/01 20:53:24 savage +# Changed Linux Shared Object names so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.2 2004/03/30 20:23:28 savage +# Tidied up use of UNIX compiler directive. +# +# Revision 1.1 2004/02/16 22:16:40 savage +# v1.0 changes +# +# +# +#****************************************************************************** +# +# Define this to workaround a known bug in some freetype versions. +# The error manifests as TTF_RenderGlyph_Solid returning nil (error) +# and error message (in SDL_Error) is +# "Failed loading DPMSDisable: /usr/lib/libX11.so.6: undefined symbol: DPMSDisable" +# See [http://lists.libsdl.org/pipermail/sdl-libsdl.org/2007-March/060459.html] +# + +import sdl + +when defined(windows): + const SDLttfLibName = "SDL_ttf.dll" +elif defined(macosx): + const SDLttfLibName = "libSDL_ttf-2.0.0.dylib" +else: + const SDLttfLibName = "libSDL_ttf.so" + +const + SDL_TTF_MAJOR_VERSION* = 2'i8 + SDL_TTF_MINOR_VERSION* = 0'i8 + SDL_TTF_PATCHLEVEL* = 8'i8 # Backwards compatibility + TTF_MAJOR_VERSION* = SDL_TTF_MAJOR_VERSION + TTF_MINOR_VERSION* = SDL_TTF_MINOR_VERSION + TTF_PATCHLEVEL* = SDL_TTF_PATCHLEVEL #* + # Set and retrieve the font style + # This font style is implemented by modifying the font glyphs, and + # doesn't reflect any inherent properties of the truetype font file. + #* + TTF_STYLE_NORMAL* = 0x00000000 + TTF_STYLE_BOLD* = 0x00000001 + TTF_STYLE_ITALIC* = 0x00000002 + TTF_STYLE_UNDERLINE* = 0x00000004 # ZERO WIDTH NO-BREAKSPACE (Unicode byte order mark) + UNICODE_BOM_NATIVE* = 0x0000FEFF + UNICODE_BOM_SWAPPED* = 0x0000FFFE + +type + PTTF_Font* = ptr TTTF_font + TTTF_Font*{.final.} = object # This macro can be used to fill a version structure with the compile-time + # version of the SDL_ttf library. + +proc SDL_TTF_VERSION*(X: var TSDL_version) + # This function gets the version of the dynamically linked SDL_ttf library. + # It should NOT be used to fill a version structure, instead you should use the + # SDL_TTF_VERSION() macro. +proc TTF_Linked_Version*(): PSDL_version{.cdecl, importc, dynlib: SDLttfLibName.} + # This function tells the library whether UNICODE text is generally + # byteswapped. A UNICODE BOM character in a string will override + # this setting for the remainder of that string. + # +proc TTF_ByteSwappedUNICODE*(swapped: int){.cdecl, importc, dynlib: SDLttfLibName.} + #returns 0 on succes, -1 if error occurs +proc TTF_Init*(): int{.cdecl, importc, dynlib: SDLttfLibName.} + # + # Open a font file and create a font of the specified point size. + # Some .fon fonts will have several sizes embedded in the file, so the + # point size becomes the index of choosing which size. If the value + # is too high, the last indexed size will be the default. + # +proc TTF_OpenFont*(filename: cstring, ptsize: int): PTTF_Font{.cdecl, + importc, dynlib: SDLttfLibName.} +proc TTF_OpenFontIndex*(filename: cstring, ptsize: int, index: int32): PTTF_Font{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_OpenFontRW*(src: PSDL_RWops, freesrc: int, ptsize: int): PTTF_Font{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_OpenFontIndexRW*(src: PSDL_RWops, freesrc: int, ptsize: int, + index: int32): PTTF_Font{.cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_GetFontStyle*(font: PTTF_Font): int{.cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_SetFontStyle*(font: PTTF_Font, style: int){.cdecl, + importc, dynlib: SDLttfLibName.} + # Get the total height of the font - usually equal to point size +proc TTF_FontHeight*(font: PTTF_Font): int{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the offset from the baseline to the top of the font + # This is a positive value, relative to the baseline. + # +proc TTF_FontAscent*(font: PTTF_Font): int{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the offset from the baseline to the bottom of the font + # This is a negative value, relative to the baseline. + # +proc TTF_FontDescent*(font: PTTF_Font): int{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the recommended spacing between lines of text for this font +proc TTF_FontLineSkip*(font: PTTF_Font): int{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the number of faces of the font +proc TTF_FontFaces*(font: PTTF_Font): int32{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the font face attributes, if any +proc TTF_FontFaceIsFixedWidth*(font: PTTF_Font): int{.cdecl, + importc, dynlib: SDLttfLibName.} +proc TTF_FontFaceFamilyName*(font: PTTF_Font): cstring{.cdecl, + importc, dynlib: SDLttfLibName.} +proc TTF_FontFaceStyleName*(font: PTTF_Font): cstring{.cdecl, + importc, dynlib: SDLttfLibName.} + # Get the metrics (dimensions) of a glyph +proc TTF_GlyphMetrics*(font: PTTF_Font, ch: Uint16, minx: var int, + maxx: var int, miny: var int, maxy: var int, + advance: var int): int{.cdecl, importc, dynlib: SDLttfLibName.} + # Get the dimensions of a rendered string of text +proc TTF_SizeText*(font: PTTF_Font, text: cstring, w: var int, y: var int): int{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_SizeUTF8*(font: PTTF_Font, text: cstring, w: var int, y: var int): int{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_SizeUNICODE*(font: PTTF_Font, text: PUint16, w: var int, y: var int): int{. + cdecl, importc, dynlib: SDLttfLibName.} + # Create an 8-bit palettized surface and render the given text at + # fast quality with the given font and color. The 0 pixel is the + # colorkey, giving a transparent background, and the 1 pixel is set + # to the text color. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderUTF8_Solid*(font: PTTF_Font, text: cstring, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_RenderUNICODE_Solid*(font: PTTF_Font, text: PUint16, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} + # + #Create an 8-bit palettized surface and render the given glyph at + # fast quality with the given font and color. The 0 pixel is the + # colorkey, giving a transparent background, and the 1 pixel is set + # to the text color. The glyph is rendered without any padding or + # centering in the X direction, and aligned normally in the Y direction. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderGlyph_Solid*(font: PTTF_Font, ch: Uint16, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} + # Create an 8-bit palettized surface and render the given text at + # high quality with the given font and colors. The 0 pixel is background, + # while other pixels have varying degrees of the foreground color. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderText_Shaded*(font: PTTF_Font, text: cstring, fg: TSDL_Color, + bg: TSDL_Color): PSDL_Surface{.cdecl, + importc, dynlib: SDLttfLibName.} +proc TTF_RenderUTF8_Shaded*(font: PTTF_Font, text: cstring, fg: TSDL_Color, + bg: TSDL_Color): PSDL_Surface{.cdecl, + importc, dynlib: SDLttfLibName.} +proc TTF_RenderUNICODE_Shaded*(font: PTTF_Font, text: PUint16, fg: TSDL_Color, + bg: TSDL_Color): PSDL_Surface{.cdecl, + importc, dynlib: SDLttfLibName.} + # Create an 8-bit palettized surface and render the given glyph at + # high quality with the given font and colors. The 0 pixel is background, + # while other pixels have varying degrees of the foreground color. + # The glyph is rendered without any padding or centering in the X + # direction, and aligned normally in the Y direction. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderGlyph_Shaded*(font: PTTF_Font, ch: Uint16, fg: TSDL_Color, + bg: TSDL_Color): PSDL_Surface{.cdecl, + importc, dynlib: SDLttfLibName.} + # Create a 32-bit ARGB surface and render the given text at high quality, + # using alpha blending to dither the font with the given color. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderText_Blended*(font: PTTF_Font, text: cstring, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_RenderUTF8_Blended*(font: PTTF_Font, text: cstring, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} +proc TTF_RenderUNICODE_Blended*(font: PTTF_Font, text: PUint16, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} + # Create a 32-bit ARGB surface and render the given glyph at high quality, + # using alpha blending to dither the font with the given color. + # The glyph is rendered without any padding or centering in the X + # direction, and aligned normally in the Y direction. + # This function returns the new surface, or NULL if there was an error. + # +proc TTF_RenderGlyph_Blended*(font: PTTF_Font, ch: Uint16, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} + # For compatibility with previous versions, here are the old functions + ##define TTF_RenderText(font, text, fg, bg) + # TTF_RenderText_Shaded(font, text, fg, bg) + ##define TTF_RenderUTF8(font, text, fg, bg) + # TTF_RenderUTF8_Shaded(font, text, fg, bg) + ##define TTF_RenderUNICODE(font, text, fg, bg) + # TTF_RenderUNICODE_Shaded(font, text, fg, bg) + # Close an opened font file +proc TTF_CloseFont*(font: PTTF_Font){.cdecl, importc, dynlib: SDLttfLibName.} + #De-initialize TTF engine +proc TTF_Quit*(){.cdecl, importc, dynlib: SDLttfLibName.} + # Check if the TTF engine is initialized +proc TTF_WasInit*(): int{.cdecl, importc, dynlib: SDLttfLibName.} + # We'll use SDL for reporting errors +proc TTF_SetError*(fmt: cstring) +proc TTF_GetError*(): cstring +# implementation + +proc SDL_TTF_VERSION(X: var TSDL_version) = + X.major = SDL_TTF_MAJOR_VERSION + X.minor = SDL_TTF_MINOR_VERSION + X.patch = SDL_TTF_PATCHLEVEL + +proc TTF_SetError(fmt: cstring) = + SDL_SetError(fmt) + +proc TTF_GetError(): cstring = + result = SDL_GetError() + +when not(defined(Workaround_TTF_RenderText_Solid)): + proc TTF_RenderText_Solid*(font: PTTF_Font, text: cstring, fg: TSDL_Color): PSDL_Surface{. + cdecl, importc, dynlib: SDLttfLibName.} +else: + proc TTF_RenderText_Solid(font: PTTF_Font, text: cstring, fg: TSDL_Color): PSDL_Surface = + var Black: TSDL_Color # initialized to zero + Result = TTF_RenderText_Shaded(font, text, fg, Black) diff --git a/lib/wrappers/sdl/sdlutils.pas b/lib/wrappers/sdl/sdlutils.pas new file mode 100644 index 000000000..e4206e935 --- /dev/null +++ b/lib/wrappers/sdl/sdlutils.pas @@ -0,0 +1,4354 @@ +unit sdlutils; +{ + $Id: sdlutils.pas,v 1.5 2006/11/19 18:56:44 savage Exp $ + +} +{******************************************************************************} +{ } +{ Borland Delphi SDL - Simple DirectMedia Layer } +{ SDL Utility functions } +{ } +{ } +{ The initial developer of this Pascal code was : } +{ Tom Jones <tigertomjones@gmx.de> } +{ } +{ Portions created by Tom Jones are } +{ Copyright (C) 2000 - 2001 Tom Jones. } +{ } +{ } +{ Contributor(s) } +{ -------------- } +{ Dominique Louis <Dominique@SavageSoftware.com.au> } +{ Róbert Kisnémeth <mikrobi@freemail.hu> } +{ } +{ Obtained through: } +{ Joint Endeavour of Delphi Innovators ( Project JEDI ) } +{ } +{ You may retrieve the latest version of this file at the Project } +{ JEDI home page, located at http://delphi-jedi.org } +{ } +{ The contents of this file are used with permission, subject to } +{ the Mozilla Public License Version 1.1 (the "License"); you may } +{ not use this file except in compliance with the License. You may } +{ obtain a copy of the License at } +{ http://www.mozilla.org/MPL/MPL-1.1.html } +{ } +{ Software distributed under the License is distributed on an } +{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or } +{ implied. See the License for the specific language governing } +{ rights and limitations under the License. } +{ } +{ Description } +{ ----------- } +{ Helper functions... } +{ } +{ } +{ Requires } +{ -------- } +{ SDL.dll on Windows platforms } +{ libSDL-1.1.so.0 on Linux platform } +{ } +{ Programming Notes } +{ ----------------- } +{ } +{ } +{ } +{ } +{ Revision History } +{ ---------------- } +{ 2000 - TJ : Initial creation } +{ } +{ July 13 2001 - DL : Added PutPixel and GetPixel routines. } +{ } +{ Sept 14 2001 - RK : Added flipping routines. } +{ } +{ Sept 19 2001 - RK : Added PutPixel & line drawing & blitting with ADD } +{ effect. Fixed a bug in SDL_PutPixel & SDL_GetPixel } +{ Added PSDLRect() } +{ Sept 22 2001 - DL : Removed need for Windows.pas by defining types here} +{ Also removed by poor attempt or a dialog box } +{ } +{ Sept 25 2001 - RK : Added PixelTest, NewPutPixel, SubPixel, SubLine, } +{ SubSurface, MonoSurface & TexturedSurface } +{ } +{ Sept 26 2001 - DL : Made change so that it refers to native Pascal } +{ types rather that Windows types. This makes it more} +{ portable to Linix. } +{ } +{ Sept 27 2001 - RK : SDLUtils now can be compiled with FreePascal } +{ } +{ Oct 27 2001 - JF : Added ScrollY function } +{ } +{ Jan 21 2002 - RK : Added SDL_ZoomSurface and SDL_WarpSurface } +{ } +{ Mar 28 2002 - JF : Added SDL_RotateSurface } +{ } +{ May 13 2002 - RK : Improved SDL_FillRectAdd & SDL_FillRectSub } +{ } +{ May 27 2002 - YS : GradientFillRect function } +{ } +{ May 30 2002 - RK : Added SDL_2xBlit, SDL_Scanline2xBlit } +{ & SDL_50Scanline2xBlit } +{ } +{ June 12 2002 - RK : Added SDL_PixelTestSurfaceVsRect } +{ } +{ June 12 2002 - JF : Updated SDL_PixelTestSurfaceVsRect } +{ } +{ November 9 2002 - JF : Added Jason's boolean Surface functions } +{ } +{ December 10 2002 - DE : Added Dean's SDL_ClipLine function } +{ } +{ April 26 2003 - SS : Incorporated JF's changes to SDL_ClipLine } +{ Fixed SDL_ClipLine bug for non-zero cliprect x, y } +{ Added overloaded SDL_DrawLine for dashed lines } +{ } +{******************************************************************************} +{ + $Log: sdlutils.pas,v $ + Revision 1.5 2006/11/19 18:56:44 savage + Removed Hints and Warnings. + + Revision 1.4 2004/06/02 19:38:53 savage + Changes to SDL_GradientFillRect as suggested by + Ángel Eduardo García Hernández. Many thanks. + + Revision 1.3 2004/05/29 23:11:54 savage + Changes to SDL_ScaleSurfaceRect as suggested by + Ángel Eduardo García Hernández to fix a colour issue with the function. Many thanks. + + Revision 1.2 2004/02/14 00:23:39 savage + As UNIX is defined in jedi-sdl.inc this will be used to check linux compatability as well. Units have been changed to reflect this change. + + Revision 1.1 2004/02/05 00:08:20 savage + Module 1.0 release + + +} + +interface + +uses + sdl; + +type + TGradientStyle = ( gsHorizontal, gsVertical ); + +// Pixel procedures +function SDL_PixelTest( SrcSurface1 : PSDL_Surface; SrcRect1 : PSDL_Rect; SrcSurface2 : + PSDL_Surface; SrcRect2 : PSDL_Rect; Left1, Top1, Left2, Top2 : integer ) : Boolean; + +function SDL_GetPixel( SrcSurface : PSDL_Surface; x : integer; y : integer ) : Uint32; + +procedure SDL_PutPixel( DstSurface : PSDL_Surface; x : integer; y : integer; pixel : + Uint32 ); + +procedure SDL_AddPixel( DstSurface : PSDL_Surface; x : cardinal; y : cardinal; Color : + cardinal ); + +procedure SDL_SubPixel( DstSurface : PSDL_Surface; x : cardinal; y : cardinal; Color : + cardinal ); + +// Line procedures +procedure SDL_DrawLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); overload; + +procedure SDL_DrawLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal; DashLength, DashSpace : byte ); overload; + +procedure SDL_AddLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); + +procedure SDL_SubLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); + +// Surface procedures +procedure SDL_AddSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + +procedure SDL_SubSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + +procedure SDL_MonoSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect; Color : cardinal ); + +procedure SDL_TexturedSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect; Texture : PSDL_Surface; + TextureRect : PSDL_Rect ); + +procedure SDL_ZoomSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; DstSurface : PSDL_Surface; DstRect : PSDL_Rect ); + +procedure SDL_WarpSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; DstSurface : PSDL_Surface; UL, UR, LR, LL : PPoint ); + +// Flip procedures +procedure SDL_FlipRectH( DstSurface : PSDL_Surface; Rect : PSDL_Rect ); + +procedure SDL_FlipRectV( DstSurface : PSDL_Surface; Rect : PSDL_Rect ); + +function PSDLRect( aLeft, aTop, aWidth, aHeight : integer ) : PSDL_Rect; + +function SDLRect( aLeft, aTop, aWidth, aHeight : integer ) : TSDL_Rect; overload; + +function SDLRect( aRect : TRect ) : TSDL_Rect; overload; + +function SDL_ScaleSurfaceRect( SrcSurface : PSDL_Surface; SrcX1, SrcY1, SrcW, SrcH, + Width, Height : integer ) : PSDL_Surface; + +procedure SDL_ScrollY( DstSurface : PSDL_Surface; DifY : integer ); + +procedure SDL_ScrollX( DstSurface : PSDL_Surface; DifX : integer ); + +procedure SDL_RotateDeg( DstSurface, SrcSurface : PSDL_Surface; SrcRect : + PSDL_Rect; DestX, DestY, OffsetX, OffsetY : Integer; Angle : Integer ); + +procedure SDL_RotateRad( DstSurface, SrcSurface : PSDL_Surface; SrcRect : + PSDL_Rect; DestX, DestY, OffsetX, OffsetY : Integer; Angle : Single ); + +function ValidateSurfaceRect( DstSurface : PSDL_Surface; dstrect : PSDL_Rect ) : TSDL_Rect; + +// Fill Rect routine +procedure SDL_FillRectAdd( DstSurface : PSDL_Surface; dstrect : PSDL_Rect; color : UInt32 ); + +procedure SDL_FillRectSub( DstSurface : PSDL_Surface; dstrect : PSDL_Rect; color : UInt32 ); + +procedure SDL_GradientFillRect( DstSurface : PSDL_Surface; const Rect : PSDL_Rect; const StartColor, EndColor : TSDL_Color; const Style : TGradientStyle ); + +// NOTE for All SDL_2xblit... function : the dest surface must be 2x of the source surface! +procedure SDL_2xBlit( Src, Dest : PSDL_Surface ); + +procedure SDL_Scanline2xBlit( Src, Dest : PSDL_Surface ); + +procedure SDL_50Scanline2xBlit( Src, Dest : PSDL_Surface ); + +// +function SDL_PixelTestSurfaceVsRect( SrcSurface1 : PSDL_Surface; SrcRect1 : + PSDL_Rect; SrcRect2 : PSDL_Rect; Left1, Top1, Left2, Top2 : integer ) : + boolean; + +// Jason's boolean Surface functions +procedure SDL_ORSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + +procedure SDL_ANDSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + + +procedure SDL_GTSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + +procedure SDL_LTSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); + +function SDL_ClipLine( var x1, y1, x2, y2 : Integer; ClipRect : PSDL_Rect ) : boolean; + +implementation + +uses + Math; + +function SDL_PixelTest( SrcSurface1 : PSDL_Surface; SrcRect1 : PSDL_Rect; SrcSurface2 : + PSDL_Surface; SrcRect2 : PSDL_Rect; Left1, Top1, Left2, Top2 : integer ) : boolean; +var + Src_Rect1, Src_Rect2 : TSDL_Rect; + right1, bottom1 : integer; + right2, bottom2 : integer; + Scan1Start, Scan2Start, ScanWidth, ScanHeight : cardinal; + Mod1, Mod2 : cardinal; + Addr1, Addr2 : cardinal; + BPP : cardinal; + Pitch1, Pitch2 : cardinal; + TransparentColor1, TransparentColor2 : cardinal; + tx, ty : cardinal; + StartTick : cardinal; + Color1, Color2 : cardinal; +begin + Result := false; + if SrcRect1 = nil then + begin + with Src_Rect1 do + begin + x := 0; + y := 0; + w := SrcSurface1.w; + h := SrcSurface1.h; + end; + end + else + Src_Rect1 := SrcRect1^; + if SrcRect2 = nil then + begin + with Src_Rect2 do + begin + x := 0; + y := 0; + w := SrcSurface2.w; + h := SrcSurface2.h; + end; + end + else + Src_Rect2 := SrcRect2^; + with Src_Rect1 do + begin + Right1 := Left1 + w; + Bottom1 := Top1 + h; + end; + with Src_Rect2 do + begin + Right2 := Left2 + w; + Bottom2 := Top2 + h; + end; + if ( Left1 >= Right2 ) or ( Right1 <= Left2 ) or ( Top1 >= Bottom2 ) or ( Bottom1 <= + Top2 ) then + exit; + if Left1 <= Left2 then + begin + // 1. left, 2. right + Scan1Start := Src_Rect1.x + Left2 - Left1; + Scan2Start := Src_Rect2.x; + ScanWidth := Right1 - Left2; + with Src_Rect2 do + if ScanWidth > w then + ScanWidth := w; + end + else + begin + // 1. right, 2. left + Scan1Start := Src_Rect1.x; + Scan2Start := Src_Rect2.x + Left1 - Left2; + ScanWidth := Right2 - Left1; + with Src_Rect1 do + if ScanWidth > w then + ScanWidth := w; + end; + with SrcSurface1^ do + begin + Pitch1 := Pitch; + Addr1 := cardinal( Pixels ); + inc( Addr1, Pitch1 * UInt32( Src_Rect1.y ) ); + with format^ do + begin + BPP := BytesPerPixel; + TransparentColor1 := colorkey; + end; + end; + with SrcSurface2^ do + begin + TransparentColor2 := format.colorkey; + Pitch2 := Pitch; + Addr2 := cardinal( Pixels ); + inc( Addr2, Pitch2 * UInt32( Src_Rect2.y ) ); + end; + Mod1 := Pitch1 - ( ScanWidth * BPP ); + Mod2 := Pitch2 - ( ScanWidth * BPP ); + inc( Addr1, BPP * Scan1Start ); + inc( Addr2, BPP * Scan2Start ); + if Top1 <= Top2 then + begin + // 1. up, 2. down + ScanHeight := Bottom1 - Top2; + if ScanHeight > Src_Rect2.h then + ScanHeight := Src_Rect2.h; + inc( Addr1, Pitch1 * UInt32( Top2 - Top1 ) ); + end + else + begin + // 1. down, 2. up + ScanHeight := Bottom2 - Top1; + if ScanHeight > Src_Rect1.h then + ScanHeight := Src_Rect1.h; + inc( Addr2, Pitch2 * UInt32( Top1 - Top2 ) ); + end; + case BPP of + 1 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PByte( Addr1 )^ <> TransparentColor1 ) and ( PByte( Addr2 )^ <> + TransparentColor2 ) then + begin + Result := true; + exit; + end; + inc( Addr1 ); + inc( Addr2 ); + end; + inc( Addr1, Mod1 ); + inc( Addr2, Mod2 ); + end; + 2 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PWord( Addr1 )^ <> TransparentColor1 ) and ( PWord( Addr2 )^ <> + TransparentColor2 ) then + begin + Result := true; + exit; + end; + inc( Addr1, 2 ); + inc( Addr2, 2 ); + end; + inc( Addr1, Mod1 ); + inc( Addr2, Mod2 ); + end; + 3 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + Color1 := PLongWord( Addr1 )^ and $00FFFFFF; + Color2 := PLongWord( Addr2 )^ and $00FFFFFF; + if ( Color1 <> TransparentColor1 ) and ( Color2 <> TransparentColor2 ) + then + begin + Result := true; + exit; + end; + inc( Addr1, 3 ); + inc( Addr2, 3 ); + end; + inc( Addr1, Mod1 ); + inc( Addr2, Mod2 ); + end; + 4 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PLongWord( Addr1 )^ <> TransparentColor1 ) and ( PLongWord( Addr2 )^ <> + TransparentColor2 ) then + begin + Result := true; + exit; + end; + inc( Addr1, 4 ); + inc( Addr2, 4 ); + end; + inc( Addr1, Mod1 ); + inc( Addr2, Mod2 ); + end; + end; +end; + +procedure SDL_AddPixel( DstSurface : PSDL_Surface; x : cardinal; y : cardinal; Color : + cardinal ); +var + SrcColor : cardinal; + Addr : cardinal; + R, G, B : cardinal; +begin + if Color = 0 then + exit; + with DstSurface^ do + begin + Addr := cardinal( Pixels ) + y * Pitch + x * format.BytesPerPixel; + SrcColor := PUInt32( Addr )^; + case format.BitsPerPixel of + 8 : + begin + R := SrcColor and $E0 + Color and $E0; + G := SrcColor and $1C + Color and $1C; + B := SrcColor and $03 + Color and $03; + if R > $E0 then + R := $E0; + if G > $1C then + G := $1C; + if B > $03 then + B := $03; + PUInt8( Addr )^ := R or G or B; + end; + 15 : + begin + R := SrcColor and $7C00 + Color and $7C00; + G := SrcColor and $03E0 + Color and $03E0; + B := SrcColor and $001F + Color and $001F; + if R > $7C00 then + R := $7C00; + if G > $03E0 then + G := $03E0; + if B > $001F then + B := $001F; + PUInt16( Addr )^ := R or G or B; + end; + 16 : + begin + R := SrcColor and $F800 + Color and $F800; + G := SrcColor and $07C0 + Color and $07C0; + B := SrcColor and $001F + Color and $001F; + if R > $F800 then + R := $F800; + if G > $07C0 then + G := $07C0; + if B > $001F then + B := $001F; + PUInt16( Addr )^ := R or G or B; + end; + 24 : + begin + R := SrcColor and $00FF0000 + Color and $00FF0000; + G := SrcColor and $0000FF00 + Color and $0000FF00; + B := SrcColor and $000000FF + Color and $000000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( Addr )^ := SrcColor and $FF000000 or R or G or B; + end; + 32 : + begin + R := SrcColor and $00FF0000 + Color and $00FF0000; + G := SrcColor and $0000FF00 + Color and $0000FF00; + B := SrcColor and $000000FF + Color and $000000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( Addr )^ := R or G or B; + end; + end; + end; +end; + +procedure SDL_SubPixel( DstSurface : PSDL_Surface; x : cardinal; y : cardinal; Color : + cardinal ); +var + SrcColor : cardinal; + Addr : cardinal; + R, G, B : cardinal; +begin + if Color = 0 then + exit; + with DstSurface^ do + begin + Addr := cardinal( Pixels ) + y * Pitch + x * format.BytesPerPixel; + SrcColor := PUInt32( Addr )^; + case format.BitsPerPixel of + 8 : + begin + R := SrcColor and $E0 - Color and $E0; + G := SrcColor and $1C - Color and $1C; + B := SrcColor and $03 - Color and $03; + if R > $E0 then + R := 0; + if G > $1C then + G := 0; + if B > $03 then + B := 0; + PUInt8( Addr )^ := R or G or B; + end; + 15 : + begin + R := SrcColor and $7C00 - Color and $7C00; + G := SrcColor and $03E0 - Color and $03E0; + B := SrcColor and $001F - Color and $001F; + if R > $7C00 then + R := 0; + if G > $03E0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( Addr )^ := R or G or B; + end; + 16 : + begin + R := SrcColor and $F800 - Color and $F800; + G := SrcColor and $07C0 - Color and $07C0; + B := SrcColor and $001F - Color and $001F; + if R > $F800 then + R := 0; + if G > $07C0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( Addr )^ := R or G or B; + end; + 24 : + begin + R := SrcColor and $00FF0000 - Color and $00FF0000; + G := SrcColor and $0000FF00 - Color and $0000FF00; + B := SrcColor and $000000FF - Color and $000000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( Addr )^ := SrcColor and $FF000000 or R or G or B; + end; + 32 : + begin + R := SrcColor and $00FF0000 - Color and $00FF0000; + G := SrcColor and $0000FF00 - Color and $0000FF00; + B := SrcColor and $000000FF - Color and $000000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( Addr )^ := R or G or B; + end; + end; + end; +end; +// This procedure works on 8, 15, 16, 24 and 32 bits color depth surfaces. +// In 8 bit color depth mode the procedure works with the default packed +// palette (RRRGGGBB). It handles all clipping. + +procedure SDL_AddSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel1 and $E0 + Pixel2 and $E0; + G := Pixel1 and $1C + Pixel2 and $1C; + B := Pixel1 and $03 + Pixel2 and $03; + if R > $E0 then + R := $E0; + if G > $1C then + G := $1C; + if B > $03 then + B := $03; + PUInt8( DestAddr )^ := R or G or B; + end + else + PUInt8( DestAddr )^ := Pixel1; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel1 and $7C00 + Pixel2 and $7C00; + G := Pixel1 and $03E0 + Pixel2 and $03E0; + B := Pixel1 and $001F + Pixel2 and $001F; + if R > $7C00 then + R := $7C00; + if G > $03E0 then + G := $03E0; + if B > $001F then + B := $001F; + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel1 and $F800 + Pixel2 and $F800; + G := Pixel1 and $07E0 + Pixel2 and $07E0; + B := Pixel1 and $001F + Pixel2 and $001F; + if R > $F800 then + R := $F800; + if G > $07E0 then + G := $07E0; + if B > $001F then + B := $001F; + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + if Pixel2 > 0 then + begin + R := Pixel1 and $FF0000 + Pixel2 and $FF0000; + G := Pixel1 and $00FF00 + Pixel2 and $00FF00; + B := Pixel1 and $0000FF + Pixel2 and $0000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or ( R or G or B ); + end + else + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or Pixel1; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel1 and $FF0000 + Pixel2 and $FF0000; + G := Pixel1 and $00FF00 + Pixel2 and $00FF00; + B := Pixel1 and $0000FF + Pixel2 and $0000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( DestAddr )^ := R or G or B; + end + else + PUInt32( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + +procedure SDL_SubSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + _ebx, _esi, _edi, _esp : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := DestSurface.Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel2 and $E0 - Pixel1 and $E0; + G := Pixel2 and $1C - Pixel1 and $1C; + B := Pixel2 and $03 - Pixel1 and $03; + if R > $E0 then + R := 0; + if G > $1C then + G := 0; + if B > $03 then + B := 0; + PUInt8( DestAddr )^ := R or G or B; + end; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel2 and $7C00 - Pixel1 and $7C00; + G := Pixel2 and $03E0 - Pixel1 and $03E0; + B := Pixel2 and $001F - Pixel1 and $001F; + if R > $7C00 then + R := 0; + if G > $03E0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( DestAddr )^ := R or G or B; + end; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel2 and $F800 - Pixel1 and $F800; + G := Pixel2 and $07E0 - Pixel1 and $07E0; + B := Pixel2 and $001F - Pixel1 and $001F; + if R > $F800 then + R := 0; + if G > $07E0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( DestAddr )^ := R or G or B; + end; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + if Pixel2 > 0 then + begin + R := Pixel2 and $FF0000 - Pixel1 and $FF0000; + G := Pixel2 and $00FF00 - Pixel1 and $00FF00; + B := Pixel2 and $0000FF - Pixel1 and $0000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or ( R or G or B ); + end; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + if Pixel2 > 0 then + begin + R := Pixel2 and $FF0000 - Pixel1 and $FF0000; + G := Pixel2 and $00FF00 - Pixel1 and $00FF00; + B := Pixel2 and $0000FF - Pixel1 and $0000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( DestAddr )^ := R or G or B; + end + else + PUInt32( DestAddr )^ := Pixel2; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + +procedure SDL_MonoSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect; Color : cardinal ); +var + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + _ebx, _esi, _edi, _esp : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + TransparentColor, SrcColor : cardinal; + BPP : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + BPP := DestSurface.Format.BytesPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case BPP of + 1 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt8( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt8( DestAddr )^ := SrcColor; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 2 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt16( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt16( DestAddr )^ := SrcColor; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 3 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt32( SrcAddr )^ and $FFFFFF; + if SrcColor <> TransparentColor then + PUInt32( DestAddr )^ := ( PUInt32( DestAddr )^ and $FFFFFF ) or SrcColor; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 4 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt32( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt32( DestAddr )^ := SrcColor; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; +// TextureRect.w and TextureRect.h are not used. +// The TextureSurface's size MUST larger than the drawing rectangle!!! + +procedure SDL_TexturedSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect; Texture : PSDL_Surface; + TextureRect : PSDL_Rect ); +var + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr, TextAddr : cardinal; + _ebx, _esi, _edi, _esp : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod, TextMod : cardinal; + SrcColor, TransparentColor, TextureColor : cardinal; + BPP : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + BPP := DestSurface.Format.BitsPerPixel; + end; + with Texture^ do + begin + TextAddr := cardinal( Pixels ) + UInt32( TextureRect.y ) * Pitch + + UInt32( TextureRect.x ) * Format.BytesPerPixel; + TextMod := Pitch - Src.w * Format.BytesPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + SDL_LockSurface( Texture ); + WorkY := Src.h; + case BPP of + 1 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt8( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt8( DestAddr )^ := PUint8( TextAddr )^; + inc( SrcAddr ); + inc( DestAddr ); + inc( TextAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + inc( TextAddr, TextMod ); + dec( WorkY ); + until WorkY = 0; + end; + 2 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt16( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt16( DestAddr )^ := PUInt16( TextAddr )^; + inc( SrcAddr ); + inc( DestAddr ); + inc( TextAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + inc( TextAddr, TextMod ); + dec( WorkY ); + until WorkY = 0; + end; + 3 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt32( SrcAddr )^ and $FFFFFF; + if SrcColor <> TransparentColor then + PUInt32( DestAddr )^ := ( PUInt32( DestAddr )^ and $FFFFFF ) or ( PUInt32( TextAddr )^ and $FFFFFF ); + inc( SrcAddr ); + inc( DestAddr ); + inc( TextAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + inc( TextAddr, TextMod ); + dec( WorkY ); + until WorkY = 0; + end; + 4 : + begin + repeat + WorkX := Src.w; + repeat + SrcColor := PUInt32( SrcAddr )^; + if SrcColor <> TransparentColor then + PUInt32( DestAddr )^ := PUInt32( TextAddr )^; + inc( SrcAddr ); + inc( DestAddr ); + inc( TextAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + inc( TextAddr, TextMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); + SDL_UnlockSurface( Texture ); +end; + +procedure SDL_ZoomSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; DstSurface : PSDL_Surface; DstRect : PSDL_Rect ); +var + xc, yc : cardinal; + rx, wx, ry, wy, ry16 : cardinal; + color : cardinal; + modx, mody : cardinal; +begin + // Warning! No checks for surface pointers!!! + if srcrect = nil then + srcrect := @SrcSurface.clip_rect; + if dstrect = nil then + dstrect := @DstSurface.clip_rect; + if SDL_MustLock( SrcSurface ) then + SDL_LockSurface( SrcSurface ); + if SDL_MustLock( DstSurface ) then + SDL_LockSurface( DstSurface ); + modx := trunc( ( srcrect.w / dstrect.w ) * 65536 ); + mody := trunc( ( srcrect.h / dstrect.h ) * 65536 ); + //rx := srcrect.x * 65536; + ry := srcrect.y * 65536; + wy := dstrect.y; + for yc := 0 to dstrect.h - 1 do + begin + rx := srcrect.x * 65536; + wx := dstrect.x; + ry16 := ry shr 16; + for xc := 0 to dstrect.w - 1 do + begin + color := SDL_GetPixel( SrcSurface, rx shr 16, ry16 ); + SDL_PutPixel( DstSurface, wx, wy, color ); + rx := rx + modx; + inc( wx ); + end; + ry := ry + mody; + inc( wy ); + end; + if SDL_MustLock( SrcSurface ) then + SDL_UnlockSurface( SrcSurface ); + if SDL_MustLock( DstSurface ) then + SDL_UnlockSurface( DstSurface ); +end; +// Re-map a rectangular area into an area defined by four vertices +// Converted from C to Pascal by KiCHY + +procedure SDL_WarpSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; DstSurface : PSDL_Surface; UL, UR, LR, LL : PPoint ); +const + SHIFTS = 15; // Extend ints to limit round-off error (try 2 - 20) + THRESH = 1 shl SHIFTS; // Threshold for pixel size value + procedure CopySourceToDest( UL, UR, LR, LL : TPoint; x1, y1, x2, y2 : cardinal ); + var + tm, lm, rm, bm, m : TPoint; + mx, my : cardinal; + cr : cardinal; + begin + // Does the destination area specify a single pixel? + if ( ( abs( ul.x - ur.x ) < THRESH ) and + ( abs( ul.x - lr.x ) < THRESH ) and + ( abs( ul.x - ll.x ) < THRESH ) and + ( abs( ul.y - ur.y ) < THRESH ) and + ( abs( ul.y - lr.y ) < THRESH ) and + ( abs( ul.y - ll.y ) < THRESH ) ) then + begin // Yes + cr := SDL_GetPixel( SrcSurface, ( x1 shr SHIFTS ), ( y1 shr SHIFTS ) ); + SDL_PutPixel( DstSurface, ( ul.x shr SHIFTS ), ( ul.y shr SHIFTS ), cr ); + end + else + begin // No + // Quarter the source and the destination, and then recurse + tm.x := ( ul.x + ur.x ) shr 1; + tm.y := ( ul.y + ur.y ) shr 1; + bm.x := ( ll.x + lr.x ) shr 1; + bm.y := ( ll.y + lr.y ) shr 1; + lm.x := ( ul.x + ll.x ) shr 1; + lm.y := ( ul.y + ll.y ) shr 1; + rm.x := ( ur.x + lr.x ) shr 1; + rm.y := ( ur.y + lr.y ) shr 1; + m.x := ( tm.x + bm.x ) shr 1; + m.y := ( tm.y + bm.y ) shr 1; + mx := ( x1 + x2 ) shr 1; + my := ( y1 + y2 ) shr 1; + CopySourceToDest( ul, tm, m, lm, x1, y1, mx, my ); + CopySourceToDest( tm, ur, rm, m, mx, y1, x2, my ); + CopySourceToDest( m, rm, lr, bm, mx, my, x2, y2 ); + CopySourceToDest( lm, m, bm, ll, x1, my, mx, y2 ); + end; + end; +var + _UL, _UR, _LR, _LL : TPoint; + Rect_x, Rect_y, Rect_w, Rect_h : integer; +begin + if SDL_MustLock( SrcSurface ) then + SDL_LockSurface( SrcSurface ); + if SDL_MustLock( DstSurface ) then + SDL_LockSurface( DstSurface ); + if SrcRect = nil then + begin + Rect_x := 0; + Rect_y := 0; + Rect_w := ( SrcSurface.w - 1 ) shl SHIFTS; + Rect_h := ( SrcSurface.h - 1 ) shl SHIFTS; + end + else + begin + Rect_x := SrcRect.x; + Rect_y := SrcRect.y; + Rect_w := ( SrcRect.w - 1 ) shl SHIFTS; + Rect_h := ( SrcRect.h - 1 ) shl SHIFTS; + end; + // Shift all values to help reduce round-off error. + _ul.x := ul.x shl SHIFTS; + _ul.y := ul.y shl SHIFTS; + _ur.x := ur.x shl SHIFTS; + _ur.y := ur.y shl SHIFTS; + _lr.x := lr.x shl SHIFTS; + _lr.y := lr.y shl SHIFTS; + _ll.x := ll.x shl SHIFTS; + _ll.y := ll.y shl SHIFTS; + CopySourceToDest( _ul, _ur, _lr, _ll, Rect_x, Rect_y, Rect_w, Rect_h ); + if SDL_MustLock( SrcSurface ) then + SDL_UnlockSurface( SrcSurface ); + if SDL_MustLock( DstSurface ) then + SDL_UnlockSurface( DstSurface ); +end; + +// Draw a line between x1,y1 and x2,y2 to the given surface +// NOTE: The surface must be locked before calling this! + +procedure SDL_DrawLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); +var + dx, dy, sdx, sdy, x, y, px, py : integer; +begin + dx := x2 - x1; + dy := y2 - y1; + if dx < 0 then + sdx := -1 + else + sdx := 1; + if dy < 0 then + sdy := -1 + else + sdy := 1; + dx := sdx * dx + 1; + dy := sdy * dy + 1; + x := 0; + y := 0; + px := x1; + py := y1; + if dx >= dy then + begin + for x := 0 to dx - 1 do + begin + SDL_PutPixel( DstSurface, px, py, Color ); + y := y + dy; + if y >= dx then + begin + y := y - dx; + py := py + sdy; + end; + px := px + sdx; + end; + end + else + begin + for y := 0 to dy - 1 do + begin + SDL_PutPixel( DstSurface, px, py, Color ); + x := x + dx; + if x >= dy then + begin + x := x - dy; + px := px + sdx; + end; + py := py + sdy; + end; + end; +end; + +// Draw a dashed line between x1,y1 and x2,y2 to the given surface +// NOTE: The surface must be locked before calling this! + +procedure SDL_DrawLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal; DashLength, DashSpace : byte ); overload; +var + dx, dy, sdx, sdy, x, y, px, py, counter : integer; drawdash : boolean; +begin + counter := 0; + drawdash := true; //begin line drawing with dash + + //Avoid invalid user-passed dash parameters + if ( DashLength < 1 ) + then + DashLength := 1; + if ( DashSpace < 1 ) + then + DashSpace := 0; + + dx := x2 - x1; + dy := y2 - y1; + if dx < 0 then + sdx := -1 + else + sdx := 1; + if dy < 0 then + sdy := -1 + else + sdy := 1; + dx := sdx * dx + 1; + dy := sdy * dy + 1; + x := 0; + y := 0; + px := x1; + py := y1; + if dx >= dy then + begin + for x := 0 to dx - 1 do + begin + + //Alternate drawing dashes, or leaving spaces + if drawdash then + begin + SDL_PutPixel( DstSurface, px, py, Color ); + inc( counter ); + if ( counter > DashLength - 1 ) and ( DashSpace > 0 ) then + begin + drawdash := false; + counter := 0; + end; + end + else //space + begin + inc( counter ); + if counter > DashSpace - 1 then + begin + drawdash := true; + counter := 0; + end; + end; + + y := y + dy; + if y >= dx then + begin + y := y - dx; + py := py + sdy; + end; + px := px + sdx; + end; + end + else + begin + for y := 0 to dy - 1 do + begin + + //Alternate drawing dashes, or leaving spaces + if drawdash then + begin + SDL_PutPixel( DstSurface, px, py, Color ); + inc( counter ); + if ( counter > DashLength - 1 ) and ( DashSpace > 0 ) then + begin + drawdash := false; + counter := 0; + end; + end + else //space + begin + inc( counter ); + if counter > DashSpace - 1 then + begin + drawdash := true; + counter := 0; + end; + end; + + x := x + dx; + if x >= dy then + begin + x := x - dy; + px := px + sdx; + end; + py := py + sdy; + end; + end; +end; + +procedure SDL_AddLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); +var + dx, dy, sdx, sdy, x, y, px, py : integer; +begin + dx := x2 - x1; + dy := y2 - y1; + if dx < 0 then + sdx := -1 + else + sdx := 1; + if dy < 0 then + sdy := -1 + else + sdy := 1; + dx := sdx * dx + 1; + dy := sdy * dy + 1; + x := 0; + y := 0; + px := x1; + py := y1; + if dx >= dy then + begin + for x := 0 to dx - 1 do + begin + SDL_AddPixel( DstSurface, px, py, Color ); + y := y + dy; + if y >= dx then + begin + y := y - dx; + py := py + sdy; + end; + px := px + sdx; + end; + end + else + begin + for y := 0 to dy - 1 do + begin + SDL_AddPixel( DstSurface, px, py, Color ); + x := x + dx; + if x >= dy then + begin + x := x - dy; + px := px + sdx; + end; + py := py + sdy; + end; + end; +end; + +procedure SDL_SubLine( DstSurface : PSDL_Surface; x1, y1, x2, y2 : integer; Color : + cardinal ); +var + dx, dy, sdx, sdy, x, y, px, py : integer; +begin + dx := x2 - x1; + dy := y2 - y1; + if dx < 0 then + sdx := -1 + else + sdx := 1; + if dy < 0 then + sdy := -1 + else + sdy := 1; + dx := sdx * dx + 1; + dy := sdy * dy + 1; + x := 0; + y := 0; + px := x1; + py := y1; + if dx >= dy then + begin + for x := 0 to dx - 1 do + begin + SDL_SubPixel( DstSurface, px, py, Color ); + y := y + dy; + if y >= dx then + begin + y := y - dx; + py := py + sdy; + end; + px := px + sdx; + end; + end + else + begin + for y := 0 to dy - 1 do + begin + SDL_SubPixel( DstSurface, px, py, Color ); + x := x + dx; + if x >= dy then + begin + x := x - dy; + px := px + sdx; + end; + py := py + sdy; + end; + end; +end; + +// flips a rectangle vertically on given surface + +procedure SDL_FlipRectV( DstSurface : PSDL_Surface; Rect : PSDL_Rect ); +var + TmpRect : TSDL_Rect; + Locked : boolean; + y, FlipLength, RowLength : integer; + Row1, Row2 : Pointer; + OneRow : TByteArray; // Optimize it if you wish +begin + if DstSurface <> nil then + begin + if Rect = nil then + begin // if Rect=nil then we flip the whole surface + TmpRect := SDLRect( 0, 0, DstSurface.w, DstSurface.h ); + Rect := @TmpRect; + end; + FlipLength := Rect^.h shr 1 - 1; + RowLength := Rect^.w * DstSurface^.format.BytesPerPixel; + if SDL_MustLock( DstSurface ) then + begin + Locked := true; + SDL_LockSurface( DstSurface ); + end + else + Locked := false; + Row1 := pointer( cardinal( DstSurface^.Pixels ) + UInt32( Rect^.y ) * + DstSurface^.Pitch ); + Row2 := pointer( cardinal( DstSurface^.Pixels ) + ( UInt32( Rect^.y ) + Rect^.h - 1 ) + * DstSurface^.Pitch ); + for y := 0 to FlipLength do + begin + Move( Row1^, OneRow, RowLength ); + Move( Row2^, Row1^, RowLength ); + Move( OneRow, Row2^, RowLength ); + inc( cardinal( Row1 ), DstSurface^.Pitch ); + dec( cardinal( Row2 ), DstSurface^.Pitch ); + end; + if Locked then + SDL_UnlockSurface( DstSurface ); + end; +end; + +// flips a rectangle horizontally on given surface + +procedure SDL_FlipRectH( DstSurface : PSDL_Surface; Rect : PSDL_Rect ); +type + T24bit = packed array[ 0..2 ] of byte; + T24bitArray = packed array[ 0..8191 ] of T24bit; + P24bitArray = ^T24bitArray; + TLongWordArray = array[ 0..8191 ] of LongWord; + PLongWordArray = ^TLongWordArray; +var + TmpRect : TSDL_Rect; + Row8bit : PByteArray; + Row16bit : PWordArray; + Row24bit : P24bitArray; + Row32bit : PLongWordArray; + y, x, RightSide, FlipLength : integer; + Pixel : cardinal; + Pixel24 : T24bit; + Locked : boolean; +begin + if DstSurface <> nil then + begin + if Rect = nil then + begin + TmpRect := SDLRect( 0, 0, DstSurface.w, DstSurface.h ); + Rect := @TmpRect; + end; + FlipLength := Rect^.w shr 1 - 1; + if SDL_MustLock( DstSurface ) then + begin + Locked := true; + SDL_LockSurface( DstSurface ); + end + else + Locked := false; + case DstSurface^.format.BytesPerPixel of + 1 : + begin + Row8Bit := pointer( cardinal( DstSurface^.pixels ) + UInt32( Rect^.y ) * + DstSurface^.pitch ); + for y := 1 to Rect^.h do + begin + RightSide := Rect^.w - 1; + for x := 0 to FlipLength do + begin + Pixel := Row8Bit^[ x ]; + Row8Bit^[ x ] := Row8Bit^[ RightSide ]; + Row8Bit^[ RightSide ] := Pixel; + dec( RightSide ); + end; + inc( cardinal( Row8Bit ), DstSurface^.pitch ); + end; + end; + 2 : + begin + Row16Bit := pointer( cardinal( DstSurface^.pixels ) + UInt32( Rect^.y ) * + DstSurface^.pitch ); + for y := 1 to Rect^.h do + begin + RightSide := Rect^.w - 1; + for x := 0 to FlipLength do + begin + Pixel := Row16Bit^[ x ]; + Row16Bit^[ x ] := Row16Bit^[ RightSide ]; + Row16Bit^[ RightSide ] := Pixel; + dec( RightSide ); + end; + inc( cardinal( Row16Bit ), DstSurface^.pitch ); + end; + end; + 3 : + begin + Row24Bit := pointer( cardinal( DstSurface^.pixels ) + UInt32( Rect^.y ) * + DstSurface^.pitch ); + for y := 1 to Rect^.h do + begin + RightSide := Rect^.w - 1; + for x := 0 to FlipLength do + begin + Pixel24 := Row24Bit^[ x ]; + Row24Bit^[ x ] := Row24Bit^[ RightSide ]; + Row24Bit^[ RightSide ] := Pixel24; + dec( RightSide ); + end; + inc( cardinal( Row24Bit ), DstSurface^.pitch ); + end; + end; + 4 : + begin + Row32Bit := pointer( cardinal( DstSurface^.pixels ) + UInt32( Rect^.y ) * + DstSurface^.pitch ); + for y := 1 to Rect^.h do + begin + RightSide := Rect^.w - 1; + for x := 0 to FlipLength do + begin + Pixel := Row32Bit^[ x ]; + Row32Bit^[ x ] := Row32Bit^[ RightSide ]; + Row32Bit^[ RightSide ] := Pixel; + dec( RightSide ); + end; + inc( cardinal( Row32Bit ), DstSurface^.pitch ); + end; + end; + end; + if Locked then + SDL_UnlockSurface( DstSurface ); + end; +end; + +// Use with caution! The procedure allocates memory for TSDL_Rect and return with its pointer. +// But you MUST free it after you don't need it anymore!!! + +function PSDLRect( aLeft, aTop, aWidth, aHeight : integer ) : PSDL_Rect; +var + Rect : PSDL_Rect; +begin + New( Rect ); + with Rect^ do + begin + x := aLeft; + y := aTop; + w := aWidth; + h := aHeight; + end; + Result := Rect; +end; + +function SDLRect( aLeft, aTop, aWidth, aHeight : integer ) : TSDL_Rect; +begin + with result do + begin + x := aLeft; + y := aTop; + w := aWidth; + h := aHeight; + end; +end; + +function SDLRect( aRect : TRect ) : TSDL_Rect; +begin + with aRect do + result := SDLRect( Left, Top, Right - Left, Bottom - Top ); +end; + +procedure SDL_Stretch8( Surface, Dst_Surface : PSDL_Surface; x1, x2, y1, y2, yr, yw, + depth : integer ); +var + dx, dy, e, d, dx2 : integer; + src_pitch, dst_pitch : uint16; + src_pixels, dst_pixels : PUint8; +begin + if ( yw >= dst_surface^.h ) then + exit; + dx := ( x2 - x1 ); + dy := ( y2 - y1 ); + dy := dy shl 1; + e := dy - dx; + dx2 := dx shl 1; + src_pitch := Surface^.pitch; + dst_pitch := dst_surface^.pitch; + src_pixels := PUint8( integer( Surface^.pixels ) + yr * src_pitch + y1 * depth ); + dst_pixels := PUint8( integer( dst_surface^.pixels ) + yw * dst_pitch + x1 * + depth ); + for d := 0 to dx - 1 do + begin + move( src_pixels^, dst_pixels^, depth ); + while ( e >= 0 ) do + begin + inc( src_pixels, depth ); + e := e - dx2; + end; + inc( dst_pixels, depth ); + e := e + dy; + end; +end; + +function sign( x : integer ) : integer; +begin + if x > 0 then + result := 1 + else + result := -1; +end; + +// Stretches a part of a surface + +function SDL_ScaleSurfaceRect( SrcSurface : PSDL_Surface; SrcX1, SrcY1, SrcW, SrcH, + Width, Height : integer ) : PSDL_Surface; +var + dst_surface : PSDL_Surface; + dx, dy, e, d, dx2, srcx2, srcy2 : integer; + destx1, desty1 : integer; +begin + srcx2 := srcx1 + SrcW; + srcy2 := srcy1 + SrcH; + result := nil; + destx1 := 0; + desty1 := 0; + dx := abs( integer( Height - desty1 ) ); + dy := abs( integer( SrcY2 - SrcY1 ) ); + e := ( dy shl 1 ) - dx; + dx2 := dx shl 1; + dy := dy shl 1; + dst_surface := SDL_CreateRGBSurface( SDL_HWPALETTE, width - destx1, Height - + desty1, + SrcSurface^.Format^.BitsPerPixel, + SrcSurface^.Format^.RMask, + SrcSurface^.Format^.GMask, + SrcSurface^.Format^.BMask, + SrcSurface^.Format^.AMask ); + if ( dst_surface^.format^.BytesPerPixel = 1 ) then + SDL_SetColors( dst_surface, @SrcSurface^.format^.palette^.colors^[ 0 ], 0, 256 ); + SDL_SetColorKey( dst_surface, sdl_srccolorkey, SrcSurface^.format^.colorkey ); + if ( SDL_MustLock( dst_surface ) ) then + if ( SDL_LockSurface( dst_surface ) < 0 ) then + exit; + for d := 0 to dx - 1 do + begin + SDL_Stretch8( SrcSurface, dst_surface, destx1, Width, SrcX1, SrcX2, SrcY1, desty1, + SrcSurface^.format^.BytesPerPixel ); + while e >= 0 do + begin + inc( SrcY1 ); + e := e - dx2; + end; + inc( desty1 ); + e := e + dy; + end; + if SDL_MUSTLOCK( dst_surface ) then + SDL_UnlockSurface( dst_surface ); + result := dst_surface; +end; + +procedure SDL_MoveLine( Surface : PSDL_Surface; x1, x2, y1, xofs, depth : integer ); +var + src_pixels, dst_pixels : PUint8; + i : integer; +begin + src_pixels := PUint8( integer( Surface^.pixels ) + Surface^.w * y1 * depth + x2 * + depth ); + dst_pixels := PUint8( integer( Surface^.pixels ) + Surface^.w * y1 * depth + ( x2 + + xofs ) * depth ); + for i := x2 downto x1 do + begin + move( src_pixels^, dst_pixels^, depth ); + dec( src_pixels ); + dec( dst_pixels ); + end; +end; +{ Return the pixel value at (x, y) +NOTE: The surface must be locked before calling this! } + +function SDL_GetPixel( SrcSurface : PSDL_Surface; x : integer; y : integer ) : Uint32; +var + bpp : UInt32; + p : PInteger; +begin + bpp := SrcSurface.format.BytesPerPixel; + // Here p is the address to the pixel we want to retrieve + p := Pointer( Uint32( SrcSurface.pixels ) + UInt32( y ) * SrcSurface.pitch + UInt32( x ) * + bpp ); + case bpp of + 1 : result := PUint8( p )^; + 2 : result := PUint16( p )^; + 3 : + if ( SDL_BYTEORDER = SDL_BIG_ENDIAN ) then + result := PUInt8Array( p )[ 0 ] shl 16 or PUInt8Array( p )[ 1 ] shl 8 or + PUInt8Array( p )[ 2 ] + else + result := PUInt8Array( p )[ 0 ] or PUInt8Array( p )[ 1 ] shl 8 or + PUInt8Array( p )[ 2 ] shl 16; + 4 : result := PUint32( p )^; + else + result := 0; // shouldn't happen, but avoids warnings + end; +end; +{ Set the pixel at (x, y) to the given value + NOTE: The surface must be locked before calling this! } + +procedure SDL_PutPixel( DstSurface : PSDL_Surface; x : integer; y : integer; pixel : + Uint32 ); +var + bpp : UInt32; + p : PInteger; +begin + bpp := DstSurface.format.BytesPerPixel; + p := Pointer( Uint32( DstSurface.pixels ) + UInt32( y ) * DstSurface.pitch + UInt32( x ) + * bpp ); + case bpp of + 1 : PUint8( p )^ := pixel; + 2 : PUint16( p )^ := pixel; + 3 : + if ( SDL_BYTEORDER = SDL_BIG_ENDIAN ) then + begin + PUInt8Array( p )[ 0 ] := ( pixel shr 16 ) and $FF; + PUInt8Array( p )[ 1 ] := ( pixel shr 8 ) and $FF; + PUInt8Array( p )[ 2 ] := pixel and $FF; + end + else + begin + PUInt8Array( p )[ 0 ] := pixel and $FF; + PUInt8Array( p )[ 1 ] := ( pixel shr 8 ) and $FF; + PUInt8Array( p )[ 2 ] := ( pixel shr 16 ) and $FF; + end; + 4 : + PUint32( p )^ := pixel; + end; +end; + +procedure SDL_ScrollY( DstSurface : PSDL_Surface; DifY : integer ); +var + r1, r2 : TSDL_Rect; + //buffer: PSDL_Surface; + YPos : Integer; +begin + if ( DstSurface <> nil ) and ( DifY <> 0 ) then + begin + //if DifY > 0 then // going up + //begin + ypos := 0; + r1.x := 0; + r2.x := 0; + r1.w := DstSurface.w; + r2.w := DstSurface.w; + r1.h := DifY; + r2.h := DifY; + while ypos < DstSurface.h do + begin + r1.y := ypos; + r2.y := ypos + DifY; + SDL_BlitSurface( DstSurface, @r2, DstSurface, @r1 ); + ypos := ypos + DifY; + end; + //end + //else + //begin // Going Down + //end; + end; +end; + +{procedure SDL_ScrollY(Surface: PSDL_Surface; DifY: integer); +var + r1, r2: TSDL_Rect; + buffer: PSDL_Surface; +begin + if (Surface <> nil) and (Dify <> 0) then + begin + buffer := SDL_CreateRGBSurface(SDL_HWSURFACE, (Surface^.w - DifY) * 2, + Surface^.h * 2, + Surface^.Format^.BitsPerPixel, 0, 0, 0, 0); + if buffer <> nil then + begin + if (buffer^.format^.BytesPerPixel = 1) then + SDL_SetColors(buffer, @Surface^.format^.palette^.colors^[0], 0, 256); + r1 := SDLRect(0, DifY, buffer^.w, buffer^.h); + r2 := SDLRect(0, 0, buffer^.w, buffer^.h); + SDL_BlitSurface(Surface, @r1, buffer, @r2); + SDL_BlitSurface(buffer, @r2, Surface, @r2); + SDL_FreeSurface(buffer); + end; + end; +end;} + +procedure SDL_ScrollX( DstSurface : PSDL_Surface; DifX : integer ); +var + r1, r2 : TSDL_Rect; + buffer : PSDL_Surface; +begin + if ( DstSurface <> nil ) and ( DifX <> 0 ) then + begin + buffer := SDL_CreateRGBSurface( SDL_HWSURFACE, ( DstSurface^.w - DifX ) * 2, + DstSurface^.h * 2, + DstSurface^.Format^.BitsPerPixel, + DstSurface^.Format^.RMask, + DstSurface^.Format^.GMask, + DstSurface^.Format^.BMask, + DstSurface^.Format^.AMask ); + if buffer <> nil then + begin + if ( buffer^.format^.BytesPerPixel = 1 ) then + SDL_SetColors( buffer, @DstSurface^.format^.palette^.colors^[ 0 ], 0, 256 ); + r1 := SDLRect( DifX, 0, buffer^.w, buffer^.h ); + r2 := SDLRect( 0, 0, buffer^.w, buffer^.h ); + SDL_BlitSurface( DstSurface, @r1, buffer, @r2 ); + SDL_BlitSurface( buffer, @r2, DstSurface, @r2 ); + SDL_FreeSurface( buffer ); + end; + end; +end; + +procedure SDL_RotateRad( DstSurface, SrcSurface : PSDL_Surface; SrcRect : + PSDL_Rect; DestX, DestY, OffsetX, OffsetY : Integer; Angle : Single ); +var + aSin, aCos : Single; + MX, MY, DX, DY, NX, NY, SX, SY, OX, OY, Width, Height, TX, TY, RX, RY, ROX, ROY : Integer; + Colour, TempTransparentColour : UInt32; + MAXX, MAXY : Integer; +begin + // Rotate the surface to the target surface. + TempTransparentColour := SrcSurface.format.colorkey; + {if srcRect.w > srcRect.h then + begin + Width := srcRect.w; + Height := srcRect.w; + end + else + begin + Width := srcRect.h; + Height := srcRect.h; + end; } + + maxx := DstSurface.w; + maxy := DstSurface.h; + aCos := cos( Angle ); + aSin := sin( Angle ); + + Width := round( abs( srcrect.h * acos ) + abs( srcrect.w * asin ) ); + Height := round( abs( srcrect.h * asin ) + abs( srcrect.w * acos ) ); + + OX := Width div 2; + OY := Height div 2; ; + MX := ( srcRect.x + ( srcRect.x + srcRect.w ) ) div 2; + MY := ( srcRect.y + ( srcRect.y + srcRect.h ) ) div 2; + ROX := ( -( srcRect.w div 2 ) ) + Offsetx; + ROY := ( -( srcRect.h div 2 ) ) + OffsetY; + Tx := ox + round( ROX * aSin - ROY * aCos ); + Ty := oy + round( ROY * aSin + ROX * aCos ); + SX := 0; + for DX := DestX - TX to DestX - TX + ( width ) do + begin + Inc( SX ); + SY := 0; + for DY := DestY - TY to DestY - TY + ( Height ) do + begin + RX := SX - OX; + RY := SY - OY; + NX := round( mx + RX * aSin + RY * aCos ); // + NY := round( my + RY * aSin - RX * aCos ); // + // Used for testing only + //SDL_PutPixel(DestSurface.SDLSurfacePointer,DX,DY,0); + if ( ( DX > 0 ) and ( DX < MAXX ) ) and ( ( DY > 0 ) and ( DY < MAXY ) ) then + begin + if ( NX >= srcRect.x ) and ( NX <= srcRect.x + srcRect.w ) then + begin + if ( NY >= srcRect.y ) and ( NY <= srcRect.y + srcRect.h ) then + begin + Colour := SDL_GetPixel( SrcSurface, NX, NY ); + if Colour <> TempTransparentColour then + begin + SDL_PutPixel( DstSurface, DX, DY, Colour ); + end; + end; + end; + end; + inc( SY ); + end; + end; +end; + +procedure SDL_RotateDeg( DstSurface, SrcSurface : PSDL_Surface; SrcRect : + PSDL_Rect; DestX, DestY, OffsetX, OffsetY : Integer; Angle : Integer ); +begin + SDL_RotateRad( DstSurface, SrcSurface, SrcRect, DestX, DestY, OffsetX, OffsetY, DegToRad( Angle ) ); +end; + +function ValidateSurfaceRect( DstSurface : PSDL_Surface; dstrect : PSDL_Rect ) : TSDL_Rect; +var + RealRect : TSDL_Rect; + OutOfRange : Boolean; +begin + OutOfRange := false; + if dstrect = nil then + begin + RealRect.x := 0; + RealRect.y := 0; + RealRect.w := DstSurface.w; + RealRect.h := DstSurface.h; + end + else + begin + if dstrect.x < DstSurface.w then + begin + RealRect.x := dstrect.x; + end + else if dstrect.x < 0 then + begin + realrect.x := 0; + end + else + begin + OutOfRange := True; + end; + if dstrect.y < DstSurface.h then + begin + RealRect.y := dstrect.y; + end + else if dstrect.y < 0 then + begin + realrect.y := 0; + end + else + begin + OutOfRange := True; + end; + if OutOfRange = False then + begin + if realrect.x + dstrect.w <= DstSurface.w then + begin + RealRect.w := dstrect.w; + end + else + begin + RealRect.w := dstrect.w - realrect.x; + end; + if realrect.y + dstrect.h <= DstSurface.h then + begin + RealRect.h := dstrect.h; + end + else + begin + RealRect.h := dstrect.h - realrect.y; + end; + end; + end; + if OutOfRange = False then + begin + result := realrect; + end + else + begin + realrect.w := 0; + realrect.h := 0; + realrect.x := 0; + realrect.y := 0; + result := realrect; + end; +end; + +procedure SDL_FillRectAdd( DstSurface : PSDL_Surface; dstrect : PSDL_Rect; color : UInt32 ); +var + RealRect : TSDL_Rect; + Addr : pointer; + ModX, BPP : cardinal; + x, y, R, G, B, SrcColor : cardinal; +begin + RealRect := ValidateSurfaceRect( DstSurface, DstRect ); + if ( RealRect.w > 0 ) and ( RealRect.h > 0 ) then + begin + SDL_LockSurface( DstSurface ); + BPP := DstSurface.format.BytesPerPixel; + with DstSurface^ do + begin + Addr := pointer( UInt32( pixels ) + UInt32( RealRect.y ) * pitch + UInt32( RealRect.x ) * BPP ); + ModX := Pitch - UInt32( RealRect.w ) * BPP; + end; + case DstSurface.format.BitsPerPixel of + 8 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $E0 + Color and $E0; + G := SrcColor and $1C + Color and $1C; + B := SrcColor and $03 + Color and $03; + if R > $E0 then + R := $E0; + if G > $1C then + G := $1C; + if B > $03 then + B := $03; + PUInt8( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 15 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $7C00 + Color and $7C00; + G := SrcColor and $03E0 + Color and $03E0; + B := SrcColor and $001F + Color and $001F; + if R > $7C00 then + R := $7C00; + if G > $03E0 then + G := $03E0; + if B > $001F then + B := $001F; + PUInt16( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 16 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $F800 + Color and $F800; + G := SrcColor and $07C0 + Color and $07C0; + B := SrcColor and $001F + Color and $001F; + if R > $F800 then + R := $F800; + if G > $07C0 then + G := $07C0; + if B > $001F then + B := $001F; + PUInt16( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 24 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $00FF0000 + Color and $00FF0000; + G := SrcColor and $0000FF00 + Color and $0000FF00; + B := SrcColor and $000000FF + Color and $000000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( Addr )^ := SrcColor and $FF000000 or R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 32 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $00FF0000 + Color and $00FF0000; + G := SrcColor and $0000FF00 + Color and $0000FF00; + B := SrcColor and $000000FF + Color and $000000FF; + if R > $FF0000 then + R := $FF0000; + if G > $00FF00 then + G := $00FF00; + if B > $0000FF then + B := $0000FF; + PUInt32( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + end; + SDL_UnlockSurface( DstSurface ); + end; +end; + +procedure SDL_FillRectSub( DstSurface : PSDL_Surface; dstrect : PSDL_Rect; color : UInt32 ); +var + RealRect : TSDL_Rect; + Addr : pointer; + ModX, BPP : cardinal; + x, y, R, G, B, SrcColor : cardinal; +begin + RealRect := ValidateSurfaceRect( DstSurface, DstRect ); + if ( RealRect.w > 0 ) and ( RealRect.h > 0 ) then + begin + SDL_LockSurface( DstSurface ); + BPP := DstSurface.format.BytesPerPixel; + with DstSurface^ do + begin + Addr := pointer( UInt32( pixels ) + UInt32( RealRect.y ) * pitch + UInt32( RealRect.x ) * BPP ); + ModX := Pitch - UInt32( RealRect.w ) * BPP; + end; + case DstSurface.format.BitsPerPixel of + 8 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $E0 - Color and $E0; + G := SrcColor and $1C - Color and $1C; + B := SrcColor and $03 - Color and $03; + if R > $E0 then + R := 0; + if G > $1C then + G := 0; + if B > $03 then + B := 0; + PUInt8( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 15 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $7C00 - Color and $7C00; + G := SrcColor and $03E0 - Color and $03E0; + B := SrcColor and $001F - Color and $001F; + if R > $7C00 then + R := 0; + if G > $03E0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 16 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $F800 - Color and $F800; + G := SrcColor and $07C0 - Color and $07C0; + B := SrcColor and $001F - Color and $001F; + if R > $F800 then + R := 0; + if G > $07C0 then + G := 0; + if B > $001F then + B := 0; + PUInt16( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 24 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $00FF0000 - Color and $00FF0000; + G := SrcColor and $0000FF00 - Color and $0000FF00; + B := SrcColor and $000000FF - Color and $000000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( Addr )^ := SrcColor and $FF000000 or R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + 32 : + begin + for y := 0 to RealRect.h - 1 do + begin + for x := 0 to RealRect.w - 1 do + begin + SrcColor := PUInt32( Addr )^; + R := SrcColor and $00FF0000 - Color and $00FF0000; + G := SrcColor and $0000FF00 - Color and $0000FF00; + B := SrcColor and $000000FF - Color and $000000FF; + if R > $FF0000 then + R := 0; + if G > $00FF00 then + G := 0; + if B > $0000FF then + B := 0; + PUInt32( Addr )^ := R or G or B; + inc( UInt32( Addr ), BPP ); + end; + inc( UInt32( Addr ), ModX ); + end; + end; + end; + SDL_UnlockSurface( DstSurface ); + end; +end; + +procedure SDL_GradientFillRect( DstSurface : PSDL_Surface; const Rect : PSDL_Rect; const StartColor, EndColor : TSDL_Color; const Style : TGradientStyle ); +var + FBC : array[ 0..255 ] of Cardinal; + // temp vars + i, YR, YG, YB, SR, SG, SB, DR, DG, DB : Integer; + + TempStepV, TempStepH : Single; + TempLeft, TempTop, TempHeight, TempWidth : integer; + TempRect : TSDL_Rect; + +begin + // calc FBC + YR := StartColor.r; + YG := StartColor.g; + YB := StartColor.b; + SR := YR; + SG := YG; + SB := YB; + DR := EndColor.r - SR; + DG := EndColor.g - SG; + DB := EndColor.b - SB; + + for i := 0 to 255 do + begin + FBC[ i ] := SDL_MapRGB( DstSurface.format, YR, YG, YB ); + YR := SR + round( DR / 255 * i ); + YG := SG + round( DG / 255 * i ); + YB := SB + round( DB / 255 * i ); + end; + + // if aStyle = 1 then begin + TempStepH := Rect.w / 255; + TempStepV := Rect.h / 255; + TempHeight := Trunc( TempStepV + 1 ); + TempWidth := Trunc( TempStepH + 1 ); + TempTop := 0; + TempLeft := 0; + TempRect.x := Rect.x; + TempRect.y := Rect.y; + TempRect.h := Rect.h; + TempRect.w := Rect.w; + + case Style of + gsHorizontal : + begin + TempRect.h := TempHeight; + for i := 0 to 255 do + begin + TempRect.y := Rect.y + TempTop; + SDL_FillRect( DstSurface, @TempRect, FBC[ i ] ); + TempTop := Trunc( TempStepV * i ); + end; + end; + gsVertical : + begin + TempRect.w := TempWidth; + for i := 0 to 255 do + begin + TempRect.x := Rect.x + TempLeft; + SDL_FillRect( DstSurface, @TempRect, FBC[ i ] ); + TempLeft := Trunc( TempStepH * i ); + end; + end; + end; +end; + +procedure SDL_2xBlit( Src, Dest : PSDL_Surface ); +var + ReadAddr, WriteAddr, ReadRow, WriteRow : UInt32; + SrcPitch, DestPitch, x, y : UInt32; +begin + if ( Src = nil ) or ( Dest = nil ) then + exit; + if ( Src.w shl 1 ) < Dest.w then + exit; + if ( Src.h shl 1 ) < Dest.h then + exit; + + if SDL_MustLock( Src ) then + SDL_LockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_LockSurface( Dest ); + + ReadRow := UInt32( Src.Pixels ); + WriteRow := UInt32( Dest.Pixels ); + + SrcPitch := Src.pitch; + DestPitch := Dest.pitch; + + case Src.format.BytesPerPixel of + 1 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt8( WriteAddr )^ := PUInt8( ReadAddr )^; + PUInt8( WriteAddr + 1 )^ := PUInt8( ReadAddr )^; + PUInt8( WriteAddr + DestPitch )^ := PUInt8( ReadAddr )^; + PUInt8( WriteAddr + DestPitch + 1 )^ := PUInt8( ReadAddr )^; + inc( ReadAddr ); + inc( WriteAddr, 2 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 2 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt16( WriteAddr )^ := PUInt16( ReadAddr )^; + PUInt16( WriteAddr + 2 )^ := PUInt16( ReadAddr )^; + PUInt16( WriteAddr + DestPitch )^ := PUInt16( ReadAddr )^; + PUInt16( WriteAddr + DestPitch + 2 )^ := PUInt16( ReadAddr )^; + inc( ReadAddr, 2 ); + inc( WriteAddr, 4 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 3 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt32( WriteAddr )^ := ( PUInt32( WriteAddr )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + PUInt32( WriteAddr + 3 )^ := ( PUInt32( WriteAddr + 3 )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + PUInt32( WriteAddr + DestPitch )^ := ( PUInt32( WriteAddr + DestPitch )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + PUInt32( WriteAddr + DestPitch + 3 )^ := ( PUInt32( WriteAddr + DestPitch + 3 )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + inc( ReadAddr, 3 ); + inc( WriteAddr, 6 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 4 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt32( WriteAddr )^ := PUInt32( ReadAddr )^; + PUInt32( WriteAddr + 4 )^ := PUInt32( ReadAddr )^; + PUInt32( WriteAddr + DestPitch )^ := PUInt32( ReadAddr )^; + PUInt32( WriteAddr + DestPitch + 4 )^ := PUInt32( ReadAddr )^; + inc( ReadAddr, 4 ); + inc( WriteAddr, 8 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + end; + + if SDL_MustLock( Src ) then + SDL_UnlockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_UnlockSurface( Dest ); +end; + +procedure SDL_Scanline2xBlit( Src, Dest : PSDL_Surface ); +var + ReadAddr, WriteAddr, ReadRow, WriteRow : UInt32; + SrcPitch, DestPitch, x, y : UInt32; +begin + if ( Src = nil ) or ( Dest = nil ) then + exit; + if ( Src.w shl 1 ) < Dest.w then + exit; + if ( Src.h shl 1 ) < Dest.h then + exit; + + if SDL_MustLock( Src ) then + SDL_LockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_LockSurface( Dest ); + + ReadRow := UInt32( Src.Pixels ); + WriteRow := UInt32( Dest.Pixels ); + + SrcPitch := Src.pitch; + DestPitch := Dest.pitch; + + case Src.format.BytesPerPixel of + 1 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt8( WriteAddr )^ := PUInt8( ReadAddr )^; + PUInt8( WriteAddr + 1 )^ := PUInt8( ReadAddr )^; + inc( ReadAddr ); + inc( WriteAddr, 2 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 2 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt16( WriteAddr )^ := PUInt16( ReadAddr )^; + PUInt16( WriteAddr + 2 )^ := PUInt16( ReadAddr )^; + inc( ReadAddr, 2 ); + inc( WriteAddr, 4 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 3 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt32( WriteAddr )^ := ( PUInt32( WriteAddr )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + PUInt32( WriteAddr + 3 )^ := ( PUInt32( WriteAddr + 3 )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + inc( ReadAddr, 3 ); + inc( WriteAddr, 6 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 4 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + PUInt32( WriteAddr )^ := PUInt32( ReadAddr )^; + PUInt32( WriteAddr + 4 )^ := PUInt32( ReadAddr )^; + inc( ReadAddr, 4 ); + inc( WriteAddr, 8 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + end; + + if SDL_MustLock( Src ) then + SDL_UnlockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_UnlockSurface( Dest ); +end; + +procedure SDL_50Scanline2xBlit( Src, Dest : PSDL_Surface ); +var + ReadAddr, WriteAddr, ReadRow, WriteRow : UInt32; + SrcPitch, DestPitch, x, y, Color : UInt32; +begin + if ( Src = nil ) or ( Dest = nil ) then + exit; + if ( Src.w shl 1 ) < Dest.w then + exit; + if ( Src.h shl 1 ) < Dest.h then + exit; + + if SDL_MustLock( Src ) then + SDL_LockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_LockSurface( Dest ); + + ReadRow := UInt32( Src.Pixels ); + WriteRow := UInt32( Dest.Pixels ); + + SrcPitch := Src.pitch; + DestPitch := Dest.pitch; + + case Src.format.BitsPerPixel of + 8 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + Color := PUInt8( ReadAddr )^; + PUInt8( WriteAddr )^ := Color; + PUInt8( WriteAddr + 1 )^ := Color; + Color := ( Color shr 1 ) and $6D; {%01101101} + PUInt8( WriteAddr + DestPitch )^ := Color; + PUInt8( WriteAddr + DestPitch + 1 )^ := Color; + inc( ReadAddr ); + inc( WriteAddr, 2 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 15 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + Color := PUInt16( ReadAddr )^; + PUInt16( WriteAddr )^ := Color; + PUInt16( WriteAddr + 2 )^ := Color; + Color := ( Color shr 1 ) and $3DEF; {%0011110111101111} + PUInt16( WriteAddr + DestPitch )^ := Color; + PUInt16( WriteAddr + DestPitch + 2 )^ := Color; + inc( ReadAddr, 2 ); + inc( WriteAddr, 4 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 16 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + Color := PUInt16( ReadAddr )^; + PUInt16( WriteAddr )^ := Color; + PUInt16( WriteAddr + 2 )^ := Color; + Color := ( Color shr 1 ) and $7BEF; {%0111101111101111} + PUInt16( WriteAddr + DestPitch )^ := Color; + PUInt16( WriteAddr + DestPitch + 2 )^ := Color; + inc( ReadAddr, 2 ); + inc( WriteAddr, 4 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 24 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + Color := ( PUInt32( WriteAddr )^ and $FF000000 ) or ( PUInt32( ReadAddr )^ and $00FFFFFF ); + PUInt32( WriteAddr )^ := Color; + PUInt32( WriteAddr + 3 )^ := Color; + Color := ( Color shr 1 ) and $007F7F7F; {%011111110111111101111111} + PUInt32( WriteAddr + DestPitch )^ := Color; + PUInt32( WriteAddr + DestPitch + 3 )^ := Color; + inc( ReadAddr, 3 ); + inc( WriteAddr, 6 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + 32 : for y := 1 to Src.h do + begin + ReadAddr := ReadRow; + WriteAddr := WriteRow; + for x := 1 to Src.w do + begin + Color := PUInt32( ReadAddr )^; + PUInt32( WriteAddr )^ := Color; + PUInt32( WriteAddr + 4 )^ := Color; + Color := ( Color shr 1 ) and $7F7F7F7F; + PUInt32( WriteAddr + DestPitch )^ := Color; + PUInt32( WriteAddr + DestPitch + 4 )^ := Color; + inc( ReadAddr, 4 ); + inc( WriteAddr, 8 ); + end; + inc( UInt32( ReadRow ), SrcPitch ); + inc( UInt32( WriteRow ), DestPitch * 2 ); + end; + end; + + if SDL_MustLock( Src ) then + SDL_UnlockSurface( Src ); + if SDL_MustLock( Dest ) then + SDL_UnlockSurface( Dest ); +end; + +function SDL_PixelTestSurfaceVsRect( SrcSurface1 : PSDL_Surface; SrcRect1 : + PSDL_Rect; SrcRect2 : PSDL_Rect; Left1, Top1, Left2, Top2 : integer ) : + boolean; +var + Src_Rect1, Src_Rect2 : TSDL_Rect; + right1, bottom1 : integer; + right2, bottom2 : integer; + Scan1Start, {Scan2Start,} ScanWidth, ScanHeight : cardinal; + Mod1 : cardinal; + Addr1 : cardinal; + BPP : cardinal; + Pitch1 : cardinal; + TransparentColor1 : cardinal; + tx, ty : cardinal; + StartTick : cardinal; + Color1 : cardinal; +begin + Result := false; + if SrcRect1 = nil then + begin + with Src_Rect1 do + begin + x := 0; + y := 0; + w := SrcSurface1.w; + h := SrcSurface1.h; + end; + end + else + Src_Rect1 := SrcRect1^; + + Src_Rect2 := SrcRect2^; + with Src_Rect1 do + begin + Right1 := Left1 + w; + Bottom1 := Top1 + h; + end; + with Src_Rect2 do + begin + Right2 := Left2 + w; + Bottom2 := Top2 + h; + end; + if ( Left1 >= Right2 ) or ( Right1 <= Left2 ) or ( Top1 >= Bottom2 ) or ( Bottom1 <= Top2 ) then + exit; + if Left1 <= Left2 then + begin + // 1. left, 2. right + Scan1Start := Src_Rect1.x + Left2 - Left1; + //Scan2Start := Src_Rect2.x; + ScanWidth := Right1 - Left2; + with Src_Rect2 do + if ScanWidth > w then + ScanWidth := w; + end + else + begin + // 1. right, 2. left + Scan1Start := Src_Rect1.x; + //Scan2Start := Src_Rect2.x + Left1 - Left2; + ScanWidth := Right2 - Left1; + with Src_Rect1 do + if ScanWidth > w then + ScanWidth := w; + end; + with SrcSurface1^ do + begin + Pitch1 := Pitch; + Addr1 := cardinal( Pixels ); + inc( Addr1, Pitch1 * UInt32( Src_Rect1.y ) ); + with format^ do + begin + BPP := BytesPerPixel; + TransparentColor1 := colorkey; + end; + end; + + Mod1 := Pitch1 - ( ScanWidth * BPP ); + + inc( Addr1, BPP * Scan1Start ); + + if Top1 <= Top2 then + begin + // 1. up, 2. down + ScanHeight := Bottom1 - Top2; + if ScanHeight > Src_Rect2.h then + ScanHeight := Src_Rect2.h; + inc( Addr1, Pitch1 * UInt32( Top2 - Top1 ) ); + end + else + begin + // 1. down, 2. up + ScanHeight := Bottom2 - Top1; + if ScanHeight > Src_Rect1.h then + ScanHeight := Src_Rect1.h; + + end; + case BPP of + 1 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PByte( Addr1 )^ <> TransparentColor1 ) then + begin + Result := true; + exit; + end; + inc( Addr1 ); + + end; + inc( Addr1, Mod1 ); + + end; + 2 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PWord( Addr1 )^ <> TransparentColor1 ) then + begin + Result := true; + exit; + end; + inc( Addr1, 2 ); + + end; + inc( Addr1, Mod1 ); + + end; + 3 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + Color1 := PLongWord( Addr1 )^ and $00FFFFFF; + + if ( Color1 <> TransparentColor1 ) + then + begin + Result := true; + exit; + end; + inc( Addr1, 3 ); + + end; + inc( Addr1, Mod1 ); + + end; + 4 : + for ty := 1 to ScanHeight do + begin + for tx := 1 to ScanWidth do + begin + if ( PLongWord( Addr1 )^ <> TransparentColor1 ) then + begin + Result := true; + exit; + end; + inc( Addr1, 4 ); + + end; + inc( Addr1, Mod1 ); + + end; + end; +end; + +procedure SDL_ORSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + PUInt8( DestAddr )^ := Pixel2 or Pixel1; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + + PUInt16( DestAddr )^ := Pixel2 or Pixel1; + + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + + PUInt16( DestAddr )^ := Pixel2 or Pixel1; + + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or Pixel2 or Pixel1; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + + PUInt32( DestAddr )^ := Pixel2 or Pixel1; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + +procedure SDL_ANDSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + PUInt8( DestAddr )^ := Pixel2 and Pixel1; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + + PUInt16( DestAddr )^ := Pixel2 and Pixel1; + + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + + PUInt16( DestAddr )^ := Pixel2 and Pixel1; + + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or Pixel2 and Pixel1; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + + PUInt32( DestAddr )^ := Pixel2 and Pixel1; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + + + +procedure SDL_GTSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + if Pixel2 > 0 then + begin + if Pixel2 and $E0 > Pixel1 and $E0 then + R := Pixel2 and $E0 + else + R := Pixel1 and $E0; + if Pixel2 and $1C > Pixel1 and $1C then + G := Pixel2 and $1C + else + G := Pixel1 and $1C; + if Pixel2 and $03 > Pixel1 and $03 then + B := Pixel2 and $03 + else + B := Pixel1 and $03; + + if R > $E0 then + R := $E0; + if G > $1C then + G := $1C; + if B > $03 then + B := $03; + PUInt8( DestAddr )^ := R or G or B; + end + else + PUInt8( DestAddr )^ := Pixel1; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $7C00 > Pixel1 and $7C00 then + R := Pixel2 and $7C00 + else + R := Pixel1 and $7C00; + if Pixel2 and $03E0 > Pixel1 and $03E0 then + G := Pixel2 and $03E0 + else + G := Pixel1 and $03E0; + if Pixel2 and $001F > Pixel1 and $001F then + B := Pixel2 and $001F + else + B := Pixel1 and $001F; + + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $F800 > Pixel1 and $F800 then + R := Pixel2 and $F800 + else + R := Pixel1 and $F800; + if Pixel2 and $07E0 > Pixel1 and $07E0 then + G := Pixel2 and $07E0 + else + G := Pixel1 and $07E0; + if Pixel2 and $001F > Pixel1 and $001F then + B := Pixel2 and $001F + else + B := Pixel1 and $001F; + + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + if Pixel2 > 0 then + begin + + if Pixel2 and $FF0000 > Pixel1 and $FF0000 then + R := Pixel2 and $FF0000 + else + R := Pixel1 and $FF0000; + if Pixel2 and $00FF00 > Pixel1 and $00FF00 then + G := Pixel2 and $00FF00 + else + G := Pixel1 and $00FF00; + if Pixel2 and $0000FF > Pixel1 and $0000FF then + B := Pixel2 and $0000FF + else + B := Pixel1 and $0000FF; + + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or ( R or G or B ); + end + else + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or Pixel1; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $FF0000 > Pixel1 and $FF0000 then + R := Pixel2 and $FF0000 + else + R := Pixel1 and $FF0000; + if Pixel2 and $00FF00 > Pixel1 and $00FF00 then + G := Pixel2 and $00FF00 + else + G := Pixel1 and $00FF00; + if Pixel2 and $0000FF > Pixel1 and $0000FF then + B := Pixel2 and $0000FF + else + B := Pixel1 and $0000FF; + + PUInt32( DestAddr )^ := R or G or B; + end + else + PUInt32( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + + +procedure SDL_LTSurface( SrcSurface : PSDL_Surface; SrcRect : PSDL_Rect; + DestSurface : PSDL_Surface; DestRect : PSDL_Rect ); +var + R, G, B, Pixel1, Pixel2, TransparentColor : cardinal; + Src, Dest : TSDL_Rect; + Diff : integer; + SrcAddr, DestAddr : cardinal; + WorkX, WorkY : word; + SrcMod, DestMod : cardinal; + Bits : cardinal; +begin + if ( SrcSurface = nil ) or ( DestSurface = nil ) then + exit; // Remove this to make it faster + if ( SrcSurface.Format.BitsPerPixel <> DestSurface.Format.BitsPerPixel ) then + exit; // Remove this to make it faster + if SrcRect = nil then + begin + with Src do + begin + x := 0; + y := 0; + w := SrcSurface.w; + h := SrcSurface.h; + end; + end + else + Src := SrcRect^; + if DestRect = nil then + begin + Dest.x := 0; + Dest.y := 0; + end + else + Dest := DestRect^; + Dest.w := Src.w; + Dest.h := Src.h; + with DestSurface.Clip_Rect do + begin + // Source's right side is greater than the dest.cliprect + if Dest.x + Src.w > x + w then + begin + smallint( Src.w ) := x + w - Dest.x; + smallint( Dest.w ) := x + w - Dest.x; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's bottom side is greater than the dest.clip + if Dest.y + Src.h > y + h then + begin + smallint( Src.h ) := y + h - Dest.y; + smallint( Dest.h ) := y + h - Dest.y; + if smallint( Dest.h ) < 1 then + exit; + end; + // Source's left side is less than the dest.clip + if Dest.x < x then + begin + Diff := x - Dest.x; + Src.x := Src.x + Diff; + smallint( Src.w ) := smallint( Src.w ) - Diff; + Dest.x := x; + smallint( Dest.w ) := smallint( Dest.w ) - Diff; + if smallint( Dest.w ) < 1 then + exit; + end; + // Source's Top side is less than the dest.clip + if Dest.y < y then + begin + Diff := y - Dest.y; + Src.y := Src.y + Diff; + smallint( Src.h ) := smallint( Src.h ) - Diff; + Dest.y := y; + smallint( Dest.h ) := smallint( Dest.h ) - Diff; + if smallint( Dest.h ) < 1 then + exit; + end; + end; + with SrcSurface^ do + begin + SrcAddr := cardinal( Pixels ) + UInt32( Src.y ) * Pitch + UInt32( Src.x ) * + Format.BytesPerPixel; + SrcMod := Pitch - Src.w * Format.BytesPerPixel; + TransparentColor := Format.colorkey; + end; + with DestSurface^ do + begin + DestAddr := cardinal( Pixels ) + UInt32( Dest.y ) * Pitch + UInt32( Dest.x ) * + Format.BytesPerPixel; + DestMod := Pitch - Dest.w * Format.BytesPerPixel; + Bits := Format.BitsPerPixel; + end; + SDL_LockSurface( SrcSurface ); + SDL_LockSurface( DestSurface ); + WorkY := Src.h; + case bits of + 8 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt8( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt8( DestAddr )^; + if Pixel2 > 0 then + begin + if Pixel2 and $E0 < Pixel1 and $E0 then + R := Pixel2 and $E0 + else + R := Pixel1 and $E0; + if Pixel2 and $1C < Pixel1 and $1C then + G := Pixel2 and $1C + else + G := Pixel1 and $1C; + if Pixel2 and $03 < Pixel1 and $03 then + B := Pixel2 and $03 + else + B := Pixel1 and $03; + + if R > $E0 then + R := $E0; + if G > $1C then + G := $1C; + if B > $03 then + B := $03; + PUInt8( DestAddr )^ := R or G or B; + end + else + PUInt8( DestAddr )^ := Pixel1; + end; + inc( SrcAddr ); + inc( DestAddr ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 15 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $7C00 < Pixel1 and $7C00 then + R := Pixel2 and $7C00 + else + R := Pixel1 and $7C00; + if Pixel2 and $03E0 < Pixel1 and $03E0 then + G := Pixel2 and $03E0 + else + G := Pixel1 and $03E0; + if Pixel2 and $001F < Pixel1 and $001F then + B := Pixel2 and $001F + else + B := Pixel1 and $001F; + + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 16 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt16( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt16( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $F800 < Pixel1 and $F800 then + R := Pixel2 and $F800 + else + R := Pixel1 and $F800; + if Pixel2 and $07E0 < Pixel1 and $07E0 then + G := Pixel2 and $07E0 + else + G := Pixel1 and $07E0; + if Pixel2 and $001F < Pixel1 and $001F then + B := Pixel2 and $001F + else + B := Pixel1 and $001F; + + PUInt16( DestAddr )^ := R or G or B; + end + else + PUInt16( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 2 ); + inc( DestAddr, 2 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 24 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^ and $00FFFFFF; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^ and $00FFFFFF; + if Pixel2 > 0 then + begin + + if Pixel2 and $FF0000 < Pixel1 and $FF0000 then + R := Pixel2 and $FF0000 + else + R := Pixel1 and $FF0000; + if Pixel2 and $00FF00 < Pixel1 and $00FF00 then + G := Pixel2 and $00FF00 + else + G := Pixel1 and $00FF00; + if Pixel2 and $0000FF < Pixel1 and $0000FF then + B := Pixel2 and $0000FF + else + B := Pixel1 and $0000FF; + + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or ( R or G or B ); + end + else + PUInt32( DestAddr )^ := PUInt32( DestAddr )^ and $FF000000 or Pixel1; + end; + inc( SrcAddr, 3 ); + inc( DestAddr, 3 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + 32 : + begin + repeat + WorkX := Src.w; + repeat + Pixel1 := PUInt32( SrcAddr )^; + if ( Pixel1 <> TransparentColor ) and ( Pixel1 <> 0 ) then + begin + Pixel2 := PUInt32( DestAddr )^; + if Pixel2 > 0 then + begin + + if Pixel2 and $FF0000 < Pixel1 and $FF0000 then + R := Pixel2 and $FF0000 + else + R := Pixel1 and $FF0000; + if Pixel2 and $00FF00 < Pixel1 and $00FF00 then + G := Pixel2 and $00FF00 + else + G := Pixel1 and $00FF00; + if Pixel2 and $0000FF < Pixel1 and $0000FF then + B := Pixel2 and $0000FF + else + B := Pixel1 and $0000FF; + + PUInt32( DestAddr )^ := R or G or B; + end + else + PUInt32( DestAddr )^ := Pixel1; + end; + inc( SrcAddr, 4 ); + inc( DestAddr, 4 ); + dec( WorkX ); + until WorkX = 0; + inc( SrcAddr, SrcMod ); + inc( DestAddr, DestMod ); + dec( WorkY ); + until WorkY = 0; + end; + end; + SDL_UnlockSurface( SrcSurface ); + SDL_UnlockSurface( DestSurface ); +end; + +// Will clip the x1,x2,y1,x2 params to the ClipRect provided + +function SDL_ClipLine( var x1, y1, x2, y2 : Integer; ClipRect : PSDL_Rect ) : boolean; +var + tflag, flag1, flag2 : word; + txy, xedge, yedge : Integer; + slope : single; + + function ClipCode( x, y : Integer ) : word; + begin + Result := 0; + if x < ClipRect.x then + Result := 1; + if x >= ClipRect.w + ClipRect.x then + Result := Result or 2; + if y < ClipRect.y then + Result := Result or 4; + if y >= ClipRect.h + ClipRect.y then + Result := Result or 8; + end; + +begin + flag1 := ClipCode( x1, y1 ); + flag2 := ClipCode( x2, y2 ); + result := true; + + while true do + begin + if ( flag1 or flag2 ) = 0 then + Exit; // all in + + if ( flag1 and flag2 ) <> 0 then + begin + result := false; + Exit; // all out + end; + + if flag2 = 0 then + begin + txy := x1; x1 := x2; x2 := txy; + txy := y1; y1 := y2; y2 := txy; + tflag := flag1; flag1 := flag2; flag2 := tflag; + end; + + if ( flag2 and 3 ) <> 0 then + begin + if ( flag2 and 1 ) <> 0 then + xedge := ClipRect.x + else + xedge := ClipRect.w + ClipRect.x - 1; // back 1 pixel otherwise we end up in a loop + + slope := ( y2 - y1 ) / ( x2 - x1 ); + y2 := y1 + Round( slope * ( xedge - x1 ) ); + x2 := xedge; + end + else + begin + if ( flag2 and 4 ) <> 0 then + yedge := ClipRect.y + else + yedge := ClipRect.h + ClipRect.y - 1; // up 1 pixel otherwise we end up in a loop + + slope := ( x2 - x1 ) / ( y2 - y1 ); + x2 := x1 + Round( slope * ( yedge - y1 ) ); + y2 := yedge; + end; + + flag2 := ClipCode( x2, y2 ); + end; +end; + +end. + diff --git a/lib/wrappers/sdl/smpeg.nim b/lib/wrappers/sdl/smpeg.nim new file mode 100644 index 000000000..ada0ed57c --- /dev/null +++ b/lib/wrappers/sdl/smpeg.nim @@ -0,0 +1,319 @@ + +#****************************************************************************** +# +# $Id: smpeg.pas,v 1.7 2004/08/14 22:54:30 savage Exp $ +# +# +# +# Borland Delphi SMPEG - SDL MPEG Player Library +# Conversion of the SMPEG - SDL MPEG Player Library +# +# Portions created by Sam Lantinga <slouken@devolution.com> are +# Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga +# 5635-34 Springhouse Dr. +# Pleasanton, CA 94588 (USA) +# +# All Rights Reserved. +# +# The original files are : smpeg.h +# +# The initial developer of this Pascal code was : +# Matthias Thoma <ma.thoma@gmx.de> +# +# Portions created by Matthias Thoma are +# Copyright (C) 2000 - 2001 Matthias Thoma. +# +# +# Contributor(s) +# -------------- +# Tom Jones <tigertomjones@gmx.de> His Project inspired this conversion +# Matthias Thoma <ma.thoma@gmx.de> +# +# Obtained through: +# Joint Endeavour of Delphi Innovators ( Project JEDI ) +# +# You may retrieve the latest version of this file at the Project +# JEDI home page, located at http://delphi-jedi.org +# +# The contents of this file are used with permission, subject to +# the Mozilla Public License Version 1.1 (the "License"); you may +# not use this file except in compliance with the License. You may +# obtain a copy of the License at +# http://www.mozilla.org/MPL/MPL-1.1.html +# +# Software distributed under the License is distributed on an +# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# Description +# ----------- +# +# +# +# +# +# +# +# Requires +# -------- +# The SDL Runtime libraris on Win32 : SDL.dll on Linux : libSDL-1.2.so.0 +# They are available from... +# http://www.libsdl.org . +# +# Programming Notes +# ----------------- +# +# +# +# +# Revision History +# ---------------- +# May 08 2001 - MT : Initial conversion +# +# October 12 2001 - DA : Various changes as suggested by David Acklam +# +# April 03 2003 - DL : Added jedi-sdl.inc include file to support more +# Pascal compilers. Initial support is now included +# for GnuPascal, VirtualPascal, TMT and obviously +# continue support for Delphi Kylix and FreePascal. +# +# April 08 2003 - MK : Aka Mr Kroket - Added Better FPC support +# Fixed all invalid calls to DLL. +# Changed constant names to: +# const +# STATUS_SMPEG_ERROR = -1; +# STATUS_SMPEG_STOPPED = 0; +# STATUS_SMPEG_PLAYING = 1; +# because SMPEG_ERROR is a function (_SMPEG_error +# isn't correct), and cannot be two elements with the +# same name +# +# April 24 2003 - DL : under instruction from Alexey Barkovoy, I have added +# better TMT Pascal support and under instruction +# from Prof. Abimbola Olowofoyeku (The African Chief), +# I have added better Gnu Pascal support +# +# April 30 2003 - DL : under instruction from David Mears AKA +# Jason Siletto, I have added FPC Linux support. +# This was compiled with fpc 1.1, so remember to set +# include file path. ie. -Fi/usr/share/fpcsrc/rtl/* +# +# +# $Log: smpeg.pas,v $ +# Revision 1.7 2004/08/14 22:54:30 savage +# Updated so that Library name defines are correctly defined for MacOS X. +# +# Revision 1.6 2004/05/10 14:10:04 savage +# Initial MacOS X support. Fixed defines for MACOS ( Classic ) and DARWIN ( MacOS X ). +# +# Revision 1.5 2004/04/13 09:32:08 savage +# Changed Shared object names back to just the .so extension to avoid conflicts on various Linux/Unix distros. Therefore developers will need to create Symbolic links to the actual Share Objects if necessary. +# +# Revision 1.4 2004/04/02 10:40:55 savage +# Changed Linux Shared Object name so they reflect the Symbolic Links that are created when installing the RPMs from the SDL site. +# +# Revision 1.3 2004/03/31 22:20:02 savage +# Windows unit not used in this file, so it was removed to keep the code tidy. +# +# Revision 1.2 2004/03/30 20:23:28 savage +# Tidied up use of UNIX compiler directive. +# +# Revision 1.1 2004/02/14 23:35:42 savage +# version 1 of sdl_image, sdl_mixer and smpeg. +# +# +# +#****************************************************************************** + +import + sdl + +when defined(windows): + const SmpegLibName = "smpeg.dll" +elif defined(macosx): + const SmpegLibName = "libsmpeg.dylib" +else: + const SmpegLibName = "libsmpeg.so" + +const + SMPEG_FILTER_INFO_MB_ERROR* = 1 + SMPEG_FILTER_INFO_PIXEL_ERROR* = 2 # Filter info from SMPEG + +type + SMPEG_FilterInfo*{.final.} = object + yuv_mb_square_error*: PUint16 + yuv_pixel_square_error*: PUint16 + + TSMPEG_FilterInfo* = SMPEG_FilterInfo + PSMPEG_FilterInfo* = ptr SMPEG_FilterInfo # MPEG filter definition + PSMPEG_Filter* = ptr TSMPEG_Filter # Callback functions for the filter + TSMPEG_FilterCallback* = proc (dest, source: PSDL_Overlay, region: PSDL_Rect, + filter_info: PSMPEG_FilterInfo, data: Pointer): Pointer{. + cdecl.} + TSMPEG_FilterDestroy* = proc (Filter: PSMPEG_Filter): Pointer{.cdecl.} # The filter + # definition itself + TSMPEG_Filter*{.final.} = object # The null filter (default). It simply copies the source rectangle to the video overlay. + flags*: Uint32 + data*: Pointer + callback*: TSMPEG_FilterCallback + destroy*: TSMPEG_FilterDestroy + + +proc SMPEGfilter_null*(): PSMPEG_Filter{.cdecl, importc, dynlib: SmpegLibName.} + # The bilinear filter. A basic low-pass filter that will produce a smoother image. +proc SMPEGfilter_bilinear*(): PSMPEG_Filter{.cdecl, importc, dynlib: SmpegLibName.} + # The deblocking filter. It filters block borders and non-intra coded blocks to reduce blockiness +proc SMPEGfilter_deblocking*(): PSMPEG_Filter{.cdecl, importc, dynlib: SmpegLibName.} + #------------------------------------------------------------------------------ + # SMPEG.h + #------------------------------------------------------------------------------ +const + SMPEG_MAJOR_VERSION* = 0'i8 + SMPEG_MINOR_VERSION* = 4'i8 + SMPEG_PATCHLEVEL* = 2'i8 + +type + SMPEG_version*{.final.} = object + major*: UInt8 + minor*: UInt8 + patch*: UInt8 + + TSMPEG_version* = SMPEG_version + PSMPEG_version* = ptr TSMPEG_version # This is the actual SMPEG object + TSMPEG*{.final.} = object + PSMPEG* = ptr TSMPEG # Used to get information about the SMPEG object + TSMPEG_Info*{.final.} = object + has_audio*: int + has_video*: int + width*: int + height*: int + current_frame*: int + current_fps*: float64 + audio_string*: array[0..79, char] + audio_current_frame*: int + current_offset*: UInt32 + total_size*: UInt32 + current_time*: float64 + total_time*: float64 + + PSMPEG_Info* = ptr TSMPEG_Info # Possible MPEG status codes + +const + STATUS_SMPEG_ERROR* = - 1 + STATUS_SMPEG_STOPPED* = 0 + STATUS_SMPEG_PLAYING* = 1 + +type + TSMPEGstatus* = int + PSMPEGstatus* = ptr int # Matches the declaration of SDL_UpdateRect() + TSMPEG_DisplayCallback* = proc (dst: PSDL_Surface, x, y: int, w, h: int): Pointer{. + cdecl.} # Create a new SMPEG object from an MPEG file. + # On return, if 'info' is not NULL, it will be filled with information + # about the MPEG object. + # This function returns a new SMPEG object. Use SMPEG_error() to find out + # whether or not there was a problem building the MPEG stream. + # The sdl_audio parameter indicates if SMPEG should initialize the SDL audio + # subsystem. If not, you will have to use the SMPEG_playaudio() function below + # to extract the decoded data. + +proc SMPEG_new*(theFile: cstring, info: PSMPEG_Info, sdl_audio: int): PSMPEG{. + cdecl, importc, dynlib: SmpegLibName.} + # The same as above for a file descriptor +proc SMPEG_new_descr*(theFile: int, info: PSMPEG_Info, sdl_audio: int): PSMPEG{. + cdecl, importc, dynlib: SmpegLibName.} + # The same as above but for a raw chunk of data. SMPEG makes a copy of the + # data, so the application is free to delete after a successful call to this + # function. +proc SMPEG_new_data*(data: Pointer, size: int, info: PSMPEG_Info, sdl_audio: int): PSMPEG{. + cdecl, importc, dynlib: SmpegLibName.} + # Get current information about an SMPEG object +proc SMPEG_getinfo*(mpeg: PSMPEG, info: PSMPEG_Info){.cdecl, + importc, dynlib: SmpegLibName.} + #procedure SMPEG_getinfo(mpeg: PSMPEG; info: Pointer); + #cdecl; external SmpegLibName; + # Enable or disable audio playback in MPEG stream +proc SMPEG_enableaudio*(mpeg: PSMPEG, enable: int){.cdecl, importc, dynlib: SmpegLibName.} + # Enable or disable video playback in MPEG stream +proc SMPEG_enablevideo*(mpeg: PSMPEG, enable: int){.cdecl, importc, dynlib: SmpegLibName.} + # Delete an SMPEG object +proc SMPEG_delete*(mpeg: PSMPEG){.cdecl, importc, dynlib: SmpegLibName.} + # Get the current status of an SMPEG object +proc SMPEG_status*(mpeg: PSMPEG): TSMPEGstatus{.cdecl, importc, dynlib: SmpegLibName.} + # status + # Set the audio volume of an MPEG stream, in the range 0-100 +proc SMPEG_setvolume*(mpeg: PSMPEG, volume: int){.cdecl, importc, dynlib: SmpegLibName.} + # Set the destination surface for MPEG video playback + # 'surfLock' is a mutex used to synchronize access to 'dst', and can be NULL. + # 'callback' is a function called when an area of 'dst' needs to be updated. + # If 'callback' is NULL, the default function (SDL_UpdateRect) will be used. +proc SMPEG_setdisplay*(mpeg: PSMPEG, dst: PSDL_Surface, surfLock: PSDL_mutex, + callback: TSMPEG_DisplayCallback){.cdecl, + importc, dynlib: SmpegLibName.} + # Set or clear looping play on an SMPEG object +proc SMPEG_loop*(mpeg: PSMPEG, repeat_: int){.cdecl, importc, dynlib: SmpegLibName.} + # Scale pixel display on an SMPEG object +proc SMPEG_scaleXY*(mpeg: PSMPEG, width, height: int){.cdecl, + importc, dynlib: SmpegLibName.} +proc SMPEG_scale*(mpeg: PSMPEG, scale: int){.cdecl, importc, dynlib: SmpegLibName.} +proc SMPEG_Double*(mpeg: PSMPEG, doubleit: bool) + # Move the video display area within the destination surface +proc SMPEG_move*(mpeg: PSMPEG, x, y: int){.cdecl, importc, dynlib: SmpegLibName.} + # Set the region of the video to be shown +proc SMPEG_setdisplayregion*(mpeg: PSMPEG, x, y, w, h: int){.cdecl, + importc, dynlib: SmpegLibName.} + # Play an SMPEG object +proc SMPEG_play*(mpeg: PSMPEG){.cdecl, importc, dynlib: SmpegLibName.} + # Pause/Resume playback of an SMPEG object +proc SMPEG_pause*(mpeg: PSMPEG){.cdecl, importc, dynlib: SmpegLibName.} + # Stop playback of an SMPEG object +proc SMPEG_stop*(mpeg: PSMPEG){.cdecl, importc, dynlib: SmpegLibName.} + # Rewind the play position of an SMPEG object to the beginning of the MPEG +proc SMPEG_rewind*(mpeg: PSMPEG){.cdecl, importc, dynlib: SmpegLibName.} + # Seek 'bytes' bytes in the MPEG stream +proc SMPEG_seek*(mpeg: PSMPEG, bytes: int){.cdecl, importc, dynlib: SmpegLibName.} + # Skip 'seconds' seconds in the MPEG stream +proc SMPEG_skip*(mpeg: PSMPEG, seconds: float32){.cdecl, importc, dynlib: SmpegLibName.} + # Render a particular frame in the MPEG video + # API CHANGE: This function no longer takes a target surface and position. + # Use SMPEG_setdisplay() and SMPEG_move() to set this information. +proc SMPEG_renderFrame*(mpeg: PSMPEG, framenum: int){.cdecl, + importc, dynlib: SmpegLibName.} + # Render the last frame of an MPEG video +proc SMPEG_renderFinal*(mpeg: PSMPEG, dst: PSDL_Surface, x, y: int){.cdecl, + importc, dynlib: SmpegLibName.} + # Set video filter +proc SMPEG_filter*(mpeg: PSMPEG, filter: PSMPEG_Filter): PSMPEG_Filter{.cdecl, + importc, dynlib: SmpegLibName.} + # Return NULL if there is no error in the MPEG stream, or an error message + # if there was a fatal error in the MPEG stream for the SMPEG object. +proc SMPEG_error*(mpeg: PSMPEG): cstring{.cdecl, importc, dynlib: SmpegLibName.} + # Exported callback function for audio playback. + # The function takes a buffer and the amount of data to fill, and returns + # the amount of data in bytes that was actually written. This will be the + # amount requested unless the MPEG audio has finished. + # +proc SMPEG_playAudio*(mpeg: PSMPEG, stream: PUInt8, length: int): int{.cdecl, + importc, dynlib: SmpegLibName.} + # Wrapper for SMPEG_playAudio() that can be passed to SDL and SDL_mixer +proc SMPEG_playAudioSDL*(mpeg: Pointer, stream: PUInt8, length: int){.cdecl, + importc, dynlib: SmpegLibName.} + # Get the best SDL audio spec for the audio stream +proc SMPEG_wantedSpec*(mpeg: PSMPEG, wanted: PSDL_AudioSpec): int{.cdecl, + importc, dynlib: SmpegLibName.} + # Inform SMPEG of the actual SDL audio spec used for sound playback +proc SMPEG_actualSpec*(mpeg: PSMPEG, spec: PSDL_AudioSpec){.cdecl, + importc, dynlib: SmpegLibName.} + # This macro can be used to fill a version structure with the compile-time + # version of the SDL library. +proc SMPEG_GETVERSION*(X: var TSMPEG_version) +# implementation + +proc SMPEG_double(mpeg: PSMPEG, doubleit: bool) = + if doubleit: SMPEG_scale(mpeg, 2) + else: SMPEG_scale(mpeg, 1) + +proc SMPEG_GETVERSION(X: var TSMPEG_version) = + X.major = SMPEG_MAJOR_VERSION + X.minor = SMPEG_MINOR_VERSION + X.patch = SMPEG_PATCHLEVEL |