cursors,app,libgimpwidgets: include cursors using GResource

instead of deprecated inline pixbufs. Require on gdk-pixbuf >= 2.30.8.
This commit is contained in:
Michael Natterer
2015-04-14 22:55:10 +02:00
parent 60197c227d
commit 7c36f94f7f
7 changed files with 159 additions and 117 deletions

View File

@ -325,8 +325,8 @@ static gchar *
sanity_check_gdk_pixbuf (void) sanity_check_gdk_pixbuf (void)
{ {
#define GDK_PIXBUF_REQUIRED_MAJOR 2 #define GDK_PIXBUF_REQUIRED_MAJOR 2
#define GDK_PIXBUF_REQUIRED_MINOR 24 #define GDK_PIXBUF_REQUIRED_MINOR 30
#define GDK_PIXBUF_REQUIRED_MICRO 1 #define GDK_PIXBUF_REQUIRED_MICRO 8
if (! sanity_check_version (gdk_pixbuf_major_version, GDK_PIXBUF_REQUIRED_MAJOR, if (! sanity_check_version (gdk_pixbuf_major_version, GDK_PIXBUF_REQUIRED_MAJOR,
gdk_pixbuf_minor_version, GDK_PIXBUF_REQUIRED_MINOR, gdk_pixbuf_minor_version, GDK_PIXBUF_REQUIRED_MINOR,

View File

@ -23,7 +23,7 @@
#include "gimpcursor.h" #include "gimpcursor.h"
#include "cursors/gimp-tool-cursors.h" #include "cursors/gimp-tool-cursors.c"
#define cursor_default_x_hot 10 #define cursor_default_x_hot 10
@ -43,10 +43,10 @@ typedef struct _GimpCursor GimpCursor;
struct _GimpCursor struct _GimpCursor
{ {
const guint8 *pixbuf_data; const gchar *resource_name;
const gint x_hot, y_hot; const gint x_hot, y_hot;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
}; };
@ -55,99 +55,99 @@ static GimpCursor gimp_cursors[] =
/* these have to match up with enum GimpCursorType in widgets-enums.h */ /* these have to match up with enum GimpCursorType in widgets-enums.h */
{ {
cursor_none, "cursor-none.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_mouse, "cursor-mouse.png",
cursor_mouse_x_hot, cursor_mouse_y_hot cursor_mouse_x_hot, cursor_mouse_y_hot
}, },
{ {
cursor_crosshair, "cursor-crosshair.png",
cursor_crosshair_x_hot, cursor_crosshair_y_hot cursor_crosshair_x_hot, cursor_crosshair_y_hot
}, },
{ {
cursor_crosshair_small, "cursor-crosshair-small.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_bad, "cursor-bad.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_move, "cursor-move.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_zoom, "cursor-zoom.png",
cursor_zoom_x_hot, cursor_zoom_y_hot cursor_zoom_x_hot, cursor_zoom_y_hot
}, },
{ {
cursor_color_picker, "cursor-color-picker.png",
cursor_color_picker_x_hot, cursor_color_picker_y_hot cursor_color_picker_x_hot, cursor_color_picker_y_hot
}, },
{ {
cursor_corner_top, "cursor-corner-top.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_top_right, "cursor-corner-top-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_right, "cursor-corner-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_bottom_right, "cursor-corner-bottom-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_bottom, "cursor-corner-bottom.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_bottom_left, "cursor-corner-bottom-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_left, "cursor-corner-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_corner_top_left, "cursor-corner-top-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_top, "cursor-sid-_top.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_top_right, "cursor-side-top-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_right, "cursor-side-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_bottom_right, "cursor-side-bottom-right.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_bottom, "cursor-side-bottom.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_bottom_left, "cursor-side-bottom-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_left, "cursor-side-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
}, },
{ {
cursor_side_top_left, "cursor-side-top-left.png",
cursor_default_x_hot, cursor_default_y_hot cursor_default_x_hot, cursor_default_y_hot
} }
}; };
@ -157,42 +157,42 @@ static GimpCursor gimp_tool_cursors[] =
/* these have to match up with enum GimpToolCursorType in widgets-enums.h */ /* these have to match up with enum GimpToolCursorType in widgets-enums.h */
{ NULL }, { NULL },
{ tool_rect_select }, { "tool-rect-select.png" },
{ tool_ellipse_select }, { "tool-ellipse-select.png" },
{ tool_free_select }, { "tool-free-select.png" },
{ tool_polygon_select }, { "tool-polygon-select.png" },
{ tool_fuzzy_select }, { "tool-fuzzy-select.png" },
{ tool_paths }, { "tool-paths.png" },
{ tool_paths_anchor }, { "tool-paths-anchor.png" },
{ tool_paths_control }, { "tool-paths-control.png" },
{ tool_paths_segment }, { "tool-paths-segment.png" },
{ tool_iscissors }, { "tool-iscissors.png" },
{ tool_move }, { "tool-move.png" },
{ tool_zoom }, { "tool-zoom.png" },
{ tool_crop }, { "tool-crop.png" },
{ tool_resize }, { "tool-resize.png" },
{ tool_rotate }, { "tool-rotate.png" },
{ tool_shear }, { "tool-shear.png" },
{ tool_perspective }, { "tool-perspective.png" },
{ tool_flip_horizontal }, { "tool-flip-horizontal.png" },
{ tool_flip_vertical }, { "tool-flip-vertical.png" },
{ tool_text }, { "tool-text.png" },
{ tool_color_picker }, { "tool-color-picker.png" },
{ tool_bucket_fill }, { "tool-bucket-fill.png" },
{ tool_blend }, { "tool-blend.png" },
{ tool_pencil }, { "tool-pencil.png" },
{ tool_paintbrush }, { "tool-paintbrush.png" },
{ tool_airbrush }, { "tool-airbrush.png" },
{ tool_ink }, { "tool-ink.png" },
{ tool_clone }, { "tool-clone.png" },
{ tool_heal }, { "tool-heal.png" },
{ tool_eraser }, { "tool-eraser.png" },
{ tool_smudge }, { "tool-smudge.png" },
{ tool_blur }, { "tool-blur.png" },
{ tool_dodge }, { "tool-dodge.png" },
{ tool_burn }, { "tool-burn.png" },
{ tool_measure }, { "tool-measure.png" },
{ tool_hand } { "tool-hand.png" }
}; };
static GimpCursor gimp_cursor_modifiers[] = static GimpCursor gimp_cursor_modifiers[] =
@ -200,19 +200,19 @@ static GimpCursor gimp_cursor_modifiers[] =
/* these have to match up with enum GimpCursorModifier in widgets-enums.h */ /* these have to match up with enum GimpCursorModifier in widgets-enums.h */
{ NULL }, { NULL },
{ modifier_bad }, { "modifier-bad.png" },
{ modifier_plus }, { "modifier-plus.png" },
{ modifier_minus }, { "modifier-minus.png" },
{ modifier_intersect }, { "modifier-intersect.png" },
{ modifier_move }, { "modifier-move.png" },
{ modifier_resize }, { "modifier-resize.png" },
{ modifier_control }, { "modifier-control.png" },
{ modifier_anchor }, { "modifier-anchor.png" },
{ modifier_foreground }, { "modifier-foreground.png" },
{ modifier_background }, { "modifier-background.png" },
{ modifier_pattern }, { "modifier-pattern.png" },
{ modifier_join }, { "modifier-join.png" },
{ modifier_select } { "modifier-select.png" }
}; };
@ -220,10 +220,23 @@ static const GdkPixbuf *
get_cursor_pixbuf (GimpCursor *cursor) get_cursor_pixbuf (GimpCursor *cursor)
{ {
if (! cursor->pixbuf) if (! cursor->pixbuf)
cursor->pixbuf = gdk_pixbuf_new_from_inline (-1, {
cursor->pixbuf_data, gchar *resource_path;
FALSE, NULL); GError *error = NULL;
g_return_val_if_fail (cursor->pixbuf != NULL, NULL);
resource_path = g_strconcat ("/org/gimp/tool-cursors/",
cursor->resource_name, NULL);
cursor->pixbuf = gdk_pixbuf_new_from_resource (resource_path, &error);
if (! cursor->pixbuf)
{
g_critical ("Failed to create cursor image: %s", error->message);
g_clear_error (&error);
}
g_free (resource_path);
}
return cursor->pixbuf; return cursor->pixbuf;
} }

