svn merge ^/trunk/blender -r44562:HEAD
[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         {
220                 if ((brush->ob_mode & ob_mode) &&
221                     (brush_tool(brush, tool_offset) == tool)) {
222                         return brush;
223                 }
224         }
225
226         return NULL;
227 }
228
229 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
230 {
231         struct Brush *brush, *brush_orig = paint_brush(paint);
232
233         brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
234
235         if (brush) {
236                 paint_brush_set(paint, brush);
237                 WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
238                 return OPERATOR_FINISHED;
239         }
240         else {
241                 return OPERATOR_CANCELLED;
242         }
243 }
244
245 /* used in the PAINT_OT_brush_select operator */
246 #define OB_MODE_ACTIVE 0
247
248 static int brush_select_exec(bContext *C, wmOperator *op)
249 {
250         Main *bmain = CTX_data_main(C);
251         ToolSettings *toolsettings = CTX_data_tool_settings(C);
252         Paint *paint = NULL;
253         int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
254         size_t tool_offset;
255
256         if (paint_mode == OB_MODE_ACTIVE) {
257                 Object *ob = CTX_data_active_object(C);
258                 if (ob) {
259                         /* select current paint mode */
260                         paint_mode = ob->mode &
261                                      (OB_MODE_SCULPT |
262                                       OB_MODE_VERTEX_PAINT |
263                                       OB_MODE_WEIGHT_PAINT |
264                                       OB_MODE_TEXTURE_PAINT);
265                 }
266                 else {
267                         return OPERATOR_CANCELLED;
268                 }
269         }
270
271         switch (paint_mode) {
272                 case OB_MODE_SCULPT:
273                         paint = &toolsettings->sculpt->paint;
274                         tool_offset = offsetof(Brush, sculpt_tool);
275                         tool = RNA_enum_get(op->ptr, "sculpt_tool");
276                         break;
277                 case OB_MODE_VERTEX_PAINT:
278                         paint = &toolsettings->vpaint->paint;
279                         tool_offset = offsetof(Brush, vertexpaint_tool);
280                         tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
281                         break;
282                 case OB_MODE_WEIGHT_PAINT:
283                         paint = &toolsettings->wpaint->paint;
284                         /* vertexpaint_tool is used for weight paint mode */
285                         tool_offset = offsetof(Brush, vertexpaint_tool);
286                         tool = RNA_enum_get(op->ptr, "weight_paint_tool");
287                         break;
288                 case OB_MODE_TEXTURE_PAINT:
289                         paint = &toolsettings->imapaint.paint;
290                         tool_offset = offsetof(Brush, imagepaint_tool);
291                         tool = RNA_enum_get(op->ptr, "texture_paint_tool");
292                         break;
293                 default:
294                         /* invalid paint mode */
295                         return OPERATOR_CANCELLED;
296         }
297
298         return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
299 }
300
301 static void PAINT_OT_brush_select(wmOperatorType *ot)
302 {
303         static EnumPropertyItem paint_mode_items[] = {
304                 {OB_MODE_ACTIVE, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
305                 {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
306                 {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
307                 {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
308                 {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
309                 {0, NULL, 0, NULL, NULL}
310         };
311
312         /* identifiers */
313         ot->name = "Brush Select";
314         ot->description = "Select a paint mode's brush by tool type";
315         ot->idname = "PAINT_OT_brush_select";
316
317         /* api callbacks */
318         ot->exec = brush_select_exec;
319
320         /* flags */
321         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
322
323         /* props */
324         RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, OB_MODE_ACTIVE, "Paint Mode", "");
325         RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", "");
326         RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
327         RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
328         RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
329 }
330
331 static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
332                                          int tool, int keymap_type,
333                                          int keymap_modifier)
334 {
335         wmKeyMapItem *kmi;
336         kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select",
337                                  keymap_type, KM_PRESS, keymap_modifier, 0);
338
339         RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
340         
341         switch (paint_mode) {
342                 case OB_MODE_SCULPT:
343                         RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
344                         break;
345                 case OB_MODE_VERTEX_PAINT:
346                         RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
347                         break;
348                 case OB_MODE_WEIGHT_PAINT:
349                         RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
350                         break;
351                 case OB_MODE_TEXTURE_PAINT:
352                         RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
353                         break;
354         }
355
356         return kmi;
357 }
358
359 static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
360 {
361         Brush *brush;
362         Scene *scene = CTX_data_scene(C);
363         ToolSettings *ts = scene->toolsettings;
364         ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
365         brush = ts->uvsculpt->paint.brush;
366         /* To update toolshelf */
367         WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
368
369         return OPERATOR_FINISHED;
370 }
371
372 static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
373 {
374         /* from rna_scene.c */
375         extern EnumPropertyItem uv_sculpt_tool_items[];
376         /* identifiers */
377         ot->name = "UV Sculpt Tool Set";
378         ot->description = "Set the UV sculpt tool";
379         ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
380
381         /* api callbacks */
382         ot->exec = brush_uv_sculpt_tool_set_exec;
383         ot->poll = uv_sculpt_poll;
384
385         /* flags */
386         ot->flag = 0;
387
388         /* props */
389         ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
390 }
391
392 /**************************** registration **********************************/
393
394 void ED_operatortypes_paint(void)
395 {
396         /* brush */
397         WM_operatortype_append(BRUSH_OT_add);
398         WM_operatortype_append(BRUSH_OT_scale_size);
399         WM_operatortype_append(BRUSH_OT_curve_preset);
400         WM_operatortype_append(BRUSH_OT_reset);
401
402         /* note, particle uses a different system, can be added with existing operators in wm.py */
403         WM_operatortype_append(PAINT_OT_brush_select);
404         WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
405
406         /* image */
407         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
408         WM_operatortype_append(PAINT_OT_image_paint);
409         WM_operatortype_append(PAINT_OT_sample_color);
410         WM_operatortype_append(PAINT_OT_grab_clone);
411         WM_operatortype_append(PAINT_OT_clone_cursor_set);
412         WM_operatortype_append(PAINT_OT_project_image);
413         WM_operatortype_append(PAINT_OT_image_from_view);
414
415         /* weight */
416         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
417         WM_operatortype_append(PAINT_OT_weight_paint);
418         WM_operatortype_append(PAINT_OT_weight_set);
419         WM_operatortype_append(PAINT_OT_weight_from_bones);
420         WM_operatortype_append(PAINT_OT_weight_sample);
421         WM_operatortype_append(PAINT_OT_weight_sample_group);
422
423         /* uv */
424         WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
425
426         /* vertex selection */
427         WM_operatortype_append(PAINT_OT_vert_select_all);
428         WM_operatortype_append(PAINT_OT_vert_select_inverse);
429
430         /* vertex */
431         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
432         WM_operatortype_append(PAINT_OT_vertex_paint);
433         WM_operatortype_append(PAINT_OT_vertex_color_set);
434
435         /* face-select */
436         WM_operatortype_append(PAINT_OT_face_select_linked);
437         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
438         WM_operatortype_append(PAINT_OT_face_select_all);
439         WM_operatortype_append(PAINT_OT_face_select_inverse);
440         WM_operatortype_append(PAINT_OT_face_select_hide);
441         WM_operatortype_append(PAINT_OT_face_select_reveal);
442
443         /* partial visibility */
444         WM_operatortype_append(PAINT_OT_hide_show);
445 }
446
447
448 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
449 {
450         wmKeyMapItem *kmi;
451         int i;
452         /* index 0-9 (zero key is tenth), shift key for index 10-19 */
453         for (i = 0; i < 20; i++) {
454                 kmi = WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
455                                          ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
456                 RNA_string_set(kmi->ptr, "mode", mode);
457                 RNA_int_set(kmi->ptr, "index", i);
458         }
459 }
460
461 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
462 {
463         wmKeyMapItem *kmi;
464
465         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
466         RNA_float_set(kmi->ptr, "scalar", 0.9);
467
468         kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
469         RNA_float_set(kmi->ptr, "scalar", 10.0 / 9.0); // 1.1111....
470 }
471
472 typedef enum {
473         RC_COLOR = 1,
474         RC_ROTATION = 2,
475         RC_ZOOM = 4,
476 } RCFlags;
477
478 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
479                               const char *output_name, const char *input_name)
480 {
481         char *path;
482
483         path = BLI_sprintfN("%s.%s", brush_path, input_name);
484         RNA_string_set(ptr, output_name, path);
485         MEM_freeN(path);
486 }
487
488 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
489                                const char *prop, const char *secondary_prop,
490                                RCFlags flags)
491 {
492         const char *ups_path = "tool_settings.unified_paint_settings";
493         char *brush_path;
494
495         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
496
497         set_brush_rc_path(ptr, brush_path, "data_path_primary", prop);
498         if (secondary_prop) {
499                 set_brush_rc_path(ptr, ups_path, "use_secondary", secondary_prop);
500                 set_brush_rc_path(ptr, ups_path, "data_path_secondary", prop);
501         }
502         else {
503                 RNA_string_set(ptr, "use_secondary", "");
504                 RNA_string_set(ptr, "data_path_secondary", "");
505         }
506         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
507         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
508         RNA_string_set(ptr, "image_id", brush_path);
509
510         if (flags & RC_COLOR)
511                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
512         else
513                 RNA_string_set(ptr, "fill_color_path", "");
514         if (flags & RC_ZOOM)
515                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
516         else
517                 RNA_string_set(ptr, "zoom_path", "");
518
519         MEM_freeN(brush_path);
520 }
521
522 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
523                                                  RCFlags flags)
524 {
525         wmKeyMapItem *kmi;
526
527         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
528         set_brush_rc_props(kmi->ptr, paint, "size", "use_unified_size", flags);
529
530         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
531         set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags);
532
533         if (flags & RC_ROTATION) {
534                 kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
535                 set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags);
536         }
537 }
538
539 void paint_partial_visibility_keys(wmKeyMap *keymap)
540 {
541         wmKeyMapItem *kmi;
542         
543         /* Partial visiblity */
544         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_SHIFT, 0);
545         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
546         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
547         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, 0, 0);
548         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_HIDE);
549         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
550         kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_ALT, 0);
551         RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
552         RNA_enum_set(kmi->ptr, "area", PARTIALVIS_ALL);
553 }
554
555 void ED_keymap_paint(wmKeyConfig *keyconf)
556 {
557         wmKeyMap *keymap;
558         wmKeyMapItem *kmi;
559         int i;
560         
561         /* Sculpt mode */
562         keymap = WM_keymap_find(keyconf, "Sculpt", 0, 0);
563         keymap->poll = sculpt_poll;
564
565         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
566         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
567         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
568
569         /* Partial visibility, sculpt-only for now */
570         paint_partial_visibility_keys(keymap);
571
572         for (i = 0; i <= 5; i++)
573                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
574
575         /* multires switch */
576         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
577         RNA_int_set(kmi->ptr, "level", 1);
578         RNA_boolean_set(kmi->ptr, "relative", TRUE);
579
580         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
581         RNA_int_set(kmi->ptr, "level", -1);
582         RNA_boolean_set(kmi->ptr, "relative", TRUE);
583
584         ed_keymap_paint_brush_switch(keymap, "sculpt");
585         ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
586         ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
587
588         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_DRAW, DKEY, 0);
589         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SMOOTH, SKEY, 0);
590         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_PINCH, PKEY, 0);
591         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_INFLATE, IKEY, 0);
592         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_GRAB, GKEY, 0);
593         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_LAYER, LKEY, 0);
594         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_FLATTEN, TKEY, KM_SHIFT);
595         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CLAY, CKEY, 0);
596         keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CREASE, CKEY, KM_SHIFT);
597
598         /* */
599         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
600         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");
601
602         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
603         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
604
605         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
606         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
607
608         /* Vertex Paint mode */
609         keymap = WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
610         keymap->poll = vertex_paint_mode_poll;
611
612         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
613         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
614
615         WM_keymap_add_item(keymap,
616                            "PAINT_OT_vertex_color_set", KKEY, KM_PRESS, KM_SHIFT, 0);
617
618         ed_keymap_paint_brush_switch(keymap, "vertex_paint");
619         ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
620         ed_keymap_paint_brush_radial_control(keymap, "vertex_paint", RC_COLOR);
621
622         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
623         RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
624
625         /* Weight Paint mode */
626         keymap = WM_keymap_find(keyconf, "Weight Paint", 0, 0);
627         keymap->poll = weight_paint_mode_poll;
628
629         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
630
631         /* these keys are from 2.4x but could be changed */
632         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
633         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
634
635         WM_keymap_add_item(keymap,
636                            "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
637
638         ed_keymap_paint_brush_switch(keymap, "weight_paint");
639         ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
640         ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
641
642         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* face mask toggle */
643         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
644
645         /* note, conflicts with vertex paint, but this is more useful */
646         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
647         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
648
649         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
650
651         
652         /*Weight paint's Vertex Selection Mode */
653         keymap = WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
654         keymap->poll = vert_paint_poll;
655         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
656         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
657         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
658         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
659         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
660         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
661         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
662         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
663
664         /* Image/Texture Paint mode */
665         keymap = WM_keymap_find(keyconf, "Image Paint", 0, 0);
666         keymap->poll = image_texture_paint_poll;
667
668         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
669         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
670         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
671         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
672
673         ed_keymap_paint_brush_switch(keymap, "image_paint");
674         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
675         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR | RC_ZOOM);
676
677         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
678         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
679
680         /* face-mask mode */
681         keymap = WM_keymap_find(keyconf, "Face Mask", 0, 0);
682         keymap->poll = facemask_paint_poll;
683
684         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
685         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
686         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
687         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
688         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
689         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
690         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
691
692         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
693         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
694
695         keymap = WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
696         keymap->poll = uv_sculpt_poll;
697
698         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
699         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
700
701         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
702         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
703         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
704
705         ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
706         ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
707
708         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);
709         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);
710         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);
711
712 }