Anim: Add option to show modified property on slider #119920
|
@ -104,6 +104,9 @@ void ED_slider_allow_increments_set(tSlider *slider, bool value);
|
||||||
void ED_slider_mode_set(tSlider *slider, SliderMode mode);
|
void ED_slider_mode_set(tSlider *slider, SliderMode mode);
|
||||||
SliderMode ED_slider_mode_get(const tSlider *slider);
|
SliderMode ED_slider_mode_get(const tSlider *slider);
|
||||||
void ED_slider_unit_set(tSlider *slider, const char *unit);
|
void ED_slider_unit_set(tSlider *slider, const char *unit);
|
||||||
|
/* Set a name that will show next to the slider to indicate which property is modified currently.
|
||||||
|
* To clear, set to an empty string. */
|
||||||
|
void ED_slider_property_label_set(tSlider *slider, const char *prop_name);
|
||||||
|
|
||||||
/* ************** XXX OLD CRUFT WARNING ************* */
|
/* ************** XXX OLD CRUFT WARNING ************* */
|
||||||
|
|
||||||
|
|
|
@ -1030,6 +1030,7 @@ static int ease_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||||
ED_slider_unit_set(gso->slider, "%");
|
ED_slider_unit_set(gso->slider, "%");
|
||||||
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
|
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
|
||||||
}
|
}
|
||||||
|
ED_slider_property_label_set(gso->slider, RNA_property_ui_name(gso->factor_prop));
|
||||||
ease_modal_update(C, op);
|
ease_modal_update(C, op);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1055,6 +1056,7 @@ static int ease_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||||
ED_slider_allow_overshoot_set(gso->slider, false, false);
|
ED_slider_allow_overshoot_set(gso->slider, false, false);
|
||||||
ED_slider_factor_bounds_set(gso->slider, -1, 1);
|
ED_slider_factor_bounds_set(gso->slider, -1, 1);
|
||||||
ED_slider_factor_set(gso->slider, 0.0f);
|
ED_slider_factor_set(gso->slider, 0.0f);
|
||||||
|
ED_slider_property_label_set(gso->slider, RNA_property_ui_name(gso->factor_prop));
|
||||||
|
|
||||||
return invoke_result;
|
return invoke_result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,10 @@ struct tSlider {
|
||||||
/* How the factor number is drawn. When drawing percent it is factor*100. */
|
/* How the factor number is drawn. When drawing percent it is factor*100. */
|
||||||
SliderMode slider_mode;
|
SliderMode slider_mode;
|
||||||
|
|
||||||
|
/* Optional string that will display next to the slider to indicate which property is modified
|
||||||
|
* right now. */
|
||||||
|
std::string property_label;
|
||||||
|
|
||||||
|
|||||||
/* What unit to add to the slider. */
|
/* What unit to add to the slider. */
|
||||||
char unit_string[SLIDER_UNIT_STRING_SIZE];
|
char unit_string[SLIDER_UNIT_STRING_SIZE];
|
||||||
|
|
||||||
|
@ -224,19 +228,28 @@ static void draw_backdrop(const int fontid,
|
||||||
const rctf *main_line_rect,
|
const rctf *main_line_rect,
|
||||||
const uint8_t color_bg[4],
|
const uint8_t color_bg[4],
|
||||||
const short region_y_size,
|
const short region_y_size,
|
||||||
const float base_tick_height)
|
const float base_tick_height,
|
||||||
|
const std::string &property_label)
|
||||||
{
|
{
|
||||||
float string_pixel_size[2];
|
float percent_string_pixel_size[2];
|
||||||
const char *percentage_string_placeholder = "000%%";
|
const char *percentage_string_placeholder = "000%%";
|
||||||
BLF_width_and_height(fontid,
|
BLF_width_and_height(fontid,
|
||||||
percentage_string_placeholder,
|
percentage_string_placeholder,
|
||||||
sizeof(percentage_string_placeholder),
|
sizeof(percentage_string_placeholder),
|
||||||
&string_pixel_size[0],
|
&percent_string_pixel_size[0],
|
||||||
&string_pixel_size[1]);
|
&percent_string_pixel_size[1]);
|
||||||
const float pad[2] = {(region_y_size - base_tick_height) / 2, 2.0f * U.pixelsize};
|
|
||||||
|
float property_name_pixel_size[2];
|
||||||
|
BLF_width_and_height(fontid,
|
||||||
|
property_label.c_str(),
|
||||||
|
property_label.size(),
|
||||||
|
&property_name_pixel_size[0],
|
||||||
|
&property_name_pixel_size[1]);
|
||||||
|
const float pad[2] = {(region_y_size - base_tick_height) / 2 + 12.0f * U.pixelsize,
|
||||||
|
2.0f * U.pixelsize};
|
||||||
rctf backdrop_rect{};
|
rctf backdrop_rect{};
|
||||||
backdrop_rect.xmin = main_line_rect->xmin - string_pixel_size[0] - pad[0];
|
backdrop_rect.xmin = main_line_rect->xmin - property_name_pixel_size[0] - pad[0];
|
||||||
backdrop_rect.xmax = main_line_rect->xmax + pad[0];
|
backdrop_rect.xmax = main_line_rect->xmax + percent_string_pixel_size[0] + pad[0];
|
||||||
backdrop_rect.ymin = pad[1];
|
backdrop_rect.ymin = pad[1];
|
||||||
backdrop_rect.ymax = region_y_size - pad[1];
|
backdrop_rect.ymax = region_y_size - pad[1];
|
||||||
UI_draw_roundbox_3ub_alpha(&backdrop_rect, true, 4.0f, color_bg, color_bg[3]);
|
UI_draw_roundbox_3ub_alpha(&backdrop_rect, true, 4.0f, color_bg, color_bg[3]);
|
||||||
|
@ -304,7 +317,12 @@ static void slider_draw(const bContext * /*C*/, ARegion *region, void *arg)
|
||||||
handle_pos_x = main_line_rect.xmin + SLIDE_PIXEL_DISTANCE * range_factor;
|
handle_pos_x = main_line_rect.xmin + SLIDE_PIXEL_DISTANCE * range_factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_backdrop(fontid, &main_line_rect, color_bg, slider->region_header->winy, base_tick_height);
|
draw_backdrop(fontid,
|
||||||
|
&main_line_rect,
|
||||||
|
color_bg,
|
||||||
|
slider->region_header->winy,
|
||||||
|
base_tick_height,
|
||||||
|
slider->property_label);
|
||||||
|
|
||||||
draw_main_line(&main_line_rect, slider->factor, slider->overshoot, color_overshoot, color_line);
|
draw_main_line(&main_line_rect, slider->factor, slider->overshoot, color_overshoot, color_line);
|
||||||
|
|
||||||
|
@ -356,11 +374,25 @@ static void slider_draw(const bContext * /*C*/, ARegion *region, void *arg)
|
||||||
&factor_string_pixel_size[0],
|
&factor_string_pixel_size[0],
|
||||||
&factor_string_pixel_size[1]);
|
&factor_string_pixel_size[1]);
|
||||||
|
|
||||||
BLF_position(fontid,
|
const float text_padding = 12.0 * U.pixelsize;
|
||||||
main_line_rect.xmin - 12.0 * U.pixelsize - factor_string_pixel_size[0],
|
const float factor_string_pos_x = main_line_rect.xmax + text_padding;
|
||||||
(region->winy / 2) - factor_string_pixel_size[1] / 2,
|
BLF_position(
|
||||||
0.0f);
|
fontid, factor_string_pos_x, (region->winy / 2) - factor_string_pixel_size[1] / 2, 0.0f);
|
||||||
BLF_draw(fontid, factor_string, sizeof(factor_string));
|
BLF_draw(fontid, factor_string, sizeof(factor_string));
|
||||||
|
|
||||||
|
if (!slider->property_label.empty()) {
|
||||||
|
float property_name_pixel_size[2];
|
||||||
|
BLF_width_and_height(fontid,
|
||||||
dr.sybren marked this conversation as resolved
Sybren A. Stüvel
commented
I think you want `warning: address of array 'slider->property_name' will always evaluate to 'true'`
I think you want `if (slider->property_name[0])`
|
|||||||
|
slider->property_label.c_str(),
|
||||||
|
slider->property_label.length(),
|
||||||
Sybren A. Stüvel
commented
`sizeof` is incorrect here, I think you need `slider->property_label.length()`
|
|||||||
|
&property_name_pixel_size[0],
|
||||||
|
&property_name_pixel_size[1]);
|
||||||
|
BLF_position(fontid,
|
||||||
|
main_line_rect.xmin - text_padding - property_name_pixel_size[0],
|
||||||
|
(region->winy / 2) - property_name_pixel_size[1] / 2,
|
||||||
|
0.0f);
|
||||||
|
BLF_draw(fontid, slider->property_label.c_str(), slider->property_label.length());
|
||||||
Sybren A. Stüvel
commented
same same `sizeof` here
|
|||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void slider_update_factor(tSlider *slider, const wmEvent *event)
|
static void slider_update_factor(tSlider *slider, const wmEvent *event)
|
||||||
|
@ -584,6 +616,11 @@ void ED_slider_unit_set(tSlider *slider, const char *unit)
|
||||||
STRNCPY(slider->unit_string, unit);
|
STRNCPY(slider->unit_string, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ED_slider_property_label_set(tSlider *slider, const char *property_label)
|
||||||
|
{
|
||||||
|
slider->property_label.assign(property_label);
|
||||||
|
}
|
||||||
|
|
||||||
/** \} */
|
/** \} */
|
||||||
|
|
||||||
void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *region, void *arg_info)
|
void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *region, void *arg_info)
|
||||||
|
|
Loading…
Reference in New Issue
Given that this is runtime data that's owned by
tSlider
anyway, do we need a fixed-sizechar[]
? Or could we just usestd::string
instead? That could get rid of the fixed array size. Passing references around could then be via aStringRef
instead ofconst char *
.