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