Changeset 3114
- Timestamp:
- Oct 26, 2008, 10:27:32 PM (14 years ago)
- Location:
- libcaca/trunk/caca-php
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/examples/drivers.php
r3113 r3114 2 2 <? 3 3 4 echo "libcaca version: ".caca_get_version()."\n"; 4 5 //--- Just for fun ---// 6 7 function just_for_fun() { 8 9 $moo = <<<EOT 10 (__) 11 (oo) 12 /------\/ 13 / | || 14 * /\---/\ 15 ~~ ~~ 16 EOT; 17 18 $cv = caca_create_canvas(0, 0); 19 caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT); 20 caca_import_string($cv, $moo, "text"); 21 22 for($j = 0; $j < caca_get_canvas_height($cv); $j++) { 23 for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) { 24 caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT); 25 $a = caca_get_attr($cv, -1, -1); 26 caca_put_attr($cv, $i, $j, $a); 27 caca_put_attr($cv, $i + 1, $j, $a); 28 } 29 } 30 caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT); 31 caca_put_str($cv, 8, 0, "Moo!"); 32 echo caca_export_string($cv, "utf8"); 33 } 34 35 36 just_for_fun(); 37 38 //--- Show caca's information ---// 39 40 echo "libcaca version: ".caca_get_version()."\n\n"; 5 41 echo "Available drivers:\n"; 6 42 $list = caca_get_display_driver_list(); 7 43 foreach($list as $type => $name) 8 44 echo "* $name ($type)\n"; 45 echo "\n"; 46 47 echo "Available export modules:\n"; 48 $list = caca_get_export_list(); 49 foreach($list as $type => $name) 50 echo "* $name ($type)\n"; 51 echo "\n"; 52 53 echo "Available caca fonts:\n"; 54 $list = caca_get_font_list(); 55 foreach($list as $name) 56 echo "* $name\n"; 57 echo "\n"; -
libcaca/trunk/caca-php/php_caca.c
r3113 r3114 957 957 958 958 PHP_FUNCTION(caca_get_dither_color_list) { 959 zval *_zval; 960 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 961 RETURN_FALSE; 962 } 963 caca_dither_t *dither; 964 ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); 965 966 char const * const *list = caca_get_dither_antialias_list(dither); 967 int i; 968 array_init(return_value); 969 for(i = 0; list[i]; i += 2) 970 add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); 959 971 } 960 972 … … 966 978 967 979 PHP_FUNCTION(caca_get_dither_charset_list) { 980 zval *_zval; 981 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 982 RETURN_FALSE; 983 } 984 caca_dither_t *dither; 985 ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); 986 987 char const * const *list = caca_get_dither_charset_list(dither); 988 int i; 989 array_init(return_value); 990 for(i = 0; list[i]; i += 2) 991 add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); 968 992 } 969 993 … … 975 999 976 1000 PHP_FUNCTION(caca_get_dither_algorithm_list) { 1001 zval *_zval; 1002 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 1003 RETURN_FALSE; 1004 } 1005 caca_dither_t *dither; 1006 ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither); 1007 1008 char const * const *list = caca_get_dither_algorithm_list(dither); 1009 int i; 1010 array_init(return_value); 1011 for(i = 0; list[i]; i += 2) 1012 add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); 977 1013 } 978 1014 … … 984 1020 985 1021 PHP_FUNCTION(caca_get_font_list) { 1022 char const * const *list = caca_get_font_list(); 1023 int i; 1024 array_init(return_value); 1025 for(i = 0; list[i]; i += 1) 1026 add_next_index_string(return_value, (char*) list[i], 1); 986 1027 } 987 1028 988 1029 PHP_FUNCTION(caca_get_font_width) { 1030 zval *_zval; 1031 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 1032 RETURN_FALSE; 1033 } 1034 caca_font_t *font; 1035 ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font); 1036 RETURN_LONG(caca_get_font_width(font)); 989 1037 } 990 1038 991 1039 PHP_FUNCTION(caca_get_font_height) { 1040 zval *_zval; 1041 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { 1042 RETURN_FALSE; 1043 } 1044 caca_font_t *font; 1045 ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font); 1046 RETURN_LONG(caca_get_font_height(font)); 992 1047 } 993 1048 … … 1062 1117 1063 1118 PHP_FUNCTION(caca_get_export_list) { 1119 char const * const *list = caca_get_export_list(); 1120 int i; 1121 array_init(return_value); 1122 for(i = 0; list[i]; i += 2) 1123 add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1); 1064 1124 } 1065 1125
Note: See TracChangeset
for help on using the changeset viewer.