svn merge ^/trunk/blender -r46300:46330
[blender.git] / source / blender / editors / sculpt_paint / paint_ops.c
index e81e1f6dc779fc1c4099ae0c5fee88a16eeee9cc..bf01c91171bfb21c87680543b337b48ec8e117c8 100644 (file)
@@ -63,9 +63,9 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
        struct Brush *br = paint_brush(paint);
 
        if (br)
-               br = copy_brush(br);
+               br = BKE_brush_copy(br);
        else
-               br = add_brush("Brush");
+               br = BKE_brush_add("Brush");
 
        paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
 
@@ -75,31 +75,31 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
 static void BRUSH_OT_add(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Add Brush";
-       ot->description= "Add brush by mode type";
-       ot->idname= "BRUSH_OT_add";
+       ot->name = "Add Brush";
+       ot->description = "Add brush by mode type";
+       ot->idname = "BRUSH_OT_add";
        
        /* api callbacks */
-       ot->exec= brush_add_exec;
+       ot->exec = brush_add_exec;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 
 static int brush_scale_size_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
-       Paint  *paint=  paint_get_active(scene);
-       struct Brush  *brush=  paint_brush(paint);
+       Paint  *paint =  paint_get_active(scene);
+       struct Brush  *brush =  paint_brush(paint);
        // Object *ob=     CTX_data_active_object(C);
-       float   scalar= RNA_float_get(op->ptr, "scalar");
+       float scalar = RNA_float_get(op->ptr, "scalar");
 
        if (brush) {
                // pixel radius
                {
-                       const int old_size= brush_size(scene, brush);
-                       int size= (int)(scalar*old_size);
+                       const int old_size = BKE_brush_size_get(scene, brush);
+                       int size = (int)(scalar * old_size);
 
                        if (old_size == size) {
                                if (scalar > 1) {
@@ -111,17 +111,17 @@ static int brush_scale_size_exec(bContext *C, wmOperator *op)
                        }
                        CLAMP(size, 1, 2000); // XXX magic number
 
-                       brush_set_size(scene, brush, size);
+                       BKE_brush_size_set(scene, brush, size);
                }
 
                // unprojected radius
                {
-                       float unprojected_radius= scalar*brush_unprojected_radius(scene, brush);
+                       float unprojected_radius = scalar * BKE_brush_unprojected_radius_get(scene, brush);
 
                        if (unprojected_radius < 0.001f) // XXX magic number
-                               unprojected_radius= 0.001f;
+                               unprojected_radius = 0.001f;
 
-                       brush_set_unprojected_radius(scene, brush, unprojected_radius);
+                       BKE_brush_unprojected_radius_set(scene, brush, unprojected_radius);
                }
        }
 
@@ -131,15 +131,15 @@ static int brush_scale_size_exec(bContext *C, wmOperator *op)
 static void BRUSH_OT_scale_size(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Scale Sculpt/Paint Brush Size";
-       ot->description= "Change brush size by a scalar";
-       ot->idname= "BRUSH_OT_scale_size";
+       ot->name = "Scale Sculpt/Paint Brush Size";
+       ot->description = "Change brush size by a scalar";
+       ot->idname = "BRUSH_OT_scale_size";
        
        /* api callbacks */
-       ot->exec= brush_scale_size_exec;
+       ot->exec = brush_scale_size_exec;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
 }
@@ -158,15 +158,16 @@ static int vertex_color_set_exec(bContext *C, wmOperator *UNUSED(op))
 static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Set Vertex Colors";
-       ot->idname= "PAINT_OT_vertex_color_set";
+       ot->name = "Set Vertex Colors";
+       ot->idname = "PAINT_OT_vertex_color_set";
+       ot->description = "Fill the active vertex color layer with the current paint color";
        
        /* api callbacks */
-       ot->exec= vertex_color_set_exec;
-       ot->poll= vertex_paint_mode_poll;
+       ot->exec = vertex_color_set_exec;
+       ot->poll = vertex_paint_mode_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
 static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
@@ -175,10 +176,10 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
        struct Brush *brush = paint_brush(paint);
        Object *ob = CTX_data_active_object(C);
 
-       if(!ob) return OPERATOR_CANCELLED;
+       if (!ob) return OPERATOR_CANCELLED;
 
-       if(ob->mode & OB_MODE_SCULPT)
-               brush_reset_sculpt(brush);
+       if (ob->mode & OB_MODE_SCULPT)
+               BKE_brush_sculpt_reset(brush);
        /* TODO: other modes */
 
        return OPERATOR_FINISHED;
@@ -187,15 +188,20 @@ static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
 static void BRUSH_OT_reset(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Reset Brush";
-       ot->description= "Return brush to defaults based on current tool";
-       ot->idname= "BRUSH_OT_reset";
+       ot->name = "Reset Brush";
+       ot->description = "Return brush to defaults based on current tool";
+       ot->idname = "BRUSH_OT_reset";
        
        /* api callbacks */
-       ot->exec= brush_reset_exec;
+       ot->exec = brush_reset_exec;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int brush_tool(const Brush *brush, size_t tool_offset)
+{
+       return *(((char *)brush) + tool_offset);
 }
 
 /* generic functions for setting the active brush based on the tool */
@@ -203,35 +209,33 @@ static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, c
 {
        struct Brush *brush;
 
-       if(!brush_orig && !(brush_orig= bmain->brush.first)) {
+       if (!brush_orig && !(brush_orig = bmain->brush.first)) {
                return NULL;
        }
 
        /* get the next brush with the active tool */
-       for(    brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
-                       brush != brush_orig;
-                       brush= brush->id.next ? brush->id.next : bmain->brush.first)
+       for (brush = brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
+            brush != brush_orig;
+            brush = brush->id.next ? brush->id.next : bmain->brush.first)
        {
-               if(     (brush->ob_mode & ob_mode) &&
-                       (*(((char *)brush) + tool_offset) == tool)
-               ) {
+               if ((brush->ob_mode & ob_mode) &&
+                   (brush_tool(brush, tool_offset) == tool)) {
                        return brush;
                }
        }
 
        return NULL;
-
 }
 
 static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
 {
-       struct Brush *brush, *brush_orig= paint_brush(paint);
+       struct Brush *brush, *brush_orig = paint_brush(paint);
 
-       brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
+       brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
 
-       if(brush) {
+       if (brush) {
                paint_brush_set(paint, brush);
-               WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
+               WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
                return OPERATOR_FINISHED;
        }
        else {
@@ -239,107 +243,153 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, con
        }
 }
 
-static int brush_sculpt_tool_set_exec(bContext *C, wmOperator *op)
-{
-       Main *bmain= CTX_data_main(C);
-       Scene *scene= CTX_data_scene(C);
+/* used in the PAINT_OT_brush_select operator */
+#define OB_MODE_ACTIVE 0
 
-       return brush_generic_tool_set(bmain, &scene->toolsettings->sculpt->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, sculpt_tool), OB_MODE_SCULPT);
-}
-
-static void BRUSH_OT_sculpt_tool_set(wmOperatorType *ot)
+static int brush_select_exec(bContext *C, wmOperator *op)
 {
-       /* identifiers */
-       ot->name= "Sculpt Tool Set";
-       ot->description= "Set the sculpt tool";
-       ot->idname= "BRUSH_OT_sculpt_tool_set";
-
-       /* api callbacks */
-       ot->exec= brush_sculpt_tool_set_exec;
+       Main *bmain = CTX_data_main(C);
+       ToolSettings *toolsettings = CTX_data_tool_settings(C);
+       Paint *paint = NULL;
+       int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
+       size_t tool_offset;
+
+       if (paint_mode == OB_MODE_ACTIVE) {
+               Object *ob = CTX_data_active_object(C);
+               if (ob) {
+                       /* select current paint mode */
+                       paint_mode = ob->mode &
+                                    (OB_MODE_SCULPT |
+                                     OB_MODE_VERTEX_PAINT |
+                                     OB_MODE_WEIGHT_PAINT |
+                                     OB_MODE_TEXTURE_PAINT);
+               }
+               else {
+                       return OPERATOR_CANCELLED;
+               }
+       }
 
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       switch (paint_mode) {
+               case OB_MODE_SCULPT:
+                       paint = &toolsettings->sculpt->paint;
+                       tool_offset = offsetof(Brush, sculpt_tool);
+                       tool = RNA_enum_get(op->ptr, "sculpt_tool");
+                       break;
+               case OB_MODE_VERTEX_PAINT:
+                       paint = &toolsettings->vpaint->paint;
+                       tool_offset = offsetof(Brush, vertexpaint_tool);
+                       tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
+                       break;
+               case OB_MODE_WEIGHT_PAINT:
+                       paint = &toolsettings->wpaint->paint;
+                       /* vertexpaint_tool is used for weight paint mode */
+                       tool_offset = offsetof(Brush, vertexpaint_tool);
+                       tool = RNA_enum_get(op->ptr, "weight_paint_tool");
+                       break;
+               case OB_MODE_TEXTURE_PAINT:
+                       paint = &toolsettings->imapaint.paint;
+                       tool_offset = offsetof(Brush, imagepaint_tool);
+                       tool = RNA_enum_get(op->ptr, "texture_paint_tool");
+                       break;
+               default:
+                       /* invalid paint mode */
+                       return OPERATOR_CANCELLED;
+       }
 
-       /* props */
-       ot->prop= RNA_def_enum(ot->srna, "tool", brush_sculpt_tool_items, 0, "Tool", "");
+       return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
 }
 
-static int brush_vertex_tool_set_exec(bContext *C, wmOperator *op)
+static void PAINT_OT_brush_select(wmOperatorType *ot)
 {
-       Main *bmain= CTX_data_main(C);
-       Scene *scene= CTX_data_scene(C);
+       static EnumPropertyItem paint_mode_items[] = {
+               {OB_MODE_ACTIVE, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
+               {OB_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
+               {OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
+               {OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
+               {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
 
-       return brush_generic_tool_set(bmain, &scene->toolsettings->vpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_VERTEX_PAINT);
-}
-
-static void BRUSH_OT_vertex_tool_set(wmOperatorType *ot)
-{
        /* identifiers */
-       ot->name= "Vertex Paint Tool Set";
-       ot->description= "Set the vertex paint tool";
-       ot->idname= "BRUSH_OT_vertex_tool_set";
+       ot->name = "Brush Select";
+       ot->description = "Select a paint mode's brush by tool type";
+       ot->idname = "PAINT_OT_brush_select";
 
        /* api callbacks */
-       ot->exec= brush_vertex_tool_set_exec;
+       ot->exec = brush_select_exec;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* props */
-       ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
+       RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, OB_MODE_ACTIVE, "Paint Mode", "");
+       RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", "");
+       RNA_def_enum(ot->srna, "vertex_paint_tool", brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
+       RNA_def_enum(ot->srna, "weight_paint_tool", brush_vertex_tool_items, 0, "Weight Paint Tool", "");
+       RNA_def_enum(ot->srna, "texture_paint_tool", brush_image_tool_items, 0, "Texture Paint Tool", "");
 }
 
-static int brush_weight_tool_set_exec(bContext *C, wmOperator *op)
+static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
+                                         int tool, int keymap_type,
+                                         int keymap_modifier)
 {
-       Main *bmain= CTX_data_main(C);
-       Scene *scene= CTX_data_scene(C);
-       /* vertexpaint_tool is used for weight paint mode */
-       return brush_generic_tool_set(bmain, &scene->toolsettings->wpaint->paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, vertexpaint_tool), OB_MODE_WEIGHT_PAINT);
-}
-
-static void BRUSH_OT_weight_tool_set(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Weight Paint Tool Set";
-       ot->description= "Set the weight paint tool";
-       ot->idname= "BRUSH_OT_weight_tool_set";
-
-       /* api callbacks */
-       ot->exec= brush_weight_tool_set_exec;
+       wmKeyMapItem *kmi;
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select",
+                                keymap_type, KM_PRESS, keymap_modifier, 0);
 
-       /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
+       
+       switch (paint_mode) {
+               case OB_MODE_SCULPT:
+                       RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
+                       break;
+               case OB_MODE_VERTEX_PAINT:
+                       RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
+                       break;
+               case OB_MODE_WEIGHT_PAINT:
+                       RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
+                       break;
+               case OB_MODE_TEXTURE_PAINT:
+                       RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
+                       break;
+       }
 
-       /* props */
-       ot->prop= RNA_def_enum(ot->srna, "tool", brush_vertex_tool_items, 0, "Tool", "");
+       return kmi;
 }
 
-static int brush_image_tool_set_exec(bContext *C, wmOperator *op)
+static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
 {
-       Main *bmain= CTX_data_main(C);
-       Scene *scene= CTX_data_scene(C);
+       Brush *brush;
+       Scene *scene = CTX_data_scene(C);
+       ToolSettings *ts = scene->toolsettings;
+       ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
+       brush = ts->uvsculpt->paint.brush;
+       /* To update toolshelf */
+       WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
 
-       return brush_generic_tool_set(bmain, &scene->toolsettings->imapaint.paint, RNA_enum_get(op->ptr, "tool"), offsetof(Brush, imagepaint_tool), OB_MODE_TEXTURE_PAINT);
+       return OPERATOR_FINISHED;
 }
 
-static void BRUSH_OT_image_tool_set(wmOperatorType *ot)
+static void BRUSH_OT_uv_sculpt_tool_set(wmOperatorType *ot)
 {
+       /* from rna_scene.c */
+       extern EnumPropertyItem uv_sculpt_tool_items[];
        /* identifiers */
-       ot->name= "Image Paint Tool Set";
-       ot->description= "Set the image tool";
-       ot->idname= "BRUSH_OT_image_tool_set";
+       ot->name = "UV Sculpt Tool Set";
+       ot->description = "Set the UV sculpt tool";
+       ot->idname = "BRUSH_OT_uv_sculpt_tool_set";
 
        /* api callbacks */
-       ot->exec= brush_image_tool_set_exec;
+       ot->exec = brush_uv_sculpt_tool_set_exec;
+       ot->poll = uv_sculpt_poll;
 
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag = 0;
 
        /* props */
-       ot->prop= RNA_def_enum(ot->srna, "tool", brush_image_tool_items, 0, "Tool", "");
+       ot->prop = RNA_def_enum(ot->srna, "tool", uv_sculpt_tool_items, 0, "Tool", "");
 }
 
-
 /**************************** registration **********************************/
 
 void ED_operatortypes_paint(void)
@@ -351,10 +401,8 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(BRUSH_OT_reset);
 
        /* note, particle uses a different system, can be added with existing operators in wm.py */
-       WM_operatortype_append(BRUSH_OT_sculpt_tool_set);
-       WM_operatortype_append(BRUSH_OT_vertex_tool_set);
-       WM_operatortype_append(BRUSH_OT_weight_tool_set);
-       WM_operatortype_append(BRUSH_OT_image_tool_set);
+       WM_operatortype_append(PAINT_OT_brush_select);
+       WM_operatortype_append(BRUSH_OT_uv_sculpt_tool_set);
 
        /* image */
        WM_operatortype_append(PAINT_OT_texture_paint_toggle);
@@ -373,6 +421,9 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(PAINT_OT_weight_sample);
        WM_operatortype_append(PAINT_OT_weight_sample_group);
 
+       /* uv */
+       WM_operatortype_append(SCULPT_OT_uv_sculpt_stroke);
+
        /* vertex selection */
        WM_operatortype_append(PAINT_OT_vert_select_all);
        WM_operatortype_append(PAINT_OT_vert_select_inverse);
@@ -389,84 +440,34 @@ void ED_operatortypes_paint(void)
        WM_operatortype_append(PAINT_OT_face_select_inverse);
        WM_operatortype_append(PAINT_OT_face_select_hide);
        WM_operatortype_append(PAINT_OT_face_select_reveal);
+
+       /* partial visibility */
+       WM_operatortype_append(PAINT_OT_hide_show);
 }
 
 
 static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
 {
        wmKeyMapItem *kmi;
-
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 0);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 1);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 2);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 3);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 4);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 5);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 6);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 7);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 8);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, 0, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 9);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ONEKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 10);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", TWOKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 11);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", THREEKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 12);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FOURKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 13);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", FIVEKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 14);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SIXKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 15);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", SEVENKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 16);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", EIGHTKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 17);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", NINEKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 18);
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set", ZEROKEY, KM_PRESS, KM_SHIFT, 0);
-       RNA_string_set(kmi->ptr, "mode", mode);
-       RNA_int_set(kmi->ptr, "index", 19);
+       int i;
+       /* index 0-9 (zero key is tenth), shift key for index 10-19 */
+       for (i = 0; i < 20; i++) {
+               kmi = WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
+                                        ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
+               RNA_string_set(kmi->ptr, "mode", mode);
+               RNA_int_set(kmi->ptr, "index", i);
+       }
 }
 
 static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path))
 {
        wmKeyMapItem *kmi;
 
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
+       kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", LEFTBRACKETKEY, KM_PRESS, 0, 0);
        RNA_float_set(kmi->ptr, "scalar", 0.9);
 
-       kmi= WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
-       RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
+       kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
+       RNA_float_set(kmi->ptr, "scalar", 10.0 / 9.0); // 1.1111....
 }
 
 typedef enum {
@@ -476,7 +477,7 @@ typedef enum {
 } RCFlags;
 
 static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
-                                                         const char *output_name, const char *input_name)
+                              const char *output_name, const char *input_name)
 {
        char *path;
 
@@ -486,8 +487,8 @@ static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
 }
 
 static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
