diff --git a/caca-php/examples/example1.php b/caca-php/examples/example1.php index c116700..759c6c0 100755 --- a/caca-php/examples/example1.php +++ b/caca-php/examples/example1.php @@ -34,11 +34,32 @@ if (!$display) { } -caca_set_color_ansi($pig, CACA_LIGHTRED, CACA_WHITE); +caca_set_color_ansi($pig, CACA_LIGHTMAGENTA, CACA_TRANSPARENT); caca_import_memory($pig, $pig_str, "text"); -caca_blit($canvas, caca_get_canvas_width($canvas) / 2 - 20, caca_get_canvas_height($canvas) /2 - 7, $pig); -caca_refresh_display($display); +caca_set_display_time($display, 30000); -sleep(5); +$x = $y = 0; +$ix = $iy = 1; +while (caca_get_event($display, CACA_EVENT_KEY_PRESS)) { + // In case of resize ... + if ($x + caca_get_canvas_width($pig) - 1 >= caca_get_canvas_width($canvas) || $x < 0 ) + $x = 0; + if ($y + caca_get_canvas_height($pig) - 1 >= caca_get_canvas_height($canvas) || $y < 0 ) + $y = 0; + + caca_clear_canvas($canvas); + + // Draw pig + caca_blit($canvas, $x, $y, $pig); + caca_refresh_display($display); + + $x += $ix; + $y += $iy; + + if ($x + caca_get_canvas_width($pig) >= caca_get_canvas_width($canvas) || $x < 0 ) + $ix = -$ix; + if ($y + caca_get_canvas_height($pig) >= caca_get_canvas_height($canvas) || $y < 0 ) + $iy = -$iy; +} diff --git a/caca-php/php_caca.c b/caca-php/php_caca.c index 3612408..770f930 100644 --- a/caca-php/php_caca.c +++ b/caca-php/php_caca.c @@ -805,6 +805,14 @@ PHP_FUNCTION(caca_refresh_display) { } PHP_FUNCTION(caca_set_display_time) { + zval *_zval; + long value = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) { + RETURN_FALSE; + } + caca_display_t *display; + ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display); + RETURN_BOOL(caca_set_display_time(display, value) == 0); } PHP_FUNCTION(caca_get_display_time) { @@ -860,6 +868,19 @@ PHP_FUNCTION(caca_set_cursor) { } PHP_FUNCTION(caca_get_event) { + zval *_zval1, *_zval2 = NULL; + long g, aa = 0; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) { + RETURN_FALSE; + } + caca_display_t *display; + ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display); + + caca_event_t *event = NULL; + if (_zval2) { + ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event); + } + RETURN_BOOL(caca_get_event(display, g, event, aa) == 0); } PHP_FUNCTION(caca_get_mouse_x) {