1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * gimpcontext.h
5  * Copyright (C) 1999-2010 Michael Natterer
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __GIMP_CONTEXT_H__
22 #define __GIMP_CONTEXT_H__
23 
24 
25 #include "gimpviewable.h"
26 
27 
28 #define GIMP_TYPE_CONTEXT            (gimp_context_get_type ())
29 #define GIMP_CONTEXT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_CONTEXT, GimpContext))
30 #define GIMP_CONTEXT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GIMP_TYPE_CONTEXT, GimpContextClass))
31 #define GIMP_IS_CONTEXT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_CONTEXT))
32 #define GIMP_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_CONTEXT))
33 #define GIMP_CONTEXT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS (obj, GIMP_TYPE_CONTEXT, GimpContextClass))
34 
35 
36 typedef struct _GimpContextClass GimpContextClass;
37 
38 /**
39  * GimpContext:
40  *
41  * Holds state such as the active image, active display, active brush,
42  * active foreground and background color, and so on. There can many
43  * instances of contexts. The user context is what the user sees and
44  * interacts with but there can also be contexts for docks and for
45  * plug-ins.
46  */
47 struct _GimpContext
48 {
49   GimpViewable          parent_instance;
50 
51   Gimp                 *gimp;
52 
53   GimpContext          *parent;
54 
55   guint32               defined_props;
56   guint32               serialize_props;
57 
58   GimpImage            *image;
59   gpointer              display;
60 
61   GimpToolInfo         *tool_info;
62   gchar                *tool_name;
63 
64   GimpPaintInfo        *paint_info;
65   gchar                *paint_name;
66 
67   GimpRGB               foreground;
68   GimpRGB               background;
69 
70   gdouble               opacity;
71   GimpLayerMode         paint_mode;
72 
73   GimpBrush            *brush;
74   gchar                *brush_name;
75 
76   GimpDynamics         *dynamics;
77   gchar                *dynamics_name;
78 
79   GimpMybrush          *mybrush;
80   gchar                *mybrush_name;
81 
82   GimpPattern          *pattern;
83   gchar                *pattern_name;
84 
85   GimpGradient         *gradient;
86   gchar                *gradient_name;
87 
88   GimpPalette          *palette;
89   gchar                *palette_name;
90 
91   GimpFont             *font;
92   gchar                *font_name;
93 
94   GimpToolPreset       *tool_preset;
95   gchar                *tool_preset_name;
96 
97   GimpBuffer           *buffer;
98   gchar                *buffer_name;
99 
100   GimpImagefile        *imagefile;
101   gchar                *imagefile_name;
102 
103   GimpTemplate         *template;
104   gchar                *template_name;
105 };
106 
107 struct _GimpContextClass
108 {
109   GimpViewableClass  parent_class;
110 
111   void (* image_changed)      (GimpContext          *context,
112                                GimpImage            *image);
113   void (* display_changed)    (GimpContext          *context,
114                                gpointer              display);
115 
116   void (* tool_changed)       (GimpContext          *context,
117                                GimpToolInfo         *tool_info);
118   void (* paint_info_changed) (GimpContext          *context,
119                                GimpPaintInfo        *paint_info);
120 
121   void (* foreground_changed) (GimpContext          *context,
122                                GimpRGB              *color);
123   void (* background_changed) (GimpContext          *context,
124                                GimpRGB              *color);
125   void (* opacity_changed)    (GimpContext          *context,
126                                gdouble               opacity);
127   void (* paint_mode_changed) (GimpContext          *context,
128                                GimpLayerMode         paint_mode);
129   void (* brush_changed)      (GimpContext          *context,
130                                GimpBrush            *brush);
131   void (* dynamics_changed)   (GimpContext          *context,
132                                GimpDynamics         *dynamics);
133   void (* mybrush_changed)    (GimpContext          *context,
134                                GimpMybrush          *brush);
135   void (* pattern_changed)    (GimpContext          *context,
136                                GimpPattern          *pattern);
137   void (* gradient_changed)   (GimpContext          *context,
138                                GimpGradient         *gradient);
139   void (* palette_changed)    (GimpContext          *context,
140                                GimpPalette          *palette);
141   void (* font_changed)       (GimpContext          *context,
142                                GimpFont             *font);
143   void (* tool_preset_changed)(GimpContext          *context,
144                                GimpToolPreset       *tool_preset);
145   void (* buffer_changed)     (GimpContext          *context,
146                                GimpBuffer           *buffer);
147   void (* imagefile_changed)  (GimpContext          *context,
148                                GimpImagefile        *imagefile);
149   void (* template_changed)   (GimpContext          *context,
150                                GimpTemplate         *template);
151 
152   void (* prop_name_changed)  (GimpContext          *context,
153                                GimpContextPropType   prop);
154 };
155 
156 
157 GType         gimp_context_get_type          (void) G_GNUC_CONST;
158 
159 GimpContext * gimp_context_new               (Gimp                *gimp,
160                                               const gchar         *name,
161                                               GimpContext         *template);
162 
163 GimpContext * gimp_context_get_parent        (GimpContext         *context);
164 void          gimp_context_set_parent        (GimpContext         *context,
165                                               GimpContext         *parent);
166 
167 /*  define / undefinine context properties
168  *
169  *  the value of an undefined property will be taken from the parent context.
170  */
171 void          gimp_context_define_property   (GimpContext         *context,
172                                               GimpContextPropType  prop,
173                                               gboolean             defined);
174 
175 gboolean      gimp_context_property_defined  (GimpContext         *context,
176                                               GimpContextPropType  prop);
177 
178 void          gimp_context_define_properties (GimpContext         *context,
179                                               GimpContextPropMask  props_mask,
180                                               gboolean             defined);
181 
182 
183 /*  specify which context properties will be serialized
184  */
185 void   gimp_context_set_serialize_properties (GimpContext         *context,
186                                               GimpContextPropMask  props_mask);
187 
188 GimpContextPropMask
189        gimp_context_get_serialize_properties (GimpContext         *context);
190 
191 
192 /*  copying context properties
193  */
194 void          gimp_context_copy_property     (GimpContext         *src,
195                                               GimpContext         *dest,
196                                               GimpContextPropType  prop);
197 
198 void          gimp_context_copy_properties   (GimpContext         *src,
199                                               GimpContext         *dest,
200                                               GimpContextPropMask  props_mask);
201 
202 
203 /*  manipulate by GType  */
204 GimpContextPropType   gimp_context_type_to_property    (GType     type);
205 const gchar         * gimp_context_type_to_prop_name   (GType     type);
206 const gchar         * gimp_context_type_to_signal_name (GType     type);
207 
208 GimpObject     * gimp_context_get_by_type         (GimpContext     *context,
209                                                    GType            type);
210 void             gimp_context_set_by_type         (GimpContext     *context,
211                                                    GType            type,
212                                                    GimpObject      *object);
213 void             gimp_context_changed_by_type     (GimpContext     *context,
214                                                    GType            type);
215 
216 
217 /*  image  */
218 GimpImage      * gimp_context_get_image           (GimpContext     *context);
219 void             gimp_context_set_image           (GimpContext     *context,
220                                                    GimpImage       *image);
221 void             gimp_context_image_changed       (GimpContext     *context);
222 
223 
224 /*  display  */
225 gpointer         gimp_context_get_display         (GimpContext     *context);
226 void             gimp_context_set_display         (GimpContext     *context,
227                                                    gpointer         display);
228 void             gimp_context_display_changed     (GimpContext     *context);
229 
230 
231 /*  tool  */
232 GimpToolInfo   * gimp_context_get_tool            (GimpContext     *context);
233 void             gimp_context_set_tool            (GimpContext     *context,
234                                                    GimpToolInfo    *tool_info);
235 void             gimp_context_tool_changed        (GimpContext     *context);
236 
237 
238 /*  paint info  */
239 GimpPaintInfo  * gimp_context_get_paint_info      (GimpContext     *context);
240 void             gimp_context_set_paint_info      (GimpContext     *context,
241                                                    GimpPaintInfo   *paint_info);
242 void             gimp_context_paint_info_changed  (GimpContext     *context);
243 
244 
245 /*  foreground color  */
246 void             gimp_context_get_foreground       (GimpContext     *context,
247                                                     GimpRGB         *color);
248 void             gimp_context_set_foreground       (GimpContext     *context,
249                                                     const GimpRGB   *color);
250 void             gimp_context_foreground_changed   (GimpContext     *context);
251 
252 
253 /*  background color  */
254 void             gimp_context_get_background       (GimpContext     *context,
255                                                     GimpRGB         *color);
256 void             gimp_context_set_background       (GimpContext     *context,
257                                                     const GimpRGB   *color);
258 void             gimp_context_background_changed   (GimpContext     *context);
259 
260 
261 /*  color utility functions  */
262 void             gimp_context_set_default_colors  (GimpContext     *context);
263 void             gimp_context_swap_colors         (GimpContext     *context);
264 
265 
266 /*  opacity  */
267 gdouble          gimp_context_get_opacity         (GimpContext     *context);
268 void             gimp_context_set_opacity         (GimpContext     *context,
269                                                    gdouble          opacity);
270 void             gimp_context_opacity_changed     (GimpContext     *context);
271 
272 
273 /*  paint mode  */
274 GimpLayerMode    gimp_context_get_paint_mode      (GimpContext     *context);
275 void             gimp_context_set_paint_mode      (GimpContext     *context,
276                                                    GimpLayerMode    paint_mode);
277 void             gimp_context_paint_mode_changed  (GimpContext     *context);
278 
279 
280 /*  brush  */
281 GimpBrush      * gimp_context_get_brush           (GimpContext     *context);
282 void             gimp_context_set_brush           (GimpContext     *context,
283                                                    GimpBrush       *brush);
284 void             gimp_context_brush_changed       (GimpContext     *context);
285 
286 
287 /*  dynamics  */
288 GimpDynamics   * gimp_context_get_dynamics        (GimpContext     *context);
289 void             gimp_context_set_dynamics        (GimpContext     *context,
290                                                    GimpDynamics    *dynamics);
291 void             gimp_context_dynamics_changed    (GimpContext     *context);
292 
293 
294 /*  mybrush  */
295 GimpMybrush    * gimp_context_get_mybrush         (GimpContext     *context);
296 void             gimp_context_set_mybrush         (GimpContext     *context,
297                                                    GimpMybrush     *brush);
298 void             gimp_context_mybrush_changed     (GimpContext     *context);
299 
300 
301 /*  pattern  */
302 GimpPattern    * gimp_context_get_pattern         (GimpContext     *context);
303 void             gimp_context_set_pattern         (GimpContext     *context,
304                                                    GimpPattern     *pattern);
305 void             gimp_context_pattern_changed     (GimpContext     *context);
306 
307 
308 /*  gradient  */
309 GimpGradient   * gimp_context_get_gradient        (GimpContext     *context);
310 void             gimp_context_set_gradient        (GimpContext     *context,
311                                                    GimpGradient    *gradient);
312 void             gimp_context_gradient_changed    (GimpContext     *context);
313 
314 
315 /*  palette  */
316 GimpPalette    * gimp_context_get_palette         (GimpContext     *context);
317 void             gimp_context_set_palette         (GimpContext     *context,
318                                                    GimpPalette     *palette);
319 void             gimp_context_palette_changed     (GimpContext     *context);
320 
321 
322 /*  font  */
323 GimpFont       * gimp_context_get_font            (GimpContext     *context);
324 void             gimp_context_set_font            (GimpContext     *context,
325                                                    GimpFont        *font);
326 const gchar    * gimp_context_get_font_name       (GimpContext     *context);
327 void             gimp_context_set_font_name       (GimpContext     *context,
328                                                    const gchar     *name);
329 void             gimp_context_font_changed        (GimpContext     *context);
330 
331 
332 /*  tool_preset  */
333 GimpToolPreset * gimp_context_get_tool_preset     (GimpContext     *context);
334 void             gimp_context_set_tool_preset     (GimpContext     *context,
335                                                    GimpToolPreset  *tool_preset);
336 void             gimp_context_tool_preset_changed (GimpContext     *context);
337 
338 
339 /*  buffer  */
340 GimpBuffer     * gimp_context_get_buffer          (GimpContext     *context);
341 void             gimp_context_set_buffer          (GimpContext     *context,
342                                                    GimpBuffer      *palette);
343 void             gimp_context_buffer_changed      (GimpContext     *context);
344 
345 
346 /*  imagefile  */
347 GimpImagefile  * gimp_context_get_imagefile       (GimpContext     *context);
348 void             gimp_context_set_imagefile       (GimpContext     *context,
349                                                    GimpImagefile   *imagefile);
350 void             gimp_context_imagefile_changed   (GimpContext     *context);
351 
352 
353 /*  template  */
354 GimpTemplate   * gimp_context_get_template        (GimpContext     *context);
355 void             gimp_context_set_template        (GimpContext     *context,
356                                                    GimpTemplate    *template);
357 void             gimp_context_template_changed    (GimpContext     *context);
358 
359 
360 #endif /* __GIMP_CONTEXT_H__ */
361