-                                                          const char *prop, const char *secondary_prop,
-                                                          RCFlags flags)
+                               const char *prop, const char *secondary_prop,
+                               RCFlags flags)
 {
        const char *ups_path = "tool_settings.unified_paint_settings";
        char *brush_path;
@@ -495,7 +496,7 @@ static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
        brush_path = BLI_sprintfN("tool_settings.%s.brush", paint);
 
        set_brush_rc_path(ptr, brush_path, "data_path_primary", prop);
-       if(secondary_prop) {
+       if (secondary_prop) {
                set_brush_rc_path(ptr, ups_path, "use_secondary", secondary_prop);
                set_brush_rc_path(ptr, ups_path, "data_path_secondary", prop);
        }
@@ -507,11 +508,11 @@ static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
        set_brush_rc_path(ptr, brush_path, "rotation_path", "texture_slot.angle");
        RNA_string_set(ptr, "image_id", brush_path);
 
-       if(flags & RC_COLOR)
+       if (flags & RC_COLOR)
                set_brush_rc_path(ptr, brush_path, "fill_color_path", "color");
        else
                RNA_string_set(ptr, "fill_color_path", "");
-       if(flags & RC_ZOOM)
+       if (flags & RC_ZOOM)
                RNA_string_set(ptr, "zoom_path", "space_data.zoom");
        else
                RNA_string_set(ptr, "zoom_path", "");
@@ -520,7 +521,7 @@ static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
 }
 
 static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
-                                                RCFlags flags)
+                                                 RCFlags flags)
 {
        wmKeyMapItem *kmi;
 
@@ -530,12 +531,31 @@ static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *p
        kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
        set_brush_rc_props(kmi->ptr, paint, "strength", "use_unified_strength", flags);
 
-       if(flags & RC_ROTATION) {
+       kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", WKEY, KM_PRESS, 0, 0);
+       set_brush_rc_props(kmi->ptr, paint, "weight", "use_unified_weight", flags);
+
+       if (flags & RC_ROTATION) {
                kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0);
                set_brush_rc_props(kmi->ptr, paint, "texture_slot.angle", NULL, flags);
        }
 }
 
