X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fsp-cursor.cpp;h=4bbba5f10875748550293add149c905de30b6e12;hb=b752616506705efd28f22c4d852d198ff40c7026;hp=75b0affe377381e25270f1cff815e20ac82dcdaf;hpb=ec6318247c57f041ede7a34a88d59c636edc2d90;p=inkscape.git diff --git a/src/sp-cursor.cpp b/src/sp-cursor.cpp index 75b0affe3..4bbba5f10 100644 --- a/src/sp-cursor.cpp +++ b/src/sp-cursor.cpp @@ -12,11 +12,14 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include +#include +#include +#include #include #include "sp-cursor.h" -void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, gchar **xpm) +void +sp_cursor_bitmap_and_mask_from_xpm(GdkBitmap **bitmap, GdkBitmap **mask, gchar const *const *xpm) { int height; int width; @@ -30,7 +33,7 @@ void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, g int transparent_color = ' '; int black_color = '.'; - + char pixmap_buffer[(32 * 32)/8]; char mask_buffer[(32 * 32)/8]; @@ -51,7 +54,7 @@ void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, g if (strcmp(p, "None") == 0) { transparent_color = ccode; } - + if (strcmp(p, "#000000") == 0) { black_color = ccode; } @@ -59,20 +62,20 @@ void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, g for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; ) { - + char value = 0; char maskv = 0; for (int pix = 0; pix < 8; pix++, x++){ - if (xpm [4+y][x] != transparent_color) { + if (xpm[4+y][x] != transparent_color) { maskv |= 1 << pix; - if (xpm [4+y][x] == black_color) { + if (xpm[4+y][x] == black_color) { value |= 1 << pix; } } } - + pixmap_buffer[(y * 4 + x/8)-1] = value; mask_buffer[(y * 4 + x/8)-1] = maskv; } @@ -82,40 +85,25 @@ void sp_cursor_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, g *mask = gdk_bitmap_create_from_data(NULL, mask_buffer, 32, 32); } -GdkCursor *sp_cursor_new_from_xpm (gchar **xpm, gint hot_x, gint hot_y) +GdkCursor * +sp_cursor_new_from_xpm(gchar const *const *xpm, gint hot_x, gint hot_y) { -GdkDisplay *display=gdk_display_get_default(); - if ( - gdk_display_supports_cursor_alpha(display) & - gdk_display_supports_cursor_color(display) - ) - { - GdkPixbuf *pixbuf=NULL; - GdkCursor *new_cursor=NULL; - pixbuf=gdk_pixbuf_new_from_xpm_data((const char**)xpm); - if (pixbuf != NULL){ - new_cursor = gdk_cursor_new_from_pixbuf(display,pixbuf,hot_x,hot_y); - } + GdkColor const fg = { 0, 0, 0, 0 }; + GdkColor const bg = { 0, 65535, 65535, 65535 }; + + GdkBitmap *bitmap = NULL; + GdkBitmap *mask = NULL; + + sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm); + if ( bitmap != NULL && mask != NULL ) { + GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask, + &fg, &bg, + hot_x, hot_y); + g_object_unref (bitmap); + g_object_unref (mask); return new_cursor; } - else - { - GdkColor const fg = { 0, 0, 0, 0 }; - GdkColor const bg = { 0, 65535, 65535, 65535 }; - - GdkBitmap *bitmap = NULL; - GdkBitmap *mask = NULL; - - sp_cursor_bitmap_and_mask_from_xpm (&bitmap, &mask, xpm); - if ( bitmap != NULL && mask != NULL ) { - GdkCursor *new_cursor = gdk_cursor_new_from_pixmap (bitmap, mask, - &fg, &bg, - hot_x, hot_y); - g_object_unref (bitmap); - g_object_unref (mask); - return new_cursor; - } - } + return NULL; }