svn merge -r37793:37865 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / sculpt_paint / paint_ops.c
1 /*
2  *
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * ***** END GPL LICENSE BLOCK *****
20  */
21
22 /** \file blender/editors/sculpt_paint/paint_ops.c
23  *  \ingroup edsculpt
24  */
25
26 #include "MEM_guardedalloc.h"
27
28 #include <stdlib.h>
29 #include "BLI_string.h"
30 #include "BLI_utildefines.h"
31
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
34 #include "DNA_brush_types.h"
35
36 #include "BKE_brush.h"
37 #include "BKE_context.h"
38 #include "BKE_paint.h"
39 #include "BKE_main.h"
40
41 #include "ED_sculpt.h"
42 #include "ED_screen.h"
43 #include "UI_resources.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "RNA_access.h"
49 #include "RNA_define.h"
50 #include "RNA_enum_types.h"
51
52 #include "paint_intern.h"
53 #include "sculpt_intern.h"
54
55 #include <string.h>
56 //#include <stdio.h>
57 #include <stddef.h>
58
59 /* Brush operators */
60 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
61 {
62         /*int type = RNA_enum_get(op->ptr, "type");*/
63         Paint *paint = paint_get_active(CTX_data_scene(C));
64         struct Brush *br = paint_brush(paint);
65
66         if (br)
67                 br = copy_brush(br);
68         else
69                 br = add_brush("Brush");
70
71         paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
72
73         return OPERATOR_FINISHED;
74 }
75
76 static void BRUSH_OT_add(wmOperatorType *ot)
77 {
78         /* identifiers */
79         ot->name= "Add Brush";
80         ot->description= "Add brush by mode type";
81         ot->idname= "BRUSH_OT_add";
82         
83         /* api callbacks */
84         ot->exec= brush_add_exec;
85         
86         /* flags */
87         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
88 }
89
90
91 static int brush_scale_size_exec(bContext *C, wmOperator *op)
92 {
93         Paint  *paint=  paint_get_active(CTX_data_scene(C));
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(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(brush, size);
115                 }
116
117                 // unprojected radius
118                 {
119                         float unprojected_radius= scalar*brush_unprojected_radius(brush);
120
121                         if (unprojected_radius < 0.001f) // XXX magic number
122                                 unprojected_radius= 0.001f;
123
124                         brush_set_unprojected_radius(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 /* generic functions for setting the active brush based on the tool */
202 static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
203 {
204         struct Brush *brush;
205
206         if(!brush_orig && !(brush_orig= bmain->brush.first)) {
207                 return NULL;
208         }
209
210         /* get the next brush with the active tool */
211         for(    brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
212                         brush != brush_orig;
213                         brush= brush->id.next ? brush->id.next : bmain->brush.first)
214         {
215                 if(     (brush->ob_mode & ob_mode) &&
216                         (*(((char *)brush) + tool_offset) == tool)
217                 ) {
218                         return brush;
219                 }
220         }
221
222         return NULL;
223
224 }
225
226 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
227 {
228         struct Brush *brush, *brush_orig= paint_brush(paint);
229
230         brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
231
232         if(brush) {
233                 paint_brush_set(paint, brush);
234                 WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
235                 return OPERATOR_FINISHED;
236         }
237         else {
238                 return OPERATOR_CANCELLED;
239         }
240 }
241
242 static int brush_sculpt_tool_set_exec(bContext *C, wmOperator *op)
243 {
244         Main *bmain= CTX_data_main(C);
245         Scene *scene= CTX_data_scene(C);
246
247         return brush_generic_tool_set(bmain, &scene->toolsettings->sculpt->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, sculpt_tool), OB_MODE_SCULPT);
248 }
249
250 static void BRUSH_OT_sculpt_tool_set(wmOperatorType *ot)
251 {
252         /* identifiers */
253         ot->name= "Sculpt Tool Set";
254         ot->description= "Set the sculpt tool";
255         ot->idname= "BRUSH_OT_sculpt_tool_set";
256
257         /* api callbacks */
258         ot->exec= brush_sculpt_tool_set_exec;
259
260         /* flags */
261         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
262
263         /* props */
264         ot->prop= RNA_def_enum(ot->srna, "tool", brush_sculpt_tool_items, 0, "Tool", "");
265 }
266
267 static int brush_vertex_tool_set_exec(bContext *C, wmOperator *op)
268 {
269         Main *bmain= CTX_data_main(C);
270         Scene *scene= CTX_data_scene(C);
271
272         return brush_generic_tool_set(bmain, &scene->toolsettings->vpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_VERTEX_PAINT);
273 }
274
275 static void BRUSH_OT_vertex_tool_set(wmOperatorType *ot)
276 {
277         /* identifiers */
278         ot->name= "Vertex Paint Tool Set";
279         ot->description= "Set the vertex paint tool";
280         ot->idname= "BRUSH_OT_vertex_tool_set";
281
282         /* api callbacks */
283         ot->exec= brush_vertex_tool_set_exec;
284
285         /* flags */
286         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
287
288         /* props */
289         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
290 }
291
292 static int brush_weight_tool_set_exec(bContext *C, wmOperator *op)
293 {
294         Main *bmain= CTX_data_main(C);
295         Scene *scene= CTX_data_scene(C);
296         /* vertexpaint_tool is used for weight paint mode */
297         return brush_generic_tool_set(bmain, &scene->toolsettings->wpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_WEIGHT_PAINT);
298 }
299
300 static void BRUSH_OT_weight_tool_set(wmOperatorType *ot)
301 {
302         /* identifiers */
303         ot->name= "Weight Paint Tool Set";
304         ot->description= "Set the weight paint tool";
305         ot->idname= "BRUSH_OT_weight_tool_set";
306
307         /* api callbacks */
308         ot->exec= brush_weight_tool_set_exec;
309
310         /* flags */
311         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
312
313         /* props */
314         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
315 }
316
317 static int brush_image_tool_set_exec(bContext *C, wmOperator *op)
318 {
319         Main *bmain= CTX_data_main(C);
320         Scene *scene= CTX_data_scene(C);
321
322         return brush_generic_tool_set(bmain, &scene->toolsettings->imapaint.paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, imagepaint_tool), OB_MODE_TEXTURE_PAINT);
323 }
324
325 static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
326 {
327         /* identifiers */
328         ot->name= "Image Paint Tool Set";
329         ot->description= "Set the image tool";
330         ot->idname= "BRUSH_OT_image_tool_set";
331
332         /* api callbacks */
333         ot->exec= brush_image_tool_set_exec;
334
335         /* flags */
336         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
337
338         /* props */
339         ot->prop= RNA_def_enum(ot->srna, "tool", brush_image_tool_items, 0, "Tool", "");
340 }
341
342
343 /**************************** registration **********************************/
344
345 void ED_operatortypes_paint(void)
346 {
347         /* brush */
348         WM_operatortype_append(BRUSH_OT_add);
349         WM_operatortype_append(BRUSH_OT_scale_size);
350         WM_operatortype_append(BRUSH_OT_curve_preset);
351         WM_operatortype_append(BRUSH_OT_reset);
352
353         /* note, particle uses a different system, can be added with existing operators in wm.py */
354         WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
355         WM_operatortype_append(BRUSH_OT_vertex_tool_set);
356         WM_operatortype_append(BRUSH_OT_weight_tool_set);
357         WM_operatortype_append(BRUSH_OT_image_tool_set);
358
359         /* image */
360         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
361         WM_operatortype_append(PAINT_OT_image_paint);
362         WM_operatortype_append(PAINT_OT_sample_color);
363         WM_operatortype_append(PAINT_OT_grab_clone);
364         WM_operatortype_append(PAINT_OT_clone_cursor_set);
365         WM_operatortype_append(PAINT_OT_project_image);
366         WM_operatortype_append(PAINT_OT_image_from_view);
367
368         /* weight */
369         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
370         WM_operatortype_append(PAINT_OT_weight_paint);
371         WM_operatortype_append(PAINT_OT_weight_set);
372         WM_operatortype_append(PAINT_OT_weight_from_bones);
373         WM_operatortype_append(PAINT_OT_weight_sample);
374         WM_operatortype_append(PAINT_OT_weight_sample_group);
375
376         /* Jason, vertex selection */
377         WM_operatortype_append(PAINT_OT_vert_select_all);
378
379         /* vertex */
380         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
381         WM_operatortype_append(PAINT_OT_vertex_paint);
382         WM_operatortype_append(PAINT_OT_vertex_color_set);
383
384         /* face-select */
385         WM_operatortype_append(PAINT_OT_face_select_linked);
386         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
387         WM_operatortype_append(PAINT_OT_face_select_all);
388         WM_operatortype_append(PAINT_OT_face_select_inverse);
389         WM_operatortype_append(PAINT_OT_face_select_hide);
390         WM_operatortype_append(PAINT_OT_face_select_reveal);
391 }
392
393
394 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
395 {
396         wmKeyMapItem *kmi;
397
398         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, 0, 0);
399         RNA_string_set(kmi->ptr, "mode", mode);
400         RNA_int_set(kmi->ptr, "index", 0);
401         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, 0, 0);
402         RNA_string_set(kmi->ptr, "mode", mode);
403         RNA_int_set(kmi->ptr, "index", 1);
404         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, 0, 0);
405         RNA_string_set(kmi->ptr, "mode", mode);
406         RNA_int_set(kmi->ptr, "index", 2);
407         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, 0, 0);
408         RNA_string_set(kmi->ptr, "mode", mode);
409         RNA_int_set(kmi->ptr, "index", 3);
410         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, 0, 0);
411         RNA_string_set(kmi->ptr, "mode", mode);
412         RNA_int_set(kmi->ptr, "index", 4);
413         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, 0, 0);
414         RNA_string_set(kmi->ptr, "mode", mode);
415         RNA_int_set(kmi->ptr, "index", 5);
416         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, 0, 0);
417         RNA_string_set(kmi->ptr, "mode", mode);
418         RNA_int_set(kmi->ptr, "index", 6);
419         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, 0, 0);
420         RNA_string_set(kmi->ptr, "mode", mode);
421         RNA_int_set(kmi->ptr, "index", 7);
422         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, 0, 0);
423         RNA_string_set(kmi->ptr, "mode", mode);
424         RNA_int_set(kmi->ptr, "index", 8);
425         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, 0, 0);
426         RNA_string_set(kmi->ptr, "mode", mode);
427         RNA_int_set(kmi->ptr, "index", 9);
428         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, KM_SHIFT, 0);
429         RNA_string_set(kmi->ptr, "mode", mode);
430         RNA_int_set(kmi->ptr, "index", 10);
431         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, KM_SHIFT, 0);
432         RNA_string_set(kmi->ptr, "mode", mode);
433         RNA_int_set(kmi->ptr, "index", 11);
434         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, KM_SHIFT, 0);
435         RNA_string_set(kmi->ptr, "mode", mode);
436         RNA_int_set(kmi->ptr, "index", 12);
437         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, KM_SHIFT, 0);
438         RNA_string_set(kmi->ptr, "mode", mode);
439         RNA_int_set(kmi->ptr, "index", 13);
440         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, KM_SHIFT, 0);
441         RNA_string_set(kmi->ptr, "mode", mode);
442         RNA_int_set(kmi->ptr, "index", 14);
443         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, KM_SHIFT, 0);
444         RNA_string_set(kmi->ptr, "mode", mode);
445         RNA_int_set(kmi->ptr, "index", 15);
446         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, KM_SHIFT, 0);
447         RNA_string_set(kmi->ptr, "mode", mode);
448         RNA_int_set(kmi->ptr, "index", 16);
449         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, KM_SHIFT, 0);
450         RNA_string_set(kmi->ptr, "mode", mode);
451         RNA_int_set(kmi->ptr, "index", 17);
452         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, KM_SHIFT, 0);
453         RNA_string_set(kmi->ptr, "mode", mode);
454         RNA_int_set(kmi->ptr, "index", 18);
455         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, KM_SHIFT, 0);
456         RNA_string_set(kmi->ptr, "mode", mode);
457         RNA_int_set(kmi->ptr, "index", 19);
458 }
459
460 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
461 {
462         wmKeyMapItem *kmi;
463
464         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
465         RNA_float_set(kmi->ptr, "scalar", 0.9);
466
467         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
468         RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
469 }
470
471 typedef enum {
472         RC_COLOR = 1,
473         RC_ROTATION = 2,
474         RC_ZOOM = 4,
475 } RCFlags;
476
477 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
478                               const char *output_name, const char *input_name)
479 {
480         char *path;
481
482         path = BLI_sprintfN("%s.%s", brush_path, input_name);
483         RNA_string_set(ptr, output_name, path);
484         MEM_freeN(path);
485 }
486
487 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
488                                const char *prop, RCFlags flags)
489 {
490         char *brush_path;
491
492         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
493
494         set_brush_rc_path(ptr, brush_path, "data_path", prop);
495         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
496         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
497         RNA_string_set(ptr, "image_id", brush_path);
498
499         if(flags & RC_COLOR)
500                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
501         if(flags & RC_ZOOM)
502                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
503
504         MEM_freeN(brush_path);
505 }
506
507 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
508                                                  RCFlags flags)
509 {
510         wmKeyMapItem *kmi;
511
512         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
513         set_brush_rc_props(kmi->ptr, paint, "size", flags);
514
515         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
516         set_brush_rc_props(kmi->ptr, paint, "strength", flags);
517
518         if(flags & RC_ROTATION) {
519                 kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
520                 set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", flags);
521         }
522 }
523
524 void ED_keymap_paint(wmKeyConfig *keyconf)
525 {
526         wmKeyMap *keymap;
527         wmKeyMapItem *kmi;
528         int i;
529         
530         /* Sculpt mode */
531         keymap= WM_keymap_find(keyconf, "Sculpt", 0, 0);
532         keymap->poll= sculpt_poll;
533
534         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
535         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
536         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
537
538         for(i=0; i<=5; i++)
539                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
540
541         /* multires switch */
542         kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
543         RNA_int_set(kmi->ptr, "level", 1);
544         RNA_boolean_set(kmi->ptr, "relative", 1);
545
546         kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
547         RNA_int_set(kmi->ptr, "level", -1);
548         RNA_boolean_set(kmi->ptr, "relative", 1);
549
550         ed_keymap_paint_brush_switch(keymap, "sculpt");
551         ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
552         ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
553
554         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", DKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_DRAW);
555         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_SMOOTH);
556         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_PINCH);
557         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", IKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_INFLATE);
558         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_GRAB);
559         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", LKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_LAYER);
560         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", TKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_FLATTEN); /* was just TKEY in 2.4x */
561         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_CLAY);
562         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_CREASE);
563
564         /* */
565         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
566         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");
567
568         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
569         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
570
571         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
572         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
573
574         /* Vertex Paint mode */
575         keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
576         keymap->poll= vertex_paint_mode_poll;
577
578         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
579         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
580
581         WM_keymap_add_item(keymap,
582                         "PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
583
584         ed_keymap_paint_brush_switch(keymap, "vertex_paint");
585         ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
586         ed_keymap_paint_brush_radial_control(keymap, "vertex_paint", RC_COLOR);
587
588         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
589         RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
590
591         /* Weight Paint mode */
592         keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
593         keymap->poll= weight_paint_mode_poll;
594
595         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
596
597         /* these keys are from 2.4x but could be changed */
598         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
599         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
600
601         WM_keymap_add_item(keymap,
602                         "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
603
604         ed_keymap_paint_brush_switch(keymap, "weight_paint");
605         ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
606         ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
607
608         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
609         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
610
611         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
612
613         // Jason
614         /*Weight paint's Vertex Selection Mode */
615         keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
616         keymap->poll= vert_paint_poll;
617         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
618         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
619         WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
620         RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0)->ptr, "deselect", 1);
621         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
622
623         /* Image/Texture Paint mode */
624         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
625         keymap->poll= image_texture_paint_poll;
626
627         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
628         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
629         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
630         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
631
632         ed_keymap_paint_brush_switch(keymap, "image_paint");
633         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
634         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
635
636         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
637         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
638
639         /* face-mask mode */
640         keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
641         keymap->poll= facemask_paint_poll;
642
643         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
644         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
645         WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
646         RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
647         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
648
649         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
650         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
651 }