View File

@ -48,7 +48,7 @@ m4_define([gegl_required_version], [0.3.0])
m4_define([glib_required_version], [2.40.0]) m4_define([glib_required_version], [2.40.0])
m4_define([atk_required_version], [2.2.0]) m4_define([atk_required_version], [2.2.0])
m4_define([gtk_required_version], [2.24.10]) m4_define([gtk_required_version], [2.24.10])
m4_define([gdk_pixbuf_required_version], [2.24.1]) m4_define([gdk_pixbuf_required_version], [2.30.8])
m4_define([cairo_required_version], [1.12.2]) m4_define([cairo_required_version], [1.12.2])
m4_define([cairo_pdf_required_version], [1.12.2]) m4_define([cairo_pdf_required_version], [1.12.2])
m4_define([pangocairo_required_version], [1.29.4]) m4_define([pangocairo_required_version], [1.29.4])
@ -589,6 +589,11 @@ else
PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0) PKG_CHECK_MODULES(GIO_UNIX, gio-unix-2.0)
fi fi
AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources, no)
if test "x$GLIB_COMPILE_RESOURCES" = xno; then
AC_MSG_ERROR(Could not find glib-compile-resources in your PATH)
fi
AC_PATH_PROG(GDBUS_CODEGEN, gdbus-codegen, no) AC_PATH_PROG(GDBUS_CODEGEN, gdbus-codegen, no)
if test "x$GDBUS_CODEGEN" = xno; then if test "x$GDBUS_CODEGEN" = xno; then
AC_MSG_ERROR([Could not find gdbus-codegen in your PATH]) AC_MSG_ERROR([Could not find gdbus-codegen in your PATH])

