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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ zend_bool sdl_event_to_zval(SDL_Event *event, zval *value)

switch (event->type)
{
case SDL_FINGERDOWN:
case SDL_FINGERUP:
case SDL_FINGERMOTION:
{
zval tfinger;
php_sdl_touchfingerevent_to_zval(&event->tfinger, &tfinger);
add_property_zval(value, "tfinger", &tfinger);

}
break;
case SDL_MOUSEMOTION:
{
zval motion;
Expand Down Expand Up @@ -240,6 +250,11 @@ PHP_MINIT_FUNCTION(sdl_event)

REGISTER_LONG_CONSTANT("SDL_QUIT", SDL_QUIT, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("SDL_FINGERDOWN", SDL_FINGERDOWN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SDL_FINGERUP", SDL_FINGERUP, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SDL_FINGERMOTION", SDL_FINGERMOTION, CONST_CS | CONST_PERSISTENT);


REGISTER_LONG_CONSTANT("SDL_APP_TERMINATING", SDL_APP_TERMINATING, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SDL_APP_LOWMEMORY", SDL_APP_LOWMEMORY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SDL_APP_WILLENTERBACKGROUND", SDL_APP_WILLENTERBACKGROUND, CONST_CS | CONST_PERSISTENT);
Expand Down Expand Up @@ -291,6 +306,50 @@ PHP_MINIT_FUNCTION(sdl_event)
zend_declare_property_null(php_sdl_event_ce, ZEND_STRL("window"), ZEND_ACC_PUBLIC);
zend_declare_property_null(php_sdl_event_ce, ZEND_STRL("button"), ZEND_ACC_PUBLIC);


// touchpad
zend_declare_property_null(php_sdl_event_ce, "tfinger", sizeof("tfinger") - 1, ZEND_ACC_PUBLIC);

zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "SDL_TouchFingerEvent", NULL);
sdlTouchFingerEvent_ce = zend_register_internal_class(&ce);


// Déclaration explicite des propriétés publiques
zend_declare_property_null(sdlTouchFingerEvent_ce, "type", sizeof("type") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "timestamp", sizeof("timestamp") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "x", sizeof("x") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "y", sizeof("y") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "dx", sizeof("dx") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "dy", sizeof("dy") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "pressure", sizeof("pressure") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "fingerId", sizeof("fingerId") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(sdlTouchFingerEvent_ce, "touchId", sizeof("touchId") - 1, ZEND_ACC_PUBLIC);


return SUCCESS;
}
/* }}} */

zend_class_entry *sdlTouchFingerEvent_ce;

zend_object* php_sdl_touchfingerevent_new(zend_class_entry *class_type) {
zend_object *obj = zend_objects_new(class_type);
object_properties_init(obj, class_type);
obj->handlers = &std_object_handlers;
return obj;
}

void php_sdl_touchfingerevent_to_zval(SDL_TouchFingerEvent *event, zval *value) {
object_init_ex(value, sdlTouchFingerEvent_ce);

add_property_long(value, "type", event->type);
add_property_long(value, "timestamp", event->timestamp);
add_property_double(value, "x", event->x);
add_property_double(value, "y", event->y);
add_property_double(value, "dx", event->dx);
add_property_double(value, "dy", event->dy);
add_property_double(value, "pressure", event->pressure);
add_property_long(value, "fingerId", (zend_long)event->fingerId);
add_property_long(value, "touchId", (zend_long)event->touchId);
}
5 changes: 3 additions & 2 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ extern "C" {
zend_class_entry *get_php_sdl_event_ce(void);
zend_bool sdl_event_to_zval(SDL_Event *event, zval *value);
zend_bool zval_to_sdl_event(zval *value, SDL_Event *event);

void php_sdl_touchfingerevent_to_zval(SDL_TouchFingerEvent *event, zval *value);
extern zend_class_entry *sdlTouchFingerEvent_ce; // déclaration externe
ZEND_BEGIN_ARG_INFO_EX(arginfo_SDL_PollEvent, 0, 0, 1)
ZEND_ARG_OBJ_INFO(1, event, SDL_Event, 0)
ZEND_END_ARG_INFO()
Expand All @@ -42,7 +43,7 @@ PHP_FUNCTION(SDL_WaitEvent);
PHP_MINIT_FUNCTION(sdl_event);

#ifdef __cplusplus
} // extern "C"
} // extern "C"
#endif

#endif /* PHP_SDL_EVENT_H */
Expand Down
19 changes: 15 additions & 4 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ PHP_FUNCTION(SDL_UpdateTexture)
if(z_rect != NULL && Z_TYPE_P(z_rect) != IS_NULL) {
rect = &def_rect;
zval_to_sdl_rect(z_rect, rect);
rect = NULL;
rect = NULL;
}

if (!(pixels = zval_to_sdl_pixels(z_pixels)))
Expand All @@ -261,9 +261,20 @@ PHP_FUNCTION(SDL_SetRenderTarget)
}

renderer = (SDL_Renderer*)zend_fetch_resource(Z_RES_P(z_renderer), SDL_RENDERER_RES_NAME, le_sdl_renderer);
texture = (SDL_Texture*)zend_fetch_resource(Z_RES_P(z_texture), SDL_TEXTURE_RES_NAME, le_sdl_texture);

if( renderer && texture ) {
// texture = (SDL_Texture*)zend_fetch_resource(Z_RES_P(z_texture), SDL_TEXTURE_RES_NAME, le_sdl_texture);
if (Z_TYPE_P(z_texture) == IS_NULL) {
// SDL accepte NULL pour reset la target vers le default render target
texture = NULL;
} else {
texture = (SDL_Texture*)zend_fetch_resource(Z_RES_P(z_texture), SDL_TEXTURE_RES_NAME, le_sdl_texture);
if (!texture) {
php_error_docref(NULL, E_WARNING, "Invalid SDL_Texture resource");
RETURN_FALSE;
}
}

if (renderer)
{
RETURN_LONG(SDL_SetRenderTarget(renderer, texture));
}
}
Expand Down