From 17a2833d831eb68ca5fce8a0fb75f3fea37a3d5b Mon Sep 17 00:00:00 2001 From: David Nurdin Date: Sat, 24 May 2025 00:05:43 +0200 Subject: [PATCH 1/4] add touchscreen --- src/event.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/event.h | 5 +++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/event.c b/src/event.c index 45942ee..be0c31c 100644 --- a/src/event.c +++ b/src/event.c @@ -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; @@ -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); @@ -291,6 +306,37 @@ 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_class_entry ce; + INIT_CLASS_ENTRY(ce, "SDL_TouchFingerEvent", NULL); + sdlTouchFingerEvent_ce = zend_register_internal_class(&ce); + + + 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); +} diff --git a/src/event.h b/src/event.h index 297fcf2..ba0be5c 100644 --- a/src/event.h +++ b/src/event.h @@ -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() @@ -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 */ From 28928984d4750689ccb199c853ccc74cb20d1ed9 Mon Sep 17 00:00:00 2001 From: David Nurdin Date: Sat, 24 May 2025 00:23:40 +0200 Subject: [PATCH 2/4] deprecated dynamic properties --- src/event.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/event.c b/src/event.c index be0c31c..92613cf 100644 --- a/src/event.c +++ b/src/event.c @@ -313,6 +313,17 @@ PHP_MINIT_FUNCTION(sdl_event) 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; } From 245a817d12057fc32a9ac8ec23543b7beaeea0c9 Mon Sep 17 00:00:00 2001 From: David Nurdin Date: Sat, 24 May 2025 00:43:30 +0200 Subject: [PATCH 3/4] properties dynamic --- src/event.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/event.c b/src/event.c index 92613cf..29fa842 100644 --- a/src/event.c +++ b/src/event.c @@ -308,6 +308,8 @@ PHP_MINIT_FUNCTION(sdl_event) // 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); From 89855c8f4f63b77f9a548007b9c4afe366785b4b Mon Sep 17 00:00:00 2001 From: David Nurdin Date: Wed, 4 Jun 2025 15:48:37 +0200 Subject: [PATCH 4/4] bug render target null --- src/render.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/render.c b/src/render.c index 9314a00..49412c7 100644 --- a/src/render.c +++ b/src/render.c @@ -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))) @@ -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)); } }