예제 #1
0
void
vectors_edit_cmd_callback (GtkAction *action,
                           gpointer   data)
{
  GimpImage   *image;
  GimpVectors *vectors;
  GimpTool    *active_tool;
  return_if_no_vectors (image, vectors, data);

  active_tool = tool_manager_get_active (image->gimp);

  if (! GIMP_IS_VECTOR_TOOL (active_tool))
    {
      GimpToolInfo  *tool_info = gimp_get_tool_info (image->gimp,
                                                     "gimp-vector-tool");

      if (GIMP_IS_TOOL_INFO (tool_info))
        {
          gimp_context_set_tool (action_data_get_context (data), tool_info);
          active_tool = tool_manager_get_active (image->gimp);
        }
    }

  if (GIMP_IS_VECTOR_TOOL (active_tool))
    gimp_vector_tool_set_vectors (GIMP_VECTOR_TOOL (active_tool), vectors);
}
예제 #2
0
void
layers_text_tool_cmd_callback (GtkAction *action,
                               gpointer   data)
{
  GimpImage *image;
  GimpLayer *layer;
  GtkWidget *widget;
  GimpTool  *active_tool;
  return_if_no_layer (image, layer, data);
  return_if_no_widget (widget, data);

  if (! gimp_item_is_text_layer (GIMP_ITEM (layer)))
    {
      layers_edit_attributes_cmd_callback (action, data);
      return;
    }

  active_tool = tool_manager_get_active (image->gimp);

  if (! GIMP_IS_TEXT_TOOL (active_tool))
    {
      GimpToolInfo *tool_info = gimp_get_tool_info (image->gimp,
                                                    "gimp-text-tool");

      if (GIMP_IS_TOOL_INFO (tool_info))
        {
          gimp_context_set_tool (action_data_get_context (data), tool_info);
          active_tool = tool_manager_get_active (image->gimp);
        }
    }

  if (GIMP_IS_TEXT_TOOL (active_tool))
    gimp_text_tool_set_layer (GIMP_TEXT_TOOL (active_tool), layer);
}
예제 #3
0
void
gimp_image_map_tool_edit_as (GimpImageMapTool *im_tool,
                             const gchar      *new_tool_id,
                             GimpConfig       *config)
{
  GimpDisplay  *display;
  GimpContext  *user_context;
  GimpToolInfo *tool_info;
  GimpTool     *new_tool;

  g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (im_tool));
  g_return_if_fail (new_tool_id);
  g_return_if_fail (GIMP_IS_CONFIG (config));

  display = GIMP_TOOL (im_tool)->display;

  user_context = gimp_get_user_context (display->gimp);

  tool_info = (GimpToolInfo *)
    gimp_container_get_child_by_name (display->gimp->tool_info_list,
                                      new_tool_id);

  gimp_context_set_tool (user_context, tool_info);
  tool_manager_initialize_active (display->gimp, display);

  new_tool = tool_manager_get_active (display->gimp);

  GIMP_IMAGE_MAP_TOOL (new_tool)->default_config = g_object_ref (config);

  gimp_image_map_tool_reset (GIMP_IMAGE_MAP_TOOL (new_tool));
}
예제 #4
0
void
gimp_display_delete (GimpDisplay *display)
{
  GimpTool *active_tool;

  g_return_if_fail (GIMP_IS_DISPLAY (display));

  /* remove the display from the list */
  gimp_container_remove (display->image->gimp->displays,
                         GIMP_OBJECT (display));

  /*  stop any active tool  */
  tool_manager_control_active (display->image->gimp, GIMP_TOOL_ACTION_HALT,
                               display);

  active_tool = tool_manager_get_active (display->image->gimp);

  if (active_tool && active_tool->focus_display == display)
    tool_manager_focus_display_active (display->image->gimp, NULL);

  /*  free the update area lists  */
  gimp_area_list_free (display->update_areas);
  display->update_areas = NULL;

  if (display->shell)
    {
      GtkWidget *shell = display->shell;

      /*  set display->shell to NULL *before* destroying the shell.
       *  all callbacks in gimpdisplayshell-callbacks.c will check
       *  this pointer and do nothing if the shell is in destruction.
       */
      display->shell = NULL;
      gtk_widget_destroy (shell);
    }

  /*  unrefs the image  */
  gimp_display_disconnect (display);

  g_object_unref (display);
}
예제 #5
0
void
tools_object_2_cmd_callback (GtkAction *action,
                             gint       value,
                             gpointer   data)
{
  GimpContext *context;
  GimpTool    *tool;
  return_if_no_context (context, data);

  tool = tool_manager_get_active (context->gimp);

  if (tool)
    {
      const gchar *action_desc;

      action_desc = gimp_tool_control_get_action_object_2 (tool->control);

      if (action_desc)
        tools_activate_enum_action (action_desc, value);
    }
}
예제 #6
0
static void
gimp_guide_tool_button_release (GimpTool              *tool,
                                const GimpCoords      *coords,
                                guint32                time,
                                GdkModifierType        state,
                                GimpButtonReleaseType  release_type,
                                GimpDisplay           *display)
{
  GimpGuideTool    *guide_tool = GIMP_GUIDE_TOOL (tool);
  GimpDisplayShell *shell      = gimp_display_get_shell (display);
  GimpImage        *image      = gimp_display_get_image (display);

  gimp_tool_pop_status (tool, display);

  gimp_tool_control_halt (tool->control);

  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));

  if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
    {
      /* custom guides are moved live */
      if (guide_tool->guide_custom)
        gimp_image_move_guide (image, guide_tool->guide,
                               guide_tool->guide_old_position, TRUE);
    }
  else
    {
      gint max_position;

      if (guide_tool->guide_orientation == GIMP_ORIENTATION_HORIZONTAL)
        max_position = gimp_image_get_height (image);
      else
        max_position = gimp_image_get_width (image);

      if (guide_tool->guide_position == GIMP_GUIDE_POSITION_UNDEFINED ||
          guide_tool->guide_position <  0                             ||
          guide_tool->guide_position > max_position)
        {
          if (guide_tool->guide)
            {
              gimp_image_remove_guide (image, guide_tool->guide, TRUE);
              guide_tool->guide = NULL;
            }
        }
      else
        {
          if (guide_tool->guide)
            {
              /* custom guides are moved live */
              if (! guide_tool->guide_custom)
                gimp_image_move_guide (image, guide_tool->guide,
                                       guide_tool->guide_position, TRUE);
            }
          else
            {
              switch (guide_tool->guide_orientation)
                {
                case GIMP_ORIENTATION_HORIZONTAL:
                  guide_tool->guide =
                    gimp_image_add_hguide (image,
                                           guide_tool->guide_position,
                                           TRUE);
                  break;

                case GIMP_ORIENTATION_VERTICAL:
                  guide_tool->guide =
                    gimp_image_add_vguide (image,
                                           guide_tool->guide_position,
                                           TRUE);
                  break;

                default:
                  gimp_assert_not_reached ();
                }
            }
        }

      gimp_image_flush (image);
    }

  gimp_display_shell_selection_resume (shell);

  guide_tool->guide_position    = GIMP_GUIDE_POSITION_UNDEFINED;
  guide_tool->guide_orientation = GIMP_ORIENTATION_UNKNOWN;

  tool_manager_pop_tool (display->gimp);
  g_object_unref (guide_tool);

  {
    GimpTool *active_tool = tool_manager_get_active (display->gimp);

    if (GIMP_IS_DRAW_TOOL (active_tool))
      gimp_draw_tool_pause (GIMP_DRAW_TOOL (active_tool));

    tool_manager_oper_update_active (display->gimp, coords, state,
                                     TRUE, display);
    tool_manager_cursor_update_active (display->gimp, coords, state,
                                       display);

    if (GIMP_IS_DRAW_TOOL (active_tool))
      gimp_draw_tool_resume (GIMP_DRAW_TOOL (active_tool));
  }
}
static gboolean
gimp_display_shell_autoscroll_timeout (gpointer data)
{
  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (data);
  ScrollInfo       *info  = shell->scroll_info;
  GimpCoords        device_coords;
  GimpCoords        image_coords;
  gint              dx = 0;
  gint              dy = 0;

  gimp_device_info_get_device_coords (info->device,
                                      gtk_widget_get_window (shell->canvas),
                                      &device_coords);

  if (device_coords.x < 0)
    dx = device_coords.x;
  else if (device_coords.x > shell->disp_width)
    dx = device_coords.x - shell->disp_width;

  if (device_coords.y < 0)
    dy = device_coords.y;
  else if (device_coords.y > shell->disp_height)
    dy = device_coords.y - shell->disp_height;

  if (dx || dy)
    {
      GimpDisplay *display         = shell->display;
      GimpTool    *active_tool     = tool_manager_get_active (display->gimp);
      gint         scroll_amount_x = AUTOSCROLL_DX * dx;
      gint         scroll_amount_y = AUTOSCROLL_DX * dy;

      info->time += AUTOSCROLL_DT;

      gimp_display_shell_scroll_unoverscrollify (shell,
                                                 scroll_amount_x,
                                                 scroll_amount_y,
                                                 &scroll_amount_x,
                                                 &scroll_amount_y);

      gimp_display_shell_scroll (shell,
                                 scroll_amount_x,
                                 scroll_amount_y);

      gimp_display_shell_untransform_coords (shell,
                                             &device_coords,
                                             &image_coords);

      if (gimp_tool_control_get_snap_to (active_tool->control))
        {
          gint x, y, width, height;

          gimp_tool_control_get_snap_offsets (active_tool->control,
                                              &x, &y, &width, &height);

          gimp_display_shell_snap_coords (shell,
                                          &image_coords,
                                          x, y, width, height);
        }

      tool_manager_motion_active (display->gimp,
                                  &image_coords,
                                  info->time, info->state,
                                  display);

      return TRUE;
    }
  else
    {
      g_slice_free (ScrollInfo, info);
      shell->scroll_info = NULL;

      return FALSE;
    }
}
예제 #8
0
static void
gimp_sample_point_tool_button_release (GimpTool              *tool,
                                       const GimpCoords      *coords,
                                       guint32                time,
                                       GdkModifierType        state,
                                       GimpButtonReleaseType  release_type,
                                       GimpDisplay           *display)
{
  GimpSamplePointTool *sp_tool = GIMP_SAMPLE_POINT_TOOL (tool);
  GimpDisplayShell    *shell   = gimp_display_get_shell (display);
  GimpImage           *image   = gimp_display_get_image (display);

  gimp_tool_pop_status (tool, display);

  gimp_tool_control_halt (tool->control);

  gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));

  if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
    {
      gint width  = gimp_image_get_width  (image);
      gint height = gimp_image_get_height (image);

      if (sp_tool->sample_point_x == GIMP_SAMPLE_POINT_POSITION_UNDEFINED ||
          sp_tool->sample_point_x <  0                                    ||
          sp_tool->sample_point_x >= width                                ||
          sp_tool->sample_point_y == GIMP_SAMPLE_POINT_POSITION_UNDEFINED ||
          sp_tool->sample_point_y <  0                                    ||
          sp_tool->sample_point_y >= height)
        {
          if (sp_tool->sample_point)
            {
              gimp_image_remove_sample_point (image,
                                              sp_tool->sample_point, TRUE);
              sp_tool->sample_point = NULL;
            }
        }
      else
        {
          if (sp_tool->sample_point)
            {
              gimp_image_move_sample_point (image,
                                            sp_tool->sample_point,
                                            sp_tool->sample_point_x,
                                            sp_tool->sample_point_y,
                                            TRUE);
            }
          else
            {
              sp_tool->sample_point =
                gimp_image_add_sample_point_at_pos (image,
                                                    sp_tool->sample_point_x,
                                                    sp_tool->sample_point_y,
                                                    TRUE);
            }
        }

      gimp_image_flush (image);
    }

  gimp_display_shell_selection_resume (shell);

  sp_tool->sample_point_x = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;
  sp_tool->sample_point_y = GIMP_SAMPLE_POINT_POSITION_UNDEFINED;

  tool_manager_pop_tool (display->gimp);
  g_object_unref (sp_tool);

  {
    GimpTool *active_tool = tool_manager_get_active (display->gimp);

    if (GIMP_IS_DRAW_TOOL (active_tool))
      gimp_draw_tool_pause (GIMP_DRAW_TOOL (active_tool));

    tool_manager_oper_update_active (display->gimp, coords, state,
                                     TRUE, display);
    tool_manager_cursor_update_active (display->gimp, coords, state,
                                       display);

    if (GIMP_IS_DRAW_TOOL (active_tool))
      gimp_draw_tool_resume (GIMP_DRAW_TOOL (active_tool));
  }
}