UI Code Quality: Use derived struct for curve profile buttons

Continuing the work from rB49f088e2d093.

Differential Revision: https://developer.blender.org/D8561
This commit is contained in:
Hans Goudey 2020-08-13 21:00:54 -04:00
parent 275f1039d2
commit 570044e9f4
Notes: blender-bot 2023-02-14 08:25:14 +01:00
Referenced by commit cd179b5048, UI Code Quality: Use derived struct for color ramp buttons
Referenced by commit 0ab21bf06a, UI Code Quality: Use derived struct for curve mapping buttons
4 changed files with 36 additions and 14 deletions

View File

@ -3797,6 +3797,10 @@ static void ui_but_alloc_info(const eButType type,
alloc_size = sizeof(uiButHSVCube);
alloc_str = "uiButHSVCube";
break;
case UI_BTYPE_CURVEPROFILE:
alloc_size = sizeof(uiButCurveProfile);
alloc_str = "uiButCurveProfile";
break;
default:
alloc_size = sizeof(uiBut);
alloc_str = "uiBut";

View File

@ -2179,13 +2179,10 @@ void ui_draw_but_CURVEPROFILE(ARegion *region,
{
uint i;
float fx, fy;
CurveProfile *profile;
if (but->editprofile) {
profile = but->editprofile;
}
else {
profile = (CurveProfile *)but->poin;
}
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
CurveProfile *profile = (but_profile->edit_profile == NULL) ? (CurveProfile *)but->poin :
but_profile->edit_profile;
/* Calculate offset and zoom. */
float zoomx = (BLI_rcti_size_x(rect) - 2.0f) / BLI_rctf_size_x(&profile->view_rect);

View File

@ -2088,13 +2088,19 @@ static void ui_apply_but(
editvec = but->editvec;
editcoba = but->editcoba;
editcumap = but->editcumap;
editprofile = but->editprofile;
if (but->type == UI_BTYPE_CURVEPROFILE) {
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
editprofile = but_profile->edit_profile;
}
but->editstr = NULL;
but->editval = NULL;
but->editvec = NULL;
but->editcoba = NULL;
but->editcumap = NULL;
but->editprofile = NULL;
if (but->type == UI_BTYPE_CURVEPROFILE) {
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
but_profile->edit_profile = NULL;
}
/* handle different types */
switch (but->type) {
@ -2205,7 +2211,10 @@ static void ui_apply_but(
but->editvec = editvec;
but->editcoba = editcoba;
but->editcumap = editcumap;
but->editprofile = editprofile;
if (but->type == UI_BTYPE_CURVEPROFILE) {
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
but_profile->edit_profile = editprofile;
}
}
/** \} */
@ -3851,7 +3860,8 @@ static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
but->editcumap = (CurveMapping *)but->poin;
}
if (but->type == UI_BTYPE_CURVEPROFILE) {
but->editprofile = (CurveProfile *)but->poin;
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
but_profile->edit_profile = (CurveProfile *)but->poin;
}
else if (but->type == UI_BTYPE_COLORBAND) {
data->coba = (ColorBand *)but->poin;
@ -3943,8 +3953,10 @@ static void ui_numedit_end(uiBut *but, uiHandleButtonData *data)
but->editvec = NULL;
but->editcoba = NULL;
but->editcumap = NULL;
but->editprofile = NULL;
if (but->type == UI_BTYPE_CURVEPROFILE) {
uiButCurveProfile *but_profile = (uiButCurveProfile *)but;
but_profile->edit_profile = NULL;
}
data->dragstartx = 0;
data->draglastx = 0;
data->dragchange = false;

View File

@ -33,6 +33,7 @@
struct AnimationEvalContext;
struct ARegion;
struct CurveProfile;
struct ID;
struct ImBuf;
struct Scene;
@ -268,7 +269,6 @@ struct uiBut {
float *editvec;
void *editcoba;
void *editcumap;
void *editprofile;
uiButPushedStateFunc pushed_state_func;
void *pushed_state_arg;
@ -320,6 +320,7 @@ typedef struct uiButDecorator {
int rnaindex;
} uiButDecorator;
/** Derived struct for #UI_BTYPE_PROGRESS_BAR. */
typedef struct uiButProgressbar {
uiBut but;
@ -327,12 +328,20 @@ typedef struct uiButProgressbar {
float progress;
} uiButProgressbar;
/** Derived struct for #UI_BTYPE_HSVCUBE. */
typedef struct uiButHSVCube {
uiBut but;
eButGradientType gradient_type;
} uiButHSVCube;
/** Derived struct for #UI_BTYPE_CURVEPROFILE. */
typedef struct uiButCurveProfile {
uiBut but;
struct CurveProfile *edit_profile;
} uiButCurveProfile;
/**
* Additional, superimposed icon for a button, invoking an operator.
*/