示例#1
0
gint
gimp_guide_get_position (GimpGuide *guide)
{
    g_return_val_if_fail (GIMP_IS_GUIDE (guide), -1);

    return guide->position;
}
示例#2
0
void
gimp_guide_removed (GimpGuide *guide)
{
    g_return_if_fail (GIMP_IS_GUIDE (guide));

    g_signal_emit (guide, gimp_guide_signals[REMOVED], 0);
}
示例#3
0
GimpOrientationType
gimp_guide_get_orientation (GimpGuide *guide)
{
    g_return_val_if_fail (GIMP_IS_GUIDE (guide), GIMP_ORIENTATION_UNKNOWN);

    return guide->orientation;
}
示例#4
0
guint32
gimp_guide_get_ID (GimpGuide *guide)
{
    g_return_val_if_fail (GIMP_IS_GUIDE (guide), 0);

    return guide->guide_ID;
}
示例#5
0
void
gimp_guide_set_position (GimpGuide *guide,
                         gint       position)
{
    g_return_if_fail (GIMP_IS_GUIDE (guide));

    guide->position = position;

    g_object_notify (G_OBJECT (guide), "position");
}
示例#6
0
void
gimp_guide_set_orientation (GimpGuide           *guide,
                            GimpOrientationType  orientation)
{
    g_return_if_fail (GIMP_IS_GUIDE (guide));

    guide->orientation = orientation;

    g_object_notify (G_OBJECT (guide), "orientation");
}
示例#7
0
void
gimp_guide_tool_start_edit (GimpTool    *parent_tool,
                            GimpDisplay *display,
                            GimpGuide   *guide)
{
  g_return_if_fail (GIMP_IS_TOOL (parent_tool));
  g_return_if_fail (GIMP_IS_DISPLAY (display));
  g_return_if_fail (GIMP_IS_GUIDE (guide));

  gimp_guide_tool_start (parent_tool, display,
                         guide, GIMP_ORIENTATION_UNKNOWN);
}
示例#8
0
GimpUndo *
gimp_image_undo_push_guide (GimpImage   *image,
                            const gchar *undo_desc,
                            GimpGuide   *guide)
{
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_GUIDE (guide), NULL);

  return gimp_image_undo_push (image, GIMP_TYPE_GUIDE_UNDO,
                               GIMP_UNDO_GUIDE, undo_desc,
                               GIMP_DIRTY_IMAGE_META,
                               "guide", guide,
                               NULL);
}
示例#9
0
static GObject *
gimp_guide_undo_constructor (GType                  type,
                             guint                  n_params,
                             GObjectConstructParam *params)
{
  GObject       *object;
  GimpGuideUndo *guide_undo;

  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);

  guide_undo = GIMP_GUIDE_UNDO (object);

  g_assert (GIMP_IS_GUIDE (guide_undo->guide));

  guide_undo->orientation = gimp_guide_get_orientation (guide_undo->guide);
  guide_undo->position    = gimp_guide_get_position (guide_undo->guide);

  return object;
}
示例#10
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;
            }
        }
    }
}
示例#11
0
/**
 * gimp_image_arrange_objects:
 * @image:                The #GimpImage to which the objects belong.
 * @list:                 A #GList of objects to be aligned.
 * @alignment:            The point on each target object to bring into alignment.
 * @reference:            The #GObject to align the targets with, or #NULL.
 * @reference_alignment:  The point on the reference object to align the target item with..
 * @offset:               How much to shift the target from perfect alignment..
 *
 * This function shifts the positions of a set of target objects, which can be
 * "items" or guides, to bring them into a specified type of alignment with a
 * reference object, which can be an item, guide, or image.  If the requested
 * alignment does not make sense (i.e., trying to align a vertical guide vertically),
 * nothing happens and no error message is generated.
 *
 * The objects in the list are sorted into increasing order before
 * being arranged, where the order is defined by the type of alignment
 * being requested.  If the @reference argument is #NULL, then the first
 * object in the sorted list is used as reference.
 *
 * When there are multiple target objects, they are arranged so that the spacing
 * between consecutive ones is given by the argument @offset.
 */
