Bug 641187 - GIMP needs a left-handed cursor option

Add a cursor-handedness setting and flip the cursor when it's set to
left-handed.
This commit is contained in:
Alexander Hämmerle 2011-07-24 22:09:21 +02:00 committed by Michael Natterer
parent 6b78436f56
commit 421ca4114e
12 changed files with 141 additions and 20 deletions

View File

@ -221,6 +221,35 @@ gimp_cursor_format_get_type (void)
return type;
}
GType
gimp_handedness_get_type (void)
{
static const GEnumValue values[] =
{
{ GIMP_HANDEDNESS_LEFT, "GIMP_HANDEDNESS_LEFT", "left" },
{ GIMP_HANDEDNESS_RIGHT, "GIMP_HANDEDNESS_RIGHT", "right" },
{ 0, NULL, NULL }
};
static const GimpEnumDesc descs[] =
{
{ GIMP_HANDEDNESS_LEFT, NC_("handedness", "Left-handed"), NULL },
{ GIMP_HANDEDNESS_RIGHT, NC_("handedness", "Right-handed"), NULL },
{ 0, NULL, NULL }
};
static GType type = 0;
if (G_UNLIKELY (! type))
{
type = g_enum_register_static ("GimpHandedness", values);
gimp_type_set_translation_context (type, "handedness");
gimp_enum_set_value_descriptions (type, descs);
}
return type;
}
/* Generated data ends here */

View File

@ -102,4 +102,15 @@ typedef enum
} GimpCursorFormat;
#define GIMP_TYPE_HANDEDNESS (gimp_handedness_get_type ())
GType gimp_handedness_get_type (void) G_GNUC_CONST;
typedef enum
{
GIMP_HANDEDNESS_LEFT, /*< desc="Left-handed" >*/
GIMP_HANDEDNESS_RIGHT /*< desc="Right-handed" >*/
} GimpHandedness;
#endif /* __CONFIG_ENUMS_H__ */

View File

