1 /* GIMP - The GNU Image Manipulation Program 2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis 3 * 4 * gimpvectors.h 5 * Copyright (C) 2002 Simon Budig <simon@gimp.org> 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_VECTORS_H__ 22 #define __GIMP_VECTORS_H__ 23 24 #include "core/gimpitem.h" 25 26 #define GIMP_TYPE_VECTORS (gimp_vectors_get_type ()) 27 #define GIMP_VECTORS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_VECTORS, GimpVectors)) 28 #define GIMP_VECTORS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_VECTORS, GimpVectorsClass)) 29 #define GIMP_IS_VECTORS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_VECTORS)) 30 #define GIMP_IS_VECTORS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_VECTORS)) 31 #define GIMP_VECTORS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_VECTORS, GimpVectorsClass)) 32 33 34 typedef struct _GimpVectorsClass GimpVectorsClass; 35 36 struct _GimpVectors 37 { 38 GimpItem parent_instance; 39 40 GQueue *strokes; /* Queue of GimpStrokes */ 41 GHashTable *stroke_to_list; /* Map from GimpStroke to strokes listnode */ 42 gint last_stroke_ID; 43 44 gint freeze_count; 45 gdouble precision; 46 47 GimpBezierDesc *bezier_desc; /* Cached bezier representation */ 48 49 gboolean bounds_valid; /* Cached bounding box */ 50 gboolean bounds_empty; 51 gdouble bounds_x1; 52 gdouble bounds_y1; 53 gdouble bounds_x2; 54 gdouble bounds_y2; 55 }; 56 57 struct _GimpVectorsClass 58 { 59 GimpItemClass parent_class; 60 61 /* signals */ 62 void (* freeze) (GimpVectors *vectors); 63 void (* thaw) (GimpVectors *vectors); 64 65 /* virtual functions */ 66 void (* stroke_add) (GimpVectors *vectors, 67 GimpStroke *stroke); 68 void (* stroke_remove) (GimpVectors *vectors, 69 GimpStroke *stroke); 70 GimpStroke * (* stroke_get) (GimpVectors *vectors, 71 const GimpCoords *coord); 72 GimpStroke * (* stroke_get_next) (GimpVectors *vectors, 73 GimpStroke *prev); 74 gdouble (* stroke_get_length) (GimpVectors *vectors, 75 GimpStroke *stroke); 76 GimpAnchor * (* anchor_get) (GimpVectors *vectors, 77 const GimpCoords *coord, 78 GimpStroke **ret_stroke); 79 void (* anchor_delete) (GimpVectors *vectors, 80 GimpAnchor *anchor); 81 gdouble (* get_length) (GimpVectors *vectors, 82 const GimpAnchor *start); 83 gdouble (* get_distance) (GimpVectors *vectors, 84 const GimpCoords *coord); 85 gint (* interpolate) (GimpVectors *vectors, 86 GimpStroke *stroke, 87 gdouble precision, 88 gint max_points, 89 GimpCoords *ret_coords); 90 GimpBezierDesc * (* make_bezier) (GimpVectors *vectors); 91 }; 92 93 94 /* vectors utility functions */ 95 96 GType gimp_vectors_get_type (void) G_GNUC_CONST; 97 98 GimpVectors * gimp_vectors_new (GimpImage *image, 99 const gchar *name); 100 101 GimpVectors * gimp_vectors_get_parent (GimpVectors *vectors); 102 103 void gimp_vectors_freeze (GimpVectors *vectors); 104 void gimp_vectors_thaw (GimpVectors *vectors); 105 106 void gimp_vectors_copy_strokes (GimpVectors *src_vectors, 107 GimpVectors *dest_vectors); 108 void gimp_vectors_add_strokes (GimpVectors *src_vectors, 109 GimpVectors *dest_vectors); 110 111 112 /* accessing / modifying the anchors */ 113 114 GimpAnchor * gimp_vectors_anchor_get (GimpVectors *vectors, 115 const GimpCoords *coord, 116 GimpStroke **ret_stroke); 117 118 /* prev == NULL: "first" anchor */ 119 GimpAnchor * gimp_vectors_anchor_get_next (GimpVectors *vectors, 120 const GimpAnchor *prev); 121 122 /* type will be an xorable enum: 123 * VECTORS_NONE, VECTORS_FIX_ANGLE, VECTORS_FIX_RATIO, VECTORS_RESTRICT_ANGLE 124 * or so. 125 */ 126 void gimp_vectors_anchor_move_relative (GimpVectors *vectors, 127 GimpAnchor *anchor, 128 const GimpCoords *deltacoord, 129 gint type); 130 void gimp_vectors_anchor_move_absolute (GimpVectors *vectors, 131 GimpAnchor *anchor, 132 const GimpCoords *coord, 133 gint type); 134 135 void gimp_vectors_anchor_delete (GimpVectors *vectors, 136 GimpAnchor *anchor); 137 138 void gimp_vectors_anchor_select (GimpVectors *vectors, 139 GimpStroke *target_stroke, 140 GimpAnchor *anchor, 141 gboolean selected, 142 gboolean exclusive); 143 144 145 /* GimpStroke is a connected component of a GimpVectors object */ 146 147 void gimp_vectors_stroke_add (GimpVectors *vectors, 148 GimpStroke *stroke); 149 void gimp_vectors_stroke_remove (GimpVectors *vectors, 150 GimpStroke *stroke); 151 gint gimp_vectors_get_n_strokes (GimpVectors *vectors); 152 GimpStroke * gimp_vectors_stroke_get (GimpVectors *vectors, 153 const GimpCoords *coord); 154 GimpStroke * gimp_vectors_stroke_get_by_ID (GimpVectors *vectors, 155 gint id); 156 157 /* prev == NULL: "first" stroke */ 158 GimpStroke * gimp_vectors_stroke_get_next (GimpVectors *vectors, 159 GimpStroke *prev); 160 gdouble gimp_vectors_stroke_get_length (GimpVectors *vectors, 161 GimpStroke *stroke); 162 163 /* accessing the shape of the curve */ 164 165 gdouble gimp_vectors_get_length (GimpVectors *vectors, 166 const GimpAnchor *start); 167 gdouble gimp_vectors_get_distance (GimpVectors *vectors, 168 const GimpCoords *coord); 169 170 /* returns the number of valid coordinates */ 171 172 gint gimp_vectors_interpolate (GimpVectors *vectors, 173 GimpStroke *stroke, 174 gdouble precision, 175 gint max_points, 176 GimpCoords *ret_coords); 177 178 /* usually overloaded */ 179 180 /* returns a bezier representation */ 181 const GimpBezierDesc * gimp_vectors_get_bezier (GimpVectors *vectors); 182 183 184 #endif /* __GIMP_VECTORS_H__ */ 185