8
cursors/.gitignore vendored
View File

@ -2,7 +2,7 @@
/Makefile.in /Makefile.in
/.xvpics /.xvpics
/.thumbnails /.thumbnails
/color-picker-cursors.list /gimp-color-picker-cursors.c
/tool-cursors.list /gimp-color-picker-cursors.gresource.xml
/gimp-color-picker-cursors.h /gimp-tool-cursors.c
/gimp-tool-cursors.h /gimp-tool-cursors.gresource.xml

View File

@ -85,33 +85,45 @@ EXTRA_DIST = \
gimp-tool-cursors.xcf gimp-tool-cursors.xcf
noinst_DATA = \ noinst_DATA = \
gimp-tool-cursors.h \ gimp-tool-cursors.c \
gimp-color-picker-cursors.h gimp-color-picker-cursors.c
CLEANFILES = \ CLEANFILES = \
gimp-tool-cursors.h \ gimp-tool-cursors.c \
tool-cursors.list \ gimp-tool-cursors.gresource.xml \
gimp-color-picker-cursors.h \ gimp-color-picker-cursors.c \
color-picker-cursors.list gimp-color-picker-cursors.gresource.xml
tool-cursors.list: $(CURSOR_IMAGES) Makefile.am
gimp-tool-cursors.gresource.xml: $(CURSOR_IMAGES) Makefile.am
$(AM_V_GEN) ( rm -f $@; \ $(AM_V_GEN) ( rm -f $@; \
echo '<?xml version="1.0" encoding="UTF-8"?>' > $@; \
echo '<gresources>' >> $@; \
echo ' <gresource prefix="/org/gimp/tool-cursors">' >> $@; \
for image in $(CURSOR_IMAGES); do \ for image in $(CURSOR_IMAGES); do \
echo $$image | \ echo " <file preprocess=\"to-pixdata\">$$image</file>" >> $@; \
sed -e 's|.*/||' -e 's|-|_|g' -e 's|\.png$$||' >> $@; \ done; \
echo " $(srcdir)/$$image" >> $@; \ echo ' </gresource>' >> $@; \
done ) echo '</gresources>' >> $@ )
color-picker-cursors.list: $(COLOR_PICKER_IMAGES) Makefile.am gimp-tool-cursors.c: gimp-tool-cursors.gresource.xml
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) \
--sourcedir=$(srcdir) --generate-source \
--target=$@ gimp-tool-cursors.gresource.xml
gimp-color-picker-cursors.gresource.xml: $(CURSOR_IMAGES) Makefile.am
$(AM_V_GEN) ( rm -f $@; \ $(AM_V_GEN) ( rm -f $@; \
for image in $(COLOR_PICKER_IMAGES); do \ echo '<?xml version="1.0" encoding="UTF-8"?>' > $@; \
echo $$image | \ echo '<gresources>' >> $@; \
sed -e 's|.*/||' -e 's|-|_|g' -e 's|\.png$$||' >> $@; \ echo ' <gresource prefix="/org/gimp/color-picker-cursors">' >> $@; \
echo " $(srcdir)/$$image" >> $@; \ for image in $(CURSOR_IMAGES); do \
done ) echo " <file preprocess=\"to-pixdata\">$$image</file>" >> $@; \
done; \
echo ' </gresource>' >> $@; \
echo '</gresources>' >> $@ )
$(srcdir)/gimp-tool-cursors.h: tool-cursors.list gimp-color-picker-cursors.c: gimp-color-picker-cursors.gresource.xml
$(AM_V_GEN) $(GDK_PIXBUF_CSOURCE) --raw --build-list `cat tool-cursors.list` > $(@F) $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) \
--sourcedir=$(srcdir) --generate-source \
$(srcdir)/gimp-color-picker-cursors.h: color-picker-cursors.list --target=$@ gimp-color-picker-cursors.gresource.xml
$(AM_V_GEN) $(GDK_PIXBUF_CSOURCE) --raw --build-list `cat color-picker-cursors.list` > $(@F)