+void paint_partial_visibility_keys(wmKeyMap *keymap)
+{
+       wmKeyMapItem *kmi;
+       
+       /* Partial visiblity */
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_SHIFT, 0);
+       RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
+       RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, 0, 0);
+       RNA_enum_set(kmi->ptr, "action", PARTIALVIS_HIDE);
+       RNA_enum_set(kmi->ptr, "area", PARTIALVIS_INSIDE);
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_hide_show", HKEY, KM_PRESS, KM_ALT, 0);
+       RNA_enum_set(kmi->ptr, "action", PARTIALVIS_SHOW);
+       RNA_enum_set(kmi->ptr, "area", PARTIALVIS_ALL);
+}
+
 void ED_keymap_paint(wmKeyConfig *keyconf)
 {
        wmKeyMap *keymap;
@@ -543,38 +563,41 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        int i;
        
        /* Sculpt mode */
-       keymap= WM_keymap_find(keyconf, "Sculpt", 0, 0);
-       keymap->poll= sculpt_poll;
+       keymap = WM_keymap_find(keyconf, "Sculpt", 0, 0);
+       keymap->poll = sculpt_poll;
 
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
        RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
 
-       for(i=0; i<=5; i++)
-               RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
+       /* Partial visibility, sculpt-only for now */
+       paint_partial_visibility_keys(keymap);
+
+       for (i = 0; i <= 5; i++)
+               RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
 
        /* multires switch */
-       kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
+       kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
        RNA_int_set(kmi->ptr, "level", 1);
-       RNA_boolean_set(kmi->ptr, "relative", 1);
+       RNA_boolean_set(kmi->ptr, "relative", TRUE);
 
-       kmi= WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
+       kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEDOWNKEY, KM_PRESS, 0, 0);
        RNA_int_set(kmi->ptr, "level", -1);
