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. --- 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 ++++++++++++++++++++++----- 4 files changed, 60 insertions(+), 56 deletions(-) (limited to 'source/blender/blenkernel') 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); -- cgit v1.2.3