code cleanup: don't use magic numbers for curve flag & use bool args for curvemapping...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 21 Aug 2012 08:47:36 +0000 (08:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 21 Aug 2012 08:47:36 +0000 (08:47 +0000)
source/blender/blenkernel/BKE_colortools.h
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/colortools.c
source/blender/blenkernel/intern/texture.c
source/blender/blenloader/intern/versioning_250.c
source/blender/editors/interface/interface_draw.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_templates.c
source/blender/makesdna/DNA_color_types.h
source/blender/makesrna/intern/rna_color.c

index 90358ba..249cb32 100644 (file)
@@ -59,7 +59,7 @@ void                curvemapping_set_black_white(struct CurveMapping *cumap, con
 #define CURVEMAP_SLOPE_NEGATIVE 0
 #define CURVEMAP_SLOPE_POSITIVE 1
 void                    curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope);
-void                    curvemap_remove(struct CurveMap *cuma, int flag);
+void                    curvemap_remove(struct CurveMap *cuma, const short flag);
 void                    curvemap_remove_point(struct CurveMap *cuma, struct CurveMapPoint *cmp);
 struct CurveMapPoint    *curvemap_insert(struct CurveMap *cuma, float x, float y);
 void                    curvemap_sethandle(struct CurveMap *cuma, int type);
index 4688612..fc4df95 100644 (file)
@@ -421,7 +421,7 @@ void BKE_brush_curve_preset(Brush *b, /*CurveMappingPreset*/ int preset)
 
        b->curve->preset = preset;
        curvemap_reset(cm, &b->curve->clipr, b->curve->preset, CURVEMAP_SLOPE_NEGATIVE);
-       curvemapping_changed(b->curve, 0);
+       curvemapping_changed(b->curve, FALSE);
 }
 
 int BKE_brush_texture_set_nr(Brush *brush, int nr)
index 606fd83..4bc22d7 100644 (file)
@@ -202,7 +202,7 @@ void curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point)
 }
 
 /* removes with flag set */
-void curvemap_remove(CurveMap *cuma, int flag)
+void curvemap_remove(CurveMap *cuma, const short flag)
 {
        CurveMapPoint *cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points");
        int a, b, removed = 0;
@@ -711,12 +711,12 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles)
                        dy = cmp[a].y - cmp[a + 1].y;
                        if (sqrtf(dx * dx + dy * dy) < thresh) {
                                if (a == 0) {
-                                       cmp[a + 1].flag |= 2;
+                                       cmp[a + 1].flag |= CUMA_VECTOR;
                                        if (cmp[a + 1].flag & CUMA_SELECT)
                                                cmp[a].flag |= CUMA_SELECT;
                                }
                                else {
-                                       cmp[a].flag |= 2;
+                                       cmp[a].flag |= CUMA_VECTOR;
                                        if (cmp[a].flag & CUMA_SELECT)
                                                cmp[a + 1].flag |= CUMA_SELECT;
                                }
@@ -736,7 +736,7 @@ void curvemapping_changed_all(CurveMapping *cumap)
        for (a = 0; a < CM_TOT; a++) {
                if (cumap->cm[a].curve) {
                        cumap->cur = a;
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                }
        }
 
@@ -807,31 +807,17 @@ void curvemapping_evaluateRGBF(CurveMapping *cumap, float vecout[3], const float
 void curvemapping_evaluate_premulRGBF_ex(CurveMapping *cumap, float vecout[3], const float vecin[3],
                                          const float black[3], const float bwmul[3])
 {
-       float fac;
-
-       fac = (vecin[0] - black[0]) * bwmul[0];
-       vecout[0] = curvemap_evaluateF(cumap->cm, fac);
-
-       fac = (vecin[1] - black[1]) * bwmul[1];
-       vecout[1] = curvemap_evaluateF(cumap->cm + 1, fac);
-
-       fac = (vecin[2] - black[2]) * bwmul[2];
-       vecout[2] = curvemap_evaluateF(cumap->cm + 2, fac);
+       vecout[0] = curvemap_evaluateF(&cumap->cm[0], (vecin[0] - black[0]) * bwmul[0]);
+       vecout[1] = curvemap_evaluateF(&cumap->cm[1], (vecin[1] - black[1]) * bwmul[1]);
+       vecout[2] = curvemap_evaluateF(&cumap->cm[2], (vecin[2] - black[2]) * bwmul[2]);
 }
 
 /* RGB with black/white points and premult. tables are checked */
 void curvemapping_evaluate_premulRGBF(CurveMapping *cumap, float vecout[3], const float vecin[3])
 {
-       float fac;
-       
-       fac = (vecin[0] - cumap->black[0]) * cumap->bwmul[0];
-       vecout[0] = curvemap_evaluateF(cumap->cm, fac);
-       
-       fac = (vecin[1] - cumap->black[1]) * cumap->bwmul[1];
-       vecout[1] = curvemap_evaluateF(cumap->cm + 1, fac);
-       
-       fac = (vecin[2] - cumap->black[2]) * cumap->bwmul[2];
-       vecout[2] = curvemap_evaluateF(cumap->cm + 2, fac);
+       vecout[0] = curvemap_evaluateF(&cumap->cm[0], (vecin[0] - cumap->black[0]) * cumap->bwmul[0]);
+       vecout[1] = curvemap_evaluateF(&cumap->cm[1], (vecin[1] - cumap->black[1]) * cumap->bwmul[1]);
+       vecout[2] = curvemap_evaluateF(&cumap->cm[2], (vecin[2] - cumap->black[2]) * cumap->bwmul[2]);
 }
 
 /* same as above, byte version */
index 5bad69c..2f54fe6 100644 (file)
@@ -1292,7 +1292,7 @@ PointDensity *BKE_add_pointdensity(void)
        pd->falloff_curve->preset = CURVE_PRESET_LINE;
        pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
        curvemap_reset(pd->falloff_curve->cm, &pd->falloff_curve->clipr, pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
-       curvemapping_changed(pd->falloff_curve, 0);
+       curvemapping_changed(pd->falloff_curve, FALSE);
 
        return pd;
 } 
index d551cae..ed5ffbf 100644 (file)
@@ -2435,7 +2435,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
                                                tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
                                                tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
                                                curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
-                                               curvemapping_changed(tex->pd->falloff_curve, 0);
+                                               curvemapping_changed(tex->pd->falloff_curve, FALSE);
                                        }
                                }
                        }
