gimpitem-linked.c 6.49 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gegl.h>
21 22 23

#include "core-types.h"

24
#include "gimpcontext.h"
25
#include "gimpimage.h"
26
#include "gimpimage-item-list.h"
27 28 29
#include "gimpitem.h"
#include "gimpitem-linked.h"
#include "gimplist.h"
30
#include "gimpprogress.h"
31 32


33 34
/*  public functions  */

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
gboolean
gimp_item_linked_is_locked (const GimpItem *item)
{
  GList    *list;
  GList    *l;
  gboolean  locked = FALSE;

  g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
  g_return_val_if_fail (gimp_item_get_linked (item) == TRUE, FALSE);
  g_return_val_if_fail (gimp_item_is_attached (item), FALSE);

  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_ALL,
                                        GIMP_ITEM_SET_LINKED);

  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

52
  for (l = list; l && ! locked; l = g_list_next (l))
53 54 55
    {
      GimpItem *item = l->data;

56 57 58 59 60 61
      /*  temporarily set the item to not being linked, or we will
       *  run into a recursion because gimp_item_is_position_locked()
       *  call this function if the item is linked
       */
      gimp_item_set_linked (item, FALSE, FALSE);

62
      if (gimp_item_is_position_locked (item))
63 64 65
        locked = TRUE;

      gimp_item_set_linked (item, TRUE, FALSE);
66 67 68 69 70 71 72
    }

  g_list_free (list);

  return locked;
}

73 74 75 76 77 78
void
gimp_item_linked_translate (GimpItem *item,
                            gint      offset_x,
                            gint      offset_y,
                            gboolean  push_undo)
{
79
  GList *list;
80 81

  g_return_if_fail (GIMP_IS_ITEM (item));
82
  g_return_if_fail (gimp_item_get_linked (item) == TRUE);
83
  g_return_if_fail (gimp_item_is_attached (item));
84

85 86 87
  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_ALL,
                                        GIMP_ITEM_SET_LINKED);
88

89 90
  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

91 92
  gimp_image_item_list_translate (gimp_item_get_image (item), list,
                                  offset_x, offset_y, push_undo);
93

94
  g_list_free (list);
95 96 97 98
}

void
gimp_item_linked_flip (GimpItem            *item,
99
                       GimpContext         *context,
100
                       GimpOrientationType  flip_type,
101 102
                       gdouble              axis,
                       gboolean             clip_result)
103
{
104
  GList *list;
105 106

  g_return_if_fail (GIMP_IS_ITEM (item));
107
  g_return_if_fail (GIMP_IS_CONTEXT (context));
108
  g_return_if_fail (gimp_item_get_linked (item) == TRUE);
109
  g_return_if_fail (gimp_item_is_attached (item));
110

111 112 113
  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_ALL,
                                        GIMP_ITEM_SET_LINKED);
114

115 116
  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

117 118
  gimp_image_item_list_flip (gimp_item_get_image (item), list, context,
                             flip_type, axis, clip_result);
119

120
  g_list_free (list);
121 122
}

123 124
void
gimp_item_linked_rotate (GimpItem         *item,
125
                         GimpContext      *context,
126 127 128 129 130
                         GimpRotationType  rotate_type,
                         gdouble           center_x,
                         gdouble           center_y,
                         gboolean          clip_result)
{
131
  GList *list;
132 133

  g_return_if_fail (GIMP_IS_ITEM (item));
134
  g_return_if_fail (GIMP_IS_CONTEXT (context));
135
  g_return_if_fail (gimp_item_get_linked (item) == TRUE);
136
  g_return_if_fail (gimp_item_is_attached (item));
137

138 139 140 141
  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_LAYERS |
                                        GIMP_ITEM_TYPE_VECTORS,
                                        GIMP_ITEM_SET_LINKED);
142

143 144
  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

145 146
  gimp_image_item_list_rotate (gimp_item_get_image (item), list, context,
                               rotate_type, center_x, center_y, clip_result);
147

148
  g_list_free (list);
149

150 151 152
  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_CHANNELS,
                                        GIMP_ITEM_SET_LINKED);
153

154 155
  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

156 157
  gimp_image_item_list_rotate (gimp_item_get_image (item), list, context,
                               rotate_type, center_x, center_y, TRUE);
158

159
  g_list_free (list);
160 161
}

162 163
void
gimp_item_linked_transform (GimpItem               *item,
164
                            GimpContext            *context,
165
                            const GimpMatrix3      *matrix,
166 167
                            GimpTransformDirection  direction,
                            GimpInterpolationType   interpolation_type,
168
                            gint                    recursion_level,
169
                            GimpTransformResize     clip_result,
170
                            GimpProgress           *progress)
171
{
172
  GList *list;
173 174

  g_return_if_fail (GIMP_IS_ITEM (item));
175
  g_return_if_fail (GIMP_IS_CONTEXT (context));
176
  g_return_if_fail (gimp_item_get_linked (item) == TRUE);
177
  g_return_if_fail (gimp_item_is_attached (item));
178
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
179

180 181 182
  list = gimp_image_item_list_get_list (gimp_item_get_image (item), item,
                                        GIMP_ITEM_TYPE_ALL,
                                        GIMP_ITEM_SET_LINKED);
183

184 185
  list = gimp_image_item_list_filter (item, list, TRUE, FALSE);

186 187
  gimp_image_item_list_transform (gimp_item_get_image (item), list, context,
                                  matrix, direction,
188
                                  interpolation_type, recursion_level,
189
                                  clip_result, progress);
190

191
  g_list_free (list);
192
}