merge with trunk r38787
[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 "BLF_api.h"
33
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_brush_types.h"
37
38 #include "BKE_brush.h"
39 #include "BKE_context.h"
40 #include "BKE_paint.h"
41 #include "BKE_main.h"
42
43 #include "ED_sculpt.h"
44 #include "ED_screen.h"
45 #include "UI_resources.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "RNA_access.h"
51 #include "RNA_define.h"
52 #include "RNA_enum_types.h"
53
54 #include "paint_intern.h"
55 #include "sculpt_intern.h"
56
57 #include <string.h>
58 //#include <stdio.h>
59 #include <stddef.h>
60
61 /* Brush operators */
62 static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
63 {
64         /*int type = RNA_enum_get(op->ptr, "type");*/
65         Paint *paint = paint_get_active(CTX_data_scene(C));
66         struct Brush *br = paint_brush(paint);
67
68         if (br)
69                 br = copy_brush(br);
70         else
71                 br = add_brush("Brush");
72
73         paint_brush_set(paint_get_active(CTX_data_scene(C)), 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         Paint  *paint=  paint_get_active(CTX_data_scene(C));
96         struct Brush  *brush=  paint_brush(paint);
97         // Object *ob=     CTX_data_active_object(C);
98         float   scalar= RNA_float_get(op->ptr, "scalar");
99
100         if (brush) {
101                 // pixel radius
102                 {
103                         const int old_size= brush_size(brush);
104                         int size= (int)(scalar*old_size);
105
106                         if (old_size == size) {
107                                 if (scalar > 1) {
108                                         size++;
109                                 }
110                                 else if (scalar < 1) {
111                                         size--;
112                                 }
113                         }
114                         CLAMP(size, 1, 2000); // XXX magic number
115
116                         brush_set_size(brush, size);
117                 }
118
119                 // unprojected radius
120                 {
121                         float unprojected_radius= scalar*brush_unprojected_radius(brush);
122
123                         if (unprojected_radius < 0.001f) // XXX magic number
124                                 unprojected_radius= 0.001f;
125
126                         brush_set_unprojected_radius(brush, unprojected_radius);
127                 }
128         }
129
130         return OPERATOR_FINISHED;
131 }
132
133 static void BRUSH_OT_scale_size(wmOperatorType *ot)
134 {
135         /* identifiers */
136         ot->name= _("Scale Sculpt/Paint Brush Size");
137         ot->description= _("Change brush size by a scalar");
138         ot->idname= "BRUSH_OT_scale_size";
139         
140         /* api callbacks */
141         ot->exec= brush_scale_size_exec;
142         
143         /* flags */
144         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
145
146         RNA_def_float(ot->srna, "scalar", 1, 0, 2, _("Scalar"), _("Factor to scale brush size by"), 0, 2);
147 }
148
149 static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
150 {
151         Scene *scene = CTX_data_scene(C);
152         Object *obact = CTX_data_active_object(C);
153         unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint);
154         vpaint_fill(obact, paintcol);
155         
156         ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
157         return OPERATOR_FINISHED;
158 }
159
160 static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
161 {
162         /* identifiers */
163         ot->name= _("Set Vertex Colors");
164         ot->idname= "PAINT_OT_vertex_color_set";
165         
166         /* api callbacks */
167         ot->exec= vertex_color_set_exec;
168         ot->poll= vertex_paint_mode_poll;
169         
170         /* flags */
171         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
172 }
173
174 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
175 {
176         Paint *paint = paint_get_active(CTX_data_scene(C));
177         struct Brush *brush = paint_brush(paint);
178         Object *ob = CTX_data_active_object(C);
179
180         if(!ob) return OPERATOR_CANCELLED;
181
182         if(ob->mode & OB_MODE_SCULPT)
183                 brush_reset_sculpt(brush);
184         /* TODO: other modes */
185
186         return OPERATOR_FINISHED;
187 }
188
189 static void BRUSH_OT_reset(wmOperatorType *ot)
190 {
191         /* identifiers */
192         ot->name= _("Reset Brush");
193         ot->description= _("Return brush to defaults based on current tool");
194         ot->idname= "BRUSH_OT_reset";
195         
196         /* api callbacks */
197         ot->exec= brush_reset_exec;
198         
199         /* flags */
200         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
201 }
202
203 /* generic functions for setting the active brush based on the tool */
204 static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
205 {
206         struct Brush *brush;
207
208         if(!brush_orig && !(brush_orig= bmain->brush.first)) {
209                 return NULL;
210         }
211
212         /* get the next brush with the active tool */
213         for(    brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
214                         brush != brush_orig;
215                         brush= brush->id.next ? brush->id.next : bmain->brush.first)
216         {
217                 if(     (brush->ob_mode & ob_mode) &&
218                         (*(((char *)brush) + tool_offset) == tool)
219                 ) {
220                         return brush;
221                 }
222         }
223
224         return NULL;
225
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 static int brush_sculpt_tool_set_exec(bContext *C, wmOperator *op)
245 {
246         Main *bmain= CTX_data_main(C);
247         Scene *scene= CTX_data_scene(C);
248
249         return brush_generic_tool_set(bmain, &scene->toolsettings->sculpt->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, sculpt_tool), OB_MODE_SCULPT);
250 }
251
252 static void BRUSH_OT_sculpt_tool_set(wmOperatorType *ot)
253 {
254         /* identifiers */
255         ot->name= _("Sculpt Tool Set");
256         ot->description= _("Set the sculpt tool");
257         ot->idname= "BRUSH_OT_sculpt_tool_set";
258
259         /* api callbacks */
260         ot->exec= brush_sculpt_tool_set_exec;
261
262         /* flags */
263         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
264
265         /* props */
266         ot->prop= RNA_def_enum(ot->srna, "tool", brush_sculpt_tool_items, 0, _("Tool"), "");
267 }
268
269 static int brush_vertex_tool_set_exec(bContext *C, wmOperator *op)
270 {
271         Main *bmain= CTX_data_main(C);
272         Scene *scene= CTX_data_scene(C);
273
274         return brush_generic_tool_set(bmain, &scene->toolsettings->vpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_VERTEX_PAINT);
275 }
276
277 static void BRUSH_OT_vertex_tool_set(wmOperatorType *ot)
278 {
279         /* identifiers */
280         ot->name= _("Vertex Paint Tool Set");
281         ot->description= _("Set the vertex paint tool");
282         ot->idname= "BRUSH_OT_vertex_tool_set";
283
284         /* api callbacks */
285         ot->exec= brush_vertex_tool_set_exec;
286
287         /* flags */
288         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
289
290         /* props */
291         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, _("Tool"), "");
292 }
293
294 static int brush_weight_tool_set_exec(bContext *C, wmOperator *op)
295 {
296         Main *bmain= CTX_data_main(C);
297         Scene *scene= CTX_data_scene(C);
298         /* vertexpaint_tool is used for weight paint mode */
299         return brush_generic_tool_set(bmain, &scene->toolsettings->wpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_WEIGHT_PAINT);
300 }
301
302 static void BRUSH_OT_weight_tool_set(wmOperatorType *ot)
303 {
304         /* identifiers */
305         ot->name= _("Weight Paint Tool Set");
306         ot->description= _("Set the weight paint tool");
307         ot->idname= "BRUSH_OT_weight_tool_set";
308
309         /* api callbacks */
310         ot->exec= brush_weight_tool_set_exec;
311
312         /* flags */
313         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
314
315         /* props */
316         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, _("Tool"), "");
317 }
318
319 static int brush_image_tool_set_exec(bContext *C, wmOperator *op)
320 {
321         Main *bmain= CTX_data_main(C);
322         Scene *scene= CTX_data_scene(C);
323
324         return brush_generic_tool_set(bmain, &scene->toolsettings->imapaint.paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, imagepaint_tool), OB_MODE_TEXTURE_PAINT);
325 }
326
327 static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
328 {
329         /* identifiers */
330         ot->name= _("Image Paint Tool Set");
331         ot->description= _("Set the image tool");
332         ot->idname= "BRUSH_OT_image_tool_set";
333
334         /* api callbacks */
335         ot->exec= brush_image_tool_set_exec;
336
337         /* flags */
338         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
339
340         /* props */
341         ot->prop= RNA_def_enum(ot->srna, "tool", brush_image_tool_items, 0, "Tool", "");
342 }
343
344
345 /**************************** registration **********************************/
346
347 void ED_operatortypes_paint(void)
348 {
349         /* brush */
350         WM_operatortype_append(BRUSH_OT_add);
351         WM_operatortype_append(BRUSH_OT_scale_size);
352         WM_operatortype_append(BRUSH_OT_curve_preset);
353         WM_operatortype_append(BRUSH_OT_reset);
354
355         /* note, particle uses a different system, can be added with existing operators in wm.py */
356         WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
357         WM_operatortype_append(BRUSH_OT_vertex_tool_set);
358         WM_operatortype_append(BRUSH_OT_weight_tool_set);
359         WM_operatortype_append(BRUSH_OT_image_tool_set);
360
361         /* image */
362         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
363         WM_operatortype_append(PAINT_OT_image_paint);
364         WM_operatortype_append(PAINT_OT_sample_color);
365         WM_operatortype_append(PAINT_OT_grab_clone);
366         WM_operatortype_append(PAINT_OT_clone_cursor_set);
367         WM_operatortype_append(PAINT_OT_project_image);
368         WM_operatortype_append(PAINT_OT_image_from_view);
369
370         /* weight */
371         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
372         WM_operatortype_append(PAINT_OT_weight_paint);
373         WM_operatortype_append(PAINT_OT_weight_set);
374         WM_operatortype_append(PAINT_OT_weight_from_bones);
375         WM_operatortype_append(PAINT_OT_weight_sample);
376         WM_operatortype_append(PAINT_OT_weight_sample_group);
377
378         /* vertex */
379         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
380         WM_operatortype_append(PAINT_OT_vertex_paint);
381         WM_operatortype_append(PAINT_OT_vertex_color_set);
382
383         /* face-select */
384         WM_operatortype_append(PAINT_OT_face_select_linked);
385         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
386         WM_operatortype_append(PAINT_OT_face_select_all);
387         WM_operatortype_append(PAINT_OT_face_select_inverse);
388         WM_operatortype_append(PAINT_OT_face_select_hide);
389         WM_operatortype_append(PAINT_OT_face_select_reveal);
390 }
391
392
393 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
394 {
395         wmKeyMapItem *kmi;
396
397         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, 0, 0);
398         RNA_string_set(kmi->ptr, "mode", mode);
399         RNA_int_set(kmi->ptr, "index", 0);
400         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, 0, 0);
401         RNA_string_set(kmi->ptr, "mode", mode);
402         RNA_int_set(kmi->ptr, "index", 1);
403         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, 0, 0);
404         RNA_string_set(kmi->ptr, "mode", mode);
405         RNA_int_set(kmi->ptr, "index", 2);
406         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, 0, 0);
407         RNA_string_set(kmi->ptr, "mode", mode);
408         RNA_int_set(kmi->ptr, "index", 3);
409         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, 0, 0);
410         RNA_string_set(kmi->ptr, "mode", mode);
411         RNA_int_set(kmi->ptr, "index", 4);
412         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, 0, 0);
413         RNA_string_set(kmi->ptr, "mode", mode);
414         RNA_int_set(kmi->ptr, "index", 5);
415         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, 0, 0);
416         RNA_string_set(kmi->ptr, "mode", mode);
417         RNA_int_set(kmi->ptr, "index", 6);
418         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, 0, 0);
419         RNA_string_set(kmi->ptr, "mode", mode);
420         RNA_int_set(kmi->ptr, "index", 7);
421         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, 0, 0);
422         RNA_string_set(kmi->ptr, "mode", mode);
423         RNA_int_set(kmi->ptr, "index", 8);
424         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, 0, 0);
425         RNA_string_set(kmi->ptr, "mode", mode);
426         RNA_int_set(kmi->ptr, "index", 9);
427         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, KM_SHIFT, 0);
428         RNA_string_set(kmi->ptr, "mode", mode);
429         RNA_int_set(kmi->ptr, "index", 10);
430         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, KM_SHIFT, 0);
431         RNA_string_set(kmi->ptr, "mode", mode);
432         RNA_int_set(kmi->ptr, "index", 11);
433         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, KM_SHIFT, 0);
434         RNA_string_set(kmi->ptr, "mode", mode);
435         RNA_int_set(kmi->ptr, "index", 12);
436         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, KM_SHIFT, 0);
437         RNA_string_set(kmi->ptr, "mode", mode);
438         RNA_int_set(kmi->ptr, "index", 13);
439         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, KM_SHIFT, 0);
440         RNA_string_set(kmi->ptr, "mode", mode);
441         RNA_int_set(kmi->ptr, "index", 14);
442         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, KM_SHIFT, 0);
443         RNA_string_set(kmi->ptr, "mode", mode);
444         RNA_int_set(kmi->ptr, "index", 15);
445         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, KM_SHIFT, 0);
446         RNA_string_set(kmi->ptr, "mode", mode);
447         RNA_int_set(kmi->ptr, "index", 16);
448         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, KM_SHIFT, 0);
449         RNA_string_set(kmi->ptr, "mode", mode);
450         RNA_int_set(kmi->ptr, "index", 17);
451         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, KM_SHIFT, 0);
452         RNA_string_set(kmi->ptr, "mode", mode);
453         RNA_int_set(kmi->ptr, "index", 18);
454         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, KM_SHIFT, 0);
455         RNA_string_set(kmi->ptr, "mode", mode);
456         RNA_int_set(kmi->ptr, "index", 19);
457 }
458
459 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
460 {
461         wmKeyMapItem *kmi;
462
463         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
464         RNA_float_set(kmi->ptr, "scalar", 0.9);
465
466         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
467         RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
468 }
469
470 typedef enum {
471         RC_COLOR = 1,
472         RC_ROTATION = 2,
473         RC_ZOOM = 4,
474 } RCFlags;
475
476 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
477                               const char *output_name, const char *input_name)
478 {
479         char *path;
480
481         path = BLI_sprintfN("%s.%s", brush_path, input_name);
482         RNA_string_set(ptr, output_name, path);
483         MEM_freeN(path);
484 }
485
486 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
487                                const char *prop, RCFlags flags)
488 {
489         char *brush_path;
490
491         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
492
493         set_brush_rc_path(ptr, brush_path, "data_path", prop);
494         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
495         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
496         RNA_string_set(ptr, "image_id", brush_path);
497
498         if(flags & RC_COLOR)
499                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
500         if(flags & RC_ZOOM)
501                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
502
503         MEM_freeN(brush_path);
504 }
505
506 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
507                                                  RCFlags flags)
508 {
509         wmKeyMapItem *kmi;
510
511         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
512         set_brush_rc_props(kmi->ptr, paint, "size", flags);
513
514         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
515         set_brush_rc_props(kmi->ptr, paint, "strength", flags);
516
517         if(flags & RC_ROTATION) {
518                 kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
519                 set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", flags);
520         }
521 }
522
523 void ED_keymap_paint(wmKeyConfig *keyconf)
524 {
525         wmKeyMap *keymap;
526         wmKeyMapItem *kmi;
527         int i;
528         
529         /* Sculpt mode */
530         keymap= WM_keymap_find(keyconf, "Sculpt", 0, 0);
531         keymap->poll= sculpt_poll;
532
533         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
534         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
535         RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
536
537         for(i=0; i<=5; i++)
538                 RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
539
540         /* multires switch */
541         kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
542         RNA_int_set(kmi->ptr, "level", 1);
543         RNA_boolean_set(kmi->ptr, "relative", 1);
544
545         kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
546         RNA_int_set(kmi->ptr, "level", -1);
547         RNA_boolean_set(kmi->ptr, "relative", 1);
548
549         ed_keymap_paint_brush_switch(keymap, "sculpt");
550         ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
551         ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
552
553         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", DKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_DRAW);
554         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_SMOOTH);
555         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_PINCH);
556         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", IKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_INFLATE);
557         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_GRAB);
558         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", LKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_LAYER);
559         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 */
560         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_CLAY);
561         RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_CREASE);
562
563         /* */
564         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
565         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.stroke_method");
566
567         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SKEY, KM_PRESS, KM_SHIFT, 0);
568         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.use_smooth_stroke");
569
570         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", RKEY, KM_PRESS, 0, 0);
571         RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
572
573         /* Vertex Paint mode */
574         keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
575         keymap->poll= vertex_paint_mode_poll;
576
577         WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
578         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
579
580         WM_keymap_add_item(keymap,
581                         "PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
582
583         ed_keymap_paint_brush_switch(keymap, "vertex_paint");
584         ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
585         ed_keymap_paint_brush_radial_control(keymap, "vertex_paint", RC_COLOR);
586
587         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
588         RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
589
590         /* Weight Paint mode */
591         keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
592         keymap->poll= weight_paint_mode_poll;
593
594         WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
595
596         /* these keys are from 2.4x but could be changed */
597         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
598         WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
599
600         WM_keymap_add_item(keymap,
601                         "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
602
603         ed_keymap_paint_brush_switch(keymap, "weight_paint");
604         ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
605         ed_keymap_paint_brush_radial_control(keymap, "weight_paint", 0);
606
607         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
608         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
609
610         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
611
612         /* Image/Texture Paint mode */
613         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
614         keymap->poll= image_texture_paint_poll;
615
616         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
617         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
618         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
619         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
620
621         ed_keymap_paint_brush_switch(keymap, "image_paint");
622         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
623         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
624
625         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
626         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
627
628         /* face-mask mode */
629         keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
630         keymap->poll= facemask_paint_poll;
631
632         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
633         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
634         WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
635         RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
636         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
637
638         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
639         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
640 }