-       RNA_boolean_set(kmi->ptr, "relative", 1);
+       RNA_boolean_set(kmi->ptr, "relative", TRUE);
 
        ed_keymap_paint_brush_switch(keymap, "sculpt");
        ed_keymap_paint_brush_size(keymap, "tool_settings.sculpt.brush.size");
        ed_keymap_paint_brush_radial_control(keymap, "sculpt", RC_ROTATION);
 
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", DKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_DRAW);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", SKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_SMOOTH);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", PKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_PINCH);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", IKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_INFLATE);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", GKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_GRAB);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", LKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_LAYER);
-       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 */
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, 0, 0)->ptr, "tool", SCULPT_TOOL_CLAY);
-       RNA_enum_set(WM_keymap_add_item(keymap, "BRUSH_OT_sculpt_tool_set", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "tool", SCULPT_TOOL_CREASE);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_DRAW, DKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_SMOOTH, SKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_PINCH, PKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_INFLATE, IKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_GRAB, GKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_LAYER, LKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_FLATTEN, TKEY, KM_SHIFT);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CLAY, CKEY, 0);
+       keymap_brush_select(keymap, OB_MODE_SCULPT, SCULPT_TOOL_CREASE, CKEY, KM_SHIFT);
 
        /* */
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", AKEY, KM_PRESS, 0, 0);
@@ -587,14 +610,14 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        RNA_string_set(kmi->ptr, "data_path", "tool_settings.sculpt.brush.texture_angle_source_random");
 
        /* Vertex Paint mode */
