Camera tracking: improvements of track preview widget
[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         Paint  *paint=  paint_get_active(CTX_data_scene(C));
93         struct Brush  *brush=  paint_brush(paint);
94         // Object *ob=     CTX_data_active_object(C);
95         float   scalar= RNA_float_get(op->ptr, "scalar");
96
97         if (brush) {
98                 // pixel radius
99                 {
100                         const int old_size= brush_size(brush);
101                         int size= (int)(scalar*old_size);
102
103                         if (old_size == size) {
104                                 if (scalar > 1) {
105                                         size++;
106                                 }
107                                 else if (scalar < 1) {
108                                         size--;
109                                 }
110                         }
111                         CLAMP(size, 1, 2000); // XXX magic number
112
113                         brush_set_size(brush, size);
114                 }
115
116                 // unprojected radius
117                 {
118                         float unprojected_radius= scalar*brush_unprojected_radius(brush);
119
120                         if (unprojected_radius < 0.001f) // XXX magic number
121                                 unprojected_radius= 0.001f;
122
123                         brush_set_unprojected_radius(brush, unprojected_radius);
124                 }
125         }
126
127         return OPERATOR_FINISHED;
128 }
129
130 static void BRUSH_OT_scale_size(wmOperatorType *ot)
131 {
132         /* identifiers */
133         ot->name= "Scale Sculpt/Paint Brush Size";
134         ot->description= "Change brush size by a scalar";
135         ot->idname= "BRUSH_OT_scale_size";
136         
137         /* api callbacks */
138         ot->exec= brush_scale_size_exec;
139         
140         /* flags */
141         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
142
143         RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
144 }
145
146 static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
147 {
148         Scene *scene = CTX_data_scene(C);
149         Object *obact = CTX_data_active_object(C);
150         unsigned int paintcol = vpaint_get_current_col(scene->toolsettings->vpaint);
151         vpaint_fill(obact, paintcol);
152         
153         ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
154         return OPERATOR_FINISHED;
155 }
156
157 static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
158 {
159         /* identifiers */
160         ot->name= "Set Vertex Colors";
161         ot->idname= "PAINT_OT_vertex_color_set";
162         
163         /* api callbacks */
164         ot->exec= vertex_color_set_exec;
165         ot->poll= vertex_paint_mode_poll;
166         
167         /* flags */
168         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
169 }
170
171 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
172 {
173         Paint *paint = paint_get_active(CTX_data_scene(C));
174         struct Brush *brush = paint_brush(paint);
175         Object *ob = CTX_data_active_object(C);
176
177         if(!ob) return OPERATOR_CANCELLED;
178
179         if(ob->mode & OB_MODE_SCULPT)
180                 brush_reset_sculpt(brush);
181         /* TODO: other modes */
182
183         return OPERATOR_FINISHED;
184 }
185
186 static void BRUSH_OT_reset(wmOperatorType *ot)
187 {
188         /* identifiers */
189         ot->name= "Reset Brush";
190         ot->description= "Return brush to defaults based on current tool";
191         ot->idname= "BRUSH_OT_reset";
192         
193         /* api callbacks */
194         ot->exec= brush_reset_exec;
195         
196         /* flags */
197         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
198 }
199
200 /* generic functions for setting the active brush based on the tool */
201 static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, const size_t tool_offset, const int ob_mode)
202 {
203         struct Brush *brush;
204
205         if(!brush_orig && !(brush_orig= bmain->brush.first)) {
206                 return NULL;
207         }
208
209         /* get the next brush with the active tool */
210         for(    brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
211                         brush != brush_orig;
212                         brush= brush->id.next ? brush->id.next : bmain->brush.first)
213         {
214                 if(     (brush->ob_mode & ob_mode) &&
215                         (*(((char *)brush) + tool_offset) == tool)
216                 ) {
217                         return brush;
218                 }
219         }
220
221         return NULL;
222
223 }
224
225 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
226 {
227         struct Brush *brush, *brush_orig= paint_brush(paint);
228
229         brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
230
231         if(brush) {
232                 paint_brush_set(paint, brush);
233                 WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
234                 return OPERATOR_FINISHED;
235         }
236         else {
237                 return OPERATOR_CANCELLED;
238         }
239 }
240
241 static int brush_sculpt_tool_set_exec(bContext *C, wmOperator *op)
242 {
243         Main *bmain= CTX_data_main(C);
244         Scene *scene= CTX_data_scene(C);
245
246         return brush_generic_tool_set(bmain, &scene->toolsettings->sculpt->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, sculpt_tool), OB_MODE_SCULPT);
247 }
248
249 static void BRUSH_OT_sculpt_tool_set(wmOperatorType *ot)
250 {
251         /* identifiers */
252         ot->name= "Sculpt Tool Set";
253         ot->description= "Set the sculpt tool";
254         ot->idname= "BRUSH_OT_sculpt_tool_set";
255
256         /* api callbacks */
257         ot->exec= brush_sculpt_tool_set_exec;
258
259         /* flags */
260         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
261
262         /* props */
263         ot->prop= RNA_def_enum(ot->srna, "tool", brush_sculpt_tool_items, 0, "Tool", "");
264 }
265
266 static int brush_vertex_tool_set_exec(bContext *C, wmOperator *op)
267 {
268         Main *bmain= CTX_data_main(C);
269         Scene *scene= CTX_data_scene(C);
270
271         return brush_generic_tool_set(bmain, &scene->toolsettings->vpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_VERTEX_PAINT);
272 }
273
274 static void BRUSH_OT_vertex_tool_set(wmOperatorType *ot)
275 {
276         /* identifiers */
277         ot->name= "Vertex Paint Tool Set";
278         ot->description= "Set the vertex paint tool";
279         ot->idname= "BRUSH_OT_vertex_tool_set";
280
281         /* api callbacks */
282         ot->exec= brush_vertex_tool_set_exec;
283
284         /* flags */
285         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
286
287         /* props */
288         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
289 }
290
291 static int brush_weight_tool_set_exec(bContext *C, wmOperator *op)
292 {
293         Main *bmain= CTX_data_main(C);
294         Scene *scene= CTX_data_scene(C);
295         /* vertexpaint_tool is used for weight paint mode */
296         return brush_generic_tool_set(bmain, &scene->toolsettings->wpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_WEIGHT_PAINT);
297 }
298
299 static void BRUSH_OT_weight_tool_set(wmOperatorType *ot)
300 {
301         /* identifiers */
302         ot->name= "Weight Paint Tool Set";
303         ot->description= "Set the weight paint tool";
304         ot->idname= "BRUSH_OT_weight_tool_set";
305
306         /* api callbacks */
307         ot->exec= brush_weight_tool_set_exec;
308
309         /* flags */
310         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
311
312         /* props */
313         ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
314 }
315
316 static int brush_image_tool_set_exec(bContext *C, wmOperator *op)
317 {
318         Main *bmain= CTX_data_main(C);
319         Scene *scene= CTX_data_scene(C);
320
321         return brush_generic_tool_set(bmain, &scene->toolsettings->imapaint.paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, imagepaint_tool), OB_MODE_TEXTURE_PAINT);
322 }
323
324 static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
325 {
326         /* identifiers */
327         ot->name= "Image Paint Tool Set";
328         ot->description= "Set the image tool";
329         ot->idname= "BRUSH_OT_image_tool_set";
330
331         /* api callbacks */
332         ot->exec= brush_image_tool_set_exec;
333
334         /* flags */
335         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
336
337         /* props */
338         ot->prop= RNA_def_enum(ot->srna, "tool", brush_image_tool_items, 0, "Tool", "");
339 }
340
341
342 /**************************** registration **********************************/
343
344 void ED_operatortypes_paint(void)
345 {
346         /* brush */
347         WM_operatortype_append(BRUSH_OT_add);
348         WM_operatortype_append(BRUSH_OT_scale_size);
349         WM_operatortype_append(BRUSH_OT_curve_preset);
350         WM_operatortype_append(BRUSH_OT_reset);
351
352         /* note, particle uses a different system, can be added with existing operators in wm.py */
353         WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
354         WM_operatortype_append(BRUSH_OT_vertex_tool_set);
355         WM_operatortype_append(BRUSH_OT_weight_tool_set);
356         WM_operatortype_append(BRUSH_OT_image_tool_set);
357
358         /* image */
359         WM_operatortype_append(PAINT_OT_texture_paint_toggle);
360         WM_operatortype_append(PAINT_OT_image_paint);
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);
370         WM_operatortype_append(PAINT_OT_weight_set);
371         WM_operatortype_append(PAINT_OT_weight_from_bones);
372         WM_operatortype_append(PAINT_OT_weight_sample);
373         WM_operatortype_append(PAINT_OT_weight_sample_group);
374
375         /* vertex selection */
376         WM_operatortype_append(PAINT_OT_vert_select_all);
377         WM_operatortype_append(PAINT_OT_vert_select_inverse);
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); /* face mask toggle */
609         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask");
610
611         /* note, conflicts with vertex paint, but this is more useful */
612         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", VKEY, KM_PRESS, 0, 0); /* vert mask toggle */
613         RNA_string_set(kmi->ptr, "data_path", "weight_paint_object.data.use_paint_mask_vertex");
614
615         WM_keymap_verify_item(keymap, "PAINT_OT_weight_from_bones", WKEY, KM_PRESS, 0, 0);
616
617         
618         /*Weight paint's Vertex Selection Mode */
619         keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
620         keymap->poll= vert_paint_poll;
621         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
622         WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
623         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
624         WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
625         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);
626         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
627
628         /* Image/Texture Paint mode */
629         keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
630         keymap->poll= image_texture_paint_poll;
631
632         WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
633         WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
634         WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
635         WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
636
637         ed_keymap_paint_brush_switch(keymap, "image_paint");
638         ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
639         ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
640
641         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
642         RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
643
644         /* face-mask mode */
645         keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
646         keymap->poll= facemask_paint_poll;
647
648         WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
649         WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
650         WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
651         RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
652         WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
653
654         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
655         WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
656 }