diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-08-17 06:49:31 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-08-17 06:49:31 +0400 |
commit | 9d2d3a8be7c3c0b101e7f0f33bb1a04c69deaf67 (patch) | |
tree | 93345dd6c9c76d3c3052573d45e7230918a197a8 /source/blender/editors/sculpt_paint | |
parent | 1e0fd0d4c14824e856424000e1122dcb1c8b44dd (diff) |
2.5 Paint:
* Converted vertex paint and weight paint to use the new Paint type
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 54 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 60 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 7 |
4 files changed, 83 insertions, 40 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 4ff658b51cf..93744072fff 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5167,7 +5167,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) me->mtface= CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface); - brush_check_exists(&scene->toolsettings->imapaint.brush); + brush_check_exists(&scene->toolsettings->imapaint.brush, "Brush"); if(U.glreslimit != 0) GPU_free_images(); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index c1404b7a63e..5d6589b7d8c 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -19,6 +19,8 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include "DNA_brush_types.h" +#include "DNA_object_types.h" #include "DNA_scene_types.h" #include "BKE_brush.h" @@ -26,6 +28,7 @@ #include "BKE_paint.h" #include "ED_sculpt.h" +#include "UI_resources.h" #include "WM_api.h" #include "WM_types.h" @@ -39,13 +42,18 @@ #include <string.h> /* Brush operators */ -static int new_brush_exec(bContext *C, wmOperator *op) +static int brush_add_exec(bContext *C, wmOperator *op) { - int sculpt_tool = RNA_enum_get(op->ptr, "sculpt_tool"); - const char *name = NULL; + int type = RNA_enum_get(op->ptr, "type"); + int sculpt_tool = SCULPT_TOOL_DRAW; + const char *name = "Brush"; Brush *br = NULL; - RNA_enum_name(brush_sculpt_tool_items, sculpt_tool, &name); + 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(name); if(br) { @@ -56,20 +64,43 @@ static int new_brush_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BRUSH_OT_new(wmOperatorType *ot) +static EnumPropertyItem brush_type_items[] = { + {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}}; + +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 */ ot->name= "Add Brush"; - ot->idname= "BRUSH_OT_new"; + ot->idname= "BRUSH_OT_add"; /* api callbacks */ - ot->exec= new_brush_exec; + ot->exec= brush_add_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - /* TODO: add enum props for other paint modes */ - RNA_def_enum(ot->srna, "sculpt_tool", brush_sculpt_tool_items, 0, "Sculpt Tool", ""); + RNA_def_enum(ot->srna, "type", brush_type_items, OB_MODE_VERTEX_PAINT, "Type", "Which paint mode to create the brush for."); } /* Paint operators */ @@ -133,9 +164,12 @@ void ED_operatortypes_paint(void) WM_operatortype_append(PAINT_OT_brush_slot_remove); /* brush */ - WM_operatortype_append(BRUSH_OT_new); + 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/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index bbc68a6bd0a..1a548708ec8 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -76,6 +76,7 @@ #include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_paint.h" #include "BKE_utildefines.h" #include "WM_api.h" @@ -110,7 +111,8 @@ static int vp_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if(ob && ob->mode & OB_MODE_VERTEX_PAINT) { + if(ob && ob->mode & OB_MODE_VERTEX_PAINT && + paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) { ScrArea *sa= CTX_wm_area(C); if(sa->spacetype==SPACE_VIEW3D) { ARegion *ar= CTX_wm_region(C); @@ -125,7 +127,8 @@ static int wp_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - if(ob && ob->mode & OB_MODE_WEIGHT_PAINT) { + if(ob && ob->mode & OB_MODE_WEIGHT_PAINT && + paint_brush(&CTX_data_tool_settings(C)->wpaint->paint)) { ScrArea *sa= CTX_wm_area(C); if(sa->spacetype==SPACE_VIEW3D) { ARegion *ar= CTX_wm_region(C); @@ -140,14 +143,14 @@ static int wp_poll(bContext *C) /* Cursors */ static void vp_drawcursor(bContext *C, int x, int y, void *customdata) { - ToolSettings *ts= CTX_data_tool_settings(C); + Brush *brush = paint_brush(&CTX_data_tool_settings(C)->vpaint->paint); glTranslatef((float)x, (float)y, 0.0f); glColor4ub(255, 255, 255, 128); glEnable( GL_LINE_SMOOTH ); glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->brush->size, 40); + glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); glDisable(GL_BLEND); glDisable( GL_LINE_SMOOTH ); @@ -156,14 +159,14 @@ static void vp_drawcursor(bContext *C, int x, int y, void *customdata) static void wp_drawcursor(bContext *C, int x, int y, void *customdata) { - ToolSettings *ts= CTX_data_tool_settings(C); - + Brush *brush = paint_brush(&CTX_data_tool_settings(C)->wpaint->paint); + glTranslatef((float)x, (float)y, 0.0f); glColor4ub(200, 200, 255, 128); glEnable( GL_LINE_SMOOTH ); glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->brush->size, 40); + glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); glDisable(GL_BLEND); glDisable( GL_LINE_SMOOTH ); @@ -236,7 +239,8 @@ unsigned int rgba_to_mcol(float r, float g, float b, float a) static unsigned int vpaint_get_current_col(VPaint *vp) { - return rgba_to_mcol(vp->brush->rgb[0], vp->brush->rgb[1], vp->brush->rgb[2], 1.0f); + Brush *brush = paint_brush(&vp->paint); + return rgba_to_mcol(brush->rgb[0], brush->rgb[1], brush->rgb[2], 1.0f); } void do_shared_vertexcol(Mesh *me) @@ -725,6 +729,7 @@ static unsigned int mcol_darken(unsigned int col1, unsigned int col2, int fac) static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, unsigned int paintcol, int alpha) { + Brush *brush = paint_brush(&vp->paint); if(vp->mode==VP_MIX || vp->mode==VP_BLUR) *col= mcol_blend( *col, paintcol, alpha); else if(vp->mode==VP_ADD) *col= mcol_add( *col, paintcol, alpha); @@ -738,7 +743,7 @@ static void vpaint_blend(VPaint *vp, unsigned int *col, unsigned int *colorig, u unsigned int testcol=0, a; char *cp, *ct, *co; - alpha= (int)(255.0*vp->brush->alpha); + alpha= (int)(255.0*brush->alpha); if(vp->mode==VP_MIX || vp->mode==VP_BLUR) testcol= mcol_blend( *colorig, paintcol, alpha); else if(vp->mode==VP_ADD) testcol= mcol_add( *colorig, paintcol, alpha); @@ -804,6 +809,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, short *mval) { + Brush *brush = paint_brush(&vp->paint); float fac, dx, dy; int alpha; short vertco[2]; @@ -814,14 +820,14 @@ static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], floa dy= mval[1]-vertco[1]; fac= sqrt(dx*dx + dy*dy); - if(fac > vp->brush->size) return 0; + if(fac > brush->size) return 0; if(vp->flag & VP_HARD) alpha= 255; else - alpha= 255.0*vp->brush->alpha*(1.0-fac/vp->brush->size); + alpha= 255.0*brush->alpha*(1.0-fac/brush->size); } else { - alpha= 255.0*vp->brush->alpha; + alpha= 255.0*brush->alpha; } if(vp->flag & VP_NORMALS) { @@ -843,6 +849,7 @@ static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], floa static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval) { + Brush *brush = paint_brush(&wp->paint); if(dw==NULL || uw==NULL) return; @@ -868,7 +875,7 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float if((wp->flag & VP_SPRAY)==0) { float testw=0.0f; - alpha= wp->brush->alpha; + alpha= brush->alpha; if(wp->mode==VP_MIX || wp->mode==VP_BLUR) testw = paintval*alpha + uw->weight*(1.0-alpha); else if(wp->mode==VP_ADD) @@ -1117,8 +1124,8 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */ if(wp==NULL) wp= scene->toolsettings->wpaint= new_vpaint(1); - brush_check_exists(&wp->brush); - + paint_init(&wp->paint, "Brush"); + toggle_paint_cursor(C, 1); mesh_octree_table(ob, NULL, NULL, 's'); @@ -1178,8 +1185,10 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot) static int vpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { + Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->vpaint->paint); + toggle_paint_cursor(C, 0); - brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->vpaint->brush, 1); + brush_radial_control_invoke(op, brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1193,13 +1202,15 @@ static int vpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve static int vpaint_radial_control_exec(bContext *C, wmOperator *op) { - return brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->vpaint->brush, 1); + Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->vpaint->paint); + return brush_radial_control_exec(op, brush, 1); } static int wpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { + Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->wpaint->paint); toggle_paint_cursor(C, 1); - brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->wpaint->brush, 1); + brush_radial_control_invoke(op, brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1213,7 +1224,8 @@ static int wpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve static int wpaint_radial_control_exec(bContext *C, wmOperator *op) { - return brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->wpaint->brush, 1); + Brush *brush = paint_brush(&CTX_data_scene(C)->toolsettings->wpaint->paint); + return brush_radial_control_exec(op, brush, 1); } void PAINT_OT_weight_paint_radial_control(wmOperatorType *ot) @@ -1297,6 +1309,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) { ToolSettings *ts= CTX_data_tool_settings(C); VPaint *wp= ts->wpaint; + Brush *brush = paint_brush(&wp->paint); switch(event->type) { case LEFTMOUSE: @@ -1332,7 +1345,7 @@ static int wpaint_modal(bContext *C, wmOperator *op, wmEvent *event) /* which faces are involved */ if(wp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], wp->brush->size); + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); @@ -1611,7 +1624,6 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ } } else { - ob->mode |= OB_MODE_VERTEX_PAINT; /* Turn off weight painting */ if (ob->mode & OB_MODE_WEIGHT_PAINT) @@ -1621,7 +1633,8 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ vp= scene->toolsettings->vpaint= new_vpaint(0); toggle_paint_cursor(C, 0); - brush_check_exists(&scene->toolsettings->vpaint->brush); + + paint_init(&vp->paint, "Brush"); } if (me) @@ -1700,6 +1713,7 @@ static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) { ToolSettings *ts= CTX_data_tool_settings(C); VPaint *vp= ts->vpaint; + Brush *brush = paint_brush(&vp->paint); switch(event->type) { case LEFTMOUSE: @@ -1732,7 +1746,7 @@ static int vpaint_modal(bContext *C, wmOperator *op, wmEvent *event) /* which faces are involved */ if(vp->flag & VP_AREA) { - totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], vp->brush->size); + totindex= sample_backbuf_area(vc, indexar, me->totface, mval[0], mval[1], brush->size); } else { indexar[0]= view3d_sample_backbuf(vc, mval[0], mval[1]); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index eae73feeccb..59a71609065 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1686,8 +1686,6 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) free_sculptsession(&ob->sculpt); } else { - Brush *brush; - /* Enter sculptmode */ ob->mode |= OB_MODE_SCULPT; @@ -1704,10 +1702,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op) if(!ts->sculpt->cursor) toggle_paint_cursor(C); - /* If there's no brush, create one */ - brush = paint_brush(&ts->sculpt->paint); - brush_check_exists(&brush); - paint_brush_set(&ts->sculpt->paint, brush); + paint_init(&ts->sculpt->paint, "Draw"); WM_event_add_notifier(C, NC_SCENE|ND_MODE, CTX_data_scene(C)); } |