1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * Gradient editor module copyight (C) 1996-1997 Federico Mena Quintero
5  * federico@nuclecu.unam.mx
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_GRADIENT_EDITOR_H__
22 #define __GIMP_GRADIENT_EDITOR_H__
23 
24 
25 #include "gimpdataeditor.h"
26 
27 
28 #define GRAD_NUM_COLORS 10
29 
30 
31 typedef enum
32 {
33   GRAD_DRAG_NONE = 0,
34   GRAD_DRAG_LEFT,
35   GRAD_DRAG_MIDDLE,
36   GRAD_DRAG_ALL
37 } GradientEditorDragMode;
38 
39 
40 #define GIMP_TYPE_GRADIENT_EDITOR            (gimp_gradient_editor_get_type ())
41 #define GIMP_GRADIENT_EDITOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_GRADIENT_EDITOR, GimpGradientEditor))
42 #define GIMP_GRADIENT_EDITOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_GRADIENT_EDITOR, GimpGradientEditorClass))
43 #define GIMP_IS_GRADIENT_EDITOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_GRADIENT_EDITOR))
44 #define GIMP_IS_GRADIENT_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_GRADIENT_EDITOR))
45 #define GIMP_GRADIENT_EDITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_GRADIENT_EDITOR, GimpGradientEditorClass))
46 
47 
48 typedef struct _GimpGradientEditorClass GimpGradientEditorClass;
49 
50 struct _GimpGradientEditor
51 {
52   GimpDataEditor          parent_instance;
53 
54   GtkWidget              *current_color;
55   GtkWidget              *hint_label1;
56   GtkWidget              *hint_label2;
57   GtkWidget              *hint_label3;
58   GtkWidget              *hint_label4;
59   GtkWidget              *scrollbar;
60   GtkWidget              *control;
61 
62   /*  Zoom and scrollbar  */
63   guint                   zoom_factor;
64   GtkAdjustment          *scroll_data;
65 
66   /*  Gradient view  */
67   gint                    view_last_x;
68   gboolean                view_button_down;
69 
70   /*  Gradient control  */
71   GimpGradientSegment    *control_drag_segment; /* Segment which is being dragged */
72   GimpGradientSegment    *control_sel_l;        /* Left segment of selection */
73   GimpGradientSegment    *control_sel_r;        /* Right segment of selection */
74   GradientEditorDragMode  control_drag_mode;    /* What is being dragged? */
75   guint32                 control_click_time;   /* Time when mouse was pressed */
76   gboolean                control_compress;     /* Compressing/expanding handles */
77   gint                    control_last_x;       /* Last mouse position when dragging */
78   gdouble                 control_last_gx;      /* Last position (wrt gradient) when dragging */
79   gdouble                 control_orig_pos;     /* Original click position when dragging */
80 
81   GimpGradientBlendColorSpace  blend_color_space;
82 
83   /*  Saved colors  */
84   GimpRGB                 saved_colors[GRAD_NUM_COLORS];
85 
86   /*  Color dialog  */
87   GtkWidget              *color_dialog;
88   GimpGradientSegment    *saved_segments;
89   gboolean                saved_dirty;
90 };
91 
92 struct _GimpGradientEditorClass
93 {
94   GimpDataEditorClass  parent_class;
95 };
96 
97 
98 GType       gimp_gradient_editor_get_type         (void) G_GNUC_CONST;
99 
100 GtkWidget * gimp_gradient_editor_new              (GimpContext          *context,
101                                                    GimpMenuFactory      *menu_factory);
102 
103 void        gimp_gradient_editor_get_selection    (GimpGradientEditor   *editor,
104                                                    GimpGradient        **gradient,
105                                                    GimpGradientSegment **left,
106                                                    GimpGradientSegment **right);
107 void        gimp_gradient_editor_set_selection    (GimpGradientEditor   *editor,
108                                                    GimpGradientSegment  *left,
109                                                    GimpGradientSegment  *right);
110 
111 void        gimp_gradient_editor_edit_left_color  (GimpGradientEditor   *editor);
112 void        gimp_gradient_editor_edit_right_color (GimpGradientEditor   *editor);
113 
114 void        gimp_gradient_editor_zoom             (GimpGradientEditor   *editor,
115                                                    GimpZoomType          zoom_type);
116 
117 
118 #endif  /* __GIMP_GRADIENT_EDITOR_H__ */
119