Skip to content

Commit c67eb26

Browse files
b-viguiersantiagolizardo
authored andcommitted
feat: Support for SDL_RenderCopyEx (Ponup#25)
1 parent 428af10 commit c67eb26

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

examples/007-mouse-events.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
SDL_SetRenderDrawColor($renderer, 255, 0, 255, 255);
2222

23+
$rotCenter = new SDL_Point(10, 10);
2324
$event = new SDL_Event;
2425
while (!$quit) {
2526
while(SDL_PollEvent($event)) {
@@ -34,7 +35,7 @@
3435
$destRect->y = $event->motion->y;
3536
$destRect->w = 64;//$drect->w;
3637
$destRect->h = 64;//$drect->h;
37-
if (SDL_RenderCopy($renderer, $texture, NULL, $destRect) != 0) {
38+
if (SDL_RenderCopyEx($renderer, $texture, NULL, $destRect, 90, $rotCenter, SDL_FLIP_NONE) != 0) {
3839
echo SDL_GetError(), PHP_EOL;
3940
}
4041
SDL_RenderPresent($renderer);

php_sdl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static zend_function_entry sdl_functions[] = {
209209
ZEND_FE(SDL_RenderDrawPoint, arginfo_SDL_RenderDrawPoint)
210210
ZEND_FE(SDL_RenderClear, arginfo_SDL_RenderClear)
211211
ZEND_FE(SDL_RenderCopy, arginfo_SDL_RenderCopy)
212+
ZEND_FE(SDL_RenderCopyEx, arginfo_SDL_RenderCopyEx)
212213
ZEND_FE(SDL_RenderFillRect, arginfo_SDL_RenderFillRect)
213214
ZEND_FE(SDL_RenderPresent, arginfo_SDL_RenderPresent)
214215
ZEND_FE(SDL_CreateTextureFromSurface, arginfo_SDL_CreateTextureFromSurface)

render.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,42 @@ PHP_FUNCTION(SDL_RenderCopy)
202202
}
203203
/* }}} */
204204

205+
PHP_FUNCTION(SDL_RenderCopyEx)
206+
{
207+
zval *z_renderer, *z_texture;
208+
zval *z_srcrect, *z_dstrect;
209+
zval *z_center;
210+
SDL_Renderer *renderer = NULL;
211+
SDL_Texture *texture = NULL;
212+
SDL_Rect *srcrect = NULL, *dstrect = NULL;
213+
double angle;
214+
SDL_Point *center = NULL;
215+
long flip;
216+
217+
if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzO!O!dO!l", &z_renderer, &z_texture, &z_srcrect, get_php_sdl_rect_ce(), &z_dstrect, get_php_sdl_rect_ce(), &angle, &z_center, get_php_sdl_point_ce(), &flip) == FAILURE ) {
218+
WRONG_PARAM_COUNT;
219+
}
220+
221+
renderer = (SDL_Renderer*)zend_fetch_resource(Z_RES_P(z_renderer), SDL_RENDERER_RES_NAME, le_sdl_renderer);
222+
texture = (SDL_Texture*)zend_fetch_resource(Z_RES_P(z_texture), SDL_TEXTURE_RES_NAME, le_sdl_texture);
223+
224+
if(z_srcrect != NULL && Z_TYPE_P(z_srcrect) != IS_NULL) {
225+
srcrect = (SDL_Rect*)emalloc(sizeof(SDL_Rect));
226+
zval_to_sdl_rect(z_srcrect, srcrect TSRMLS_CC);
227+
}
228+
if(z_dstrect != NULL && Z_TYPE_P(z_dstrect) != IS_NULL) {
229+
dstrect = (SDL_Rect*)ecalloc(1, sizeof(SDL_Rect));
230+
zval_to_sdl_rect(z_dstrect, dstrect TSRMLS_CC);
231+
}
232+
if(z_center != NULL && Z_TYPE_P(z_center) != IS_NULL) {
233+
center = (SDL_Point*)ecalloc(1, sizeof(SDL_Point));
234+
zval_to_sdl_point(z_center, center TSRMLS_CC);
235+
}
236+
237+
RETURN_LONG(SDL_RenderCopyEx(renderer, texture, srcrect, dstrect, angle, center, (Uint32)flip));
238+
}
239+
/* }}} */
240+
205241
/* {{{ MINIT */
206242
PHP_MINIT_FUNCTION(sdl_render)
207243
{
@@ -210,6 +246,10 @@ PHP_MINIT_FUNCTION(sdl_render)
210246
REGISTER_LONG_CONSTANT("SDL_RENDERER_PRESENTVSYNC", SDL_RENDERER_PRESENTVSYNC, CONST_CS | CONST_PERSISTENT);
211247
REGISTER_LONG_CONSTANT("SDL_RENDERER_TARGETTEXTURE", SDL_RENDERER_TARGETTEXTURE, CONST_CS | CONST_PERSISTENT);
212248

249+
REGISTER_LONG_CONSTANT("SDL_FLIP_NONE", SDL_FLIP_NONE, CONST_CS | CONST_PERSISTENT);
250+
REGISTER_LONG_CONSTANT("SDL_FLIP_HORIZONTAL", SDL_FLIP_HORIZONTAL, CONST_CS | CONST_PERSISTENT);
251+
REGISTER_LONG_CONSTANT("SDL_FLIP_VERTICAL", SDL_FLIP_VERTICAL, CONST_CS | CONST_PERSISTENT);
252+
213253
le_sdl_renderer = zend_register_list_destructors_ex(NULL, NULL, SDL_RENDERER_RES_NAME, module_number);
214254
le_sdl_texture = zend_register_list_destructors_ex(NULL, NULL, SDL_TEXTURE_RES_NAME, module_number);
215255

render.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderCopy, 0, 0, 4)
8585
ZEND_ARG_OBJ_INFO(0, dstrect, SDL_Rect, 1)
8686
ZEND_END_ARG_INFO()
8787

88+
ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_RenderCopyEx, 0, 0, 7)
89+
ZEND_ARG_INFO(0, renderer)
90+
ZEND_ARG_INFO(0, texture)
91+
ZEND_ARG_OBJ_INFO(0, srcrect, SDL_Rect, 1)
92+
ZEND_ARG_OBJ_INFO(0, dstrect, SDL_Rect, 1)
93+
ZEND_ARG_INFO(0, angle)
94+
ZEND_ARG_OBJ_INFO(0, center, SDL_Point, 1)
95+
ZEND_ARG_INFO(0, flip)
96+
ZEND_END_ARG_INFO()
97+
8898
PHP_FUNCTION(SDL_SetRenderDrawColor);
8999
PHP_FUNCTION(SDL_RenderClear);
90100
PHP_FUNCTION(SDL_DestroyRenderer);
@@ -95,6 +105,7 @@ PHP_FUNCTION(SDL_RenderDrawPoint);
95105
PHP_FUNCTION(SDL_CreateTextureFromSurface);
96106
PHP_FUNCTION(SDL_CreateRenderer);
97107
PHP_FUNCTION(SDL_RenderCopy);
108+
PHP_FUNCTION(SDL_RenderCopyEx);
98109

99110
PHP_MINIT_FUNCTION(sdl_render);
100111

0 commit comments

Comments
 (0)