Fix: curve reset for brushes now gives proper smooth curve as default,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 4 Jan 2010 17:28:37 +0000 (17:28 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 4 Jan 2010 17:28:37 +0000 (17:28 +0000)
also moved brush curve presets code into curvemapping code.

12 files changed:
release/scripts/ui/space_view3d_toolbar.py
source/blender/blenkernel/BKE_brush.h
source/blender/blenkernel/BKE_colortools.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/colortools.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/sculpt_paint/paint_utils.c
source/blender/editors/space_image/image_buttons.c
source/blender/editors/space_node/drawnode.c
source/blender/makesrna/intern/rna_ui_api.c

index e8b082181606bbb256c5353d84d3cbafe1258675..a9e6dcc73d924f0c6d4f648c1af3e678619ac91b 100644 (file)
@@ -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")
 
 
index f302618e60d9316a148c6eaa6d57b5b51ebddeef..40e1859ade2457ff2a4d35a283ae76eddf63cba9 100644 (file)
@@ -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 */
 
index c571688737a036d01228b37a9f5912b705d56958..85215592ff0814857662b57fb1384dbe73055233 100644 (file)
@@ -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);
index 444c6d2c903e03b0574d1c59f7ecb6a21578cfb6..ec761c27c64b12f1cf801028ee6176b2380246a5 100644 (file)
@@ -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);
 }
 
index 48e42bc539f0e474f97447cda915e5657a559c86..cd8c0c24087c39da00dc38714ef412ec166ebde7 100644 (file)
@@ -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);
index 4165d2860a49a5fe95db876fbefb0467998e688d..3e35250bd748a977274f7fe17b6eea3e21e17074 100644 (file)
@@ -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)
index 1cca811d909213eea1ba258677c7c7709651fbcc..243e55b851a45e9a4292784ca3581bc9e8ce1992 100644 (file)
@@ -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);
index 3c2387c7df0f8eb79779581fe4ffa570b397b50d..bbfd3a8786f39f705e7be0d7bfb4209a99b4aa0d 100644 (file)
@@ -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; a<CM_TOT; a++)
-               curvemap_reset(cumap->cm+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);
 }
index b968930128a9dcf820bdaf79964784705835db6c..606fae3d8bb7b835fb8020f724c949a096e1b5b0 100644 (file)
@@ -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", "");
 }
 
 
index 4811eb411ec416bfc5b67a35bbf723e1a50e982d..6b92fc3fe4f959ab1d4d28ae48492e283906a33f 100644 (file)
@@ -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);
index 30212abd4da9424fdfe7aaa35267f8f0cf79617c..4c634c204404c60e96aa49b518608040c1e0bc20 100644 (file)
@@ -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)
index 37917bb743585bbe2148acb47eb845848d412d91..de20da0c0ca71bc8b5b3091d79e6e487c2a2a99b 100644 (file)
@@ -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);