summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Valavanis <valavanisalex@gmail.com>2012-05-27 23:56:59 +0000
committerAlex Valavanis <valavanisalex@gmail.com>2012-05-27 23:56:59 +0000
commit732b61f8a63db0f01ea3e524f20e74ddcbab5c48 (patch)
tree59ff4ec6efc38c69f62d97419fd4fbaa7d9b2a71 /src
parentReorder measure context item painting for better legibility. (diff)
downloadinkscape-732b61f8a63db0f01ea3e524f20e74ddcbab5c48.tar.gz
inkscape-732b61f8a63db0f01ea3e524f20e74ddcbab5c48.zip
Stop using deprecated GdkBitmap in custom cursors
Fixed bugs: - https://launchpad.net/bugs/943200 (bzr r11429)
Diffstat (limited to 'src')
-rw-r--r--src/event-context.cpp16
-rw-r--r--src/sp-cursor.cpp94
-rw-r--r--src/sp-cursor.h1
-rw-r--r--src/ui/widget/selected-style.cpp23
4 files changed, 24 insertions, 110 deletions
diff --git a/src/event-context.cpp b/src/event-context.cpp
index 63a77ec58..fbde681d8 100644
--- a/src/event-context.cpp
+++ b/src/event-context.cpp
@@ -212,21 +212,19 @@ void sp_event_context_update_cursor(SPEventContext *ec) {
g_object_unref(pixbuf);
}
} else {
- GdkBitmap *bitmap = NULL;
- GdkBitmap *mask = NULL;
- sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, ec->cursor_shape);
- if ((bitmap != NULL) && (mask != NULL)) {
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)ec->cursor_shape);
+
+ if (pixbuf) {
if (ec->cursor)
#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(ec->cursor);
#else
gdk_cursor_unref(ec->cursor);
#endif
- ec->cursor = gdk_cursor_new_from_pixmap(bitmap, mask,
- &style->black, &style->white, ec->hot_x,
- ec->hot_y);
- g_object_unref(bitmap);
- g_object_unref(mask);
+ ec->cursor = gdk_cursor_new_from_pixbuf(display,
+ pixbuf, ec->hot_x, ec->hot_y);
+
+ g_object_unref(pixbuf);
}
}
}
diff --git a/src/sp-cursor.cpp b/src/sp-cursor.cpp
index 2069bddbd..ea73da00c 100644
--- a/src/sp-cursor.cpp
+++ b/src/sp-cursor.cpp
@@ -23,80 +23,6 @@
#include "color.h"
#include "sp-cursor.h"
-void sp_cursor_bitmap_and_mask_from_xpm(GdkBitmap **bitmap, GdkBitmap **mask, gchar const *const *xpm)
-{
- int height = 0;
- int width = 0;
- int colors = 0;
- int pix = 0;
- std::stringstream ss;
- ss << xpm[0];
- ss >> height;
- ss >> width;
- ss >> colors;
- ss >> pix;
-
- g_return_if_fail(height == 32);
- g_return_if_fail(width == 32);
- g_return_if_fail(colors >= 3);
-
- int transparent_color = ' ';
- std::string black_colors;
-
- char pixmap_buffer[(32 * 32) / 8] = {0};
- char mask_buffer[(32 * 32) / 8] = {0};
-
- for (int i = 0; i < colors; i++) {
-
- char const *p = xpm[1 + i];
- char const ccode = *p;
-
- p++;
- while (isspace(*p)) {
- p++;
- }
- p++;
- while (isspace(*p)) {
- p++;
- }
-
- if (strcmp(p, "None") == 0) {
- transparent_color = ccode;
- }
-
- if (strcmp(p, "Stroke") == 0) {
- black_colors.push_back(ccode);
- }
-
- if (strcmp(p, "#000000") == 0) {
- black_colors.push_back(ccode);
- }
- }
-
- 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[1 + colors + y][x] != transparent_color) {
- maskv |= 1 << pix;
-
- if (black_colors.find(xpm[1 + colors + y][x]) != std::string::npos) {
- value |= 1 << pix;
- }
- }
- }
-
- pixmap_buffer[(y * 4 + x / 8) - 1] = value;
- mask_buffer[(y * 4 + x / 8) - 1] = maskv;
- }
- }
-
- *bitmap = gdk_bitmap_create_from_data(NULL, pixmap_buffer, 32, 32);
- *mask = gdk_bitmap_create_from_data(NULL, mask_buffer, 32, 32);
-}
-
static void free_cursor_data(guchar *pixels, gpointer /*data*/) {
delete [] reinterpret_cast<guint32*>(pixels);
}
@@ -187,19 +113,13 @@ GdkPixbuf *sp_cursor_pixbuf_from_xpm(gchar const *const *xpm, GdkColor const& bl
GdkCursor *sp_cursor_new_from_xpm(gchar const *const *xpm, gint hot_x, gint hot_y)
{
GdkCursor *cursor = 0;
- GdkColor const fg = { 0, 0, 0, 0 };
- GdkColor const bg = { 0, 65535, 65535, 65535 };
-
- GdkBitmap *bitmap = 0;
- GdkBitmap *mask = 0;
-
- sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, xpm);
- if ( bitmap && mask ) {
- cursor = gdk_cursor_new_from_pixmap(bitmap, mask,
- &fg, &bg,
- hot_x, hot_y);
- g_object_unref(bitmap);
- g_object_unref(mask);
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)xpm);
+
+ if (pixbuf) {
+ cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(),
+ pixbuf, hot_x, hot_y);
+
+ g_object_unref(pixbuf);
}
return cursor;
diff --git a/src/sp-cursor.h b/src/sp-cursor.h
index 8c23d4632..f445127ad 100644
--- a/src/sp-cursor.h
+++ b/src/sp-cursor.h
@@ -3,7 +3,6 @@
#include <gdk/gdk.h>
-void sp_cursor_bitmap_and_mask_from_xpm(GdkBitmap **bitmap, GdkBitmap **mask, gchar const *const *xpm);
GdkPixbuf* sp_cursor_pixbuf_from_xpm(gchar const *const *xpm, GdkColor const& black, GdkColor const& white, guint32 fill, guint32 stroke);
GdkCursor *sp_cursor_new_from_xpm(gchar const *const *xpm, gint hot_x, gint hot_y);
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index a60e3cc31..37b3f8a1a 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -1253,30 +1253,27 @@ RotateableSwatch::do_motion(double by, guint modifier) {
if (!cr_set && modifier != 3) {
GtkWidget *w = GTK_WIDGET(gobj());
+ GdkPixbuf *pixbuf = NULL;
- GdkBitmap *bitmap = NULL;
- GdkBitmap *mask = NULL;
if (modifier == 2) { // saturation
- sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, cursor_adj_s_xpm);
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)cursor_adj_s_xpm);
} else if (modifier == 1) { // lightness
- sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, cursor_adj_l_xpm);
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)cursor_adj_l_xpm);
} else { // hue
- sp_cursor_bitmap_and_mask_from_xpm(&bitmap, &mask, cursor_adj_h_xpm);
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const gchar **)cursor_adj_h_xpm);
}
- if ((bitmap != NULL) && (mask != NULL)) {
- GtkStyle *style = gtk_widget_get_style(w);
- cr = gdk_cursor_new_from_pixmap(bitmap, mask,
- &style->black,
- &style->white,
- 16, 16);
- g_object_unref (bitmap);
- g_object_unref (mask);
+
+ if (pixbuf != NULL) {
+ cr = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 16, 16);
+
+ g_object_unref(pixbuf);
gdk_window_set_cursor(gtk_widget_get_window(w), cr);
#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cr);
#else
gdk_cursor_unref(cr);
#endif
+ cr = NULL;
cr_set = true;
}
}