Re[8]: [PHP-GTK-DEV] create cursor
| From: | Tom Rogers | Date: | Thu, 05 Aug 2004 14:05:57 +0000 |
| Subject: | Re[8]: [PHP-GTK-DEV] create cursor | ||
| References: | 1 2 | Groups: | php.gtk.dev |
| Request: | Send a blank email to php-gtk-dev+get-675@lists.php.net to get a copy of this message | ||
Hi,
Thursday, August 5, 2004, 10:33:42 AM, you wrote:
S> Why not try doing as the GDK manual example shows it - with two _bitmaps_
S> not two _pixmaps_? You'd need to recompile it to take two bitmaps, sorry..
S> I hadn't seen that example when I suggested the pixmap/bitmap mix.
S> The error you got, Tom, (and I managed to reproduce with two pixmaps) said
S> that the problem was both *maps didn't have a depth of 1. If there's a
S> depth of 1, surely by definition that's a bitmap? Or am I talking out of my
S> bottom (again)?
S> /me is running out of ideas, but suspects that in GDK there's less of a
S> distinction between pixmap and bitmap than there is in PHP-GTK
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