1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup edsculpt
22  */
23 
24 #pragma once
25 
26 struct ARegion;
27 struct Brush;
28 struct ColorManagedDisplay;
29 struct ColorSpace;
30 struct ImagePool;
31 struct MTex;
32 struct Object;
33 struct Paint;
34 struct PaintStroke;
35 struct PointerRNA;
36 struct RegionView3D;
37 struct Scene;
38 struct VPaint;
39 struct ViewContext;
40 struct bContext;
41 struct rcti;
42 struct wmEvent;
43 struct wmKeyConfig;
44 struct wmOperator;
45 struct wmOperatorType;
46 struct wmWindowManager;
47 enum ePaintMode;
48 enum ePaintSymmetryFlags;
49 
50 typedef struct CoNo {
51   float co[3];
52   float no[3];
53 } CoNo;
54 
55 /* paint_stroke.c */
56 typedef bool (*StrokeGetLocation)(struct bContext *C, float location[3], const float mouse[2]);
57 typedef bool (*StrokeTestStart)(struct bContext *C, struct wmOperator *op, const float mouse[2]);
58 typedef void (*StrokeUpdateStep)(struct bContext *C,
59                                  struct PaintStroke *stroke,
60                                  struct PointerRNA *itemptr);
61 typedef void (*StrokeRedraw)(const struct bContext *C, struct PaintStroke *stroke, bool final);
62 typedef void (*StrokeDone)(const struct bContext *C, struct PaintStroke *stroke);
63 
64 struct PaintStroke *paint_stroke_new(struct bContext *C,
65                                      struct wmOperator *op,
66                                      StrokeGetLocation get_location,
67                                      StrokeTestStart test_start,
68                                      StrokeUpdateStep update_step,
69                                      StrokeRedraw redraw,
70                                      StrokeDone done,
71                                      int event_type);
72 void paint_stroke_free(struct bContext *C, struct wmOperator *op);
73 
74 bool paint_space_stroke_enabled(struct Brush *br, enum ePaintMode mode);
75 bool paint_supports_dynamic_size(struct Brush *br, enum ePaintMode mode);
76 bool paint_supports_dynamic_tex_coords(struct Brush *br, enum ePaintMode mode);
77 bool paint_supports_smooth_stroke(struct Brush *br, enum ePaintMode mode);
78 bool paint_supports_texture(enum ePaintMode mode);
79 bool paint_supports_jitter(enum ePaintMode mode);
80 
81 struct wmKeyMap *paint_stroke_modal_keymap(struct wmKeyConfig *keyconf);
82 int paint_stroke_modal(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
83 int paint_stroke_exec(struct bContext *C, struct wmOperator *op);
84 void paint_stroke_cancel(struct bContext *C, struct wmOperator *op);
85 bool paint_stroke_flipped(struct PaintStroke *stroke);
86 bool paint_stroke_inverted(struct PaintStroke *stroke);
87 struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke);
88 void *paint_stroke_mode_data(struct PaintStroke *stroke);
89 float paint_stroke_distance_get(struct PaintStroke *stroke);
90 void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data);
91 bool paint_poll(struct bContext *C);
92 void paint_cursor_start(struct Paint *p, bool (*poll)(struct bContext *C));
93 void paint_cursor_delete_textures(void);
94 
95 /* paint_vertex.c */
96 bool weight_paint_poll(struct bContext *C);
97 bool weight_paint_poll_ignore_tool(bContext *C);
98 bool weight_paint_mode_poll(struct bContext *C);
99 bool vertex_paint_poll(struct bContext *C);
100 bool vertex_paint_poll_ignore_tool(struct bContext *C);
101 bool vertex_paint_mode_poll(struct bContext *C);
102 
103 typedef void (*VPaintTransform_Callback)(const float col[3],
104                                          const void *user_data,
105                                          float r_col[3]);
106 
107 void PAINT_OT_weight_paint_toggle(struct wmOperatorType *ot);
108 void PAINT_OT_weight_paint(struct wmOperatorType *ot);
109 void PAINT_OT_weight_set(struct wmOperatorType *ot);
110 
111 enum {
112   WPAINT_GRADIENT_TYPE_LINEAR,
113   WPAINT_GRADIENT_TYPE_RADIAL,
114 };
115 void PAINT_OT_weight_gradient(struct wmOperatorType *ot);
116 
117 void PAINT_OT_vertex_paint_toggle(struct wmOperatorType *ot);
118 void PAINT_OT_vertex_paint(struct wmOperatorType *ot);
119 
120 unsigned int vpaint_get_current_col(struct Scene *scene, struct VPaint *vp, bool secondary);
121 
122 /* paint_vertex_color_utils.c */
123 unsigned int ED_vpaint_blend_tool(const int tool,
124                                   const uint col,
125                                   const uint paintcol,
126                                   const int alpha_i);
127 bool ED_vpaint_color_transform(struct Object *ob,
128                                VPaintTransform_Callback vpaint_tx_fn,
129                                const void *user_data);
130 
131 /* paint_vertex_weight_utils.c */
132 float ED_wpaint_blend_tool(const int tool,
133                            const float weight,
134                            const float paintval,
135                            const float alpha);
136 /* Utility for tools to ensure vertex groups exist before they begin. */
137 enum eWPaintFlag {
138   WPAINT_ENSURE_MIRROR = (1 << 0),
139 };
140 struct WPaintVGroupIndex {
141   int active;
142   int mirror;
143 };
144 bool ED_wpaint_ensure_data(struct bContext *C,
145                            struct ReportList *reports,
146                            enum eWPaintFlag flag,
147                            struct WPaintVGroupIndex *vgroup_index);
148 int ED_wpaint_mirror_vgroup_ensure(struct Object *ob, const int vgroup_active);
149 
150 /* paint_vertex_color_ops.c */
151 void PAINT_OT_vertex_color_set(struct wmOperatorType *ot);
152 void PAINT_OT_vertex_color_from_weight(struct wmOperatorType *ot);
153 void PAINT_OT_vertex_color_smooth(struct wmOperatorType *ot);
154 void PAINT_OT_vertex_color_brightness_contrast(struct wmOperatorType *ot);
155 void PAINT_OT_vertex_color_hsv(struct wmOperatorType *ot);
156 void PAINT_OT_vertex_color_invert(struct wmOperatorType *ot);
157 void PAINT_OT_vertex_color_levels(struct wmOperatorType *ot);
158 
159 /* paint_vertex_weight_ops.c */
160 void PAINT_OT_weight_from_bones(struct wmOperatorType *ot);
161 void PAINT_OT_weight_sample(struct wmOperatorType *ot);
162 void PAINT_OT_weight_sample_group(struct wmOperatorType *ot);
163 
164 /* paint_vertex_proj.c */
165 struct VertProjHandle;
166 struct VertProjHandle *ED_vpaint_proj_handle_create(struct Depsgraph *depsgraph,
167                                                     struct Scene *scene,
168                                                     struct Object *ob,
169                                                     struct CoNo **r_vcosnos);
170 void ED_vpaint_proj_handle_update(struct Depsgraph *depsgraph,
171                                   struct VertProjHandle *vp_handle,
172                                   /* runtime vars */
173                                   struct ARegion *region,
174                                   const float mval_fl[2]);
175 void ED_vpaint_proj_handle_free(struct VertProjHandle *vp_handle);
176 
177 /* paint_image.c */
178 typedef struct ImagePaintPartialRedraw {
179   int x1, y1, x2, y2; /* XXX, could use 'rcti' */
180   int enabled;
181 } ImagePaintPartialRedraw;
182 
183 bool image_texture_paint_poll(struct bContext *C);
184 void imapaint_image_update(struct SpaceImage *sima,
185                            struct Image *image,
186                            struct ImBuf *ibuf,
187                            struct ImageUser *iuser,
188                            short texpaint);
189 struct ImagePaintPartialRedraw *get_imapaintpartial(void);
190 void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr);
191 void imapaint_region_tiles(
192     struct ImBuf *ibuf, int x, int y, int w, int h, int *tx, int *ty, int *tw, int *th);
193 bool get_imapaint_zoom(struct bContext *C, float *zoomx, float *zoomy);
194 void *paint_2d_new_stroke(struct bContext *, struct wmOperator *, int mode);
195 void paint_2d_redraw(const struct bContext *C, void *ps, bool final);
196 void paint_2d_stroke_done(void *ps);
197 void paint_2d_stroke(void *ps,
198                      const float prev_mval[2],
199                      const float mval[2],
200                      const bool eraser,
201                      float pressure,
202                      float distance,
203                      float size);
204 void paint_2d_bucket_fill(const struct bContext *C,
205                           const float color[3],
206                           struct Brush *br,
207                           const float mouse_init[2],
208                           const float mouse_final[2],
209                           void *ps);
210 void paint_2d_gradient_fill(const struct bContext *C,
211                             struct Brush *br,
212                             const float mouse_init[2],
213                             const float mouse_final[2],
214                             void *ps);
215 void *paint_proj_new_stroke(struct bContext *C, struct Object *ob, const float mouse[2], int mode);
216 void paint_proj_stroke(const struct bContext *C,
217                        void *ps_handle_p,
218                        const float prev_pos[2],
219                        const float pos[2],
220                        const bool eraser,
221                        float pressure,
222                        float distance,
223                        float size);
224 void paint_proj_redraw(const struct bContext *C, void *ps_handle_p, bool final);
225 void paint_proj_stroke_done(void *ps_handle_p);
226 
227 void paint_brush_color_get(struct Scene *scene,
228                            struct Brush *br,
229                            bool color_correction,
230                            bool invert,
231                            float distance,
232                            float pressure,
233                            float color[3],
234                            struct ColorManagedDisplay *display);
235 bool paint_use_opacity_masking(struct Brush *brush);
236 void paint_brush_init_tex(struct Brush *brush);
237 void paint_brush_exit_tex(struct Brush *brush);
238 
239 void PAINT_OT_grab_clone(struct wmOperatorType *ot);
240 void PAINT_OT_sample_color(struct wmOperatorType *ot);
241 void PAINT_OT_brush_colors_flip(struct wmOperatorType *ot);
242 void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
243 void PAINT_OT_project_image(struct wmOperatorType *ot);
244 void PAINT_OT_image_from_view(struct wmOperatorType *ot);
245 void PAINT_OT_add_texture_paint_slot(struct wmOperatorType *ot);
246 void PAINT_OT_image_paint(struct wmOperatorType *ot);
247 void PAINT_OT_add_simple_uvs(struct wmOperatorType *ot);
248 
249 /* sculpt_uv.c */
250 void SCULPT_OT_uv_sculpt_stroke(struct wmOperatorType *ot);
251 
252 /* paint_utils.c */
253 
254 /* Convert the object-space axis-aligned bounding box (expressed as
255  * its minimum and maximum corners) into a screen-space rectangle,
256  * returns zero if the result is empty */
257 bool paint_convert_bb_to_rect(struct rcti *rect,
258                               const float bb_min[3],
259                               const float bb_max[3],
260                               const struct ARegion *region,
261                               struct RegionView3D *rv3d,
262                               struct Object *ob);
263 
264 /* Get four planes in object-space that describe the projection of
265  * screen_rect from screen into object-space (essentially converting a
266  * 2D screens-space bounding box into four 3D planes) */
267 void paint_calc_redraw_planes(float planes[4][4],
268                               const struct ARegion *region,
269                               struct Object *ob,
270                               const struct rcti *screen_rect);
271 
272 float paint_calc_object_space_radius(struct ViewContext *vc,
273                                      const float center[3],
274                                      float pixel_radius);
275 float paint_get_tex_pixel(
276     const struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread);
277 void paint_get_tex_pixel_col(const struct MTex *mtex,
278                              float u,
279                              float v,
280                              float rgba[4],
281                              struct ImagePool *pool,
282                              int thread,
283                              bool convert,
284                              struct ColorSpace *colorspace);
285 
286 void paint_sample_color(
287     struct bContext *C, struct ARegion *region, int x, int y, bool texpaint_proj, bool palette);
288 
289 void paint_stroke_operator_properties(struct wmOperatorType *ot);
290 
291 void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
292 
293 void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
294 void PAINT_OT_face_select_linked_pick(struct wmOperatorType *ot);
295 void PAINT_OT_face_select_all(struct wmOperatorType *ot);
296 void PAINT_OT_face_select_hide(struct wmOperatorType *ot);
297 void PAINT_OT_face_select_reveal(struct wmOperatorType *ot);
298 
299 void PAINT_OT_vert_select_all(struct wmOperatorType *ot);
300 void PAINT_OT_vert_select_ungrouped(struct wmOperatorType *ot);
301 
302 bool vert_paint_poll(struct bContext *C);
303 bool mask_paint_poll(struct bContext *C);
304 bool paint_curve_poll(struct bContext *C);
305 
306 bool facemask_paint_poll(struct bContext *C);
307 void flip_v3_v3(float out[3], const float in[3], const enum ePaintSymmetryFlags symm);
308 void flip_qt_qt(float out[3], const float in[3], const enum ePaintSymmetryFlags symm);
309 
310 /* stroke operator */
311 typedef enum BrushStrokeMode {
312   BRUSH_STROKE_NORMAL,
313   BRUSH_STROKE_INVERT,
314   BRUSH_STROKE_SMOOTH,
315 } BrushStrokeMode;
316 
317 /* paint_hide.c */
318 
319 typedef enum {
320   PARTIALVIS_HIDE,
321   PARTIALVIS_SHOW,
322 } PartialVisAction;
323 
324 typedef enum {
325   PARTIALVIS_INSIDE,
326   PARTIALVIS_OUTSIDE,
327   PARTIALVIS_ALL,
328   PARTIALVIS_MASKED,
329 } PartialVisArea;
330 
331 void PAINT_OT_hide_show(struct wmOperatorType *ot);
332 
333 /* paint_mask.c */
334 
335 typedef enum {
336   PAINT_MASK_FLOOD_VALUE,
337   PAINT_MASK_FLOOD_VALUE_INVERSE,
338   PAINT_MASK_INVERT,
339 } PaintMaskFloodMode;
340 
341 void PAINT_OT_mask_flood_fill(struct wmOperatorType *ot);
342 void PAINT_OT_mask_lasso_gesture(struct wmOperatorType *ot);
343 void PAINT_OT_mask_box_gesture(struct wmOperatorType *ot);
344 void PAINT_OT_mask_line_gesture(struct wmOperatorType *ot);
345 
346 /* paint_curve.c */
347 void PAINTCURVE_OT_new(struct wmOperatorType *ot);
348 void PAINTCURVE_OT_add_point(struct wmOperatorType *ot);
349 void PAINTCURVE_OT_delete_point(struct wmOperatorType *ot);
350 void PAINTCURVE_OT_select(struct wmOperatorType *ot);
351 void PAINTCURVE_OT_slide(struct wmOperatorType *ot);
352 void PAINTCURVE_OT_draw(struct wmOperatorType *ot);
353 void PAINTCURVE_OT_cursor(struct wmOperatorType *ot);
354 
355 /* image painting blur kernel */
356 typedef struct {
357   float *wdata;     /* actual kernel */
358   int side;         /* kernel side */
359   int side_squared; /* data side */
360   int pixel_len;    /* pixels around center that kernel is wide */
361 } BlurKernel;
362 
363 enum eBlurKernelType;
364 /* can be extended to other blur kernels later */
365 BlurKernel *paint_new_blur_kernel(struct Brush *br, bool proj);
366 void paint_delete_blur_kernel(BlurKernel *);
367 
368 /* paint curve defines */
369 #define PAINT_CURVE_NUM_SEGMENTS 40
370