Пример #1
0
static void
gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
{
  GimpForegroundSelectTool    *fg_select = GIMP_FOREGROUND_SELECT_TOOL (draw_tool);
  GimpTool                    *tool      = GIMP_TOOL (draw_tool);
  GimpForegroundSelectOptions *options;

  options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

  if (fg_select->stroke)
    {
      gimp_draw_tool_add_pen (draw_tool,
                              (const GimpVector2 *) fg_select->stroke->data,
                              fg_select->stroke->len,
                              GIMP_CONTEXT (options),
                              (options->background ?
                               GIMP_ACTIVE_COLOR_BACKGROUND :
                               GIMP_ACTIVE_COLOR_FOREGROUND),
                              options->stroke_width);
    }

  if (fg_select->mask)
    {
      GimpDisplayShell   *shell = gimp_display_get_shell (draw_tool->display);
      gint                x     = fg_select->last_coords.x;
      gint                y     = fg_select->last_coords.y;
      gdouble             radius;

      radius = (options->stroke_width / shell->scale_y) / 2;

      /*  warn if the user is drawing outside of the working area  */
      if (FALSE)
        {
          gint x1, y1;
          gint x2, y2;

          gimp_foreground_select_tool_get_area (fg_select->mask,
                                                &x1, &y1, &x2, &y2);

          if (x < x1 + radius || x > x2 - radius ||
              y < y1 + radius || y > y2 - radius)
            {
              gimp_draw_tool_add_rectangle (draw_tool, FALSE,
                                            x1, y1,
                                            x2 - x1, y2 - y1);
            }
        }

      gimp_draw_tool_add_arc (draw_tool, FALSE,
                              x - radius, y - radius,
                              2 * radius, 2 * radius,
                              0.0, 2.0 * G_PI);
    }
  else
    {
      GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
    }
}
Пример #2
0
static void
gimp_seamless_clone_tool_draw (GimpDrawTool *draw_tool)
{
  GimpSeamlessCloneTool *sc = GIMP_SEAMLESS_CLONE_TOOL (draw_tool);

  if (sc->tool_state == SC_STATE_RENDER_WAIT ||
      sc->tool_state == SC_STATE_RENDER_MOTION)
    {
      gimp_draw_tool_add_rectangle (draw_tool, FALSE,
                                    sc->xoff, sc->yoff, sc->width, sc->height);
    }
}
Пример #3
0
static void
gimp_color_tool_draw (GimpDrawTool *draw_tool)
{
  GimpColorTool *color_tool = GIMP_COLOR_TOOL (draw_tool);

  if (color_tool->enabled)
    {
      if (color_tool->sample_point)
        {
          GimpImage      *image = gimp_display_get_image (draw_tool->display);
          GimpCanvasItem *item;
          gint            index;
          gint            x;
          gint            y;

          gimp_sample_point_get_position (color_tool->sample_point, &x, &y);

          index = g_list_index (gimp_image_get_sample_points (image),
                                color_tool->sample_point) + 1;

          item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
          gimp_canvas_item_set_highlight (item, TRUE);
        }

      if (color_tool->moving_sample_point)
        {
          if (color_tool->sample_point_x != SAMPLE_POINT_POSITION_INVALID &&
              color_tool->sample_point_y != SAMPLE_POINT_POSITION_INVALID)
            {
              gimp_draw_tool_add_crosshair (draw_tool,
                                            color_tool->sample_point_x,
                                            color_tool->sample_point_y);
            }
        }
      else if (color_tool->options->sample_average &&
               gimp_tool_control_is_active (GIMP_TOOL (draw_tool)->control))
        {
          gdouble radius = color_tool->options->average_radius;

          gimp_draw_tool_add_rectangle (draw_tool,
                                        FALSE,
                                        color_tool->center_x - radius,
                                        color_tool->center_y - radius,
                                        2 * radius + 1,
                                        2 * radius + 1);
        }
    }
}
static void
gimp_n_point_deformation_tool_draw (GimpDrawTool *draw_tool)
{
  GimpNPointDeformationTool    *npd_tool;
  GimpNPointDeformationOptions *npd_options;
  NPDModel                     *model;
  gint                          x0, y0, x1, y1;
  gint                          i;

  npd_tool    = GIMP_N_POINT_DEFORMATION_TOOL (draw_tool);
  npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool);

  model = npd_tool->model;

  g_return_if_fail (model != NULL);

  /* draw lattice */
  if (npd_options->mesh_visible)
    gimp_n_point_deformation_tool_draw_lattice (npd_tool);

  x0 = MIN (npd_tool->start_x, npd_tool->cursor_x);
  y0 = MIN (npd_tool->start_y, npd_tool->cursor_y);
  x1 = MAX (npd_tool->start_x, npd_tool->cursor_x);
  y1 = MAX (npd_tool->start_y, npd_tool->cursor_y);

  for (i = 0; i < model->control_points->len; i++)
    {
      NPDControlPoint *cp = &g_array_index (model->control_points,
                                            NPDControlPoint, i);
      NPDPoint         p  = cp->point;
      GimpHandleType   handle_type;

      p.x += npd_tool->offset_x;
      p.y += npd_tool->offset_y;

      handle_type = GIMP_HANDLE_CIRCLE;

      /* check if cursor is hovering over a control point or if a
       * control point is situated in an area defined by rubber band
       */
      if (cp == npd_tool->hovering_cp ||
          (npd_tool->rubber_band &&
           gimp_n_point_deformation_tool_is_cp_in_area (cp,
                                                        x0, y0,
                                                        x1, y1,
                                                        npd_tool->offset_x,
                                                        npd_tool->offset_y,
                                                        npd_tool->cp_scaled_radius)))
        {
          handle_type = GIMP_HANDLE_FILLED_CIRCLE;
        }

      gimp_draw_tool_add_handle (draw_tool,
                                 handle_type,
                                 p.x, p.y,
                                 GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                 GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                 GIMP_HANDLE_ANCHOR_CENTER);

      if (g_list_find (npd_tool->selected_cps, cp))
        {
          gimp_draw_tool_add_handle (draw_tool,
                                     GIMP_HANDLE_SQUARE,
                                     p.x, p.y,
                                     GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                     GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                     GIMP_HANDLE_ANCHOR_CENTER);
        }
    }

  if (npd_tool->rubber_band)
    {
      /* draw a rubber band */
      gimp_draw_tool_add_rectangle (draw_tool, FALSE,
                                    x0, y0, x1 - x0, y1 - y0);
    }

  if (npd_tool->preview_buffer)
    {
      GimpCanvasItem *item;

      item = gimp_canvas_buffer_preview_new (gimp_display_get_shell (draw_tool->display),
                                             npd_tool->preview_buffer);

      gimp_draw_tool_add_preview (draw_tool, item);
      g_object_unref (item);
    }

  GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
}
Пример #5
0
static void
gimp_align_tool_draw (GimpDrawTool *draw_tool)
{
    GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (draw_tool);
    GList         *list;
    gint           x, y, w, h;

    /* draw rubber-band rectangle */
    x = MIN (align_tool->x2, align_tool->x1);
    y = MIN (align_tool->y2, align_tool->y1);
    w = MAX (align_tool->x2, align_tool->x1) - x;
    h = MAX (align_tool->y2, align_tool->y1) - y;

    gimp_draw_tool_add_rectangle (draw_tool, FALSE, x, y, w, h);

    for (list = align_tool->selected_objects;
            list;
            list = g_list_next (list))
    {
        if (GIMP_IS_ITEM (list->data))
        {
            GimpItem *item = list->data;

            if (GIMP_IS_VECTORS (item))
            {
                gdouble x1_f, y1_f, x2_f, y2_f;

                gimp_vectors_bounds (GIMP_VECTORS (item),
                                     &x1_f, &y1_f,
                                     &x2_f, &y2_f);
                x = ROUND (x1_f);
                y = ROUND (y1_f);
                w = ROUND (x2_f - x1_f);
                h = ROUND (y2_f - y1_f);
            }
            else
            {
                gimp_item_get_offset (item, &x, &y);

                w = gimp_item_get_width  (item);
                h = gimp_item_get_height (item);
            }

            gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                       x, y,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_HANDLE_ANCHOR_NORTH_WEST);
            gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                       x + w, y,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_HANDLE_ANCHOR_NORTH_EAST);
            gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                       x, y + h,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_HANDLE_ANCHOR_SOUTH_WEST);
            gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                       x + w, y + h,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_TOOL_HANDLE_SIZE_SMALL,
                                       GIMP_HANDLE_ANCHOR_SOUTH_EAST);
        }
        else if (GIMP_IS_GUIDE (list->data))
        {
            GimpGuide *guide = list->data;
            GimpImage *image = gimp_display_get_image (GIMP_TOOL (draw_tool)->display);
            gint       x, y;
            gint       w, h;

            switch (gimp_guide_get_orientation (guide))
            {
            case GIMP_ORIENTATION_VERTICAL:
                x = gimp_guide_get_position (guide);
                h = gimp_image_get_height (image);
                gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                           x, h,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_HANDLE_ANCHOR_SOUTH);
                gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                           x, 0,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_HANDLE_ANCHOR_NORTH);
                break;

            case GIMP_ORIENTATION_HORIZONTAL:
                y = gimp_guide_get_position (guide);
                w = gimp_image_get_width (image);
                gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                           w, y,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_HANDLE_ANCHOR_EAST);
                gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
                                           0, y,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_TOOL_HANDLE_SIZE_SMALL,
                                           GIMP_HANDLE_ANCHOR_WEST);
                break;

            default:
                break;
            }
        }
    }
}
Пример #6
0
static void
gimp_cage_tool_draw (GimpDrawTool *draw_tool)
{
  GimpCageTool    *ct        = GIMP_CAGE_TOOL (draw_tool);
  GimpCageOptions *options   = GIMP_CAGE_TOOL_GET_OPTIONS (ct);
  GimpCageConfig  *config    = ct->config;
  GimpCanvasGroup *stroke_group;
  gint             n_vertices;
  gint             i;
  GimpHandleType   handle;

  n_vertices = gimp_cage_config_get_n_points (config);

  if (n_vertices == 0)
    return;

  if (ct->tool_state == CAGE_STATE_INIT)
    return;

  stroke_group = gimp_draw_tool_add_stroke_group (draw_tool);

  gimp_draw_tool_push_group (draw_tool, stroke_group);

  /* If needed, draw line to the cursor. */
  if (! gimp_cage_tool_is_complete (ct))
    {
      GimpVector2 last_point;

      last_point = gimp_cage_config_get_point_coordinate (ct->config,
                                                          options->cage_mode,
                                                          n_vertices - 1);

      gimp_draw_tool_add_line (draw_tool,
                               last_point.x + ct->offset_x,
                               last_point.y + ct->offset_y,
                               ct->cursor_x,
                               ct->cursor_y);
    }

  gimp_draw_tool_pop_group (draw_tool);

  /* Draw the cage with handles. */
  for (i = 0; i < n_vertices; i++)
    {
      GimpVector2 point1, point2;

      point1 = gimp_cage_config_get_point_coordinate (ct->config,
                                                      options->cage_mode,
                                                      i);
      point1.x += ct->offset_x;
      point1.y += ct->offset_y;

      if (i > 0 || gimp_cage_tool_is_complete (ct))
        {
          gint index_point2;

          if (i == 0)
            index_point2 = n_vertices - 1;
          else
            index_point2 = i - 1;

          point2 = gimp_cage_config_get_point_coordinate (ct->config,
                                                          options->cage_mode,
                                                          index_point2);
          point2.x += ct->offset_x;
          point2.y += ct->offset_y;

          gimp_draw_tool_push_group (draw_tool, stroke_group);

          gimp_draw_tool_add_line (draw_tool,
                                   point1.x,
                                   point1.y,
                                   point2.x,
                                   point2.y);

          gimp_draw_tool_pop_group (draw_tool);
        }

      if (i == ct->hovering_handle)
        handle = GIMP_HANDLE_FILLED_CIRCLE;
      else
        handle = GIMP_HANDLE_CIRCLE;

      gimp_draw_tool_add_handle (draw_tool,
                                 handle,
                                 point1.x,
                                 point1.y,
                                 GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                 GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                 GIMP_HANDLE_ANCHOR_CENTER);

      if (gimp_cage_config_point_is_selected (ct->config, i))
        {
          gimp_draw_tool_add_handle (draw_tool,
                                     GIMP_HANDLE_SQUARE,
                                     point1.x,
                                     point1.y,
                                     GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                     GIMP_TOOL_HANDLE_SIZE_CIRCLE,
                                     GIMP_HANDLE_ANCHOR_CENTER);
        }
    }

  if (ct->tool_state == DEFORM_STATE_SELECTING ||
      ct->tool_state == CAGE_STATE_SELECTING)
    {
      gimp_draw_tool_add_rectangle (draw_tool,
                                    FALSE,
                                    MIN (ct->selection_start_x, ct->cursor_x),
                                    MIN (ct->selection_start_y, ct->cursor_y),
                                    abs (ct->selection_start_x - ct->cursor_x),
                                    abs (ct->selection_start_y - ct->cursor_y));
    }
}