-       keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
-       keymap->poll= vertex_paint_mode_poll;
+       keymap = WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
+       keymap->poll = vertex_paint_mode_poll;
 
        WM_keymap_verify_item(keymap, "PAINT_OT_vertex_paint", LEFTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
 
        WM_keymap_add_item(keymap,
-                       "PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
+                          "PAINT_OT_vertex_color_set", KKEY, KM_PRESS, KM_SHIFT, 0);
 
        ed_keymap_paint_brush_switch(keymap, "vertex_paint");
        ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
@@ -604,8 +627,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        RNA_string_set(kmi->ptr, "data_path", "vertex_paint_object.data.use_paint_mask");
 
        /* Weight Paint mode */
-       keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
-       keymap->poll= weight_paint_mode_poll;
+       keymap = WM_keymap_find(keyconf, "Weight Paint", 0, 0);
+       keymap->poll = weight_paint_mode_poll;
 
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_paint", LEFTMOUSE, KM_PRESS, 0, 0);
 
@@ -614,7 +637,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
        WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
 
        WM_keymap_add_item(keymap,
-                       "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
+                          "PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
 
        ed_keymap_paint_brush_switch(keymap, "weight_paint");
        ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
@@ -631,18 +654,20 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
 
        
        /*Weight paint's Vertex Selection Mode */
-       keymap= WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
-       keymap->poll= vert_paint_poll;
+       keymap = WM_keymap_find(keyconf, "Weight Paint Vertex Selection", 0, 0);
+       keymap->poll = vert_paint_poll;
        WM_keymap_add_item(keymap, "PAINT_OT_vert_select_all", AKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_vert_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
-       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);
+       kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
+       RNA_boolean_set(kmi->ptr, "deselect", FALSE);
+       kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
+       RNA_boolean_set(kmi->ptr, "deselect", TRUE);
        WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
 
        /* Image/Texture Paint mode */
-       keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
-       keymap->poll= image_texture_paint_poll;
+       keymap = WM_keymap_find(keyconf, "Image Paint", 0, 0);
+       keymap->poll = image_texture_paint_poll;
 
        WM_keymap_add_item(keymap, "PAINT_OT_image_paint", LEFTMOUSE, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_grab_clone", RIGHTMOUSE, KM_PRESS, 0, 0);
@@ -651,21 +676,41 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
 
        ed_keymap_paint_brush_switch(keymap, "image_paint");
        ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
-       ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
+       ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR | RC_ZOOM);
 
        kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
        RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");
 
        /* face-mask mode */
-       keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
-       keymap->poll= facemask_paint_poll;
+       keymap = WM_keymap_find(keyconf, "Face Mask", 0, 0);
+       keymap->poll = facemask_paint_poll;
 
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_all", AKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
-       WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
-       RNA_boolean_set(WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, 0, 0);
+       RNA_boolean_set(kmi->ptr, "unselected", FALSE);
+       kmi = WM_keymap_add_item(keymap, "PAINT_OT_face_select_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
+       RNA_boolean_set(kmi->ptr, "unselected", TRUE);
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_reveal", HKEY, KM_PRESS, KM_ALT, 0);
 
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked", LKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "PAINT_OT_face_select_linked_pick", LKEY, KM_PRESS, 0, 0);
+
+       keymap = WM_keymap_find(keyconf, "UV Sculpt", 0, 0);
+       keymap->poll = uv_sculpt_poll;
+
+       kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", QKEY, KM_PRESS, 0, 0);
+       RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_uv_sculpt");
+
+       RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, 0,        0)->ptr, "mode", BRUSH_STROKE_NORMAL);
+       RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL,  0)->ptr, "mode", BRUSH_STROKE_INVERT);
+       RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_uv_sculpt_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", BRUSH_STROKE_SMOOTH);
+
+       ed_keymap_paint_brush_size(keymap, "tool_settings.uv_sculpt.brush.size");
+       ed_keymap_paint_brush_radial_control(keymap, "uv_sculpt", 0);
+
+       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);
+       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);
+       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);
+
 }