View File

@ -31,7 +31,7 @@
#include "gimppickbutton.h" #include "gimppickbutton.h"
#include "gimpstock.h" #include "gimpstock.h"
#include "cursors/gimp-color-picker-cursors.h" #include "cursors/gimp-color-picker-cursors.c"
#include "libgimp/libgimp-intl.h" #include "libgimp/libgimp-intl.h"
@ -175,16 +175,27 @@ gimp_pick_button_new (void)
static GdkCursor * static GdkCursor *
make_cursor (GdkDisplay *display) make_cursor (GdkDisplay *display)
{ {
GdkCursor *cursor; GdkPixbuf *pixbuf;
GdkPixbuf *pixbuf; GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_inline (-1, cursor_color_picker, FALSE, NULL); pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/color-picker-cursors/cursor-color-picker.png",
&error);
cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 1, 30); if (pixbuf)
{
GdkCursor *cursor = gdk_cursor_new_from_pixbuf (display, pixbuf, 1, 30);
g_object_unref (pixbuf); g_object_unref (pixbuf);
return cursor; return cursor;
}
else
{
g_critical ("Failed to create cursor image: %s", error->message);
g_clear_error (&error);
}
return NULL;
} }
static void static void

View File

@ -72,6 +72,7 @@ EXPORTS
gimp_color_hex_entry_set_color gimp_color_hex_entry_set_color
gimp_color_notebook_get_type gimp_color_notebook_get_type
gimp_color_notebook_set_has_page gimp_color_notebook_set_has_page
gimp_color_picker_cursors_get_resource
gimp_color_profile_chooser_dialog_get_type gimp_color_profile_chooser_dialog_get_type
gimp_color_profile_chooser_dialog_new gimp_color_profile_chooser_dialog_new
gimp_color_profile_combo_box_add gimp_color_profile_combo_box_add