draw_polygon - possible code...
| From: | Alan Knowles | Date: | Wed, 29 Aug 2001 02:54:31 +0000 |
| Subject: | draw_polygon - possible code... | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-26@lists.php.net to get a copy of this message | ||
had a look at draw_polygon - this version uses a array eg.
(1,0,2,0,2,2,1,2) etc. to create the polygon..
- the overhead to create a 'point object' for 'x,y' seemed a bit much..
I guess it could also do
((1,0),(2,0),(2,2))..
note that there is no error checking on the array reading..
I think the code could be fitted into gen_types.php reasonably easily..
thoughts...
regards
alan
PHP_FUNCTION(wrap_gdk_draw_polygon)
{
GdkDrawable *drawable;
zval **data_temp;
zval *php_drawable, *gc;
zval *php_data = NULL;
GdkPoint *points = NULL;
gint n_elements;
gint filled;
int i;
if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "VOiV", &php_drawable, &gc, gdk_gc_ce,
&filled, &php_data))
return;
if (php_gtk_check_class(php_drawable, gdk_window_ce))
drawable = (GdkDrawable *)PHP_GDK_WINDOW_GET(php_drawable);
else if(php_gtk_check_class(php_drawable, gdk_pixmap_ce))
drawable = (GdkDrawable *)PHP_GDK_PIXMAP_GET(php_drawable);
else if(php_gtk_check_class(php_drawable, gdk_bitmap_ce))
drawable = (GdkDrawable *)PHP_GDK_BITMAP_GET(php_drawable);
else {
php_error(E_WARNING, "%s() expects the drawable to be GdkWindow, GdkPixmap, or
GdkBitmap", get_active_function_name());
return;
}
// how many items ** will barf if not a factor of 2?
// then for each item convert it into a point!
n_elements = zend_hash_num_elements(Z_ARRVAL_P(php_data)) / 2;
points = g_new(GdkPoint, n_elements);
i = 0;
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_data));
zend_hash_get_current_data(Z_ARRVAL_P(php_data), (void **)&data_temp);
zend_hash_move_forward(Z_ARRVAL_P(php_data))) {
convert_to_long_ex(data_temp);
points[i].x = Z_LVAL_PP(data_temp);
zend_hash_move_forward(Z_ARRVAL_P(php_data));
zend_hash_get_current_data(Z_ARRVAL_P(php_data), (void **)&data_temp);
convert_to_long_ex(data_temp);
points[i++].y = Z_LVAL_PP(data_temp);
}
gdk_draw_polygon(drawable, PHP_GDK_GC_GET(gc), (gint) filled, points, n_elements);
RETURN_NULL();
}