浏览代码

* Remove php function caca_create_event

* caca_get_event return false if type == CACA_EVENT_NONE otherwise return a new
  php resource
* Adapt sample program demo.php
tags/v0.99.beta17
Nicolas Vion nico 16 年前
父节点
当前提交
a234a5971e
共有 3 个文件被更改,包括 49 次插入60 次删除
  1. +35
    -38
      caca-php/examples/demo.php
  2. +14
    -20
      caca-php/php_caca.c
  3. +0
    -2
      caca-php/php_caca.h

+ 35
- 38
caca-php/examples/demo.php 查看文件

@@ -15,8 +15,6 @@
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/



function main() {
$cv = caca_create_canvas(0, 0);
if (!$cv) {
@@ -30,7 +28,7 @@ function main() {

caca_set_display_time($dp, 40000);

/* Disable cursor */
/* Disable X cursor */
caca_set_mouse($dp, 0);

/* Main menu */
@@ -39,9 +37,8 @@ function main() {
/* Go ! */
$bounds = $outline = $dithering = 0;
$need_refresh = false;
$ev = caca_create_event();
while(!$quit) {
while (caca_get_event($dp, CACA_EVENT_ANY, $ev, 1000)) {
while ($ev = caca_get_event($dp, CACA_EVENT_ANY, 1000)) {
if (caca_get_event_type($ev) & CACA_EVENT_KEY_PRESS) {
switch (caca_get_event_key_ch($ev)) {
case ord('q'):
@@ -116,6 +113,39 @@ function main() {
}
}

function display_menu($cv, $dp, $bounds, $outline, $refresh = true) {
$xo = caca_get_canvas_width($cv) - 2;
$yo = caca_get_canvas_height($cv) - 2;

caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas($cv);
caca_draw_thin_box($cv, 1, 1, $xo, $yo);

caca_put_str($cv, ($xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
caca_put_str($cv, ($xo - strlen("==============")) / 2, 4, "==============");

caca_put_str($cv, 4, 6, "demos:");
caca_put_str($cv, 4, 7, "'f': full");
caca_put_str($cv, 4, 8, "'1': dots");
caca_put_str($cv, 4, 9, "'2': lines");
caca_put_str($cv, 4, 10, "'3': boxes");
caca_put_str($cv, 4, 11, "'4': triangles");
caca_put_str($cv, 4, 12, "'5': ellipses");
caca_put_str($cv, 4, 13, "'c': colour");
caca_put_str($cv, 4, 14, "'r': render");

if ($sprite)
caca_put_str($cv, 4, 15, "'s': sprites");

caca_put_str($cv, 4, 16, "settings:");
caca_put_str($cv, 4, 17, "'o': outline: ".(($outline == 0) ? "none" : (($outline == 1) ? "solid" : "thin")));
caca_put_str($cv, 4, 18, "'b': drawing boundaries: ".(($bounds == 0) ? "screen" : "infinite"));
caca_put_str($cv, 4, $yo - 2, "'q': quit");

if ($refresh)
caca_refresh_display($dp);
}

function demo_go($dp, $demo, $cv, $bounds, $outline) {
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas($cv);
@@ -220,39 +250,6 @@ function demo_all($cv, $bounds, $outline) {
}
}

function display_menu($cv, $dp, $bounds, $outline, $refresh = true) {
$xo = caca_get_canvas_width($cv) - 2;
$yo = caca_get_canvas_height($cv) - 2;

caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
caca_clear_canvas($cv);
caca_draw_thin_box($cv, 1, 1, $xo, $yo);

caca_put_str($cv, ($xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
caca_put_str($cv, ($xo - strlen("==============")) / 2, 4, "==============");

caca_put_str($cv, 4, 6, "demos:");
caca_put_str($cv, 4, 7, "'f': full");
caca_put_str($cv, 4, 8, "'1': dots");
caca_put_str($cv, 4, 9, "'2': lines");
caca_put_str($cv, 4, 10, "'3': boxes");
caca_put_str($cv, 4, 11, "'4': triangles");
caca_put_str($cv, 4, 12, "'5': ellipses");
caca_put_str($cv, 4, 13, "'c': colour");
caca_put_str($cv, 4, 14, "'r': render");

if ($sprite)
caca_put_str($cv, 4, 15, "'s': sprites");

caca_put_str($cv, 4, 16, "settings:");
caca_put_str($cv, 4, 17, "'o': outline: ".(($outline == 0) ? "none" : (($outline == 1) ? "solid" : "thin")));
caca_put_str($cv, 4, 18, "'b': drawing boundaries: ".(($bounds == 0) ? "screen" : "infinite"));
caca_put_str($cv, 4, $yo - 2, "'q': quit");

if ($refresh)
caca_refresh_display($dp);
}

function demo_dots($cv, $bounds, $outline) {
$xmax = caca_get_canvas_width($cv);
$ymax = caca_get_canvas_height($cv);


+ 14
- 20
caca-php/php_caca.c 查看文件

@@ -19,7 +19,6 @@
#include <gd.h>

static function_entry caca_functions[] = {
PHP_FE(caca_create_event, NULL)
PHP_FE(caca_create_canvas, NULL)
PHP_FE(caca_set_canvas_size, NULL)
PHP_FE(caca_get_canvas_width, NULL)
@@ -381,18 +380,6 @@ void *gd_get_pixels(gdImage *img) {
}
}

//------- PHP Binding's specific functions ----------//

//TODO: register new resources in caca_get_event and remove caca_create_event
PHP_FUNCTION(caca_create_event) {
caca_event_t *event;
event = emalloc(sizeof(caca_event_t));
if (!event) {
RETURN_FALSE;
}
ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
}

//------- Caca's functions ----------------//

PHP_FUNCTION(caca_create_canvas) {
@@ -1714,19 +1701,26 @@ PHP_FUNCTION(caca_set_cursor) {
}

PHP_FUNCTION(caca_get_event) {
zval *_zval1, *_zval2 = NULL;
zval *_zval = NULL;
long g, aa = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &_zval, &g, &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);
ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);

caca_event_t *event = emalloc(sizeof(caca_event_t));
if (!event) {
RETURN_FALSE;
}

caca_get_event(display, g, event, aa);

caca_event_t *event = NULL;
if (_zval2) {
ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
if (caca_get_event_type(event) == CACA_EVENT_NONE) {
efree(event);
RETURN_FALSE;
}
RETURN_LONG(caca_get_event(display, g, event, aa));
ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
}

PHP_FUNCTION(caca_get_mouse_x) {


+ 0
- 2
caca-php/php_caca.h 查看文件

@@ -35,8 +35,6 @@ int le_caca_event;
PHP_MINIT_FUNCTION(caca);
PHP_MINFO_FUNCTION(caca);

PHP_FUNCTION(caca_create_event);

PHP_FUNCTION(caca_create_canvas);
PHP_FUNCTION(caca_set_canvas_size);
PHP_FUNCTION(caca_get_canvas_width);


正在加载...
取消
保存