index e66c040..c9a6ba0 100644 (file)
@@ -1481,7 +1481,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
        glBegin(GL_LINE_STRIP);
        
        if (cuma->table == NULL)
-               curvemapping_changed(cumap, 0);  /* 0 = no remove doubles */
+               curvemapping_changed(cumap, FALSE);
        cmp = cuma->table;
        
        /* first point */
@@ -1514,7 +1514,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
        glPointSize(3.0f);
        bglBegin(GL_POINTS);
        for (a = 0; a < cuma->totpoint; a++) {
-               if (cmp[a].flag & SELECT)
+               if (cmp[a].flag & CUMA_SELECT)
                        UI_ThemeColor(TH_TEXT_HI);
                else
                        UI_ThemeColor(TH_TEXT);
index d78a677..ce0ec31 100644 (file)
@@ -3647,7 +3647,7 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
                fy *= mval_factor;
 
                for (a = 0; a < cuma->totpoint; a++) {
-                       if (cmp[a].flag & SELECT) {
+                       if (cmp[a].flag & CUMA_SELECT) {
                                float origx = cmp[a].x, origy = cmp[a].y;
                                cmp[a].x += fx;
                                cmp[a].y += fy;
@@ -3660,7 +3660,7 @@ static int ui_numedit_but_CURVE(uiBut *but, uiHandleButtonData *data, int snap,
                        }
                }
 
-               curvemapping_changed(cumap, 0); /* no remove doubles */
+               curvemapping_changed(cumap, FALSE);
                
                if (moved_point) {
                        data->draglastx = mx;
@@ -3727,7 +3727,7 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                fy = ((float)my - but->rect.ymin) / zoomy + offsy;
                                
                                curvemap_insert(cuma, fx, fy);
-                               curvemapping_changed(cumap, 0);
+                               curvemapping_changed(cumap, FALSE);
                                changed = 1;
                        }
 
@@ -3756,12 +3756,12 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                /* loop through the curve segment table and find what's near the mouse.
                                 * 0.05 is kinda arbitrary, but seems to be what works nicely. */
                                for (i = 0; i <= CM_TABLE; i++) {
-                                       if ( (fabsf(fx - cmp[i].x) < 0.05f) &&
-                                            (fabsf(fy - cmp[i].y) < 0.05f))
+                                       if ((fabsf(fx - cmp[i].x) < 0.05f) &&
+                                           (fabsf(fy - cmp[i].y) < 0.05f))
                                        {
                                        
                                                curvemap_insert(cuma, fx, fy);
-                                               curvemapping_changed(cumap, 0);
+                                               curvemapping_changed(cumap, FALSE);
 
                                                changed = 1;
                                                
@@ -3783,11 +3783,11 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                /* deselect all if this one is deselect. except if we hold shift */
                                if (event->shift == FALSE) {
                                        for (a = 0; a < cuma->totpoint; a++)
-                                               cmp[a].flag &= ~SELECT;
-                                       cmp[sel].flag |= SELECT;
+                                               cmp[a].flag &= ~CUMA_SELECT;
+                                       cmp[sel].flag |= CUMA_SELECT;
                                }
                                else
-                                       cmp[sel].flag ^= SELECT;
+                                       cmp[sel].flag ^= CUMA_SELECT;
                        }
                        else {
                                /* move the view */
@@ -3822,12 +3822,13 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt
                                        /* deselect all, select one */
                                        if (event->shift == FALSE) {
                                                for (a = 0; a < cuma->totpoint; a++)
-                                                       cmp[a].flag &= ~SELECT;
-                                               cmp[data->dragsel].flag |= SELECT;
+                                                       cmp[a].flag &= ~CUMA_SELECT;
+                                               cmp[data->dragsel].flag |= CUMA_SELECT;
                                        }
                                }
-                               else
-                                       curvemapping_changed(cumap, 1);  /* remove doubles */
+                               else {
+                                       curvemapping_changed(cumap, TRUE);  /* remove doubles */
+                               }
                        }
 
                        button_activate_state(C, but, BUTTON_STATE_EXIT);
index 24dccb2..54202ca 100644 (file)
@@ -1622,7 +1622,7 @@ static void curvemap_buttons_setclip(bContext *UNUSED(C), void *cumap_v, void *U
 {
        CurveMapping *cumap = cumap_v;
 
-       curvemapping_changed(cumap, 0);
+       curvemapping_changed(cumap, FALSE);
 }      
 
 static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v)
@@ -1630,7 +1630,7 @@ static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v)
        CurveMapping *cumap = cumap_v;
 
        curvemap_remove(cumap->cm + cumap->cur, SELECT);
-       curvemapping_changed(cumap, 0);
+       curvemapping_changed(cumap, FALSE);
 
        rna_update_cb(C, cb_v, NULL);
 }
@@ -1672,26 +1672,26 @@ static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event)
        switch (event) {
                case 0: /* reset */
                        curvemap_reset(cuma, &cumap->clipr, cumap->preset, CURVEMAP_SLOPE_POSITIVE);
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                        break;
                case 1:
                        cumap->curr = cumap->clipr;
                        break;
                case 2: /* set vector */
                        curvemap_sethandle(cuma, 1);
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                        break;
                case 3: /* set auto */
                        curvemap_sethandle(cuma, 0);
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                        break;
                case 4: /* extend horiz */
                        cuma->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                        break;
                case 5: /* extend extrapolate */
                        cuma->flag |= CUMA_EXTEND_EXTRAPOLATE;
-                       curvemapping_changed(cumap, 0);
+                       curvemapping_changed(cumap, FALSE);
                        break;
        }
        ED_region_tag_redraw(CTX_wm_region(C));
index 1f8fdd2..4ead26c 100644 (file)
@@ -47,8 +47,10 @@ typedef struct CurveMapPoint {
 } CurveMapPoint;
 
 /* curvepoint->flag */
-#define CUMA_SELECT            1
-#define CUMA_VECTOR            2
+enum {
+       CUMA_SELECT = 1,
+       CUMA_VECTOR = 2
+};
 
 typedef struct CurveMap {
        short totpoint, flag;
index 15fdce0..5dafe77 100644 (file)
@@ -79,7 +79,7 @@ static void rna_CurveMapping_clip_set(PointerRNA *ptr, int value)
        if (value) cumap->flag |= CUMA_DO_CLIP;
        else cumap->flag &= ~CUMA_DO_CLIP;
 
-       curvemapping_changed(cumap, 0);
+       curvemapping_changed(cumap, FALSE);
 }
 
 static void rna_CurveMapping_black_level_set(PointerRNA *ptr, const float *values)