2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2009 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/gpencil/gpencil_intern.h
31 #ifndef __GPENCIL_INTERN_H__
32 #define __GPENCIL_INTERN_H__
35 #include "DNA_vec_types.h"
38 /* internal exports only */
45 struct wmOperatorType;
49 struct EnumPropertyItem;
52 /* ***************************************************** */
55 /* Stroke Coordinates API ------------------------------ */
58 typedef struct GP_SpaceConversion {
60 struct bGPDlayer *gpl;
66 rctf *subrect; /* for using the camera rect within the 3d view */
69 float mat[4][4]; /* transform matrix on the strokes (introduced in [b770964]) */
74 * Check whether a given stroke segment is inside a circular brush
76 * \param mval The current screen-space coordinates (midpoint) of the brush
77 * \param mvalo The previous screen-space coordinates (midpoint) of the brush (NOT CURRENTLY USED)
78 * \param rad The radius of the brush
80 * \param x0, y0 The screen-space x and y coordinates of the start of the stroke segment
81 * \param x1, y1 The screen-space x and y coordinates of the end of the stroke segment
83 bool gp_stroke_inside_circle(const int mval[2], const int UNUSED(mvalo[2]),
84 int rad, int x0, int y0, int x1, int y1);
88 * Init settings for stroke point space conversions
90 * \param[out] r_gsc The space conversion settings struct, populated with necessary params
92 void gp_point_conversion_init(struct bContext *C, GP_SpaceConversion *r_gsc);
95 * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D)
97 * \param[out] r_x The screen-space x-coordinate of the point
98 * \param[out] r_y The screen-space y-coordinate of the point
100 void gp_point_to_xy(GP_SpaceConversion *settings, struct bGPDstroke *gps, struct bGPDspoint *pt,
104 * Convert a Grease Pencil coordinate (i.e. can be 2D or 3D) to screenspace (2D)
106 * Just like gp_point_to_xy(), except the resulting coordinates are floats not ints.
107 * Use this version to solve "stair-step" artifacts which may arise when roundtripping the calculations.
109 * \param[out] r_x The screen-space x-coordinate of the point
110 * \param[out] r_y The screen-space y-coordinate of the point
112 void gp_point_to_xy_fl(GP_SpaceConversion *gsc, bGPDstroke *gps, bGPDspoint *pt,
113 float *r_x, float *r_y);
116 * Convert point to parent space
118 * \param pt Original point
119 * \param diff_mat Matrix with the difference between original parent matrix
120 * \param[out] r_pt Pointer to new point after apply matrix
122 void gp_point_to_parent_space(bGPDspoint *pt, float diff_mat[4][4], bGPDspoint *r_pt);
124 * Change points position relative to parent object
126 void gp_apply_parent(bGPDlayer *gpl, bGPDstroke *gps);
128 * Change point position relative to parent object
130 void gp_apply_parent_point(bGPDlayer *gpl, bGPDspoint *pt);
133 * Convert a screenspace point to a 3D Grease Pencil coordinate.
135 * For use with editing tools where it is easier to perform the operations in 2D,
136 * and then later convert the transformed points back to 3D.
138 * \param screeN_co The screenspace 2D coordinates to convert to
139 * \param[out] r_out The resulting 3D coordinates of the input point
141 bool gp_point_xy_to_3d(GP_SpaceConversion *gsc, struct Scene *scene, const float screen_co[2], float r_out[3]);
143 /* Poll Callbacks ------------------------------------ */
144 /* gpencil_utils.c */
146 int gp_add_poll(struct bContext *C);
147 int gp_active_layer_poll(struct bContext *C);
148 int gp_active_brush_poll(struct bContext *C);
149 int gp_active_palette_poll(struct bContext *C);
150 int gp_active_palettecolor_poll(struct bContext *C);
151 int gp_brush_crt_presets_poll(bContext *C);
153 /* Copy/Paste Buffer --------------------------------- */
156 extern ListBase gp_strokes_copypastebuf;
158 /* Stroke Editing ------------------------------------ */
160 void gp_stroke_delete_tagged_points(bGPDframe *gpf, bGPDstroke *gps, bGPDstroke *next_stroke, int tag_flags);
164 * Apply smooth to stroke point
165 * \param gps Stroke to smooth
166 * \param i Point index
167 * \param inf Amount of smoothing to apply
168 * \param affect_pressure Apply smoothing to pressure values too?
170 bool gp_smooth_stroke(bGPDstroke *gps, int i, float inf, bool affect_pressure);
173 * Apply smooth for strength to stroke point
174 * \param gps Stroke to smooth
175 * \param i Point index
176 * \param inf Amount of smoothing to apply
178 bool gp_smooth_stroke_strength(bGPDstroke *gps, int i, float inf);
181 * Apply smooth for thickness to stroke point (use pressure)
182 * \param gps Stroke to smooth
183 * \param i Point index
184 * \param inf Amount of smoothing to apply
186 bool gp_smooth_stroke_thickness(bGPDstroke *gps, int i, float inf);
189 * Subdivide a stroke once, by adding points at the midpoint between each pair of points
190 * \param gps Stroke data
191 * \param new_totpoints Total number of points (after subdividing)
193 void gp_subdivide_stroke(bGPDstroke *gps, const int new_totpoints);
196 * Add randomness to stroke
197 * \param gps Stroke data
198 * \param brush Brush data
200 void gp_randomize_stroke(bGPDstroke *gps, bGPDbrush *brush);
202 /* Layers Enums -------------------------------------- */
204 struct EnumPropertyItem *ED_gpencil_layers_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
205 struct EnumPropertyItem *ED_gpencil_layers_with_new_enum_itemf(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
207 /* Enums of GP Brushes */
208 EnumPropertyItem *ED_gpencil_brushes_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
211 /* Enums of GP palettes */
212 EnumPropertyItem *ED_gpencil_palettes_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop),
215 /* ***************************************************** */
216 /* Operator Defines */
218 /* drawing ---------- */
220 void GPENCIL_OT_draw(struct wmOperatorType *ot);
222 /* Paint Modes for operator */
223 typedef enum eGPencil_PaintModes {
224 GP_PAINTMODE_DRAW = 0,
226 GP_PAINTMODE_DRAW_STRAIGHT,
227 GP_PAINTMODE_DRAW_POLY
228 } eGPencil_PaintModes;
230 /* maximum sizes of gp-session buffer */
231 #define GP_STROKE_BUFFER_MAX 5000
233 /* stroke editing ----- */
235 void GPENCIL_OT_editmode_toggle(struct wmOperatorType *ot);
236 void GPENCIL_OT_selection_opacity_toggle(struct wmOperatorType *ot);
238 void GPENCIL_OT_select(struct wmOperatorType *ot);
239 void GPENCIL_OT_select_all(struct wmOperatorType *ot);
240 void GPENCIL_OT_select_circle(struct wmOperatorType *ot);
241 void GPENCIL_OT_select_border(struct wmOperatorType *ot);
242 void GPENCIL_OT_select_lasso(struct wmOperatorType *ot);
244 void GPENCIL_OT_select_linked(struct wmOperatorType *ot);
245 void GPENCIL_OT_select_grouped(struct wmOperatorType *ot);
246 void GPENCIL_OT_select_more(struct wmOperatorType *ot);
247 void GPENCIL_OT_select_less(struct wmOperatorType *ot);
248 void GPENCIL_OT_select_first(struct wmOperatorType *ot);
249 void GPENCIL_OT_select_last(struct wmOperatorType *ot);
251 void GPENCIL_OT_duplicate(struct wmOperatorType *ot);
252 void GPENCIL_OT_delete(struct wmOperatorType *ot);
253 void GPENCIL_OT_dissolve(struct wmOperatorType *ot);
254 void GPENCIL_OT_copy(struct wmOperatorType *ot);
255 void GPENCIL_OT_paste(struct wmOperatorType *ot);
257 void GPENCIL_OT_move_to_layer(struct wmOperatorType *ot);
258 void GPENCIL_OT_layer_change(struct wmOperatorType *ot);
260 void GPENCIL_OT_snap_to_grid(struct wmOperatorType *ot);
261 void GPENCIL_OT_snap_to_cursor(struct wmOperatorType *ot);
262 void GPENCIL_OT_snap_cursor_to_selected(struct wmOperatorType *ot);
263 void GPENCIL_OT_snap_cursor_to_center(struct wmOperatorType *ot);
265 void GPENCIL_OT_reproject(struct wmOperatorType *ot);
267 /* stroke sculpting -- */
269 void GPENCIL_OT_brush_paint(struct wmOperatorType *ot);
271 /* buttons editing --- */
273 void GPENCIL_OT_data_add(struct wmOperatorType *ot);
274 void GPENCIL_OT_data_unlink(struct wmOperatorType *ot);
276 void GPENCIL_OT_layer_add(struct wmOperatorType *ot);
277 void GPENCIL_OT_layer_remove(struct wmOperatorType *ot);
278 void GPENCIL_OT_layer_move(struct wmOperatorType *ot);
279 void GPENCIL_OT_layer_duplicate(struct wmOperatorType *ot);
281 void GPENCIL_OT_hide(struct wmOperatorType *ot);
282 void GPENCIL_OT_reveal(struct wmOperatorType *ot);
284 void GPENCIL_OT_lock_all(struct wmOperatorType *ot);
285 void GPENCIL_OT_unlock_all(struct wmOperatorType *ot);
287 void GPENCIL_OT_layer_isolate(struct wmOperatorType *ot);
288 void GPENCIL_OT_layer_merge(struct wmOperatorType *ot);
290 void GPENCIL_OT_active_frame_delete(struct wmOperatorType *ot);
291 void GPENCIL_OT_active_frames_delete_all(struct wmOperatorType *ot);
293 void GPENCIL_OT_convert(struct wmOperatorType *ot);
297 GP_STROKE_JOINCOPY = 1
300 void GPENCIL_OT_stroke_arrange(struct wmOperatorType *ot);
301 void GPENCIL_OT_stroke_change_color(struct wmOperatorType *ot);
302 void GPENCIL_OT_stroke_lock_color(struct wmOperatorType *ot);
303 void GPENCIL_OT_stroke_apply_thickness(struct wmOperatorType *ot);
304 void GPENCIL_OT_stroke_cyclical_set(struct wmOperatorType *ot);
305 void GPENCIL_OT_stroke_join(struct wmOperatorType *ot);
306 void GPENCIL_OT_stroke_flip(struct wmOperatorType *ot);
308 void GPENCIL_OT_brush_add(struct wmOperatorType *ot);
309 void GPENCIL_OT_brush_remove(struct wmOperatorType *ot);
310 void GPENCIL_OT_brush_change(struct wmOperatorType *ot);
311 void GPENCIL_OT_brush_move(struct wmOperatorType *ot);
312 void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
313 void GPENCIL_OT_brush_copy(struct wmOperatorType *ot);
314 void GPENCIL_OT_brush_select(struct wmOperatorType *ot);
316 void GPENCIL_OT_palette_add(struct wmOperatorType *ot);
317 void GPENCIL_OT_palette_remove(struct wmOperatorType *ot);
318 void GPENCIL_OT_palette_change(struct wmOperatorType *ot);
319 void GPENCIL_OT_palette_lock_layer(struct wmOperatorType *ot);
321 void GPENCIL_OT_palettecolor_add(struct wmOperatorType *ot);
322 void GPENCIL_OT_palettecolor_remove(struct wmOperatorType *ot);
323 void GPENCIL_OT_palettecolor_isolate(struct wmOperatorType *ot);
324 void GPENCIL_OT_palettecolor_hide(struct wmOperatorType *ot);
325 void GPENCIL_OT_palettecolor_reveal(struct wmOperatorType *ot);
326 void GPENCIL_OT_palettecolor_lock_all(struct wmOperatorType *ot);
327 void GPENCIL_OT_palettecolor_unlock_all(struct wmOperatorType *ot);
328 void GPENCIL_OT_palettecolor_move(struct wmOperatorType *ot);
329 void GPENCIL_OT_palettecolor_select(struct wmOperatorType *ot);
330 void GPENCIL_OT_palettecolor_copy(struct wmOperatorType *ot);
332 /* undo stack ---------- */
334 void gpencil_undo_init(struct bGPdata *gpd);
335 void gpencil_undo_push(struct bGPdata *gpd);
336 void gpencil_undo_finish(void);
338 /* interpolation ---------- */
340 void GPENCIL_OT_interpolate(struct wmOperatorType *ot);
341 void GPENCIL_OT_interpolate_sequence(struct wmOperatorType *ot);
343 /* ****************************************************** */
344 /* FILTERED ACTION DATA - TYPES ---> XXX DEPRECEATED OLD ANIM SYSTEM CODE! */
346 /* XXX - TODO: replace this with the modern bAnimListElem... */
347 /* This struct defines a structure used for quick access */
348 typedef struct bActListElem {
349 struct bActListElem *next, *prev;
351 void *data; /* source data this elem represents */
352 int type; /* one of the ACTTYPE_* values */
353 int flag; /* copy of elem's flags for quick access */
354 int index; /* copy of adrcode where applicable */
356 void *key_data; /* motion data - ipo or ipo-curve */
357 short datatype; /* type of motion data to expect */
359 struct bActionGroup *grp; /* action group that owns the channel */
361 void *owner; /* will either be an action channel or fake ipo-channel (for keys) */
362 short ownertype; /* type of owner */
365 /* ****************************************************** */
366 /* FILTER ACTION DATA - METHODS/TYPES */
368 /* filtering flags - under what circumstances should a channel be added */
369 typedef enum ACTFILTER_FLAGS {
370 ACTFILTER_VISIBLE = (1 << 0), /* should channels be visible */
371 ACTFILTER_SEL = (1 << 1), /* should channels be selected */
372 ACTFILTER_FOREDIT = (1 << 2), /* does editable status matter */
373 ACTFILTER_CHANNELS = (1 << 3), /* do we only care that it is a channel */
374 ACTFILTER_IPOKEYS = (1 << 4), /* only channels referencing ipo's */
375 ACTFILTER_ONLYICU = (1 << 5), /* only reference ipo-curves */
376 ACTFILTER_FORDRAWING = (1 << 6), /* make list for interface drawing */
377 ACTFILTER_ACTGROUPED = (1 << 7) /* belongs to the active group */
380 /* Action Editor - Main Data types */
381 typedef enum ACTCONT_TYPES {
388 /* ****************************************************** */
389 /* Stroke Iteration Utilities */
392 * Iterate over all editable strokes in the current context,
393 * stopping on each usable layer + stroke pair (i.e. gpl and gps)
394 * to perform some operations on the stroke.
396 * \param gpl The identifier to use for the layer of the stroke being processed.
397 * Choose a suitable value to avoid name clashes.
398 * \param gps The identifier to use for current stroke being processed.
399 * Choose a suitable value to avoid name clashes.
401 #define GP_EDITABLE_STROKES_BEGIN(C, gpl, gps) \
403 CTX_DATA_BEGIN(C, bGPDlayer*, gpl, editable_gpencil_layers) \
405 if (gpl->actframe == NULL) \
407 /* calculate difference matrix if parent object */ \
408 float diff_mat[4][4]; \
409 ED_gpencil_parent_location(gpl, diff_mat); \
410 /* loop over strokes */ \
411 for (bGPDstroke *gps = gpl->actframe->strokes.first; gps; gps = gps->next) { \
412 /* skip strokes that are invalid for current view */ \
413 if (ED_gpencil_stroke_can_use(C, gps) == false) \
415 /* check if the color is editable */ \
416 if (ED_gpencil_stroke_color_use(gpl, gps) == false) \
418 /* ... Do Stuff With Strokes ... */
420 #define GP_EDITABLE_STROKES_END \
426 /* ****************************************************** */
428 #endif /* __GPENCIL_INTERN_H__ */