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) 2008, Blender Foundation
19 * This is a new part of Blender
21 * Contributor(s): Joshua Leung
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file ED_gpencil.h
30 #ifndef __ED_GPENCIL_H__
31 #define __ED_GPENCIL_H__
33 #include "ED_numinput.h"
47 struct bGPDpalettecolor;
49 struct KeyframeEditData;
51 struct wmWindowManager;
55 /* ------------- Grease-Pencil Helpers ---------------- */
56 typedef struct tGPDinterpolate_layer {
57 struct tGPDinterpolate_layer *next, *prev;
59 struct bGPDlayer *gpl; /* layer */
60 struct bGPDframe *prevFrame; /* frame before current frame (interpolate-from) */
61 struct bGPDframe *nextFrame; /* frame after current frame (interpolate-to) */
62 struct bGPDframe *interFrame; /* interpolated frame */
63 float factor; /* interpolate factor */
65 } tGPDinterpolate_layer;
67 /* Temporary interpolate operation data */
68 typedef struct tGPDinterpolate {
69 struct Scene *scene; /* current scene from context */
70 struct ScrArea *sa; /* area where painting originated */
71 struct ARegion *ar; /* region where painting originated */
72 struct bGPdata *gpd; /* current GP datablock */
74 int cframe; /* current frame number */
75 ListBase ilayers; /* (tGPDinterpolate_layer) layers to be interpolated */
76 float shift; /* -1/1 value for determining the displacement influence */
77 int flag; /* flag from toolsettings */
79 NumInput num; /* numeric input */
80 void *draw_handle_3d; /* handle for drawing strokes while operator is running 3d stuff */
81 void *draw_handle_screen; /* handle for drawing strokes while operator is running screen stuff */
84 /* Temporary 'Stroke Point' data
86 * Used as part of the 'stroke cache' used during drawing of new strokes
88 typedef struct tGPspoint {
89 int x, y; /* x and y coordinates of cursor (in relative to area) */
90 float pressure; /* pressure of tablet at this point */
91 float strength; /* pressure of tablet at this point for alpha factor */
92 float time; /* Time relative to stroke start (used when converting to path) */
96 /* Check if 'sketching sessions' are enabled */
97 #define GPENCIL_SKETCH_SESSIONS_ON(scene) ((scene)->toolsettings->gpencil_flags & GP_TOOL_FLAG_PAINTSESSIONS_ON)
99 /* ----------- Grease Pencil Tools/Context ------------- */
101 /* Context-dependent */
102 struct bGPdata **ED_gpencil_data_get_pointers(const struct bContext *C, struct PointerRNA *ptr);
103 struct bGPdata *ED_gpencil_data_get_active(const struct bContext *C);
105 /* Context independent (i.e. each required part is passed in instead) */
106 struct bGPdata **ED_gpencil_data_get_pointers_direct(struct ID *screen_id, struct Scene *scene,
107 struct ScrArea *sa, struct Object *ob,
108 struct PointerRNA *ptr);
109 struct bGPdata *ED_gpencil_data_get_active_direct(struct ID *screen_id, struct Scene *scene,
110 struct ScrArea *sa, struct Object *ob);
113 struct bGPdata *ED_gpencil_data_get_active_v3d(struct Scene *scene, struct View3D *v3d);
115 bool ED_gpencil_has_keyframe_v3d(struct Scene *scene, struct Object *ob, int cfra);
117 /* ----------- Stroke Editing Utilities ---------------- */
119 bool ED_gpencil_stroke_can_use_direct(const struct ScrArea *sa, const struct bGPDstroke *gps);
120 bool ED_gpencil_stroke_can_use(const struct bContext *C, const struct bGPDstroke *gps);
121 bool ED_gpencil_stroke_color_use(const struct bGPDlayer *gpl, const struct bGPDstroke *gps);
123 struct bGPDpalettecolor *ED_gpencil_stroke_getcolor(struct bGPdata *gpd, struct bGPDstroke *gps);
125 bool ED_gpencil_stroke_minmax(
126 const struct bGPDstroke *gps, const bool use_select,
127 float r_min[3], float r_max[3]);
129 /* ----------- Grease Pencil Operators ----------------- */
131 void ED_keymap_gpencil(struct wmKeyConfig *keyconf);
133 void ED_operatortypes_gpencil(void);
134 void ED_operatormacros_gpencil(void);
136 /* ------------- Copy-Paste Buffers -------------------- */
138 /* Strokes copybuf */
139 void ED_gpencil_strokes_copybuf_free(void);
142 /* ------------ Grease-Pencil Drawing API ------------------ */
145 void ED_gpencil_draw_2dimage(const struct bContext *C);
146 void ED_gpencil_draw_view2d(const struct bContext *C, bool onlyv2d);
147 void ED_gpencil_draw_view3d(struct wmWindowManager *wm, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, bool only3d);
148 void ED_gpencil_draw_ex(struct Scene *scene, struct bGPdata *gpd, int winx, int winy,
149 const int cfra, const char spacetype);
150 void ED_gp_draw_interpolation(struct tGPDinterpolate *tgpi, const int type);
152 /* ----------- Grease-Pencil AnimEdit API ------------------ */
153 bool ED_gplayer_frames_looper(struct bGPDlayer *gpl, struct Scene *scene,
154 short (*gpf_cb)(struct bGPDframe *, struct Scene *));
155 void ED_gplayer_make_cfra_list(struct bGPDlayer *gpl, ListBase *elems, bool onlysel);
157 bool ED_gplayer_frame_select_check(struct bGPDlayer *gpl);
158 void ED_gplayer_frame_select_set(struct bGPDlayer *gpl, short mode);
159 void ED_gplayer_frames_select_border(struct bGPDlayer *gpl, float min, float max, short select_mode);
160 void ED_gplayer_frames_select_region(struct KeyframeEditData *ked, struct bGPDlayer *gpl, short tool, short select_mode);
161 void ED_gpencil_select_frames(struct bGPDlayer *gpl, short select_mode);
162 void ED_gpencil_select_frame(struct bGPDlayer *gpl, int selx, short select_mode);
164 bool ED_gplayer_frames_delete(struct bGPDlayer *gpl);
165 void ED_gplayer_frames_duplicate(struct bGPDlayer *gpl);
167 void ED_gplayer_frames_keytype_set(struct bGPDlayer *gpl, short type);
169 void ED_gplayer_snap_frames(struct bGPDlayer *gpl, struct Scene *scene, short mode);
170 void ED_gplayer_mirror_frames(struct bGPDlayer *gpl, struct Scene *scene, short mode);
172 void ED_gpencil_anim_copybuf_free(void);
173 bool ED_gpencil_anim_copybuf_copy(struct bAnimContext *ac);
174 bool ED_gpencil_anim_copybuf_paste(struct bAnimContext *ac, const short copy_mode);
177 /* ------------ Grease-Pencil Undo System ------------------ */
178 int ED_gpencil_session_active(void);
179 int ED_undo_gpencil_step(struct bContext *C, int step, const char *name);
181 /* ------------ Transformation Utilities ------------ */
183 /* get difference matrix using parent */
184 void ED_gpencil_parent_location(struct bGPDlayer *gpl, float diff_mat[4][4]);
187 #endif /* __ED_GPENCIL_H__ */