style cleanup: follow style guide for formatting of if/for/while loops, and else...
[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_string.h"
29 #include "BLI_utildefines.h"
30
31 #include "DNA_object_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_brush_types.h"
34
35 #include "BKE_brush.h"
36 #include "BKE_context.h"
37 #include "BKE_paint.h"
38 #include "BKE_main.h"
39
40 #include "ED_sculpt.h"
41 #include "ED_screen.h"
42 #include "UI_resources.h"
43
44 #include "WM_api.h"
45 #include "WM_types.h"
46
47 #include "RNA_access.h"
48 #include "RNA_define.h"
49 #include "RNA_enum_types.h"
50
51 #include "paint_intern.h"
52 #include "sculpt_intern.h"
53
54 #include <string.h>
55 //#include <stdio.h>
56 #include <stddef.h>
57
58 /* Brush operators */
59 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
60 {
61         /*int type = RNA_enum_get(op->ptr, "type");*/
62         Paint *paint = paint_get_active(CTX_data_scene(C));
63         struct Brush *br = paint_brush(paint);
64
65         if (br)
66                 br = copy_brush(br);
67         else
68                 br = add_brush("Brush");
69
70         paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
71
72         return OPERATOR_FINISHED;
73 }
74
75 static void BRUSH_OT_add(wmOperatorType *ot)
76 {
77         /* identifiers */
78         ot->name = "Add Brush";
79         ot->description = "Add brush by mode type";
80         ot->idname = "BRUSH_OT_add";
81         
82         /* api callbacks */
83         ot->exec = brush_add_exec;
84         
85         /* flags */
86         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
87 }
88
89
90 static int brush_scale_size_exec(bContext *C, wmOperator *op)
91 {
92         Scene *scene = CTX_data_scene(C);
93         Paint  *paint=  paint_get_active(scene);
94         struct Brush  *brush=  paint_brush(paint);
95         // Object *ob=     CTX_data_active_object(C);
96         float   scalar= RNA_float_get(op->ptr, "scalar");
97
98         if (brush) {
99                 // pixel radius
100                 {
101                         const int old_size= brush_size(scene, brush);
102                         int size= (int)(scalar*old_size);
103
104                         if (old_size == size) {
105                                 if (scalar > 1) {
106                                         size++;
107                                 }
108                                 else if (scalar < 1) {
109                                         size--;
110                                 }
111                         }
112                         CLAMP(size, 1, 2000); // XXX magic number
113
114                         brush_set_size(scene, brush, size);
115                 }
116
117                 // unprojected radius
118                 {
119                         float unprojected_radius= scalar*brush_unprojected_radius(scene, brush);
120
121                         if (unprojected_radius < 0.001f) // XXX magic number
122                                 unprojected_radius= 0.001f;
123
124                         brush_set_unprojected_radius(scene, brush, unprojected_radius);
125                 }
126         }
127
128         return OPERATOR_FINISHED;
129 }
130
131 static void BRUSH_OT_scale_size(wmOperatorType *ot)
132 {
133         /* identifiers */
134         ot->name = "Scale Sculpt/Paint Brush Size";
135         ot->description = "Change brush size by a scalar";
136         ot->idname = "BRUSH_OT_scale_size";
137         
138         /* api callbacks */
139         ot->exec = brush_scale_size_exec;
140         
141         /* flags */
142         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
143
144         RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
145 }
146
147 static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
148 {
149         Scene *scene = CTX_data_scene(C);
150         Object *obact = CTX_data_active_object(C);
151         unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint);
152         vpaint_fill(obact, paintcol);
153         
154         ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
155         return OPERATOR_FINISHED;
156 }
157
158 static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
159 {
160         /* identifiers */
161         ot->name = "Set Vertex Colors";
162         ot->idname = "PAINT_OT_vertex_color_set";
163         
164         /* api callbacks */
165         ot->exec = vertex_color_set_exec;
166         ot->poll = vertex_paint_mode_poll;
167         
168         /* flags */
169         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
170 }
171
172 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
173 {
174         Paint *paint = paint_get_active(CTX_data_scene(C));
175         struct Brush *brush = paint_brush(paint);
176         Object *ob = CTX_data_active_object(C);
177
178         if (!ob) return OPERATOR_CANCELLED;
179
180         if (ob->mode & OB_MODE_SCULPT)
181                 brush_reset_sculpt(brush);
182         /* TODO: other modes */
183
184         return OPERATOR_FINISHED;
185 }
186
187 static void BRUSH_OT_reset(wmOperatorType *ot)
188 {
189         /* identifiers */
190         ot->name = "Reset Brush";
191         ot->description = "Return brush to defaults based on current tool";
192         ot->idname = "BRUSH_OT_reset";
193         
194         /* api callbacks */
195         ot->exec = brush_reset_exec;
196         
197         /* flags */
198         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
199 }
200
201 static int brush_tool(const Brush *brush, size_t tool_offset)
202 {
203         return *(((char *)brush) + tool_offset);
204 }
205
206 /* generic functions for setting the active brush based on the tool */
207 static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
208 {
209         struct Brush *brush;
210
211         if (!brush_orig && !(brush_orig= bmain->brush.first)) {
212                 return NULL;
213         }
214
215         /* get the next brush with the active tool */
216         for (brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
217                 brush != brush_orig;
218                 brush= brush->id.next ? brush->id.next : bmain->brush.first) {
219                 if ((brush->ob_mode & ob_mode) &&
220                    (brush_tool(brush, tool_offset) == tool)) {
221                         return brush;
222                 }
223         }
224
225         return NULL;
226 }
227
228 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
229 {
230         struct Brush *brush, *brush_orig= paint_brush(paint);
231
232         brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
233
234         if (brush) {
235                 paint_brush_set(paint, brush);
236                 WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
237                 return OPERATOR_FINISHED;
238         }
239         else {
240                 return OPERATOR_CANCELLED;
241         }
242 }
243
244 /* used in the PAINT_OT_brush_select operator */
245 #define OB_MODE_ACTIVE 0
246
247 static int brush_select_exec(bContext *C, wmOperator *op)
248 {
249         Main *bmain= CTX_data_main(C);
250         ToolSettings *toolsettings= CTX_data_tool_settings(C);
251         Paint *paint= NULL;
252         int tool, paint_mode= RNA_enum_get(op->ptr, "paint_mode");
253         size_t tool_offset;
254
255         if (paint_mode == OB_MODE_ACTIVE) {
256                 /* select current paint mode */
257                 paint_mode = CTX_data_active_object(C)->mode &
258                         (OB_MODE_SCULPT|
259                          OB_MODE_VERTEX_PAINT|
260                          OB_MODE_WEIGHT_PAINT|
261                          OB_MODE_TEXTURE_PAINT);
262         }
263
264         switch(paint_mode) {
265         case OB_MODE_SCULPT:
266                 paint= &toolsettings->sculpt->paint;
267                 tool_offset= offsetof(Brush, sculpt_tool);
268                 tool= RNA_enum_get(op->ptr, "sculpt_tool");
269                 break;
270         case OB_MODE_VERTEX_PAINT:
271                 paint= &toolsettings->vpaint->paint;
272                 tool_offset= offsetof(Brush, vertexpaint_tool);
273                 tool= RNA_enum_get(op->ptr, "vertex_paint_tool");
274                 break;
275         case OB_MODE_WEIGHT_PAINT:
276                 paint= &toolsettings->wpaint->paint;
277                 /* vertexpaint_tool is used for weight paint mode */
278                 tool_offset= offsetof(Brush, vertexpaint_tool);
279                 tool= RNA_enum_get(op->ptr, "weight_paint_tool");
280                 break;
281         case OB_MODE_TEXTURE_PAINT:
282                 paint= &toolsettings->imapaint.paint;
283                 tool_offset= offsetof(Brush, imagepaint_tool);
284                 tool= RNA_enum_get(op->ptr, "texture_paint_tool");
285                 break;
286         default:
287                 /* invalid paint mode */
288                 return OPERATOR_CANCELLED;
289         }
290
291         return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
292 }
293
294 static void PAINT_OT_brush_select(wmOperatorType *ot)
295 {
296         static EnumPropertyItem paint_mode_items[] = {
297                 {OB_MODE_ACTIVE, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
298                 {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
299                 {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
300                 {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
301                 {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
302                 {0, NULL, 0, NULL, NULL}};
303
304         /* identifiers */
305         ot->name = "Brush Select";
306         ot->description = "Select a paint mode's brush by tool type";
307         ot->idname = "PAINT_OT_brush_select";
308
309         /* api callbacks */
310         ot->exec = brush_select_exec;
311
312         /* flags */
313         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
314
315         /* props */
316         RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, OB_MODE_ACTIVE, "Paint Mode", "");
317         RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", "");
318         RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
319         RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
320         RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
321 }
322
323 static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
324                                                                                  int tool, int keymap_type,
325                                                                                  int keymap_modifier)
326 {
327         wmKeyMapItem *kmi;
328         kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select",
329                                                          keymap_type, KM_PRESS, keymap_modifier, 0);
330
331         RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
332         
333         switch(paint_mode) {
334         case OB_MODE_SCULPT:
335                 RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
336                 break;
337         case OB_MODE_VERTEX_PAINT:
338                 RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
339                 break;
340         case OB_MODE_WEIGHT_PAINT:
341                 RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
342                 break;
343         case OB_MODE_TEXTURE_PAINT:
344                 RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
345                 break;
346         }
347
348         return kmi;
349 }
350
351 static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
352 {
353         Brush *brush;
354         Scene *scene= CTX_data_scene(C);
355         ToolSettings *ts = scene->toolsettings;
356         ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
357         brush = ts->uvsculpt->paint.brush;
358         /* To update toolshelf */
359         WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush);
360
361         return OPERATOR_FINISHED;
362 }
363
364 static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
365 {
366         /* from rna_scene.c */
367         extern EnumPropertyItem uv_sculpt_tool_items[];
368         /* identifiers */
369         ot->name = "UV Sculpt Tool Set";
370         ot->description = "Set the UV sculpt tool";
371         ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
372
373         /* api callbacks */
374         ot->exec = brush_uv_sculpt_tool_set_exec;
375         ot->poll = uv_sculpt_poll;
376
377         /* flags */
378         ot->flag = 0;
379
380         /* props */
381         ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
382 }
383
384 /**************************** registration **********************************/
385
386 void ED_operatortypes_paint(void)
387 {
388         /* brush */
389         WM_operatortype_append(BRUSH_OT_add);
390         WM_operatortype_append(BRUSH_OT_scale_size);
391         WM_operatortype_append(BRUSH_OT_curve_preset);
392         WM_operatortype_append(BRUSH_OT_reset);
393
394         /* note, particle uses a different system, can be added with existing operators in wm.py */
395         WM_operatortype_append(PAINT_OT_brush_select);
396         WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
397
398         /* image */
399         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
400         WM_operatortype_append(PAINT_OT_image_paint);
401         WM_operatortype_append(PAINT_OT_sample_color);
402         WM_operatortype_append(PAINT_OT_grab_clone);
403         WM_operatortype_append(PAINT_OT_clone_cursor_set);
404         WM_operatortype_append(PAINT_OT_project_image);
405         WM_operatortype_append(PAINT_OT_image_from_view);
406
407         /* weight */
408         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
409         WM_operatortype_append(PAINT_OT_weight_paint);
410         WM_operatortype_append(PAINT_OT_weight_set);
411         WM_operatortype_append(PAINT_OT_weight_from_bones);
412         WM_operatortype_append(PAINT_OT_weight_sample);
413         WM_operatortype_append(PAINT_OT_weight_sample_group);
414
415         /* uv */
416         WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
417
418         /* vertex selection */
419         WM_operatortype_append(PAINT_OT_vert_select_all);
420         WM_operatortype_append(PAINT_OT_vert_select_inverse);
421
422         /* vertex */
423         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
424         WM_operatortype_append(PAINT_OT_vertex_paint);
425         WM_operatortype_append(PAINT_OT_vertex_color_set);
426
427         /* face-select */
428         WM_operatortype_append(PAINT_OT_face_select_linked);
429         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
430         WM_operatortype_append(PAINT_OT_face_select_all);
431         WM_operatortype_append(PAINT_OT_face_select_inverse);
432         WM_operatortype_append(PAINT_OT_face_select_hide);
433         WM_operatortype_append(PAINT_OT_face_select_reveal);
434
435         /* partial visibility */
436         WM_operatortype_append(PAINT_OT_hide_show);
437 }
438
439
440 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
441 {
442         wmKeyMapItem *kmi;
443         int i;
444         /* index 0-9 (zero key is tenth), shift key for index 10-19 */
445         for (i = 0; i < 20; i++) {
446                 kmi = WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
447                                         ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
448                 RNA_string_set(kmi->ptr, "mode", mode);
449                 RNA_int_set(kmi->ptr, "index", i);
450         }
451 }
452
453 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
454 {
455         wmKeyMapItem *kmi;
456
457         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
458         RNA_float_set(kmi->ptr, "scalar", 0.9);
459
460         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
461         RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
462 }
463
464 typedef enum {
465         RC_COLOR = 1,
466         RC_ROTATION = 2,
467         RC_ZOOM = 4,
468 } RCFlags;
469
470 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
471                                                           const char *output_name, const char *input_name)
472 {
473         char *path;
474
475         path = BLI_sprintfN("%s.%s", brush_path, input_name);
476         RNA_string_set(ptr, output_name, path);
477         MEM_freeN(path);
478 }
479
480 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
481                                                            const char *prop, const char *secondary_prop,
482                                                            RCFlags flags)
483 {
484         const char *ups_path = "tool_settings.unified_paint_settings";
485         char *brush_path;
486
487         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
488
489         set_brush_rc_path(ptr, brush_path, "data_path_primary", prop);
490         if (secondary_prop) {
491                 set_brush_rc_path(ptr, ups_path, "use_secondary", secondary_prop);
492                 set_brush_rc_path(ptr, ups_path, "data_path_secondary", prop);
493         }
494         else {
495                 RNA_string_set(ptr, "use_secondary", "");
496                 RNA_string_set(ptr, "data_path_secondary", "");
497         }
498         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
499         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
500         RNA_string_set(ptr, "image_id", brush_path);
501
502         if (flags & RC_COLOR)
503                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
504         else
505                 RNA_string_set(ptr, "fill_color_path", "");
506         if (flags & RC_ZOOM)
507                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
508         else
509                 RNA_string_set(ptr, "zoom_path", "");
510
511         MEM_freeN(brush_path);
512 }
513
514 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
515                                                  RCFlags flags)
516 {
517         wmKeyMapItem *kmi;
518
519         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
520         set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags);
521
522         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
523         set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags);
524
525         if (flags & RC_ROTATION) {
526                 kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
527                 set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags);
528         }
529 }
530
531 void paint_partial_visibility_keys(wmKeyMap *keymap)
532 {
533         wmKeyMapItem *kmi;
534         
535         /* Partial visiblity */
536         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_SHIFT, 0);
537         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
538         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
539         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, 0, 0);
540         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_HIDE);
541         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
542         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_ALT, 0);
543         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
544         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_ALL);
545 }
546
547 void ED_keymap_paint(wmKeyConfig *keyconf)
548 {
549         wmKeyMap *keymap;
550         wmKeyMapItem *kmi;
551         int i;
552         
553         /* Sculpt mode */
554         keymap = WM_keymap_find(keyconf, "Sculpt", 0, 0);
555         keymap->poll = sculpt_poll;
556
557         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
558         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
559         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
560
561         /* Partial visibility, sculpt-only for now */
562         paint_partial_visibility_keys(keymap);
563
564         for (i=0; i<=5; i++)
565                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
566
567         /* multires switch */
568         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
569         RNA_int_set(kmi->ptr, "level", 1);
570         RNA_boolean_set(kmi->ptr, "relative", TRUE);
571
572         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
573         RNA_int_set(kmi->ptr, "level", -1);
574         RNA_boolean_set(kmi->ptr, "relative", TRUE);
575
576         ed_keymap_paint_brush_switch(keymap, "sculpt");
577         ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
578         ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
579
580         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_DRAW, DKEY, 0);
581         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SMOOTH, SKEY, 0);
582         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_PINCH, PKEY, 0);
583         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_INFLATE, IKEY, 0);
584         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_GRAB, GKEY, 0);
585         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_LAYER, LKEY, 0);
586         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_FLATTEN, TKEY, KM_SHIFT);
587         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CLAY, CKEY, 0);
588         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CREASE, CKEY, KM_SHIFT);
589
590         /* */
591         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
592         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");
593
594         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
595         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
596
597         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
598         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
599
600         /* Vertex Paint mode */
601         keymap = WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
602         keymap->poll = vertex_paint_mode_poll;
603
604         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
605         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
606
607         WM_keymap_add_item(keymap,
608                         "PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
609
610         ed_keymap_paint_brush_switch(keymap, "vertex_paint");
611         ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
612         ed_keymap_paint_brush_radial_control(keymap, "vertex_paint", RC_COLOR);
613
614         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
615         RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
616
617         /* Weight Paint mode */
618         keymap = WM_keymap_find(keyconf, "Weight Paint", 0, 0);
619         keymap->poll = weight_paint_mode_poll;
620
621         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
622
623         /* these keys are from 2.4x but could be changed */
624         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
625         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
626
627         WM_keymap_add_item(keymap,
628                         "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
629
630         ed_keymap_paint_brush_switch(keymap, "weight_paint");
631         ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
632         ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
633
634         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* face mask toggle */
635         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
636
637         /* note, conflicts with vertex paint, but this is more useful */
638         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
639         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
640
641         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
642
643         
644         /*Weight paint's Vertex Selection Mode */
645         keymap = WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
646         keymap->poll = vert_paint_poll;
647         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
648         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
649         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
650         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
651         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
652         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0);
653         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
654         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
655
656         /* Image/Texture Paint mode */
657         keymap = WM_keymap_find(keyconf, "Image Paint", 0, 0);
658         keymap->poll = image_texture_paint_poll;
659
660         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
661         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
662         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
663         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
664
665         ed_keymap_paint_brush_switch(keymap, "image_paint");
666         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
667         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
668
669         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
670         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
671
672         /* face-mask mode */
673         keymap = WM_keymap_find(keyconf, "Face Mask", 0, 0);
674         keymap->poll = facemask_paint_poll;
675
676         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
677         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
678         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
679         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
680         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
681         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
682         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
683
684         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
685         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
686
687         keymap = WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
688         keymap->poll = uv_sculpt_poll;
689
690         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
691         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
692
693         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
694         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
695         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
696
697         ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
698         ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
699
700         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);
701         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);
702         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);
703
704 }