Browse Source

* Add Php binding for caca's functions: caca_get_event, caca_set_display_time

* Animate pink pig & add event managment in sample program "example1.php"
tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
728d89c673
2 changed files with 46 additions and 4 deletions
  1. +25
    -4
      caca-php/examples/example1.php
  2. +21
    -0
      caca-php/php_caca.c

+ 25
- 4
caca-php/examples/example1.php View File

@@ -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_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;
}



+ 21
- 0
caca-php/php_caca.c View File

@@ -805,6 +805,14 @@ PHP_FUNCTION(caca_refresh_display) {
} }


PHP_FUNCTION(caca_set_display_time) { 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) { PHP_FUNCTION(caca_get_display_time) {
@@ -860,6 +868,19 @@ PHP_FUNCTION(caca_set_cursor) {
} }


PHP_FUNCTION(caca_get_event) { 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) { PHP_FUNCTION(caca_get_mouse_x) {


Loading…
Cancel
Save