Esempio n. 1
0
static void
gimp_blend_tool_dispose (GObject *object)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (object);
  gimp_blend_tool_set_gradient (blend_tool, NULL);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}
Esempio n. 2
0
static void
gimp_blend_tool_draw (GimpDrawTool *draw_tool)
{
  GimpBlendTool   *blend_tool = GIMP_BLEND_TOOL (draw_tool);

  if (blend_tool->grabbed_point != POINT_FILL_MODE &&
      blend_tool->grabbed_point != POINT_INIT_MODE)
    {
      blend_tool->line =
        gimp_draw_tool_add_line (draw_tool,
                                 blend_tool->start_x,
                                 blend_tool->start_y,
                                 blend_tool->end_x,
                                 blend_tool->end_y);

      gimp_canvas_item_set_visible (blend_tool->line, SHOW_LINE);

      blend_tool->start_handle_circle =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CIRCLE,
                                   blend_tool->start_x,
                                   blend_tool->start_y,
                                   HANDLE_DIAMETER,
                                   HANDLE_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      blend_tool->start_handle_cross =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CROSS,
                                   blend_tool->start_x,
                                   blend_tool->start_y,
                                   HANDLE_CROSS_DIAMETER,
                                   HANDLE_CROSS_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      blend_tool->end_handle_circle =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CIRCLE,
                                   blend_tool->end_x,
                                   blend_tool->end_y,
                                   HANDLE_DIAMETER,
                                   HANDLE_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      blend_tool->end_handle_cross =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CROSS,
                                   blend_tool->end_x,
                                   blend_tool->end_y,
                                   HANDLE_CROSS_DIAMETER,
                                   HANDLE_CROSS_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      gimp_blend_tool_update_item_hilight (blend_tool);
    }
}
Esempio n. 3
0
static void
gimp_blend_tool_button_press (GimpTool            *tool,
                              const GimpCoords    *coords,
                              guint32              time,
                              GdkModifierType      state,
                              GimpButtonPressType  press_type,
                              GimpDisplay         *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  if (tool->display && display != tool->display)
    {
      gimp_tool_pop_status (tool, tool->display);
      gimp_blend_tool_halt (blend_tool);
    }

  blend_tool->grabbed_point = gimp_blend_tool_get_point_under_cursor (blend_tool);

  if (blend_tool->grabbed_point == POINT_NONE &&
      ! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
    {
      blend_tool->start_x = coords->x;
      blend_tool->start_y = coords->y;

      if (gimp_blend_tool_is_shapeburst (blend_tool))
        {
          blend_tool->grabbed_point = POINT_FILL_MODE;
        }
      else
        {
          blend_tool->grabbed_point = POINT_INIT_MODE;
        }
    }
  else if ((state & GDK_MOD1_MASK) &&
           gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
    {
      blend_tool->grabbed_point = POINT_BOTH;
    }

  gimp_blend_tool_point_motion (blend_tool,
                                state & gimp_get_constrain_behavior_mask ());

  tool->display = display;
  gimp_blend_tool_update_items (blend_tool);

  if (blend_tool->grabbed_point != POINT_FILL_MODE &&
      blend_tool->grabbed_point != POINT_INIT_MODE)
    {
      gimp_blend_tool_update_graph (blend_tool);
      gimp_drawable_filter_apply (blend_tool->filter, NULL);
    }

  gimp_tool_control_activate (tool->control);

  gimp_blend_tool_push_status (blend_tool, state, display);
}
Esempio n. 4
0
static void
gimp_blend_tool_motion (GimpTool         *tool,
                        const GimpCoords *coords,
                        guint32           time,
                        GdkModifierType   state,
                        GimpDisplay      *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  /* Save the mouse coordinates from last call */
  gdouble last_x = blend_tool->mouse_x;
  gdouble last_y = blend_tool->mouse_y;

  blend_tool->mouse_x = coords->x;
  blend_tool->mouse_y = coords->y;

  if (blend_tool->grabbed_point == POINT_INIT_MODE)
    {
      GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (blend_tool);

      gimp_draw_tool_pause (draw_tool);
      blend_tool->grabbed_point = POINT_END;
      gimp_draw_tool_resume (draw_tool);
    }

  /* Move the whole line if alt is pressed */
  if (state & GDK_MOD1_MASK)
    {
      gdouble dx = last_x - coords->x;
      gdouble dy = last_y - coords->y;

      blend_tool->start_x -= dx;
      blend_tool->start_y -= dy;

      blend_tool->end_x -= dx;
      blend_tool->end_y -= dy;
    }
  else
    {
      gimp_blend_tool_point_motion (blend_tool,
                                    state & gimp_get_constrain_behavior_mask ());
    }

  gimp_tool_pop_status (tool, display);
  gimp_blend_tool_push_status (blend_tool, state, display);

  if (GIMP_IS_CANVAS_LINE (blend_tool->line))
    gimp_blend_tool_update_items (blend_tool);

  gimp_blend_tool_update_preview_coords (blend_tool);
  gimp_image_map_apply (blend_tool->image_map, NULL);
}
Esempio n. 5
0
static void
gimp_blend_tool_options_notify (GimpTool         *tool,
                                GimpToolOptions  *options,
                                const GParamSpec *pspec)
{
  GimpContext   *context    = GIMP_CONTEXT (options);
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  if (! strcmp (pspec->name, "gradient"))
    {
      gimp_blend_tool_set_gradient (blend_tool, context->gradient);

      if (blend_tool->filter)
        gimp_drawable_filter_apply (blend_tool->filter, NULL);
    }
  else if (blend_tool->render_node &&
           gegl_node_find_property (blend_tool->render_node, pspec->name))
    {
      /* Sync any property changes on the config object that match the op */
      GValue value = G_VALUE_INIT;

      g_value_init (&value, pspec->value_type);

      g_object_get_property (G_OBJECT (options), pspec->name, &value);
      gegl_node_set_property (blend_tool->render_node, pspec->name, &value);

      g_value_unset (&value);

      if (! strcmp (pspec->name, "gradient-type"))
        {
          if (gimp_blend_tool_is_shapeburst (blend_tool))
            gimp_blend_tool_precalc_shapeburst (blend_tool);

          gimp_blend_tool_update_graph (blend_tool);
        }

      gimp_drawable_filter_apply (blend_tool->filter, NULL);
    }
  else if (blend_tool->filter &&
           ! strcmp (pspec->name, "opacity"))
    {
      gimp_drawable_filter_set_opacity (blend_tool->filter,
                                        gimp_context_get_opacity (context));
    }
  else if (blend_tool->filter &&
           ! strcmp (pspec->name, "paint-mode"))
    {
      gimp_drawable_filter_set_mode (blend_tool->filter,
                                     gimp_context_get_paint_mode (context));
    }
}
Esempio n. 6
0
static void
gimp_blend_tool_oper_update (GimpTool         *tool,
                             const GimpCoords *coords,
                             GdkModifierType   state,
                             gboolean          proximity,
                             GimpDisplay      *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  blend_tool->mouse_x = coords->x;
  blend_tool->mouse_y = coords->y;

  gimp_blend_tool_update_item_hilight (blend_tool);
}
Esempio n. 7
0
static void
gimp_blend_tool_motion (GimpTool         *tool,
                        const GimpCoords *coords,
                        guint32           time,
                        GdkModifierType   state,
                        GimpDisplay      *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  /* Save the mouse coordinates from last call */
  gdouble last_x = blend_tool->mouse_x;
  gdouble last_y = blend_tool->mouse_y;

  blend_tool->mouse_x = coords->x;
  blend_tool->mouse_y = coords->y;

  if (blend_tool->grabbed_point == POINT_FILL_MODE ||
      blend_tool->grabbed_point == POINT_INIT_MODE)
    {
      blend_tool->grabbed_point = POINT_END;
      gimp_blend_tool_start (blend_tool, display);
    }

  /* Move the whole line if alt is pressed */
  if (blend_tool->grabbed_point == POINT_BOTH)
    {
      gdouble dx = last_x - coords->x;
      gdouble dy = last_y - coords->y;

      blend_tool->start_x -= dx;
      blend_tool->start_y -= dy;

      blend_tool->end_x -= dx;
      blend_tool->end_y -= dy;
    }
  else
    {
      gimp_blend_tool_point_motion (blend_tool,
                                    state & gimp_get_constrain_behavior_mask ());
    }

  gimp_tool_pop_status (tool, display);
  gimp_blend_tool_push_status (blend_tool, state, display);

  gimp_blend_tool_update_items (blend_tool);

  gimp_blend_tool_update_graph (blend_tool);
  gimp_drawable_filter_apply (blend_tool->filter, NULL);
}
Esempio n. 8
0
static void
gimp_blend_tool_oper_update (GimpTool         *tool,
                             const GimpCoords *coords,
                             GdkModifierType   state,
                             gboolean          proximity,
                             GimpDisplay      *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
  GimpDrawTool  *draw_tool  = GIMP_DRAW_TOOL (tool);

  gimp_draw_tool_pause (draw_tool);
  blend_tool->mouse_x = coords->x;
  blend_tool->mouse_y = coords->y;
  gimp_draw_tool_resume (draw_tool);
}
Esempio n. 9
0
static void
gimp_blend_tool_button_release (GimpTool              *tool,
                                const GimpCoords      *coords,
                                guint32                time,
                                GdkModifierType        state,
                                GimpButtonReleaseType  release_type,
                                GimpDisplay           *display)
{
  GimpBlendTool    *blend_tool    = GIMP_BLEND_TOOL (tool);

  gimp_tool_pop_status (tool, display);
  /* XXX: Push a useful status message */

  gimp_tool_control_halt (tool->control);

  switch (release_type)
    {
    case GIMP_BUTTON_RELEASE_NORMAL:
      break;

    case GIMP_BUTTON_RELEASE_CANCEL:
      /* XXX: handle cancel properly */
      break;

    case GIMP_BUTTON_RELEASE_CLICK:
    case GIMP_BUTTON_RELEASE_NO_MOTION:
      if (blend_tool->grabbed_point == POINT_NONE)
        {
          if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
            {
              gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display);
              gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
            }
        }
      else if (blend_tool->grabbed_point == POINT_FILL_MODE)
        {
          /* XXX: Temporary, until the handles are working properly
           * for shapebursts
           */
          gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display);
          gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
        }
      break;
    }

  blend_tool->grabbed_point = POINT_NONE;
}
Esempio n. 10
0
static void
gimp_blend_tool_motion (GimpTool         *tool,
                        const GimpCoords *coords,
                        guint32           time,
                        GdkModifierType   state,
                        GimpDisplay      *display)
{
    GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

    blend_tool->mouse_x = coords->x;
    blend_tool->mouse_y = coords->y;

    /* Move the whole line if alt is pressed */
    if (state & GDK_MOD1_MASK)
    {
        gdouble dx = blend_tool->last_x - coords->x;
        gdouble dy = blend_tool->last_y - coords->y;

        blend_tool->start_x -= dx;
        blend_tool->start_y -= dy;

        blend_tool->end_x -= dx;
        blend_tool->end_y -= dy;
    }
    else
    {
        blend_tool->end_x = coords->x;
        blend_tool->end_y = coords->y;
    }

    if (state & GDK_CONTROL_MASK)
    {
        gimp_constrain_line (blend_tool->start_x, blend_tool->start_y,
                             &blend_tool->end_x, &blend_tool->end_y,
                             GIMP_CONSTRAIN_LINE_15_DEGREES);
    }

    gimp_tool_pop_status (tool, display);
    gimp_blend_tool_push_status (blend_tool, state, display);

    blend_tool->last_x = coords->x;
    blend_tool->last_y = coords->y;

    gimp_blend_tool_update_items (blend_tool);
}
Esempio n. 11
0
static void
gimp_blend_tool_control (GimpTool       *tool,
                         GimpToolAction  action,
                         GimpDisplay    *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

  switch (action)
    {
    case GIMP_TOOL_ACTION_PAUSE:
    case GIMP_TOOL_ACTION_RESUME:
      break;

    case GIMP_TOOL_ACTION_HALT:
      gimp_blend_tool_halt_preview (blend_tool);
      break;

    case GIMP_TOOL_ACTION_COMMIT:
      gimp_blend_tool_commit (blend_tool);
      break;
    }

  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
Esempio n. 12
0
static void
gimp_blend_tool_button_press (GimpTool            *tool,
                              const GimpCoords    *coords,
                              guint32              time,
                              GdkModifierType      state,
                              GimpButtonPressType  press_type,
                              GimpDisplay         *display)
{
    GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);

    blend_tool->start_x = blend_tool->end_x = coords->x;
    blend_tool->start_y = blend_tool->end_y = coords->y;

    blend_tool->last_x = blend_tool->mouse_x = coords->x;
    blend_tool->last_y = blend_tool->mouse_y = coords->y;

    tool->display = display;

    gimp_tool_control_activate (tool->control);

    gimp_blend_tool_push_status (blend_tool, state, display);

    gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
}
Esempio n. 13
0
static void
gimp_blend_tool_draw (GimpDrawTool *draw_tool)
{
  GimpBlendTool  *blend_tool = GIMP_BLEND_TOOL (draw_tool);
  GimpCanvasItem *start_handle_cross, *end_handle_cross;

  gimp_draw_tool_add_line (draw_tool,
                           blend_tool->start_x,
                           blend_tool->start_y,
                           blend_tool->end_x,
                           blend_tool->end_y);

  start_handle_cross =
    gimp_draw_tool_add_handle (draw_tool,
                               GIMP_HANDLE_CROSS,
                               blend_tool->start_x,
                               blend_tool->start_y,
                               HANDLE_CROSS_DIAMETER,
                               HANDLE_CROSS_DIAMETER,
                               GIMP_HANDLE_ANCHOR_CENTER);

  end_handle_cross =
    gimp_draw_tool_add_handle (draw_tool,
                               GIMP_HANDLE_CROSS,
                               blend_tool->end_x,
                               blend_tool->end_y,
                               HANDLE_CROSS_DIAMETER,
                               HANDLE_CROSS_DIAMETER,
                               GIMP_HANDLE_ANCHOR_CENTER);

  GimpBlendToolPoint hilight_point;
  gboolean           start_visible, end_visible;

  /* Calculate handle visibility */
  if (blend_tool->grabbed_point)
    {
      start_visible = FALSE;
      end_visible = FALSE;
    }
  else
    {
      gdouble dist;
      dist = gimp_draw_tool_calc_distance_square (draw_tool,
                                                  draw_tool->display,
                                                  blend_tool->mouse_x,
                                                  blend_tool->mouse_y,
                                                  blend_tool->start_x,
                                                  blend_tool->start_y);

      start_visible = dist < FULL_HANDLE_THRESHOLD_SQ;

      dist = gimp_draw_tool_calc_distance_square (draw_tool,
                                                  draw_tool->display,
                                                  blend_tool->mouse_x,
                                                  blend_tool->mouse_y,
                                                  blend_tool->end_x,
                                                  blend_tool->end_y);

      end_visible = dist < FULL_HANDLE_THRESHOLD_SQ;
    }

  /* Update hilights */
  if (blend_tool->grabbed_point)
    hilight_point = blend_tool->grabbed_point;
  else
    hilight_point = gimp_blend_tool_get_point_under_cursor (blend_tool);

  if (start_visible)
    {
      GimpCanvasItem *start_handle_circle;

      start_handle_circle =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CIRCLE,
                                   blend_tool->start_x,
                                   blend_tool->start_y,
                                   HANDLE_DIAMETER,
                                   HANDLE_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      gimp_canvas_item_set_highlight (start_handle_circle,
                                      hilight_point == POINT_START);
    }

  if (end_visible)
    {
      GimpCanvasItem *end_handle_circle;

      end_handle_circle =
        gimp_draw_tool_add_handle (draw_tool,
                                   GIMP_HANDLE_CIRCLE,
                                   blend_tool->end_x,
                                   blend_tool->end_y,
                                   HANDLE_DIAMETER,
                                   HANDLE_DIAMETER,
                                   GIMP_HANDLE_ANCHOR_CENTER);

      gimp_canvas_item_set_highlight (end_handle_circle,
                                      hilight_point == POINT_END);
    }

  gimp_canvas_item_set_highlight (start_handle_cross,
                                  hilight_point == POINT_START);
  gimp_canvas_item_set_highlight (end_handle_cross,
                                  hilight_point == POINT_END);
}
Esempio n. 14
0
static void
gimp_blend_tool_button_press (GimpTool            *tool,
                              const GimpCoords    *coords,
                              guint32              time,
                              GdkModifierType      state,
                              GimpButtonPressType  press_type,
                              GimpDisplay         *display)
{
  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
  GimpDrawTool  *draw_tool  = GIMP_DRAW_TOOL (tool);

  blend_tool->mouse_x = coords->x;
  blend_tool->mouse_y = coords->y;

  if (tool->display && display != tool->display)
    {
      gimp_tool_pop_status (tool, tool->display);
      gimp_blend_tool_halt_preview (blend_tool);
    }

  gimp_draw_tool_pause (draw_tool);

  blend_tool->grabbed_point = gimp_blend_tool_get_point_under_cursor (blend_tool);

  if (blend_tool->grabbed_point == POINT_NONE)
    {
      if (gimp_draw_tool_is_active (draw_tool))
        {
          gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, display);
          gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
        }

      if (gimp_blend_tool_is_shapeburst (blend_tool))
        {
          blend_tool->grabbed_point = POINT_FILL_MODE;
        }
      else
        {
          blend_tool->grabbed_point = POINT_INIT_MODE;

          blend_tool->start_x = coords->x;
          blend_tool->start_y = coords->y;
        }
    }

  gimp_blend_tool_point_motion (blend_tool,
                                state & gimp_get_constrain_behavior_mask ());

  tool->display = display;

  gimp_draw_tool_resume (draw_tool);

  if (blend_tool->grabbed_point != POINT_FILL_MODE &&
      blend_tool->grabbed_point != POINT_INIT_MODE)
    {
      gimp_blend_tool_update_preview_coords (blend_tool);
      gimp_image_map_apply (blend_tool->image_map, NULL);
    }

  gimp_tool_control_activate (tool->control);

  gimp_blend_tool_push_status (blend_tool, state, display);
}
Esempio n. 15
0
static void
gimp_blend_tool_button_release (GimpTool              *tool,
                                const GimpCoords      *coords,
                                guint32                time,
                                GdkModifierType        state,
                                GimpButtonReleaseType  release_type,
                                GimpDisplay           *display)
{
    GimpBlendTool    *blend_tool    = GIMP_BLEND_TOOL (tool);
    GimpBlendOptions *options       = GIMP_BLEND_TOOL_GET_OPTIONS (tool);
    GimpPaintOptions *paint_options = GIMP_PAINT_OPTIONS (options);
    GimpContext      *context       = GIMP_CONTEXT (options);
    GimpImage        *image         = gimp_display_get_image (display);

    gimp_tool_pop_status (tool, display);

    gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));

    gimp_tool_control_halt (tool->control);

    if ((release_type != GIMP_BUTTON_RELEASE_CANCEL) &&
            ((blend_tool->start_x != blend_tool->end_x) ||
             (blend_tool->start_y != blend_tool->end_y)))
    {
        GimpDrawable *drawable = gimp_image_get_active_drawable (image);
        GimpProgress *progress;
        gint          off_x;
        gint          off_y;

        progress = gimp_progress_start (GIMP_PROGRESS (tool),
                                        _("Blending"), FALSE);

        gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);

        gimp_drawable_blend (drawable,
                             context,
                             GIMP_CUSTOM_MODE,
                             gimp_context_get_paint_mode (context),
                             options->gradient_type,
                             gimp_context_get_opacity (context),
                             options->offset,
                             paint_options->gradient_options->gradient_repeat,
                             paint_options->gradient_options->gradient_reverse,
                             options->supersample,
                             options->supersample_depth,
                             options->supersample_threshold,
                             options->dither,
                             blend_tool->start_x - off_x,
                             blend_tool->start_y - off_y,
                             blend_tool->end_x - off_x,
                             blend_tool->end_y - off_y,
                             progress);

        if (progress)
            gimp_progress_end (progress);

        gimp_image_flush (image);
    }

    tool->display  = NULL;
    tool->drawable = NULL;
}