RE: Re[8]: [PHP-GTK-DEV] create cursor

From: Date: Thu, 05 Aug 2004 16:10:01 +0000
Subject: RE: Re[8]: [PHP-GTK-DEV] create cursor
References: 1  Groups: php.gtk.dev 
Request: Send a blank email to php-gtk-dev+get-677@lists.php.net to get a copy of this message
Wow, you used GdkImage? /me is impressed If simply replacing pixmap with bitmap in the .defs file works, wouldn't it be easier to take the resulting entry from gen_gdk.c and put that into gdk.overrides? Just a thought - Steph > I did what you suggested and of course it works, so then I worked > backwards and ended up with this which now works. > > PHP_FUNCTION(gdk_cursor_new_from_pixmap) > { > zval *source, *mask, *fg, *bg; > long x, y,i,j; > int width,height; > GdkPixmap *dest,*spix; > GdkGC *gc; > GdkImage *simage,*dimage; > guint32 pixel; > > if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "OOOOii", > &source, gdk_pixmap_ce, &mask, gdk_bitmap_ce, &fg, gdk_color_ce, > &bg, gdk_color_ce, &x, &y)) > return; > > spix = PHP_GDK_PIXMAP_GET(source); > if(spix){ > gdk_drawable_get_size(spix,&width,&height); > > simage = gdk_image_get(spix,0,0,width,height); > > dest = gdk_pixmap_new(NULL,width,height,1); > dimage = gdk_image_get(dest,0,0,width,height); > > for(i=0;i<height;i++){ > for(j=0;j<width;j++){ > pixel = gdk_image_get_pixel(simage,j,i); > pixel = (pixel == 0)? 0:1; > gdk_image_put_pixel(dimage,j,i,pixel); > } > } > gc = gdk_gc_new(dest); > gdk_draw_image(dest,gc,dimage,0,0,0,0,width,height); > > PHP_GTK_SEPARATE_RETURN(return_value, > php_gdk_cursor_new(gdk_cursor_new_from_pixmap (dest, > PHP_GDK_BITMAP_GET(mask), PHP_GDK_COLOR_GET(fg), > PHP_GDK_COLOR_GET(bg), (gint)x, (gint)y))); > > /* cleanup */ > gdk_gc_unref(gc); > gdk_image_destroy(simage); > gdk_image_destroy(dimage); > gdk_pixmap_unref(dest); > > } > return; > } > > and the php code to make it work: > > > <?php > if( !extension_loaded('gtk')) { > dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); > } > > $window = &new GtkWindow(); > $window->set_default_size(300, 300); > $window->connect_object('destroy', array('gtk', 'main_quit')); > > $cursorpmp = array( > "16 16 3 1", > "0 c none s none", > "1 c black", > "w c white", > "0000000110000000", > "0000001ww1000000", > "000001wwww100000", > "00001wwwwww10000", > "0001wwwwwwww1000", > "001wwwwwwwwww100", > "01wwwww11wwwww10", > "1wwwww1001wwwww1", > "1wwwww1001wwwww1", > "01wwwww11wwwww10", > "001wwwwwwwwww100", > "0001wwwwwwww1000", > "00001wwwwww10000", > "000001wwww100000", > "0000001ww1000000", > "0000000110000000" > ); > > $window->realize(); > $gdkwin = $window->window; > > list($pixmap, $mask) = gdk::pixmap_create_from_xpm_d($gdkwin, > null, $cursorpmp); > > $style = new GtkStyle(); > $fg = gdk::color_parse('black'); > $bg = gdk::color_parse('white'); > $cursor = gdk::cursor_new_from_pixmap($pixmap, $mask, $fg, $bg, 8, 8); > > $gdkwin->set_cursor($cursor); > $window->show(); > > gtk::main(); > ?> > > This was done under windows so it will need testing on a real system > :) > > -- > regards, > Tom > > -- > PHP-GTK Development Mailing List (http://gtk.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.gtk.dev (#677) next »