@ -73,6 +73,7 @@ enum
PROP_USER_MANUAL_ONLINE_URI,
PROP_DOCK_WINDOW_HINT,
PROP_CURSOR_FORMAT,
PROP_CURSOR_HANDEDNESS,
/* ignored, only for backward compatibility: */
PROP_INFO_WINDOW_PER_DISPLAY,
@ -256,6 +257,11 @@ gimp_gui_config_class_init (GimpGuiConfigClass *klass)
GIMP_TYPE_CURSOR_FORMAT,
GIMP_CURSOR_FORMAT_PIXBUF,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_CURSOR_HANDEDNESS,
"cursor-handedness", CURSOR_HANDEDNESS_BLURB,
GIMP_TYPE_HANDEDNESS,
GIMP_HANDEDNESS_RIGHT,
GIMP_PARAM_STATIC_STRINGS);
/* only for backward compatibility: */
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_INFO_WINDOW_PER_DISPLAY,
@ -421,6 +427,9 @@ gimp_gui_config_set_property (GObject *object,
case PROP_CURSOR_FORMAT:
gui_config->cursor_format = g_value_get_enum (value);
break;
case PROP_CURSOR_HANDEDNESS:
gui_config->cursor_handedness = g_value_get_enum (value);
break;
case PROP_INFO_WINDOW_PER_DISPLAY:
case PROP_MENU_MNEMONICS:
@ -538,6 +547,9 @@ gimp_gui_config_get_property (GObject *object,
case PROP_CURSOR_FORMAT:
g_value_set_enum (value, gui_config->cursor_format);
break;
case PROP_CURSOR_HANDEDNESS:
g_value_set_enum (value, gui_config->cursor_handedness);
break;
case PROP_INFO_WINDOW_PER_DISPLAY:
case PROP_MENU_MNEMONICS:

View File

@ -68,6 +68,7 @@ struct _GimpGuiConfig
gchar *user_manual_online_uri;
GimpWindowHint dock_window_hint;
GimpCursorFormat cursor_format;
GimpHandedness cursor_handedness;
gint last_tip; /* saved in sessionrc */
};

View File

@ -51,6 +51,9 @@ N_("Sets the pixel format to use for mouse pointers.")
#define CURSOR_MODE_BLURB \
N_("Sets the type of mouse pointers to use.")
#define CURSOR_HANDEDNESS_BLURB \
N_("Sets the handedness for cursor positioning.")
#define CURSOR_UPDATING_BLURB \
N_("Context-dependent mouse pointers are helpful. They are enabled by " \
"default. However, they require overhead that you may want to do without.")

View File

@ -2112,7 +2112,7 @@ prefs_dialog_new (Gimp *gimp,
_("Show pointer for paint _tools"),
GTK_BOX (vbox2));
table = prefs_table_new (2, GTK_CONTAINER (vbox2));
table = prefs_table_new (3, GTK_CONTAINER (vbox2));
prefs_enum_combo_box_add (object, "cursor-mode", 0, 0,
_("Pointer _mode:"),
@ -2120,6 +2120,9 @@ prefs_dialog_new (Gimp *gimp,
prefs_enum_combo_box_add (object, "cursor-format", 0, 0,
_("Pointer re_ndering:"),
GTK_TABLE (table), 1, size_group);
prefs_enum_combo_box_add (object, "cursor-handedness", 0, 0,
_("Pointer _handedness:"),
GTK_TABLE (table), 2, NULL);
g_object_unref (size_group);
size_group = NULL;

View File

@ -93,6 +93,7 @@ gimp_display_shell_set_override_cursor (GimpDisplayShell *shell,
gimp_cursor_set (shell->canvas,
shell->cursor_format,
shell->cursor_handedness,
cursor_type,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_NONE);
@ -221,6 +222,7 @@ gimp_display_shell_real_set_cursor (GimpDisplayShell *shell,
gboolean always_install)
{
GimpCursorFormat cursor_format;
GimpHandedness cursor_handedness;
g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@ -266,20 +268,24 @@ gimp_display_shell_real_set_cursor (GimpDisplayShell *shell,
}
}
cursor_format = GIMP_GUI_CONFIG (shell->display->config)->cursor_format;
cursor_format = GIMP_GUI_CONFIG (shell->display->config)->cursor_format;
cursor_handedness = GIMP_GUI_CONFIG (shell->display->config)->cursor_handedness;
if (shell->cursor_format != cursor_format ||
shell->current_cursor != cursor_type ||
shell->tool_cursor != tool_cursor ||
shell->cursor_modifier != modifier ||
if (shell->cursor_format != cursor_format ||
shell->cursor_handedness != cursor_handedness ||
shell->current_cursor != cursor_type ||
shell->tool_cursor != tool_cursor ||
shell->cursor_modifier != modifier ||
always_install)
{
shell->cursor_format = cursor_format;
shell->current_cursor = cursor_type;
shell->tool_cursor = tool_cursor;
shell->cursor_modifier = modifier;
shell->cursor_format = cursor_format;
shell->cursor_handedness = cursor_handedness;
shell->current_cursor = cursor_type;
shell->tool_cursor = tool_cursor;
shell->cursor_modifier = modifier;
gimp_cursor_set (shell->canvas, cursor_format,
gimp_cursor_set (shell->canvas,
cursor_format, cursor_handedness,
cursor_type, tool_cursor, modifier);
}
}

View File

@ -299,11 +299,12 @@ gimp_display_shell_init (GimpDisplayShell *shell)
shell->icon_size = 32;
shell->cursor_format = GIMP_CURSOR_FORMAT_BITMAP;
shell->current_cursor = (GimpCursorType) -1;
shell->tool_cursor = GIMP_TOOL_CURSOR_NONE;
shell->cursor_modifier = GIMP_CURSOR_MODIFIER_NONE;
shell->override_cursor = (GimpCursorType) -1;
shell->cursor_format = GIMP_CURSOR_FORMAT_BITMAP;
shell->cursor_handedness = GIMP_HANDEDNESS_RIGHT;
shell->current_cursor = (GimpCursorType) -1;
shell->tool_cursor = GIMP_TOOL_CURSOR_NONE;
shell->cursor_modifier = GIMP_CURSOR_MODIFIER_NONE;
shell->override_cursor = (GimpCursorType) -1;
shell->motion_buffer = gimp_motion_buffer_new ();

View File

@ -138,11 +138,12 @@ struct _GimpDisplayShell
guint fill_idle_id; /* display_shell_fill() idle ID */
GimpCursorFormat cursor_format; /* Currently used cursor format */
GimpHandedness cursor_handedness;/* Handedness for cursor display */
GimpCursorType current_cursor; /* Currently installed main cursor */
GimpToolCursorType tool_cursor; /* Current Tool cursor */
GimpCursorModifier cursor_modifier; /* Cursor modifier (plus, minus, ...) */
GimpCursorType override_cursor; /* Overriding cursor */
GimpCursorType override_cursor; /* Overriding cursor */
gboolean using_override_cursor;
gboolean draw_cursor; /* should we draw software cursor ? */

View File

@ -247,6 +247,7 @@ get_cursor_pixbuf (GimpCursor *cursor,
GdkCursor *
gimp_cursor_new (GdkDisplay *display,
GimpCursorFormat cursor_format,
GimpHandedness cursor_handedness,
GimpCursorType cursor_type,
GimpToolCursorType tool_cursor,
GimpCursorModifier modifier)
@ -293,6 +294,38 @@ gimp_cursor_new (GdkDisplay *display,
modifier = GIMP_CURSOR_MODIFIER_NONE;
}
/* when cursor is "corner" or "side" sides must be exchanged for
* left-hand-mice-flipping of pixbuf below
*/
if (cursor_handedness == GIMP_HANDEDNESS_LEFT)
{
if (cursor_type == GIMP_CURSOR_CORNER_TOP_LEFT)
{
cursor_type = GIMP_CURSOR_CORNER_TOP_RIGHT;
}
else if (cursor_type == GIMP_CURSOR_CORNER_TOP_RIGHT)
{
cursor_type = GIMP_CURSOR_CORNER_TOP_LEFT;
}
else if (cursor_type == GIMP_CURSOR_CORNER_BOTTOM_LEFT)
{
cursor_type = GIMP_CURSOR_CORNER_BOTTOM_RIGHT;
}
else if (cursor_type == GIMP_CURSOR_CORNER_BOTTOM_RIGHT)
{
cursor_type = GIMP_CURSOR_CORNER_BOTTOM_LEFT;
}
else if (cursor_type == GIMP_CURSOR_SIDE_LEFT)
{
cursor_type = GIMP_CURSOR_SIDE_RIGHT;
}
else if (cursor_type == GIMP_CURSOR_SIDE_RIGHT)
{
cursor_type = GIMP_CURSOR_SIDE_LEFT;
}
}
/* prepare the main cursor */
cursor_type -= GIMP_CURSOR_NONE;
@ -345,9 +378,25 @@ gimp_cursor_new (GdkDisplay *display,
GDK_INTERP_NEAREST, bw ? 255 : 200);
}
cursor = gdk_cursor_new_from_pixbuf (display, pixbuf,
bmcursor->x_hot,
bmcursor->y_hot);
/* flip the cursor if mouse setting is left-handed */
if (cursor_handedness == GIMP_HANDEDNESS_LEFT)
{
GdkPixbuf *flipped = gdk_pixbuf_flip (pixbuf, TRUE);
gint width = gdk_pixbuf_get_width (flipped);
cursor = gdk_cursor_new_from_pixbuf (display, flipped,
(width - 1) - bmcursor->x_hot,
bmcursor->y_hot);
g_object_unref (flipped);
}
else
{
cursor = gdk_cursor_new_from_pixbuf (display, pixbuf,
bmcursor->x_hot,
bmcursor->y_hot);
}
g_object_unref (pixbuf);
return cursor;
@ -356,6 +405,7 @@ gimp_cursor_new (GdkDisplay *display,
void
gimp_cursor_set (GtkWidget *widget,
GimpCursorFormat cursor_format,
GimpHandedness cursor_handedness,
GimpCursorType cursor_type,
GimpToolCursorType tool_cursor,
GimpCursorModifier modifier)
@ -367,6 +417,7 @@ gimp_cursor_set (GtkWidget *widget,
cursor = gimp_cursor_new (gtk_widget_get_display (widget),
cursor_format,
cursor_handedness,
cursor_type,
tool_cursor,
modifier);

View File

@ -21,11 +21,13 @@
GdkCursor * gimp_cursor_new (GdkDisplay *display,
GimpCursorFormat cursor_format,
GimpHandedness cursor_handedness,
GimpCursorType cursor_type,
GimpToolCursorType tool_cursor,
GimpCursorModifier modifier);
void gimp_cursor_set (GtkWidget *widget,
GimpCursorFormat cursor_format,
GimpHandedness cursor_handedness,
GimpCursorType cursor_type,
GimpToolCursorType tool_cursor,
GimpCursorModifier modifier);

View File

@ -1503,6 +1503,7 @@ gimp_dialog_factory_set_busy (GimpDialogFactory *factory)
cursor = gimp_cursor_new (display,
GIMP_CURSOR_FORMAT_BITMAP,
GIMP_HANDEDNESS_RIGHT,
GDK_WATCH,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_NONE);