void
gimp_image_arrange_objects (GimpImage         *image,
                            GList             *list,
                            GimpAlignmentType  alignment,
                            GObject           *reference,
                            GimpAlignmentType  reference_alignment,
                            gint               offset)
{
  gboolean do_x               = FALSE;
  gboolean do_y               = FALSE;
  gint     z0                 = 0;
  GList   *object_list;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (G_IS_OBJECT (reference) || reference == NULL);

  /* get offsets used for sorting */
  switch (alignment)
    {
      /* order vertically for horizontal alignment */
    case GIMP_ALIGN_LEFT:
    case GIMP_ALIGN_HCENTER:
    case GIMP_ALIGN_RIGHT:
      do_x = TRUE;
      compute_offsets (list, GIMP_ALIGN_TOP);
      break;
      /* order horizontally for horizontal arrangement */
    case GIMP_ARRANGE_LEFT:
    case GIMP_ARRANGE_HCENTER:
    case GIMP_ARRANGE_RIGHT:
      do_x = TRUE;
      compute_offsets (list, alignment);
      break;
      /* order horizontally for vertical alignment */
    case GIMP_ALIGN_TOP:
    case GIMP_ALIGN_VCENTER:
    case GIMP_ALIGN_BOTTOM:
      do_y = TRUE;
      compute_offsets (list, GIMP_ALIGN_LEFT);
      break;
      /* order vertically for vertical arrangement */
    case GIMP_ARRANGE_TOP:
    case GIMP_ARRANGE_VCENTER:
    case GIMP_ARRANGE_BOTTOM:
      do_y = TRUE;
      compute_offsets (list, alignment);
      break;
    }

  object_list = sort_by_offset (list);

  /* now get offsets used for aligning */
  compute_offsets (list, alignment);

  if (reference == NULL)
    {
      reference = G_OBJECT (object_list->data);
      object_list = g_list_next (object_list);
    }
  else
    compute_offset (reference, reference_alignment);

  z0 = GPOINTER_TO_INT (g_object_get_data (reference, "align-offset"));

  if (object_list)
    {
      GList *l;
      gint   n;

      /* FIXME: undo group type is wrong */
      gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_ITEM_DISPLACE,
                                   C_("undo-type", "Arrange Objects"));

      for (l = object_list, n = 1; l; l = g_list_next (l), n++)
        {
          GObject *target          = G_OBJECT (l->data);
          gint     xtranslate      = 0;
          gint     ytranslate      = 0;
          gint     z1;

          z1 = GPOINTER_TO_INT (g_object_get_data (target,
                                                    "align-offset"));

          if (do_x)
            xtranslate = z0 - z1 + n * offset;

          if (do_y)
            ytranslate = z0 - z1 + n * offset;

          /* now actually align the target object */
          if (GIMP_IS_ITEM (target))
            {
              gimp_item_translate (GIMP_ITEM (target),
                                   xtranslate, ytranslate, TRUE);
            }
          else if (GIMP_IS_GUIDE (target))
            {
              GimpGuide *guide = GIMP_GUIDE (target);

              switch (gimp_guide_get_orientation (guide))
                {
                case GIMP_ORIENTATION_VERTICAL:
                  gimp_image_move_guide (image, guide, z1 + xtranslate, TRUE);
                  break;

                case GIMP_ORIENTATION_HORIZONTAL:
                  gimp_image_move_guide (image, guide, z1 + ytranslate, TRUE);
                  break;

                default:
                  break;
                }
            }
        }

      gimp_image_undo_group_end (image);
    }

  g_list_free (object_list);
}
示例#12
0
static void
compute_offset (GObject *object,
                GimpAlignmentType  alignment)
{
  gint object_offset_x = 0;
  gint object_offset_y = 0;
  gint object_height   = 0;
  gint object_width    = 0;
  gint offset          = 0;

  if (GIMP_IS_IMAGE (object))
    {
      GimpImage *image = GIMP_IMAGE (object);

      object_offset_x = 0;
      object_offset_y = 0;
      object_height   = gimp_image_get_height (image);
      object_width    = gimp_image_get_width (image);
    }
  else if (GIMP_IS_CHANNEL (object))
    {
      /* for channels, we use the bounds of the visible area, not
         the layer bounds.  This includes the selection channel */

      GimpChannel *channel = GIMP_CHANNEL (object);

      if (gimp_channel_is_empty (channel))
        {
          /* fall back on using the offsets instead */
          GimpItem *item = GIMP_ITEM (object);

          gimp_item_get_offset (item, &object_offset_x, &object_offset_y);
          object_width  = gimp_item_get_width  (item);
          object_height = gimp_item_get_height (item);
        }
      else
        {
          gint x1, x2, y1, y2;

          gimp_channel_bounds (channel, &x1, &y1, &x2, &y2);
          object_offset_x = x1;
          object_offset_y = y1;
          object_width    = x2 - x1;
          object_height   = y2 - y1;
        }
    }
  else if (GIMP_IS_ITEM (object))
    {
      GimpItem *item = GIMP_ITEM (object);

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

          gimp_vectors_bounds (GIMP_VECTORS (item),
                               &x1_f, &y1_f,
                               &x2_f, &y2_f);

          object_offset_x = ROUND (x1_f);
          object_offset_y = ROUND (y1_f);
          object_height   = ROUND (y2_f - y1_f);
          object_width    = ROUND (x2_f - x1_f);
        }
      else
        {
          gimp_item_get_offset (item, &object_offset_x, &object_offset_y);
          object_width  = gimp_item_get_width  (item);
          object_height = gimp_item_get_height (item);
        }
    }
  else if (GIMP_IS_GUIDE (object))
    {
      GimpGuide *guide = GIMP_GUIDE (object);

      switch (gimp_guide_get_orientation (guide))
        {
        case GIMP_ORIENTATION_VERTICAL:
          object_offset_x = gimp_guide_get_position (guide);
          object_width = 0;
          break;

        case GIMP_ORIENTATION_HORIZONTAL:
          object_offset_y = gimp_guide_get_position (guide);
          object_height = 0;
          break;

        default:
          break;
        }
    }
  else
    {
      g_printerr ("Alignment object is not an image, item or guide.\n");
    }

  switch (alignment)
    {
    case GIMP_ALIGN_LEFT:
    case GIMP_ARRANGE_LEFT:
      offset = object_offset_x;
      break;
    case GIMP_ALIGN_HCENTER:
    case GIMP_ARRANGE_HCENTER:
      offset = object_offset_x + object_width/2;
      break;
    case GIMP_ALIGN_RIGHT:
    case GIMP_ARRANGE_RIGHT:
      offset = object_offset_x + object_width;
      break;
    case GIMP_ALIGN_TOP:
    case GIMP_ARRANGE_TOP:
      offset = object_offset_y;
      break;
    case GIMP_ALIGN_VCENTER:
    case GIMP_ARRANGE_VCENTER:
      offset = object_offset_y + object_height/2;
      break;
    case GIMP_ALIGN_BOTTOM:
    case GIMP_ARRANGE_BOTTOM:
      offset = object_offset_y + object_height;
      break;
    default:
      g_assert_not_reached ();
    }

  g_object_set_data (object, "align-offset",
                     GINT_TO_POINTER (offset));
}