[gimp] app: simplify gimp_tool_set_[active]_modifier_state()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: simplify gimp_tool_set_[active]_modifier_state()
- Date: Sat, 25 May 2013 00:14:45 +0000 (UTC)
commit df2257072733d6a9d72a8e2b8d461a5ad070d218
Author: Michael Natterer <mitch gimp org>
Date: Sat May 25 02:09:33 2013 +0200
app: simplify gimp_tool_set_[active]_modifier_state()
by factoring out bits of code that were repeated 8 times, also
make sure we actually pass TRUE or FALSE as gboolean, and not some
(state & MODIFIER).
app/tools/gimptool.c | 90 ++++++++++++++++++++++++++++---------------------
1 files changed, 51 insertions(+), 39 deletions(-)
---
diff --git a/app/tools/gimptool.c b/app/tools/gimptool.c
index dd83489..64d5bdd 100644
--- a/app/tools/gimptool.c
+++ b/app/tools/gimptool.c
@@ -828,11 +828,44 @@ gimp_tool_modifier_key (GimpTool *tool,
GIMP_TOOL_GET_CLASS (tool)->modifier_key (tool, key, press, state, display);
}
+static void
+gimp_tool_active_modifier_key (GimpTool *tool,
+ GdkModifierType key,
+ gboolean press,
+ GdkModifierType state,
+ GimpDisplay *display)
+{
+ g_return_if_fail (GIMP_IS_TOOL (tool));
+ g_return_if_fail (GIMP_IS_DISPLAY (display));
+ g_return_if_fail (display == tool->focus_display);
+
+ GIMP_TOOL_GET_CLASS (tool)->active_modifier_key (tool, key, press, state,
+ display);
+}
+
+static gboolean
+state_changed (GdkModifierType old_state,
+ GdkModifierType new_state,
+ GdkModifierType modifier,
+ gboolean *press)
+{
+ if ((old_state & modifier) != (new_state & modifier))
+ {
+ *press = (new_state & modifier) ? TRUE : FALSE;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
void
gimp_tool_set_modifier_state (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
+ gboolean press;
+
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (gimp_tool_control_is_active (tool->control) == FALSE);
@@ -842,57 +875,44 @@ gimp_tool_set_modifier_state (GimpTool *tool,
g_return_if_fail (display == tool->focus_display);
- if ((tool->modifier_state & GDK_SHIFT_MASK) != (state & GDK_SHIFT_MASK))
+ if (state_changed (tool->modifier_state, state, GDK_SHIFT_MASK, &press))
{
gimp_tool_modifier_key (tool, GDK_SHIFT_MASK,
- (state & GDK_SHIFT_MASK) ? TRUE : FALSE, state,
+ press, state,
display);
}
- if ((tool->modifier_state & GDK_CONTROL_MASK) != (state & GDK_CONTROL_MASK))
+ if (state_changed (tool->modifier_state, state, GDK_CONTROL_MASK, &press))
{
gimp_tool_modifier_key (tool, GDK_CONTROL_MASK,
- (state & GDK_CONTROL_MASK) ? TRUE : FALSE, state,
+ press, state,
display);
}
- if ((tool->modifier_state & GDK_MOD1_MASK) != (state & GDK_MOD1_MASK))
+ if (state_changed (tool->modifier_state, state, GDK_MOD1_MASK, &press))
{
gimp_tool_modifier_key (tool, GDK_MOD1_MASK,
- (state & GDK_MOD1_MASK) ? TRUE : FALSE, state,
+ press, state,
display);
}
- if ((tool->modifier_state & GDK_MOD2_MASK) != (state & GDK_MOD2_MASK))
+ if (state_changed (tool->modifier_state, state, GDK_MOD2_MASK, &press))
{
gimp_tool_modifier_key (tool, GDK_MOD2_MASK,
- (state & GDK_MOD2_MASK) ? TRUE : FALSE, state,
+ press, state,
display);
}
tool->modifier_state = state;
}
-static void
-gimp_tool_active_modifier_key (GimpTool *tool,
- GdkModifierType key,
- gboolean press,
- GdkModifierType state,
- GimpDisplay *display)
-{
- g_return_if_fail (GIMP_IS_TOOL (tool));
- g_return_if_fail (GIMP_IS_DISPLAY (display));
- g_return_if_fail (display == tool->focus_display);
-
- GIMP_TOOL_GET_CLASS (tool)->active_modifier_key (tool, key, press, state,
- display);
-}
-
void
gimp_tool_set_active_modifier_state (GimpTool *tool,
GdkModifierType state,
GimpDisplay *display)
{
+ gboolean press;
+
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (gimp_tool_control_is_active (tool->control) == TRUE);
@@ -902,11 +922,9 @@ gimp_tool_set_active_modifier_state (GimpTool *tool,
g_return_if_fail (display == tool->focus_display);
- if ((tool->active_modifier_state & GDK_SHIFT_MASK) !=
- (state & GDK_SHIFT_MASK))
+ if (state_changed (tool->active_modifier_state, state, GDK_SHIFT_MASK,
+ &press))
{
- gboolean press = state & GDK_SHIFT_MASK;
-
#ifdef DEBUG_ACTIVE_STATE
g_printerr ("%s: SHIFT %s\n", G_STRFUNC,
press ? "pressed" : "released");
@@ -924,11 +942,9 @@ gimp_tool_set_active_modifier_state (GimpTool *tool,
}
}
- if ((tool->active_modifier_state & GDK_CONTROL_MASK) !=
- (state & GDK_CONTROL_MASK))
+ if (state_changed (tool->active_modifier_state, state, GDK_CONTROL_MASK,
+ &press))
{
- gboolean press = state & GDK_CONTROL_MASK;
-
#ifdef DEBUG_ACTIVE_STATE
g_printerr ("%s: CONTROL %s\n", G_STRFUNC,
press ? "pressed" : "released");
@@ -946,11 +962,9 @@ gimp_tool_set_active_modifier_state (GimpTool *tool,
}
}
- if ((tool->active_modifier_state & GDK_MOD1_MASK) !=
- (state & GDK_MOD1_MASK))
+ if (state_changed (tool->active_modifier_state, state, GDK_MOD1_MASK,
+ &press))
{
- gboolean press = state & GDK_MOD1_MASK;
-
#ifdef DEBUG_ACTIVE_STATE
g_printerr ("%s: ALT %s\n", G_STRFUNC,
press ? "pressed" : "released");
@@ -968,11 +982,9 @@ gimp_tool_set_active_modifier_state (GimpTool *tool,
}
}
- if ((tool->active_modifier_state & GDK_MOD2_MASK) !=
- (state & GDK_MOD2_MASK))
+ if (state_changed (tool->active_modifier_state, state, GDK_MOD2_MASK,
+ &press))
{
- gboolean press = state & GDK_MOD2_MASK;
-
#ifdef DEBUG_ACTIVE_STATE
g_printerr ("%s: MOD2 %s\n", G_STRFUNC,
press ? "pressed" : "released");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]