Merging r43130 through r43500 from trunk into soc-2011-tomato
[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 /* 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 static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
344 {
345         Brush *brush;
346         Scene *scene= CTX_data_scene(C);
347         ToolSettings *ts = scene->toolsettings;
348         ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
349         brush = ts->uvsculpt->paint.brush;
350         /* To update toolshelf */
351         WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush);
352
353         return OPERATOR_FINISHED;
354 }
355
356 static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
357 {
358         /* from rna_scene.c */
359         extern EnumPropertyItem uv_sculpt_tool_items[];
360         /* identifiers */
361         ot->name = "UV Sculpt Tool Set";
362         ot->description = "Set the uv sculpt tool";
363         ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
364
365         /* api callbacks */
366         ot->exec = brush_uv_sculpt_tool_set_exec;
367         ot->poll = uv_sculpt_poll;
368
369         /* flags */
370         ot->flag = 0;
371
372         /* props */
373         ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
374 }
375
376 /**************************** registration **********************************/
377
378 void ED_operatortypes_paint(void)
379 {
380         /* brush */
381         WM_operatortype_append(BRUSH_OT_add);
382         WM_operatortype_append(BRUSH_OT_scale_size);
383         WM_operatortype_append(BRUSH_OT_curve_preset);
384         WM_operatortype_append(BRUSH_OT_reset);
385
386         /* note, particle uses a different system, can be added with existing operators in wm.py */
387         WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
388         WM_operatortype_append(BRUSH_OT_vertex_tool_set);
389         WM_operatortype_append(BRUSH_OT_weight_tool_set);
390         WM_operatortype_append(BRUSH_OT_image_tool_set);
391         WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
392
393         /* image */
394         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
395         WM_operatortype_append(PAINT_OT_image_paint);
396         WM_operatortype_append(PAINT_OT_sample_color);
397         WM_operatortype_append(PAINT_OT_grab_clone);
398         WM_operatortype_append(PAINT_OT_clone_cursor_set);
399         WM_operatortype_append(PAINT_OT_project_image);
400         WM_operatortype_append(PAINT_OT_image_from_view);
401
402         /* weight */
403         WM_operatortype_append(PAINT_OT_weight_paint_toggle);
404         WM_operatortype_append(PAINT_OT_weight_paint);
405         WM_operatortype_append(PAINT_OT_weight_set);
406         WM_operatortype_append(PAINT_OT_weight_from_bones);
407         WM_operatortype_append(PAINT_OT_weight_sample);
408         WM_operatortype_append(PAINT_OT_weight_sample_group);
409
410         /* uv */
411         WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
412
413         /* vertex selection */
414         WM_operatortype_append(PAINT_OT_vert_select_all);
415         WM_operatortype_append(PAINT_OT_vert_select_inverse);
416
417         /* vertex */
418         WM_operatortype_append(PAINT_OT_vertex_paint_toggle);
419         WM_operatortype_append(PAINT_OT_vertex_paint);
420         WM_operatortype_append(PAINT_OT_vertex_color_set);
421
422         /* face-select */
423         WM_operatortype_append(PAINT_OT_face_select_linked);
424         WM_operatortype_append(PAINT_OT_face_select_linked_pick);
425         WM_operatortype_append(PAINT_OT_face_select_all);
426         WM_operatortype_append(PAINT_OT_face_select_inverse);
427         WM_operatortype_append(PAINT_OT_face_select_hide);
428         WM_operatortype_append(PAINT_OT_face_select_reveal);
429 }
430
431
432 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
433 {
434         wmKeyMapItem *kmi;
435         int i;
436         /* index 0-9 (zero key is tenth), shift key for index 10-19 */
437         for (i = 0; i < 20; i++) {
438                 kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
439                                         ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
440                 RNA_string_set(kmi->ptr, "mode", mode);
441                 RNA_int_set(kmi->ptr, "index", i);
442         }
443 }
444
445 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
446 {
447         wmKeyMapItem *kmi;
448
449         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
450         RNA_float_set(kmi->ptr, "scalar", 0.9);
451
452         kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
453         RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
454 }
455
456 typedef enum {
457         RC_COLOR = 1,
458         RC_ROTATION = 2,
459         RC_ZOOM = 4,
460 } RCFlags;
461
462 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
463                                                           const char *output_name, const char *input_name)
464 {
465         char *path;
466
467         path = BLI_sprintfN("%s.%s", brush_path, input_name);
468         RNA_string_set(ptr, output_name, path);
469         MEM_freeN(path);
470 }
471
472 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
473                                                            const char *prop, const char *secondary_prop,
474                                                            RCFlags flags)
475 {
476         const char *ups_path = "tool_settings.unified_paint_settings";
477         char *brush_path;
478
479         brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
480
481         set_brush_rc_path(ptr, brush_path, "data_path_primary", prop);
482         if(secondary_prop) {
483                 set_brush_rc_path(ptr, ups_path, "use_secondary", secondary_prop);
484                 set_brush_rc_path(ptr, ups_path, "data_path_secondary", prop);
485         }
486         else {
487                 RNA_string_set(ptr, "use_secondary", "");
488                 RNA_string_set(ptr, "data_path_secondary", "");
489         }
490         set_brush_rc_path(ptr, brush_path, "color_path", "cursor_color_add");
491         set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
492         RNA_string_set(ptr, "image_id", brush_path);
493
494         if(flags & RC_COLOR)
495                 set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
496         else
497                 RNA_string_set(ptr, "fill_color_path", "");
498         if(flags & RC_ZOOM)
499                 RNA_string_set(ptr, "zoom_path", "space_data.zoom");
500         else
501                 RNA_string_set(ptr, "zoom_path", "");
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", "use_unified_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", "use_unified_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", NULL, 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", TRUE);
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", TRUE);
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); /* face mask toggle */
608         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
609
610         /* note, conflicts with vertex paint, but this is more useful */
611         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
612         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
613
614         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
615
616         
617         /*Weight paint's Vertex Selection Mode */
618         keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
619         keymap->poll= vert_paint_poll;
620         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
621         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
622         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
623         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
624         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
625         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0);
626         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
627         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
628
629         /* Image/Texture Paint mode */
630         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
631         keymap->poll= image_texture_paint_poll;
632
633         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
634         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
635         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
636         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
637
638         ed_keymap_paint_brush_switch(keymap, "image_paint");
639         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
640         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
641
642         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
643         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
644
645         /* face-mask mode */
646         keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
647         keymap->poll= facemask_paint_poll;
648
649         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
650         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
651         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
652         RNA_boolean_set(kmi->ptr, "unselected", FALSE);
653         kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
654         RNA_boolean_set(kmi->ptr, "unselected", TRUE);
655         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
656
657         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
658         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
659
660         keymap= WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
661         keymap->poll= uv_sculpt_poll;
662
663         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
664         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
665
666         WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
667         RNA_boolean_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
668         RNA_boolean_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "temp_relax", 1);
669
670         ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
671         ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
672
673         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);
674         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);
675         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);
676
677 }