First fix for install_deps and ubuntu 10.04 (no libtiff5, only libtiff4, wonder why...
[blender.git] / source / blender / editors / sculpt_paint / paint_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
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.
8  *
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.
13  *
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.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file blender/editors/sculpt_paint/paint_ops.c
22  *  \ingroup edsculpt
23  */
24
25 #include "MEM_guardedalloc.h"
26
27 #include <stdlib.h>
28 #include "BLI_listbase.h"
29 #include "BLI_string.h"
30 #include "BLI_utildefines.h"
31 #include "BLI_math_vector.h"
32
33 #include "DNA_object_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_brush_types.h"
36
37 #include "BKE_brush.h"
38 #include "BKE_context.h"
39 #include "BKE_paint.h"
40 #include "BKE_main.h"
41
42 #include "ED_sculpt.h"
43 #include "ED_screen.h"
44 #include "UI_resources.h"
45
46 #include "WM_api.h"
47 #include "WM_types.h"
48
49 #include "RNA_access.h"
50 #include "RNA_define.h"
51 #include "RNA_enum_types.h"
52
53 #include "paint_intern.h"
54 #include "sculpt_intern.h"
55
56 #include <string.h>
57 //#include <stdio.h>
58 #include <stddef.h>
59
60 /* Brush operators */
61 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
62 {
63         /*int type = RNA_enum_get(op->ptr, "type");*/
64         Paint *paint = paint_get_active_from_context(C);
65         Brush *br = paint_brush(paint);
66         Main *bmain = CTX_data_main(C);
67
68         if (br)
69                 br = BKE_brush_copy(br);
70         else
71                 br = BKE_brush_add(bmain, "Brush");
72
73         paint_brush_set(paint, br);
74
75         return OPERATOR_FINISHED;
76 }
77
78 static void BRUSH_OT_add(wmOperatorType *ot)
79 {
80         /* identifiers */
81         ot->name = "Add Brush";
82         ot->description = "Add brush by mode type";
83         ot->idname = "BRUSH_OT_add";
84         
85         /* api callbacks */
86         ot->exec = brush_add_exec;
87         
88         /* flags */
89         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
90 }
91
92
93 static int brush_scale_size_exec(bContext *C, wmOperator *op)
94 {
95         Scene *scene = CTX_data_scene(C);
96         Paint  *paint =  paint_get_active_from_context(C);
97         Brush  *brush =  paint_brush(paint);
98         // Object *ob = CTX_data_active_object(C);
99         float scalar = RNA_float_get(op->ptr, "scalar");
100
101         if (brush) {
102                 // pixel radius
103                 {
104                         const int old_size = BKE_brush_size_get(scene, brush);
105                         int size = (int)(scalar * old_size);
106
107                         if (old_size == size) {
108                                 if (scalar > 1) {
109                                         size++;
110                                 }
111                                 else if (scalar < 1) {
112                                         size--;
113                                 }
114                         }
115                         CLAMP(size, 1, 2000); // XXX magic number
116
117                         BKE_brush_size_set(scene, brush, size);
118                 }
119
120                 // unprojected radius
121                 {
122                         float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush);
123
124                         if (unprojected_radius < 0.001f) // XXX magic number
125                                 unprojected_radius = 0.001f;
126
127                         BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius);
128                 }
129         }
130
131         return OPERATOR_FINISHED;
132 }
133
134 static void BRUSH_OT_scale_size(wmOperatorType *ot)
135 {
136         /* identifiers */
137         ot->name = "Scale Sculpt/Paint Brush Size";
138         ot->description = "Change brush size by a scalar";
139         ot->idname = "BRUSH_OT_scale_size";
140         
141         /* api callbacks */
142         ot->exec = brush_scale_size_exec;
143         
144         /* flags */
145         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
146
147         RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
148 }
149
150 static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
151 {
152         Scene *scene = CTX_data_scene(C);
153         Object *obact = CTX_data_active_object(C);
154         unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint);
155         vpaint_fill(obact, paintcol);
156         
157         ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
158         return OPERATOR_FINISHED;
159 }
160
161 static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
162 {
163         /* identifiers */
164         ot->name = "Set Vertex Colors";
165         ot->idname = "PAINT_OT_vertex_color_set";
166         ot->description = "Fill the active vertex color layer with the current paint color";
167         
168         /* api callbacks */
169         ot->exec = vertex_color_set_exec;
170         ot->poll = vertex_paint_mode_poll;
171         
172         /* flags */
173         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
174 }
175
176 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
177 {
178         Paint *paint = paint_get_active_from_context(C);
179         Brush *brush = paint_brush(paint);
180         Object *ob = CTX_data_active_object(C);
181
182         if (!ob || !brush) return OPERATOR_CANCELLED;
183
184         if (ob->mode & OB_MODE_SCULPT)
185                 BKE_brush_sculpt_reset(brush);
186         /* TODO: other modes */
187
188         return OPERATOR_FINISHED;
189 }
190
191 static void BRUSH_OT_reset(wmOperatorType *ot)
192 {
193         /* identifiers */
194         ot->name = "Reset Brush";
195         ot->description = "Return brush to defaults based on current tool";
196         ot->idname = "BRUSH_OT_reset";
197         
198         /* api callbacks */
199         ot->exec = brush_reset_exec;
200         
201         /* flags */
202         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
203 }
204
205 static int brush_tool(const Brush *brush, size_t tool_offset)
206 {
207         return *(((char *)brush) + tool_offset);
208 }
209
210 static void brush_tool_set(const Brush *brush, size_t tool_offset, int tool)
211 {
212         *(((char *)brush) + tool_offset) = tool;
213 }
214
215 /* generic functions for setting the active brush based on the tool */
216 static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
217 {
218         Brush *brush;
219
220         if (!brush_orig && !(brush_orig = bmain->brush.first)) {
221                 return NULL;
222         }
223
224         /* get the next brush with the active tool */
225         for (brush = brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
226              brush != brush_orig;
227              brush = brush->id.next ? brush->id.next : bmain->brush.first)
228         {
229                 if ((brush->ob_mode & ob_mode) &&
230                     (brush_tool(brush, tool_offset) == tool))
231                 {
232                         return brush;
233                 }
234         }
235
236         return NULL;
237 }
238
239 static Brush *brush_tool_toggle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
240 {
241         if (!brush_orig || brush_tool(brush_orig, tool_offset) != tool) {
242                 Brush *br;
243                 /* if the current brush is not using the desired tool, look
244                  * for one that is */
245                 br = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
246                 /* store the previously-selected brush */
247                 if (br)
248                         br->toggle_brush = brush_orig;
249                 
250                 return br;
251         }
252         else if (brush_orig->toggle_brush &&
253                  BLI_findindex(bmain->brush.first, brush_orig->toggle_brush) != -1)
254         {
255                 /* if current brush is using the desired tool, try to toggle
256                  * back to the previously selected brush (if it was set, and
257                  * if it still exists) */
258                 return brush_orig->toggle_brush;
259         }
260         else
261                 return NULL;
262 }
263
264 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool,
265                                   const size_t tool_offset, const int ob_mode,
266                                   const char *tool_name, int create_missing,
267                                   int toggle)
268 {
269         Brush *brush, *brush_orig = paint_brush(paint);
270
271         if (toggle)
272                 brush = brush_tool_toggle(bmain, brush_orig, tool, tool_offset, ob_mode);
273         else
274                 brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
275
276         if (!brush && brush_tool(brush_orig, tool_offset) != tool && create_missing) {
277                 brush = BKE_brush_add(bmain, tool_name);
278                 brush_tool_set(brush, tool_offset, tool);
279                 brush->ob_mode = ob_mode;
280                 brush->toggle_brush = brush_orig;
281         }
282
283         if (brush) {
284                 paint_brush_set(paint, brush);
285                 WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
286                 return OPERATOR_FINISHED;
287         }
288         else {
289                 return OPERATOR_CANCELLED;
290         }
291 }
292
293 /* used in the PAINT_OT_brush_select operator */
294 #define OB_MODE_ACTIVE 0
295
296 static int brush_select_exec(bContext *C, wmOperator *op)
297 {
298         Main *bmain = CTX_data_main(C);
299         ToolSettings *toolsettings = CTX_data_tool_settings(C);
300         Paint *paint = NULL;
301         int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
302         int create_missing = RNA_boolean_get(op->ptr, "create_missing");
303         int toggle = RNA_boolean_get(op->ptr, "toggle");
304         const char *tool_name = "Brush";
305         size_t tool_offset;
306
307         if (paint_mode == OB_MODE_ACTIVE) {
308                 Object *ob = CTX_data_active_object(C);
309                 if (ob) {
310                         /* select current paint mode */
311                         paint_mode = ob->mode & OB_MODE_ALL_PAINT;
312                 }
313                 else {
314                         return OPERATOR_CANCELLED;
315                 }
316         }
317
318         switch (paint_mode) {
319                 case OB_MODE_SCULPT:
320                         paint = &toolsettings->sculpt->paint;
321                         tool_offset = offsetof(Brush, sculpt_tool);
322                         tool = RNA_enum_get(op->ptr, "sculpt_tool");
323                         RNA_enum_name_from_value(brush_sculpt_tool_items, tool, &tool_name);
324                         break;
325                 case OB_MODE_VERTEX_PAINT:
326                         paint = &toolsettings->vpaint->paint;
327                         tool_offset = offsetof(Brush, vertexpaint_tool);
328                         tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
329                         RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
330                         break;
331                 case OB_MODE_WEIGHT_PAINT:
332                         paint = &toolsettings->wpaint->paint;
333                         /* vertexpaint_tool is used for weight paint mode */
334                         tool_offset = offsetof(Brush, vertexpaint_tool);
335                         tool = RNA_enum_get(op->ptr, "weight_paint_tool");
336                         RNA_enum_name_from_value(brush_vertex_tool_items, tool, &tool_name);
337                         break;
338                 case OB_MODE_TEXTURE_PAINT:
339                         paint = &toolsettings->imapaint.paint;
340                         tool_offset = offsetof(Brush, imagepaint_tool);
341                         tool = RNA_enum_get(op->ptr, "texture_paint_tool");
342                         RNA_enum_name_from_value(brush_image_tool_items, tool, &tool_name);
343                         break;
344                 default:
345                         /* invalid paint mode */
346                         return OPERATOR_CANCELLED;
347         }
348
349         return brush_generic_tool_set(bmain, paint, tool, tool_offset,
350                                       paint_mode, tool_name, create_missing,
351                                       toggle);
352 }
353
354 static void PAINT_OT_brush_select(wmOperatorType *ot)
355 {
356         static EnumPropertyItem paint_mode_items[] = {
357                 {OB_MODE_ACTIVE, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
358                 {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
359                 {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
360                 {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
361                 {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
362                 {0, NULL, 0, NULL, NULL}
363         };
364
365         /* identifiers */
366         ot->name = "Brush Select";
367         ot->description = "Select a paint mode's brush by tool type";
368         ot->idname = "PAINT_OT_brush_select";
369
370         /* api callbacks */
371         ot->exec = brush_select_exec;
372
373         /* flags */
374         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
375
376         /* props */
377         RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, OB_MODE_ACTIVE, "Paint Mode", "");
378         RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", "");
379         RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
380         RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
381         RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
382
383         RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle between two brushes rather than cycling");
384         RNA_def_boolean(ot->srna, "create_missing", 0, "Create Missing", "If the requested brush type does not exist, create a new brush");
385 }
386
387 static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
388                                          int tool, int keymap_type,
389                                          int keymap_modifier)
390 {
391         wmKeyMapItem *kmi;
392         kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select",
393                                  keymap_type, KM_PRESS, keymap_modifier, 0);
394
395         RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
396         
397         switch (paint_mode) {
398                 case OB_MODE_SCULPT:
399                         RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
400                         break;
401                 case OB_MODE_VERTEX_PAINT:
402                         RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
403                         break;
404                 case OB_MODE_WEIGHT_PAINT:
405                         RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
406                         break;
407                 case OB_MODE_TEXTURE_PAINT:
408                         RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
409                         break;
410         }
411
412         return kmi;
413 }
414
415 static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
416 {
417         Brush *brush;
418         Scene *scene = CTX_data_scene(C);
419         ToolSettings *ts = scene->toolsettings;
420         ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
421         brush = ts->uvsculpt->paint.brush;
422         /* To update toolshelf */
423         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
424
425         return OPERATOR_FINISHED;
426 }
427
428 static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
429 {
430         /* from rna_scene.c */
431         extern EnumPropertyItem uv_sculpt_tool_items[];
432         /* identifiers */
433         ot->name = "UV Sculpt Tool Set";
434         ot->description = "Set the UV sculpt tool";
435         ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
436
437         /* api callbacks */
438         ot->exec = brush_uv_sculpt_tool_set_exec;
439         ot->poll = uv_sculpt_poll;
440
441         /* flags */
442         ot->flag = 0;
443
444         /* props */
445         ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
446 }
447
448 /***** Stencil Control *****/
449
450 enum {
451 STENCIL_TRANSLATE,
452 STENCIL_SCALE,
453 STENCIL_ROTATE
454 } StencilControlMode;
455
456 typedef struct {
457         float init_mouse[2];
458         float init_spos[2];
459         float init_sdim[2];
460         float init_rot;
461         float init_angle;
462         float lenorig;
463         int mode;
464         Brush *br;
465 } StencilControlData;
466
467 static int stencil_control_invoke(bContext *C, wmOperator *op, const wmEvent *event)
468 {
469         Paint *paint = paint_get_active_from_context(C);
470         Brush *br = paint_brush(paint);
471         float mdiff[2];
472         float mvalf[2] = {event->mval[0], event->mval[1]};
473
474         StencilControlData *scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control");
475
476         copy_v2_v2(scd->init_mouse, mvalf);
477         copy_v2_v2(scd->init_sdim, br->stencil_dimension);
478         copy_v2_v2(scd->init_spos, br->stencil_pos);
479         sub_v2_v2v2(mdiff, mvalf, br->stencil_pos);
480         scd->lenorig = len_v2(mdiff);
481         scd->br = br;
482         scd->init_rot = br->mtex.rot;
483         scd->init_angle = atan2(mdiff[1], mdiff[0]);
484         scd->mode = RNA_enum_get(op->ptr, "mode");
485
486         op->customdata = scd;
487         WM_event_add_modal_handler(C, op);
488
489         return OPERATOR_RUNNING_MODAL;
490 }
491
492
493 static int stencil_control_cancel(bContext *UNUSED(C), wmOperator *op)
494 {
495         StencilControlData *scd = op->customdata;
496         Brush *br = scd->br;
497
498         copy_v2_v2(br->stencil_dimension, scd->init_sdim);
499         copy_v2_v2(br->stencil_pos, scd->init_spos);
500         br->mtex.rot = scd->init_rot;
501         MEM_freeN(op->customdata);
502         return OPERATOR_CANCELLED;
503 }
504
505 static int stencil_control_modal(bContext *C, wmOperator *op, const wmEvent *event)
506 {
507         StencilControlData *scd = op->customdata;
508
509         switch (event->type) {
510                 case MOUSEMOVE:
511                         {
512                                 float mdiff[2];
513                                 float mvalf[2] = {event->mval[0], event->mval[1]};
514                                 switch (scd->mode) {
515                                         case STENCIL_TRANSLATE:
516                                                 sub_v2_v2v2(mdiff, mvalf, scd->init_mouse);
517                                                 add_v2_v2v2(scd->br->stencil_pos, scd->init_spos,
518                                                             mdiff);
519                                                 break;
520                                         case STENCIL_SCALE:
521                                         {
522                                                 float len, factor;
523                                                 sub_v2_v2v2(mdiff, mvalf, scd->br->stencil_pos);
524                                                 len = len_v2(mdiff);
525                                                 factor = len / scd->lenorig;
526                                                 mdiff[0] = factor * scd->init_sdim[0];
527                                                 mdiff[1] = factor * scd->init_sdim[1];
528                                                 copy_v2_v2(scd->br->stencil_dimension, mdiff);
529                                                 break;
530                                         }
531                                         case STENCIL_ROTATE:
532                                         {
533                                                 float angle;
534                                                 sub_v2_v2v2(mdiff, mvalf, scd->br->stencil_pos);
535                                                 angle = atan2(mdiff[1], mdiff[0]);
536                                                 angle = scd->init_rot + angle - scd->init_angle;
537                                                 if (angle < 0.0f)
538                                                         angle += (float)(2 * M_PI);
539                                                 if (angle > (float)(2 * M_PI))
540                                                         angle -= (float)(2 * M_PI);
541                                                 scd->br->mtex.rot = angle;
542                                                 break;
543                                         }
544                                 }
545                         }
546                         break;
547                 /* XXX hardcoded! */
548                 case RIGHTMOUSE:
549                         if (event->val == KM_RELEASE) {
550                                 MEM_freeN(op->customdata);
551                                 WM_event_add_notifier(C, NC_WINDOW, NULL);
552                                 return OPERATOR_FINISHED;
553                         }
554                 case ESCKEY:
555                         if (event->val == KM_PRESS) {
556                                 stencil_control_cancel(C, op);
557                                 WM_event_add_notifier(C, NC_WINDOW, NULL);
558                                 return OPERATOR_CANCELLED;
559                         }
560                 default:
561                         break;
562         }
563
564         ED_region_tag_redraw(CTX_wm_region(C));
565
566         return OPERATOR_RUNNING_MODAL;
567 }
568
569 static int stencil_control_poll(bContext *C)
570 {
571         Paint *paint = paint_get_active_from_context(C);
572         Brush *br = paint_brush(paint);
573
574         return (br && br->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL);
575 }
576
577 static void BRUSH_OT_stencil_control(wmOperatorType *ot)
578 {
579         static EnumPropertyItem stencil_control_items[] = {
580                 {STENCIL_TRANSLATE, "TRANSLATION", 0, "Translation", ""},
581                 {STENCIL_SCALE, "SCALE", 0, "Scale", ""},
582                 {STENCIL_ROTATE, "ROTATION", 0, "Rotation", ""},
583                 {0, NULL, 0, NULL, NULL}
584         };
585         /* identifiers */
586         ot->name = "Stencil Brush Control";
587         ot->description = "Control the stencil brush";
588         ot->idname = "BRUSH_OT_stencil_control";
589
590         /* api callbacks */
591         ot->invoke = stencil_control_invoke;
592         ot->modal = stencil_control_modal;
593         ot->cancel = stencil_control_cancel;
594         ot->poll = stencil_control_poll;
595
596         /* flags */
597         ot->flag = 0;
598
599         RNA_def_enum(ot->srna, "mode", stencil_control_items, 0, "Tool", "");
600 }
601
602 static void ed_keymap_stencil(wmKeyMap *keymap)
603 {
604         wmKeyMapItem *kmi;
605
606         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_stencil_control", RIGHTMOUSE, KM_PRESS, 0, 0);
607         RNA_enum_set(kmi->ptr, "mode", STENCIL_TRANSLATE);
608         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_stencil_control", RIGHTMOUSE, KM_PRESS, KM_SHIFT, 0);
609         RNA_enum_set(kmi->ptr, "mode", STENCIL_SCALE);
610         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_stencil_control", RIGHTMOUSE, KM_PRESS, KM_CTRL, 0);
611         RNA_enum_set(kmi->ptr, "mode", STENCIL_ROTATE);
612
613 }
614
615 /**************************** registration **********************************/
616
617 void ED_operatortypes_paint(void)
618 {
619         /* brush */
620         WM_operatortype_append(BRUSH_OT_add);
621         WM_operatortype_append(BRUSH_OT_scale_size);
622         WM_operatortype_append(BRUSH_OT_curve_preset);
623         WM_operatortype_append(BRUSH_OT_reset);
624         WM_operatortype_append(BRUSH_OT_stencil_control);
625
626         /* note, particle uses a different system, can be added with existing operators in wm.py */
627         WM_operatortype_append(PAINT_OT_brush_select);
628         WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
629
630         /* image */
631         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
632         WM_operatortype_append(PAINT_OT_image_paint);
633         WM_operatortype_append(PAINT_OT_sample_color);
634         WM_operatortype_append(PAINT_OT_grab_clone);
635         WM_operatortype_append(PAINT_OT_project_image);
636         WM_operatortype_append(PAINT_OT_image_from_view);
637
638         /* weight */
639         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
640         WM_operatortype_append(PAINT_OT_weight_paint);
641         WM_operatortype_append(PAINT_OT_weight_set);
642         WM_operatortype_append(PAINT_OT_weight_from_bones);
643         WM_operatortype_append(PAINT_OT_weight_gradient);
644         WM_operatortype_append(PAINT_OT_weight_sample);
645         WM_operatortype_append(PAINT_OT_weight_sample_group);
646
647         /* uv */
648         WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
649
650         /* vertex selection */
651         WM_operatortype_append(PAINT_OT_vert_select_all);
652         WM_operatortype_append(PAINT_OT_vert_select_ungrouped);
653
654         /* vertex */
655         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
656         WM_operatortype_append(PAINT_OT_vertex_paint);
657         WM_operatortype_append(PAINT_OT_vertex_color_set);
658
659         /* face-select */
660         WM_operatortype_append(PAINT_OT_face_select_linked);
661         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
662         WM_operatortype_append(PAINT_OT_face_select_all);
663         WM_operatortype_append(PAINT_OT_face_select_hide);
664         WM_operatortype_append(PAINT_OT_face_select_reveal);
665
666         /* partial visibility */
667         WM_operatortype_append(PAINT_OT_hide_show);
668
669         /* paint masking */
670         WM_operatortype_append(PAINT_OT_mask_flood_fill);
671 }
672
673
674 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
675 {
676         wmKeyMapItem *kmi;
677         int i;
678         /* index 0-9 (zero key is tenth), shift key for index 10-19 */
679         for (i = 0; i < 20; i++) {
680                 kmi = WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
681                                          ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
682                 RNA_string_set(kmi->ptr, "mode", mode);
683                 RNA_int_set(kmi->ptr, "index", i);
684         }
685 }
686
687 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
688 {
689         wmKeyMapItem *kmi;
690
691         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
692         RNA_float_set(kmi->ptr, "scalar", 0.9);
693
694         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
695         RNA_float_set(kmi->ptr, "scalar", 10.0 / 9.0); // 1.1111....
696 }
697
698 typedef enum {
699         RC_COLOR = 1,
700         RC_ROTATION = 2,
701         RC_ZOOM = 4
702 } RCFlags;
703
704 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
705                               const char *output_name, const char *input_name)
706 {
707         char *path;
708
709         path = BLI_sprintfN("%s.%s", brush_path, input_name);
710         RNA_string_set(ptr, output_name, path);
711         MEM_freeN(path);
712 }
713
714 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
715                                const char *prop, const char *secondary_prop,
716                                RCFlags flags)
717 {
718         const char *ups_path = "tool_settings.unified_paint_settings";
719         char *brush_path;
720
721         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
722
723         set_brush_rc_path(ptr, brush_path, "data_path_primary", prop);
724         if (secondary_prop) {
725                 set_brush_rc_path(ptr, ups_path, "use_secondary", secondary_prop);
726                 set_brush_rc_path(ptr, ups_path, "data_path_secondary", prop);
727         }
728         else {
729                 RNA_string_set(ptr, "use_secondary", "");
730                 RNA_string_set(ptr, "data_path_secondary", "");
731         }
732         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
733         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
734         RNA_string_set(ptr, "image_id", brush_path);
735
736         if (flags & RC_COLOR)
737                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
738         else
739                 RNA_string_set(ptr, "fill_color_path", "");
740         if (flags & RC_ZOOM)
741                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
742         else
743                 RNA_string_set(ptr, "zoom_path", "");
744
745         MEM_freeN(brush_path);
746 }
747
748 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
749                                                  RCFlags flags)
750 {
751         wmKeyMapItem *kmi;
752         /* only size needs to follow zoom, strength shows fixed size circle */
753         int flags_nozoom = flags & (~RC_ZOOM);
754
755         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
756         set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags);
757
758         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
759         set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags_nozoom);
760
761         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0);
762         set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags_nozoom);
763
764         if (flags & RC_ROTATION) {
765                 kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
766                 set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags_nozoom);
767         }
768 }
769
770 static void paint_partial_visibility_keys(wmKeyMap *keymap)
771 {
772         wmKeyMapItem *kmi;
773         
774         /* Partial visibility */
775         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_SHIFT, 0);
776         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
777         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
778         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, 0, 0);
779         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_HIDE);
780         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
781         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_ALT, 0);
782         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
783         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_ALL);
784 }
785
786 void ED_keymap_paint(wmKeyConfig *keyconf)
787 {
788         wmKeyMap *keymap;
789         wmKeyMapItem *kmi;
790         int i;
791         
792         /* Sculpt mode */
793         keymap = WM_keymap_find(keyconf, "Sculpt", 0, 0);
794         keymap->poll = sculpt_mode_poll;
795
796         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
797         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
798         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
799
800         /* Partial visibility, sculpt-only for now */
801         paint_partial_visibility_keys(keymap);
802
803         for (i = 0; i <= 5; i++)
804                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
805
806         /* Clear mask */
807         kmi = WM_keymap_add_item(keymap, "PAINT_OT_mask_flood_fill", MKEY, KM_PRESS, KM_ALT, 0);
808         RNA_enum_set(kmi->ptr, "mode", PAINT_MASK_FLOOD_VALUE);
809         RNA_float_set(kmi->ptr, "value", 0);
810
811         /* Invert mask */
812         kmi = WM_keymap_add_item(keymap, "PAINT_OT_mask_flood_fill", IKEY, KM_PRESS, KM_CTRL, 0);
813         RNA_enum_set(kmi->ptr, "mode", PAINT_MASK_INVERT);
814
815         /* Toggle dynamic topology */
816         WM_keymap_add_item(keymap, "SCULPT_OT_dynamic_topology_toggle", DKEY, KM_PRESS, KM_CTRL, 0);
817
818         /* Dynamic-topology detail size
819          * 
820          * This should be improved further, perhaps by showing a triangle
821          * grid rather than brush alpha */
822         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", DKEY, KM_PRESS, KM_SHIFT, 0);
823         set_brush_rc_props(kmi->ptr, "sculpt", "detail_size", NULL, 0);
824         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.sculpt.detail_size");
825
826         /* multires switch */
827         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
828         RNA_int_set(kmi->ptr, "level", 1);
829         RNA_boolean_set(kmi->ptr, "relative", TRUE);
830
831         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
832         RNA_int_set(kmi->ptr, "level", -1);
833         RNA_boolean_set(kmi->ptr, "relative", TRUE);
834
835         ed_keymap_paint_brush_switch(keymap, "sculpt");
836         ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
837         ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
838
839         ed_keymap_stencil(keymap);
840
841         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_DRAW, DKEY, 0);
842         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SMOOTH, SKEY, 0);
843         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_PINCH, PKEY, 0);
844         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_INFLATE, IKEY, 0);
845         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_GRAB, GKEY, 0);
846         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_LAYER, LKEY, 0);
847         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_FLATTEN, TKEY, KM_SHIFT);
848         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CLAY, CKEY, 0);
849         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CREASE, CKEY, KM_SHIFT);
850         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SNAKE_HOOK, KKEY, 0);
851         kmi = keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_MASK, MKEY, 0);
852         RNA_boolean_set(kmi->ptr, "toggle", 1);
853         RNA_boolean_set(kmi->ptr, "create_missing", 1);
854
855         /* */
856         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
857         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.sculpt_stroke_method");
858
859         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
860         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
861
862         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
863         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
864
865         /* Vertex Paint mode */
866         keymap = WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
867         keymap->poll = vertex_paint_mode_poll;
868
869         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
870         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", SKEY, KM_PRESS, 0, 0);
871
872         WM_keymap_add_item(keymap,
873                            "PAINT_OT_vertex_color_set", KKEY, KM_PRESS, KM_SHIFT, 0);
874
875         ed_keymap_paint_brush_switch(keymap, "vertex_paint");
876         ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
877         ed_keymap_paint_brush_radial_control(keymap, "vertex_paint", RC_COLOR | RC_ROTATION);
878
879         ed_keymap_stencil(keymap);
880
881         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
882         RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
883
884         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
885         RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.use_smooth_stroke");
886
887         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
888         RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.texture_angle_source_random");
889
890         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
891         RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.stroke_method");
892
893         /* Weight Paint mode */
894         keymap = WM_keymap_find(keyconf, "Weight Paint", 0, 0);
895         keymap->poll = weight_paint_mode_poll;
896
897         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
898
899         /* these keys are from 2.4x but could be changed */
900         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0);
901         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
902
903         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT, 0)->ptr,           "type", WPAINT_GRADIENT_TYPE_LINEAR);
904         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_weight_gradient", LEFTMOUSE, KM_PRESS, KM_ALT | KM_CTRL, 0)->ptr, "type", WPAINT_GRADIENT_TYPE_RADIAL);
905
906         WM_keymap_add_item(keymap,
907                            "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
908
909         ed_keymap_paint_brush_switch(keymap, "weight_paint");
910         ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
911         ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
912
913         ed_keymap_stencil(keymap);
914
915         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
916         RNA_string_set(kmi->ptr, "data_path", "tool_settings.vertex_paint.brush.stroke_method");
917
918         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* face mask toggle */
919         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
920
921         /* note, conflicts with vertex paint, but this is more useful */
922         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
923         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
924
925         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
926
927         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
928         RNA_string_set(kmi->ptr, "data_path", "tool_settings.weight_paint.brush.use_smooth_stroke");
929
930         /*Weight paint's Vertex Selection Mode */
931         keymap = WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
932         keymap->poll = vert_paint_poll;
933         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
934         kmi = WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
935         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
936         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
937         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
938         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
939         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
940         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
941         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
942
943         /* Image/Texture Paint mode */
944         keymap = WM_keymap_find(keyconf, "Image Paint", 0, 0);
945         keymap->poll = image_texture_paint_poll;
946
947         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
948         RNA_enum_set(WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
949         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
950         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", SKEY, KM_PRESS, 0, 0);
951
952         ed_keymap_paint_brush_switch(keymap, "image_paint");
953         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
954         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR | RC_ZOOM | RC_ROTATION);
955
956         ed_keymap_stencil(keymap);
957
958         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
959         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
960
961         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
962         RNA_string_set(kmi->ptr, "data_path", "tool_settings.image_paint.brush.use_smooth_stroke");
963
964         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
965         RNA_string_set(kmi->ptr, "data_path", "tool_settings.image_paint.brush.texture_angle_source_random");
966
967         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
968         RNA_string_set(kmi->ptr, "data_path", "tool_settings.image_paint.brush.stroke_method");
969
970         /* face-mask mode */
971         keymap = WM_keymap_find(keyconf, "Face Mask", 0, 0);
972         keymap->poll = facemask_paint_poll;
973
974         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
975         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
976         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
977         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
978         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
979         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
980         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
981         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
982
983         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
984         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
985
986         keymap = WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
987         keymap->poll = uv_sculpt_poll;
988
989         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
990         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
991
992         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
993         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
994         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
995
996         ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
997         ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
998
999         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_RELAX);
1000         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_PINCH);
1001         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_uv_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", UV_SCULPT_TOOL_GRAB);
1002
1003         /* paint stroke */
1004         keymap = paint_stroke_modal_keymap(keyconf);
1005         WM_modalkeymap_assign(keymap, "SCULPT_OT_brush_stroke");
1006 }