├── .dockerignore ├── .gitattributes ├── CREDITS ├── examples ├── spaceship.bmp ├── p01_shape24.bmp ├── p01_shape32alpha.bmp ├── 002-error-messagebox.php ├── 001-sdl-version.php ├── bootstrap.php ├── 004-draw-points.php ├── 005-draw-rectangle.php ├── 008-shaped-window.php ├── 003-messagebox-inputs.php ├── 010-draw-lines.php ├── 006-animated-boxes.php ├── 007-input-handling.php ├── 011-draw-with-subpixels.php └── 009-window-events.php ├── input-handling-example.gif ├── docker-entrypoint.sh ├── check-files-are-in-package-xml.sh ├── .github └── workflows │ └── build-test.yml ├── tests ├── 029-point-in-rect.phpt ├── 027-joystick.phpt ├── 019-platform.phpt ├── test-functions.php ├── 008-error.phpt ├── 026-filesystem.phpt ├── 002-init-and-shutdown.phpt ├── 022-pixels.phpt ├── 028-point.phpt ├── 017-rwops-stream.phpt ├── 001-extension-loading.phpt ├── 003-init-and-quit-subsystems.phpt ├── 018-power.phpt ├── 004-cpuinfo.phpt ├── 010-palette.phpt ├── 014-version.phpt ├── 009-color.phpt ├── 024-mutex.phpt ├── 025-mutex-oo.phpt ├── 011-palette-oo.phpt ├── 015-rwops.phpt ├── 005-video.phpt ├── 016-rwops-oo.phpt ├── 020-surface.phpt ├── 021-surface-oo.phpt ├── 007-rect-oo.phpt ├── 023-messagebox.phpt ├── 006-rect.phpt ├── 012-pixelformat.phpt └── 013-pixelformat-oo.phpt ├── Dockerfile ├── .gitignore ├── config.w32 ├── LICENSE ├── src ├── blendmode.h ├── timer.c ├── timer.h ├── platform.c ├── platform.h ├── power.h ├── shape.h ├── blendmode.c ├── error.h ├── filesystem.h ├── cpuinfo.h ├── rect.h ├── event.h ├── error.c ├── version.h ├── sdl.h ├── php_sdl.h ├── messagebox.h ├── rect.stub.php ├── power.c ├── joystick.h ├── keyboard.h ├── video.h ├── mouse.h ├── glcontext.h ├── mutex.h ├── rwops.h ├── sdl.c ├── cpuinfo.c ├── joystick.c ├── filesystem.c ├── version.c ├── pixels.h ├── render.h ├── shape.c └── window.h ├── README.md └── config.m4 /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.c ident 2 | *.h ident 3 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | SDL 2 | Santiago Lizardo, Remi Collet, Manuel Baldassarri, Benoit Viguier 3 | -------------------------------------------------------------------------------- /examples/spaceship.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ponup/php-sdl/HEAD/examples/spaceship.bmp -------------------------------------------------------------------------------- /examples/p01_shape24.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ponup/php-sdl/HEAD/examples/p01_shape24.bmp -------------------------------------------------------------------------------- /input-handling-example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ponup/php-sdl/HEAD/input-handling-example.gif -------------------------------------------------------------------------------- /examples/p01_shape32alpha.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ponup/php-sdl/HEAD/examples/p01_shape32alpha.bmp -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | Xvfb :99 -screen 0 800x600x24 -ac & 4 | 5 | chmod +x ./run-tests.php 6 | 7 | export DISPLAY=:99 8 | ./run-tests.php -q --show-diff 9 | 10 | killall -9 Xvfb 11 | -------------------------------------------------------------------------------- /check-files-are-in-package-xml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | for i in *.c *.h examples/*.php tests/*.phpt 3 | do 4 | j=$(basename $i) 5 | if [ $j != config.h ]; then 6 | grep -q "['\"]$j['\"]" package.xml || echo Missing $i 7 | fi 8 | done 9 | 10 | -------------------------------------------------------------------------------- /examples/002-error-messagebox.php: -------------------------------------------------------------------------------- 1 | 12 | SUITE: End 13 | --EXPECTF-- 14 | SUITE: Start 15 | bool(false) 16 | bool(true) 17 | SUITE: End 18 | -------------------------------------------------------------------------------- /tests/027-joystick.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Joystick test suite. 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | --EXPECTF-- 16 | = Functions 17 | bool(true) 18 | bool(true) 19 | = Done 20 | 21 | -------------------------------------------------------------------------------- /tests/test-functions.php: -------------------------------------------------------------------------------- 1 | 7 | --FILE-- 8 | 18 | Done 19 | --EXPECTF-- 20 | + start 21 | string(0) "" 22 | + set 23 | int(-1) 24 | string(3) "Foo" 25 | + clear 26 | NULL 27 | string(0) "" 28 | Done 29 | 30 | -------------------------------------------------------------------------------- /tests/026-filesystem.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Tests for functions beloning to the filesystem "module". 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 15 | + Done 16 | --EXPECTF-- 17 | bool(true) 18 | bool(true) 19 | bool(true) 20 | + Done 21 | -------------------------------------------------------------------------------- /examples/001-sdl-version.php: -------------------------------------------------------------------------------- 1 | 0, SDL_INIT_EVERYTHING > 0, 'everything is initialised'); 13 | SDL_Quit(); 14 | assertEquals(SDL_WasInit(), 0, 'everything is shutdown'); 15 | --EXPECTF-- 16 | PASS: nothings is initialised. 17 | PASS: everything is initialised. 18 | PASS: everything is shutdown. 19 | -------------------------------------------------------------------------------- /tests/022-pixels.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Pixels test 3 | --SKIPIF-- 4 | getMessage() . "\n"; 15 | } 16 | var_dump($pix = new SDL_Pixels(10, 10), "$pix"); 17 | ?> 18 | = Done 19 | --EXPECTF-- 20 | = Create 21 | Exception: Invalid size 22 | 23 | Notice: SDL_Pixels::__construct(): Pitch set to 12 in %s%e022-pixels.php on line 8 24 | object(SDL_Pixels)#%d (0) { 25 | } 26 | string(10) "SDL_Pixels" 27 | = Done 28 | -------------------------------------------------------------------------------- /tests/028-point.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Point test suite 3 | --SKIPIF-- 4 | 18 | SUITE: End 19 | --EXPECTF-- 20 | SUITE: Start 21 | TEST: Subclasses of SDL_Point can be converted properly 22 | SDL_Point(10,20) 23 | TEST: SDL_FPoint to string 24 | SDL_FPoint(22.230000,42.430000) 25 | SUITE: End 26 | -------------------------------------------------------------------------------- /tests/017-rwops-stream.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_RWops test, stream mode 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | size()); 14 | echo "read:"; var_dump($ro->read($buf, $size)==$size, strlen($buf)==$size); 15 | $ro->Free(); 16 | fclose($stream); 17 | ?> 18 | = Done 19 | --CLEAN-- 20 | 23 | --EXPECTF-- 24 | = Read Stream 25 | size:int(20932) 26 | read:bool(true) 27 | bool(true) 28 | = Done 29 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:11 2 | 3 | ARG TARGET_PHP_VERSION=8.1 4 | 5 | RUN apt-get update 6 | RUN apt-get install -y make build-essential wget 7 | RUN apt-get install -y lsb-release apt-transport-https ca-certificates 8 | RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg 9 | RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list 10 | RUN apt-get update 11 | RUN apt-get install -y php${TARGET_PHP_VERSION}-dev 12 | RUN apt-get install -y libsdl2-dev 13 | RUN apt-get install -y xvfb 14 | COPY . /opt/php-sdl 15 | WORKDIR /opt/php-sdl 16 | RUN phpize 17 | RUN ./configure 18 | RUN make 19 | RUN make install 20 | RUN echo "extension=sdl.so" >> /etc/php/${TARGET_PHP_VERSION}/cli/php.ini 21 | 22 | ENTRYPOINT ["/opt/php-sdl/docker-entrypoint.sh"] 23 | 24 | -------------------------------------------------------------------------------- /tests/001-extension-loading.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Extension is loaded. 3 | --SKIPIF-- 4 | getFunctions()); 13 | if($numFunctions) 14 | echo "$numFunctions functions defined", PHP_EOL; 15 | else 16 | echo 'no functions defined', PHP_EOL; 17 | 18 | $numClasses = count($ext->getClasses()); 19 | if($numClasses) 20 | echo "$numClasses classes defined", PHP_EOL; 21 | else 22 | echo 'no functions defined', PHP_EOL; 23 | 24 | $numConstants = count($ext->getConstants()); 25 | if($numConstants) 26 | echo "$numConstants constants defined", PHP_EOL; 27 | else 28 | echo 'no constants defined', PHP_EOL; 29 | --EXPECTF-- 30 | SDL extension version: %s 31 | %d functions defined 32 | %d classes defined 33 | %d constants defined 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.lo 3 | *.la 4 | .deps 5 | *.dep 6 | .libs 7 | Makefile 8 | Makefile.fragments 9 | Makefile.global 10 | Makefile.objects 11 | acinclude.m4 12 | aclocal.m4 13 | autom4te.cache 14 | build 15 | config.cache 16 | config.guess 17 | config.h 18 | config.h.in 19 | config.log 20 | config.nice 21 | config.status 22 | config.sub 23 | configure 24 | configure.in 25 | conftest 26 | conftest.c 27 | include 28 | install-sh 29 | libtool 30 | ltmain.sh 31 | missing 32 | mkinstalldirs 33 | modules 34 | scan_makefile_in.awk 35 | *.dsw 36 | *.plg 37 | *.opt 38 | *.ncb 39 | Release 40 | Release_inline 41 | Debug 42 | Release_TS 43 | Release_TSDbg 44 | Release_TS_inline 45 | Debug_TS 46 | sdl-*.tgz 47 | tmp-php.ini 48 | run-tests.php 49 | *.o 50 | *.loT 51 | tests/*.diff 52 | tests/*.exp 53 | tests/*.log 54 | tests/*.sh 55 | tests/*.out 56 | tests/*.php 57 | nbproject 58 | php_test_results*.txt 59 | configure.ac 60 | .vscode 61 | .DS_Store 62 | tags 63 | *.dep 64 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // vim:ft=javascript 2 | 3 | ARG_ENABLE('sdl', 'Whether to enable SDL2 support', 'no'); 4 | 5 | if(PHP_SDL != 'no') { 6 | CHECK_LIB("SDL2.lib", "sdl", PHP_SDL); 7 | CHECK_LIB("SDL2main.lib", "sdl", PHP_SDL); 8 | CHECK_LIB("SDL2test.lib", "sdl", PHP_SDL); 9 | 10 | var sdl_sources = 'php_sdl.c blendmode.c cpuinfo.c error.c event.c filesystem.c glcontext.c joystick.c keyboard.c messagebox.c mouse.c mutex.c pixels.c platform.c power.c rect.c render.c rwops.c sdl.c shape.c surface.c timer.c version.c video.c window.c'; 11 | 12 | EXTENSION('sdl', sdl_sources, PHP_SDL_SHARED); 13 | 14 | var sdl_headers = 'php_sdl.h blendmode.h cpuinfo.h error.h event.h filesystem.h glcontext.h joystick.h keyboard.h messagebox.h mouse.h mutex.h pixels.h platform.h power.h rect.h render.h rwops.h sdl.h shape.h surface.h timer.h version.h video.h window.h'; 15 | 16 | PHP_INSTALL_HEADERS('ext/sdl', sdl_headers); 17 | AC_DEFINE('HAVE_SDL', 1); 18 | } 19 | -------------------------------------------------------------------------------- /examples/004-draw-points.php: -------------------------------------------------------------------------------- 1 | type == SDL_QUIT) { 29 | break; 30 | } 31 | } 32 | 33 | SDL_DestroyRenderer($renderer); 34 | SDL_DestroyWindow($window); 35 | SDL_Quit(); 36 | -------------------------------------------------------------------------------- /tests/003-init-and-quit-subsystems.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Subsystems can be init and shutdown. 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | = -1); 22 | var_dump($pct >= -1 && $pct <= 100); 23 | 24 | echo '= Done', PHP_EOL; 25 | ?> 26 | --EXPECTF-- 27 | = Constants 28 | bool(true) 29 | bool(true) 30 | bool(true) 31 | bool(true) 32 | bool(true) 33 | = Functions 34 | bool(true) 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | = Done 39 | -------------------------------------------------------------------------------- /examples/005-draw-rectangle.php: -------------------------------------------------------------------------------- 1 | type == SDL_QUIT) $quit = true; 33 | } 34 | } 35 | 36 | SDL_DestroyRenderer($renderer); 37 | SDL_DestroyWindow($window); 38 | SDL_Quit(); 39 | 40 | -------------------------------------------------------------------------------- /examples/008-shaped-window.php: -------------------------------------------------------------------------------- 1 | type, [SDL_QUIT, SDL_MOUSEBUTTONDOWN]); 34 | } 35 | 36 | SDL_Delay(20); 37 | } 38 | 39 | SDL_DestroyRenderer($renderer); 40 | SDL_DestroyWindow($window); 41 | SDL_Quit(); 42 | -------------------------------------------------------------------------------- /examples/003-messagebox-inputs.php: -------------------------------------------------------------------------------- 1 | new SDL_MessageBoxColor(0, 0, 0), 19 | SDL_MessageBoxColor::TEXT => new SDL_MessageBoxColor(255, 255, 255), 20 | SDL_MessageBoxColor::BUTTON_BORDER => new SDL_MessageBoxColor(255, 0, 0), 21 | SDL_MessageBoxColor::BUTTON_BACKGROUND => new SDL_MessageBoxColor(0, 255, 0), 22 | SDL_MessageBoxColor::BUTTON_SELECTED => new SDL_MessageBoxColor(0, 0, 255), 23 | ]; 24 | $dialog = new SDL_MessageBoxData(SDL_MessageBoxData::INFORMATION, "Message box data", 'Select Yes or No', $buttons, $colors); 25 | if(0 === $dialog->Show($buttonId)) { 26 | echo 'Button selection: ', $buttonId === BUTTON_ID_YES ? 'Yes' : 'No', PHP_EOL; 27 | } else { 28 | printSdlErrorAndExit(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/010-draw-lines.php: -------------------------------------------------------------------------------- 1 | 0; ++$iteration) { 24 | $side = $iteration % 4; 25 | $sign = $side < 2 ? 1 : -1; 26 | 27 | $x2 = $side % 2 ? $x1 + $sign * $offset : $x1; 28 | $y2 = $side % 2 ? $y1 : $y1 + $sign * $offset; 29 | 30 | SDL_RenderDrawLine($renderer, $x1, $y1, $x2, $y2); 31 | 32 | $x1 = $x2; 33 | $y1 = $y2; 34 | $offset -= 10; 35 | } 36 | SDL_RenderPresent($renderer); 37 | 38 | // Wait for quit event 39 | $event = new SDL_Event; 40 | while (true) { 41 | if (SDL_PollEvent($event) && $event->type == SDL_QUIT) { 42 | break; 43 | } 44 | } 45 | 46 | SDL_DestroyRenderer($renderer); 47 | SDL_DestroyWindow($window); 48 | SDL_Quit(); 49 | -------------------------------------------------------------------------------- /tests/004-cpuinfo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | cpuinfo group test 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 22 | Done 23 | --EXPECTF-- 24 | SDL_GetCPUCount: int(%d) 25 | SDL_GetCPUCacheLineSize: int(%d) 26 | SDL_HasRDTSC: int(%d) 27 | SDL_HasAltiVec: int(%d) 28 | SDL_HasMMX: int(%d) 29 | SDL_Has3DNow: int(%d) 30 | SDL_HasSSE: int(%d) 31 | SDL_HasSSE2: int(%d) 32 | SDL_HasSSE3: int(%d) 33 | SDL_HasSSE41: int(%d) 34 | SDL_HasSSE42: int(%d) 35 | SDL_GetSystemRAM: int(%d) 36 | Done 37 | -------------------------------------------------------------------------------- /src/blendmode.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_BLENDMODE_H 20 | #define PHP_SDL_BLENDMODE_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | PHP_MINIT_FUNCTION(sdl_blendmode); 29 | 30 | #ifdef __cplusplus 31 | } // extern "C" 32 | #endif 33 | 34 | #endif /* PHP_SDL_BLENDMODE_H */ 35 | 36 | -------------------------------------------------------------------------------- /tests/010-palette.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Palette test, procedural mode 3 | --SKIPIF-- 4 | colors[0]); 14 | $colors = array(new SDL_Color(1,2,3,4)); 15 | var_dump(SDL_SetPaletteColors($p2, $colors, 2)); 16 | var_dump(SDL_SetPaletteColors($p2, $colors, 0)); 17 | var_dump($p2->colors[0]); 18 | echo "= Free\n"; 19 | SDL_FreePalette($p2); 20 | ?> 21 | = Done 22 | --EXPECTF-- 23 | = Alloc 24 | NULL 25 | object(SDL_Palette)#%d (4) { 26 | ["ncolors"]=> 27 | int(1) 28 | ["version"]=> 29 | int(1) 30 | ["refcount"]=> 31 | int(1) 32 | ["colors"]=> 33 | array(1) { 34 | [0]=> 35 | object(SDL_Color)#%d (4) { 36 | ["r"]=> 37 | int(255) 38 | ["g"]=> 39 | int(255) 40 | ["b"]=> 41 | int(255) 42 | ["a"]=> 43 | int(255) 44 | } 45 | } 46 | } 47 | = Color 48 | object(SDL_Color)#%d (4) { 49 | ["r"]=> 50 | int(255) 51 | ["g"]=> 52 | int(255) 53 | ["b"]=> 54 | int(255) 55 | ["a"]=> 56 | int(255) 57 | } 58 | 59 | %s: SDL_SetPaletteColors(): Invalid first color index, 2 >= 1 in %s/010-palette.php on line 9 60 | int(-1) 61 | int(0) 62 | object(SDL_Color)#%d (4) { 63 | ["r"]=> 64 | int(1) 65 | ["g"]=> 66 | int(2) 67 | ["b"]=> 68 | int(3) 69 | ["a"]=> 70 | int(4) 71 | } 72 | = Free 73 | = Done 74 | -------------------------------------------------------------------------------- /tests/014-version.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_version test suite 3 | --SKIPIF-- 4 | 0); 13 | var_dump(is_integer(SDL_MAJOR_VERSION)); 14 | var_dump(SDL_MAJOR_VERSION > 0); 15 | var_dump(is_integer(SDL_MINOR_VERSION)); 16 | var_dump(SDL_MINOR_VERSION >= 0); 17 | var_dump(is_integer(SDL_PATCHLEVEL)); 18 | var_dump(SDL_PATCHLEVEL >= 0); 19 | var_dump(empty(SDL_REVISION)); 20 | var_dump(is_string(SDL_REVISION)); 21 | 22 | echo '= Functions', PHP_EOL; 23 | SDL_VERSION($version); 24 | var_dump(array_key_exists('major', $version) && array_key_exists('minor', $version) && array_key_exists('patch', $version)); 25 | var_dump(12030 === SDL_VERSIONNUM(10,20,30)); 26 | var_dump(SDL_VERSION_ATLEAST(2,0,25)); 27 | var_dump(is_string(SDL_GetRevision())); 28 | SDL_GetVersion($linkedVersion); 29 | var_dump(array_key_exists('major', $linkedVersion) && array_key_exists('minor', $linkedVersion) && array_key_exists('patch', $linkedVersion)); 30 | 31 | echo '= Done', PHP_EOL; 32 | ?> 33 | --EXPECTF-- 34 | = Constants 35 | bool(true) 36 | bool(true) 37 | bool(true) 38 | bool(true) 39 | bool(true) 40 | bool(true) 41 | bool(true) 42 | bool(true) 43 | bool(false) 44 | bool(true) 45 | = Functions 46 | bool(true) 47 | bool(true) 48 | bool(true) 49 | bool(true) 50 | bool(true) 51 | = Done 52 | -------------------------------------------------------------------------------- /src/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #include "php_sdl.h" 19 | #include "timer.h" 20 | #include "window.h" 21 | 22 | PHP_FUNCTION(SDL_Delay) 23 | { 24 | zend_long ms; 25 | 26 | ZEND_PARSE_PARAMETERS_START(1, 1) 27 | Z_PARAM_LONG(ms) 28 | ZEND_PARSE_PARAMETERS_END(); 29 | 30 | SDL_Delay((Uint32)ms); 31 | } 32 | 33 | /* {{{ MINIT */ 34 | PHP_MINIT_FUNCTION(sdl_timer) 35 | { 36 | return SUCCESS; 37 | } 38 | /* }}} */ 39 | -------------------------------------------------------------------------------- /examples/006-animated-boxes.php: -------------------------------------------------------------------------------- 1 | format, 0xff, 0x87, 0xef); 15 | 16 | // Compute rects 17 | $rects = []; 18 | for ($t = $time * $step; $t; $t--) { 19 | $rects[$time * $step - $t] = new SDL_Rect(35 + ($time * $step + 1 - $t) * 15, 20, 10, 10); 20 | } 21 | // Display rects in ~white 22 | $surf->FillRects($rects, count($rects), $color); 23 | 24 | SDL_UpdateWindowSurface($window); 25 | 26 | $cursor = SDL_Cursor::CreateSystem(SDL_Cursor::HAND); 27 | $cursor->Set(); 28 | 29 | $event = new SDL_Event; 30 | 31 | $color = SDL_MapRGB($surf->format, 0xef, 0xff, 0x87); 32 | for ($t = $time * $step; $t; $t--) { 33 | 34 | if (!($t % $step)) { 35 | $secondsLeft = $t / $step; 36 | SDL_SetWindowTitle($window, "Will be closed in $secondsLeft seconds"); 37 | } 38 | 39 | // Display 1 rect in ~red 40 | $surf->FillRect($rects[$time * $step - $t], $color); 41 | SDL_UpdateWindowSurfaceRects($window, array($rects[$time * $step - $t])); 42 | 43 | usleep(1000000 / $step); 44 | 45 | while (SDL_PollEvent($event)) { 46 | if ($event->type == SDL_QUIT) break; 47 | } 48 | } 49 | 50 | SDL_DestroyWindow($window); 51 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_SDL_TIMER_H 19 | #define PHP_SDL_TIMER_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Delay, 0, 0, 1) 26 | ZEND_ARG_INFO(0, ms) 27 | ZEND_END_ARG_INFO() 28 | 29 | PHP_FUNCTION(SDL_Delay); 30 | 31 | PHP_MINIT_FUNCTION(sdl_timer); 32 | 33 | #ifdef __cplusplus 34 | } // extern "C" 35 | #endif 36 | 37 | #endif /* PHP_SDL_TIMER_H */ 38 | 39 | -------------------------------------------------------------------------------- /src/platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #include "platform.h" 19 | 20 | /* {{{ proto string SDL_GetPlatform(void) 21 | 22 | * \brief Gets the name of the platform. 23 | */ 24 | PHP_FUNCTION(SDL_GetPlatform) 25 | { 26 | if (zend_parse_parameters_none() == FAILURE) { 27 | RETURN_FALSE; 28 | } 29 | 30 | RETURN_STRING(SDL_GetPlatform()); 31 | } 32 | 33 | /* {{{ MINIT */ 34 | PHP_MINIT_FUNCTION(sdl_platform) 35 | { 36 | return SUCCESS; 37 | } 38 | /* }}} */ 39 | -------------------------------------------------------------------------------- /src/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_PLATFORM_H 20 | #define PHP_SDL_PLATFORM_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetPlatform, 0, 0, 0) 29 | ZEND_END_ARG_INFO() 30 | 31 | PHP_FUNCTION(SDL_GetPlatform); 32 | 33 | PHP_MINIT_FUNCTION(sdl_platform); 34 | 35 | #ifdef __cplusplus 36 | } // extern "C" 37 | #endif 38 | 39 | #endif /* PHP_SDL_PLATFORM_H */ 40 | 41 | -------------------------------------------------------------------------------- /src/power.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_POWER_H 20 | #define PHP_SDL_POWER_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetPowerInfo, 0, 0, 0) 29 | ZEND_ARG_INFO(1, secs) 30 | ZEND_ARG_INFO(1, pct) 31 | ZEND_END_ARG_INFO() 32 | 33 | PHP_FUNCTION(SDL_GetPowerInfo); 34 | 35 | PHP_MINIT_FUNCTION(sdl_power); 36 | 37 | #ifdef __cplusplus 38 | } // extern "C" 39 | #endif 40 | 41 | #endif /* PHP_SDL_POWER_H */ 42 | 43 | -------------------------------------------------------------------------------- /tests/009-color.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Color test 3 | --SKIPIF-- 4 | 25 | Done 26 | --EXPECTF-- 27 | Color 28 | object(SDL_Color)#1 (4) { 29 | ["r"]=> 30 | int(1) 31 | ["g"]=> 32 | int(63) 33 | ["b"]=> 34 | int(127) 35 | ["a"]=> 36 | int(255) 37 | } 38 | object(SDL_Color)#2 (4) { 39 | ["r"]=> 40 | int(0) 41 | ["g"]=> 42 | int(255) 43 | ["b"]=> 44 | int(0) 45 | ["a"]=> 46 | int(64) 47 | } 48 | Name 49 | string(23) "SDL_PIXELFORMAT_UNKNOWN" 50 | string(24) "SDL_PIXELFORMAT_RGBA4444" 51 | string(20) "SDL_PIXELFORMAT_YVYU" 52 | string(23) "SDL_PIXELFORMAT_UNKNOWN" 53 | Mask 54 | bool(true) 55 | int(356651010) 56 | int(16) 57 | int(61440) 58 | int(3840) 59 | int(240) 60 | int(15) 61 | int(356651010) 62 | string(24) "SDL_PIXELFORMAT_RGBA4444" 63 | int(373694468) 64 | string(24) "SDL_PIXELFORMAT_RGBA8888" 65 | Done 66 | -------------------------------------------------------------------------------- /src/shape.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_SHAPE_H 20 | #define PHP_SDL_SHAPE_H 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | #include "php_sdl.h" 29 | 30 | zend_class_entry *get_php_sdl_windowshapemode_ce(void); 31 | zend_bool sdl_windowshapemode_to_zval(SDL_WindowShapeMode *mode, zval *z_val); 32 | SDL_WindowShapeMode *zval_to_sdl_windowshapemode(zval *z_val); 33 | 34 | 35 | PHP_MINIT_FUNCTION(sdl_shape); 36 | 37 | #ifdef __cplusplus 38 | } // extern "C" 39 | #endif 40 | 41 | #endif /* PHP_SDL_SHAPE_H */ 42 | 43 | -------------------------------------------------------------------------------- /src/blendmode.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #include "blendmode.h" 20 | 21 | /* {{{ MINIT */ 22 | PHP_MINIT_FUNCTION(sdl_blendmode) 23 | { 24 | REGISTER_LONG_CONSTANT("SDL_BLENDMODE_NONE", SDL_BLENDMODE_NONE, CONST_CS | CONST_PERSISTENT); 25 | REGISTER_LONG_CONSTANT("SDL_BLENDMODE_BLEND", SDL_BLENDMODE_BLEND, CONST_CS | CONST_PERSISTENT); 26 | REGISTER_LONG_CONSTANT("SDL_BLENDMODE_ADD", SDL_BLENDMODE_ADD, CONST_CS | CONST_PERSISTENT); 27 | REGISTER_LONG_CONSTANT("SDL_BLENDMODE_MOD", SDL_BLENDMODE_MOD, CONST_CS | CONST_PERSISTENT); 28 | 29 | return SUCCESS; 30 | } 31 | /* }}} */ 32 | -------------------------------------------------------------------------------- /src/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_ERROR_H 20 | #define PHP_SDL_ERROR_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | PHP_FUNCTION(SDL_SetError); 29 | PHP_FUNCTION(SDL_GetError); 30 | PHP_FUNCTION(SDL_ClearError); 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetError, 0, 0, 1) 33 | ZEND_ARG_INFO(0, error_message) 34 | ZEND_END_ARG_INFO() 35 | 36 | ZEND_BEGIN_ARG_INFO_EX(arginfo_error_none, 0, 0, 0) 37 | ZEND_END_ARG_INFO() 38 | 39 | PHP_MINIT_FUNCTION(sdl_error); 40 | 41 | #ifdef __cplusplus 42 | } // extern "C" 43 | #endif 44 | 45 | #endif /* PHP_SDL_ERROR_H */ 46 | 47 | -------------------------------------------------------------------------------- /src/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_FILESYSTEM_H 20 | #define PHP_SDL_FILESYSTEM_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetPrefPath, 0, 0, 2) 27 | ZEND_ARG_INFO(0, org) 28 | ZEND_ARG_INFO(0, app) 29 | ZEND_END_ARG_INFO() 30 | 31 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetBasePath, 0, 0, 0) 32 | ZEND_END_ARG_INFO() 33 | 34 | PHP_FUNCTION(SDL_GetPrefPath); 35 | PHP_FUNCTION(SDL_GetBasePath); 36 | 37 | PHP_MINIT_FUNCTION(sdl_filesystem); 38 | 39 | #ifdef __cplusplus 40 | } // extern "C" 41 | #endif 42 | 43 | #endif /* PHP_SDL_FILESYSTEM_H */ 44 | 45 | -------------------------------------------------------------------------------- /tests/024-mutex.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mutex group test, procedural mode 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 46 | + Done 47 | --EXPECTF-- 48 | ++ Mutex 49 | + Create 50 | object(SDL_mutex)#%d (0) { 51 | } 52 | + TryLock/Unlock 53 | int(0) 54 | int(0) 55 | + Lock/Unlock 56 | int(0) 57 | int(0) 58 | + Unlock 59 | int(0) 60 | + Destroy 61 | NULL 62 | object(SDL_mutex)#%d (0) { 63 | } 64 | ++ Semaphore 65 | + Create 66 | object(SDL_sem)#%d (0) { 67 | } 68 | + WaitTimeout 69 | int(1) 70 | + Post 71 | int(0) 72 | + Value 73 | int(1) 74 | + WaitTimeout 75 | int(0) 76 | + TryWait 77 | int(1) 78 | + Post 79 | int(0) 80 | + Wait 81 | int(0) 82 | + Destroy 83 | NULL 84 | object(SDL_sem)#%d (0) { 85 | } 86 | + Done 87 | -------------------------------------------------------------------------------- /tests/025-mutex-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mutex group test, object mode 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | TryLock()); 15 | var_dump($m->Unlock()); 16 | echo "+ Lock/Unlock\n"; 17 | var_dump($m->Lock()); 18 | var_dump($m->Unlock()); 19 | echo "+ Unlock\n"; 20 | var_dump($m->Unlock()); 21 | echo "+ Destroy\n"; 22 | var_dump($m->Destroy(), $m, "$m"); 23 | 24 | echo "++ Semaphore\n"; 25 | echo "+ Create\n"; 26 | var_dump($s=new SDL_sem(0), "$s"); 27 | echo "+ WaitTimeout\n", 28 | var_dump($s->WaitTimeout(10)); 29 | echo "+ Post\n", 30 | var_dump($s->Post()); 31 | echo "+ Value\n", 32 | var_dump($s->Value()); 33 | echo "+ WaitTimeout\n", 34 | var_dump($s->WaitTimeout(10)); 35 | echo "+ TryWait\n", 36 | var_dump($s->TryWait()); 37 | echo "+ Post\n", 38 | var_dump($s->Post()); 39 | echo "+ Wait\n", 40 | var_dump($s->Wait()); 41 | echo "+ Destroy\n"; 42 | var_dump(SDL_DestroySemaphore($s), $s, "$s"); 43 | 44 | ?> 45 | + Done 46 | --EXPECTF-- 47 | ++ Mutex 48 | + Create 49 | object(SDL_mutex)#%d (0) { 50 | } 51 | string(23) "SDL_mutex(%s)" 52 | + TryLock/Unlock 53 | int(0) 54 | int(0) 55 | + Lock/Unlock 56 | int(0) 57 | int(0) 58 | + Unlock 59 | int(0) 60 | + Destroy 61 | NULL 62 | object(SDL_mutex)#%d (0) { 63 | } 64 | string(11) "SDL_mutex()" 65 | ++ Semaphore 66 | + Create 67 | object(SDL_sem)#%d (0) { 68 | } 69 | string(21) "SDL_sem(%s)" 70 | + WaitTimeout 71 | int(1) 72 | + Post 73 | int(0) 74 | + Value 75 | int(1) 76 | + WaitTimeout 77 | int(0) 78 | + TryWait 79 | int(1) 80 | + Post 81 | int(0) 82 | + Wait 83 | int(0) 84 | + Destroy 85 | NULL 86 | object(SDL_sem)#%d (0) { 87 | } 88 | string(9) "SDL_sem()" 89 | + Done 90 | -------------------------------------------------------------------------------- /src/cpuinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_CPUINFO_H 20 | #define PHP_SDL_CPUINFO_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | PHP_FUNCTION(SDL_GetCPUCount); 29 | PHP_FUNCTION(SDL_GetCPUCacheLineSize); 30 | PHP_FUNCTION(SDL_HasRDTSC); 31 | PHP_FUNCTION(SDL_HasAltiVec); 32 | PHP_FUNCTION(SDL_HasMMX); 33 | PHP_FUNCTION(SDL_Has3DNow); 34 | PHP_FUNCTION(SDL_HasSSE); 35 | PHP_FUNCTION(SDL_HasSSE2); 36 | PHP_FUNCTION(SDL_HasSSE3); 37 | PHP_FUNCTION(SDL_HasSSE41); 38 | PHP_FUNCTION(SDL_HasSSE42); 39 | PHP_FUNCTION(SDL_GetSystemRAM); 40 | 41 | /* generic arginfo */ 42 | ZEND_BEGIN_ARG_INFO_EX(arginfo_cpuinfo_none, 0, 0, 0) 43 | ZEND_END_ARG_INFO() 44 | 45 | PHP_MINIT_FUNCTION(sdl_cpuinfo); 46 | 47 | #ifdef __cplusplus 48 | } // extern "C" 49 | #endif 50 | 51 | #endif /* PHP_SDL_CPUINFO_H */ 52 | 53 | -------------------------------------------------------------------------------- /src/rect.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_RECT_H 20 | #define PHP_SDL_RECT_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_point_ce(void); 29 | zend_bool sdl_point_to_zval(SDL_Point *pt, zval *value); 30 | zend_bool zval_to_sdl_point(zval *value, SDL_Point *pt); 31 | 32 | zend_class_entry *get_php_sdl_rect_ce(void); 33 | zend_bool sdl_rect_to_zval(SDL_Rect *rect, zval *value); 34 | zend_bool zval_to_sdl_rect(zval *value, SDL_Rect *rect); 35 | 36 | zend_class_entry *get_php_sdl_frect_ce(void); 37 | zend_bool zval_to_sdl_frect(zval *value, SDL_FRect *rect); 38 | 39 | zend_class_entry *get_php_sdl_fpoint_ce(void); 40 | zend_bool zval_to_sdl_fpoint(zval *value, SDL_FPoint *rect); 41 | 42 | PHP_MINIT_FUNCTION(sdl_rect); 43 | PHP_MSHUTDOWN_FUNCTION(sdl_rect); 44 | 45 | #ifdef __cplusplus 46 | } // extern "C" 47 | #endif 48 | 49 | #endif /* PHP_SDL_RECT_H */ 50 | 51 | -------------------------------------------------------------------------------- /src/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_SDL_EVENT_H 19 | #define PHP_SDL_EVENT_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "php_sdl.h" 26 | 27 | zend_class_entry *get_php_sdl_event_ce(void); 28 | zend_bool sdl_event_to_zval(SDL_Event *event, zval *value); 29 | zend_bool zval_to_sdl_event(zval *value, SDL_Event *event); 30 | void php_sdl_touchfingerevent_to_zval(SDL_TouchFingerEvent *event, zval *value); 31 | extern zend_class_entry *sdlTouchFingerEvent_ce; // déclaration externe 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PollEvent, 0, 0, 1) 33 | ZEND_ARG_OBJ_INFO(1, event, SDL_Event, 0) 34 | ZEND_END_ARG_INFO() 35 | 36 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_WaitEvent, 0, 0, 1) 37 | ZEND_ARG_OBJ_INFO(1, event, SDL_Event, 0) 38 | ZEND_END_ARG_INFO() 39 | 40 | PHP_FUNCTION(SDL_PollEvent); 41 | PHP_FUNCTION(SDL_WaitEvent); 42 | 43 | PHP_MINIT_FUNCTION(sdl_event); 44 | 45 | #ifdef __cplusplus 46 | } // extern "C" 47 | #endif 48 | 49 | #endif /* PHP_SDL_EVENT_H */ 50 | 51 | -------------------------------------------------------------------------------- /tests/011-palette-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Palette test, object mode 3 | --SKIPIF-- 4 | getMessage(), "\n"; 13 | } 14 | $p2 = new SDL_Palette(1); 15 | var_dump($p2); 16 | echo "= Color\n"; 17 | var_dump($p2->colors[0]); 18 | $colors = array(new SDL_Color(1,2,3,4)); 19 | var_dump($p2->SetColors($colors, 2)); 20 | var_dump($p2->SetColors($colors, 0)); 21 | var_dump($p2->colors[0]); 22 | echo "= Array\n"; 23 | var_dump($p2->count()); 24 | $p2[0] = new SDL_Color(7,8,9,0); 25 | var_dump($p2[0]); 26 | unset($p2[0]); 27 | var_dump($p2[0]); 28 | echo "= Free\n"; 29 | $p2->Free() 30 | ?> 31 | = Done 32 | --EXPECTF-- 33 | = Alloc 34 | Parameter 'ncolors' is invalid 35 | object(SDL_Palette)#%d (4) { 36 | ["ncolors"]=> 37 | int(1) 38 | ["version"]=> 39 | int(1) 40 | ["refcount"]=> 41 | int(1) 42 | ["colors"]=> 43 | array(1) { 44 | [0]=> 45 | object(SDL_Color)#%d (4) { 46 | ["r"]=> 47 | int(255) 48 | ["g"]=> 49 | int(255) 50 | ["b"]=> 51 | int(255) 52 | ["a"]=> 53 | int(255) 54 | } 55 | } 56 | } 57 | = Color 58 | object(SDL_Color)#%d (4) { 59 | ["r"]=> 60 | int(255) 61 | ["g"]=> 62 | int(255) 63 | ["b"]=> 64 | int(255) 65 | ["a"]=> 66 | int(255) 67 | } 68 | 69 | %s: SDL_Palette::SetColors(): Invalid first color index, 2 >= 1 in %s/011-palette-oo.php on line 13 70 | int(-1) 71 | int(0) 72 | object(SDL_Color)#%d (4) { 73 | ["r"]=> 74 | int(1) 75 | ["g"]=> 76 | int(2) 77 | ["b"]=> 78 | int(3) 79 | ["a"]=> 80 | int(4) 81 | } 82 | = Array 83 | int(1) 84 | object(SDL_Color)#%d (4) { 85 | ["r"]=> 86 | int(7) 87 | ["g"]=> 88 | int(8) 89 | ["b"]=> 90 | int(9) 91 | ["a"]=> 92 | int(0) 93 | } 94 | object(SDL_Color)#%d (4) { 95 | ["r"]=> 96 | int(0) 97 | ["g"]=> 98 | int(0) 99 | ["b"]=> 100 | int(0) 101 | ["a"]=> 102 | int(0) 103 | } 104 | = Free 105 | = Done 106 | -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #include "error.h" 20 | 21 | /* {{{ proto int SDL_SetError(string error) 22 | 23 | * SDL_SetError() unconditionally returns -1. 24 | extern DECLSPEC int SDLCALL SDL_SetError(const char *fmt, ...); 25 | */ 26 | PHP_FUNCTION(SDL_SetError) { 27 | char *error; 28 | size_t error_len; 29 | 30 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &error, &error_len) == FAILURE) { 31 | RETURN_FALSE; 32 | } 33 | 34 | RETURN_LONG(SDL_SetError("%s", error)); 35 | } 36 | /* }}} */ 37 | 38 | /* {{{ proto string SDL_GetError(void) 39 | 40 | extern DECLSPEC const char *SDLCALL SDL_GetError(void); 41 | */ 42 | PHP_FUNCTION(SDL_GetError) { 43 | const char *error; 44 | 45 | if (zend_parse_parameters_none() == FAILURE) { 46 | RETURN_FALSE; 47 | } 48 | 49 | error = SDL_GetError(); 50 | if (error) { 51 | RETURN_STRING(error); 52 | } 53 | } 54 | /* }}} */ 55 | 56 | 57 | /* {{{ proto string SDL_ClearError(void) 58 | 59 | extern DECLSPEC void SDLCALL SDL_ClearError(void); 60 | */ 61 | PHP_FUNCTION(SDL_ClearError) { 62 | 63 | if (zend_parse_parameters_none() == FAILURE) { 64 | RETURN_FALSE; 65 | } 66 | 67 | SDL_ClearError(); 68 | } 69 | /* }}} */ 70 | 71 | /* {{{ MINIT */ 72 | PHP_MINIT_FUNCTION(sdl_error) 73 | { 74 | return SUCCESS; 75 | } 76 | /* }}} */ 77 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_VERSION_H 20 | #define PHP_SDL_VERSION_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | zend_bool convert_sdl_version_to_php_array(SDL_version *version, zval *version_array); 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_sdl_version_none, 0, 0, 0) 29 | ZEND_END_ARG_INFO() 30 | 31 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetVersion, 0, 0, 1) 32 | ZEND_ARG_INFO(1, version) 33 | ZEND_END_ARG_INFO() 34 | 35 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_VERSION, 0, 0, 1) 36 | ZEND_ARG_INFO(1, version) 37 | ZEND_END_ARG_INFO() 38 | 39 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_VERSIONNUM, 0, 0, 3) 40 | ZEND_ARG_INFO(0, x) 41 | ZEND_ARG_INFO(0, y) 42 | ZEND_ARG_INFO(0, z) 43 | ZEND_END_ARG_INFO() 44 | 45 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_VERSION_ATLEAST, 0, 0, 3) 46 | ZEND_ARG_INFO(0, x) 47 | ZEND_ARG_INFO(0, y) 48 | ZEND_ARG_INFO(0, z) 49 | ZEND_END_ARG_INFO() 50 | 51 | PHP_FUNCTION(SDL_GetRevision); 52 | #ifdef HAVE_SDL_GETREVISIONNUMBER 53 | PHP_FUNCTION(SDL_GetRevisionNumber); 54 | #endif 55 | PHP_FUNCTION(SDL_GetVersion); 56 | PHP_FUNCTION(SDL_VERSION); 57 | PHP_FUNCTION(SDL_VERSIONNUM); 58 | PHP_FUNCTION(SDL_VERSION_ATLEAST); 59 | 60 | PHP_MINIT_FUNCTION(sdl_version); 61 | 62 | #ifdef __cplusplus 63 | } // extern "C" 64 | #endif 65 | 66 | #endif /* PHP_SDL_VERSION_H */ 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build and test](https://github.com/Ponup/php-sdl/actions/workflows/build-test.yml/badge.svg)](https://github.com/Ponup/php-sdl/actions/workflows/build-test.yml) 2 | 3 | PHP-SDL 4 | ======= 5 | 6 | SDL (Simple DirectMedia Layer) bindings for the PHP language. The extension allows you to create multimedia desktop applications with windows, input handling, events, and more. 7 | 8 | [](input-handling-example.gif) 9 | 10 | ## Installation 11 | 12 | ### Requirements 13 | 14 | * C compiler 15 | * Automake tools 16 | * PHP8.1 devel 17 | * libSDL2 devel libraries and headers 18 | * UN*X OS (eg Linux, Macos) 19 | 20 | ### Via PECL 21 | 22 | ```bash 23 | pecl install sdl-beta 24 | ``` 25 | 26 | Then add 27 | 28 | ``` 29 | extension=sdl.so 30 | ``` 31 | to your _php.ini_ file. 32 | 33 | > If you have no idea about your ini file position you can run `php -i | grep ini` and see the list of you ini files. 34 | 35 | ## Documentation 36 | 37 | The SDL extension mimics in almost every single aspect to the official C library, so until we write our own documentation, refer to the [C counterpart](https://wiki.libsdl.org/APIByCategory). 38 | 39 | ## Examples 40 | 41 | Standard SDL2 API is available in procedural style: 42 | 43 | ```php 44 | $window = SDL_CreateWindow( "Foo window", 500, 50, 350, 300, SDL_WINDOW_SHOWN+SDL_WINDOW_RESIZABLE); 45 | SDL_SetWindowTitle($window, "Some new title"); 46 | SDL_DestroyWindow($window); 47 | ``` 48 | 49 | Complete examples can be found in the [examples](examples) folder. 50 | 51 | ## Related projects 52 | 53 | * [PHP-SDL_TTF](https://github.com/Ponup/php-sdl-ttf) 54 | * [PHP-SDL_Mixer](https://github.com/kea/php-sdl-mixer) 55 | * [PHP-SDL_Image](https://github.com/kea/php-sdl-image) 56 | * [PHP-OpenGL](https://github.com/ponup/php-opengl) 57 | * [PHP-OpenAL](https://github.com/Ponup/php-openal) 58 | 59 | ## Projects using the extension 60 | 61 | * [CubeCraft](https://github.com/Ponup/cubecraft) 62 | * [Conway's game of life](https://github.com/Ponup/conways-game-of-life) 63 | * [PhpOkoban](https://github.com/b-viguier/PhpOkoban) 64 | * [Inphpinity](https://github.com/b-viguier/Inphpinity) 65 | * [PhPresent](https://github.com/b-viguier/PhPresent) 66 | 67 | ## Building 68 | 69 | To compile your new extension, you will have to execute the following steps: 70 | 71 | ```bash 72 | phpize 73 | ./configure [--with--sdl] 74 | make 75 | make test 76 | sudo make install 77 | ``` 78 | 79 | -------------------------------------------------------------------------------- /tests/015-rwops.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_RWops test, procedural mode 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | size()); 41 | echo "seek:"; var_dump($rm->seek(0, RW_SEEK_SET)); 42 | echo "tell:"; var_dump($rm->tell()); 43 | printf("read8: %x\n", SDL_ReadU8($rm)); 44 | printf("readLE16: %x\n", SDL_ReadLE16($rm)); 45 | printf("readBE16: %x\n", SDL_ReadBE16($rm)); 46 | printf("readBE32: %x\n", SDL_ReadLE32($rm)); 47 | printf("readBE32: %x\n", SDL_ReadBE32($rm)); 48 | SDL_FreeRW($rm); 49 | 50 | ?> 51 | = Done 52 | --CLEAN-- 53 | 56 | --EXPECTF-- 57 | = Create file 58 | write:int(16) 59 | = Read file 60 | size:int(16) 61 | seek:int(0) 62 | tell:int(0) 63 | read:int(16) 64 | string(16) "Hello SDL2 world" 65 | = Write memory 66 | 67 | %s: SDL_RWFromMem(): this function may raised unsupported error with PHP memory in %s/015-rwops.php on line %d 68 | Buffer:100 69 | write:int(1) 70 | write:int(3) 71 | write:int(5) 72 | write:int(9) 73 | write:int(13) 74 | Buffer:100 75 | Content:90341256787856341212345678 76 | = Read memory 77 | size:int(100) 78 | seek:int(0) 79 | tell:int(0) 80 | read8: 90 81 | readLE16: 1234 82 | readBE16: 5678 83 | readBE32: 12345678 84 | readBE32: 12345678 85 | = Done 86 | -------------------------------------------------------------------------------- /tests/005-video.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | video group test 3 | --SKIPIF-- 4 | 32 | Done 33 | --EXPECTF-- 34 | == VideoDriver == 35 | int(%d) 36 | string(%d) "%s" 37 | bool(false) 38 | == Video OFF == 39 | bool(false) 40 | int(0) 41 | == Video ON == 42 | SDL_VideoInit():int(0) 43 | SDL_GetCurrentVideoDriver():string(%d) "%s" 44 | SDL_GetNumVideoDisplays():int(%d) 45 | SDL_GetDisplayName(0):string(%d) "%s" 46 | SDL_GetDisplayBounds(0):int(0) 47 | object(SDL_Rect)#1 (4) { 48 | ["x"]=> 49 | int(0) 50 | ["y"]=> 51 | int(0) 52 | ["w"]=> 53 | int(%d) 54 | ["h"]=> 55 | int(%d) 56 | } 57 | SDL_GetNumDisplayModes(0):int(%d) 58 | SDL_GetDisplayMode(0,0):object(SDL_DisplayMode)#2 (4) { 59 | ["format"]=> 60 | int(%d) 61 | ["w"]=> 62 | int(%d) 63 | ["h"]=> 64 | int(%d) 65 | ["refresh_rate"]=> 66 | int(%d) 67 | } 68 | SDL_GetDesktopDisplayMode(0):object(SDL_DisplayMode)#2 (4) { 69 | ["format"]=> 70 | int(%d) 71 | ["w"]=> 72 | int(%d) 73 | ["h"]=> 74 | int(%d) 75 | ["refresh_rate"]=> 76 | int(%d) 77 | } 78 | SDL_GetCurrentDisplayMode(0):object(SDL_DisplayMode)#2 (4) { 79 | ["format"]=> 80 | int(%d) 81 | ["w"]=> 82 | int(%d) 83 | ["h"]=> 84 | int(%d) 85 | ["refresh_rate"]=> 86 | int(%d) 87 | } 88 | string(%d) "SDL_DisplayMode(%s,%d,%d,%d)" 89 | NULL 90 | int(0) 91 | NULL 92 | int(-1) 93 | NULL 94 | Done 95 | 96 | -------------------------------------------------------------------------------- /src/sdl.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_H 20 | #define PHP_SDL_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Init, 0, 0, 0) 29 | ZEND_ARG_INFO(0, flags) 30 | ZEND_END_ARG_INFO() 31 | 32 | PHP_FUNCTION(SDL_Init); 33 | 34 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_InitSubSystem, 0, 0, 1) 35 | ZEND_ARG_INFO(0, flags) 36 | ZEND_END_ARG_INFO() 37 | 38 | PHP_FUNCTION(SDL_InitSubSystem); 39 | 40 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_QuitSubSystem, 0, 0, 1) 41 | ZEND_ARG_INFO(0, flags) 42 | ZEND_END_ARG_INFO() 43 | 44 | PHP_FUNCTION(SDL_QuitSubSystem); 45 | 46 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_WasInit, 0, 0, 1) 47 | ZEND_ARG_INFO(0, flags) 48 | ZEND_END_ARG_INFO() 49 | 50 | PHP_FUNCTION(SDL_WasInit); 51 | 52 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Quit, 0, 0, 0) 53 | ZEND_END_ARG_INFO() 54 | 55 | PHP_FUNCTION(SDL_Quit); 56 | 57 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetHint, 0, 0, 2) 58 | ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) 59 | ZEND_ARG_TYPE_INFO(0, value, IS_STRING, 0) 60 | ZEND_END_ARG_INFO() 61 | 62 | PHP_FUNCTION(SDL_SetHint); 63 | 64 | 65 | PHP_MINIT_FUNCTION(sdl_sdl); 66 | 67 | #ifdef __cplusplus 68 | } // extern "C" 69 | #endif 70 | 71 | 72 | #endif /* PHP_SDL_H */ 73 | 74 | 75 | /* 76 | * Local variables: 77 | * tab-width: 4 78 | * c-basic-offset: 4 79 | * End: 80 | * vim600: noet sw=4 ts=4 fdm=marker 81 | * vim<600: noet sw=4 ts=4 82 | */ 83 | -------------------------------------------------------------------------------- /examples/007-input-handling.php: -------------------------------------------------------------------------------- 1 | format, 0xff, 0xff, 0xff); 25 | SDL_SetColorKey($image, true, $color); 26 | 27 | $texture = SDL_CreateTextureFromSurface($renderer, $image); 28 | $drect = $image->clip_rect; 29 | SDL_FreeSurface($image); 30 | 31 | SDL_SetRenderDrawColor($renderer, 0xbb, 0xcc, 0xdd, 0xff); 32 | SDL_RenderClear($renderer); 33 | SDL_RenderPresent($renderer); 34 | 35 | $rotCenter = new SDL_Point(10, 10); 36 | $event = new SDL_Event; 37 | $destRect = new SDL_Rect; 38 | $destRect->x = $x = 100; 39 | $destRect->y = $y = 100; 40 | $destRect->w = 64; 41 | $destRect->h = 64; 42 | $update = true; 43 | while (!$quit) { 44 | if ($joystickFound) { 45 | $xJoystickMotion = SDL_JoystickGetAxis($joystick, 0); 46 | if ($xJoystickMotion !== 0) { 47 | $x += ceil($xJoystickMotion / 32767) * 5; 48 | $update = true; 49 | } 50 | $yJoystickMotion = SDL_JoystickGetAxis($joystick, 1); 51 | if ($yJoystickMotion !== 0) { 52 | $y += ceil($yJoystickMotion / 32767) * 5; 53 | $update = true; 54 | } 55 | } 56 | 57 | while (SDL_PollEvent($event)) { 58 | switch ($event->type) { 59 | case SDL_QUIT: 60 | $quit = true; 61 | break; 62 | case SDL_MOUSEMOTION: 63 | $x = $event->motion->x; 64 | $y = $event->motion->y; 65 | $update = true; 66 | break; 67 | case SDL_JOYAXISMOTION: 68 | break; 69 | } 70 | } 71 | 72 | if ($update) { 73 | SDL_RenderClear($renderer); 74 | $destRect->x = $x; 75 | $destRect->y = $y; 76 | 77 | if (SDL_RenderCopyEx($renderer, $texture, NULL, $destRect, 90, $rotCenter, SDL_FLIP_NONE) != 0) { 78 | echo SDL_GetError(), PHP_EOL; 79 | } 80 | SDL_RenderPresent($renderer); 81 | $update = false; 82 | } 83 | 84 | SDL_Delay(5); 85 | } 86 | 87 | if ($joystickFound) { 88 | SDL_JoystickClose($joystick); 89 | } 90 | 91 | SDL_DestroyTexture($texture); 92 | SDL_DestroyRenderer($renderer); 93 | SDL_DestroyWindow($window); 94 | SDL_Quit(); 95 | -------------------------------------------------------------------------------- /src/php_sdl.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_PHPSDL_H 19 | #define PHP_PHPSDL_H 20 | 21 | #define ARG_PASS_BY_REF 1 22 | #define ARG_NOT_PASS_BY_REF 0 23 | 24 | #define ARG_ALLOW_NULL 1 25 | #define ARG_NOT_ALLOW_NULL 0 26 | 27 | #ifdef __cplusplus 28 | extern "C" 29 | { 30 | #endif 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include "config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | 39 | #define PHP_SDL_VERSION "2.7.0" 40 | 41 | #if defined(__APPLE__) && defined(__MACH__) 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #ifdef __cplusplus 52 | } // extern "C" 53 | #endif 54 | #ifdef __cplusplus 55 | extern "C" 56 | { 57 | #endif 58 | 59 | extern zend_module_entry sdl_module_entry; 60 | #define phpext_sdl_ptr &sdl_module_entry 61 | 62 | #ifdef PHP_WIN32 63 | #define PHP_SDL_API __declspec(dllexport) 64 | #else 65 | #define PHP_SDL_API 66 | #endif 67 | 68 | PHP_MINIT_FUNCTION(sdl); 69 | PHP_MSHUTDOWN_FUNCTION(sdl); 70 | PHP_RINIT_FUNCTION(sdl); 71 | PHP_RSHUTDOWN_FUNCTION(sdl); 72 | PHP_MINFO_FUNCTION(sdl); 73 | 74 | zend_bool php_sdl_check_overflow(int a, int b, int silent); 75 | 76 | #ifdef __cplusplus 77 | } // extern "C" 78 | #endif 79 | 80 | #endif /* PHP_PHPSDL_H */ 81 | 82 | /* 83 | * Local variables: 84 | * tab-width: 4 85 | * c-basic-offset: 4 86 | * End: 87 | * vim600: noet sw=4 ts=4 fdm=marker 88 | * vim<600: noet sw=4 ts=4 89 | */ 90 | -------------------------------------------------------------------------------- /tests/016-rwops-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_RWops test, object mode 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | write($memory)); 17 | $rw->close(); 18 | 19 | echo "= Read file\n"; 20 | $ro = SDL_RWFromFile($p, "rb"); 21 | var_dump("$ro"); 22 | echo "size:"; var_dump($ro->size()); 23 | echo "seek:"; var_dump($ro->seek(0, RW_SEEK_SET)); 24 | echo "tell:"; var_dump($ro->tell()); 25 | echo "read:"; var_dump($ro->read($buf, 100), $buf); 26 | $ro->Free(); 27 | 28 | echo "= Write memory\n"; 29 | $wm = SDL_RWFromMem($buffer, 100); 30 | var_dump("$wm"); 31 | echo "Buffer:".strlen($buffer)."\n"; 32 | echo "write:"; var_dump($l =1*$wm->writeU8(0x90)); 33 | echo "write:"; var_dump($l+=2*$wm->writeLE16(0x1234)); 34 | echo "write:"; var_dump($l+=2*$wm->writeBE16(0x5678)); 35 | echo "write:"; var_dump($l+=4*$wm->writeLE32(0x12345678)); 36 | echo "write:"; var_dump($l+=4*$wm->writeBE32(0x12345678)); 37 | echo "Buffer:".strlen($buffer)."\n"; 38 | echo "Content:".bin2hex(substr($buffer,0,$l))."\n"; 39 | $wm->Free(); 40 | 41 | echo "= Read memory\n"; 42 | $rm = SDL_RWFromConstMem($buffer); 43 | var_dump("$rm"); 44 | echo "size:"; var_dump($rm->size()); 45 | echo "seek:"; var_dump($rm->seek(0, RW_SEEK_SET)); 46 | echo "tell:"; var_dump($rm->tell()); 47 | printf("read8: %x\n", $rm->ReadU8()); 48 | printf("readLE16: %x\n", $rm->ReadLE16()); 49 | printf("readBE16: %x\n", $rm->ReadBE16()); 50 | printf("readBE32: %x\n", $rm->ReadLE32()); 51 | printf("readBE32: %x\n", $rm->ReadBE32()); 52 | $rm->Free(); 53 | 54 | 55 | ?> 56 | = Done 57 | --CLEAN-- 58 | 61 | --EXPECTF-- 62 | = Create file 63 | string(23) "SDL_RWops("Stdio file")" 64 | write:int(16) 65 | = Read file 66 | string(23) "SDL_RWops("Stdio file")" 67 | size:int(16) 68 | seek:int(0) 69 | tell:int(0) 70 | read:int(16) 71 | string(16) "Hello SDL2 world" 72 | = Write memory 73 | 74 | %s: SDL_RWFromMem(): this function may raised unsupported error with PHP memory in %s/016-rwops-oo.php on line %d 75 | string(26) "SDL_RWops("Memory stream")" 76 | Buffer:100 77 | write:int(1) 78 | write:int(3) 79 | write:int(5) 80 | write:int(9) 81 | write:int(13) 82 | Buffer:100 83 | Content:90341256787856341212345678 84 | = Read memory 85 | string(36) "SDL_RWops("Read only memory stream")" 86 | size:int(100) 87 | seek:int(0) 88 | tell:int(0) 89 | read8: 90 90 | readLE16: 1234 91 | readBE16: 5678 92 | readBE32: 12345678 93 | readBE32: 12345678 94 | = Done 95 | -------------------------------------------------------------------------------- /src/messagebox.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_MESSAGEBOX_H 20 | #define PHP_SDL_MESSAGEBOX_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_messageboxcolor_ce(void); 29 | zend_bool sdl_messageboxcolor_to_zval(const SDL_MessageBoxColor *color, zval *value); 30 | zend_bool zval_to_sdl_messageboxcolor(zval *value, SDL_MessageBoxColor *color); 31 | 32 | zend_class_entry *get_php_sdl_messageboxbuttondata_ce(void); 33 | zend_bool sdl_messageboxbuttondata_to_zval(const SDL_MessageBoxButtonData *data, zval *value); 34 | zend_bool zval_to_sdl_messageboxbuttondata(zval *value, SDL_MessageBoxButtonData *data); 35 | 36 | zend_class_entry *get_php_sdl_messageboxdata_ce(void); 37 | zend_bool sdl_messageboxdata_to_zval(SDL_MessageBoxData *data, zval *z_val, Uint32 flags); 38 | SDL_MessageBoxData *zval_to_sdl_messageboxdata(zval *z_val); 39 | 40 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_ShowMessageBox, 0, 0, 2) 41 | ZEND_ARG_INFO(0, messageboxdata) 42 | ZEND_ARG_INFO(1, buttonid) 43 | ZEND_END_ARG_INFO() 44 | 45 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_ShowSimpleMessageBox, 0, 0, 3) 46 | ZEND_ARG_INFO(0, flags) 47 | ZEND_ARG_INFO(0, title) 48 | ZEND_ARG_INFO(0, message) 49 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 1) 50 | ZEND_END_ARG_INFO() 51 | 52 | PHP_FUNCTION(SDL_ShowMessageBox); 53 | PHP_FUNCTION(SDL_ShowSimpleMessageBox); 54 | 55 | PHP_MINIT_FUNCTION(sdl_messagebox); 56 | 57 | #ifdef __cplusplus 58 | } // extern "C" 59 | #endif 60 | 61 | #endif /* PHP_SDL_MESSAGEBOX_H */ 62 | 63 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl config.m4 for the PHP SDL extension 2 | 3 | PHP_ARG_WITH(sdl, whether to enable SDL functions, 4 | [ --with-sdl[=SDLCONFIG_PATH] Enable SDL support]) 5 | 6 | PHP_ARG_ENABLE(sdl-debug, whether to enable PHP-SDL debug support, 7 | [ --enable-sdl-debug Enable SDL debug support], no, no) 8 | 9 | if test "$PHP_SDL" != "no"; then 10 | export OLD_CPPFLAGS="$CPPFLAGS" 11 | export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_SDL2 -Wall -Wfatal-errors" 12 | 13 | REQ_PHP_VERSION="8.0.0" 14 | REQ_PHP_VERSION_ID=80000 15 | if test -z "$PHP_VERSION_ID"; then 16 | AC_MSG_CHECKING(PHP version) 17 | AC_TRY_COMPILE([#include ], [ 18 | #if PHP_VERSION_ID < $REQ_PHP_VERSION_ID 19 | #error this extension requires at least PHP version $REQ_PHP_VERSION 20 | #endif 21 | ], 22 | [AC_MSG_RESULT(ok)], 23 | [AC_MSG_ERROR([need at least PHP v$REQ_PHP_VERSION])]) 24 | else 25 | if test "$PHP_VERSION_ID" -lt "$REQ_PHP_VERSION_ID"; then 26 | AC_MSG_ERROR([SDL needs at least PHP v$REQ_PHP_VERSION]) 27 | fi 28 | fi 29 | PHP_SDL_CFLAGS="$CPPFLAGS" 30 | 31 | export CPPFLAGS="$OLD_CPPFLAGS" 32 | 33 | dnl {{{ --enable-sdl-debug 34 | if test "$PHP_SDL_DEBUG" != "no"; then 35 | CFLAGS="$CFLAGS -Wall -Wpedantic -g -ggdb -O0" 36 | fi 37 | dnl }}} 38 | 39 | if test "$PHP_SDL" == "yes"; then 40 | AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no) 41 | else 42 | SDL2_CONFIG="$PHP_SDL" 43 | fi 44 | 45 | AC_MSG_CHECKING(for SDL2 library) 46 | if test -x "$SDL2_CONFIG" ; then 47 | SDL2_VERSION=`$SDL2_CONFIG --version` 48 | AC_MSG_RESULT(using SDL2 version $SDL2_VERSION) 49 | PHP_EVAL_INCLINE(`$SDL2_CONFIG --cflags`) 50 | PHP_EVAL_LIBLINE(`$SDL2_CONFIG --libs`, SDL_SHARED_LIBADD) 51 | else 52 | AC_MSG_ERROR(Cannot find sdl2-config) 53 | fi 54 | 55 | PHP_SUBST(SDL_SHARED_LIBADD) 56 | AC_DEFINE(HAVE_SDL2, 1, [ ]) 57 | 58 | PHP_CHECK_LIBRARY(SDL2, SDL_GetRevisionNumber, [ 59 | AC_DEFINE(HAVE_SDL_GETREVISIONNUMBER, 1, [ ]) 60 | ]) 61 | 62 | SDL_SOURCE_FILES="src/blendmode.c \ 63 | src/cpuinfo.c \ 64 | src/error.c \ 65 | src/event.c \ 66 | src/filesystem.c \ 67 | src/glcontext.c \ 68 | src/joystick.c \ 69 | src/keyboard.c \ 70 | src/messagebox.c \ 71 | src/mouse.c \ 72 | src/mutex.c \ 73 | src/php_sdl.c \ 74 | src/pixels.c \ 75 | src/platform.c \ 76 | src/power.c \ 77 | src/rect.c \ 78 | src/render.c \ 79 | src/rwops.c \ 80 | src/sdl.c \ 81 | src/shape.c \ 82 | src/surface.c \ 83 | src/timer.c \ 84 | src/version.c \ 85 | src/video.c \ 86 | src/window.c" 87 | 88 | PHP_NEW_EXTENSION(sdl, $SDL_SOURCE_FILES, $ext_shared,, $PHP_SDL_CFLAGS) 89 | PHP_ADD_BUILD_DIR($ext_builddir/src) 90 | fi 91 | -------------------------------------------------------------------------------- /src/rect.stub.php: -------------------------------------------------------------------------------- 1 | 7 | --FILE-- 8 | w, $spal->h, $spal->format->palette->ncolors); 12 | 13 | echo "= Create True colors\n"; 14 | $scol = SDL_CreateRGBSurface(0, 150, 100, 32, 0xff000000, 0xff0000, 0xff00, 0xff); 15 | var_dump($scol->w, $scol->h, $scol->format->palette); 16 | 17 | echo "= Lock\n"; 18 | var_dump(SDL_MustLock($spal), $spal->locked); 19 | var_dump(SDL_LockSurface($spal), $spal->locked); 20 | var_dump(SDL_UnlockSurface($spal), $spal->locked); 21 | 22 | echo "= ColorKey\n"; 23 | var_dump(SDL_SetColorKey($spal, true, 127)); 24 | var_dump(SDL_GetColorKey($spal, $key), $key); 25 | var_dump(SDL_SetColorKey($spal, false)); 26 | var_dump(SDL_GetColorKey($spal, $key)); 27 | var_dump(SDL_GetError()); 28 | SDL_ClearError(); 29 | echo "= ColorMod\n"; 30 | var_dump(SDL_SetSurfaceColorMod($scol, 1, 2, 3)); 31 | var_dump(SDL_GetSurfaceColorMod($scol, $r, $g, $b), $r, $g, $b); 32 | 33 | echo "= AlphaMod\n"; 34 | var_dump(SDL_SetSurfaceAlphaMod($scol, 4)); 35 | var_dump(SDL_GetSurfaceAlphaMod($scol, $a), $a); 36 | 37 | echo "= BlendMode\n"; 38 | var_dump(SDL_SetSurfaceBlendMode($scol, SDL_BLENDMODE_ADD)); 39 | var_dump(SDL_GetSurfaceBlendMode($scol, $a), $a==SDL_BLENDMODE_ADD); 40 | 41 | echo "= ClipRect\n"; 42 | var_dump(SDL_SetClipRect($scol, new SDL_Rect(10,20,30,40))); 43 | var_dump(SDL_GetClipRect($scol, $rect), $rect); 44 | 45 | echo "= Convert\n"; 46 | $conv = SDL_ConvertSurface($spal, $scol->format); 47 | var_dump($scol->format->format == $conv->format->format); 48 | $conv = SDL_ConvertSurfaceFormat($spal, $scol->format->format); 49 | var_dump($scol->format->format == $conv->format->format); 50 | 51 | echo "= ConvertPixels\n"; 52 | var_dump(SDL_ConvertPixels( 53 | 150,100, 54 | $scol->format->format, $scol->pixels, $scol->pitch, 55 | $conv->format->format, $conv->pixels, $conv->pitch 56 | ), SDL_GetError()); 57 | echo "= Free\n"; 58 | SDL_FreeSurface($spal); 59 | SDL_FreeSurface($scol); 60 | ?> 61 | = Done 62 | --EXPECTF-- 63 | = Create Palette 64 | int(150) 65 | int(100) 66 | int(256) 67 | = Create True colors 68 | int(150) 69 | int(100) 70 | NULL 71 | = Lock 72 | bool(false) 73 | int(0) 74 | int(0) 75 | int(1) 76 | NULL 77 | int(0) 78 | = ColorKey 79 | int(0) 80 | int(0) 81 | int(127) 82 | int(0) 83 | int(-1) 84 | string(31) "Surface doesn't have a colorkey" 85 | = ColorMod 86 | int(0) 87 | int(0) 88 | int(1) 89 | int(2) 90 | int(3) 91 | = AlphaMod 92 | int(0) 93 | int(0) 94 | int(4) 95 | = BlendMode 96 | int(0) 97 | int(0) 98 | bool(true) 99 | = ClipRect 100 | bool(true) 101 | NULL 102 | object(SDL_Rect)#%d (4) { 103 | ["x"]=> 104 | int(10) 105 | ["y"]=> 106 | int(20) 107 | ["w"]=> 108 | int(30) 109 | ["h"]=> 110 | int(40) 111 | } 112 | = Convert 113 | bool(true) 114 | bool(true) 115 | = ConvertPixels 116 | int(0) 117 | string(0) "" 118 | = Free 119 | = Done 120 | -------------------------------------------------------------------------------- /tests/021-surface-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_Surface test, procedural mode 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | w, $spal->h, $spal->format->palette->ncolors, $spal->pixels); 14 | 15 | echo "= Create True colors\n"; 16 | $scol = new SDL_Surface(0, 150, 100, 32, 0xff000000, 0xff0000, 0xff00, 0xff); 17 | var_dump("$scol"); 18 | var_dump($scol->w, $scol->h, $scol->format->palette, $scol->pixels); 19 | 20 | echo "= Lock\n"; 21 | var_dump($spal->MustLock(), $spal->locked); 22 | var_dump($spal->Lock(), $spal->locked); 23 | var_dump($spal->Unlock(), $spal->locked); 24 | 25 | echo "= ColorKey\n"; 26 | var_dump($spal->SetColorKey(1, 127)); 27 | var_dump($spal->GetColorKey($key), $key); 28 | var_dump($spal->SetColorKey(0)); 29 | var_dump($spal->GetColorKey($key)); 30 | 31 | echo "= ColorMod\n"; 32 | var_dump($scol->SetColorMod(1, 2, 3)); 33 | var_dump($scol->GetColorMod($r, $g, $b), $r, $g, $b); 34 | 35 | echo "= AlphaMod\n"; 36 | var_dump($scol->SetAlphaMod(4)); 37 | var_dump($scol->GetAlphaMod($a), $a); 38 | 39 | echo "= BlendMode\n"; 40 | var_dump($scol->SetBlendMode(SDL_BLENDMODE_ADD)); 41 | var_dump($scol->GetBlendMode($a), $a==SDL_BLENDMODE_ADD); 42 | 43 | echo "= ClipRect\n"; 44 | var_dump($scol->SetClipRect(new SDL_Rect(10,20,30,40))); 45 | var_dump($scol->GetClipRect($rect), $rect); 46 | var_dump($scol->clip_rect); 47 | 48 | echo "= Convert\n"; 49 | $conv = $spal->Convert($scol->format); 50 | var_dump($scol->format->format == $conv->format->format); 51 | $conv = $spal->ConvertFormat($scol->format->format); 52 | var_dump($scol->format->format == $conv->format->format); 53 | 54 | echo "= Free\n"; 55 | $scol->Free() 56 | ?> 57 | = Done 58 | --EXPECTF-- 59 | = Create Palette 60 | string(40) "SDL_Surface(%d,150,100,8,0x0,0x0,0x0,0x0)" 61 | int(150) 62 | int(100) 63 | int(256) 64 | object(SDL_Pixels)#%d (0) { 65 | } 66 | = Create True colors 67 | string(57) "SDL_Surface(%d,150,100,32,0xff000000,0xff0000,0xff00,0xff)" 68 | int(150) 69 | int(100) 70 | NULL 71 | object(SDL_Pixels)#%d (0) { 72 | } 73 | = Lock 74 | bool(false) 75 | int(0) 76 | int(0) 77 | int(1) 78 | NULL 79 | int(0) 80 | = ColorKey 81 | int(0) 82 | int(0) 83 | int(127) 84 | int(0) 85 | int(-1) 86 | = ColorMod 87 | int(0) 88 | int(0) 89 | int(1) 90 | int(2) 91 | int(3) 92 | = AlphaMod 93 | int(0) 94 | int(0) 95 | int(4) 96 | = BlendMode 97 | int(0) 98 | int(0) 99 | bool(true) 100 | = ClipRect 101 | bool(true) 102 | NULL 103 | object(SDL_Rect)#%d (4) { 104 | ["x"]=> 105 | int(10) 106 | ["y"]=> 107 | int(20) 108 | ["w"]=> 109 | int(30) 110 | ["h"]=> 111 | int(40) 112 | } 113 | object(SDL_Rect)#%d (4) { 114 | ["x"]=> 115 | int(10) 116 | ["y"]=> 117 | int(20) 118 | ["w"]=> 119 | int(30) 120 | ["h"]=> 121 | int(40) 122 | } 123 | = Convert 124 | bool(true) 125 | bool(true) 126 | = Free 127 | = Done 128 | -------------------------------------------------------------------------------- /src/power.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #include "power.h" 19 | 20 | /* {{{ proto string SDL_GetPowerInfo(int &sec, int &pct) 21 | 22 | * \brief Get the current power supply details. 23 | * 24 | * \param secs Seconds of battery life left. You can pass a NULL here if 25 | * you don't care. Will return -1 if we can't determine a 26 | * value, or we're not running on a battery. 27 | * 28 | * \param pct Percentage of battery life left, between 0 and 100. You can 29 | * pass a NULL here if you don't care. Will return -1 if we 30 | * can't determine a value, or we're not running on a battery. 31 | * 32 | * \return The state of the battery (if any). 33 | */ 34 | PHP_FUNCTION(SDL_GetPowerInfo) 35 | { 36 | int secs, pct; 37 | SDL_PowerState power_state; 38 | zval *z_secs = NULL, *z_pct = NULL; 39 | zend_bool has_secs, has_pct; 40 | 41 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z/z/", &z_secs, &z_pct) == FAILURE) { 42 | RETURN_FALSE; 43 | } 44 | 45 | has_secs = ( NULL == z_secs ? 0 : 1 ); 46 | has_pct = ( NULL == z_pct ? 0 : 1 ); 47 | 48 | power_state = SDL_GetPowerInfo(has_secs ? &secs : NULL, has_pct ? &pct : NULL); 49 | 50 | if (has_secs) { 51 | ZVAL_LONG(z_secs, (long)secs); 52 | } 53 | if (has_pct) { 54 | ZVAL_LONG(z_pct, (long)pct); 55 | } 56 | 57 | RETURN_LONG(power_state); 58 | } 59 | /* }}} */ 60 | 61 | 62 | /* {{{ MINIT */ 63 | PHP_MINIT_FUNCTION(sdl_power) 64 | { 65 | REGISTER_LONG_CONSTANT("SDL_POWERSTATE_UNKNOWN", SDL_POWERSTATE_UNKNOWN, CONST_CS | CONST_PERSISTENT); 66 | REGISTER_LONG_CONSTANT("SDL_POWERSTATE_ON_BATTERY", SDL_POWERSTATE_ON_BATTERY, CONST_CS | CONST_PERSISTENT); 67 | REGISTER_LONG_CONSTANT("SDL_POWERSTATE_NO_BATTERY", SDL_POWERSTATE_NO_BATTERY, CONST_CS | CONST_PERSISTENT); 68 | REGISTER_LONG_CONSTANT("SDL_POWERSTATE_CHARGING", SDL_POWERSTATE_CHARGING, CONST_CS | CONST_PERSISTENT); 69 | REGISTER_LONG_CONSTANT("SDL_POWERSTATE_CHARGED", SDL_POWERSTATE_CHARGED, CONST_CS | CONST_PERSISTENT); 70 | 71 | return SUCCESS; 72 | } 73 | /* }}} */ 74 | -------------------------------------------------------------------------------- /src/joystick.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Author: Santiago Lizardo | 14 | | Author: Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_SDL_JOYSTICK_H 19 | #define PHP_SDL_JOYSTICK_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_NumJoysticks, 0, 0, 0) 29 | ZEND_END_ARG_INFO() 30 | PHP_FUNCTION(SDL_NumJoysticks); 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickOpen, 0, 0, 1) 33 | ZEND_ARG_TYPE_INFO(ARG_NOT_PASS_BY_REF, index, IS_LONG, ARG_NOT_ALLOW_NULL) 34 | ZEND_END_ARG_INFO() 35 | PHP_FUNCTION(SDL_JoystickOpen); 36 | 37 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickClose, 0, 0, 1) 38 | ZEND_ARG_OBJ_INFO(ARG_NOT_PASS_BY_REF, joystick, SDL_Joystick, ARG_NOT_ALLOW_NULL) 39 | ZEND_END_ARG_INFO() 40 | PHP_FUNCTION(SDL_JoystickClose); 41 | 42 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickName, 0, 0, 1) 43 | ZEND_ARG_OBJ_INFO(ARG_NOT_PASS_BY_REF, joystick, SDL_Joystick, ARG_NOT_ALLOW_NULL) 44 | ZEND_END_ARG_INFO() 45 | PHP_FUNCTION(SDL_JoystickName); 46 | 47 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickGetAxis, 0, 0, 2) 48 | ZEND_ARG_OBJ_INFO(ARG_NOT_PASS_BY_REF, joystick, SDL_Joystick, ARG_NOT_ALLOW_NULL) 49 | ZEND_ARG_TYPE_INFO(ARG_NOT_PASS_BY_REF, axis, IS_LONG, ARG_NOT_ALLOW_NULL) 50 | ZEND_END_ARG_INFO() 51 | PHP_FUNCTION(SDL_JoystickGetAxis); 52 | 53 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickNameForIndex, 0, 0, 1) 54 | ZEND_ARG_TYPE_INFO(ARG_NOT_PASS_BY_REF, index, IS_LONG, ARG_NOT_ALLOW_NULL) 55 | ZEND_END_ARG_INFO() 56 | PHP_FUNCTION(SDL_JoystickNameForIndex); 57 | 58 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_JoystickNumButtons, 0, 0, 1) 59 | ZEND_ARG_OBJ_INFO(ARG_NOT_PASS_BY_REF, joystick, SDL_Joystick, ARG_NOT_ALLOW_NULL) 60 | ZEND_END_ARG_INFO() 61 | PHP_FUNCTION(SDL_JoystickNumButtons); 62 | 63 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_IsGameController, 0, 0, 1) 64 | ZEND_ARG_TYPE_INFO(ARG_NOT_PASS_BY_REF, index, IS_LONG, ARG_NOT_ALLOW_NULL) 65 | ZEND_END_ARG_INFO() 66 | PHP_FUNCTION(SDL_IsGameController); 67 | 68 | PHP_MINIT_FUNCTION(sdl_joystick); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /src/keyboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2022 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_SDL_KEYBOARD_H 19 | #define PHP_SDL_KEYBOARD_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" 23 | { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetKeyboardState, 0, 0, 0) 29 | ZEND_ARG_TYPE_INFO(ARG_PASS_BY_REF, numkeys, IS_LONG, ARG_ALLOW_NULL) 30 | ZEND_END_ARG_INFO() 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetModState, 0, 0, 1) 33 | ZEND_ARG_INFO(0, modstate) 34 | ZEND_END_ARG_INFO() 35 | 36 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetTextInputRect, 0, 0, 1) 37 | ZEND_ARG_OBJ_INFO(0, rect, SDL_Rect, 0) 38 | ZEND_END_ARG_INFO() 39 | 40 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_IsScreenKeyboardShown, 0, 0, 1) 41 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 42 | ZEND_END_ARG_INFO() 43 | 44 | ZEND_BEGIN_ARG_INFO_EX(arginfo_scancode, 0, 0, 1) 45 | ZEND_ARG_INFO(0, scancode) 46 | ZEND_END_ARG_INFO() 47 | 48 | ZEND_BEGIN_ARG_INFO_EX(arginfo_key, 0, 0, 1) 49 | ZEND_ARG_INFO(0, key) 50 | ZEND_END_ARG_INFO() 51 | 52 | ZEND_BEGIN_ARG_INFO_EX(arginfo_name, 0, 0, 1) 53 | ZEND_ARG_INFO(0, name) 54 | ZEND_END_ARG_INFO() 55 | 56 | PHP_FUNCTION(SDL_GetKeyboardFocus); 57 | PHP_FUNCTION(SDL_GetKeyboardState); 58 | PHP_FUNCTION(SDL_GetModState); 59 | PHP_FUNCTION(SDL_SetModState); 60 | PHP_FUNCTION(SDL_GetKeyFromScancode); 61 | PHP_FUNCTION(SDL_GetScancodeFromKey); 62 | PHP_FUNCTION(SDL_GetScancodeName); 63 | PHP_FUNCTION(SDL_GetScancodeFromName); 64 | PHP_FUNCTION(SDL_GetKeyName); 65 | PHP_FUNCTION(SDL_GetKeyFromName); 66 | PHP_FUNCTION(SDL_StartTextInput); 67 | PHP_FUNCTION(SDL_IsTextInputActive); 68 | PHP_FUNCTION(SDL_StopTextInput); 69 | PHP_FUNCTION(SDL_SetTextInputRect); 70 | PHP_FUNCTION(SDL_HasScreenKeyboardSupport); 71 | PHP_FUNCTION(SDL_IsScreenKeyboardShown); 72 | 73 | PHP_MINIT_FUNCTION(sdl_keyboard); 74 | 75 | #ifdef __cplusplus 76 | } // extern "C" 77 | #endif 78 | 79 | #endif /* PHP_SDL_KEYBOARD_H */ 80 | -------------------------------------------------------------------------------- /src/video.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_VIDEO_H 20 | #define PHP_SDL_VIDEO_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_displaymode_ce(void); 29 | zend_bool sdl_displaymode_to_zval(SDL_DisplayMode *display, zval *value); 30 | zend_bool zval_to_sdl_displaymode(zval *value, SDL_DisplayMode *display); 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetVideoDriver, 0, 0, 1) 33 | ZEND_ARG_INFO(0, driverIndex) 34 | ZEND_END_ARG_INFO() 35 | 36 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_VideoInit, 0, 0, 0) 37 | ZEND_ARG_INFO(0, drivername) 38 | ZEND_END_ARG_INFO() 39 | 40 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetDisplayBounds, 0, 0, 2) 41 | ZEND_ARG_INFO(0, displayIndex) 42 | ZEND_ARG_INFO(1, rect) 43 | ZEND_END_ARG_INFO() 44 | 45 | 46 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetDisplayMode, 0, 0, 2) 47 | ZEND_ARG_INFO(0, displayIndex) 48 | ZEND_ARG_INFO(0, modeIndex) 49 | ZEND_END_ARG_INFO() 50 | 51 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetClosestDisplayMode, 0, 0, 2) 52 | ZEND_ARG_INFO(0, displayIndex) 53 | ZEND_ARG_OBJ_INFO(0, desired, SDL_DisplayMode, 0) 54 | ZEND_ARG_INFO(1, closest) 55 | ZEND_END_ARG_INFO() 56 | 57 | /* generic arginfo */ 58 | ZEND_BEGIN_ARG_INFO_EX(arginfo_video_none, 0, 0, 0) 59 | ZEND_END_ARG_INFO() 60 | 61 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_dysplayindex, 0, 0, 1) 62 | ZEND_ARG_INFO(0, displayIndex) 63 | ZEND_END_ARG_INFO() 64 | 65 | PHP_FUNCTION(SDL_GetNumVideoDrivers); 66 | PHP_FUNCTION(SDL_GetVideoDriver); 67 | PHP_FUNCTION(SDL_VideoInit); 68 | PHP_FUNCTION(SDL_VideoQuit); 69 | PHP_FUNCTION(SDL_GetCurrentVideoDriver); 70 | PHP_FUNCTION(SDL_GetNumVideoDisplays); 71 | PHP_FUNCTION(SDL_GetDisplayName); 72 | PHP_FUNCTION(SDL_GetDisplayBounds); 73 | PHP_FUNCTION(SDL_GetNumDisplayModes); 74 | PHP_FUNCTION(SDL_GetDisplayMode); 75 | PHP_FUNCTION(SDL_GetDesktopDisplayMode); 76 | PHP_FUNCTION(SDL_GetCurrentDisplayMode); 77 | PHP_FUNCTION(SDL_GetClosestDisplayMode); 78 | PHP_FUNCTION(SDL_IsScreenSaverEnabled); 79 | PHP_FUNCTION(SDL_EnableScreenSaver); 80 | PHP_FUNCTION(SDL_DisableScreenSaver); 81 | 82 | PHP_MINIT_FUNCTION(sdl_video); 83 | 84 | #ifdef __cplusplus 85 | } // extern "C" 86 | #endif 87 | 88 | #endif /* PHP_SDL_VIDEO_H */ 89 | 90 | -------------------------------------------------------------------------------- /src/mouse.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_MOUSE_H 20 | #define PHP_SDL_MOUSE_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_cursor_ce(void); 29 | zend_bool sdl_cursor_to_zval(SDL_Cursor *cursor, zval *z_val, Uint32 flags); 30 | SDL_GLContext zval_to_sdl_cursor(zval *z_val); 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateSystemCursor, 0, 0, 1) 33 | ZEND_ARG_INFO(0, id) 34 | ZEND_END_ARG_INFO() 35 | 36 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateColorCursor, 0, 0, 3) 37 | ZEND_ARG_OBJ_INFO(0, surface, SDL_Surface, 0) 38 | ZEND_ARG_INFO(0, hot_x) 39 | ZEND_ARG_INFO(0, hot_y) 40 | ZEND_END_ARG_INFO() 41 | 42 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_ShowCursor, 0, 0, 1) 43 | ZEND_ARG_INFO(0, toggle) 44 | ZEND_END_ARG_INFO() 45 | 46 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetMouseState, 0, 0, 0) 47 | ZEND_ARG_INFO(1, x) 48 | ZEND_ARG_INFO(1, y) 49 | ZEND_END_ARG_INFO() 50 | 51 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_WarpMouseInWindow, 0, 0, 3) 52 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 53 | ZEND_ARG_INFO(0, x) 54 | ZEND_ARG_INFO(0, y) 55 | ZEND_END_ARG_INFO() 56 | 57 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetRelativeMouseMode, 0, 0, 1) 58 | ZEND_ARG_INFO(0, enabled) 59 | ZEND_END_ARG_INFO() 60 | 61 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Cursor, 0, 0, 1) 62 | ZEND_ARG_OBJ_INFO(0, cursor, SDL_Cursor, 0) 63 | ZEND_END_ARG_INFO() 64 | 65 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Cursor__construct, 0, 0, 6) 66 | ZEND_ARG_INFO(0, data) 67 | ZEND_ARG_INFO(0, mask) 68 | ZEND_ARG_INFO(0, w) 69 | ZEND_ARG_INFO(0, h) 70 | ZEND_ARG_INFO(0, hot_x) 71 | ZEND_ARG_INFO(0, hot_y) 72 | ZEND_END_ARG_INFO() 73 | 74 | PHP_FUNCTION(SDL_CreateCursor); 75 | PHP_FUNCTION(SDL_CreateSystemCursor); 76 | PHP_FUNCTION(SDL_CreateColorCursor); 77 | PHP_FUNCTION(SDL_FreeCursor); 78 | PHP_FUNCTION(SDL_SetCursor); 79 | PHP_FUNCTION(SDL_GetCursor); 80 | PHP_FUNCTION(SDL_GetDefaultCursor); 81 | PHP_FUNCTION(SDL_ShowCursor); 82 | PHP_FUNCTION(SDL_GetMouseFocus); 83 | PHP_FUNCTION(SDL_GetMouseState); 84 | PHP_FUNCTION(SDL_GetRelativeMouseState); 85 | PHP_FUNCTION(SDL_WarpMouseInWindow); 86 | PHP_FUNCTION(SDL_SetRelativeMouseMode); 87 | PHP_FUNCTION(SDL_GetRelativeMouseMode); 88 | 89 | PHP_MINIT_FUNCTION(sdl_mouse); 90 | 91 | #ifdef __cplusplus 92 | } // extern "C" 93 | #endif 94 | 95 | #endif /* PHP_SDL_MOUSE_H */ 96 | 97 | -------------------------------------------------------------------------------- /src/glcontext.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_GLCONTEXT_H 20 | #define PHP_SDL_GLCONTEXT_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | zend_class_entry *get_php_sdl_glcontext_ce(void); 27 | zend_bool sdl_glcontext_to_zval(SDL_GLContext glcontext, zval *z_val, Uint32 flags); 28 | SDL_GLContext zval_to_sdl_glcontext(zval *z_val); 29 | 30 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GLContext, 0, 0, 1) 31 | ZEND_ARG_OBJ_INFO(0, GLcontext, SDL_GLContext, 0) 32 | ZEND_END_ARG_INFO() 33 | 34 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_DeleteContext, 0, 0, 1) 35 | ZEND_ARG_OBJ_INFO(0, GLcontext, SDL_GLContext, 0) 36 | ZEND_END_ARG_INFO() 37 | 38 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_ExtensionSupported, 0, 0, 1) 39 | ZEND_ARG_INFO(0, extension) 40 | ZEND_END_ARG_INFO() 41 | 42 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_SetAttribute, 0, 0, 2) 43 | ZEND_ARG_INFO(0, attr) 44 | ZEND_ARG_INFO(0, value) 45 | ZEND_END_ARG_INFO() 46 | 47 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_GetAttribute, 0, 0, 2) 48 | ZEND_ARG_INFO(0, attr) 49 | ZEND_ARG_INFO(1, value) 50 | ZEND_END_ARG_INFO() 51 | 52 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GLContext__construct, 0, 0, 1) 53 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 54 | ZEND_END_ARG_INFO() 55 | 56 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_MakeCurrent, 0, 0, 1) 57 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 58 | ZEND_ARG_OBJ_INFO(0, context, SDL_GLContext, 0) 59 | ZEND_END_ARG_INFO() 60 | 61 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_GetDrawableSize, 0, 0, 3) 62 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 63 | ZEND_ARG_INFO(1, w) 64 | ZEND_ARG_INFO(1, h) 65 | ZEND_END_ARG_INFO() 66 | 67 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GL_SetSwapInterval, 0, 0, 1) 68 | ZEND_ARG_INFO(0, interval) 69 | ZEND_END_ARG_INFO() 70 | 71 | /* generic arginfo */ 72 | 73 | ZEND_BEGIN_ARG_INFO_EX(arginfo_none, 0, 0, 0) 74 | ZEND_END_ARG_INFO() 75 | 76 | 77 | PHP_FUNCTION(SDL_GL_CreateContext); 78 | PHP_FUNCTION(SDL_GL_MakeCurrent); 79 | PHP_FUNCTION(SDL_GL_GetCurrentWindow); 80 | #if SDL_VERSION_ATLEAST(2,0,1) 81 | PHP_FUNCTION(SDL_GL_GetDrawableSize); 82 | #endif 83 | PHP_FUNCTION(SDL_GL_SwapWindow); 84 | 85 | PHP_FUNCTION(SDL_GL_ExtensionSupported); 86 | PHP_FUNCTION(SDL_GL_SetAttribute); 87 | PHP_FUNCTION(SDL_GL_GetAttribute); 88 | PHP_FUNCTION(SDL_GL_DeleteContext); 89 | PHP_FUNCTION(SDL_GL_GetCurrentContext); 90 | PHP_FUNCTION(SDL_GL_SetSwapInterval); 91 | PHP_FUNCTION(SDL_GL_GetSwapInterval); 92 | PHP_MINIT_FUNCTION(sdl_glcontext); 93 | 94 | #ifdef __cplusplus 95 | } // extern "C" 96 | #endif 97 | 98 | #endif /* PHP_SDL_GLCONTEXT_H */ 99 | 100 | -------------------------------------------------------------------------------- /examples/011-draw-with-subpixels.php: -------------------------------------------------------------------------------- 1 | clip_rect; 22 | $drect->y = 500; 23 | $dfrect = new SDL_FRect($drect->x, $drect->y, $drect->w, $drect->h); 24 | 25 | // Draw lines 26 | function line($iteration, $renderer) 27 | { 28 | $x1 = 40.0; 29 | $y1 = 40.0 + $iteration; 30 | $x2 = SQUARE; 31 | $y2 = SQUARE - $iteration; 32 | 33 | SDL_RenderDrawLineF($renderer, $x1, $y1, $x2, $y2); 34 | } 35 | 36 | // Draw rects 37 | function rect($iteration, $renderer) 38 | { 39 | $x1 = SQUARE + 20 + $iteration/2; 40 | $y1 = SQUARE + $iteration/2 + 20; 41 | $w = SQUARE - 10 - $iteration; 42 | $h = SQUARE - 10 - $iteration; 43 | $rect1 = new SDL_FRect($x1, $y1, $w, $h); 44 | $rect2 = new SDL_FRect($x1 + 50, $y1 + 50, $w - 100 , $h - 100); 45 | SDL_RenderDrawRectF($renderer, $rect1); 46 | SDL_RenderFillRectF($renderer, $rect2); 47 | } 48 | 49 | // Draw points 50 | function points($iteration, $renderer) 51 | { 52 | for ($x = SQUARE + 80; $x < WINDOW_WIDTH - 60; $x++) { 53 | $y = sin($x*6/SQUARE + $iteration/10) * 120 + 250; 54 | SDL_RenderDrawPointF($renderer, (float) $x, $y); 55 | } 56 | } 57 | 58 | // Draw sprites 59 | function sprites($iteration, $renderer, $destRect, $destFRect, $texture) 60 | { 61 | $destFRect->x = $iteration; 62 | $destRect->x = (int) $destFRect->x + 100; 63 | if (SDL_RenderCopyEx($renderer, $texture, null, $destRect, $iteration, null, SDL_FLIP_NONE) != 0) { 64 | echo SDL_GetError(), PHP_EOL; 65 | } 66 | if (SDL_RenderCopyExF($renderer, $texture, null, $destFRect, $iteration, null, SDL_FLIP_NONE) != 0) { 67 | echo SDL_GetError(), PHP_EOL; 68 | } 69 | 70 | $destRect2 = clone $destRect; 71 | $destFRect2 = clone $destFRect; 72 | $destRect2->y += 100; 73 | $destFRect2->y += 100; 74 | if (SDL_RenderCopy($renderer, $texture, null, $destRect2) != 0) { 75 | echo SDL_GetError(), PHP_EOL; 76 | } 77 | if (SDL_RenderCopyF($renderer, $texture, null, $destFRect2) != 0) { 78 | echo SDL_GetError(), PHP_EOL; 79 | } 80 | } 81 | 82 | function getIncrement($i, $increment) 83 | { 84 | if ($i > SQUARE) { 85 | return -0.20; 86 | } 87 | 88 | if ($i < 20.0) { 89 | return 0.20; 90 | } 91 | 92 | return $increment; 93 | } 94 | 95 | // Wait for quit event 96 | $event = new SDL_Event; 97 | $i = .0; 98 | $increment = 0.20; 99 | 100 | while (true) { 101 | if (SDL_PollEvent($event) && $event->type == SDL_QUIT) { 102 | break; 103 | } 104 | // Clear screen 105 | SDL_SetRenderDrawColor($renderer, 47, 79, 79, 255); 106 | SDL_RenderClear($renderer); 107 | 108 | SDL_SetRenderDrawColor($renderer, 230, 230, 230, 255); 109 | $increment = getIncrement($i, $increment); 110 | $i += $increment; 111 | line($i, $renderer); 112 | rect($i, $renderer); 113 | points($i, $renderer); 114 | sprites($i, $renderer, $drect, $dfrect, $texture); 115 | 116 | SDL_RenderPresent($renderer); 117 | SDL_Delay(5); 118 | } 119 | 120 | SDL_DestroyRenderer($renderer); 121 | SDL_DestroyWindow($window); 122 | SDL_Quit(); 123 | -------------------------------------------------------------------------------- /examples/009-window-events.php: -------------------------------------------------------------------------------- 1 | type) { 32 | case SDL_QUIT: 33 | $quit = true; 34 | break; 35 | case SDL_WINDOWEVENT: 36 | $eventText = 'unknown'; 37 | switch ($event->window->event) { 38 | case SDL_WINDOWEVENT_SHOWN: 39 | $eventText = "Shown"; 40 | break; 41 | case SDL_WINDOWEVENT_HIDDEN: 42 | $eventText = "Hidden"; 43 | break; 44 | case SDL_WINDOWEVENT_EXPOSED: 45 | $eventText = "Exposed"; 46 | break; 47 | case SDL_WINDOWEVENT_MOVED: 48 | $eventText = "Moved ({$event->window->data1}, {$event->window->data2})"; 49 | break; 50 | case SDL_WINDOWEVENT_RESIZED: 51 | $eventText = "Resized ({$event->window->data1} x {$event->window->data2})"; 52 | break; 53 | case SDL_WINDOWEVENT_SIZE_CHANGED: 54 | $eventText = "Size changed"; 55 | break; 56 | case SDL_WINDOWEVENT_MINIMIZED: 57 | $eventText = "Minimized"; 58 | break; 59 | case SDL_WINDOWEVENT_MAXIMIZED: 60 | $eventText = "Maximized"; 61 | break; 62 | case SDL_WINDOWEVENT_RESTORED: 63 | $eventText = "Restored"; 64 | break; 65 | case SDL_WINDOWEVENT_ENTER: 66 | $eventText = "Enter"; 67 | break; 68 | case SDL_WINDOWEVENT_LEAVE: 69 | $eventText = "Leave"; 70 | break; 71 | case SDL_WINDOWEVENT_FOCUS_GAINED: 72 | $eventText = "Focus gained"; 73 | break; 74 | case SDL_WINDOWEVENT_FOCUS_LOST: 75 | $eventText = "Focus lost"; 76 | break; 77 | case SDL_WINDOWEVENT_CLOSE: 78 | $eventText = "Close"; 79 | break; 80 | case SDL_WINDOWEVENT_TAKE_FOCUS: 81 | $eventText = "Take focus"; 82 | break; 83 | case SDL_WINDOWEVENT_HIT_TEST: 84 | $eventText = "Hit test"; 85 | break; 86 | } 87 | $window->setTitle($eventText); 88 | printf('Event{windowID=%d, timestamp=%s, description=%s}' . PHP_EOL, $event->window->windowID, $event->window->timestamp, $eventText); 89 | break; 90 | } 91 | } 92 | 93 | SDL_Delay(5); 94 | } 95 | 96 | SDL_DestroyRenderer($renderer); 97 | SDL_DestroyWindow($window); 98 | SDL_Quit(); 99 | -------------------------------------------------------------------------------- /src/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_MUTEX_H 20 | #define PHP_SDL_MUTEX_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_mutex_ce(void); 29 | zend_bool sdl_mutex_to_zval(SDL_mutex *mutex, zval *z_val, Uint32 flags); 30 | SDL_mutex *zval_to_sdl_mutex(zval *z_val); 31 | 32 | zend_class_entry *get_php_sdl_sem_ce(void); 33 | zend_bool sdl_sem_to_zval(SDL_sem *sem, zval *z_val, Uint32 flags); 34 | SDL_sem *zval_to_sdl_sem(zval *z_val); 35 | 36 | zend_class_entry *get_php_sdl_cond_ce(void); 37 | zend_bool sdl_cond_to_zval(SDL_cond *cond, zval *z_val, Uint32 flags); 38 | SDL_cond *zval_to_sdl_cond(zval *z_val); 39 | 40 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_sem__construct, 0, 0, 1) 41 | ZEND_ARG_INFO(0, value) 42 | ZEND_END_ARG_INFO() 43 | 44 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SemWaitTimeout, 0, 0, 2) 45 | ZEND_ARG_OBJ_INFO(0, semaphore, SDL_sem, 0) 46 | ZEND_ARG_INFO(0, ms) 47 | ZEND_END_ARG_INFO() 48 | 49 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Sem_WaitTimeout, 0, 0, 1) 50 | ZEND_ARG_INFO(0, ms) 51 | ZEND_END_ARG_INFO() 52 | 53 | 54 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CondWait, 0, 0, 2) 55 | ZEND_ARG_OBJ_INFO(0, condition, SDL_cond, 0) 56 | ZEND_ARG_OBJ_INFO(0, mutex, SDL_mutex, 0) 57 | ZEND_END_ARG_INFO() 58 | 59 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Cond_Wait, 0, 0, 1) 60 | ZEND_ARG_OBJ_INFO(0, mutex, SDL_mutex, 0) 61 | ZEND_END_ARG_INFO() 62 | 63 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CondWaitTimeout, 0, 0, 3) 64 | ZEND_ARG_OBJ_INFO(0, condition, SDL_cond, 0) 65 | ZEND_ARG_OBJ_INFO(0, mutex, SDL_mutex, 0) 66 | ZEND_ARG_INFO(0, ms) 67 | ZEND_END_ARG_INFO() 68 | 69 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Cond_WaitTimeout, 0, 0, 2) 70 | ZEND_ARG_OBJ_INFO(0, mutex, SDL_mutex, 0) 71 | ZEND_ARG_INFO(0, ms) 72 | ZEND_END_ARG_INFO() 73 | 74 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_mutex, 0, 0, 1) 75 | ZEND_ARG_OBJ_INFO(0, mutex, SDL_mutex, 0) 76 | ZEND_END_ARG_INFO() 77 | 78 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_sem, 0, 0, 1) 79 | ZEND_ARG_OBJ_INFO(0, semaphore, SDL_sem, 0) 80 | ZEND_END_ARG_INFO() 81 | 82 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_cond, 0, 0, 1) 83 | ZEND_ARG_OBJ_INFO(0, condition, SDL_cond, 0) 84 | ZEND_END_ARG_INFO() 85 | 86 | PHP_FUNCTION(SDL_CreateMutex); 87 | PHP_FUNCTION(SDL_LockMutex); 88 | PHP_FUNCTION(SDL_TryLockMutex); 89 | PHP_FUNCTION(SDL_UnlockMutex); 90 | PHP_FUNCTION(SDL_DestroyMutex); 91 | PHP_FUNCTION(SDL_CreateSemaphore); 92 | PHP_FUNCTION(SDL_SemWait); 93 | PHP_FUNCTION(SDL_SemTryWait); 94 | PHP_FUNCTION(SDL_SemPost); 95 | PHP_FUNCTION(SDL_SemValue); 96 | PHP_FUNCTION(SDL_SemWaitTimeout); 97 | PHP_FUNCTION(SDL_DestroySemaphore); 98 | PHP_FUNCTION(SDL_CreateCond); 99 | PHP_FUNCTION(SDL_CondWait); 100 | PHP_FUNCTION(SDL_CondSignal); 101 | PHP_FUNCTION(SDL_CondBroadcast); 102 | PHP_FUNCTION(SDL_CondWaitTimeout); 103 | PHP_FUNCTION(SDL_DestroyCond); 104 | 105 | PHP_MINIT_FUNCTION(sdl_mutex); 106 | 107 | #ifdef __cplusplus 108 | } // extern "C" 109 | #endif 110 | 111 | #endif /* PHP_SDL_MUTEX_H */ 112 | 113 | -------------------------------------------------------------------------------- /tests/007-rect-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rect group test, object mode 3 | --SKIPIF-- 4 | Empty()); 12 | 13 | $r = new SDL_FRect(.0,.0,.0,.0); 14 | var_dump($r); 15 | var_dump($r->Empty()); 16 | 17 | echo "+++ Empty (false)\n"; 18 | $r = new SDL_Rect(1,2,3,4); 19 | var_dump($r, "$r"); 20 | var_dump($r->Empty()); 21 | 22 | $r = new SDL_FRect(1.1, 2.2, 3.3, 4.4); 23 | var_dump($r, "$r"); 24 | var_dump($r->Empty()); 25 | 26 | $r1 = new SDL_Rect(10,10,20,20); 27 | $r2 = new SDL_Rect(10,10,20,20); 28 | $r3 = new SDL_Rect(16,17,22,24); 29 | $r4 = new SDL_Rect(100,10,20,20); 30 | 31 | $fr2 = new SDL_FRect(10.1, 10.1, 20.1, 20.1); 32 | $fr3 = new SDL_FRect(16.1, 17.1, 22.1, 24.1); 33 | $fr4 = new SDL_FRect(100.1, 10.1, 20.1, 20.1); 34 | 35 | echo "+++ Equal (true)\n"; 36 | var_dump($r1->Equal($r1)); 37 | var_dump($r1->Equal($r2)); 38 | echo "+++ Equal (false)\n"; 39 | var_dump($r1->Equal($r3)); 40 | var_dump($r2->Equal($r3)); 41 | 42 | echo "+++ Inter (true)\n"; 43 | var_dump($r2->HasIntersection($r3)); 44 | var_dump($r2->Intersect($r3, $x)); 45 | var_dump($x); unset($x); 46 | 47 | var_dump($fr2->HasIntersection($fr3)); 48 | var_dump($fr2->Intersect($fr3, $x)); 49 | var_dump($x); unset($x); 50 | 51 | echo "+++ Inter (false)\n"; 52 | var_dump($r2->HasIntersection($r4)); 53 | var_dump($r2->Intersect($r4, $x)); 54 | var_dump($x); unset($x); 55 | 56 | var_dump($fr2->HasIntersection($fr4)); 57 | var_dump($fr2->Intersect($fr4, $x)); 58 | var_dump($x); unset($x); 59 | 60 | echo "+++ Union\n"; 61 | var_dump($r2->Union($r3, $x)); 62 | var_dump($x); unset($x); 63 | var_dump($r2->Union($r4, $x)); 64 | var_dump($x); unset($x); 65 | 66 | echo "+++ InterLine\n"; 67 | $x1=0; $y1=10; $x2=40; $y2=30; 68 | var_dump($r1->IntersectLine($x1, $y1, $x2, $y2)); 69 | var_dump($x1, $y1, $x2, $y2); 70 | $x1=0; $y1=2; $x2=40; $y2=6; 71 | var_dump($r1->IntersectLine($x1, $y1, $x2, $y2)); 72 | 73 | echo '+++ Test subclasses of SDL_Rect can be passed to SDL functions', PHP_EOL; 74 | class CustomRect extends \SDL_Rect {} 75 | $customRect = new CustomRect(10, 20, 30, 40); 76 | var_dump(SDL_RectEmpty($customRect)); 77 | ?> 78 | Done 79 | --EXPECTF-- 80 | +++ Empty (true) 81 | object(SDL_Rect)#%d (4) { 82 | ["x"]=> 83 | int(0) 84 | ["y"]=> 85 | int(0) 86 | ["w"]=> 87 | int(0) 88 | ["h"]=> 89 | int(0) 90 | } 91 | string(17) "SDL_Rect(0,0,0,0)" 92 | bool(true) 93 | object(SDL_FRect)#%d (4) { 94 | ["x"]=> 95 | float(0) 96 | ["y"]=> 97 | float(0) 98 | ["w"]=> 99 | float(0) 100 | ["h"]=> 101 | float(0) 102 | } 103 | bool(true) 104 | +++ Empty (false) 105 | object(SDL_Rect)#%d (4) { 106 | ["x"]=> 107 | int(1) 108 | ["y"]=> 109 | int(2) 110 | ["w"]=> 111 | int(3) 112 | ["h"]=> 113 | int(4) 114 | } 115 | string(17) "SDL_Rect(1,2,3,4)" 116 | bool(false) 117 | object(SDL_FRect)#%d (4) { 118 | ["x"]=> 119 | float(1.100000023841858) 120 | ["y"]=> 121 | float(2.200000047683716) 122 | ["w"]=> 123 | float(3.299999952316284) 124 | ["h"]=> 125 | float(4.400000095367432) 126 | } 127 | string(46) "SDL_FRect(1.100000,2.200000,3.300000,4.400000)" 128 | bool(false) 129 | +++ Equal (true) 130 | bool(true) 131 | bool(true) 132 | +++ Equal (false) 133 | bool(false) 134 | bool(false) 135 | +++ Inter (true) 136 | bool(true) 137 | bool(true) 138 | object(SDL_Rect)#%d (4) { 139 | ["x"]=> 140 | int(16) 141 | ["y"]=> 142 | int(17) 143 | ["w"]=> 144 | int(14) 145 | ["h"]=> 146 | int(13) 147 | } 148 | bool(true) 149 | bool(true) 150 | object(SDL_FRect)#%d (4) { 151 | ["x"]=> 152 | float(16.100000381469727) 153 | ["y"]=> 154 | float(17.100000381469727) 155 | ["w"]=> 156 | float(14.100000381469727) 157 | ["h"]=> 158 | float(13.100000381469727) 159 | } 160 | +++ Inter (false) 161 | bool(false) 162 | bool(false) 163 | NULL 164 | bool(false) 165 | bool(false) 166 | NULL 167 | +++ Union 168 | NULL 169 | object(SDL_Rect)#%d (4) { 170 | ["x"]=> 171 | int(10) 172 | ["y"]=> 173 | int(10) 174 | ["w"]=> 175 | int(28) 176 | ["h"]=> 177 | int(31) 178 | } 179 | NULL 180 | object(SDL_Rect)#%d (4) { 181 | ["x"]=> 182 | int(10) 183 | ["y"]=> 184 | int(10) 185 | ["w"]=> 186 | int(110) 187 | ["h"]=> 188 | int(20) 189 | } 190 | +++ InterLine 191 | bool(true) 192 | int(10) 193 | int(15) 194 | int(29) 195 | int(24) 196 | bool(false) 197 | +++ Test subclasses of SDL_Rect can be passed to SDL functions 198 | bool(false) 199 | Done 200 | -------------------------------------------------------------------------------- /tests/023-messagebox.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_MessageBox test 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | r = "123"; 14 | $c->g = 345.6; 15 | $c->b = -5; 16 | var_dump($c); /* string, float, int */ 17 | var_dump("$c"); 18 | var_dump($c); /* 3 int */ 19 | 20 | echo "= SDL_MessageBoxButtonData\n"; 21 | $b = new SDL_MessageBoxButtonData(0,1,"Foo button"); 22 | var_dump($b, "$b"); 23 | 24 | echo "= SDL_MessageBoxData\n"; 25 | $d = new SDL_MessageBoxData(0,"Foo title 1","Foo message"); 26 | var_dump($d, "$d"); 27 | 28 | $buttons = array( 29 | new SDL_MessageBoxButtonData(SDL_MessageBoxButtonData::RETURNKEY_DEFAULT, 1, "Yes"), 30 | new SDL_MessageBoxButtonData(SDL_MessageBoxButtonData::ESCAPEKEY_DEFAULT, 0, "No"), 31 | ); 32 | $colors = array( 33 | SDL_MessageBoxColor::BACKGROUND => new SDL_MessageBoxColor(0,0,0), 34 | SDL_MessageBoxColor::TEXT => new SDL_MessageBoxColor(255,255,255), 35 | SDL_MessageBoxColor::BUTTON_BORDER => new SDL_MessageBoxColor(255,0,0), 36 | SDL_MessageBoxColor::BUTTON_BACKGROUND => new SDL_MessageBoxColor(0,255,0), 37 | SDL_MessageBoxColor::BUTTON_SELECTED => new SDL_MessageBoxColor(0,0,255), 38 | ); 39 | $d = new SDL_MessageBoxData(0,"Foo title 2","Foo message", $buttons, $colors); 40 | var_dump($d, "$d"); 41 | ?> 42 | = Done 43 | --EXPECTF-- 44 | = SDL_MessageBoxColor 45 | object(SDL_MessageBoxColor)#%d (3) { 46 | ["r"]=> 47 | int(1) 48 | ["g"]=> 49 | int(2) 50 | ["b"]=> 51 | int(3) 52 | } 53 | string(26) "SDL_MessageBoxColor(1,2,3)" 54 | object(SDL_MessageBoxColor)#%d (3) { 55 | ["r"]=> 56 | string(3) "123" 57 | ["g"]=> 58 | float(345.6) 59 | ["b"]=> 60 | int(-5) 61 | } 62 | string(31) "SDL_MessageBoxColor(123,89,251)" 63 | object(SDL_MessageBoxColor)#%d (3) { 64 | ["r"]=> 65 | int(123) 66 | ["g"]=> 67 | int(89) 68 | ["b"]=> 69 | int(251) 70 | } 71 | = SDL_MessageBoxButtonData 72 | object(SDL_MessageBoxButtonData)#%d (3) { 73 | ["flags"]=> 74 | int(0) 75 | ["buttonid"]=> 76 | int(1) 77 | ["text"]=> 78 | string(10) "Foo button" 79 | } 80 | string(42) "SDL_MessageBoxButtonData(0,1,"Foo button")" 81 | = SDL_MessageBoxData 82 | object(SDL_MessageBoxData)#%d (7) { 83 | ["flags"]=> 84 | int(0) 85 | ["title"]=> 86 | string(11) "Foo title 1" 87 | ["message"]=> 88 | string(11) "Foo message" 89 | ["window"]=> 90 | bool(false) 91 | ["numbuttons"]=> 92 | int(0) 93 | ["buttons"]=> 94 | NULL 95 | ["colors"]=> 96 | NULL 97 | } 98 | string(33) "SDL_MessageBoxData("Foo title 1")" 99 | object(SDL_MessageBoxData)#%d (7) { 100 | ["flags"]=> 101 | int(0) 102 | ["title"]=> 103 | string(11) "Foo title 2" 104 | ["message"]=> 105 | string(11) "Foo message" 106 | ["window"]=> 107 | bool(false) 108 | ["numbuttons"]=> 109 | int(2) 110 | ["buttons"]=> 111 | array(2) { 112 | [0]=> 113 | object(SDL_MessageBoxColor)#%d (6) { 114 | ["r"]=> 115 | int(0) 116 | ["g"]=> 117 | int(0) 118 | ["b"]=> 119 | int(0) 120 | ["flags"]=> 121 | int(1) 122 | ["buttonid"]=> 123 | int(1) 124 | ["text"]=> 125 | string(3) "Yes" 126 | } 127 | [1]=> 128 | object(SDL_MessageBoxColor)#%d (6) { 129 | ["r"]=> 130 | int(0) 131 | ["g"]=> 132 | int(0) 133 | ["b"]=> 134 | int(0) 135 | ["flags"]=> 136 | int(2) 137 | ["buttonid"]=> 138 | int(0) 139 | ["text"]=> 140 | string(2) "No" 141 | } 142 | } 143 | ["colors"]=> 144 | array(5) { 145 | [0]=> 146 | object(SDL_MessageBoxColor)#%d (3) { 147 | ["r"]=> 148 | int(0) 149 | ["g"]=> 150 | int(0) 151 | ["b"]=> 152 | int(0) 153 | } 154 | [1]=> 155 | object(SDL_MessageBoxColor)#%d (3) { 156 | ["r"]=> 157 | int(255) 158 | ["g"]=> 159 | int(255) 160 | ["b"]=> 161 | int(255) 162 | } 163 | [2]=> 164 | object(SDL_MessageBoxColor)#%d (3) { 165 | ["r"]=> 166 | int(255) 167 | ["g"]=> 168 | int(0) 169 | ["b"]=> 170 | int(0) 171 | } 172 | [3]=> 173 | object(SDL_MessageBoxColor)#%d (3) { 174 | ["r"]=> 175 | int(0) 176 | ["g"]=> 177 | int(255) 178 | ["b"]=> 179 | int(0) 180 | } 181 | [4]=> 182 | object(SDL_MessageBoxColor)#%d (3) { 183 | ["r"]=> 184 | int(0) 185 | ["g"]=> 186 | int(0) 187 | ["b"]=> 188 | int(255) 189 | } 190 | } 191 | } 192 | string(33) "SDL_MessageBoxData("Foo title 2")" 193 | = Done 194 | -------------------------------------------------------------------------------- /src/rwops.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_RWOPS_H 20 | #define PHP_SDL_RWOPS_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_rwops_ce(void); 29 | zend_bool sdl_rwops_to_zval(SDL_RWops *rwops, zval *z_val, Uint32 flags, char *buf); 30 | SDL_RWops *zval_to_sdl_rwops(zval *z_val); 31 | void php_stream_to_zval_rwops(php_stream *stream, zval *return_value, int autoclose); 32 | 33 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWFromFile, 0, 0, 2) 34 | ZEND_ARG_INFO(0, path) 35 | ZEND_ARG_INFO(0, mode) 36 | ZEND_END_ARG_INFO() 37 | 38 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWFromConstMem, 0, 0, 1) 39 | ZEND_ARG_INFO(0, buf) 40 | ZEND_ARG_INFO(0, size) 41 | ZEND_END_ARG_INFO() 42 | 43 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWFromMem, 0, 0, 2) 44 | ZEND_ARG_INFO(1, buf) 45 | ZEND_ARG_INFO(0, size) 46 | ZEND_END_ARG_INFO() 47 | 48 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWFromFP, 0, 0, 1) 49 | ZEND_ARG_INFO(0, fp) 50 | ZEND_ARG_INFO(0, autoclose) 51 | ZEND_END_ARG_INFO() 52 | 53 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWseek, 0, 0, 3) 54 | ZEND_ARG_OBJ_INFO(0, RWops, SDL_RWops, 0) 55 | ZEND_ARG_INFO(0, offset) 56 | ZEND_ARG_INFO(0, whence) 57 | ZEND_END_ARG_INFO() 58 | 59 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWops_seek, 0, 0, 2) 60 | ZEND_ARG_INFO(0, offset) 61 | ZEND_ARG_INFO(0, whence) 62 | ZEND_END_ARG_INFO() 63 | 64 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWread, 0, 0, 3) 65 | ZEND_ARG_OBJ_INFO(0, RWops, SDL_RWops, 0) 66 | ZEND_ARG_INFO(1, buffer) 67 | ZEND_ARG_INFO(0, size) 68 | ZEND_ARG_INFO(0, number) 69 | ZEND_END_ARG_INFO() 70 | 71 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWops_read, 0, 0, 2) 72 | ZEND_ARG_INFO(1, buffer) 73 | ZEND_ARG_INFO(0, size) 74 | ZEND_ARG_INFO(0, number) 75 | ZEND_END_ARG_INFO() 76 | 77 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWwrite, 0, 0, 2) 78 | ZEND_ARG_OBJ_INFO(0, RWops, SDL_RWops, 0) 79 | ZEND_ARG_INFO(0, buffer) 80 | ZEND_ARG_INFO(0, size) 81 | ZEND_ARG_INFO(0, number) 82 | ZEND_END_ARG_INFO() 83 | 84 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWops_write, 0, 0, 1) 85 | ZEND_ARG_INFO(0, buffer) 86 | ZEND_ARG_INFO(0, size) 87 | ZEND_ARG_INFO(0, number) 88 | ZEND_END_ARG_INFO() 89 | 90 | 91 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_write, 0, 0, 2) 92 | ZEND_ARG_OBJ_INFO(0, RWops, SDL_RWops, 0) 93 | ZEND_ARG_INFO(0, value) 94 | ZEND_END_ARG_INFO() 95 | 96 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWops_writeint, 0, 0, 1) 97 | ZEND_ARG_INFO(0, value) 98 | ZEND_END_ARG_INFO() 99 | 100 | 101 | 102 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RWops, 0, 0, 1) 103 | ZEND_ARG_OBJ_INFO(0, RWops, SDL_RWops, 0) 104 | ZEND_END_ARG_INFO() 105 | 106 | PHP_FUNCTION(SDL_AllocRW); 107 | PHP_FUNCTION(SDL_RWFromFile); 108 | PHP_FUNCTION(SDL_RWFromConstMem); 109 | PHP_FUNCTION(SDL_RWFromMem); 110 | PHP_FUNCTION(SDL_RWFromFP); 111 | PHP_FUNCTION(SDL_FreeRW); 112 | PHP_FUNCTION(SDL_RWsize); 113 | PHP_FUNCTION(SDL_RWseek); 114 | PHP_FUNCTION(SDL_RWtell); 115 | PHP_FUNCTION(SDL_RWclose); 116 | PHP_FUNCTION(SDL_RWread); 117 | PHP_FUNCTION(SDL_RWwrite); 118 | PHP_FUNCTION(SDL_ReadU8); 119 | PHP_FUNCTION(SDL_ReadLE16); 120 | PHP_FUNCTION(SDL_ReadBE16); 121 | PHP_FUNCTION(SDL_ReadLE32); 122 | PHP_FUNCTION(SDL_ReadBE32); 123 | PHP_FUNCTION(SDL_ReadLE64); 124 | PHP_FUNCTION(SDL_ReadBE64); 125 | PHP_FUNCTION(SDL_WriteU8); 126 | PHP_FUNCTION(SDL_WriteLE16); 127 | PHP_FUNCTION(SDL_WriteBE16); 128 | PHP_FUNCTION(SDL_WriteLE32); 129 | PHP_FUNCTION(SDL_WriteBE32); 130 | PHP_FUNCTION(SDL_WriteLE64); 131 | PHP_FUNCTION(SDL_WriteBE64); 132 | 133 | PHP_MINIT_FUNCTION(sdl_rwops); 134 | 135 | #ifdef __cplusplus 136 | } // extern "C" 137 | #endif 138 | 139 | #endif /* PHP_SDL_RWOPS_H */ 140 | 141 | -------------------------------------------------------------------------------- /tests/006-rect.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | rect group test, procedural mode 3 | --SKIPIF-- 4 | 97 | Done 98 | --EXPECTF-- 99 | +++ Empty (true) 100 | SDL_Rect(0,0,0,0) 101 | object(SDL_Rect)#%d (4) { 102 | ["x"]=> 103 | int(0) 104 | ["y"]=> 105 | int(0) 106 | ["w"]=> 107 | int(0) 108 | ["h"]=> 109 | int(0) 110 | } 111 | bool(true) 112 | object(SDL_FRect)#%d (4) { 113 | ["x"]=> 114 | float(0) 115 | ["y"]=> 116 | float(0) 117 | ["w"]=> 118 | float(0) 119 | ["h"]=> 120 | float(0) 121 | } 122 | bool(true) 123 | +++ Empty (false) 124 | object(SDL_Rect)#%d (4) { 125 | ["x"]=> 126 | int(1) 127 | ["y"]=> 128 | int(2) 129 | ["w"]=> 130 | int(3) 131 | ["h"]=> 132 | int(4) 133 | } 134 | bool(false) 135 | object(SDL_FRect)#%d (4) { 136 | ["x"]=> 137 | float(1) 138 | ["y"]=> 139 | float(2) 140 | ["w"]=> 141 | float(3) 142 | ["h"]=> 143 | float(4) 144 | } 145 | bool(false) 146 | +++ Equal (true) 147 | bool(true) 148 | bool(true) 149 | +++ Equal (false) 150 | bool(false) 151 | bool(false) 152 | +++ Inter (true) 153 | bool(true) 154 | bool(true) 155 | object(SDL_Rect)#%d (4) { 156 | ["x"]=> 157 | int(16) 158 | ["y"]=> 159 | int(17) 160 | ["w"]=> 161 | int(14) 162 | ["h"]=> 163 | int(13) 164 | } 165 | bool(true) 166 | bool(true) 167 | object(SDL_FRect)#%d (4) { 168 | ["x"]=> 169 | float(16.100000381469727) 170 | ["y"]=> 171 | float(17.100000381469727) 172 | ["w"]=> 173 | float(14.100000381469727) 174 | ["h"]=> 175 | float(13.100000381469727) 176 | } 177 | +++ Inter (false) 178 | bool(false) 179 | bool(false) 180 | NULL 181 | bool(false) 182 | bool(false) 183 | NULL 184 | +++ Union 185 | NULL 186 | object(SDL_Rect)#%d (4) { 187 | ["x"]=> 188 | int(10) 189 | ["y"]=> 190 | int(10) 191 | ["w"]=> 192 | int(28) 193 | ["h"]=> 194 | int(31) 195 | } 196 | NULL 197 | object(SDL_Rect)#%d (4) { 198 | ["x"]=> 199 | int(10) 200 | ["y"]=> 201 | int(10) 202 | ["w"]=> 203 | int(110) 204 | ["h"]=> 205 | int(20) 206 | } 207 | +++ InterLine 208 | bool(true) 209 | int(10) 210 | int(15) 211 | int(29) 212 | int(24) 213 | bool(false) 214 | +++ EnclosePoints 215 | string(67) "SDL_Point(20,14) SDL_Point(13,20) SDL_Point(24,20) SDL_Point(20,28)" 216 | bool(true) 217 | object(SDL_Rect)#%d (4) { 218 | ["x"]=> 219 | int(13) 220 | ["y"]=> 221 | int(14) 222 | ["w"]=> 223 | int(12) 224 | ["h"]=> 225 | int(15) 226 | } 227 | 228 | Warning: SDL_EnclosePoints(): point #4 is not a SDL_Point object in %s/006-rect.php on line %d 229 | 230 | Warning: SDL_EnclosePoints(): point #5 missing in %s/006-rect.php on line %d 231 | bool(false) 232 | NULL 233 | +++ SDL_FRect 234 | object(SDL_FRect)#%d (4) { 235 | ["x"]=> 236 | float(1.1) 237 | ["y"]=> 238 | float(2.2) 239 | ["w"]=> 240 | float(3.3) 241 | ["h"]=> 242 | float(4.4) 243 | } 244 | +++ SDL_FPoint 245 | object(SDL_FPoint)#%d (2) { 246 | ["x"]=> 247 | float(1.1) 248 | ["y"]=> 249 | float(2.2) 250 | } 251 | Done 252 | 253 | -------------------------------------------------------------------------------- /tests/012-pixelformat.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_PixelFormat test, procedural mode 3 | --SKIPIF-- 4 | 38 | = Done 39 | --EXPECTF-- 40 | = Palette 41 | = Color 42 | = PaletteColors 43 | int(0) 44 | = PixelFormat 45 | = PixelFormatPalette 46 | int(0) 47 | = Result 48 | object(SDL_PixelFormat)#%d (16) { 49 | ["format"]=> 50 | int(303039488) 51 | ["BitsPerPixel"]=> 52 | int(4) 53 | ["BytesPerPixel"]=> 54 | int(1) 55 | ["Rmask"]=> 56 | int(0) 57 | ["Gmask"]=> 58 | int(0) 59 | ["Bmask"]=> 60 | int(0) 61 | ["Amask"]=> 62 | int(0) 63 | ["Rloss"]=> 64 | int(8) 65 | ["Gloss"]=> 66 | int(8) 67 | ["Bloss"]=> 68 | int(8) 69 | ["Aloss"]=> 70 | int(8) 71 | ["Rshift"]=> 72 | int(0) 73 | ["Gshift"]=> 74 | int(0) 75 | ["Bshift"]=> 76 | int(0) 77 | ["Ashift"]=> 78 | int(0) 79 | ["palette"]=> 80 | object(SDL_Palette)#%d (4) { 81 | ["ncolors"]=> 82 | int(16) 83 | ["version"]=> 84 | int(2) 85 | ["refcount"]=> 86 | int(2) 87 | ["colors"]=> 88 | array(16) { 89 | [0]=> 90 | object(SDL_Color)#%d (4) { 91 | ["r"]=> 92 | int(0) 93 | ["g"]=> 94 | int(0) 95 | ["b"]=> 96 | int(0) 97 | ["a"]=> 98 | int(0) 99 | } 100 | [1]=> 101 | object(SDL_Color)#%d (4) { 102 | ["r"]=> 103 | int(17) 104 | ["g"]=> 105 | int(17) 106 | ["b"]=> 107 | int(17) 108 | ["a"]=> 109 | int(17) 110 | } 111 | [2]=> 112 | object(SDL_Color)#%d (4) { 113 | ["r"]=> 114 | int(34) 115 | ["g"]=> 116 | int(34) 117 | ["b"]=> 118 | int(34) 119 | ["a"]=> 120 | int(34) 121 | } 122 | [3]=> 123 | object(SDL_Color)#%d (4) { 124 | ["r"]=> 125 | int(51) 126 | ["g"]=> 127 | int(51) 128 | ["b"]=> 129 | int(51) 130 | ["a"]=> 131 | int(51) 132 | } 133 | [4]=> 134 | object(SDL_Color)#%d (4) { 135 | ["r"]=> 136 | int(68) 137 | ["g"]=> 138 | int(68) 139 | ["b"]=> 140 | int(68) 141 | ["a"]=> 142 | int(68) 143 | } 144 | [5]=> 145 | object(SDL_Color)#%d (4) { 146 | ["r"]=> 147 | int(85) 148 | ["g"]=> 149 | int(85) 150 | ["b"]=> 151 | int(85) 152 | ["a"]=> 153 | int(85) 154 | } 155 | [6]=> 156 | object(SDL_Color)#%d (4) { 157 | ["r"]=> 158 | int(102) 159 | ["g"]=> 160 | int(102) 161 | ["b"]=> 162 | int(102) 163 | ["a"]=> 164 | int(102) 165 | } 166 | [7]=> 167 | object(SDL_Color)#%d (4) { 168 | ["r"]=> 169 | int(119) 170 | ["g"]=> 171 | int(119) 172 | ["b"]=> 173 | int(119) 174 | ["a"]=> 175 | int(119) 176 | } 177 | [8]=> 178 | object(SDL_Color)#%d (4) { 179 | ["r"]=> 180 | int(136) 181 | ["g"]=> 182 | int(136) 183 | ["b"]=> 184 | int(136) 185 | ["a"]=> 186 | int(136) 187 | } 188 | [9]=> 189 | object(SDL_Color)#%d (4) { 190 | ["r"]=> 191 | int(153) 192 | ["g"]=> 193 | int(153) 194 | ["b"]=> 195 | int(153) 196 | ["a"]=> 197 | int(153) 198 | } 199 | [10]=> 200 | object(SDL_Color)#%d (4) { 201 | ["r"]=> 202 | int(170) 203 | ["g"]=> 204 | int(170) 205 | ["b"]=> 206 | int(170) 207 | ["a"]=> 208 | int(170) 209 | } 210 | [11]=> 211 | object(SDL_Color)#%d (4) { 212 | ["r"]=> 213 | int(187) 214 | ["g"]=> 215 | int(187) 216 | ["b"]=> 217 | int(187) 218 | ["a"]=> 219 | int(187) 220 | } 221 | [12]=> 222 | object(SDL_Color)#%d (4) { 223 | ["r"]=> 224 | int(204) 225 | ["g"]=> 226 | int(204) 227 | ["b"]=> 228 | int(204) 229 | ["a"]=> 230 | int(204) 231 | } 232 | [13]=> 233 | object(SDL_Color)#%d (4) { 234 | ["r"]=> 235 | int(221) 236 | ["g"]=> 237 | int(221) 238 | ["b"]=> 239 | int(221) 240 | ["a"]=> 241 | int(221) 242 | } 243 | [14]=> 244 | object(SDL_Color)#%d (4) { 245 | ["r"]=> 246 | int(238) 247 | ["g"]=> 248 | int(238) 249 | ["b"]=> 250 | int(238) 251 | ["a"]=> 252 | int(238) 253 | } 254 | [15]=> 255 | object(SDL_Color)#%d (4) { 256 | ["r"]=> 257 | int(255) 258 | ["g"]=> 259 | int(255) 260 | ["b"]=> 261 | int(255) 262 | ["a"]=> 263 | int(255) 264 | } 265 | } 266 | } 267 | } 268 | = RGB 269 | int(8) 270 | int(12) 271 | NULL 272 | int(85) 273 | int(85) 274 | int(85) 275 | NULL 276 | int(170) 277 | int(170) 278 | int(170) 279 | int(170) 280 | = Free 281 | = Done 282 | -------------------------------------------------------------------------------- /src/sdl.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | /* 20 | +----------------------------------------------------------------------+ 21 | | wrapper for SDL2/SDL.h | 22 | +----------------------------------------------------------------------+ 23 | */ 24 | 25 | #include "sdl.h" 26 | 27 | /* {{{ proto int SDL_Init([int flags=SDL_INIT_EVERYTHING]) 28 | 29 | * This function initializes the subsystems specified by \c flags 30 | * Unless the ::SDL_INIT_NOPARACHUTE flag is set, it will install cleanup 31 | * signal handlers for some commonly ignored fatal signals (like SIGSEGV). 32 | extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); 33 | */ 34 | PHP_FUNCTION(SDL_Init) { 35 | zend_long z_flags = (zend_long)SDL_INIT_EVERYTHING; 36 | 37 | ZEND_PARSE_PARAMETERS_START(0, 1) 38 | Z_PARAM_OPTIONAL 39 | Z_PARAM_LONG(z_flags) 40 | ZEND_PARSE_PARAMETERS_END(); 41 | 42 | Uint32 flags = (Uint32)z_flags; 43 | 44 | RETURN_LONG(SDL_Init(flags)); 45 | } 46 | /* }}} */ 47 | 48 | /* {{{ proto int SDL_InitSubSystem(int flags) 49 | 50 | * This function initializes specific SDL subsystems 51 | extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags); 52 | */ 53 | PHP_FUNCTION(SDL_InitSubSystem) { 54 | zend_long flags; 55 | 56 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) { 57 | RETURN_FALSE; 58 | } 59 | 60 | RETURN_LONG(SDL_InitSubSystem((Uint32)flags)); 61 | } 62 | /* }}} */ 63 | 64 | /* {{{ proto void SDL_Quit(void) 65 | 66 | * This function cleans up all initialized subsystems. You should 67 | * call it upon all exit conditions. 68 | extern DECLSPEC void SDLCALL SDL_Quit(void); 69 | */ 70 | PHP_FUNCTION(SDL_Quit) 71 | { 72 | if (zend_parse_parameters_none() == FAILURE) { 73 | RETURN_FALSE; 74 | } 75 | 76 | SDL_Quit(); 77 | } 78 | /* }}} */ 79 | 80 | /* {{{ proto int SDL_QuitSubSystem(int flags) 81 | 82 | * This function cleans up specific SDL subsystems 83 | extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags); 84 | */ 85 | PHP_FUNCTION(SDL_QuitSubSystem) { 86 | zend_long flags; 87 | 88 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &flags) == FAILURE) { 89 | RETURN_FALSE; 90 | } 91 | 92 | SDL_QuitSubSystem((Uint32)flags); 93 | } 94 | /* }}} */ 95 | 96 | /* {{{ proto int SDL_WasInit(int flags) 97 | 98 | * This function returns a mask of the specified subsystems which have 99 | * previously been initialized. 100 | * 101 | * If \c flags is 0, it returns a mask of all initialized subsystems. 102 | extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags); 103 | */ 104 | PHP_FUNCTION(SDL_WasInit) { 105 | zend_long flags = 0; 106 | 107 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { 108 | RETURN_FALSE; 109 | } 110 | 111 | RETURN_LONG(SDL_WasInit((Uint32)flags)); 112 | } 113 | /* }}} */ 114 | 115 | /* {{{ proto int SDL_SetHint(string hint, string value) 116 | 117 | extern DECLSPEC Uint32 SDLCALL SDL_SetHint(char *hint, char *value); 118 | */ 119 | PHP_FUNCTION(SDL_SetHint) { 120 | char *hint; 121 | size_t hint_len; 122 | char *value; 123 | size_t value_len; 124 | 125 | ZEND_PARSE_PARAMETERS_START(2, 2) 126 | Z_PARAM_STRING(hint, hint_len) 127 | Z_PARAM_STRING(value, value_len) 128 | ZEND_PARSE_PARAMETERS_END(); 129 | 130 | RETURN_LONG(SDL_SetHint(hint, value) == SDL_TRUE); 131 | } 132 | /* }}} */ 133 | 134 | /* {{{ PHP_MINIT_FUNCTION */ 135 | PHP_MINIT_FUNCTION(sdl_sdl) 136 | { 137 | /* 138 | * These are the flags which may be passed to SDL_Init(). You should 139 | * specify the subsystems which you will be using in your application. 140 | */ 141 | REGISTER_LONG_CONSTANT("SDL_INIT_TIMER", SDL_INIT_TIMER, CONST_CS | CONST_PERSISTENT); 142 | REGISTER_LONG_CONSTANT("SDL_INIT_AUDIO", SDL_INIT_AUDIO, CONST_CS | CONST_PERSISTENT); 143 | REGISTER_LONG_CONSTANT("SDL_INIT_VIDEO", SDL_INIT_VIDEO, CONST_CS | CONST_PERSISTENT); 144 | REGISTER_LONG_CONSTANT("SDL_INIT_JOYSTICK", SDL_INIT_JOYSTICK, CONST_CS | CONST_PERSISTENT); 145 | REGISTER_LONG_CONSTANT("SDL_INIT_HAPTIC", SDL_INIT_HAPTIC, CONST_CS | CONST_PERSISTENT); 146 | REGISTER_LONG_CONSTANT("SDL_INIT_GAMECONTROLLER", SDL_INIT_GAMECONTROLLER, CONST_CS | CONST_PERSISTENT); 147 | REGISTER_LONG_CONSTANT("SDL_INIT_EVENTS", SDL_INIT_EVENTS, CONST_CS | CONST_PERSISTENT); 148 | REGISTER_LONG_CONSTANT("SDL_INIT_NOPARACHUTE", SDL_INIT_NOPARACHUTE, CONST_CS | CONST_PERSISTENT); 149 | REGISTER_LONG_CONSTANT("SDL_INIT_EVERYTHING", SDL_INIT_EVERYTHING, CONST_CS | CONST_PERSISTENT); 150 | 151 | REGISTER_STRING_CONSTANT("SDL_HINT_RENDER_SCALE_QUALITY", SDL_HINT_RENDER_SCALE_QUALITY, CONST_CS | CONST_PERSISTENT); 152 | 153 | return SUCCESS; 154 | } 155 | /* }}} */ 156 | 157 | 158 | /* 159 | * Local variables: 160 | * tab-width: 4 161 | * c-basic-offset: 4 162 | * End: 163 | * vim600: noet sw=4 ts=4 fdm=marker 164 | * vim<600: noet sw=4 ts=4 165 | */ 166 | -------------------------------------------------------------------------------- /tests/013-pixelformat-oo.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SDL_PixelFormat test, object mode 3 | --SKIPIF-- 4 | SetColors($colors)); 20 | 21 | echo "= PixelFormat\n"; 22 | $f = new SDL_PixelFormat(SDL_PIXELFORMAT_INDEX4LSB); 23 | var_dump("$f"); 24 | 25 | echo "= PixelFormatPalette\n"; 26 | var_dump($f->SetPalette($p)); 27 | 28 | echo "= Result\n"; 29 | var_dump($f); 30 | 31 | echo "= RGB\n"; 32 | var_dump($f->MapRGB(100,100,100)); 33 | var_dump($f->MapRGBA(200,200,200,200)); 34 | var_dump($f->GetRGB(5, $r, $g, $b), $r, $g, $b); 35 | var_dump($f->GetRGBA(10, $r, $g, $b, $a), $r, $g, $b, $a); 36 | 37 | ?> 38 | = Done 39 | --EXPECTF-- 40 | = Palette 41 | string(15) "SDL_Palette(16)" 42 | = Color 43 | string(22) "SDL_Color(85,85,85,85)" 44 | = PaletteColors 45 | int(0) 46 | = PixelFormat 47 | string(42) "SDL_PixelFormat(SDL_PIXELFORMAT_INDEX4LSB)" 48 | = PixelFormatPalette 49 | int(0) 50 | = Result 51 | object(SDL_PixelFormat)#%d (16) { 52 | ["format"]=> 53 | int(303039488) 54 | ["BitsPerPixel"]=> 55 | int(4) 56 | ["BytesPerPixel"]=> 57 | int(1) 58 | ["Rmask"]=> 59 | int(0) 60 | ["Gmask"]=> 61 | int(0) 62 | ["Bmask"]=> 63 | int(0) 64 | ["Amask"]=> 65 | int(0) 66 | ["Rloss"]=> 67 | int(8) 68 | ["Gloss"]=> 69 | int(8) 70 | ["Bloss"]=> 71 | int(8) 72 | ["Aloss"]=> 73 | int(8) 74 | ["Rshift"]=> 75 | int(0) 76 | ["Gshift"]=> 77 | int(0) 78 | ["Bshift"]=> 79 | int(0) 80 | ["Ashift"]=> 81 | int(0) 82 | ["palette"]=> 83 | object(SDL_Palette)#%d (4) { 84 | ["ncolors"]=> 85 | int(16) 86 | ["version"]=> 87 | int(2) 88 | ["refcount"]=> 89 | int(2) 90 | ["colors"]=> 91 | array(16) { 92 | [0]=> 93 | object(SDL_Color)#%d (4) { 94 | ["r"]=> 95 | int(0) 96 | ["g"]=> 97 | int(0) 98 | ["b"]=> 99 | int(0) 100 | ["a"]=> 101 | int(0) 102 | } 103 | [1]=> 104 | object(SDL_Color)#%d (4) { 105 | ["r"]=> 106 | int(17) 107 | ["g"]=> 108 | int(17) 109 | ["b"]=> 110 | int(17) 111 | ["a"]=> 112 | int(17) 113 | } 114 | [2]=> 115 | object(SDL_Color)#%d (4) { 116 | ["r"]=> 117 | int(34) 118 | ["g"]=> 119 | int(34) 120 | ["b"]=> 121 | int(34) 122 | ["a"]=> 123 | int(34) 124 | } 125 | [3]=> 126 | object(SDL_Color)#%d (4) { 127 | ["r"]=> 128 | int(51) 129 | ["g"]=> 130 | int(51) 131 | ["b"]=> 132 | int(51) 133 | ["a"]=> 134 | int(51) 135 | } 136 | [4]=> 137 | object(SDL_Color)#%d (4) { 138 | ["r"]=> 139 | int(68) 140 | ["g"]=> 141 | int(68) 142 | ["b"]=> 143 | int(68) 144 | ["a"]=> 145 | int(68) 146 | } 147 | [5]=> 148 | object(SDL_Color)#%d (4) { 149 | ["r"]=> 150 | int(85) 151 | ["g"]=> 152 | int(85) 153 | ["b"]=> 154 | int(85) 155 | ["a"]=> 156 | int(85) 157 | } 158 | [6]=> 159 | object(SDL_Color)#%d (4) { 160 | ["r"]=> 161 | int(102) 162 | ["g"]=> 163 | int(102) 164 | ["b"]=> 165 | int(102) 166 | ["a"]=> 167 | int(102) 168 | } 169 | [7]=> 170 | object(SDL_Color)#%d (4) { 171 | ["r"]=> 172 | int(119) 173 | ["g"]=> 174 | int(119) 175 | ["b"]=> 176 | int(119) 177 | ["a"]=> 178 | int(119) 179 | } 180 | [8]=> 181 | object(SDL_Color)#%d (4) { 182 | ["r"]=> 183 | int(136) 184 | ["g"]=> 185 | int(136) 186 | ["b"]=> 187 | int(136) 188 | ["a"]=> 189 | int(136) 190 | } 191 | [9]=> 192 | object(SDL_Color)#%d (4) { 193 | ["r"]=> 194 | int(153) 195 | ["g"]=> 196 | int(153) 197 | ["b"]=> 198 | int(153) 199 | ["a"]=> 200 | int(153) 201 | } 202 | [10]=> 203 | object(SDL_Color)#%d (4) { 204 | ["r"]=> 205 | int(170) 206 | ["g"]=> 207 | int(170) 208 | ["b"]=> 209 | int(170) 210 | ["a"]=> 211 | int(170) 212 | } 213 | [11]=> 214 | object(SDL_Color)#%d (4) { 215 | ["r"]=> 216 | int(187) 217 | ["g"]=> 218 | int(187) 219 | ["b"]=> 220 | int(187) 221 | ["a"]=> 222 | int(187) 223 | } 224 | [12]=> 225 | object(SDL_Color)#%d (4) { 226 | ["r"]=> 227 | int(204) 228 | ["g"]=> 229 | int(204) 230 | ["b"]=> 231 | int(204) 232 | ["a"]=> 233 | int(204) 234 | } 235 | [13]=> 236 | object(SDL_Color)#%d (4) { 237 | ["r"]=> 238 | int(221) 239 | ["g"]=> 240 | int(221) 241 | ["b"]=> 242 | int(221) 243 | ["a"]=> 244 | int(221) 245 | } 246 | [14]=> 247 | object(SDL_Color)#%d (4) { 248 | ["r"]=> 249 | int(238) 250 | ["g"]=> 251 | int(238) 252 | ["b"]=> 253 | int(238) 254 | ["a"]=> 255 | int(238) 256 | } 257 | [15]=> 258 | object(SDL_Color)#%d (4) { 259 | ["r"]=> 260 | int(255) 261 | ["g"]=> 262 | int(255) 263 | ["b"]=> 264 | int(255) 265 | ["a"]=> 266 | int(255) 267 | } 268 | } 269 | } 270 | } 271 | = RGB 272 | int(8) 273 | int(12) 274 | NULL 275 | int(85) 276 | int(85) 277 | int(85) 278 | NULL 279 | int(170) 280 | int(170) 281 | int(170) 282 | int(170) 283 | = Done 284 | -------------------------------------------------------------------------------- /src/cpuinfo.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | /* 20 | +----------------------------------------------------------------------+ 21 | | wrapper for SDL2/SDL_cpuinfo.h | 22 | +----------------------------------------------------------------------+ 23 | */ 24 | 25 | #include "cpuinfo.h" 26 | 27 | 28 | /* {{{ proto void SDL_GetCPUCount(void ) 29 | 30 | * This function returns the number of CPU cores available. 31 | extern DECLSPEC int SDLCALL SDL_GetCPUCount(void); 32 | */ 33 | PHP_FUNCTION(SDL_GetCPUCount) 34 | { 35 | if (zend_parse_parameters_none() == FAILURE) { 36 | RETURN_FALSE; 37 | } 38 | 39 | RETURN_LONG(SDL_GetCPUCount()); 40 | } 41 | /* }}} */ 42 | 43 | /* {{{ proto void SDL_GetCPUCount(void ) 44 | 45 | * This function returns the L1 cache line size of the CPU 46 | * 47 | * This is useful for determining multi-threaded structure padding 48 | * or SIMD prefetch sizes. 49 | extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void); 50 | */ 51 | PHP_FUNCTION(SDL_GetCPUCacheLineSize) 52 | { 53 | if (zend_parse_parameters_none() == FAILURE) { 54 | RETURN_FALSE; 55 | } 56 | 57 | RETURN_LONG(SDL_GetCPUCacheLineSize()); 58 | } 59 | /* }}} */ 60 | 61 | /* {{{ proto void SDL_HasRDTSC(void ) 62 | 63 | * This function returns true if the CPU has the RDTSC instruction. 64 | extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void); 65 | */ 66 | PHP_FUNCTION(SDL_HasRDTSC) 67 | { 68 | if (zend_parse_parameters_none() == FAILURE) { 69 | RETURN_FALSE; 70 | } 71 | 72 | RETURN_LONG(SDL_HasRDTSC()); 73 | } 74 | /* }}} */ 75 | 76 | /* {{{ proto void SDL_HasAltiVec(void ) 77 | 78 | * This function returns true if the CPU has AltiVec features. 79 | extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void); 80 | */ 81 | PHP_FUNCTION(SDL_HasAltiVec) 82 | { 83 | if (zend_parse_parameters_none() == FAILURE) { 84 | RETURN_FALSE; 85 | } 86 | 87 | RETURN_LONG(SDL_HasAltiVec()); 88 | } 89 | /* }}} */ 90 | 91 | /* {{{ proto void SDL_HasMMX(void ) 92 | 93 | * This function returns true if the CPU has MMX features. 94 | extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void); 95 | */ 96 | PHP_FUNCTION(SDL_HasMMX) 97 | { 98 | if (zend_parse_parameters_none() == FAILURE) { 99 | RETURN_FALSE; 100 | } 101 | 102 | RETURN_LONG(SDL_HasMMX()); 103 | } 104 | /* }}} */ 105 | 106 | /* {{{ proto void SDL_Has3DNow(void ) 107 | 108 | * This function returns true if the CPU has 3DNow! features. 109 | extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void); 110 | */ 111 | PHP_FUNCTION(SDL_Has3DNow) 112 | { 113 | if (zend_parse_parameters_none() == FAILURE) { 114 | RETURN_FALSE; 115 | } 116 | 117 | RETURN_LONG(SDL_Has3DNow()); 118 | } 119 | /* }}} */ 120 | 121 | /* {{{ proto void SDL_HasSSE(void ) 122 | 123 | * This function returns true if the CPU has SSE features. 124 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void); 125 | */ 126 | PHP_FUNCTION(SDL_HasSSE) 127 | { 128 | if (zend_parse_parameters_none() == FAILURE) { 129 | RETURN_FALSE; 130 | } 131 | 132 | RETURN_LONG(SDL_HasSSE()); 133 | } 134 | /* }}} */ 135 | 136 | 137 | /* {{{ proto void SDL_HasSSE2(void ) 138 | 139 | * This function returns true if the CPU has HasSSE2 features. 140 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void); 141 | */ 142 | PHP_FUNCTION(SDL_HasSSE2) 143 | { 144 | if (zend_parse_parameters_none() == FAILURE) { 145 | RETURN_FALSE; 146 | } 147 | 148 | RETURN_LONG(SDL_HasSSE2()); 149 | } 150 | /* }}} */ 151 | 152 | /* {{{ proto void SDL_HasSSE3(void ) 153 | 154 | * This function returns true if the CPU has SSE3 features. 155 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void); 156 | */ 157 | PHP_FUNCTION(SDL_HasSSE3) 158 | { 159 | if (zend_parse_parameters_none() == FAILURE) { 160 | RETURN_FALSE; 161 | } 162 | 163 | RETURN_LONG(SDL_HasSSE3()); 164 | } 165 | /* }}} */ 166 | 167 | 168 | /* {{{ proto void SDL_HasSSE41(void ) 169 | 170 | * This function returns true if the CPU has SSE4.1 features. 171 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void); 172 | */ 173 | PHP_FUNCTION(SDL_HasSSE41) 174 | { 175 | if (zend_parse_parameters_none() == FAILURE) { 176 | RETURN_FALSE; 177 | } 178 | 179 | RETURN_LONG(SDL_HasSSE41()); 180 | } 181 | /* }}} */ 182 | 183 | /* {{{ proto void SDL_HasSSE42(void ) 184 | 185 | * This function returns true if the CPU has SSE4.2 features. 186 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void); 187 | */ 188 | PHP_FUNCTION(SDL_HasSSE42) 189 | { 190 | if (zend_parse_parameters_none() == FAILURE) { 191 | RETURN_FALSE; 192 | } 193 | 194 | RETURN_LONG(SDL_HasSSE42()); 195 | } 196 | /* }}} */ 197 | 198 | 199 | #if SDL_COMPILEDVERSION > 2000 200 | /* {{{ proto void SDL_GetSystemRAM(void ) 201 | 202 | * This function returns the amount of RAM configured in the system, in MB. 203 | extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void); 204 | */ 205 | PHP_FUNCTION(SDL_GetSystemRAM) 206 | { 207 | if (zend_parse_parameters_none() == FAILURE) { 208 | RETURN_FALSE; 209 | } 210 | 211 | RETURN_LONG(SDL_GetSystemRAM()); 212 | } 213 | /* }}} */ 214 | #endif 215 | 216 | /* {{{ MINIT */ 217 | PHP_MINIT_FUNCTION(sdl_cpuinfo) 218 | { 219 | return SUCCESS; 220 | } 221 | /* }}} */ 222 | -------------------------------------------------------------------------------- /src/joystick.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Author: Santiago Lizardo | 14 | | Author: Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #include "joystick.h" 19 | 20 | #include 21 | 22 | static zend_class_entry *php_sdl_joystick_ce; 23 | static zend_object_handlers php_sdl_joystick_handlers; 24 | 25 | struct php_sdl_joystick 26 | { 27 | SDL_Joystick *intern; 28 | zend_object zo; 29 | }; 30 | typedef struct php_sdl_joystick php_sdl_joystick_t; 31 | 32 | static zend_object *php_sdl_joystick_create_object(zend_class_entry *ce) 33 | { 34 | php_sdl_joystick_t *php_joystick; 35 | 36 | php_joystick = (php_sdl_joystick_t *)ecalloc(1, sizeof(php_sdl_joystick_t) + zend_object_properties_size(ce)); 37 | 38 | zend_object_std_init(&php_joystick->zo, ce); 39 | object_properties_init(&php_joystick->zo, ce); 40 | 41 | php_joystick->intern = NULL; 42 | php_joystick->zo.handlers = (zend_object_handlers *)&php_sdl_joystick_handlers; 43 | 44 | return &php_joystick->zo; 45 | } 46 | 47 | static void php_sdl_joystick_free_object(zend_object *zo) 48 | { 49 | php_sdl_joystick_t *php_joystick = (php_sdl_joystick_t *)((char *)zo - zo->handlers->offset); 50 | zend_object_std_dtor(&php_joystick->zo); 51 | } 52 | 53 | static inline SDL_Joystick *sdl_joystick_from_zval(zval *zjoystick) 54 | { 55 | zend_object *zo = Z_OBJ_P(zjoystick); 56 | php_sdl_joystick_t *php_joystick = (php_sdl_joystick_t *)((char *)zo - zo->handlers->offset); 57 | return php_joystick->intern; 58 | } 59 | 60 | static inline void sdl_joystick_to_zval(SDL_Joystick *joystick, zval *zvalue) 61 | { 62 | object_init_ex(zvalue, php_sdl_joystick_ce); 63 | zend_object *zo = Z_OBJ_P(zvalue); 64 | php_sdl_joystick_t *php_joystick = (php_sdl_joystick_t *)((char *)zo - zo->handlers->offset); 65 | php_joystick->intern = joystick; 66 | } 67 | 68 | PHP_FUNCTION(SDL_NumJoysticks) 69 | { 70 | ZEND_PARSE_PARAMETERS_NONE(); 71 | 72 | RETURN_LONG(SDL_NumJoysticks()); 73 | } 74 | 75 | PHP_FUNCTION(SDL_JoystickNameForIndex) 76 | { 77 | zend_long index; 78 | 79 | ZEND_PARSE_PARAMETERS_START(1, 1) 80 | Z_PARAM_LONG(index) 81 | ZEND_PARSE_PARAMETERS_END(); 82 | 83 | const char *name = SDL_JoystickNameForIndex(index); 84 | if (name) 85 | { 86 | RETURN_STRING(name); 87 | } 88 | 89 | RETURN_NULL(); 90 | } 91 | 92 | PHP_FUNCTION(SDL_JoystickOpen) 93 | { 94 | zend_long index; 95 | 96 | ZEND_PARSE_PARAMETERS_START(1, 1) 97 | Z_PARAM_LONG(index) 98 | ZEND_PARSE_PARAMETERS_END(); 99 | 100 | SDL_Joystick *joystick = SDL_JoystickOpen(index); 101 | if (joystick) 102 | { 103 | sdl_joystick_to_zval(joystick, return_value); 104 | return; 105 | } 106 | 107 | RETURN_NULL(); 108 | } 109 | 110 | PHP_FUNCTION(SDL_JoystickClose) 111 | { 112 | zval *zjoystick; 113 | SDL_Joystick *joystick; 114 | 115 | ZEND_PARSE_PARAMETERS_START(1, 1) 116 | Z_PARAM_OBJECT_OF_CLASS(zjoystick, php_sdl_joystick_ce) 117 | ZEND_PARSE_PARAMETERS_END(); 118 | 119 | joystick = sdl_joystick_from_zval(zjoystick); 120 | 121 | SDL_JoystickClose(joystick); 122 | } 123 | 124 | PHP_FUNCTION(SDL_JoystickName) 125 | { 126 | zval *zjoystick; 127 | SDL_Joystick *joystick; 128 | 129 | ZEND_PARSE_PARAMETERS_START(1, 1) 130 | Z_PARAM_OBJECT_OF_CLASS(zjoystick, php_sdl_joystick_ce) 131 | ZEND_PARSE_PARAMETERS_END(); 132 | 133 | joystick = sdl_joystick_from_zval(zjoystick); 134 | 135 | RETURN_STRING(SDL_JoystickName(joystick)); 136 | } 137 | 138 | PHP_FUNCTION(SDL_JoystickGetAxis) 139 | { 140 | zval *zjoystick; 141 | zend_long axis; 142 | SDL_Joystick *joystick; 143 | 144 | ZEND_PARSE_PARAMETERS_START(2, 2) 145 | Z_PARAM_OBJECT_OF_CLASS(zjoystick, php_sdl_joystick_ce) 146 | Z_PARAM_LONG(axis) 147 | ZEND_PARSE_PARAMETERS_END(); 148 | 149 | joystick = sdl_joystick_from_zval(zjoystick); 150 | 151 | RETURN_LONG(SDL_JoystickGetAxis(joystick, axis)); 152 | } 153 | 154 | PHP_FUNCTION(SDL_JoystickNumButtons) 155 | { 156 | zval *zjoystick; 157 | SDL_Joystick *joystick; 158 | 159 | ZEND_PARSE_PARAMETERS_START(1, 1) 160 | Z_PARAM_OBJECT_OF_CLASS(zjoystick, php_sdl_joystick_ce) 161 | ZEND_PARSE_PARAMETERS_END(); 162 | 163 | joystick = sdl_joystick_from_zval(zjoystick); 164 | 165 | RETURN_LONG(SDL_JoystickNumButtons(joystick)); 166 | } 167 | 168 | PHP_FUNCTION(SDL_IsGameController) 169 | { 170 | zend_long index; 171 | 172 | ZEND_PARSE_PARAMETERS_START(1, 1) 173 | Z_PARAM_LONG(index) 174 | ZEND_PARSE_PARAMETERS_END(); 175 | 176 | RETURN_BOOL(SDL_IsGameController(index) == SDL_TRUE); 177 | } 178 | 179 | PHP_MINIT_FUNCTION(sdl_joystick) 180 | { 181 | zend_class_entry sdl_joystick_ce; 182 | INIT_CLASS_ENTRY(sdl_joystick_ce, "SDL_Joystick", NULL); 183 | 184 | php_sdl_joystick_ce = zend_register_internal_class(&sdl_joystick_ce); 185 | php_sdl_joystick_ce->create_object = php_sdl_joystick_create_object; 186 | 187 | memcpy(&php_sdl_joystick_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 188 | php_sdl_joystick_handlers.free_obj = php_sdl_joystick_free_object; 189 | php_sdl_joystick_handlers.offset = XtOffsetOf(php_sdl_joystick_t, zo); 190 | 191 | return SUCCESS; 192 | } 193 | -------------------------------------------------------------------------------- /src/filesystem.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | /* 20 | +----------------------------------------------------------------------+ 21 | | wrapper for SDL2/SDL_filesystem.h | 22 | +----------------------------------------------------------------------+ 23 | */ 24 | 25 | #include "php_sdl.h" 26 | #include "filesystem.h" 27 | 28 | /** 29 | * {{{ 30 | * \brief Get the path where the application resides. 31 | * 32 | * Get the "base path". This is the directory where the application was run 33 | * from, which is probably the installation directory, and may or may not 34 | * be the process's current working directory. 35 | * 36 | * This returns an absolute path in UTF-8 encoding, and is guaranteed to 37 | * end with a path separator ('\\' on Windows, '/' most other places). 38 | * 39 | * The pointer returned by this function is owned by you. Please call 40 | * SDL_free() on the pointer when you are done with it, or it will be a 41 | * memory leak. This is not necessarily a fast call, though, so you should 42 | * call this once near startup and save the string if you need it. 43 | * 44 | * Some platforms can't determine the application's path, and on other 45 | * platforms, this might be meaningless. In such cases, this function will 46 | * return NULL. 47 | * 48 | * \return String of base dir in UTF-8 encoding, or NULL on error. 49 | * 50 | * \sa SDL_GetPrefPath 51 | */ 52 | PHP_FUNCTION(SDL_GetPrefPath) 53 | { 54 | #if SDL_VERSION_ATLEAST(2,0,1) 55 | char *org = NULL, *app = NULL, *pref_path = NULL; 56 | size_t org_len, app_len; 57 | 58 | if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &org, &org_len, &app, &app_len)) { 59 | RETURN_FALSE; 60 | } 61 | 62 | pref_path = SDL_GetPrefPath(org, app); 63 | if(pref_path) { 64 | RETURN_STRING(pref_path); 65 | SDL_free(pref_path); 66 | } 67 | #endif 68 | } 69 | /* }}} */ 70 | 71 | /** 72 | * {{{ 73 | * \brief Get the user-and-app-specific path where files can be written. 74 | * 75 | * Get the "pref dir". This is meant to be where users can write personal 76 | * files (preferences and save games, etc) that are specific to your 77 | * application. This directory is unique per user, per application. 78 | * 79 | * This function will decide the appropriate location in the native filesystem, 80 | * create the directory if necessary, and return a string of the absolute 81 | * path to the directory in UTF-8 encoding. 82 | * 83 | * On Windows, the string might look like: 84 | * "C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\" 85 | * 86 | * On Linux, the string might look like: 87 | * "/home/bob/.local/share/My Program Name/" 88 | * 89 | * On Mac OS X, the string might look like: 90 | * "/Users/bob/Library/Application Support/My Program Name/" 91 | * 92 | * (etc.) 93 | * 94 | * You specify the name of your organization (if it's not a real organization, 95 | * your name or an Internet domain you own might do) and the name of your 96 | * application. These should be untranslated proper names. 97 | * 98 | * Both the org and app strings may become part of a directory name, so 99 | * please follow these rules: 100 | * 101 | * - Try to use the same org string (including case-sensitivity) for 102 | * all your applications that use this function. 103 | * - Always use a unique app string for each one, and make sure it never 104 | * changes for an app once you've decided on it. 105 | * - Unicode characters are legal, as long as it's UTF-8 encoded, but... 106 | * - ...only use letters, numbers, and spaces. Avoid punctuation like 107 | * "Game Name 2: Bad Guy's Revenge!" ... "Game Name 2" is sufficient. 108 | * 109 | * This returns an absolute path in UTF-8 encoding, and is guaranteed to 110 | * end with a path separator ('\\' on Windows, '/' most other places). 111 | * 112 | * The pointer returned by this function is owned by you. Please call 113 | * SDL_free() on the pointer when you are done with it, or it will be a 114 | * memory leak. This is not necessarily a fast call, though, so you should 115 | * call this once near startup and save the string if you need it. 116 | * 117 | * You should assume the path returned by this function is the only safe 118 | * place to write files (and that SDL_GetBasePath(), while it might be 119 | * writable, or even the parent of the returned path, aren't where you 120 | * should be writing things). 121 | * 122 | * Some platforms can't determine the pref path, and on other 123 | * platforms, this might be meaningless. In such cases, this function will 124 | * return NULL. 125 | * 126 | * \param org The name of your organization. 127 | * \param app The name of your application. 128 | * \return UTF-8 string of user dir in platform-dependent notation. NULL 129 | * if there's a problem (creating directory failed, etc). 130 | * 131 | * \sa SDL_GetBasePath 132 | */ 133 | PHP_FUNCTION(SDL_GetBasePath) 134 | { 135 | #if SDL_VERSION_ATLEAST(2,0,1) 136 | char *base_path = NULL; 137 | base_path = SDL_GetBasePath(); 138 | if(base_path) { 139 | RETURN_STRING(base_path); 140 | SDL_free(base_path); 141 | } 142 | #endif 143 | } 144 | /* }}} */ 145 | 146 | /* {{{ MINIT */ 147 | PHP_MINIT_FUNCTION(sdl_filesystem) 148 | { 149 | return SUCCESS; 150 | } 151 | /* }}} */ 152 | -------------------------------------------------------------------------------- /src/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2016 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #include 20 | 21 | /* 22 | +----------------------------------------------------------------------+ 23 | | wrapper for SDL2/SDL_version.h | 24 | +----------------------------------------------------------------------+ 25 | */ 26 | 27 | #include "php_sdl.h" 28 | #include "version.h" 29 | 30 | zend_bool convert_sdl_version_to_php_array(SDL_version *version, zval *version_array) { 31 | 32 | if (version) { 33 | array_init(version_array); 34 | add_assoc_long(version_array, "major", version->major); 35 | add_assoc_long(version_array, "minor", version->minor); 36 | add_assoc_long(version_array, "patch", version->patch); 37 | 38 | return 1; 39 | } 40 | ZVAL_NULL(version_array); 41 | return 0; 42 | } 43 | 44 | /* {{{ proto string SDL_GetRevision() 45 | 46 | * \brief Get the code revision of SDL that is linked against your program. 47 | * 48 | * Returns an arbitrary string (a hash value) uniquely identifying the 49 | * exact revision of the SDL library in use, and is only useful in comparing 50 | * against other revisions. It is NOT an incrementing number. 51 | */ 52 | PHP_FUNCTION(SDL_GetRevision) 53 | { 54 | if (zend_parse_parameters_none() == FAILURE) { 55 | RETURN_FALSE; 56 | } 57 | 58 | RETURN_STRING(SDL_GetRevision()); 59 | } 60 | /* }}} */ 61 | 62 | #ifdef HAVE_SDL_GETREVISIONNUMBER 63 | /* {{{ proto int SDL_GetRevisionNumber() 64 | 65 | * \brief Get the revision number of SDL that is linked against your program. 66 | * 67 | * Returns a number uniquely identifying the exact revision of the SDL 68 | * library in use. It is an incrementing number based on commits to 69 | * hg.libsdl.org. 70 | */ 71 | PHP_FUNCTION(SDL_GetRevisionNumber) 72 | { 73 | if (zend_parse_parameters_none() == FAILURE) { 74 | RETURN_FALSE; 75 | } 76 | 77 | RETURN_LONG(SDL_GetRevisionNumber()); 78 | } 79 | /* }}} */ 80 | #endif 81 | 82 | /* {{{ proto void SDL_GetVersion(array &version) 83 | 84 | * \brief Get the version of SDL that is linked against your program. 85 | * 86 | * If you are linking to SDL dynamically, then it is possible that the 87 | * current version will be different than the version you compiled against. 88 | * This function returns the current version, while SDL_VERSION() is a 89 | * macro that tells you what version you compiled with. 90 | * 91 | * \code 92 | * SDL_version compiled; 93 | * SDL_version linked; 94 | * 95 | * SDL_VERSION(&compiled); 96 | * SDL_GetVersion(&linked); 97 | * printf("We compiled against SDL version %d.%d.%d ...\n", 98 | * compiled.major, compiled.minor, compiled.patch); 99 | * printf("But we linked against SDL version %d.%d.%d.\n", 100 | * linked.major, linked.minor, linked.patch); 101 | * \endcode 102 | * 103 | * This function may be called safely at any time, even before SDL_Init(). 104 | * 105 | * \sa SDL_VERSION 106 | */ 107 | PHP_FUNCTION(SDL_GetVersion) 108 | { 109 | SDL_version version; 110 | zval *version_array; 111 | 112 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &version_array) == FAILURE) { 113 | RETURN_FALSE; 114 | } 115 | 116 | SDL_GetVersion(&version); 117 | if(0 == convert_sdl_version_to_php_array(&version, version_array)) { 118 | RETURN_FALSE; 119 | } 120 | 121 | RETURN_TRUE; 122 | } 123 | /* }}} */ 124 | 125 | /* {{{ proto void SDL_VERSION(array &version) 126 | 127 | * 128 | * \brief Macro to determine SDL version program was compiled against. 129 | * 130 | * This macro fills in a SDL_version structure with the version of the 131 | * library you compiled against. This is determined by what header the 132 | * compiler uses. Note that if you dynamically linked the library, you might 133 | * have a slightly newer or older version at runtime. That version can be 134 | * determined with SDL_GetVersion(), which, unlike SDL_VERSION(), 135 | * is not a macro. 136 | * 137 | * \param x A pointer to a SDL_version struct to initialize. 138 | * 139 | * \sa SDL_version 140 | * \sa SDL_GetVersion 141 | */ 142 | PHP_FUNCTION(SDL_VERSION) 143 | { 144 | SDL_version version; 145 | zval *version_array; 146 | 147 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "z/", &version_array) == FAILURE) { 148 | RETURN_FALSE; 149 | } 150 | SDL_VERSION(&version); 151 | zval_dtor(version_array); 152 | convert_sdl_version_to_php_array(&version, version_array); 153 | } 154 | /* }}} */ 155 | 156 | /* {{{ proto long SDL_VERSIONNUM(int x, int y, int z) 157 | 158 | * This macro turns the version numbers into a numeric value: 159 | * \verbatim 160 | (1,2,3) -> (1203) 161 | \endverbatim 162 | * 163 | * This assumes that there will never be more than 100 patchlevels. 164 | */ 165 | PHP_FUNCTION(SDL_VERSIONNUM) 166 | { 167 | zend_long x, y, z; 168 | 169 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &x, &y, &z) == FAILURE) { 170 | RETURN_FALSE; 171 | } 172 | 173 | RETURN_LONG(SDL_VERSIONNUM((Uint8)x, (Uint8)y, (Uint8)z)); 174 | } 175 | /* }}} */ 176 | 177 | /* {{{ proto bool SDL_VERSION_ATLEAST(int x, int y, int z) 178 | 179 | * This macro will evaluate to true if compiled with SDL at least X.Y.Z. 180 | */ 181 | PHP_FUNCTION(SDL_VERSION_ATLEAST) 182 | { 183 | zend_long x, y, z; 184 | 185 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &x, &y, &z) == FAILURE) { 186 | RETURN_FALSE; 187 | } 188 | 189 | RETURN_BOOL(SDL_VERSION_ATLEAST((Uint8)x, (Uint8)y, (Uint8)z)); 190 | } 191 | /* }}} */ 192 | 193 | /* {{{ MINIT */ 194 | PHP_MINIT_FUNCTION(sdl_version) 195 | { 196 | REGISTER_LONG_CONSTANT("SDL_COMPILEDVERSION", SDL_COMPILEDVERSION, CONST_CS | CONST_PERSISTENT); 197 | REGISTER_LONG_CONSTANT("SDL_MAJOR_VERSION", SDL_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT); 198 | REGISTER_LONG_CONSTANT("SDL_MINOR_VERSION", SDL_MINOR_VERSION, CONST_CS | CONST_PERSISTENT); 199 | REGISTER_LONG_CONSTANT("SDL_PATCHLEVEL", SDL_PATCHLEVEL, CONST_CS | CONST_PERSISTENT); 200 | REGISTER_STRING_CONSTANT("SDL_REVISION", SDL_REVISION, CONST_CS | CONST_PERSISTENT); 201 | 202 | return SUCCESS; 203 | } 204 | /* }}} */ 205 | 206 | -------------------------------------------------------------------------------- /src/pixels.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_PIXELS_H 20 | #define PHP_SDL_PIXELS_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | /* PHP specific struct to manage memory access */ 29 | typedef struct SDL_Pixels 30 | { 31 | Uint8 *pixels; 32 | } SDL_Pixels; 33 | 34 | zend_class_entry *get_php_sdl_color_ce(void); 35 | zend_bool sdl_color_to_zval(SDL_Color *color, zval *value); 36 | zend_bool zval_to_sdl_color(zval *value, SDL_Color *color); 37 | 38 | zend_class_entry *get_php_sdl_pixelformat_ce(void); 39 | zend_bool sdl_pixelformat_to_zval(SDL_PixelFormat *format, zval *z_val, Uint32 flags); 40 | SDL_PixelFormat *zval_to_sdl_pixelformat(zval *z_val); 41 | 42 | zend_class_entry *get_php_sdl_palette_ce(void); 43 | zend_bool sdl_palette_to_zval(SDL_Palette *palette, zval *z_val, Uint32 flags); 44 | SDL_Palette *zval_to_sdl_palette(zval *z_val); 45 | 46 | zend_class_entry *get_php_sdl_pixels_ce(void); 47 | zend_bool sdl_pixels_to_zval(SDL_Pixels *pixels, zval *z_val, Uint32 flags); 48 | SDL_Pixels *zval_to_sdl_pixels(zval *z_val); 49 | 50 | 51 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetPixelFormatName, 0, 0, 1) 52 | ZEND_ARG_INFO(0, format) 53 | ZEND_END_ARG_INFO() 54 | 55 | 56 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormatEnumToMasks, 0, 0, 6) 57 | ZEND_ARG_INFO(0, format) 58 | ZEND_ARG_INFO(1, bpp) 59 | ZEND_ARG_INFO(1, Rmask) 60 | ZEND_ARG_INFO(1, Gmask) 61 | ZEND_ARG_INFO(1, Bmask) 62 | ZEND_ARG_INFO(1, Amask) 63 | ZEND_END_ARG_INFO() 64 | 65 | 66 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_MasksToPixelFormatEnum, 0, 0, 5) 67 | ZEND_ARG_INFO(0, bpp) 68 | ZEND_ARG_INFO(0, Rmask) 69 | ZEND_ARG_INFO(0, Gmask) 70 | ZEND_ARG_INFO(0, Bmask) 71 | ZEND_ARG_INFO(0, Amask) 72 | ZEND_END_ARG_INFO() 73 | 74 | 75 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_AllocFormat, 0, 0, 1) 76 | ZEND_ARG_INFO(0, format) 77 | ZEND_END_ARG_INFO() 78 | 79 | 80 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_AllocPalette, 0, 0, 1) 81 | ZEND_ARG_INFO(0, ncolors) 82 | ZEND_END_ARG_INFO() 83 | 84 | 85 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetPixelFormatPalette, 0, 0, 2) 86 | ZEND_ARG_OBJ_INFO(0, pixelformat, SDL_PixelFormat, 0) 87 | ZEND_ARG_OBJ_INFO(0, palette, SDL_Palette, 0) 88 | ZEND_END_ARG_INFO() 89 | 90 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormat_SetPalette, 0, 0, 1) 91 | ZEND_ARG_OBJ_INFO(0, palette, SDL_Palette, 0) 92 | ZEND_END_ARG_INFO() 93 | 94 | 95 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetPaletteColors, 0, 0, 2) 96 | ZEND_ARG_OBJ_INFO(0, palette, SDL_Palette, 0) 97 | ZEND_ARG_ARRAY_INFO(0, colors, 0) 98 | ZEND_ARG_INFO(0, first) 99 | ZEND_ARG_INFO(0, ncolors) 100 | ZEND_END_ARG_INFO() 101 | 102 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Palette_SetColors, 0, 0, 1) 103 | ZEND_ARG_ARRAY_INFO(0, colors, 0) 104 | ZEND_ARG_INFO(0, first) 105 | ZEND_ARG_INFO(0, ncolors) 106 | ZEND_END_ARG_INFO() 107 | 108 | 109 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_MapRGB, 0, 0, 4) 110 | //ZEND_ARG_OBJ_INFO(0, pixelformat, SDL_PixelFormat, 0) 111 | ZEND_ARG_INFO(0, pixelformat) 112 | ZEND_ARG_INFO(0, r) 113 | ZEND_ARG_INFO(0, g) 114 | ZEND_ARG_INFO(0, b) 115 | ZEND_END_ARG_INFO() 116 | 117 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormat_MapRGB, 0, 0, 3) 118 | ZEND_ARG_INFO(0, r) 119 | ZEND_ARG_INFO(0, g) 120 | ZEND_ARG_INFO(0, b) 121 | ZEND_END_ARG_INFO() 122 | 123 | 124 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_MapRGBA, 0, 0, 5) 125 | ZEND_ARG_OBJ_INFO(0, pixelformat, SDL_PixelFormat, 0) 126 | ZEND_ARG_INFO(0, r) 127 | ZEND_ARG_INFO(0, g) 128 | ZEND_ARG_INFO(0, b) 129 | ZEND_ARG_INFO(0, a) 130 | ZEND_END_ARG_INFO() 131 | 132 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormat_MapRGBA, 0, 0, 4) 133 | ZEND_ARG_INFO(0, r) 134 | ZEND_ARG_INFO(0, g) 135 | ZEND_ARG_INFO(0, b) 136 | ZEND_ARG_INFO(0, a) 137 | ZEND_END_ARG_INFO() 138 | 139 | 140 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetRGBA, 0, 0, 6) 141 | ZEND_ARG_INFO(0, pixel) 142 | ZEND_ARG_OBJ_INFO(0, format, SDL_PixelFormat, 0) 143 | ZEND_ARG_INFO(1, r) 144 | ZEND_ARG_INFO(1, g) 145 | ZEND_ARG_INFO(1, b) 146 | ZEND_ARG_INFO(1, a) 147 | ZEND_END_ARG_INFO() 148 | 149 | 150 | 151 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormat_GetRGBA, 0, 0, 5) 152 | ZEND_ARG_INFO(0, pixel) 153 | ZEND_ARG_INFO(1, r) 154 | ZEND_ARG_INFO(1, g) 155 | ZEND_ARG_INFO(1, b) 156 | ZEND_ARG_INFO(1, a) 157 | ZEND_END_ARG_INFO() 158 | 159 | 160 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CalculateGammaRamp, 0, 0, 2) 161 | ZEND_ARG_INFO(0, gamma) 162 | ZEND_ARG_INFO(1, ramp) 163 | ZEND_END_ARG_INFO() 164 | 165 | 166 | ZEND_BEGIN_ARG_INFO_EX(arginfo_palette_none, 0, 0, 0) 167 | ZEND_END_ARG_INFO() 168 | 169 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Palette, 0, 0, 1) 170 | ZEND_ARG_OBJ_INFO(0, palette, SDL_Palette, 0) 171 | ZEND_END_ARG_INFO() 172 | 173 | ZEND_BEGIN_ARG_INFO_EX(arginfo_format_none, 0, 0, 0) 174 | ZEND_END_ARG_INFO() 175 | 176 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PixelFormat, 0, 0, 1) 177 | ZEND_ARG_OBJ_INFO(0, format, SDL_PixelFormat, 0) 178 | ZEND_END_ARG_INFO() 179 | 180 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetRGB, 0, 0, 5) 181 | ZEND_ARG_INFO(0, pixel) 182 | ZEND_ARG_OBJ_INFO(0, format, SDL_PixelFormat, 0) 183 | ZEND_ARG_INFO(1, r) 184 | ZEND_ARG_INFO(1, g) 185 | ZEND_ARG_INFO(1, b) 186 | ZEND_END_ARG_INFO() 187 | 188 | 189 | PHP_FUNCTION(SDL_GetPixelFormatName); 190 | PHP_FUNCTION(SDL_PixelFormatEnumToMasks); 191 | PHP_FUNCTION(SDL_MasksToPixelFormatEnum); 192 | PHP_FUNCTION(SDL_AllocFormat); 193 | PHP_FUNCTION(SDL_FreeFormat); 194 | PHP_FUNCTION(SDL_AllocPalette); 195 | PHP_FUNCTION(SDL_SetPixelFormatPalette); 196 | PHP_FUNCTION(SDL_SetPaletteColors); 197 | PHP_FUNCTION(SDL_FreePalette); 198 | PHP_FUNCTION(SDL_MapRGB); 199 | PHP_FUNCTION(SDL_MapRGBA); 200 | PHP_FUNCTION(SDL_GetRGB); 201 | PHP_FUNCTION(SDL_GetRGBA); 202 | PHP_FUNCTION(SDL_CalculateGammaRamp); 203 | 204 | PHP_MINIT_FUNCTION(sdl_pixels); 205 | 206 | #ifdef __cplusplus 207 | } // extern "C" 208 | #endif 209 | 210 | #endif /* PHP_SDL_PIXELS_H */ 211 | 212 | -------------------------------------------------------------------------------- /src/render.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2022 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | #ifndef PHP_SDL_RENDER_H 19 | #define PHP_SDL_RENDER_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "php_sdl.h" 26 | 27 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetRenderDrawColor, 0, 0, 5) 28 | ZEND_ARG_INFO(0, renderer) 29 | ZEND_ARG_INFO(0, r) 30 | ZEND_ARG_INFO(0, g) 31 | ZEND_ARG_INFO(0, b) 32 | ZEND_ARG_INFO(0, a) 33 | ZEND_END_ARG_INFO() 34 | 35 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderClear, 0, 0, 1) 36 | ZEND_ARG_INFO(0, renderer) 37 | ZEND_END_ARG_INFO() 38 | 39 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_DestroyRenderer, 0, 0, 1) 40 | ZEND_ARG_INFO(0, renderer) 41 | ZEND_END_ARG_INFO() 42 | 43 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_DestroyTexture, 0, 0, 1) 44 | ZEND_ARG_INFO(0, texture) 45 | ZEND_END_ARG_INFO() 46 | 47 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderFillRect, 0, 0, 2) 48 | ZEND_ARG_INFO(0, renderer) 49 | ZEND_ARG_OBJ_INFO(0, rect, SDL_Rect, 0) 50 | ZEND_END_ARG_INFO() 51 | 52 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderDrawRect, 0, 0, 2) 53 | ZEND_ARG_INFO(0, renderer) 54 | ZEND_ARG_OBJ_INFO(0, rect, SDL_Rect, 0) 55 | ZEND_END_ARG_INFO() 56 | 57 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderDrawLine, 0, 0, 4) 58 | ZEND_ARG_INFO(0, renderer) 59 | ZEND_ARG_INFO(0, x1) 60 | ZEND_ARG_INFO(0, y1) 61 | ZEND_ARG_INFO(0, x2) 62 | ZEND_ARG_INFO(0, y2) 63 | ZEND_END_ARG_INFO() 64 | 65 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderPresent, 0, 0, 1) 66 | ZEND_ARG_INFO(0, renderer) 67 | ZEND_END_ARG_INFO() 68 | 69 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderDrawPoint, 0, 0, 3) 70 | ZEND_ARG_INFO(0, renderer) 71 | ZEND_ARG_INFO(0, x) 72 | ZEND_ARG_INFO(0, y) 73 | ZEND_END_ARG_INFO() 74 | 75 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateTextureFromSurface, 0, 0, 2) 76 | ZEND_ARG_INFO(0, renderer) 77 | ZEND_ARG_OBJ_INFO(0, surface, SDL_Surface, 0) 78 | ZEND_END_ARG_INFO() 79 | 80 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateTexture, 0, 0, 5) 81 | ZEND_ARG_INFO(0, renderer) 82 | ZEND_ARG_INFO(0, format) 83 | ZEND_ARG_INFO(0, access) 84 | ZEND_ARG_INFO(0, w) 85 | ZEND_ARG_INFO(0, h) 86 | ZEND_END_ARG_INFO() 87 | 88 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_UpdateTexture, 0, 0, 4) 89 | ZEND_ARG_OBJ_INFO(0, texture, SDL_Texture, 0) 90 | ZEND_ARG_OBJ_INFO(0, rect, SDL_Rect, 1) 91 | ZEND_ARG_OBJ_INFO(0, pixels, SDL_Pixels, 0) 92 | ZEND_ARG_TYPE_INFO(0, pitch, IS_LONG, 0) 93 | ZEND_END_ARG_INFO() 94 | 95 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_QueryTexture, 0, 0, 1) 96 | ZEND_ARG_OBJ_INFO(0, texture, SDL_Texture, 0) 97 | ZEND_ARG_TYPE_INFO(1, format, IS_LONG, 1) 98 | ZEND_ARG_TYPE_INFO(1, access, IS_LONG, 1) 99 | ZEND_ARG_TYPE_INFO(1, w, IS_LONG, 1) 100 | ZEND_ARG_TYPE_INFO(1, h, IS_LONG, 1) 101 | ZEND_END_ARG_INFO() 102 | 103 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetRenderTarget, 0, 0, 2) 104 | ZEND_ARG_INFO(0, renderer) 105 | ZEND_ARG_INFO(0, texture) 106 | ZEND_END_ARG_INFO() 107 | 108 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateRenderer, 0, 0, 3) 109 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 110 | ZEND_ARG_INFO(0, index) 111 | ZEND_ARG_INFO(0, flags) 112 | ZEND_END_ARG_INFO() 113 | 114 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateSoftwareRenderer, 0, 0, 1) 115 | ZEND_ARG_OBJ_INFO(0, surface, SDL_Surface, 0) 116 | ZEND_END_ARG_INFO() 117 | 118 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderCopy, 0, 0, 4) 119 | ZEND_ARG_INFO(0, renderer) 120 | ZEND_ARG_INFO(0, texture) 121 | ZEND_ARG_OBJ_INFO(0, srcrect, SDL_Rect, 1) 122 | ZEND_ARG_OBJ_INFO(0, dstrect, SDL_Rect, 1) 123 | ZEND_END_ARG_INFO() 124 | 125 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderCopyEx, 0, 0, 7) 126 | ZEND_ARG_INFO(0, renderer) 127 | ZEND_ARG_INFO(0, texture) 128 | ZEND_ARG_OBJ_INFO(0, srcrect, SDL_Rect, 1) 129 | ZEND_ARG_OBJ_INFO(0, dstrect, SDL_Rect, 1) 130 | ZEND_ARG_INFO(0, angle) 131 | ZEND_ARG_OBJ_INFO(0, center, SDL_Point, 1) 132 | ZEND_ARG_INFO(0, flip) 133 | ZEND_END_ARG_INFO() 134 | 135 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderSetLogicalSize, 0, 0, 3) 136 | ZEND_ARG_OBJ_INFO(0, renderer, SDL_Renderer, 0) 137 | ZEND_ARG_TYPE_INFO(0, w, IS_LONG, 0) 138 | ZEND_ARG_TYPE_INFO(0, h, IS_LONG, 0) 139 | ZEND_END_ARG_INFO() 140 | 141 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetRendererOutputSize, 0, 0, 3) 142 | ZEND_ARG_INFO(0, renderer) 143 | ZEND_ARG_INFO(1, w) 144 | ZEND_ARG_INFO(1, h) 145 | ZEND_END_ARG_INFO() 146 | 147 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_SDL_RenderDrawPointF, 0, 3, IS_LONG, 0) 148 | ZEND_ARG_INFO(0, renderer) 149 | ZEND_ARG_TYPE_INFO(0, x, IS_DOUBLE, 0) 150 | ZEND_ARG_TYPE_INFO(0, y, IS_DOUBLE, 0) 151 | ZEND_END_ARG_INFO() 152 | 153 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_SDL_RenderDrawLineF, 0, 5, IS_LONG, 0) 154 | ZEND_ARG_INFO(0, renderer) 155 | ZEND_ARG_TYPE_INFO(0, x1, IS_DOUBLE, 0) 156 | ZEND_ARG_TYPE_INFO(0, y1, IS_DOUBLE, 0) 157 | ZEND_ARG_TYPE_INFO(0, x2, IS_DOUBLE, 0) 158 | ZEND_ARG_TYPE_INFO(0, y2, IS_DOUBLE, 0) 159 | ZEND_END_ARG_INFO() 160 | 161 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_SDL_RenderDrawRectF, 0, 2, IS_LONG, 0) 162 | ZEND_ARG_INFO(0, renderer) 163 | ZEND_ARG_OBJ_INFO(0, rect, SDL_FRect, 0) 164 | ZEND_END_ARG_INFO() 165 | 166 | #define arginfo_SDL_RenderFillRectF arginfo_SDL_RenderDrawRectF 167 | 168 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_SDL_RenderCopyF, 0, 4, IS_LONG, 0) 169 | ZEND_ARG_INFO(0, renderer) 170 | ZEND_ARG_OBJ_INFO(0, texture, SDL_Texture, 0) 171 | ZEND_ARG_OBJ_INFO(0, srcrect, SDL_Rect, 1) 172 | ZEND_ARG_OBJ_INFO(0, dstrect, SDL_FRect, 1) 173 | ZEND_END_ARG_INFO() 174 | 175 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_SDL_RenderCopyExF, 0, 7, IS_LONG, 0) 176 | ZEND_ARG_INFO(0, renderer) 177 | ZEND_ARG_OBJ_INFO(0, texture, SDL_Texture, 0) 178 | ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, srcrect, SDL_Rect, 1, "null") 179 | ZEND_ARG_OBJ_INFO(0, dstrect, SDL_FRect, 1) 180 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, angle, IS_DOUBLE, 0, "0.0") 181 | ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, center, SDL_FPoint, 1, "null") 182 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flip, IS_LONG, 0, "SDL_FLIP_NONE") 183 | ZEND_END_ARG_INFO() 184 | 185 | PHP_FUNCTION(SDL_SetRenderDrawColor); 186 | PHP_FUNCTION(SDL_RenderClear); 187 | PHP_FUNCTION(SDL_DestroyRenderer); 188 | PHP_FUNCTION(SDL_DestroyTexture); 189 | PHP_FUNCTION(SDL_RenderFillRect); 190 | PHP_FUNCTION(SDL_RenderDrawRect); 191 | PHP_FUNCTION(SDL_RenderDrawLine); 192 | PHP_FUNCTION(SDL_RenderPresent); 193 | PHP_FUNCTION(SDL_RenderDrawPoint); 194 | PHP_FUNCTION(SDL_CreateTextureFromSurface); 195 | PHP_FUNCTION(SDL_CreateTexture); 196 | PHP_FUNCTION(SDL_UpdateTexture); 197 | PHP_FUNCTION(SDL_QueryTexture); 198 | PHP_FUNCTION(SDL_SetRenderTarget); 199 | PHP_FUNCTION(SDL_CreateRenderer); 200 | PHP_FUNCTION(SDL_CreateSoftwareRenderer); 201 | PHP_FUNCTION(SDL_RenderCopy); 202 | PHP_FUNCTION(SDL_RenderCopyEx); 203 | PHP_FUNCTION(SDL_RenderSetLogicalSize); 204 | PHP_FUNCTION(SDL_GetRendererOutputSize); 205 | ZEND_FUNCTION(SDL_RenderDrawPointF); 206 | ZEND_FUNCTION(SDL_RenderDrawLineF); 207 | ZEND_FUNCTION(SDL_RenderDrawRectF); 208 | ZEND_FUNCTION(SDL_RenderFillRectF); 209 | ZEND_FUNCTION(SDL_RenderCopyF); 210 | ZEND_FUNCTION(SDL_RenderCopyExF); 211 | 212 | PHP_MINIT_FUNCTION(sdl_render); 213 | 214 | #ifdef __cplusplus 215 | } // extern "C" 216 | #endif 217 | 218 | #endif /* PHP_SDL_RENDER_H */ 219 | 220 | -------------------------------------------------------------------------------- /src/shape.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2022 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | https://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #include "pixels.h" 20 | #include "shape.h" 21 | #include "window.h" 22 | 23 | static zend_class_entry *php_sdl_windowshapemode_ce; 24 | static zend_object_handlers php_sdl_windowshapemode_handlers; 25 | struct php_sdl_windowshapemode { 26 | SDL_WindowShapeMode mode; 27 | zend_object zo; 28 | }; 29 | 30 | zend_class_entry *get_php_sdl_windowshapemode_ce(void) 31 | { 32 | return php_sdl_windowshapemode_ce; 33 | } 34 | 35 | static inline struct php_sdl_windowshapemode* php_sdl_windowshapemode_fetch_object(zend_object* obj) 36 | { 37 | return (struct php_sdl_windowshapemode*) ((char*) obj - XtOffsetOf(struct php_sdl_windowshapemode, zo)); 38 | } 39 | 40 | 41 | /* {{{ sdl_windowshapemode_to_zval */ 42 | zend_bool sdl_windowshapemode_to_zval(SDL_WindowShapeMode *mode, zval *z_val) 43 | { 44 | if (mode) { 45 | struct php_sdl_windowshapemode *intern; 46 | 47 | object_init_ex(z_val, php_sdl_windowshapemode_ce); 48 | intern = php_sdl_windowshapemode_fetch_object(Z_OBJ_P(z_val)); 49 | memcpy(&intern->mode, mode, sizeof(SDL_WindowShapeMode)); 50 | 51 | return 1; 52 | } 53 | ZVAL_NULL(z_val); 54 | return 0; 55 | } 56 | /* }}} */ 57 | 58 | /* {{{ zval_to_sdl_windowshapemode */ 59 | SDL_WindowShapeMode *zval_to_sdl_windowshapemode(zval *z_val) 60 | { 61 | if (Z_TYPE_P(z_val) == IS_OBJECT && Z_OBJCE_P(z_val) == php_sdl_windowshapemode_ce) { 62 | struct php_sdl_windowshapemode *intern; 63 | intern = php_sdl_windowshapemode_fetch_object(Z_OBJ_P(z_val)); 64 | return &intern->mode; 65 | } 66 | return NULL; 67 | } 68 | /* }}} */ 69 | 70 | 71 | /* {{{ php_sdl_windowshapemode_free 72 | */ 73 | static void php_sdl_windowshapemode_free(zend_object *zo) 74 | { 75 | struct php_sdl_windowshapemode *intern = (struct php_sdl_windowshapemode*)((char*)zo - XtOffsetOf(struct php_sdl_windowshapemode, zo)); 76 | 77 | zend_object_std_dtor(&intern->zo); 78 | } 79 | /* }}} */ 80 | 81 | 82 | /* {{{ php_sdl_windowshapemode_new 83 | */ 84 | static zend_object* php_sdl_windowshapemode_new(zend_class_entry *class_type) 85 | { 86 | struct php_sdl_windowshapemode *intern; 87 | 88 | intern = ecalloc(1, sizeof(struct php_sdl_windowshapemode) + zend_object_properties_size(class_type)); 89 | 90 | zend_object_std_init(&intern->zo, class_type); 91 | object_properties_init(&intern->zo, class_type); 92 | 93 | intern->zo.handlers = (zend_object_handlers *) &php_sdl_windowshapemode_handlers; 94 | 95 | return &intern->zo; 96 | } 97 | /* }}} */ 98 | 99 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_WindowShapeMode__construct, 0, 0, 2) 100 | ZEND_ARG_INFO(0, mode) 101 | ZEND_ARG_INFO(0, parameter) 102 | ZEND_END_ARG_INFO() 103 | 104 | /* {{{ proto SDL_WindowShapeMode::__construct(int mode, mixed param) */ 105 | static PHP_METHOD(SDL_WindowShapeMode, __construct) 106 | { 107 | struct php_sdl_windowshapemode *intern; 108 | zend_long mode; 109 | zval *z_param; 110 | zend_error_handling error_handling; 111 | 112 | intern = php_sdl_windowshapemode_fetch_object(Z_OBJ_P(getThis())); 113 | 114 | zend_replace_error_handling(EH_THROW, NULL, &error_handling); 115 | if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &mode, &z_param)) { 116 | zend_restore_error_handling(&error_handling); 117 | return; 118 | } 119 | zend_restore_error_handling(&error_handling); 120 | 121 | if (SDL_SHAPEMODEALPHA(mode)) { 122 | convert_to_long(z_param); 123 | intern->mode.mode = mode; 124 | intern->mode.parameters.binarizationCutoff = (Uint8)Z_LVAL_P(z_param); 125 | 126 | } else if (mode == ShapeModeColorKey) { 127 | if (Z_TYPE_P( z_param) == IS_OBJECT && Z_OBJCE_P(z_param) == get_php_sdl_color_ce()) { 128 | intern->mode.mode = ShapeModeColorKey; 129 | zval_to_sdl_color(z_param, &intern->mode.parameters.colorKey); 130 | } else { 131 | zend_throw_exception(zend_ce_exception, "Invalid parameter for mode=ShapeModeColorKey, SDL_Color object expected", 0); 132 | } 133 | 134 | 135 | } else { 136 | zend_throw_exception(zend_ce_exception, "Invalid mode for SDL_WindowShapeMode", 0); 137 | } 138 | } 139 | /* }}} */ 140 | 141 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SDL_WindowShapeMode___toString, 0, 0, IS_STRING, 0) 142 | ZEND_END_ARG_INFO() 143 | 144 | /* {{{ proto SDL_WindowShapeMode::__toString() */ 145 | static PHP_METHOD(SDL_WindowShapeMode, __toString) 146 | { 147 | struct php_sdl_windowshapemode *intern; 148 | char *buf; 149 | 150 | if (zend_parse_parameters_none() == FAILURE) { 151 | return; 152 | } 153 | 154 | intern = php_sdl_windowshapemode_fetch_object(Z_OBJ_P(getThis())); 155 | switch (intern->mode.mode) { 156 | case ShapeModeDefault: 157 | spprintf(&buf, 200, "SDL_WindowShapeMode(ShapeModeDefault, %u)", intern->mode.parameters.binarizationCutoff); 158 | break; 159 | case ShapeModeBinarizeAlpha: 160 | spprintf(&buf, 200, "SDL_WindowShapeMode(ShapeModeBinarizeAlpha, %u)", intern->mode.parameters.binarizationCutoff); 161 | break; 162 | case ShapeModeReverseBinarizeAlpha: 163 | spprintf(&buf, 200, "SDL_WindowShapeMode(ShapeModeReverseBinarizeAlpha, %u)", intern->mode.parameters.binarizationCutoff); 164 | break; 165 | case ShapeModeColorKey: 166 | spprintf(&buf, 200, "SDL_WindowShapeMode(ShapeModeColorKey, SDL_Color(%u,%u,%u,%u))", 167 | intern->mode.parameters.colorKey.r, intern->mode.parameters.colorKey.g, 168 | intern->mode.parameters.colorKey.b, intern->mode.parameters.colorKey.a); 169 | break; 170 | default: 171 | spprintf(&buf, 200, "SDL_WindowShapeMode()"); 172 | } 173 | RETVAL_STRING(buf); 174 | } 175 | /* }}} */ 176 | 177 | /* {{{ php_sdl_windowshapemode_methods[] */ 178 | static const zend_function_entry php_sdl_windowshapemode_methods[] = { 179 | PHP_ME(SDL_WindowShapeMode, __construct, arginfo_SDL_WindowShapeMode__construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC) 180 | PHP_ME(SDL_WindowShapeMode, __toString, arginfo_class_SDL_WindowShapeMode___toString, ZEND_ACC_PUBLIC) 181 | 182 | PHP_FE_END 183 | }; 184 | /* }}} */ 185 | 186 | #define REGISTER_CLASS_CONST_LONG(const_name, value) \ 187 | REGISTER_LONG_CONSTANT("ShapeMode" const_name, value, CONST_CS | CONST_PERSISTENT); \ 188 | zend_declare_class_constant_long(php_sdl_windowshapemode_ce, const_name, sizeof(const_name)-1, value); \ 189 | 190 | /* {{{ MINIT */ 191 | PHP_MINIT_FUNCTION(sdl_shape) 192 | { 193 | zend_class_entry ce; 194 | 195 | INIT_CLASS_ENTRY(ce, "SDL_WindowShapeMode", php_sdl_windowshapemode_methods); 196 | php_sdl_windowshapemode_ce = zend_register_internal_class(&ce); 197 | php_sdl_windowshapemode_ce->create_object = php_sdl_windowshapemode_new; 198 | memcpy(&php_sdl_windowshapemode_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); 199 | php_sdl_windowshapemode_handlers.free_obj = php_sdl_windowshapemode_free; 200 | php_sdl_windowshapemode_handlers.offset = XtOffsetOf(struct php_sdl_windowshapemode, zo); 201 | 202 | zend_declare_property_long(php_sdl_windowshapemode_ce, ZEND_STRL("mode"), 0, ZEND_ACC_PUBLIC); 203 | zend_declare_property_long(php_sdl_windowshapemode_ce, ZEND_STRL("colorKey"), 0, ZEND_ACC_PUBLIC); 204 | zend_declare_property_long(php_sdl_windowshapemode_ce, ZEND_STRL("binarizationCutoff"), 0, ZEND_ACC_PUBLIC); 205 | 206 | /* typedef enum WindowShapeMode */ 207 | REGISTER_CLASS_CONST_LONG("Default", ShapeModeDefault); 208 | REGISTER_CLASS_CONST_LONG("BinarizeAlpha", ShapeModeBinarizeAlpha); 209 | REGISTER_CLASS_CONST_LONG("ReverseBinarizeAlpha", ShapeModeReverseBinarizeAlpha); 210 | REGISTER_CLASS_CONST_LONG("ColorKey", ShapeModeColorKey); 211 | 212 | REGISTER_LONG_CONSTANT("SDL_NONSHAPEABLE_WINDOW", SDL_NONSHAPEABLE_WINDOW, CONST_CS | CONST_PERSISTENT); 213 | REGISTER_LONG_CONSTANT("SDL_INVALID_SHAPE_ARGUMENT", SDL_INVALID_SHAPE_ARGUMENT, CONST_CS | CONST_PERSISTENT); 214 | REGISTER_LONG_CONSTANT("SDL_WINDOW_LACKS_SHAPE", SDL_WINDOW_LACKS_SHAPE, CONST_CS | CONST_PERSISTENT); 215 | 216 | return SUCCESS; 217 | } 218 | /* }}} */ 219 | -------------------------------------------------------------------------------- /src/window.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | Copyright (c) 1997-2018 The PHP Group | 4 | +----------------------------------------------------------------------+ 5 | | This source file is subject to version 3.01 of the PHP license, | 6 | | that is bundled with this package in the file LICENSE, and is | 7 | | available through the world-wide-web at the following url: | 8 | | http://www.php.net/license/3_01.txt | 9 | | If you did not receive a copy of the PHP license and are unable to | 10 | | obtain it through the world-wide-web, please send a note to | 11 | | license@php.net so we can mail you a copy immediately. | 12 | +----------------------------------------------------------------------+ 13 | | Authors: Santiago Lizardo | 14 | | Remi Collet | 15 | +----------------------------------------------------------------------+ 16 | */ 17 | 18 | 19 | #ifndef PHP_SDL_WINDOW_H 20 | #define PHP_SDL_WINDOW_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include "php_sdl.h" 27 | 28 | zend_class_entry *get_php_sdl_window_ce(void); 29 | zend_bool sdl_window_to_zval(SDL_Window *window, zval *z_val, int flags); 30 | SDL_Window *zval_to_sdl_window(zval *z_val); 31 | 32 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowDisplayMode, 0, 0, 2) 33 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 34 | ZEND_ARG_OBJ_INFO(0, displaymode, SDL_DisplayMode, 0) 35 | ZEND_END_ARG_INFO() 36 | 37 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetDisplayMode, 0, 0, 1) 38 | ZEND_ARG_OBJ_INFO(0, displaymode, SDL_DisplayMode, 0) 39 | ZEND_END_ARG_INFO() 40 | 41 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetWindowDisplayMode, 0, 0, 2) 42 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 43 | ZEND_ARG_INFO(1, displaymode) 44 | ZEND_END_ARG_INFO() 45 | 46 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetDisplayMode, 0, 0, 1) 47 | ZEND_ARG_INFO(1, displaymode) 48 | ZEND_END_ARG_INFO() 49 | 50 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowIcon, 0, 0, 2) 51 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 52 | ZEND_ARG_OBJ_INFO(0, icon, SDL_Surface, 0) 53 | ZEND_END_ARG_INFO() 54 | 55 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetIcon, 0, 0, 1) 56 | ZEND_ARG_OBJ_INFO(0, icon, SDL_Surface, 0) 57 | ZEND_END_ARG_INFO() 58 | 59 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowData, 0, 0, 3) 60 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 61 | ZEND_ARG_INFO(0, name) 62 | ZEND_ARG_INFO(0, value) 63 | ZEND_END_ARG_INFO() 64 | 65 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetData, 0, 0, 2) 66 | ZEND_ARG_INFO(0, name) 67 | ZEND_ARG_INFO(0, value) 68 | ZEND_END_ARG_INFO() 69 | 70 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetData, 0, 0, 1) 71 | ZEND_ARG_INFO(0, name) 72 | ZEND_END_ARG_INFO() 73 | 74 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowPosition, 0, 0, 3) 75 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 76 | ZEND_ARG_INFO(0, x) 77 | ZEND_ARG_INFO(0, y) 78 | ZEND_END_ARG_INFO() 79 | 80 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetPosition, 0, 0, 2) 81 | ZEND_ARG_INFO(0, x) 82 | ZEND_ARG_INFO(0, y) 83 | ZEND_END_ARG_INFO() 84 | 85 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetSize, 0, 0, 2) 86 | ZEND_ARG_INFO(0, w) 87 | ZEND_ARG_INFO(0, h) 88 | ZEND_END_ARG_INFO() 89 | 90 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_WINDOWPOS_DISPLAY, 0, 0, 1) 91 | ZEND_ARG_INFO(0, display) 92 | ZEND_END_ARG_INFO() 93 | 94 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetWindowPosition, 0, 0, 1) 95 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 96 | ZEND_ARG_INFO(1, x) 97 | ZEND_ARG_INFO(1, y) 98 | ZEND_END_ARG_INFO() 99 | 100 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetSize, 0, 0, 0) 101 | ZEND_ARG_INFO(1, w) 102 | ZEND_ARG_INFO(1, h) 103 | ZEND_END_ARG_INFO() 104 | 105 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetPosition, 0, 0, 0) 106 | ZEND_ARG_INFO(1, x) 107 | ZEND_ARG_INFO(1, y) 108 | ZEND_END_ARG_INFO() 109 | 110 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowBordered, 0, 0, 2) 111 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 112 | ZEND_ARG_INFO(0, bordered) 113 | ZEND_END_ARG_INFO() 114 | 115 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetBordered, 0, 0, 1) 116 | ZEND_ARG_INFO(0, bordered) 117 | ZEND_END_ARG_INFO() 118 | 119 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowFullscreen, 0, 0, 2) 120 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 121 | ZEND_ARG_INFO(0, flags) 122 | ZEND_END_ARG_INFO() 123 | 124 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetFullscreen, 0, 0, 1) 125 | ZEND_ARG_INFO(0, flags) 126 | ZEND_END_ARG_INFO() 127 | 128 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_UpdateWindowSurfaceRects, 0, 0, 2) 129 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 130 | ZEND_ARG_ARRAY_INFO(0, rects, 0) 131 | ZEND_ARG_INFO(0, numrect) 132 | ZEND_END_ARG_INFO() 133 | 134 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_UpdateSurfaceRects, 0, 0, 1) 135 | ZEND_ARG_ARRAY_INFO(0, rects, 0) 136 | ZEND_ARG_INFO(0, numrect) 137 | ZEND_END_ARG_INFO() 138 | 139 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowGrab, 0, 0, 2) 140 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 141 | ZEND_ARG_INFO(0, grabbed) 142 | ZEND_END_ARG_INFO() 143 | 144 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetGrab, 0, 0, 1) 145 | ZEND_ARG_INFO(0, grabbed) 146 | ZEND_END_ARG_INFO() 147 | 148 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowBrightness, 0, 0, 2) 149 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 150 | ZEND_ARG_INFO(0, brightness) 151 | ZEND_END_ARG_INFO() 152 | 153 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetBrightness, 0, 0, 1) 154 | ZEND_ARG_INFO(0, brightness) 155 | ZEND_END_ARG_INFO() 156 | 157 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetGammaRamp, 0, 0, 3) 158 | ZEND_ARG_ARRAY_INFO(0, red, 0) 159 | ZEND_ARG_ARRAY_INFO(0, green, 0) 160 | ZEND_ARG_ARRAY_INFO(0, blue, 0) 161 | ZEND_END_ARG_INFO() 162 | 163 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetWindowGammaRamp, 0, 0, 4) 164 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 165 | ZEND_ARG_INFO(1, red) 166 | ZEND_ARG_INFO(1, green) 167 | ZEND_ARG_INFO(1, blue) 168 | ZEND_END_ARG_INFO() 169 | 170 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetGammaRamp, 0, 0, 3) 171 | ZEND_ARG_INFO(1, red) 172 | ZEND_ARG_INFO(1, green) 173 | ZEND_ARG_INFO(1, blue) 174 | ZEND_END_ARG_INFO() 175 | 176 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_CreateWindow, 0, 0, 6) 177 | ZEND_ARG_INFO(0, title) 178 | ZEND_ARG_INFO(0, x) 179 | ZEND_ARG_INFO(0, y) 180 | ZEND_ARG_INFO(0, w) 181 | ZEND_ARG_INFO(0, h) 182 | ZEND_ARG_INFO(0, flags) 183 | ZEND_END_ARG_INFO() 184 | 185 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowTitle, 0, 0, 2) 186 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 187 | ZEND_ARG_INFO(0, title) 188 | ZEND_END_ARG_INFO() 189 | 190 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetTitle, 0, 0, 1) 191 | ZEND_ARG_INFO(0, title) 192 | ZEND_END_ARG_INFO() 193 | 194 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_SetWindowShape, 0, 0, 3) 195 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 196 | ZEND_ARG_OBJ_INFO(0, surface, SDL_Surface, 0) 197 | ZEND_ARG_OBJ_INFO(0, mode, SDL_WindowShapeMode, 0) 198 | ZEND_END_ARG_INFO() 199 | 200 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_SetShape, 0, 0, 2) 201 | ZEND_ARG_OBJ_INFO(0, surface, SDL_Surface, 0) 202 | ZEND_ARG_OBJ_INFO(0, mode, SDL_WindowShapeMode, 0) 203 | ZEND_END_ARG_INFO() 204 | 205 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_GetShapedWindowMode, 0, 0, 2) 206 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 207 | ZEND_ARG_INFO(1, shaped_mode) 208 | ZEND_END_ARG_INFO() 209 | 210 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window_GetShapedMode, 0, 0, 1) 211 | ZEND_ARG_INFO(1, shaped_mode) 212 | ZEND_END_ARG_INFO() 213 | 214 | ZEND_BEGIN_ARG_INFO_EX(arginfo_window_none, 0, 0, 0) 215 | ZEND_END_ARG_INFO() 216 | 217 | ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_Window, 0, 0, 1) 218 | ZEND_ARG_OBJ_INFO(0, window, SDL_Window, 0) 219 | ZEND_END_ARG_INFO() 220 | 221 | PHP_FUNCTION(SDL_GetWindowDisplayIndex); 222 | PHP_FUNCTION(SDL_SetWindowDisplayMode); 223 | PHP_FUNCTION(SDL_GetWindowDisplayMode); 224 | PHP_FUNCTION(SDL_GetWindowPixelFormat); 225 | PHP_FUNCTION(SDL_GetWindowID); 226 | PHP_FUNCTION(SDL_GetWindowFromID); 227 | PHP_FUNCTION(SDL_GetWindowFlags); 228 | PHP_FUNCTION(SDL_SetWindowIcon); 229 | PHP_FUNCTION(SDL_WINDOWPOS_CENTERED_DISPLAY); 230 | PHP_FUNCTION(SDL_WINDOWPOS_UNDEFINED_DISPLAY); 231 | PHP_FUNCTION(SDL_SetWindowPosition); 232 | PHP_FUNCTION(SDL_GetWindowPosition); 233 | PHP_FUNCTION(SDL_SetWindowSize); 234 | PHP_FUNCTION(SDL_GetWindowSize); 235 | PHP_FUNCTION(SDL_SetWindowMinimumSize); 236 | PHP_FUNCTION(SDL_GetWindowMinimumSize); 237 | PHP_FUNCTION(SDL_SetWindowMaximumSize); 238 | PHP_FUNCTION(SDL_GetWindowMaximumSize); 239 | PHP_FUNCTION(SDL_SetWindowBordered); 240 | PHP_FUNCTION(SDL_ShowWindow); 241 | PHP_FUNCTION(SDL_HideWindow); 242 | PHP_FUNCTION(SDL_RaiseWindow); 243 | PHP_FUNCTION(SDL_MaximizeWindow); 244 | PHP_FUNCTION(SDL_MinimizeWindow); 245 | PHP_FUNCTION(SDL_RestoreWindow); 246 | PHP_FUNCTION(SDL_SetWindowFullscreen); 247 | PHP_FUNCTION(SDL_GetWindowSurface); 248 | PHP_FUNCTION(SDL_UpdateWindowSurfaceRects); 249 | PHP_FUNCTION(SDL_SetWindowGrab); 250 | PHP_FUNCTION(SDL_GetWindowGrab); 251 | PHP_FUNCTION(SDL_SetWindowBrightness); 252 | PHP_FUNCTION(SDL_GetWindowBrightness); 253 | PHP_FUNCTION(SDL_GetWindowGammaRamp); 254 | PHP_FUNCTION(SDL_CreateShapedWindow); 255 | PHP_FUNCTION(SDL_CreateWindow); 256 | PHP_FUNCTION(SDL_UpdateWindowSurface); 257 | PHP_FUNCTION(SDL_DestroyWindow); 258 | PHP_FUNCTION(SDL_GetWindowTitle); 259 | PHP_FUNCTION(SDL_SetWindowTitle); 260 | PHP_FUNCTION(SDL_IsShapedWindow); 261 | PHP_FUNCTION(SDL_SetWindowShape); 262 | PHP_FUNCTION(SDL_GetShapedWindowMode); 263 | 264 | PHP_MINIT_FUNCTION(sdl_window); 265 | 266 | #ifdef __cplusplus 267 | } // extern "C" 268 | #endif 269 | 270 | #endif /* PHP_SDL_WINDOW_H */ 271 | 272 | --------------------------------------------------------------------------------