Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-08-07 18:42:13 +0300
committerJulian Eisel <julian@blender.org>2020-08-07 18:46:58 +0300
commitdcff28e1e7a8b1be9bb6acec24af7ca6f6468e77 (patch)
tree33b588ed6c5688a377a2a7d2421e6715c1612217 /source/blender
parent60b42ef117b66cca61468be45aab54b9bb1217e0 (diff)
UI Code Quality: Use derived struct for HSV Cube buttons
For the main rationale behind this design, see 49f088e2d093. Further, this removes users of uiBut.a1, which is a very ugly design choice (hard to reason about). Part of T74432.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/include/UI_interface.h4
-rw-r--r--source/blender/editors/interface/interface.c4
-rw-r--r--source/blender/editors/interface/interface_handlers.c42
-rw-r--r--source/blender/editors/interface/interface_intern.h14
-rw-r--r--source/blender/editors/interface/interface_region_color_picker.c161
-rw-r--r--source/blender/editors/interface/interface_templates.c246
-rw-r--r--source/blender/editors/interface/interface_widgets.c30
7 files changed, 262 insertions, 239 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index e8352bc6b21..c02b4da3599 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -378,7 +378,7 @@ typedef enum {
#define BUTTYPE (63 << 9)
/** Gradient types, for color picker #UI_BTYPE_HSVCUBE etc. */
-enum {
+typedef enum eButGradientType {
UI_GRAD_SV = 0,
UI_GRAD_HV = 1,
UI_GRAD_HS = 2,
@@ -388,7 +388,7 @@ enum {
UI_GRAD_V_ALT = 9,
UI_GRAD_L_ALT = 10,
-};
+} eButGradientType;
/* Drawing
*
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index a84ca33a7d7..22fbffa9030 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3793,6 +3793,10 @@ static void ui_but_alloc_info(const eButType type,
alloc_size = sizeof(uiButProgressbar);
alloc_str = "uiButProgressbar";
break;
+ case UI_BTYPE_HSVCUBE:
+ alloc_size = sizeof(uiButHSVCube);
+ alloc_str = "uiButHSVCube";
+ break;
default:
alloc_size = sizeof(uiBut);
alloc_str = "uiBut";
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 999ddca65b9..ef1bc3374d0 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -5941,9 +5941,11 @@ static void clamp_axis_max_v3(float v[3], const float max)
}
}
-static void ui_rgb_to_color_picker_HSVCUBE_compat_v(uiBut *but, const float rgb[3], float hsv[3])
+static void ui_rgb_to_color_picker_HSVCUBE_compat_v(const uiButHSVCube *hsv_but,
+ const float rgb[3],
+ float hsv[3])
{
- if (but->a1 == UI_GRAD_L_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_L_ALT) {
rgb_to_hsl_compat_v(rgb, hsv);
}
else {
@@ -5951,9 +5953,11 @@ static void ui_rgb_to_color_picker_HSVCUBE_compat_v(uiBut *but, const float rgb[
}
}
-static void ui_rgb_to_color_picker_HSVCUBE_v(uiBut *but, const float rgb[3], float hsv[3])
+static void ui_rgb_to_color_picker_HSVCUBE_v(const uiButHSVCube *hsv_but,
+ const float rgb[3],
+ float hsv[3])
{
- if (but->a1 == UI_GRAD_L_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_L_ALT) {
rgb_to_hsl_v(rgb, hsv);
}
else {
@@ -5961,9 +5965,11 @@ static void ui_rgb_to_color_picker_HSVCUBE_v(uiBut *but, const float rgb[3], flo
}
}
-static void ui_color_picker_to_rgb_HSVCUBE_v(uiBut *but, const float hsv[3], float rgb[3])
+static void ui_color_picker_to_rgb_HSVCUBE_v(const uiButHSVCube *hsv_but,
+ const float hsv[3],
+ float rgb[3])
{
- if (but->a1 == UI_GRAD_L_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_L_ALT) {
hsl_to_rgb_v(hsv, rgb);
}
else {
@@ -5978,6 +5984,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
const enum eSnapType snap,
const bool shift)
{
+ const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
ColorPicker *cpicker = but->custom_data;
float *hsv = cpicker->color_data;
float rgb[3];
@@ -5999,7 +6006,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
- ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv);
+ ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
/* only apply the delta motion, not absolute */
if (shift) {
@@ -6014,10 +6021,10 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
copy_v3_v3(hsvo, hsv);
- ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsvo);
+ ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsvo);
/* and original position */
- ui_hsvcube_pos_from_vals(but, &rect_i, hsvo, &xpos, &ypos);
+ ui_hsvcube_pos_from_vals(hsv_but, &rect_i, hsvo, &xpos, &ypos);
mx_fl = xpos - (data->dragstartx - mx_fl);
my_fl = ypos - (data->dragstarty - my_fl);
@@ -6029,7 +6036,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
CLAMP(x, 0.0f, 1.0f);
CLAMP(y, 0.0f, 1.0f);
- switch ((int)but->a1) {
+ switch (hsv_but->gradient_type) {
case UI_GRAD_SV:
hsv[1] = x;
hsv[2] = y;
@@ -6067,16 +6074,16 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
}
if (snap != SNAP_OFF) {
- if (ELEM((int)but->a1, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) {
+ if (ELEM(hsv_but->gradient_type, UI_GRAD_HV, UI_GRAD_HS, UI_GRAD_H)) {
ui_color_snap_hue(snap, &hsv[0]);
}
}
- ui_color_picker_to_rgb_HSVCUBE_v(but, hsv, rgb);
+ ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, hsv, rgb);
ui_color_picker_to_scene_linear_space(but, rgb);
/* clamp because with color conversion we can exceed range [#34295] */
- if (but->a1 == UI_GRAD_V_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_V_ALT) {
clamp_axis_max_v3(rgb, but->softmax);
}
@@ -6161,6 +6168,7 @@ static void ui_ndofedit_but_HSVCUBE(uiBut *but,
static int ui_do_but_HSVCUBE(
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
{
+ const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
int mx, my;
mx = event->x;
@@ -6199,7 +6207,7 @@ static int ui_do_but_HSVCUBE(
#endif /* WITH_INPUT_NDOF */
/* XXX hardcoded keymap check.... */
if (event->type == EVT_BACKSPACEKEY && event->val == KM_PRESS) {
- if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) {
+ if (ELEM(hsv_but->gradient_type, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) {
int len;
/* reset only value */
@@ -6212,15 +6220,15 @@ static int ui_do_but_HSVCUBE(
float *hsv = cpicker->color_data;
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
- ui_rgb_to_color_picker_HSVCUBE_v(but, def, def_hsv);
+ ui_rgb_to_color_picker_HSVCUBE_v(hsv_but, def, def_hsv);
ui_but_v3_get(but, rgb);
- ui_rgb_to_color_picker_HSVCUBE_compat_v(but, rgb, hsv);
+ ui_rgb_to_color_picker_HSVCUBE_compat_v(hsv_but, rgb, hsv);
def_hsv[0] = hsv[0];
def_hsv[1] = hsv[1];
- ui_color_picker_to_rgb_HSVCUBE_v(but, def_hsv, rgb);
+ ui_color_picker_to_rgb_HSVCUBE_v(hsv_but, def_hsv, rgb);
ui_but_v3_set(but, rgb);
RNA_property_update(C, &but->rnapoin, but->rnaprop);
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 41110883729..6718db39e61 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -172,7 +172,6 @@ struct uiBut {
/**
* For #uiBut.type:
- * - UI_BTYPE_HSVCUBE: Use UI_GRAD_* values.
* - UI_BTYPE_NUM: Use to store RNA 'step' value, for dragging and click-step.
* - UI_BTYPE_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!).
* - UI_BTYPE_SCROLL: Use as scroll size.
@@ -328,6 +327,12 @@ typedef struct uiButProgressbar {
float progress;
} uiButProgressbar;
+typedef struct uiButHSVCube {
+ uiBut but;
+
+ eButGradientType gradient_type;
+} uiButHSVCube;
+
/**
* Additional, superimposed icon for a button, invoking an operator.
*/
@@ -535,7 +540,7 @@ extern void ui_hsvcircle_vals_from_pos(
extern void ui_hsvcircle_pos_from_vals(
const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *xpos, float *ypos);
extern void ui_hsvcube_pos_from_vals(
- const struct uiBut *but, const rcti *rect, const float *hsv, float *xp, float *yp);
+ const struct uiButHSVCube *hsv_but, const rcti *rect, const float *hsv, float *xp, float *yp);
extern void ui_but_string_get_ex(uiBut *but,
char *str,
@@ -777,7 +782,10 @@ extern void ui_draw_aligned_panel(struct uiStyle *style,
extern void ui_draw_dropshadow(
const rctf *rct, float radius, float aspect, float alpha, int select);
-void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, const float alpha);
+void ui_draw_gradient(const rcti *rect,
+ const float hsv[3],
+ const eButGradientType type,
+ const float alpha);
void ui_draw_but_TAB_outline(const rcti *rect,
float rad,
diff --git a/source/blender/editors/interface/interface_region_color_picker.c b/source/blender/editors/interface/interface_region_color_picker.c
index f9873f8b96f..0d1b483716e 100644
--- a/source/blender/editors/interface/interface_region_color_picker.c
+++ b/source/blender/editors/interface/interface_region_color_picker.c
@@ -369,6 +369,7 @@ static void ui_colorpicker_circle(uiBlock *block,
ColorPicker *cpicker)
{
uiBut *bt;
+ uiButHSVCube *hsv_but;
/* HS circle */
bt = uiDefButR_prop(block,
@@ -392,91 +393,99 @@ static void ui_colorpicker_circle(uiBlock *block,
/* value */
if (U.color_picker_type == USER_CP_CIRCLE_HSL) {
- bt = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- PICKER_W + PICKER_SPACE,
- 0,
- PICKER_BAR,
- PICKER_H,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- UI_GRAD_L_ALT,
- 0,
- "Lightness");
- UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ PICKER_W + PICKER_SPACE,
+ 0,
+ PICKER_BAR,
+ PICKER_H,
+ ptr,
+ prop,
+ -1,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "Lightness");
+ hsv_but->gradient_type = UI_GRAD_L_ALT;
+ UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
}
else {
- bt = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- PICKER_W + PICKER_SPACE,
- 0,
- PICKER_BAR,
- PICKER_H,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- UI_GRAD_V_ALT,
- 0,
- TIP_("Value"));
- UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
- }
- bt->custom_data = cpicker;
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ PICKER_W + PICKER_SPACE,
+ 0,
+ PICKER_BAR,
+ PICKER_H,
+ ptr,
+ prop,
+ -1,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ TIP_("Value"));
+ hsv_but->gradient_type = UI_GRAD_V_ALT;
+ UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
+ }
+ hsv_but->but.custom_data = cpicker;
}
-static void ui_colorpicker_square(
- uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type, ColorPicker *cpicker)
+static void ui_colorpicker_square(uiBlock *block,
+ PointerRNA *ptr,
+ PropertyRNA *prop,
+ eButGradientType type,
+ ColorPicker *cpicker)
{
- uiBut *bt;
- int bartype = type + 3;
+ uiButHSVCube *hsv_but;
+
+ BLI_assert(type <= UI_GRAD_HS);
/* HS square */
- bt = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- PICKER_BAR + PICKER_SPACE,
- PICKER_TOTAL_W,
- PICKER_H,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- type,
- 0,
- TIP_("Color"));
- UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
- bt->custom_data = cpicker;
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ PICKER_BAR + PICKER_SPACE,
+ PICKER_TOTAL_W,
+ PICKER_H,
+ ptr,
+ prop,
+ -1,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ TIP_("Color"));
+ hsv_but->gradient_type = type;
+ UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
+ hsv_but->but.custom_data = cpicker;
/* value */
- bt = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 0,
- PICKER_TOTAL_W,
- PICKER_BAR,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- bartype,
- 0,
- TIP_("Value"));
- UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
- bt->custom_data = cpicker;
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ 0,
+ PICKER_TOTAL_W,
+ PICKER_BAR,
+ ptr,
+ prop,
+ -1,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ TIP_("Value"));
+ hsv_but->gradient_type = type + 3;
+ UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
+ hsv_but->but.custom_data = cpicker;
}
/* a HS circle, V slider, rgb/hsv/hex sliders */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index c7d3d7bf501..56807621358 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -5188,6 +5188,7 @@ void uiTemplateColorPicker(uiLayout *layout,
uiBlock *block = uiLayoutGetBlock(layout);
uiLayout *col, *row;
uiBut *but = NULL;
+ uiButHSVCube *hsv_but;
ColorPicker *cpicker = ui_block_colorpicker_create(block);
float softmin, softmax, step, precision;
@@ -5203,58 +5204,36 @@ void uiTemplateColorPicker(uiLayout *layout,
switch (U.color_picker_type) {
case USER_CP_SQUARE_SV:
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 0,
- WHEEL_SIZE,
- WHEEL_SIZE,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- UI_GRAD_SV,
- 0,
- "");
- break;
case USER_CP_SQUARE_HS:
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 0,
- WHEEL_SIZE,
- WHEEL_SIZE,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- UI_GRAD_HS,
- 0,
- "");
- break;
case USER_CP_SQUARE_HV:
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 0,
- WHEEL_SIZE,
- WHEEL_SIZE,
- ptr,
- prop,
- -1,
- 0.0,
- 0.0,
- UI_GRAD_HV,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ 0,
+ WHEEL_SIZE,
+ WHEEL_SIZE,
+ ptr,
+ prop,
+ -1,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ "");
+ switch (U.color_picker_type) {
+ case USER_CP_SQUARE_SV:
+ hsv_but->gradient_type = UI_GRAD_SV;
+ break;
+ case USER_CP_SQUARE_HS:
+ hsv_but->gradient_type = UI_GRAD_HS;
+ break;
+ case USER_CP_SQUARE_HV:
+ hsv_but->gradient_type = UI_GRAD_HV;
+ break;
+ }
+ but = &hsv_but->but;
break;
/* user default */
@@ -5297,105 +5276,110 @@ void uiTemplateColorPicker(uiLayout *layout,
switch (U.color_picker_type) {
case USER_CP_CIRCLE_HSL:
uiItemS(row);
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- WHEEL_SIZE + 6,
- 0,
- 14 * UI_DPI_FAC,
- WHEEL_SIZE,
- ptr,
- prop,
- -1,
- softmin,
- softmax,
- UI_GRAD_L_ALT,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ WHEEL_SIZE + 6,
+ 0,
+ 14 * UI_DPI_FAC,
+ WHEEL_SIZE,
+ ptr,
+ prop,
+ -1,
+ softmin,
+ softmax,
+ 0,
+ 0,
+ "");
+ hsv_but->gradient_type = UI_GRAD_L_ALT;
break;
case USER_CP_SQUARE_SV:
uiItemS(col);
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 4,
- WHEEL_SIZE,
- 18 * UI_DPI_FAC,
- ptr,
- prop,
- -1,
- softmin,
- softmax,
- UI_GRAD_SV + 3,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ 4,
+ WHEEL_SIZE,
+ 18 * UI_DPI_FAC,
+ ptr,
+ prop,
+ -1,
+ softmin,
+ softmax,
+ 0,
+ 0,
+ "");
+ hsv_but->gradient_type = UI_GRAD_SV + 3;
break;
case USER_CP_SQUARE_HS:
uiItemS(col);
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 4,
- WHEEL_SIZE,
- 18 * UI_DPI_FAC,
- ptr,
- prop,
- -1,
- softmin,
- softmax,
- UI_GRAD_HS + 3,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ 4,
+ WHEEL_SIZE,
+ 18 * UI_DPI_FAC,
+ ptr,
+ prop,
+ -1,
+ softmin,
+ softmax,
+ 0,
+ 0,
+ "");
+ hsv_but->gradient_type = UI_GRAD_HS + 3;
break;
case USER_CP_SQUARE_HV:
uiItemS(col);
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- 0,
- 4,
- WHEEL_SIZE,
- 18 * UI_DPI_FAC,
- ptr,
- prop,
- -1,
- softmin,
- softmax,
- UI_GRAD_HV + 3,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ 0,
+ 4,
+ WHEEL_SIZE,
+ 18 * UI_DPI_FAC,
+ ptr,
+ prop,
+ -1,
+ softmin,
+ softmax,
+ 0,
+ 0,
+ "");
+ hsv_but->gradient_type = UI_GRAD_HV + 3;
break;
/* user default */
case USER_CP_CIRCLE_HSV:
default:
uiItemS(row);
- but = uiDefButR_prop(block,
- UI_BTYPE_HSVCUBE,
- 0,
- "",
- WHEEL_SIZE + 6,
- 0,
- 14 * UI_DPI_FAC,
- WHEEL_SIZE,
- ptr,
- prop,
- -1,
- softmin,
- softmax,
- UI_GRAD_V_ALT,
- 0,
- "");
+ hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
+ UI_BTYPE_HSVCUBE,
+ 0,
+ "",
+ WHEEL_SIZE + 6,
+ 0,
+ 14 * UI_DPI_FAC,
+ WHEEL_SIZE,
+ ptr,
+ prop,
+ -1,
+ softmin,
+ softmax,
+ 0,
+ 0,
+ "");
+ hsv_but->gradient_type = UI_GRAD_V_ALT;
break;
}
- but->custom_data = cpicker;
+ hsv_but->but.custom_data = cpicker;
}
}
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 7c33c5e7048..c4de2730600 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -2971,7 +2971,10 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
* \{ */
/* draws in resolution of 48x4 colors */
-void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, const float alpha)
+void ui_draw_gradient(const rcti *rect,
+ const float hsv[3],
+ const eButGradientType type,
+ const float alpha)
{
/* allows for 4 steps (red->yellow) */
const int steps = 48;
@@ -3088,6 +3091,8 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
copy_v3_v3(col1[1], col1[2]);
copy_v3_v3(col1[3], col1[2]);
break;
+ default:
+ break;
}
/* rect */
@@ -3122,11 +3127,11 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
}
void ui_hsvcube_pos_from_vals(
- const uiBut *but, const rcti *rect, const float *hsv, float *r_xp, float *r_yp)
+ const uiButHSVCube *hsv_but, const rcti *rect, const float *hsv, float *r_xp, float *r_yp)
{
float x = 0.0f, y = 0.0f;
- switch ((int)but->a1) {
+ switch (hsv_but->gradient_type) {
case UI_GRAD_SV:
x = hsv[1];
y = hsv[2];
@@ -3159,7 +3164,7 @@ void ui_hsvcube_pos_from_vals(
case UI_GRAD_V_ALT:
x = 0.5f;
/* exception only for value strip - use the range set in but->min/max */
- y = (hsv[2] - but->softmin) / (but->softmax - but->softmin);
+ y = (hsv[2] - hsv_but->but.softmin) / (hsv_but->but.softmax - hsv_but->but.softmin);
break;
}
@@ -3170,6 +3175,7 @@ void ui_hsvcube_pos_from_vals(
static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
{
+ const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
float rgb[3];
float x = 0.0f, y = 0.0f;
ColorPicker *cpicker = but->custom_data;
@@ -3183,9 +3189,9 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
ui_scene_linear_to_color_picker_space(but, rgb);
rgb_to_hsv_compat_v(rgb, hsv_n);
- ui_draw_gradient(rect, hsv_n, but->a1, 1.0f);
+ ui_draw_gradient(rect, hsv_n, hsv_but->gradient_type, 1.0f);
- ui_hsvcube_pos_from_vals(but, rect, hsv_n, &x, &y);
+ ui_hsvcube_pos_from_vals(hsv_but, rect, hsv_n, &x, &y);
CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f);
CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f);
@@ -3202,6 +3208,7 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
/* vertical 'value' slider, using new widget code */
static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
{
+ const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
bTheme *btheme = UI_GetTheme();
uiWidgetColors *wcol = &btheme->tui.wcol_numslider;
uiWidgetBase wtb;
@@ -3212,7 +3219,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
ui_but_v3_get(but, rgb);
ui_scene_linear_to_color_picker_space(but, rgb);
- if (but->a1 == UI_GRAD_L_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_L_ALT) {
rgb_to_hsl_v(rgb, hsv);
}
else {
@@ -3221,7 +3228,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
v = hsv[2];
/* map v from property range to [0,1] */
- if (but->a1 == UI_GRAD_V_ALT) {
+ if (hsv_but->gradient_type == UI_GRAD_V_ALT) {
float min = but->softmin, max = but->softmax;
v = (v - min) / (max - min);
}
@@ -4670,8 +4677,10 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
break;
- case UI_BTYPE_HSVCUBE:
- if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) {
+ case UI_BTYPE_HSVCUBE: {
+ const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
+
+ if (ELEM(hsv_but->gradient_type, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) {
/* vertical V slider, uses new widget draw now */
ui_draw_but_HSV_v(but, rect);
}
@@ -4679,6 +4688,7 @@ void ui_draw_but(const bContext *C, struct ARegion *region, uiStyle *style, uiBu
ui_draw_but_HSVCUBE(but, rect);
}
break;
+ }
case UI_BTYPE_HSVCIRCLE:
ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);