UI Code Quality: Use derived struct for HSV Cube buttons
For the main rationale behind this design, see 49f088e2d0
. Further,
this removes users of uiBut.a1, which is a very ugly design
choice (hard to reason about).
Part of T74432.
This commit is contained in:
@@ -378,7 +378,7 @@ typedef enum {
|
|||||||
#define BUTTYPE (63 << 9)
|
#define BUTTYPE (63 << 9)
|
||||||
|
|
||||||
/** Gradient types, for color picker #UI_BTYPE_HSVCUBE etc. */
|
/** Gradient types, for color picker #UI_BTYPE_HSVCUBE etc. */
|
||||||
enum {
|
typedef enum eButGradientType {
|
||||||
UI_GRAD_SV = 0,
|
UI_GRAD_SV = 0,
|
||||||
UI_GRAD_HV = 1,
|
UI_GRAD_HV = 1,
|
||||||
UI_GRAD_HS = 2,
|
UI_GRAD_HS = 2,
|
||||||
@@ -388,7 +388,7 @@ enum {
|
|||||||
|
|
||||||
UI_GRAD_V_ALT = 9,
|
UI_GRAD_V_ALT = 9,
|
||||||
UI_GRAD_L_ALT = 10,
|
UI_GRAD_L_ALT = 10,
|
||||||
};
|
} eButGradientType;
|
||||||
|
|
||||||
/* Drawing
|
/* Drawing
|
||||||
*
|
*
|
||||||
|
@@ -3793,6 +3793,10 @@ static void ui_but_alloc_info(const eButType type,
|
|||||||
alloc_size = sizeof(uiButProgressbar);
|
alloc_size = sizeof(uiButProgressbar);
|
||||||
alloc_str = "uiButProgressbar";
|
alloc_str = "uiButProgressbar";
|
||||||
break;
|
break;
|
||||||
|
case UI_BTYPE_HSVCUBE:
|
||||||
|
alloc_size = sizeof(uiButHSVCube);
|
||||||
|
alloc_str = "uiButHSVCube";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
alloc_size = sizeof(uiBut);
|
alloc_size = sizeof(uiBut);
|
||||||
alloc_str = "uiBut";
|
alloc_str = "uiBut";
|
||||||
|
@@ -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);
|
rgb_to_hsl_compat_v(rgb, hsv);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
rgb_to_hsl_v(rgb, hsv);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
hsl_to_rgb_v(hsv, rgb);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -5978,6 +5984,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
|
|||||||
const enum eSnapType snap,
|
const enum eSnapType snap,
|
||||||
const bool shift)
|
const bool shift)
|
||||||
{
|
{
|
||||||
|
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
|
||||||
ColorPicker *cpicker = but->custom_data;
|
ColorPicker *cpicker = but->custom_data;
|
||||||
float *hsv = cpicker->color_data;
|
float *hsv = cpicker->color_data;
|
||||||
float rgb[3];
|
float rgb[3];
|
||||||
@@ -5999,7 +6006,7 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
|
|||||||
ui_but_v3_get(but, rgb);
|
ui_but_v3_get(but, rgb);
|
||||||
ui_scene_linear_to_color_picker_space(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 */
|
/* only apply the delta motion, not absolute */
|
||||||
if (shift) {
|
if (shift) {
|
||||||
@@ -6014,10 +6021,10 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
|
|||||||
|
|
||||||
copy_v3_v3(hsvo, hsv);
|
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 */
|
/* 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);
|
mx_fl = xpos - (data->dragstartx - mx_fl);
|
||||||
my_fl = ypos - (data->dragstarty - my_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(x, 0.0f, 1.0f);
|
||||||
CLAMP(y, 0.0f, 1.0f);
|
CLAMP(y, 0.0f, 1.0f);
|
||||||
|
|
||||||
switch ((int)but->a1) {
|
switch (hsv_but->gradient_type) {
|
||||||
case UI_GRAD_SV:
|
case UI_GRAD_SV:
|
||||||
hsv[1] = x;
|
hsv[1] = x;
|
||||||
hsv[2] = y;
|
hsv[2] = y;
|
||||||
@@ -6067,16 +6074,16 @@ static bool ui_numedit_but_HSVCUBE(uiBut *but,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (snap != SNAP_OFF) {
|
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_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);
|
ui_color_picker_to_scene_linear_space(but, rgb);
|
||||||
|
|
||||||
/* clamp because with color conversion we can exceed range [#34295] */
|
/* 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);
|
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(
|
static int ui_do_but_HSVCUBE(
|
||||||
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
|
bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
|
||||||
{
|
{
|
||||||
|
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
|
||||||
int mx, my;
|
int mx, my;
|
||||||
|
|
||||||
mx = event->x;
|
mx = event->x;
|
||||||
@@ -6199,7 +6207,7 @@ static int ui_do_but_HSVCUBE(
|
|||||||
#endif /* WITH_INPUT_NDOF */
|
#endif /* WITH_INPUT_NDOF */
|
||||||
/* XXX hardcoded keymap check.... */
|
/* XXX hardcoded keymap check.... */
|
||||||
if (event->type == EVT_BACKSPACEKEY && event->val == KM_PRESS) {
|
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;
|
int len;
|
||||||
|
|
||||||
/* reset only value */
|
/* reset only value */
|
||||||
@@ -6212,15 +6220,15 @@ static int ui_do_but_HSVCUBE(
|
|||||||
float *hsv = cpicker->color_data;
|
float *hsv = cpicker->color_data;
|
||||||
|
|
||||||
RNA_property_float_get_default_array(&but->rnapoin, but->rnaprop, def);
|
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_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[0] = hsv[0];
|
||||||
def_hsv[1] = hsv[1];
|
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);
|
ui_but_v3_set(but, rgb);
|
||||||
|
|
||||||
RNA_property_update(C, &but->rnapoin, but->rnaprop);
|
RNA_property_update(C, &but->rnapoin, but->rnaprop);
|
||||||
|
@@ -172,7 +172,6 @@ struct uiBut {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* For #uiBut.type:
|
* 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_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_LABEL: Use `(a1 == 1.0f)` to use a2 as a blending factor (imaginative!).
|
||||||
* - UI_BTYPE_SCROLL: Use as scroll size.
|
* - UI_BTYPE_SCROLL: Use as scroll size.
|
||||||
@@ -328,6 +327,12 @@ typedef struct uiButProgressbar {
|
|||||||
float progress;
|
float progress;
|
||||||
} uiButProgressbar;
|
} uiButProgressbar;
|
||||||
|
|
||||||
|
typedef struct uiButHSVCube {
|
||||||
|
uiBut but;
|
||||||
|
|
||||||
|
eButGradientType gradient_type;
|
||||||
|
} uiButHSVCube;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Additional, superimposed icon for a button, invoking an operator.
|
* 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(
|
extern void ui_hsvcircle_pos_from_vals(
|
||||||
const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *xpos, float *ypos);
|
const ColorPicker *cpicker, const rcti *rect, const float *hsv, float *xpos, float *ypos);
|
||||||
extern void ui_hsvcube_pos_from_vals(
|
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,
|
extern void ui_but_string_get_ex(uiBut *but,
|
||||||
char *str,
|
char *str,
|
||||||
@@ -777,7 +782,10 @@ extern void ui_draw_aligned_panel(struct uiStyle *style,
|
|||||||
extern void ui_draw_dropshadow(
|
extern void ui_draw_dropshadow(
|
||||||
const rctf *rct, float radius, float aspect, float alpha, int select);
|
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,
|
void ui_draw_but_TAB_outline(const rcti *rect,
|
||||||
float rad,
|
float rad,
|
||||||
|
@@ -369,6 +369,7 @@ static void ui_colorpicker_circle(uiBlock *block,
|
|||||||
ColorPicker *cpicker)
|
ColorPicker *cpicker)
|
||||||
{
|
{
|
||||||
uiBut *bt;
|
uiBut *bt;
|
||||||
|
uiButHSVCube *hsv_but;
|
||||||
|
|
||||||
/* HS circle */
|
/* HS circle */
|
||||||
bt = uiDefButR_prop(block,
|
bt = uiDefButR_prop(block,
|
||||||
@@ -392,91 +393,99 @@ static void ui_colorpicker_circle(uiBlock *block,
|
|||||||
|
|
||||||
/* value */
|
/* value */
|
||||||
if (U.color_picker_type == USER_CP_CIRCLE_HSL) {
|
if (U.color_picker_type == USER_CP_CIRCLE_HSL) {
|
||||||
bt = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
PICKER_W + PICKER_SPACE,
|
PICKER_W + PICKER_SPACE,
|
||||||
0,
|
0,
|
||||||
PICKER_BAR,
|
PICKER_BAR,
|
||||||
PICKER_H,
|
PICKER_H,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
UI_GRAD_L_ALT,
|
0,
|
||||||
0,
|
0,
|
||||||
"Lightness");
|
"Lightness");
|
||||||
UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
|
hsv_but->gradient_type = UI_GRAD_L_ALT;
|
||||||
|
UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bt = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
PICKER_W + PICKER_SPACE,
|
PICKER_W + PICKER_SPACE,
|
||||||
0,
|
0,
|
||||||
PICKER_BAR,
|
PICKER_BAR,
|
||||||
PICKER_H,
|
PICKER_H,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
UI_GRAD_V_ALT,
|
0,
|
||||||
0,
|
0,
|
||||||
TIP_("Value"));
|
TIP_("Value"));
|
||||||
UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
|
hsv_but->gradient_type = UI_GRAD_V_ALT;
|
||||||
|
UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
|
||||||
}
|
}
|
||||||
bt->custom_data = cpicker;
|
hsv_but->but.custom_data = cpicker;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ui_colorpicker_square(
|
static void ui_colorpicker_square(uiBlock *block,
|
||||||
uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int type, ColorPicker *cpicker)
|
PointerRNA *ptr,
|
||||||
|
PropertyRNA *prop,
|
||||||
|
eButGradientType type,
|
||||||
|
ColorPicker *cpicker)
|
||||||
{
|
{
|
||||||
uiBut *bt;
|
uiButHSVCube *hsv_but;
|
||||||
int bartype = type + 3;
|
|
||||||
|
BLI_assert(type <= UI_GRAD_HS);
|
||||||
|
|
||||||
/* HS square */
|
/* HS square */
|
||||||
bt = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
PICKER_BAR + PICKER_SPACE,
|
PICKER_BAR + PICKER_SPACE,
|
||||||
PICKER_TOTAL_W,
|
PICKER_TOTAL_W,
|
||||||
PICKER_H,
|
PICKER_H,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
type,
|
0,
|
||||||
0,
|
0,
|
||||||
TIP_("Color"));
|
TIP_("Color"));
|
||||||
UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
|
hsv_but->gradient_type = type;
|
||||||
bt->custom_data = cpicker;
|
UI_but_func_set(&hsv_but->but, ui_colorpicker_rna_cb, &hsv_but->but, NULL);
|
||||||
|
hsv_but->but.custom_data = cpicker;
|
||||||
|
|
||||||
/* value */
|
/* value */
|
||||||
bt = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
PICKER_TOTAL_W,
|
PICKER_TOTAL_W,
|
||||||
PICKER_BAR,
|
PICKER_BAR,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
bartype,
|
0,
|
||||||
0,
|
0,
|
||||||
TIP_("Value"));
|
TIP_("Value"));
|
||||||
UI_but_func_set(bt, ui_colorpicker_rna_cb, bt, NULL);
|
hsv_but->gradient_type = type + 3;
|
||||||
bt->custom_data = cpicker;
|
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 */
|
/* a HS circle, V slider, rgb/hsv/hex sliders */
|
||||||
|
@@ -5188,6 +5188,7 @@ void uiTemplateColorPicker(uiLayout *layout,
|
|||||||
uiBlock *block = uiLayoutGetBlock(layout);
|
uiBlock *block = uiLayoutGetBlock(layout);
|
||||||
uiLayout *col, *row;
|
uiLayout *col, *row;
|
||||||
uiBut *but = NULL;
|
uiBut *but = NULL;
|
||||||
|
uiButHSVCube *hsv_but;
|
||||||
ColorPicker *cpicker = ui_block_colorpicker_create(block);
|
ColorPicker *cpicker = ui_block_colorpicker_create(block);
|
||||||
float softmin, softmax, step, precision;
|
float softmin, softmax, step, precision;
|
||||||
|
|
||||||
@@ -5203,58 +5204,36 @@ void uiTemplateColorPicker(uiLayout *layout,
|
|||||||
|
|
||||||
switch (U.color_picker_type) {
|
switch (U.color_picker_type) {
|
||||||
case USER_CP_SQUARE_SV:
|
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:
|
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:
|
case USER_CP_SQUARE_HV:
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
0.0,
|
0.0,
|
||||||
0.0,
|
0.0,
|
||||||
UI_GRAD_HV,
|
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;
|
break;
|
||||||
|
|
||||||
/* user default */
|
/* user default */
|
||||||
@@ -5297,105 +5276,110 @@ void uiTemplateColorPicker(uiLayout *layout,
|
|||||||
switch (U.color_picker_type) {
|
switch (U.color_picker_type) {
|
||||||
case USER_CP_CIRCLE_HSL:
|
case USER_CP_CIRCLE_HSL:
|
||||||
uiItemS(row);
|
uiItemS(row);
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
WHEEL_SIZE + 6,
|
WHEEL_SIZE + 6,
|
||||||
0,
|
0,
|
||||||
14 * UI_DPI_FAC,
|
14 * UI_DPI_FAC,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
softmin,
|
softmin,
|
||||||
softmax,
|
softmax,
|
||||||
UI_GRAD_L_ALT,
|
0,
|
||||||
0,
|
0,
|
||||||
"");
|
"");
|
||||||
|
hsv_but->gradient_type = UI_GRAD_L_ALT;
|
||||||
break;
|
break;
|
||||||
case USER_CP_SQUARE_SV:
|
case USER_CP_SQUARE_SV:
|
||||||
uiItemS(col);
|
uiItemS(col);
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
4,
|
4,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
18 * UI_DPI_FAC,
|
18 * UI_DPI_FAC,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
softmin,
|
softmin,
|
||||||
softmax,
|
softmax,
|
||||||
UI_GRAD_SV + 3,
|
0,
|
||||||
0,
|
0,
|
||||||
"");
|
"");
|
||||||
|
hsv_but->gradient_type = UI_GRAD_SV + 3;
|
||||||
break;
|
break;
|
||||||
case USER_CP_SQUARE_HS:
|
case USER_CP_SQUARE_HS:
|
||||||
uiItemS(col);
|
uiItemS(col);
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
4,
|
4,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
18 * UI_DPI_FAC,
|
18 * UI_DPI_FAC,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
softmin,
|
softmin,
|
||||||
softmax,
|
softmax,
|
||||||
UI_GRAD_HS + 3,
|
0,
|
||||||
0,
|
0,
|
||||||
"");
|
"");
|
||||||
|
hsv_but->gradient_type = UI_GRAD_HS + 3;
|
||||||
break;
|
break;
|
||||||
case USER_CP_SQUARE_HV:
|
case USER_CP_SQUARE_HV:
|
||||||
uiItemS(col);
|
uiItemS(col);
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
4,
|
4,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
18 * UI_DPI_FAC,
|
18 * UI_DPI_FAC,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
softmin,
|
softmin,
|
||||||
softmax,
|
softmax,
|
||||||
UI_GRAD_HV + 3,
|
0,
|
||||||
0,
|
0,
|
||||||
"");
|
"");
|
||||||
|
hsv_but->gradient_type = UI_GRAD_HV + 3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* user default */
|
/* user default */
|
||||||
case USER_CP_CIRCLE_HSV:
|
case USER_CP_CIRCLE_HSV:
|
||||||
default:
|
default:
|
||||||
uiItemS(row);
|
uiItemS(row);
|
||||||
but = uiDefButR_prop(block,
|
hsv_but = (uiButHSVCube *)uiDefButR_prop(block,
|
||||||
UI_BTYPE_HSVCUBE,
|
UI_BTYPE_HSVCUBE,
|
||||||
0,
|
0,
|
||||||
"",
|
"",
|
||||||
WHEEL_SIZE + 6,
|
WHEEL_SIZE + 6,
|
||||||
0,
|
0,
|
||||||
14 * UI_DPI_FAC,
|
14 * UI_DPI_FAC,
|
||||||
WHEEL_SIZE,
|
WHEEL_SIZE,
|
||||||
ptr,
|
ptr,
|
||||||
prop,
|
prop,
|
||||||
-1,
|
-1,
|
||||||
softmin,
|
softmin,
|
||||||
softmax,
|
softmax,
|
||||||
UI_GRAD_V_ALT,
|
0,
|
||||||
0,
|
0,
|
||||||
"");
|
"");
|
||||||
|
hsv_but->gradient_type = UI_GRAD_V_ALT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
but->custom_data = cpicker;
|
hsv_but->but.custom_data = cpicker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2971,7 +2971,10 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const
|
|||||||
* \{ */
|
* \{ */
|
||||||
|
|
||||||
/* draws in resolution of 48x4 colors */
|
/* 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) */
|
/* allows for 4 steps (red->yellow) */
|
||||||
const int steps = 48;
|
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[1], col1[2]);
|
||||||
copy_v3_v3(col1[3], col1[2]);
|
copy_v3_v3(col1[3], col1[2]);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rect */
|
/* 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(
|
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;
|
float x = 0.0f, y = 0.0f;
|
||||||
|
|
||||||
switch ((int)but->a1) {
|
switch (hsv_but->gradient_type) {
|
||||||
case UI_GRAD_SV:
|
case UI_GRAD_SV:
|
||||||
x = hsv[1];
|
x = hsv[1];
|
||||||
y = hsv[2];
|
y = hsv[2];
|
||||||
@@ -3159,7 +3164,7 @@ void ui_hsvcube_pos_from_vals(
|
|||||||
case UI_GRAD_V_ALT:
|
case UI_GRAD_V_ALT:
|
||||||
x = 0.5f;
|
x = 0.5f;
|
||||||
/* exception only for value strip - use the range set in but->min/max */
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3170,6 +3175,7 @@ void ui_hsvcube_pos_from_vals(
|
|||||||
|
|
||||||
static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
|
static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
|
||||||
{
|
{
|
||||||
|
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
|
||||||
float rgb[3];
|
float rgb[3];
|
||||||
float x = 0.0f, y = 0.0f;
|
float x = 0.0f, y = 0.0f;
|
||||||
ColorPicker *cpicker = but->custom_data;
|
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);
|
ui_scene_linear_to_color_picker_space(but, rgb);
|
||||||
rgb_to_hsv_compat_v(rgb, hsv_n);
|
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(x, rect->xmin + 3.0f, rect->xmax - 3.0f);
|
||||||
CLAMP(y, rect->ymin + 3.0f, rect->ymax - 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 */
|
/* vertical 'value' slider, using new widget code */
|
||||||
static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
|
static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
|
||||||
{
|
{
|
||||||
|
const uiButHSVCube *hsv_but = (uiButHSVCube *)but;
|
||||||
bTheme *btheme = UI_GetTheme();
|
bTheme *btheme = UI_GetTheme();
|
||||||
uiWidgetColors *wcol = &btheme->tui.wcol_numslider;
|
uiWidgetColors *wcol = &btheme->tui.wcol_numslider;
|
||||||
uiWidgetBase wtb;
|
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_but_v3_get(but, rgb);
|
||||||
ui_scene_linear_to_color_picker_space(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);
|
rgb_to_hsl_v(rgb, hsv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -3221,7 +3228,7 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
|
|||||||
v = hsv[2];
|
v = hsv[2];
|
||||||
|
|
||||||
/* map v from property range to [0,1] */
|
/* 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;
|
float min = but->softmin, max = but->softmax;
|
||||||
v = (v - min) / (max - min);
|
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);
|
widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UI_BTYPE_HSVCUBE:
|
case UI_BTYPE_HSVCUBE: {
|
||||||
if (ELEM(but->a1, UI_GRAD_V_ALT, UI_GRAD_L_ALT)) {
|
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 */
|
/* vertical V slider, uses new widget draw now */
|
||||||
ui_draw_but_HSV_v(but, rect);
|
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);
|
ui_draw_but_HSVCUBE(but, rect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case UI_BTYPE_HSVCIRCLE:
|
case UI_BTYPE_HSVCIRCLE:
|
||||||
ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
|
ui_draw_but_HSVCIRCLE(but, &tui->wcol_regular, rect);
|
||||||
|
Reference in New Issue
Block a user