A way to determine tool type in gimp context

Hi,

Is there a better way than string comparison to determine tool type in gimpcontext.c?
The usual way of using a g_type enumerator is not available.

void
gimp_context_erase_toggle (GimpContext *context)
{
  GimpLayerMode  paint_mode;
  GimpToolInfo  *tool_info;
  GType          tool_type;
  gboolean       eraser_tool = FALSE;

  g_return_if_fail (GIMP_IS_CONTEXT (context));

  paint_mode = gimp_context_get_paint_mode (context);
  tool_info  = context->tool_info;
  tool_type  = tool_info->tool_type;

  if (! strcmp (tool_info->label, "Eraser"))
    {
      eraser_tool = TRUE;
    }

  if (! eraser_tool)
    {
      gimp_context_set_tool (context, gimp_get_tool_info (context->gimp, "gimp-eraser-tool"));
    }
  else
    {
      gimp_context_set_tool (context, context->prev_tool_info);
    }
}

You can check with GIMP_IS_ERASER_TOOL (). If it doesn’t work, then you’ll need to import tools/gimperasertool.h so it can recognize the GimpEraserTool type.

Hi,

That is the issue I’m having, it’s one of those cases where including other headers creates a chain reaction of further issues.
I try to resolve these up to a point, in this case I felt the code was resisting any attempt to include these types of headers for a reason unknown.

In file included from ../app/tools/gimpdrawtool.h:22,
                 from ../app/tools/gimpcolortool.h:22,
                 from ../app/tools/gimppainttool.h:22,
                 from ../app/tools/gimpbrushtool.h:22,
                 from ../app/tools/gimperasertool.h:22,
                 from ../app/core/gimpcontext.c:62:
../app/tools/gimptool.h:50:3: error: unknown type name ‘GimpToolControl’
   50 |   GimpToolControl *control;
      |   ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:59:3: error: unknown type name ‘GdkModifierType’
   59 |   GdkModifierType  modifier_state;
      |   ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:60:3: error: unknown type name ‘GdkModifierType’
   60 |   GdkModifierType  button_press_state;
      |   ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:61:3: error: unknown type name ‘GdkModifierType’
   61 |   GdkModifierType  active_modifier_state;
      |   ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:67:3: error: unknown type name ‘GdkModifierType’
   67 |   GdkModifierType  last_pointer_state;
      |   ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:81:3: error: unknown type name ‘GimpCanvasItem’
   81 |   GimpCanvasItem  *progress;
      |   ^~~~~~~~~~~~~~
../app/tools/gimptool.h:83:3: error: unknown type name ‘GtkWidget’
   83 |   GtkWidget       *progress_grab_widget;
      |   ^~~~~~~~~
../app/tools/gimptool.h:93:44: error: unknown type name ‘GimpTool’
   93 |   gboolean        (* has_display)         (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:95:44: error: unknown type name ‘GimpTool’
   95 |   GimpDisplay   * (* has_image)           (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:98:44: error: unknown type name ‘GimpTool’
   98 |   gboolean        (* initialize)          (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:101:44: error: unknown type name ‘GimpTool’
  101 |   void            (* control)             (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:102:44: error: unknown type name ‘GimpToolAction’; did you mean ‘GimpToolOptions’?
  102 |                                            GimpToolAction         action,
      |                                            ^~~~~~~~~~~~~~
      |                                            GimpToolOptions
../app/tools/gimptool.h:105:44: error: unknown type name ‘GimpTool’
  105 |   void            (* button_press)        (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:108:44: error: unknown type name ‘GdkModifierType’
  108 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:109:44: error: unknown type name ‘GimpButtonPressType’
  109 |                                            GimpButtonPressType    press_type,
      |                                            ^~~~~~~~~~~~~~~~~~~
../app/tools/gimptool.h:111:44: error: unknown type name ‘GimpTool’
  111 |   void            (* button_release)      (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:114:44: error: unknown type name ‘GdkModifierType’
  114 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:115:44: error: unknown type name ‘GimpButtonReleaseType’
  115 |                                            GimpButtonReleaseType  release_type,
      |                                            ^~~~~~~~~~~~~~~~~~~~~
../app/tools/gimptool.h:117:44: error: unknown type name ‘GimpTool’
  117 |   void            (* motion)              (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:120:44: error: unknown type name ‘GdkModifierType’
  120 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:123:44: error: unknown type name ‘GimpTool’
  123 |   gboolean        (* key_press)           (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:124:44: error: unknown type name ‘GdkEventKey’
  124 |                                            GdkEventKey           *kevent,
      |                                            ^~~~~~~~~~~
../app/tools/gimptool.h:126:44: error: unknown type name ‘GimpTool’
  126 |   gboolean        (* key_release)         (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:127:44: error: unknown type name ‘GdkEventKey’
  127 |                                            GdkEventKey           *kevent,
      |                                            ^~~~~~~~~~~
../app/tools/gimptool.h:129:44: error: unknown type name ‘GimpTool’
  129 |   void            (* modifier_key)        (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:130:44: error: unknown type name ‘GdkModifierType’
  130 |                                            GdkModifierType        key,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:132:44: error: unknown type name ‘GdkModifierType’
  132 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:134:44: error: unknown type name ‘GimpTool’
  134 |   void            (* active_modifier_key) (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:135:44: error: unknown type name ‘GdkModifierType’
  135 |                                            GdkModifierType        key,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:137:44: error: unknown type name ‘GdkModifierType’
  137 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:140:44: error: unknown type name ‘GimpTool’
  140 |   void            (* oper_update)         (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:142:44: error: unknown type name ‘GdkModifierType’
  142 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:145:44: error: unknown type name ‘GimpTool’
  145 |   void            (* cursor_update)       (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:147:44: error: unknown type name ‘GdkModifierType’
  147 |                                            GdkModifierType        state,
      |                                            ^~~~~~~~~~~~~~~
../app/tools/gimptool.h:150:44: error: unknown type name ‘GimpTool’
  150 |   const gchar   * (* can_undo)            (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:152:44: error: unknown type name ‘GimpTool’
  152 |   const gchar   * (* can_redo)            (GimpTool              *tool,
      |                                            ^~~~~~~~
../app/tools/gimptool.h:154:44: error: unknown type name ‘GimpTool’
  154 |   gboolean        (* undo)                (GimpTool              *tool,

...

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.