Commit: cd179b5048c927781401397c8cbd71dfb3ef6766
Author: Hans Goudey
Date:   Thu Aug 13 22:00:50 2020 -0400
Branches: master
https://developer.blender.org/rBcd179b5048c927781401397c8cbd71dfb3ef6766

UI Code Quality: Use derived struct for color ramp buttons

The same changes as rB570044e9f412 and rB0ab21bf06ae0.

===================================================================

M       source/blender/editors/interface/interface.c
M       source/blender/editors/interface/interface_draw.c
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/interface/interface_intern.h

===================================================================

diff --git a/source/blender/editors/interface/interface.c 
b/source/blender/editors/interface/interface.c
index d49beaf2ed4..2ee1ecccd56 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -767,7 +767,6 @@ static bool ui_but_update_from_old_block(const bContext *C,
     but->editstr = oldbut->editstr;
     but->editval = oldbut->editval;
     but->editvec = oldbut->editvec;
-    but->editcoba = oldbut->editcoba;
     but->selsta = oldbut->selsta;
     but->selend = oldbut->selend;
     but->softmin = oldbut->softmin;
@@ -3796,6 +3795,10 @@ static void ui_but_alloc_info(const eButType type,
       alloc_size = sizeof(uiButHSVCube);
       alloc_str = "uiButHSVCube";
       break;
+    case UI_BTYPE_COLORBAND:
+      alloc_size = sizeof(uiButColorBand);
+      alloc_str = "uiButColorBand";
+      break;
     case UI_BTYPE_CURVE:
       alloc_size = sizeof(uiButCurveMapping);
       alloc_str = "uiButCurveMapping";
diff --git a/source/blender/editors/interface/interface_draw.c 
b/source/blender/editors/interface/interface_draw.c
index 1ed43697cd1..6cd274c8b15 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -1639,7 +1639,9 @@ void ui_draw_but_COLORBAND(uiBut *but, const 
uiWidgetColors *UNUSED(wcol), const
   struct ColorManagedDisplay *display = ui_block_cm_display_get(but->block);
   uint pos_id, col_id;
 
-  ColorBand *coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
+  uiButColorBand *but_coba = (uiButColorBand *)but;
+  ColorBand *coba = (but_coba->edit_coba == NULL) ? (ColorBand *)but->poin : 
but_coba->edit_coba;
+
   if (coba == NULL) {
     return;
   }
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 3bec861568d..dcae3b9a104 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -2086,8 +2086,11 @@ static void ui_apply_but(
   editstr = but->editstr;
   editval = but->editval;
   editvec = but->editvec;
-  editcoba = but->editcoba;
-  if (but->type == UI_BTYPE_CURVE) {
+  if (but->type == UI_BTYPE_COLORBAND) {
+    uiButColorBand *but_coba = (uiButColorBand *)but;
+    editcoba = but_coba->edit_coba;
+  }
+  else if (but->type == UI_BTYPE_CURVE) {
     uiButCurveMapping *but_cumap = (uiButCurveMapping *)but;
     editcumap = but_cumap->edit_cumap;
   }
@@ -2098,8 +2101,11 @@ static void ui_apply_but(
   but->editstr = NULL;
   but->editval = NULL;
   but->editvec = NULL;
-  but->editcoba = NULL;
-  if (but->type == UI_BTYPE_CURVE) {
+  if (but->type == UI_BTYPE_COLORBAND) {
+    uiButColorBand *but_coba = (uiButColorBand *)but;
+    but_coba->edit_coba = NULL;
+  }
+  else if (but->type == UI_BTYPE_CURVE) {
     uiButCurveMapping *but_cumap = (uiButCurveMapping *)but;
     but_cumap->edit_cumap = NULL;
   }
@@ -2215,8 +2221,11 @@ static void ui_apply_but(
   but->editstr = editstr;
   but->editval = editval;
   but->editvec = editvec;
-  but->editcoba = editcoba;
-  if (but->type == UI_BTYPE_CURVE) {
+  if (but->type == UI_BTYPE_COLORBAND) {
+    uiButColorBand *but_coba = (uiButColorBand *)but;
+    but_coba->edit_coba = editcoba;
+  }
+  else if (but->type == UI_BTYPE_CURVE) {
     uiButCurveMapping *but_cumap = (uiButCurveMapping *)but;
     but_cumap->edit_cumap = editcumap;
   }
@@ -3874,8 +3883,9 @@ static void ui_numedit_begin(uiBut *but, 
uiHandleButtonData *data)
     but_profile->edit_profile = (CurveProfile *)but->poin;
   }
   else if (but->type == UI_BTYPE_COLORBAND) {
+    uiButColorBand *but_coba = (uiButColorBand *)but;
     data->coba = (ColorBand *)but->poin;
-    but->editcoba = data->coba;
+    but_coba->edit_coba = data->coba;
   }
   else if (ELEM(but->type,
                 UI_BTYPE_UNITVEC,
@@ -3961,8 +3971,11 @@ static void ui_numedit_end(uiBut *but, 
uiHandleButtonData *data)
 {
   but->editval = NULL;
   but->editvec = NULL;
-  but->editcoba = NULL;
-  if (but->type == UI_BTYPE_CURVE) {
+  if (but->type == UI_BTYPE_COLORBAND) {
+    uiButColorBand *but_coba = (uiButColorBand *)but;
+    but_coba->edit_coba = NULL;
+  }
+  else if (but->type == UI_BTYPE_CURVE) {
     uiButCurveMapping *but_cumap = (uiButCurveMapping *)but;
     but_cumap->edit_cumap = NULL;
   }
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index 6cd4571e2ab..eb1bd1ba42e 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -268,7 +268,6 @@ struct uiBut {
   char *editstr;
   double *editval;
   float *editvec;
-  void *editcoba;
 
   uiButPushedStateFunc pushed_state_func;
   void *pushed_state_arg;
@@ -335,6 +334,13 @@ typedef struct uiButHSVCube {
   eButGradientType gradient_type;
 } uiButHSVCube;
 
+/** Derived struct for #UI_BTYPE_CURVEPROFILE. */
+typedef struct uiButColorBand {
+  uiBut but;
+
+  struct ColorBand *edit_coba;
+} uiButColorBand;
+
 /** Derived struct for #UI_BTYPE_CURVEPROFILE. */
 typedef struct uiButCurveProfile {
   uiBut but;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to