From 29f90af19cb5e8284f95d25e3f9c9519c588c742 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 4 Jan 2010 17:28:37 +0000 Subject: Fix: curve reset for brushes now gives proper smooth curve as default, also moved brush curve presets code into curvemapping code. --- release/scripts/ui/space_view3d_toolbar.py | 2 +- source/blender/blenkernel/BKE_brush.h | 8 +--- source/blender/blenkernel/BKE_colortools.h | 9 +++- source/blender/blenkernel/intern/brush.c | 43 ++--------------- source/blender/blenkernel/intern/colortools.c | 56 ++++++++++++++++++---- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/editors/include/UI_interface.h | 2 +- .../editors/interface/interface_templates.c | 43 ++++++++++++++--- source/blender/editors/sculpt_paint/paint_utils.c | 9 ++-- source/blender/editors/space_image/image_buttons.c | 2 +- source/blender/editors/space_node/drawnode.c | 6 +-- source/blender/makesrna/intern/rna_ui_api.c | 1 + 12 files changed, 109 insertions(+), 74 deletions(-) diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index e8b08218160..a9e6dcc73d9 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -733,7 +733,7 @@ class VIEW3D_PT_tools_brush_curve(PaintPanel): settings = self.paint_settings(context) brush = settings.brush - layout.template_curve_mapping(brush, "curve") + layout.template_curve_mapping(brush, "curve", brush=True) layout.operator_menu_enum("brush.curve_preset", property="shape") diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index f302618e60d..40e1859ade2 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -36,6 +36,7 @@ struct Brush; struct ImBuf; struct Scene; struct wmOperator; +enum CurveMappingPreset; /* datablock functions */ struct Brush *add_brush(const char *name); @@ -54,12 +55,7 @@ int brush_clone_image_set_nr(struct Brush *brush, int nr); int brush_clone_image_delete(struct Brush *brush); /* brush curve */ -typedef enum { - BRUSH_PRESET_SHARP, - BRUSH_PRESET_SMOOTH, - BRUSH_PRESET_MAX -} BrushCurvePreset; -void brush_curve_preset(struct Brush *b, BrushCurvePreset preset); +void brush_curve_preset(struct Brush *b, enum CurveMappingPreset preset); float brush_curve_strength_clamp(struct Brush *br, float p, const float len); float brush_curve_strength(struct Brush *br, float p, const float len); /* used for sculpt */ diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h index c571688737a..85215592ff0 100644 --- a/source/blender/blenkernel/BKE_colortools.h +++ b/source/blender/blenkernel/BKE_colortools.h @@ -34,6 +34,13 @@ struct CurveMap; struct ImBuf; struct rctf; +typedef enum CurveMappingPreset { + CURVE_PRESET_LINE, + CURVE_PRESET_SHARP, + CURVE_PRESET_SMOOTH, + CURVE_PRESET_MAX +} CurveMappingPreset; + void floatbuf_to_srgb_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w); void floatbuf_to_byte(float *rectf, unsigned char *rectc, int x1, int x2, int y1, int y2, int w); @@ -44,7 +51,7 @@ void curvemapping_set_black_white(struct CurveMapping *cumap, float *black, f void curvemap_remove(struct CurveMap *cuma, int flag); void curvemap_insert(struct CurveMap *cuma, float x, float y); -void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr); +void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, CurveMappingPreset preset); void curvemap_sethandle(struct CurveMap *cuma, int type); void curvemapping_changed(struct CurveMapping *cumap, int rem_doubles); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 444c6d2c903..ec761c27c64 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -88,7 +88,7 @@ Brush *add_brush(const char *name) brush->sculpt_tool = SCULPT_TOOL_DRAW; brush->flag |= BRUSH_SPACE; - brush_curve_preset(brush, BRUSH_PRESET_SMOOTH); + brush_curve_preset(brush, CURVE_PRESET_SMOOTH); /* enable fake user by default */ brush->id.flag |= LIB_FAKEUSER; @@ -225,7 +225,7 @@ void brush_toggled_fake_user(Brush *brush) } } -void brush_curve_preset(Brush *b, BrushCurvePreset preset) +void brush_curve_preset(Brush *b, CurveMappingPreset preset) { CurveMap *cm = NULL; @@ -233,46 +233,9 @@ void brush_curve_preset(Brush *b, BrushCurvePreset preset) b->curve = curvemapping_add(1, 0, 0, 1, 1); cm = b->curve->cm; - - if(cm->curve) - MEM_freeN(cm->curve); - - if(preset == BRUSH_PRESET_SHARP) - cm->totpoint= 3; - if(preset == BRUSH_PRESET_SMOOTH) - cm->totpoint= 4; - if(preset == BRUSH_PRESET_MAX) - cm->totpoint= 2; - - - cm->curve= MEM_callocN(cm->totpoint*sizeof(CurveMapPoint), "curve points"); cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; - if(preset == BRUSH_PRESET_SHARP) { - cm->curve[0].x= 0; - cm->curve[0].y= 1; - cm->curve[1].x= 0.33; - cm->curve[1].y= 0.33; - cm->curve[2].x= 1; - cm->curve[2].y= 0; - } - else if(preset == BRUSH_PRESET_SMOOTH) { - cm->curve[0].x= 0; - cm->curve[0].y= 1; - cm->curve[1].x= 0.25; - cm->curve[1].y= 0.92; - cm->curve[2].x= 0.75; - cm->curve[2].y= 0.08; - cm->curve[3].x= 1; - cm->curve[3].y= 0; - } - else if(preset == BRUSH_PRESET_MAX) { - cm->curve[0].x= 0; - cm->curve[0].y= 1; - cm->curve[1].x= 1; - cm->curve[1].y= 1; - } - + curvemap_reset(cm, &b->curve->clipr, preset); curvemapping_changed(b->curve, 0); } diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 48e42bc539f..cd8c0c24087 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -236,16 +236,54 @@ void curvemap_insert(CurveMap *cuma, float x, float y) cuma->curve= cmp; } -void curvemap_reset(CurveMap *cuma, rctf *clipr) +void curvemap_reset(CurveMap *cuma, rctf *clipr, CurveMappingPreset preset) { - cuma->totpoint= 2; - - cuma->curve[0].x= clipr->xmin; - cuma->curve[0].y= clipr->ymin; - cuma->curve[0].flag= 0; - cuma->curve[1].x= clipr->xmax; - cuma->curve[1].y= clipr->ymax; - cuma->curve[1].flag= 0; + if(cuma->curve) + MEM_freeN(cuma->curve); + + switch(preset) { + case CURVE_PRESET_LINE: cuma->totpoint= 2; break; + case CURVE_PRESET_SHARP: cuma->totpoint= 3; break; + case CURVE_PRESET_SMOOTH: cuma->totpoint= 4; break; + case CURVE_PRESET_MAX: cuma->totpoint= 2; break; + } + + cuma->curve= MEM_callocN(cuma->totpoint*sizeof(CurveMapPoint), "curve points"); + + switch(preset) { + case CURVE_PRESET_LINE: + cuma->curve[0].x= clipr->xmin; + cuma->curve[0].y= clipr->ymin; + cuma->curve[0].flag= 0; + cuma->curve[1].x= clipr->xmax; + cuma->curve[1].y= clipr->ymax; + cuma->curve[1].flag= 0; + break; + case CURVE_PRESET_SHARP: + cuma->curve[0].x= 0; + cuma->curve[0].y= 1; + cuma->curve[1].x= 0.33; + cuma->curve[1].y= 0.33; + cuma->curve[2].x= 1; + cuma->curve[2].y= 0; + break; + case CURVE_PRESET_SMOOTH: + cuma->curve[0].x= 0; + cuma->curve[0].y= 1; + cuma->curve[1].x= 0.25; + cuma->curve[1].y= 0.92; + cuma->curve[2].x= 0.75; + cuma->curve[2].y= 0.08; + cuma->curve[3].x= 1; + cuma->curve[3].y= 0; + break; + case CURVE_PRESET_MAX: + cuma->curve[0].x= 0; + cuma->curve[0].y= 1; + cuma->curve[1].x= 1; + cuma->curve[1].y= 1; + break; + } if(cuma->table) { MEM_freeN(cuma->table); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4165d2860a4..3e35250bd74 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1553,7 +1553,7 @@ static void direct_link_brush(FileData *fd, Brush *brush) if(brush->curve) direct_link_curvemapping(fd, brush->curve); else - brush_curve_preset(brush, BRUSH_PRESET_SHARP); + brush_curve_preset(brush, CURVE_PRESET_SHARP); } static void direct_link_script(FileData *fd, Script *script) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 1cca811d909..243e55b851a 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -653,7 +653,7 @@ uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr); uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr); void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, struct MTex *slot); void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, char *propname, int expand); -void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, char *propname, int type, int levels); +void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, char *propname, int type, int levels, int brush); void uiTemplateTriColorSet(uiLayout *layout, struct PointerRNA *ptr, char *propname); void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, char *propname, PointerRNA *used_ptr, char *used_propname, int active_layer); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 3c2387c7df0..bbfd3a8786f 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -33,6 +33,7 @@ #include "BLI_string.h" +#include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_icons.h" #include "BKE_global.h" @@ -1652,8 +1653,8 @@ static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event) CurveMap *cuma= cumap->cm+cumap->cur; switch(event) { - case 0: - curvemap_reset(cuma, &cumap->clipr); + case 0: /* reset */ + curvemap_reset(cuma, &cumap->clipr, CURVE_PRESET_LINE); curvemapping_changed(cumap, 0); break; case 1: @@ -1675,6 +1676,10 @@ static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event) cuma->flag |= CUMA_EXTEND_EXTRAPOLATE; curvemapping_changed(cumap, 0); break; + case 6: /* reset smooth */ + curvemap_reset(cuma, &cumap->clipr, CURVE_PRESET_SMOOTH); + curvemapping_changed(cumap, 0); + break; } ED_region_tag_redraw(CTX_wm_region(C)); } @@ -1701,6 +1706,26 @@ static uiBlock *curvemap_tools_func(bContext *C, struct ARegion *ar, void *cumap return block; } +static uiBlock *curvemap_brush_tools_func(bContext *C, struct ARegion *ar, void *cumap_v) +{ + uiBlock *block; + short yco= 0, menuwidth=120; + + block= uiBeginBlock(C, ar, "curvemap_tools_func", UI_EMBOSS); + uiBlockSetButmFunc(block, curvemap_tools_dofunc, cumap_v); + + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset View", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 1, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Vector Handle", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 2, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Auto Handle", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 3, ""); + uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Reset Curve", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 6, ""); + + uiBlockSetDirection(block, UI_RIGHT); + uiTextBoundsBlock(block, 50); + + uiEndBlock(C, block); + return block; +} + static void curvemap_buttons_redraw(bContext *C, void *arg1, void *arg2) { ED_region_tag_redraw(CTX_wm_region(C)); @@ -1712,7 +1737,7 @@ static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) int a; for(a=0; acm+a, &cumap->clipr); + curvemap_reset(cumap->cm+a, &cumap->clipr, CURVE_PRESET_LINE); cumap->black[0]=cumap->black[1]=cumap->black[2]= 0.0f; cumap->white[0]=cumap->white[1]=cumap->white[2]= 1.0f; @@ -1724,7 +1749,7 @@ static void curvemap_buttons_reset(bContext *C, void *cb_v, void *cumap_v) } /* still unsure how this call evolves... we use labeltype for defining what curve-channels to show */ -static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels, RNAUpdateCb *cb) +static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labeltype, int levels, int brush, RNAUpdateCb *cb) { CurveMapping *cumap= ptr->data; uiLayout *row, *sub, *split; @@ -1792,7 +1817,11 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe bt= uiDefIconBut(block, BUT, 0, ICON_ZOOMOUT, 0, 0, dx, 14, NULL, 0.0, 0.0, 0.0, 0.0, "Zoom out"); uiButSetFunc(bt, curvemap_buttons_zoom_out, cumap, NULL); - bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, 0, ICON_MODIFIER, 0, 0, dx, 18, "Tools"); + if(brush) + bt= uiDefIconBlockBut(block, curvemap_brush_tools_func, cumap, 0, ICON_MODIFIER, 0, 0, dx, 18, "Tools"); + else + bt= uiDefIconBlockBut(block, curvemap_tools_func, cumap, 0, ICON_MODIFIER, 0, 0, dx, 18, "Tools"); + uiButSetNFunc(bt, rna_update_cb, MEM_dupallocN(cb), NULL); if(cumap->flag & CUMA_DO_CLIP) icon= ICON_CLIPUV_HLT; else icon= ICON_CLIPUV_DEHLT; @@ -1825,7 +1854,7 @@ static void curvemap_buttons_layout(uiLayout *layout, PointerRNA *ptr, char labe uiBlockSetNFunc(block, NULL, NULL, NULL); } -void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, char *propname, int type, int levels) +void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, char *propname, int type, int levels, int brush) { RNAUpdateCb *cb; PropertyRNA *prop= RNA_struct_find_property(ptr, propname); @@ -1842,7 +1871,7 @@ void uiTemplateCurveMapping(uiLayout *layout, PointerRNA *ptr, char *propname, i cb->ptr= *ptr; cb->prop= prop; - curvemap_buttons_layout(layout, &cptr, type, levels, cb); + curvemap_buttons_layout(layout, &cptr, type, levels, brush, cb); MEM_freeN(cb); } diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index b968930128a..606fae3d8bb 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -16,6 +16,7 @@ #include "BLI_math.h" #include "BKE_brush.h" +#include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_DerivedMesh.h" #include "BKE_global.h" @@ -214,9 +215,9 @@ static int brush_curve_preset_poll(bContext *C) void BRUSH_OT_curve_preset(wmOperatorType *ot) { static EnumPropertyItem prop_shape_items[] = { - {BRUSH_PRESET_SHARP, "SHARP", 0, "Sharp", ""}, - {BRUSH_PRESET_SMOOTH, "SMOOTH", 0, "Smooth", ""}, - {BRUSH_PRESET_MAX, "MAX", 0, "Max", ""}, + {CURVE_PRESET_SHARP, "SHARP", 0, "Sharp", ""}, + {CURVE_PRESET_SMOOTH, "SMOOTH", 0, "Smooth", ""}, + {CURVE_PRESET_MAX, "MAX", 0, "Max", ""}, {0, NULL, 0, NULL, NULL}}; ot->name= "Preset"; @@ -228,7 +229,7 @@ void BRUSH_OT_curve_preset(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - RNA_def_enum(ot->srna, "shape", prop_shape_items, BRUSH_PRESET_SHARP, "Mode", ""); + RNA_def_enum(ot->srna, "shape", prop_shape_items, CURVE_PRESET_SMOOTH, "Mode", ""); } diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 4811eb411ec..6b92fc3fe4f 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -389,7 +389,7 @@ static void image_panel_curves(const bContext *C, Panel *pa) levels= (ibuf->channels==4); RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &simaptr); - uiTemplateCurveMapping(pa->layout, &simaptr, "curves", 'c', levels); + uiTemplateCurveMapping(pa->layout, &simaptr, "curves", 'c', levels, 0); } ED_space_image_release_buffer(sima, lock); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 30212abd4da..4c634c20440 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -196,7 +196,7 @@ static void node_buts_time(uiLayout *layout, bContext *C, PointerRNA *ptr) } #endif - uiTemplateCurveMapping(layout, ptr, "curve", 's', 0); + uiTemplateCurveMapping(layout, ptr, "curve", 's', 0, 0); row= uiLayoutRow(layout, 1); uiItemR(row, "Sta", 0, ptr, "start", 0); @@ -210,7 +210,7 @@ static void node_buts_colorramp(uiLayout *layout, bContext *C, PointerRNA *ptr) static void node_buts_curvevec(uiLayout *layout, bContext *C, PointerRNA *ptr) { - uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0); + uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0); } static float *_sample_col= NULL; // bad bad, 2.5 will do better? @@ -231,7 +231,7 @@ static void node_buts_curvecol(uiLayout *layout, bContext *C, PointerRNA *ptr) else cumap->flag &= ~CUMA_DRAW_SAMPLE; - uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0); + uiTemplateCurveMapping(layout, ptr, "mapping", 'c', 0, 0); } static void node_buts_normal(uiLayout *layout, bContext *C, PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index 37917bb7435..de20da0c0ca 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -320,6 +320,7 @@ void RNA_api_ui_layout(StructRNA *srna) api_ui_item_rna_common(func); RNA_def_enum(func, "type", curve_type_items, 0, "Type", "Type of curves to display."); RNA_def_boolean(func, "levels", 0, "", "Show black/white levels."); + RNA_def_boolean(func, "brush", 0, "", "Show brush options."); func= RNA_def_function(srna, "template_color_ramp", "uiTemplateColorRamp"); api_ui_item_rna_common(func); -- cgit v1.2.3