1 /*
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * This is a plug-in for GIMP.
5  *
6  * Generates images containing vector type drawings.
7  *
8  * Copyright (C) 1997 Andy Thomas  alt@picnic.demon.co.uk
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
22  *
23  */
24 
25 #ifndef __GFIG_H__
26 #define __GFIG_H__
27 
28 #include "gfig-types.h"
29 #include "gfig-style.h"
30 
31 #define MAX_UNDO         10
32 #define MIN_UNDO         1
33 
34 typedef struct
35 {
36   gint     gridspacing;
37   GridType gridtype;
38   gboolean drawgrid;
39   gboolean snap2grid;
40   gboolean lockongrid;
41   gboolean showcontrol;
42   gdouble grid_radius_min;
43   gdouble grid_radius_interval;
44   gdouble grid_rotation;
45   gdouble grid_granularity;
46   gint grid_sectors_desired;
47 } GfigOpts;
48 
49 typedef struct
50 {
51   SelectionType type;           /* ADD etc .. */
52   gint          antia;          /* Boolean for Antia */
53   gint          feather;        /* Feather it ? */
54   gdouble       feather_radius; /* Radius to feather */
55   ArcType       as_pie;         /* Arc type selection segment/sector */
56   FillType      fill_type;      /* Fill type for selection */
57   gdouble       fill_opacity;   /* You can guess this one */
58 } selection_option;
59 
60 void       object_start            (GdkPoint *pnt, gint);
61 void       object_operation        (GdkPoint *pnt, gint);
62 void       object_operation_start  (GdkPoint *pnt, gint shift_down);
63 void       object_operation_end    (GdkPoint *pnt, gint);
64 void       object_end              (GdkPoint *pnt, gint shift_down);
65 
66 #define MAX_LOAD_LINE    256
67 #define SQ_SIZE 8
68 
69 #define PLUG_IN_PROC   "plug-in-gfig"
70 #define PLUG_IN_BINARY "gfig"
71 #define PLUG_IN_ROLE   "gimp-gfig"
72 
73 extern gint       line_no;
74 extern gint       preview_width, preview_height;
75 extern gint       need_to_scale;
76 extern gdouble    scale_x_factor, scale_y_factor;
77 extern GdkPixbuf *back_pixbuf;
78 
79 extern GtkWidget    *pic_preview;
80 extern gint          obj_show_single;
81 
82 typedef struct
83 {
84   GfigOpts      opts;
85   gboolean      showimage;
86   gint          maxundo;
87   gboolean      showpos;
88   gdouble       brushfade;
89   gdouble       brushgradient;
90   gdouble       airbrushpressure;
91   DrawonLayers  onlayers;
92   LayersBGType  onlayerbg;
93   PaintType     painttype;
94   gboolean      reverselines;
95   gboolean      scaletoimage;
96   gdouble       scaletoimagefp;
97   BrushType     brshtype;
98   DobjType      otype;
99 } SelectItVals;
100 
101 struct _GFigObj
102 {
103   gchar     *name;        /* Trailing name of file  */
104   gchar     *filename;    /* Filename itself */
105   gchar     *draw_name;   /* Name of the drawing */
106   gfloat     version;     /* Version number of data file */
107   GfigOpts   opts;        /* Options enforced when fig saved */
108   GList     *obj_list;    /* Objects that make up this list */
109   gint       obj_status;  /* See above for possible values */
110   GtkWidget *list_item;
111   GtkWidget *label_widget;
112   GtkWidget *pixmap_widget;
113 };
114 
115 /* this is temp, should be able to get rid of */
116 typedef struct BrushDesc
117 {
118   gchar         *name;
119   gdouble        opacity;
120   gint           spacing;
121   GimpLayerMode  paint_mode;
122   gint           width;
123   gint           height;
124   guchar        *pv_buf;  /* Buffer where brush placed */
125   gint16         x_off;
126   gint16         y_off;
127   const gchar   *popup;
128 } BrushDesc;
129 
130 typedef struct
131 {
132   gboolean     debug_styles;
133   gboolean     show_background;  /* show thumbnail of image behind figure */
134   gint32       image_id;         /* Gimp image id */
135   gint32       drawable_id;      /* Gimp drawable to paint on */
136   GFigObj     *current_obj;
137   GfigObject  *selected_obj;
138   GtkWidget   *preview;
139   Style        default_style;
140   BrushDesc    bdesc;
141   GtkWidget   *fg_color_button;
142   GtkWidget   *bg_color_button;
143   GtkWidget   *brush_select;
144   GtkWidget   *pattern_select;
145   GtkWidget   *gradient_select;
146   GtkWidget   *fillstyle_combo;
147   GtkWidget   *paint_type_toggle;
148   GimpRGB     *fg_color;
149   GimpRGB     *bg_color;
150   gboolean     enable_repaint;
151   gboolean     using_new_layer;
152 } GFigContext;
153 
154 extern GFigContext *gfig_context;
155 
156 extern selection_option selopt;
157 extern SelectItVals selvals;
158 
159 void       add_to_all_obj          (GFigObj    *fobj,
160                                     GfigObject *obj);
161 
162 gchar *get_line (gchar *buf,
163                  gint   s,
164                  FILE  *from,
165                  gint   init);
166 
167 gint            gfig_scale_x    (gint      x);
168 gint            gfig_scale_y    (gint      y);
169 void            scale_to_xy     (gdouble *list,
170                                  gint     size);
171 void            scale_to_original_xy (gdouble *list,
172                                       gint     size);
173 
174 void gfig_paint (BrushType brush_type,
175                  gint32    drawable_ID,
176                  gint      seg_count,
177                  gdouble   line_pnts[]);
178 
179 void draw_item   (cairo_t *cr,
180                   gboolean fill);
181 void draw_circle (GdkPoint *p,
182                   gboolean  selected,
183                   cairo_t  *cr);
184 void draw_sqr    (GdkPoint *p,
185                   gboolean  selected,
186                   cairo_t  *cr);
187 
188 void       list_button_update   (GFigObj *obj);
189 
190 GtkWidget *num_sides_widget     (const gchar *d_title,
191                                  gint        *num_sides,
192                                  gint        *which_way,
193                                  gint         adj_min,
194                                  gint         adj_max);
195 
196 void    setup_undo              (void);
197 void    draw_grid_clear         (void);
198 void    prepend_to_all_obj      (GFigObj *fobj,
199                                  GList   *nobj);
200 
201 void    gfig_draw_arc           (gint x,
202                                  gint y,
203                                  gint width,
204                                  gint height,
205                                  gint angle1,
206                                  gint angle2,
207                                  cairo_t *cr);
208 
209 void    gfig_draw_line          (gint x0,
210                                  gint y0,
211                                  gint x1,
212                                  gint y1,
213                                  cairo_t *cr);
214 
215 void      gfig_paint_callback   (void);
216 GFigObj  *gfig_load             (const gchar *filename,
217                                  const gchar *name);
218 void   gfig_name_encode         (gchar *dest,
219                                  gchar *src);
220 void   gfig_name_decode         (gchar       *dest,
221                                  const gchar *src);
222 
223 gint   gfig_list_pos            (GFigObj *gfig);
224 gint   gfig_list_insert         (GFigObj *gfig);
225 void   gfig_free                (GFigObj *gfig);
226 
227 void   save_options             (GString *string);
228 
229 GString   *gfig_save_as_string     (void);
230 gboolean   gfig_save_as_parasite   (void);
231 GFigObj   *gfig_load_from_parasite (void);
232 GFigObj   *gfig_new                (void);
233 void       gfig_save_callbk        (void);
234 void       paint_layer_fill        (gdouble x1,
235                                     gdouble y1,
236                                     gdouble x2,
237                                     gdouble y2);
238 
239 
240 
241 extern GtkWidget    *top_level_dlg;
242 extern GList        *gfig_list;
243 extern gdouble       org_scale_x_factor, org_scale_y_factor;
244 
245 #endif /* __GFIG_H__ */
246