From b0fe88117b923da49486f765521ed4c3d1b58965 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 17 Aug 2009 15:05:18 +0000 Subject: [PATCH] 2.5 Paint: * Updated the brush selection UI to make the slots less apparent; adding and removing brushes now directly adds and removes slots. --- release/ui/space_view3d_toolbar.py | 9 +- source/blender/blenkernel/intern/paint.c | 59 ++++++++----- .../blender/editors/sculpt_paint/paint_ops.c | 85 +------------------ source/blender/editors/sculpt_paint/sculpt.c | 2 +- 4 files changed, 42 insertions(+), 113 deletions(-) diff --git a/release/ui/space_view3d_toolbar.py b/release/ui/space_view3d_toolbar.py index c4ee89bd1e9..c8dedd7431c 100644 --- a/release/ui/space_view3d_toolbar.py +++ b/release/ui/space_view3d_toolbar.py @@ -296,14 +296,9 @@ class VIEW3D_PT_tools_brush(PaintPanel): if not context.particle_edit_object: col = layout.split().column() - if paint: - row = col.row() - row.template_list(settings, "brushes", settings, "active_brush_index", rows=2) + row = col.row() + row.template_list(settings, "brushes", settings, "active_brush_index", rows=2) - sub_col = row.column(align=True) - sub_col.itemO("paint.brush_slot_add", icon="ICON_ZOOMIN", text="") - sub_col.itemO("paint.brush_slot_remove", icon="ICON_ZOOMOUT", text="") - col.template_ID(settings, "brush", new="brush.add") # Particle Mode # diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5ae84118356..79d1df3d67f 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -33,6 +33,7 @@ #include "BKE_brush.h" #include "BKE_global.h" +#include "BKE_library.h" #include "BKE_paint.h" #include @@ -66,23 +67,33 @@ Brush *paint_brush(Paint *p) void paint_brush_set(Paint *p, Brush *br) { - if(p && p->brushes) { - int i; - - /* See if there's already a slot with the brush */ - for(i = 0; i < p->brush_count; ++i) { - if(p->brushes[i] == br) { - p->active_brush_index = i; - break; + if(!br) { + /* Setting to NULL removes the current slot */ + paint_brush_slot_remove(p); + } + else { + int found = 0; + + if(p && p->brushes) { + int i; + + /* See if there's already a slot with the brush */ + for(i = 0; i < p->brush_count; ++i) { + if(p->brushes[i] == br) { + p->active_brush_index = i; + found = 1; + break; + } } + } + if(!found) + paint_brush_slot_add(p); + + /* Make sure the current slot is the new brush */ + p->brushes[p->active_brush_index] = br; } - else - paint_brush_slot_add(p); - - /* Make sure the current slot is the new brush */ - p->brushes[p->active_brush_index] = br; } static void paint_brush_slots_alloc(Paint *p, const int count) @@ -96,22 +107,24 @@ static void paint_brush_slots_alloc(Paint *p, const int count) void paint_brush_slot_add(Paint *p) { - Brush **orig = p->brushes; - int orig_count = p->brushes ? p->brush_count : 0; + if(p) { + Brush **orig = p->brushes; + int orig_count = p->brushes ? p->brush_count : 0; - /* Increase size of brush slot array */ - paint_brush_slots_alloc(p, orig_count + 1); - if(orig) { - memcpy(p->brushes, orig, sizeof(Brush*) * orig_count); - MEM_freeN(orig); + /* Increase size of brush slot array */ + paint_brush_slots_alloc(p, orig_count + 1); + if(orig) { + memcpy(p->brushes, orig, sizeof(Brush*) * orig_count); + MEM_freeN(orig); + } + + p->active_brush_index = orig_count; } - - p->active_brush_index = orig_count; } void paint_brush_slot_remove(Paint *p) { - if(p->brushes) { + if(p && p->brushes) { Brush **orig = p->brushes; int src, dst; diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 5d6589b7d8c..63a6591d057 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -44,22 +44,13 @@ /* Brush operators */ static int brush_add_exec(bContext *C, wmOperator *op) { - int type = RNA_enum_get(op->ptr, "type"); - int sculpt_tool = SCULPT_TOOL_DRAW; - const char *name = "Brush"; + /*int type = RNA_enum_get(op->ptr, "type");*/ Brush *br = NULL; - if(type == OB_MODE_SCULPT) { - sculpt_tool = RNA_enum_get(op->ptr, "sculpt_tool"); - RNA_enum_name(brush_sculpt_tool_items, sculpt_tool, &name); - } + br = add_brush("Brush"); - br = add_brush(name); - - if(br) { - br->sculpt_tool = sculpt_tool; + if(br) paint_brush_set(paint_get_active(CTX_data_scene(C)), br); - } return OPERATOR_FINISHED; } @@ -71,23 +62,6 @@ static EnumPropertyItem brush_type_items[] = { {OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""}, {0, NULL, 0, NULL, NULL}}; -void SCULPT_OT_brush_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Brush"; - ot->idname= "SCULPT_OT_brush_add"; - - /* api callbacks */ - ot->exec= brush_add_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, SCULPT_TOOL_DRAW, "Sculpt Tool", ""); - - RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_SCULPT, "Type", "Which paint mode to create the brush for."); -} - void BRUSH_OT_add(wmOperatorType *ot) { /* identifiers */ @@ -109,67 +83,14 @@ static int paint_poll(bContext *C) return !!paint_get_active(CTX_data_scene(C)); } -static int brush_slot_add_exec(bContext *C, wmOperator *op) -{ - Paint *p = paint_get_active(CTX_data_scene(C)); - - paint_brush_slot_add(p); - - return OPERATOR_FINISHED; -} - -void PAINT_OT_brush_slot_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Brush Slot"; - ot->idname= "PAINT_OT_brush_slot_add"; - - /* api callbacks */ - ot->poll= paint_poll; - ot->exec= brush_slot_add_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int brush_slot_remove_exec(bContext *C, wmOperator *op) -{ - Paint *p = paint_get_active(CTX_data_scene(C)); - - paint_brush_slot_remove(p); - - return OPERATOR_FINISHED; -} - -void PAINT_OT_brush_slot_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Remove Brush Slot"; - ot->idname= "PAINT_OT_brush_slot_remove"; - - /* api callbacks */ - ot->poll= paint_poll; - ot->exec= brush_slot_remove_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - /**************************** registration **********************************/ void ED_operatortypes_paint(void) { - /* paint */ - WM_operatortype_append(PAINT_OT_brush_slot_add); - WM_operatortype_append(PAINT_OT_brush_slot_remove); - /* brush */ WM_operatortype_append(BRUSH_OT_add); WM_operatortype_append(BRUSH_OT_curve_preset); - /* sculpt */ - WM_operatortype_append(SCULPT_OT_brush_add); - /* image */ WM_operatortype_append(PAINT_OT_texture_paint_toggle); WM_operatortype_append(PAINT_OT_texture_paint_radial_control); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 59a71609065..20b13087348 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1702,7 +1702,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) if(!ts->sculpt->cursor) toggle_paint_cursor(C); - paint_init(&ts->sculpt->paint, "Draw"); + paint_init(&ts->sculpt->paint, "Brush"); WM_event_add_notifier(C, NC_SCENE|ND_MODE, CTX_data_scene(C)); }