예제 #1
0
static void
gimp_image_map_tool_guide_moved (GimpGuide        *guide,
                                 const GParamSpec *pspec,
                                 GimpImageMapTool *im_tool)
{
  GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (im_tool);
  GimpItem            *item    = GIMP_ITEM (im_tool->drawable);
  gdouble              position;

  if (options->preview_alignment == GIMP_ALIGN_LEFT ||
      options->preview_alignment == GIMP_ALIGN_RIGHT)
    {
      position = ((gdouble) (gimp_guide_get_position (guide) -
                             gimp_item_get_offset_x (item)) /
                  (gdouble) gimp_item_get_width (item));
    }
  else
    {
      position = ((gdouble) (gimp_guide_get_position (guide) -
                             gimp_item_get_offset_y (item)) /
                  (gdouble) gimp_item_get_height (item));
    }

  g_object_set (options,
                "preview-position", CLAMP (position, 0.0, 1.0),
                NULL);
}
예제 #2
0
/*
 * Position the dropped item in the middle of the viewport.
 */
static void
gimp_display_shell_dnd_position_item (GimpDisplayShell *shell,
                                      GimpImage        *image,
                                      GimpItem         *item)
{
  gint item_width  = gimp_item_get_width  (item);
  gint item_height = gimp_item_get_height (item);
  gint off_x, off_y;

  if (item_width  >= gimp_image_get_width  (image) &&
      item_height >= gimp_image_get_height (image))
    {
      off_x = (gimp_image_get_width  (image) - item_width)  / 2;
      off_y = (gimp_image_get_height (image) - item_height) / 2;
    }
  else
    {
      gint x, y;
      gint width, height;

      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);

      off_x = x + (width  - item_width)  / 2;
      off_y = y + (height - item_height) / 2;
    }

  gimp_item_translate (item,
                       off_x - gimp_item_get_offset_x (item),
                       off_y - gimp_item_get_offset_y (item),
                       FALSE);
}
예제 #3
0
void
gimp_image_resize_to_layers (GimpImage    *image,
                             GimpContext  *context,
                             GimpProgress *progress)
{
  GList    *list;
  GimpItem *item;
  gint      x, y;
  gint      width, height;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (GIMP_IS_CONTEXT (context));
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));

  list = gimp_image_get_layer_iter (image);

  if (! list)
    return;

  /* figure out starting values */
  item = list->data;

  x      = gimp_item_get_offset_x (item);
  y      = gimp_item_get_offset_y (item);
  width  = gimp_item_get_width  (item);
  height = gimp_item_get_height (item);

  /*  Respect all layers  */
  for (list = g_list_next (list); list; list = g_list_next (list))
    {
      item = list->data;

      gimp_rectangle_union (x, y,
                            width, height,
                            gimp_item_get_offset_x (item),
                            gimp_item_get_offset_y (item),
                            gimp_item_get_width  (item),
                            gimp_item_get_height (item),
                            &x, &y,
                            &width, &height);
    }

  gimp_image_resize (image, context,
                     width, height, -x, -y,
                     progress);
}
예제 #4
0
static void
gimp_image_map_tool_add_guide (GimpImageMapTool *im_tool)
{
  GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (im_tool);
  GimpItem            *item;
  GimpImage           *image;
  GimpOrientationType  orientation;
  gint                 position;

  if (im_tool->percent_guide)
    return;

  item = GIMP_ITEM (im_tool->drawable);
  image = gimp_item_get_image (item);

  if (options->preview_alignment == GIMP_ALIGN_LEFT ||
      options->preview_alignment == GIMP_ALIGN_RIGHT)
    {
      orientation = GIMP_ORIENTATION_VERTICAL;

      position = (gimp_item_get_offset_x (item) +
                  gimp_item_get_width (item) *
                  options->preview_position);
    }
  else
    {
      orientation = GIMP_ORIENTATION_HORIZONTAL;

      position = (gimp_item_get_offset_y (item) +
                  gimp_item_get_height (item) *
                  options->preview_position);
    }

  im_tool->percent_guide = gimp_guide_custom_new (orientation,
                                                  image->gimp->next_guide_ID++,
                                                  GIMP_GUIDE_STYLE_SPLIT_VIEW);

  gimp_image_add_guide (image, im_tool->percent_guide, position);

  g_signal_connect (im_tool->percent_guide, "removed",
                    G_CALLBACK (gimp_image_map_tool_guide_removed),
                    im_tool);
  g_signal_connect (im_tool->percent_guide, "notify::position",
                    G_CALLBACK (gimp_image_map_tool_guide_moved),
                    im_tool);
}
예제 #5
0
static void
gimp_image_map_tool_move_guide (GimpImageMapTool *im_tool)
{
  GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (im_tool);
  GimpItem            *item;
  GimpOrientationType  orientation;
  gint                 position;

  if (! im_tool->percent_guide)
    return;

  item = GIMP_ITEM (im_tool->drawable);

  if (options->preview_alignment == GIMP_ALIGN_LEFT ||
      options->preview_alignment == GIMP_ALIGN_RIGHT)
    {
      orientation = GIMP_ORIENTATION_VERTICAL;

      position = (gimp_item_get_offset_x (item) +
                  gimp_item_get_width (item) *
                  options->preview_position);
    }
  else
    {
      orientation = GIMP_ORIENTATION_HORIZONTAL;

      position = (gimp_item_get_offset_y (item) +
                  gimp_item_get_height (item) *
                  options->preview_position);
    }

  if (orientation != gimp_guide_get_orientation (im_tool->percent_guide) ||
      position    != gimp_guide_get_position (im_tool->percent_guide))
    {
      gimp_guide_set_orientation (im_tool->percent_guide, orientation);
      gimp_image_move_guide (gimp_item_get_image (item),
                             im_tool->percent_guide, position, FALSE);
    }
}
예제 #6
0
static void
gimp_image_map_tool_options_notify (GimpTool         *tool,
                                    GimpToolOptions  *options,
                                    const GParamSpec *pspec)
{
  GimpImageMapTool    *im_tool    = GIMP_IMAGE_MAP_TOOL (tool);
  GimpImageMapOptions *im_options = GIMP_IMAGE_MAP_OPTIONS (options);

  if (! strcmp (pspec->name, "preview") &&
      im_tool->image_map)
    {
      if (im_options->preview)
        {
          gimp_tool_control_push_preserve (tool->control, TRUE);

          gimp_image_map_apply (im_tool->image_map, NULL);

          gimp_tool_control_pop_preserve (tool->control);

          if (im_options->preview_split)
            gimp_image_map_tool_add_guide (im_tool);
        }
      else
        {
          gimp_tool_control_push_preserve (tool->control, TRUE);

          gimp_image_map_abort (im_tool->image_map);

          gimp_tool_control_pop_preserve (tool->control);

          if (im_options->preview_split)
            gimp_image_map_tool_remove_guide (im_tool);
        }
    }
  else if (! strcmp (pspec->name, "preview-split") &&
           im_tool->image_map)
    {
      if (im_options->preview_split)
        {
          GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
          GimpItem         *item  = GIMP_ITEM (im_tool->drawable);
          gint              x, y, width, height;

          gimp_display_shell_untransform_viewport (shell,
                                                   &x, &y, &width, &height);

          if (gimp_rectangle_intersect (gimp_item_get_offset_x (item),
                                        gimp_item_get_offset_y (item),
                                        gimp_item_get_width  (item),
                                        gimp_item_get_height (item),
                                        x, y, width, height,
                                        &x, &y, &width, &height))
            {
              gdouble position;

              if (im_options->preview_alignment == GIMP_ALIGN_LEFT ||
                  im_options->preview_alignment == GIMP_ALIGN_RIGHT)
                {
                  position = ((gdouble) ((x + width / 2) -
                                         gimp_item_get_offset_x (item)) /
                              (gdouble) gimp_item_get_width (item));
                }
              else
                {
                  position = ((gdouble) ((y + height / 2) -
                                         gimp_item_get_offset_y (item)) /
                              (gdouble) gimp_item_get_height (item));
                }

              g_object_set (options,
                            "preview-position", CLAMP (position, 0.0, 1.0),
                            NULL);

            }
        }

      gimp_image_map_set_preview (im_tool->image_map,
                                  im_options->preview_split,
                                  im_options->preview_alignment,
                                  im_options->preview_position);

      if (im_options->preview_split)
        gimp_image_map_tool_add_guide (im_tool);
      else
        gimp_image_map_tool_remove_guide (im_tool);
    }
  else if (! strcmp (pspec->name, "preview-alignment") &&
           im_tool->image_map)
    {
      gimp_image_map_set_preview (im_tool->image_map,
                                  im_options->preview_split,
                                  im_options->preview_alignment,
                                  im_options->preview_position);

      if (im_options->preview_split)
        gimp_image_map_tool_move_guide (im_tool);
    }
  else if (! strcmp (pspec->name, "preview-position") &&
           im_tool->image_map)
    {
      gimp_image_map_set_preview (im_tool->image_map,
                                  im_options->preview_split,
                                  im_options->preview_alignment,
                                  im_options->preview_position);

      if (im_options->preview_split)
        gimp_image_map_tool_move_guide (im_tool);
    }
  else if (! strcmp (pspec->name, "region") &&
           im_tool->image_map)
    {
      gimp_image_map_set_region (im_tool->image_map, im_options->region);
      gimp_image_map_tool_preview (im_tool);
    }
}
예제 #7
0
static void
gimp_image_map_tool_button_press (GimpTool            *tool,
                                  const GimpCoords    *coords,
                                  guint32              time,
                                  GdkModifierType      state,
                                  GimpButtonPressType  press_type,
                                  GimpDisplay         *display)
{
  GimpImageMapTool *im_tool = GIMP_IMAGE_MAP_TOOL (tool);

  if (! gimp_image_map_tool_on_guide (im_tool, coords, display))
    {
      GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
                                                    press_type, display);
    }
  else
    {
      GimpImageMapOptions *options = GIMP_IMAGE_MAP_TOOL_GET_OPTIONS (tool);

      if (state & gimp_get_extend_selection_mask ())
        {
          GimpAlignmentType alignment;

          /* switch side */
          switch (options->preview_alignment)
            {
            case GIMP_ALIGN_LEFT:   alignment = GIMP_ALIGN_RIGHT;  break;
            case GIMP_ALIGN_RIGHT:  alignment = GIMP_ALIGN_LEFT;   break;
            case GIMP_ALIGN_TOP:    alignment = GIMP_ALIGN_BOTTOM; break;
            case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_TOP;    break;
            default:
              g_return_if_reached ();
            }

          g_object_set (options, "preview-alignment", alignment, NULL);
        }
      else if (state & gimp_get_toggle_behavior_mask ())
        {
          GimpItem          *item = GIMP_ITEM (im_tool->drawable);
          GimpAlignmentType  alignment;
          gdouble            position;

          /* switch orientation */
          switch (options->preview_alignment)
            {
            case GIMP_ALIGN_LEFT:   alignment = GIMP_ALIGN_TOP;    break;
            case GIMP_ALIGN_RIGHT:  alignment = GIMP_ALIGN_BOTTOM; break;
            case GIMP_ALIGN_TOP:    alignment = GIMP_ALIGN_LEFT;   break;
            case GIMP_ALIGN_BOTTOM: alignment = GIMP_ALIGN_RIGHT;  break;
            default:
              g_return_if_reached ();
            }

          if (alignment == GIMP_ALIGN_LEFT ||
              alignment == GIMP_ALIGN_RIGHT)
            {
              position = ((coords->x - gimp_item_get_offset_x (item)) /
                          gimp_item_get_width (item));
            }
          else
            {
              position = ((coords->y - gimp_item_get_offset_y (item)) /
                          gimp_item_get_height (item));
            }

          g_object_set (options,
                        "preview-alignment", alignment,
                        "preview-position",  CLAMP (position, 0.0, 1.0),
                        NULL);
        }
      else
        {
          gimp_guide_tool_start_edit (tool, display,
                                      im_tool->percent_guide);
        }
    }
}