Refactor: UI: Use derived struct for number slider buttons
Similar to d204830107. This is the last real use of
the a1 and a2 arguments for many button definition functions.
This commit is contained in:
@@ -644,7 +644,8 @@ static uiBut *add_tab_button(uiBlock &block, StringRefNull name)
|
||||
const int pad_x = UI_UNIT_X * 0.3f;
|
||||
const int but_width = std::min(string_width + 2 * pad_x, UI_UNIT_X * 8);
|
||||
|
||||
uiBut *but = uiDefBut(&block,
|
||||
uiBut *but = uiDefBut(
|
||||
&block,
|
||||
UI_BTYPE_TAB,
|
||||
0,
|
||||
name.c_str(),
|
||||
|
||||
@@ -1734,6 +1734,9 @@ void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_colo
|
||||
void UI_but_number_step_size_set(uiBut *but, float step_size);
|
||||
void UI_but_number_precision_set(uiBut *but, float precision);
|
||||
|
||||
void UI_but_number_slider_step_size_set(uiBut *but, float step_size);
|
||||
void UI_but_number_slider_precision_set(uiBut *but, float precision);
|
||||
|
||||
void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg);
|
||||
void UI_block_func_butmenu_set(uiBlock *block, uiMenuHandleFunc func, void *arg);
|
||||
void UI_block_func_set(uiBlock *block, uiButHandleFunc func, void *arg1, void *arg2);
|
||||
|
||||
@@ -641,6 +641,9 @@ static float ui_but_get_float_precision(uiBut *but)
|
||||
if (but->type == UI_BTYPE_NUM) {
|
||||
return ((uiButNumber *)but)->precision;
|
||||
}
|
||||
if (but->type == UI_BTYPE_NUM_SLIDER) {
|
||||
return ((uiButNumberSlider *)but)->precision;
|
||||
}
|
||||
|
||||
return but->a2;
|
||||
}
|
||||
@@ -650,6 +653,9 @@ static float ui_but_get_float_step_size(uiBut *but)
|
||||
if (but->type == UI_BTYPE_NUM) {
|
||||
return ((uiButNumber *)but)->step_size;
|
||||
}
|
||||
if (but->type == UI_BTYPE_NUM_SLIDER) {
|
||||
return ((uiButNumberSlider *)but)->step_size;
|
||||
}
|
||||
|
||||
return but->a1;
|
||||
}
|
||||
@@ -3964,6 +3970,9 @@ static uiBut *ui_but_new(const eButType type)
|
||||
case UI_BTYPE_NUM:
|
||||
but = MEM_new<uiButNumber>("uiButNumber");
|
||||
break;
|
||||
case UI_BTYPE_NUM_SLIDER:
|
||||
but = MEM_new<uiButNumberSlider>("uiButNumber");
|
||||
break;
|
||||
case UI_BTYPE_COLOR:
|
||||
but = MEM_new<uiButColor>("uiButColor");
|
||||
break;
|
||||
@@ -4544,7 +4553,7 @@ static uiBut *ui_def_but_rna(uiBlock *block,
|
||||
const PropertyType proptype = RNA_property_type(prop);
|
||||
int icon = 0;
|
||||
uiMenuCreateFunc func = nullptr;
|
||||
const bool always_set_a1_a2 = ELEM(type, UI_BTYPE_NUM);
|
||||
const bool always_set_a1_a2 = ELEM(type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER);
|
||||
|
||||
if (ELEM(type, UI_BTYPE_COLOR, UI_BTYPE_HSVCIRCLE, UI_BTYPE_HSVCUBE)) {
|
||||
BLI_assert(index == -1);
|
||||
@@ -4659,6 +4668,11 @@ static uiBut *ui_def_but_rna(uiBlock *block,
|
||||
UI_but_number_step_size_set(but, a1);
|
||||
UI_but_number_precision_set(but, a2);
|
||||
}
|
||||
else if (but->type == UI_BTYPE_NUM_SLIDER) {
|
||||
/* Set default values, can be overridden later. */
|
||||
UI_but_number_slider_step_size_set(but, a1);
|
||||
UI_but_number_slider_precision_set(but, a2);
|
||||
}
|
||||
|
||||
but->rnapoin = *ptr;
|
||||
but->rnaprop = prop;
|
||||
@@ -4710,6 +4724,10 @@ static uiBut *ui_def_but_rna(uiBlock *block,
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
number_but->step_size = ui_get_but_step_unit(but, number_but->step_size);
|
||||
}
|
||||
if (type == UI_BTYPE_NUM_SLIDER) {
|
||||
uiButNumberSlider *number_but = (uiButNumberSlider *)but;
|
||||
number_but->step_size = ui_get_but_step_unit(but, number_but->step_size);
|
||||
}
|
||||
else {
|
||||
but->a1 = ui_get_but_step_unit(but, but->a1);
|
||||
}
|
||||
@@ -6480,6 +6498,25 @@ void UI_but_number_precision_set(uiBut *but, float precision)
|
||||
BLI_assert(precision > -2);
|
||||
}
|
||||
|
||||
void UI_but_number_slider_step_size_set(uiBut *but, float step_size)
|
||||
{
|
||||
uiButNumberSlider *but_number = (uiButNumberSlider *)but;
|
||||
BLI_assert(but->type == UI_BTYPE_NUM_SLIDER);
|
||||
|
||||
but_number->step_size = step_size;
|
||||
BLI_assert(step_size > 0);
|
||||
}
|
||||
|
||||
void UI_but_number_slider_precision_set(uiBut *but, float precision)
|
||||
{
|
||||
uiButNumberSlider *but_number = (uiButNumberSlider *)but;
|
||||
BLI_assert(but->type == UI_BTYPE_NUM_SLIDER);
|
||||
|
||||
but_number->precision = precision;
|
||||
/* -1 is a valid value, UI code figures out an appropriate precision then. */
|
||||
BLI_assert(precision > -2);
|
||||
}
|
||||
|
||||
void UI_but_focus_on_enter_event(wmWindow *win, uiBut *but)
|
||||
{
|
||||
wmEvent event;
|
||||
|
||||
@@ -5624,6 +5624,7 @@ static bool ui_numedit_but_SLI(uiBut *but,
|
||||
const bool snap,
|
||||
const bool shift)
|
||||
{
|
||||
uiButNumberSlider *slider_but = reinterpret_cast<uiButNumberSlider *>(but);
|
||||
float cursor_x_range, f, tempf, softmin, softmax, softrange;
|
||||
int temp, lvalue;
|
||||
bool changed = false;
|
||||
@@ -5655,7 +5656,7 @@ static bool ui_numedit_but_SLI(uiBut *but,
|
||||
const float size = (is_horizontal) ? BLI_rctf_size_x(&but->rect) :
|
||||
-BLI_rctf_size_y(&but->rect);
|
||||
cursor_x_range = size * (but->softmax - but->softmin) /
|
||||
(but->softmax - but->softmin + but->a1);
|
||||
(but->softmax - but->softmin + slider_but->step_size);
|
||||
}
|
||||
else {
|
||||
const float ofs = (BLI_rctf_size_y(&but->rect) / 2.0f);
|
||||
|
||||
@@ -321,8 +321,14 @@ struct uiBut {
|
||||
|
||||
/** Derived struct for #UI_BTYPE_NUM */
|
||||
struct uiButNumber : public uiBut {
|
||||
float step_size = 0;
|
||||
float precision = 0;
|
||||
float step_size = 0.0f;
|
||||
float precision = 0.0f;
|
||||
};
|
||||
|
||||
/** Derived struct for #UI_BTYPE_NUM_SLIDER */
|
||||
struct uiButNumberSlider : public uiBut {
|
||||
float step_size = 0.0f;
|
||||
float precision = 0.0f;
|
||||
};
|
||||
|
||||
/** Derived struct for #UI_BTYPE_COLOR */
|
||||
|
||||
@@ -649,9 +649,10 @@ static void ui_item_array(uiLayout *layout,
|
||||
UI_UNIT_Y);
|
||||
if (slider && but->type == UI_BTYPE_NUM) {
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
|
||||
but->a1 = number_but->step_size;
|
||||
const float step_size = number_but->step_size;
|
||||
but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
|
||||
uiButNumberSlider *slider_but = reinterpret_cast<uiButNumberSlider *>(but);
|
||||
slider_but->step_size = step_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,9 +720,10 @@ static void ui_item_array(uiLayout *layout,
|
||||
block, ptr, prop, a, str_buf, icon, 0, 0, width_item, UI_UNIT_Y);
|
||||
if (slider && but->type == UI_BTYPE_NUM) {
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
|
||||
but->a1 = number_but->step_size;
|
||||
const float step_size = number_but->step_size;
|
||||
but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
|
||||
uiButNumberSlider *slider_but = reinterpret_cast<uiButNumberSlider *>(but);
|
||||
slider_but->step_size = step_size;
|
||||
}
|
||||
if ((toggle == 1) && but->type == UI_BTYPE_CHECKBOX) {
|
||||
but->type = UI_BTYPE_TOGGLE;
|
||||
@@ -2448,10 +2450,11 @@ void uiItemFullR(uiLayout *layout,
|
||||
but = uiDefAutoButR(block, ptr, prop, index, name, icon, 0, 0, w, h);
|
||||
|
||||
if (slider && but->type == UI_BTYPE_NUM) {
|
||||
uiButNumber *num_but = (uiButNumber *)but;
|
||||
|
||||
but->a1 = num_but->step_size;
|
||||
uiButNumber *number_but = (uiButNumber *)but;
|
||||
const float step_size = number_but->step_size;
|
||||
but = ui_but_change_type(but, UI_BTYPE_NUM_SLIDER);
|
||||
uiButNumberSlider *slider_but = reinterpret_cast<uiButNumberSlider *>(but);
|
||||
slider_but->step_size = step_size;
|
||||
}
|
||||
|
||||
if (flag & UI_ITEM_R_CHECKBOX_INVERT) {
|
||||
|
||||
@@ -623,9 +623,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
0,
|
||||
0.0,
|
||||
0.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Red"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
bt = uiDefButR_prop(block,
|
||||
@@ -641,9 +643,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
1,
|
||||
0.0,
|
||||
0.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Green"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
bt = uiDefButR_prop(block,
|
||||
@@ -659,9 +663,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
2,
|
||||
0.0,
|
||||
0.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Blue"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
|
||||
@@ -683,9 +689,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
cpicker->hsv_scene_linear,
|
||||
0.0,
|
||||
1.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Hue"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_flag_disable(bt, UI_BUT_UNDO);
|
||||
UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
@@ -700,9 +708,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
cpicker->hsv_scene_linear + 1,
|
||||
0.0,
|
||||
1.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Saturation"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_flag_disable(bt, UI_BUT_UNDO);
|
||||
UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
@@ -718,9 +728,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
cpicker->hsv_scene_linear + 2,
|
||||
0.0,
|
||||
1.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Lightness"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
}
|
||||
else {
|
||||
bt = uiDefButF(block,
|
||||
@@ -734,10 +746,12 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
cpicker->hsv_scene_linear + 2,
|
||||
0.0,
|
||||
softmax,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
CTX_TIP_(BLT_I18NCONTEXT_COLOR, "Value"));
|
||||
}
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_flag_disable(bt, UI_BUT_UNDO);
|
||||
|
||||
bt->hardmax = hardmax; /* Not common but RGB may be over 1.0. */
|
||||
@@ -760,9 +774,11 @@ static void ui_block_colorpicker(uiBlock *block,
|
||||
3,
|
||||
0.0,
|
||||
0.0,
|
||||
10,
|
||||
3,
|
||||
0,
|
||||
0,
|
||||
TIP_("Alpha"));
|
||||
UI_but_number_slider_step_size_set(bt, 10);
|
||||
UI_but_number_slider_precision_set(bt, 3);
|
||||
UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr);
|
||||
bt->custom_data = cpicker;
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ uiBut *uiDefAutoButR(uiBlock *block,
|
||||
index,
|
||||
0,
|
||||
0,
|
||||
-1,
|
||||
-1,
|
||||
0,
|
||||
0,
|
||||
nullptr);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user