diff options
Diffstat (limited to 'source/blender/editors/interface')
41 files changed, 935 insertions, 683 deletions
diff --git a/source/blender/editors/interface/eyedroppers/eyedropper_depth.c b/source/blender/editors/interface/eyedroppers/eyedropper_depth.c index 3fb5a74944b..c6d950112b9 100644 --- a/source/blender/editors/interface/eyedroppers/eyedropper_depth.c +++ b/source/blender/editors/interface/eyedroppers/eyedropper_depth.c @@ -162,7 +162,7 @@ static void depthdropper_depth_sample_pt(bContext *C, View3D *v3d = area->spacedata.first; RegionView3D *rv3d = region->regiondata; /* weak, we could pass in some reference point */ - const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; + const float *view_co = v3d->camera ? v3d->camera->object_to_world[3] : rv3d->viewinv[3]; const int mval[2] = {m_xy[0] - region->winrct.xmin, m_xy[1] - region->winrct.ymin}; copy_v2_v2_int(ddr->name_pos, mval); diff --git a/source/blender/editors/interface/eyedroppers/interface_eyedropper.c b/source/blender/editors/interface/eyedroppers/interface_eyedropper.c index c6fb8f0ab68..e49955512a1 100644 --- a/source/blender/editors/interface/eyedroppers/interface_eyedropper.c +++ b/source/blender/editors/interface/eyedroppers/interface_eyedropper.c @@ -41,7 +41,7 @@ wmKeyMap *eyedropper_modal_keymap(wmKeyConfig *keyconf) wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map"); - /* this function is called for each spacetype, only needs to add map once */ + /* This function is called for each space-type, only needs to add map once. */ if (keymap && keymap->modal_items) { return NULL; } diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc index ca4918b2e8d..331d1581db5 100644 --- a/source/blender/editors/interface/interface.cc +++ b/source/blender/editors/interface/interface.cc @@ -82,9 +82,9 @@ static void ui_but_to_pixelrect(struct rcti *rect, const struct ARegion *region, struct uiBlock *block, const struct uiBut *but); -static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p); -static void ui_def_but_rna__panel_type(bContext *UNUSED(C), uiLayout *layout, void *but_p); -static void ui_def_but_rna__menu_type(bContext *UNUSED(C), uiLayout *layout, void *but_p); +static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p); +static void ui_def_but_rna__panel_type(bContext * /*C*/, uiLayout *layout, void *but_p); +static void ui_def_but_rna__menu_type(bContext * /*C*/, uiLayout *layout, void *but_p); /* avoid unneeded calls to ui_but_value_get */ #define UI_BUT_VALUE_UNSET DBL_MAX @@ -133,10 +133,10 @@ void ui_block_to_region_fl(const ARegion *region, uiBlock *block, float *r_x, fl gy += block->panel->ofsy; } - *r_x = ((float)getsizex) * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + - block->winmat[3][0])); - *r_y = ((float)getsizey) * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + - block->winmat[3][1])); + *r_x = float(getsizex) * (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + + block->winmat[3][0])); + *r_y = float(getsizey) * (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + + block->winmat[3][1])); } void ui_block_to_window_fl(const ARegion *region, uiBlock *block, float *r_x, float *r_y) @@ -153,8 +153,8 @@ void ui_block_to_window(const ARegion *region, uiBlock *block, int *r_x, int *r_ ui_block_to_window_fl(region, block, &fx, &fy); - *r_x = (int)lround(fx); - *r_y = (int)lround(fy); + *r_x = int(lround(fx)); + *r_y = int(lround(fy)); } void ui_block_to_region_rctf(const ARegion *region, @@ -195,13 +195,13 @@ void ui_window_to_block_fl(const ARegion *region, uiBlock *block, float *r_x, fl const int sx = region->winrct.xmin; const int sy = region->winrct.ymin; - const float a = 0.5f * ((float)getsizex) * block->winmat[0][0]; - const float b = 0.5f * ((float)getsizex) * block->winmat[1][0]; - const float c = 0.5f * ((float)getsizex) * (1.0f + block->winmat[3][0]); + const float a = 0.5f * float(getsizex) * block->winmat[0][0]; + const float b = 0.5f * float(getsizex) * block->winmat[1][0]; + const float c = 0.5f * float(getsizex) * (1.0f + block->winmat[3][0]); - const float d = 0.5f * ((float)getsizey) * block->winmat[0][1]; - const float e = 0.5f * ((float)getsizey) * block->winmat[1][1]; - const float f = 0.5f * ((float)getsizey) * (1.0f + block->winmat[3][1]); + const float d = 0.5f * float(getsizey) * block->winmat[0][1]; + const float e = 0.5f * float(getsizey) * block->winmat[1][1]; + const float f = 0.5f * float(getsizey) * (1.0f + block->winmat[3][1]); const float px = *r_x - sx; const float py = *r_y - sy; @@ -232,8 +232,8 @@ void ui_window_to_block(const ARegion *region, uiBlock *block, int *r_x, int *r_ ui_window_to_block_fl(region, block, &fx, &fy); - *r_x = (int)lround(fx); - *r_y = (int)lround(fy); + *r_x = int(lround(fx)); + *r_y = int(lround(fy)); } void ui_window_to_region(const ARegion *region, int *r_x, int *r_y) @@ -279,8 +279,8 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block) rcti rect; ui_but_to_pixelrect(&rect, region, block, static_cast<const uiBut *>(block->buttons.last)); - const float buttons_width = (float)rect.xmax + UI_HEADER_OFFSET; - const float region_width = (float)region->sizex * U.dpi_fac; + const float buttons_width = float(rect.xmax) + UI_HEADER_OFFSET; + const float region_width = float(region->sizex) * U.dpi_fac; if (region_width <= buttons_width) { return; @@ -296,7 +296,7 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block) } const float view_scale_x = UI_view2d_scale_get_x(®ion->v2d); - const float segment_width = region_width / (float)sepr_flex_len; + const float segment_width = region_width / float(sepr_flex_len); float offset = 0, remaining_space = region_width - buttons_width; int i = 0; LISTBASE_FOREACH (uiBut *, but, &block->buttons) { @@ -502,8 +502,8 @@ static void ui_block_bounds_calc_centered(wmWindow *window, uiBlock *block) static void ui_block_bounds_calc_centered_pie(uiBlock *block) { const int xy[2] = { - (int)block->pie_data.pie_center_spawned[0], - (int)block->pie_data.pie_center_spawned[1], + int(block->pie_data.pie_center_spawned[0]), + int(block->pie_data.pie_center_spawned[1]), }; UI_block_translate(block, xy[0], xy[1]); @@ -682,7 +682,7 @@ static int ui_but_calc_float_precision(uiBut *but, double value) return 0; } - int prec = (int)ui_but_get_float_precision(but); + int prec = int(ui_but_get_float_precision(but)); /* first check for various special cases: * * If button is radians, we want additional precision (see T39861). @@ -1411,7 +1411,7 @@ static bool ui_but_event_property_operator_string(const bContext *C, ui_def_but_rna__menu, ui_def_but_rna__panel_type, ui_def_but_rna__menu_type)) { - prop_enum_value = (int)but->hardmin; + prop_enum_value = int(but->hardmin); ptr = &but_parent->rnapoin; prop = but_parent->rnaprop; prop_enum_value_ok = true; @@ -1804,7 +1804,7 @@ static void ui_but_predefined_extra_operator_icons_add(uiBut *but) return; } } - ui_but_extra_operator_icon_add_ptr(but, optype, WM_OP_INVOKE_DEFAULT, (int)icon); + ui_but_extra_operator_icon_add_ptr(but, optype, WM_OP_INVOKE_DEFAULT, int(icon)); } } @@ -1853,7 +1853,7 @@ static void ui_but_validate(const uiBut *but) uiButNumber *number_but = (uiButNumber *)but; if (ELEM(but->pointype, UI_BUT_POIN_CHAR, UI_BUT_POIN_SHORT, UI_BUT_POIN_INT)) { - BLI_assert((int)number_but->step_size > 0); + BLI_assert(int(number_but->step_size) > 0); } } } @@ -2165,7 +2165,7 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N); int lvalue; UI_GET_BUT_VALUE_INIT(but, *value); - lvalue = (int)*value; + lvalue = int(*value); if (UI_BITBUT_TEST(lvalue, (but->bitnr))) { is_push = state; } @@ -2187,7 +2187,7 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) case UI_BTYPE_ICON_TOGGLE: case UI_BTYPE_CHECKBOX: UI_GET_BUT_VALUE_INIT(but, *value); - if (*value != (double)but->hardmin) { + if (*value != double(but->hardmin)) { is_push = true; } break; @@ -2220,12 +2220,12 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) UI_GET_BUT_VALUE_INIT(but, *value); /* support for rna enum buts */ if (but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) { - if ((int)*value & (int)but->hardmax) { + if (int(*value) & int(but->hardmax)) { is_push = true; } } else { - if (*value == (double)but->hardmax) { + if (*value == double(but->hardmax)) { is_push = true; } } @@ -2246,7 +2246,7 @@ int ui_but_is_pushed_ex(uiBut *but, double *value) } if ((but->drawflag & UI_BUT_CHECKBOX_INVERT) && (is_push != -1)) { - is_push = !((bool)is_push); + is_push = !bool(is_push); } return is_push; } @@ -2315,9 +2315,9 @@ void ui_but_v3_get(uiBut *but, float vec[3]) } else if (but->pointype == UI_BUT_POIN_CHAR) { const char *cp = (char *)but->poin; - vec[0] = ((float)cp[0]) / 255.0f; - vec[1] = ((float)cp[1]) / 255.0f; - vec[2] = ((float)cp[2]) / 255.0f; + vec[0] = float(cp[0]) / 255.0f; + vec[1] = float(cp[1]) / 255.0f; + vec[2] = float(cp[2]) / 255.0f; } else if (but->pointype == UI_BUT_POIN_FLOAT) { const float *fp = (float *)but->poin; @@ -2363,9 +2363,9 @@ void ui_but_v3_set(uiBut *but, const float vec[3]) } else if (but->pointype == UI_BUT_POIN_CHAR) { char *cp = (char *)but->poin; - cp[0] = (char)lround(vec[0] * 255.0f); - cp[1] = (char)lround(vec[1] * 255.0f); - cp[2] = (char)lround(vec[2] * 255.0f); + cp[0] = char(lround(vec[0] * 255.0f)); + cp[1] = char(lround(vec[1] * 255.0f)); + cp[2] = char(lround(vec[2] * 255.0f)); } else if (but->pointype == UI_BUT_POIN_FLOAT) { float *fp = (float *)but->poin; @@ -2572,10 +2572,10 @@ void ui_but_value_set(uiBut *but, double value) break; case PROP_INT: if (RNA_property_array_check(prop)) { - RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, (int)value); + RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, int(value)); } else { - RNA_property_int_set(&but->rnapoin, prop, (int)value); + RNA_property_int_set(&but->rnapoin, prop, int(value)); } break; case PROP_FLOAT: @@ -2588,7 +2588,7 @@ void ui_but_value_set(uiBut *but, double value) break; case PROP_ENUM: if (RNA_property_flag(prop) & PROP_ENUM_FLAG) { - int ivalue = (int)value; + int ivalue = int(value); /* toggle for enum/flag buttons */ ivalue ^= RNA_property_enum_get(&but->rnapoin, prop); RNA_property_enum_set(&but->rnapoin, prop, ivalue); @@ -2621,7 +2621,7 @@ void ui_but_value_set(uiBut *but, double value) value = round_db_to_int_clamp(value); } else if (but->pointype == UI_BUT_POIN_FLOAT) { - float fval = (float)value; + float fval = float(value); if (fval >= -0.00001f && fval <= 0.00001f) { /* prevent negative zero */ fval = 0.0f; @@ -2634,16 +2634,16 @@ void ui_but_value_set(uiBut *but, double value) value = *but->editval = value; } else if (but->pointype == UI_BUT_POIN_CHAR) { - value = *((char *)but->poin) = (char)value; + value = *((char *)but->poin) = char(value); } else if (but->pointype == UI_BUT_POIN_SHORT) { - value = *((short *)but->poin) = (short)value; + value = *((short *)but->poin) = short(value); } else if (but->pointype == UI_BUT_POIN_INT) { - value = *((int *)but->poin) = (int)value; + value = *((int *)but->poin) = int(value); } else if (but->pointype == UI_BUT_POIN_FLOAT) { - value = *((float *)but->poin) = (float)value; + value = *((float *)but->poin) = float(value); } } @@ -2721,7 +2721,7 @@ static void ui_get_but_string_unit( /* Use precision override? */ if (float_precision == -1) { /* Sanity checks */ - precision = (int)ui_but_get_float_precision(but); + precision = int(ui_but_get_float_precision(but)); if (precision > UI_PRECISION_FLOAT_MAX) { precision = UI_PRECISION_FLOAT_MAX; } @@ -2763,7 +2763,7 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) BLI_assert(step > 0.0); - step_final = (step / scale_unit) / (double)UI_PRECISION_FLOAT_SCALE; + step_final = (step / scale_unit) / double(UI_PRECISION_FLOAT_SCALE); if (step == step_unit) { /* Logic here is to scale by the original 'step_orig' @@ -2775,7 +2775,7 @@ static float ui_get_but_step_unit(uiBut *but, float step_default) step_final *= step_orig; } - return (float)step_final; + return float(step_final); } void ui_but_string_get_ex(uiBut *but, @@ -2904,7 +2904,7 @@ void ui_but_string_get_ex(uiBut *but, } } else { - BLI_snprintf(str, maxlen, "%d", (int)value); + BLI_snprintf(str, maxlen, "%d", int(value)); } } } @@ -3211,10 +3211,10 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) } /* not that we use hard limits here */ - if (value < (double)but->hardmin) { + if (value < double(but->hardmin)) { value = but->hardmin; } - if (value > (double)but->hardmax) { + if (value > double(but->hardmax)) { value = but->hardmax; } @@ -3307,8 +3307,8 @@ void ui_but_range_set_soft(uiBut *but) if (is_array) { int value_range[2]; RNA_property_int_get_array_range(&but->rnapoin, but->rnaprop, value_range); - value_min = (double)value_range[0]; - value_max = (double)value_range[1]; + value_min = double(value_range[0]); + value_max = double(value_range[1]); } else { value_min = value_max = ui_but_value_get(but); @@ -3319,8 +3319,8 @@ void ui_but_range_set_soft(uiBut *but) float fmin, fmax, fstep, fprecision; RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision); - softmin = (fmin == -FLT_MAX) ? (float)-1e4 : fmin; - softmax = (fmax == FLT_MAX) ? (float)1e4 : fmax; + softmin = (fmin == -FLT_MAX) ? float(-1e4) : fmin; + softmax = (fmax == FLT_MAX) ? float(1e4) : fmax; // step = fstep; /* UNUSED */ // precision = fprecision; /* UNUSED */ @@ -3328,8 +3328,8 @@ void ui_but_range_set_soft(uiBut *but) if (is_array && !(subtype == PROP_COLOR && but->rnaindex == 3)) { float value_range[2]; RNA_property_float_get_array_range(&but->rnapoin, but->rnaprop, value_range); - value_min = (double)value_range[0]; - value_max = (double)value_range[1]; + value_min = double(value_range[0]); + value_max = double(value_range[1]); } else { value_min = value_max = ui_but_value_get(but); @@ -3348,8 +3348,8 @@ void ui_but_range_set_soft(uiBut *but) softmin = soft_range_round_down(value_min, softmin); } - if (softmin < (double)but->hardmin) { - softmin = (double)but->hardmin; + if (softmin < double(but->hardmin)) { + softmin = double(but->hardmin); } } if (value_max - 1e-10 > softmax) { @@ -3360,7 +3360,7 @@ void ui_but_range_set_soft(uiBut *but) softmax = soft_range_round_up(value_max, softmax); } - if (softmax > (double)but->hardmax) { + if (softmax > double(but->hardmax)) { softmax = but->hardmax; } } @@ -3474,6 +3474,7 @@ void UI_block_free(const bContext *C, uiBlock *block) BLI_freelistN(&block->saferct); BLI_freelistN(&block->color_pickers.list); + BLI_freelistN(&block->dynamic_listeners); ui_block_free_button_groups(block); ui_block_free_views(block); @@ -3481,6 +3482,20 @@ void UI_block_free(const bContext *C, uiBlock *block) MEM_freeN(block); } +void UI_block_listen(const uiBlock *block, const wmRegionListenerParams *listener_params) +{ + /* Don't need to let invisible blocks (old blocks from previous redraw) listen. */ + if (!block->active) { + return; + } + + LISTBASE_FOREACH (uiBlockDynamicListener *, listener, &block->dynamic_listeners) { + listener->listener_func(listener_params); + } + + ui_block_views_listen(block, listener_params); +} + void UI_blocklist_update_window_matrix(const bContext *C, const ListBase *lb) { ARegion *region = CTX_wm_region(C); @@ -3659,10 +3674,10 @@ static void ui_but_build_drawstr_float(uiBut *but, double value) /* Change negative zero to regular zero, without altering anything else. */ value += +0.0f; - if (value == (double)FLT_MAX) { + if (value == double(FLT_MAX)) { STR_CONCAT(but->drawstr, slen, "inf"); } - else if (value == (double)-FLT_MAX) { + else if (value == double(-FLT_MAX)) { STR_CONCAT(but->drawstr, slen, "-inf"); } else if (subtype == PROP_PERCENTAGE) { @@ -3740,10 +3755,10 @@ static void ui_but_update_ex(uiBut *but, const bool validate) case UI_BTYPE_NUM_SLIDER: if (validate) { UI_GET_BUT_VALUE_INIT(but, value); - if (value < (double)but->hardmin) { + if (value < double(but->hardmin)) { ui_but_value_set(but, but->hardmin); } - else if (value > (double)but->hardmax) { + else if (value > double(but->hardmax)) { ui_but_value_set(but, but->hardmax); } @@ -3810,7 +3825,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate) ui_but_build_drawstr_float(but, value); } else { - ui_but_build_drawstr_int(but, (int)value); + ui_but_build_drawstr_int(but, int(value)); } break; @@ -3843,7 +3858,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate) } else { UI_GET_BUT_VALUE_INIT(but, value); - str = WM_key_event_string((short)value, false); + str = WM_key_event_string(short(value), false); } BLI_snprintf(but->drawstr, UI_MAX_DRAW_STR, "%s%s", but->str, str); break; @@ -4263,7 +4278,7 @@ void ui_def_but_icon_clear(uiBut *but) but->drawflag &= ~UI_BUT_ICON_LEFT; } -static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *but_p) +static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p) { uiBlock *block = uiLayoutGetBlock(layout); uiPopupBlockHandle *handle = block->handle; @@ -4573,7 +4588,7 @@ static uiBut *ui_def_but_rna(uiBlock *block, value = RNA_property_enum_get(ptr, prop); } else { - value = (int)max; + value = int(max); } const int i = RNA_enum_from_value(item, value); @@ -5933,12 +5948,12 @@ bContextStore *UI_but_context_get(const uiBut *but) void UI_but_unit_type_set(uiBut *but, const int unit_type) { - but->unit_type = (uchar)(RNA_SUBTYPE_UNIT_VALUE(unit_type)); + but->unit_type = uchar(RNA_SUBTYPE_UNIT_VALUE(unit_type)); } int UI_but_unit_type_get(const uiBut *but) { - const int ownUnit = (int)but->unit_type; + const int ownUnit = int(but->unit_type); /* own unit define always takes precedence over RNA provided, allowing for overriding * default value provided in RNA in a few special cases (i.e. Active Keyframe in Graph Edit) @@ -6321,6 +6336,13 @@ void UI_but_func_search_set_tooltip(uiBut *but, uiButSearchTooltipFn tooltip_fn) but_search->item_tooltip_fn = tooltip_fn; } +void UI_but_func_search_set_listen(uiBut *but, uiButSearchListenFn listen_fn) +{ + uiButSearch *but_search = (uiButSearch *)but; + BLI_assert(but->type == UI_BTYPE_SEARCH_MENU); + but_search->listen_fn = listen_fn; +} + void UI_but_func_search_set_results_are_suggestions(uiBut *but, const bool value) { uiButSearch *but_search = (uiButSearch *)but; @@ -6334,7 +6356,7 @@ static void operator_enum_search_update_fn(const struct bContext *C, void *but, const char *str, uiSearchItems *items, - const bool UNUSED(is_first)) + const bool /*is_first*/) { wmOperatorType *ot = ((uiBut *)but)->optype; PropertyRNA *prop = ot->prop; @@ -6383,7 +6405,7 @@ static void operator_enum_search_update_fn(const struct bContext *C, } } -static void operator_enum_search_exec_fn(struct bContext *UNUSED(C), void *but, void *arg2) +static void operator_enum_search_exec_fn(struct bContext * /*C*/, void *but, void *arg2) { wmOperatorType *ot = ((uiBut *)but)->optype; /* Will create it if needed! */ @@ -6445,6 +6467,11 @@ void UI_but_hint_drawstr_set(uiBut *but, const char *string) ui_but_add_shortcut(but, string, false); } +void UI_but_icon_indicator_number_set(uiBut *but, const int indicator_number) +{ + UI_icon_text_overlay_init_from_count(&but->icon_overlay_text, indicator_number); +} + void UI_but_node_link_set(uiBut *but, bNodeSocket *socket, const float draw_color[4]) { but->flag |= UI_BUT_NODE_LINK; @@ -6656,8 +6683,8 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) /* enum property */ ptr = &but->rnapoin; prop = but->rnaprop; - value = (ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_TAB)) ? (int)but->hardmax : - (int)ui_but_value_get(but); + value = ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_TAB) ? int(but->hardmax) : + int(ui_but_value_get(but)); } else if (but->optype) { PointerRNA *opptr = UI_but_operator_ptr_get(but); diff --git a/source/blender/editors/interface/interface_anim.cc b/source/blender/editors/interface/interface_anim.cc index 4da6cefd8de..58a7ac93242 100644 --- a/source/blender/editors/interface/interface_anim.cc +++ b/source/blender/editors/interface/interface_anim.cc @@ -315,7 +315,7 @@ void ui_but_anim_paste_driver(bContext *C) WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, nullptr, nullptr); } -void ui_but_anim_decorate_cb(bContext *C, void *arg_but, void *UNUSED(arg_dummy)) +void ui_but_anim_decorate_cb(bContext *C, void *arg_but, void * /*arg_dummy*/) { wmWindowManager *wm = CTX_wm_manager(C); uiButDecorator *but_decorate = static_cast<uiButDecorator *>(arg_but); diff --git a/source/blender/editors/interface/interface_context_path.cc b/source/blender/editors/interface/interface_context_path.cc index 3b91ca79c00..74a07d6edc8 100644 --- a/source/blender/editors/interface/interface_context_path.cc +++ b/source/blender/editors/interface/interface_context_path.cc @@ -17,6 +17,8 @@ #include "UI_interface.hh" #include "UI_resources.h" +#include "RNA_prototypes.h" + #include "WM_api.h" namespace blender::ui { @@ -41,7 +43,13 @@ void context_path_add_generic(Vector<ContextPathItem> &path, static_cast<BIFIconID>(RNA_struct_ui_icon(rna_ptr.type)) : icon_override; - path.append({name, static_cast<int>(icon)}); + if (&rna_type == &RNA_NodeTree) { + ID *id = (ID *)ptr; + path.append({name, int(icon), ID_REAL_USERS(id)}); + } + else { + path.append({name, int(icon), 1}); + } } /* -------------------------------------------------------------------- */ @@ -60,7 +68,9 @@ void template_breadcrumbs(uiLayout &layout, Span<ContextPathItem> context_path) if (i > 0) { uiItemL(sub_row, "", ICON_RIGHTARROW_THIN); } - uiItemL(sub_row, context_path[i].name.c_str(), context_path[i].icon); + uiBut *but = uiItemL_ex( + sub_row, context_path[i].name.c_str(), context_path[i].icon, false, false); + UI_but_icon_indicator_number_set(but, context_path[i].icon_indicator_number); } } diff --git a/source/blender/editors/interface/interface_drag.cc b/source/blender/editors/interface/interface_drag.cc index 4bf2dac4151..e959986d19e 100644 --- a/source/blender/editors/interface/interface_drag.cc +++ b/source/blender/editors/interface/interface_drag.cc @@ -27,15 +27,14 @@ void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale) } void UI_but_drag_set_asset(uiBut *but, - const AssetHandle *asset, + const AssetHandle *asset_handle, const char *path, - struct AssetMetaData *metadata, int import_type, int icon, struct ImBuf *imb, float scale) { - wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, metadata, path, import_type); + wmDragAsset *asset_drag = WM_drag_create_asset_data(asset_handle, path, import_type); /* FIXME: This is temporary evil solution to get scene/view-layer/etc in the copy callback of the * #wmDropBox. diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 190830568e3..f1a324c411a 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -2307,9 +2307,6 @@ void UI_draw_box_shadow(const rctf *rect, uchar alpha) void ui_draw_dropshadow( const rctf *rct, float radius, float aspect, float alpha, int UNUSED(select)) { - const float max_radius = (BLI_rctf_size_y(rct) - 10.0f) * 0.5f; - const float rad = min_ff(radius, max_radius); - /* This undoes the scale of the view for higher zoom factors to clamp the shadow size. */ const float clamped_aspect = smoothminf(aspect, 1.0f, 0.5f); @@ -2317,6 +2314,9 @@ void ui_draw_dropshadow( const float shadow_offset = 0.5f * U.widget_unit * clamped_aspect; const float shadow_alpha = 0.5f * alpha; + const float max_radius = (BLI_rctf_size_y(rct) - shadow_offset) * 0.5f; + const float rad = min_ff(radius, max_radius); + GPU_blend(GPU_BLEND_ALPHA); uiWidgetBaseParameters widget_params = { diff --git a/source/blender/editors/interface/interface_dropboxes.cc b/source/blender/editors/interface/interface_dropboxes.cc index b72d8d2c238..60e1c0abfa1 100644 --- a/source/blender/editors/interface/interface_dropboxes.cc +++ b/source/blender/editors/interface/interface_dropboxes.cc @@ -41,10 +41,7 @@ static bool ui_view_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event) return UI_view_item_can_drop(hovered_item, drag, &drag->drop_state.disabled_info); } -static char *ui_view_drop_tooltip(bContext *C, - wmDrag *drag, - const int xy[2], - wmDropBox *UNUSED(drop)) +static char *ui_view_drop_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropBox * /*drop*/) { const ARegion *region = CTX_wm_region(C); const uiViewItemHandle *hovered_item = UI_region_views_find_item_at(region, xy); @@ -61,12 +58,12 @@ static char *ui_view_drop_tooltip(bContext *C, /** \name Name Drag/Drop Callbacks * \{ */ -static bool ui_drop_name_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(event)) +static bool ui_drop_name_poll(struct bContext *C, wmDrag *drag, const wmEvent * /*event*/) { return UI_but_active_drop_name(C) && (drag->type == WM_DRAG_ID); } -static void ui_drop_name_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop) +static void ui_drop_name_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop) { const ID *id = WM_drag_get_local_ID(drag, 0); RNA_string_set(drop->ptr, "string", id->name + 2); @@ -78,22 +75,22 @@ static void ui_drop_name_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop /** \name Material Drag/Drop Callbacks * \{ */ -static bool ui_drop_material_poll(bContext *C, wmDrag *drag, const wmEvent *UNUSED(event)) +static bool ui_drop_material_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/) { PointerRNA mat_slot = CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot); return WM_drag_is_ID_type(drag, ID_MA) && !RNA_pointer_is_null(&mat_slot); } -static void ui_drop_material_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop) +static void ui_drop_material_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop) { const ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_MA); - RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid); + RNA_int_set(drop->ptr, "session_uuid", int(id->session_uuid)); } static char *ui_drop_material_tooltip(bContext *C, wmDrag *drag, - const int UNUSED(xy[2]), - struct wmDropBox *UNUSED(drop)) + const int /*xy*/[2], + struct wmDropBox * /*drop*/) { PointerRNA rna_ptr = CTX_data_pointer_get_type(C, "object", &RNA_Object); Object *ob = (Object *)rna_ptr.data; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 6ee421fb4d2..ac16d41dabe 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -959,7 +959,7 @@ static void ui_apply_but_undo(uiBut *but) str = ""; } - /* delayed, after all other funcs run, popups are closed, etc */ + /* Delayed, after all other functions run, popups are closed, etc. */ uiAfterFunc *after = ui_afterfunc_new(); BLI_strncpy(after->undostr, str, min_zz(str_len_clip + 1, sizeof(after->undostr))); } @@ -991,7 +991,7 @@ static void ui_apply_but_autokey(bContext *C, uiBut *but) static void ui_apply_but_funcs_after(bContext *C) { - /* copy to avoid recursive calls */ + /* Copy to avoid recursive calls. */ ListBase funcs = UIAfterFuncs; BLI_listbase_clear(&UIAfterFuncs); @@ -1118,9 +1118,6 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data) } else { value_toggle = (value == 0.0); - if (ELEM(but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N)) { - value_toggle = !value_toggle; - } } ui_but_value_set(but, (double)value_toggle); @@ -3017,23 +3014,6 @@ static bool ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data) return changed; } -static bool ui_textedit_set_cursor_pos_foreach_glyph(const char *UNUSED(str), - const size_t str_step_ofs, - const rcti *glyph_step_bounds, - const int UNUSED(glyph_advance_x), - const rcti *glyph_bounds, - const int UNUSED(glyph_bearing[2]), - void *user_data) -{ - int *cursor_data = user_data; - const int center = glyph_step_bounds->xmin + (BLI_rcti_size_x(glyph_bounds) / 2.0f); - if (cursor_data[0] < center) { - cursor_data[1] = str_step_ofs; - return false; - } - return true; -} - /** * \param x: Screen space cursor location - #wmEvent.x * @@ -3064,7 +3044,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con startx += UI_DPI_ICON_SIZE / aspect; } } - startx += (UI_TEXT_MARGIN_X * U.widget_unit) / aspect; + startx += (UI_TEXT_MARGIN_X * U.widget_unit - U.pixelsize) / aspect; /* mouse dragged outside the widget to the left */ if (x < startx) { @@ -3088,23 +3068,8 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con } /* mouse inside the widget, mouse coords mapped in widget space */ else { - str_last = &str[but->ofs]; - const int str_last_len = strlen(str_last); - const int x_pos = (int)(x - startx); - int glyph_data[2] = { - x_pos, /* horizontal position to test. */ - -1, /* Write the character offset here. */ - }; - BLF_boundbox_foreach_glyph(fstyle.uifont_id, - str + but->ofs, - INT_MAX, - ui_textedit_set_cursor_pos_foreach_glyph, - glyph_data); - /* If value untouched then we are to the right. */ - if (glyph_data[1] == -1) { - glyph_data[1] = str_last_len; - } - but->pos = glyph_data[1] + but->ofs; + but->pos = but->ofs + BLF_str_offset_from_cursor_position( + fstyle.uifont_id, str + but->ofs, INT_MAX, (int)(x - startx)); } ui_but_text_password_hide(password_str, but, true); @@ -3554,7 +3519,7 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) { - /* label and roundbox can overlap real buttons (backdrops...) */ + /* Label and round-box can overlap real buttons (backdrops...). */ if (ELEM(actbut->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, @@ -3586,7 +3551,7 @@ static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonDa static void ui_textedit_prev_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) { - /* label and roundbox can overlap real buttons (backdrops...) */ + /* Label and round-box can overlap real buttons (backdrops...). */ if (ELEM(actbut->type, UI_BTYPE_LABEL, UI_BTYPE_SEPR, @@ -3929,7 +3894,7 @@ static void ui_do_but_textedit( } if (event->type == WM_IME_COMPOSITE_EVENT && ime_data->result_len) { if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER) && - strcmp(ime_data->str_result, "\xE3\x80\x82") == 0) { + STREQ(ime_data->str_result, "\xE3\x80\x82")) { /* Convert Ideographic Full Stop (U+3002) to decimal point when entering numbers. */ ui_textedit_insert_ascii(but, data, '.'); } @@ -4646,7 +4611,7 @@ static int ui_do_but_TEX( if (data->state == BUTTON_STATE_HIGHLIGHT) { if (ELEM(event->type, LEFTMOUSE, EVT_BUT_OPEN, EVT_PADENTER, EVT_RETKEY) && event->val == KM_PRESS) { - if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && (!UI_but_is_utf8(but))) { + if (ELEM(event->type, EVT_PADENTER, EVT_RETKEY) && !UI_but_is_utf8(but)) { /* pass - allow filesel, enter to execute */ } else if (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && @@ -5172,7 +5137,7 @@ static bool ui_numedit_but_NUM(uiButNumber *number_but, CLAMP_MIN(non_linear_scale, 0.5f * UI_DPI_FAC); } - data->dragf += (((float)(mx - data->draglastx)) / deler) * non_linear_scale; + data->dragf += ((float)(mx - data->draglastx) / deler) * non_linear_scale; if (but->softmin == softmin) { CLAMP_MIN(data->dragf, 0.0f); @@ -5797,7 +5762,7 @@ static int ui_do_but_SLI( else #endif { - f = (float)(mx - but->rect.xmin) / (BLI_rctf_size_x(&but->rect)); + f = (float)(mx - but->rect.xmin) / BLI_rctf_size_x(&but->rect); } if (scale_type == PROP_SCALE_LOG) { @@ -6004,7 +5969,7 @@ static int ui_do_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data, co } } #ifdef USE_DRAG_TOGGLE - if (event->type == LEFTMOUSE && event->val == KM_PRESS && (ui_but_is_drag_toggle(but))) { + if (event->type == LEFTMOUSE && event->val == KM_PRESS && ui_but_is_drag_toggle(but)) { button_activate_state(C, but, BUTTON_STATE_WAIT_DRAG); data->dragstartx = event->xy[0]; data->dragstarty = event->xy[1]; @@ -6152,7 +6117,7 @@ static bool ui_numedit_but_UNITVEC( * do this in "angle" space - this gives increments of same size */ for (int i = 0; i < 3; i++) { angle = asinf(fp[i]); - angle_snap = roundf((angle / snap_steps_angle)) * snap_steps_angle; + angle_snap = roundf(angle / snap_steps_angle) * snap_steps_angle; fp[i] = sinf(angle_snap); } normalize_v3(fp); @@ -7008,7 +6973,7 @@ static bool ui_numedit_but_COLORBAND(uiBut *but, uiHandleButtonData *data, int m return changed; } - const float dx = ((float)(mx - data->draglastx)) / BLI_rctf_size_x(&but->rect); + const float dx = (float)(mx - data->draglastx) / BLI_rctf_size_x(&but->rect); data->dragcbd->pos += dx; CLAMP(data->dragcbd->pos, 0.0f, 1.0f); @@ -7034,7 +6999,7 @@ static int ui_do_but_COLORBAND( if (event->modifier & KM_CTRL) { /* insert new key on mouse location */ - const float pos = ((float)(mx - but->rect.xmin)) / BLI_rctf_size_x(&but->rect); + const float pos = (float)(mx - but->rect.xmin) / BLI_rctf_size_x(&but->rect); BKE_colorband_element_add(coba, pos); button_activate_state(C, but, BUTTON_STATE_EXIT); } @@ -9585,8 +9550,8 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi else if (val == KM_PRESS) { if ((ELEM(type, EVT_UPARROWKEY, EVT_DOWNARROWKEY, EVT_LEFTARROWKEY, EVT_RIGHTARROWKEY) && (event->modifier & (KM_SHIFT | KM_CTRL | KM_ALT | KM_OSKEY)) == 0) || - ((ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_CTRL) && - (event->modifier & (KM_SHIFT | KM_ALT | KM_OSKEY)) == 0))) { + (ELEM(type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_CTRL) && + (event->modifier & (KM_SHIFT | KM_ALT | KM_OSKEY)) == 0)) { const int value_orig = RNA_property_int_get(&listbox->rnapoin, listbox->rnaprop); int value, min, max; @@ -10839,7 +10804,7 @@ static int ui_handle_menu_return_submenu(bContext *C, static bool ui_but_pie_menu_supported_apply(uiBut *but) { - return (!ELEM(but->type, UI_BTYPE_NUM_SLIDER, UI_BTYPE_NUM)); + return !ELEM(but->type, UI_BTYPE_NUM_SLIDER, UI_BTYPE_NUM); } static int ui_but_pie_menu_apply(bContext *C, @@ -11113,7 +11078,7 @@ static int ui_pie_handler(bContext *C, const wmEvent *event, uiPopupBlockHandle case EVT_XKEY: case EVT_YKEY: case EVT_ZKEY: { - if ((ELEM(event->val, KM_PRESS, KM_DBL_CLICK)) && + if (ELEM(event->val, KM_PRESS, KM_DBL_CLICK) && ((event->modifier & (KM_SHIFT | KM_CTRL | KM_OSKEY)) == 0)) { LISTBASE_FOREACH (uiBut *, but, &block->buttons) { if (but->menu_key == event->type) { @@ -11380,9 +11345,9 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE (ui_region_find_active_but(data->menu->region) == NULL) && /* make sure mouse isn't inside another menu (see T43247) */ (ui_screen_region_find_mouse_over(screen, event) == NULL) && - (ELEM(but->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU)) && + ELEM(but->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU) && (but_other = ui_but_find_mouse_over(region, event)) && (but != but_other) && - (ELEM(but_other->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU)) && + ELEM(but_other->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU) && /* Hover-opening menu's doesn't work well for buttons over one another * along the same axis the menu is opening on (see T71719). */ (((data->menu->direction & (UI_DIR_LEFT | UI_DIR_RIGHT)) && diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index ad2c08194aa..a5e2cd02f3b 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -415,8 +415,15 @@ static void vicon_collection_color_draw( const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; - UI_icon_draw_ex( - x, y, ICON_OUTLINER_COLLECTION, aspect, 1.0f, 0.0f, collection_color->color, true); + UI_icon_draw_ex(x, + y, + ICON_OUTLINER_COLLECTION, + aspect, + 1.0f, + 0.0f, + collection_color->color, + true, + UI_NO_ICON_OVERLAY_TEXT); } # define DEF_ICON_COLLECTION_COLOR_DRAW(index, color) \ @@ -444,7 +451,8 @@ static void vicon_strip_color_draw( const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; - UI_icon_draw_ex(x, y, ICON_SNAP_FACE, aspect, 1.0f, 0.0f, strip_color->color, true); + UI_icon_draw_ex( + x, y, ICON_SNAP_FACE, aspect, 1.0f, 0.0f, strip_color->color, true, UI_NO_ICON_OVERLAY_TEXT); } # define DEF_ICON_STRIP_COLOR_DRAW(index, color) \ @@ -472,8 +480,15 @@ static void vicon_strip_color_draw_library_data_indirect( { const float aspect = (float)ICON_DEFAULT_WIDTH / (float)w; - UI_icon_draw_ex( - x, y, ICON_LIBRARY_DATA_DIRECT, aspect, ICON_INDIRECT_DATA_ALPHA * alpha, 0.0f, NULL, false); + UI_icon_draw_ex(x, + y, + ICON_LIBRARY_DATA_DIRECT, + aspect, + ICON_INDIRECT_DATA_ALPHA * alpha, + 0.0f, + NULL, + false, + UI_NO_ICON_OVERLAY_TEXT); } static void vicon_strip_color_draw_library_data_override_noneditable( @@ -488,7 +503,8 @@ static void vicon_strip_color_draw_library_data_override_noneditable( ICON_INDIRECT_DATA_ALPHA * alpha * 0.75f, 0.0f, NULL, - false); + false, + UI_NO_ICON_OVERLAY_TEXT); } /* Dynamically render icon instead of rendering a plain color to a texture/buffer @@ -821,7 +837,7 @@ static ImBuf *create_mono_icon_with_border(ImBuf *buf, blend_color_interpolate_float(dest_rgba, orig_rgba, border_rgba, 1.0 - orig_rgba[3]); linearrgb_to_srgb_v4(dest_srgb, dest_rgba); - const uint alpha_mask = ((uint)(dest_srgb[3] * 255)) << 24; + const uint alpha_mask = (uint)(dest_srgb[3] * 255) << 24; const uint cpack = rgb_to_cpack(dest_srgb[0], dest_srgb[1], dest_srgb[2]) | alpha_mask; result->rect[offset_write] = cpack; } @@ -923,7 +939,7 @@ static void init_internal_icons(void) char iconfilestr[FILE_MAX]; if (icondir) { - BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); + BLI_path_join(iconfilestr, sizeof(iconfilestr), icondir, btheme->tui.iconfile); /* if the image is missing bbuf will just be NULL */ bbuf = IMB_loadiffname(iconfilestr, IB_rect, NULL); @@ -1047,7 +1063,7 @@ static void init_iconfile_list(struct ListBase *list) /* check to see if the image is the right size, continue if not */ /* copying strings here should go ok, assuming that we never get back * a complete path to file longer than 256 chars */ - BLI_join_dirfile(iconfilestr, sizeof(iconfilestr), icondir, filename); + BLI_path_join(iconfilestr, sizeof(iconfilestr), icondir, filename); bbuf = IMB_loadiffname(iconfilestr, IB_rect); if (bbuf) { @@ -1293,8 +1309,8 @@ static void ui_id_preview_image_render_size( const bContext *C, Scene *scene, ID *id, PreviewImage *pi, int size, const bool use_job); static void ui_studiolight_icon_job_exec(void *customdata, - short *UNUSED(stop), - short *UNUSED(do_update), + bool *UNUSED(stop), + bool *UNUSED(do_update), float *UNUSED(progress)) { Icon **tmp = (Icon **)customdata; @@ -1716,9 +1732,47 @@ static void icon_draw_texture(float x, int ih, float alpha, const float rgb[3], - bool with_border) -{ - if (g_icon_draw_cache.enabled) { + bool with_border, + const IconTextOverlay *text_overlay) +{ + const float zoom_factor = w / UI_DPI_ICON_SIZE; + float text_width = 0.0f; + + /* No need to show if too zoomed out, otherwise it just adds noise. */ + const bool show_indicator = (text_overlay && text_overlay->text[0] != '\0') && + (zoom_factor > 0.7f); + + if (show_indicator) { + /* Handle the little numbers on top of the icon. */ + uchar text_color[4]; + UI_GetThemeColor3ubv(TH_TEXT, text_color); + text_color[3] = 255; + + uiFontStyle fstyle_small = *UI_FSTYLE_WIDGET; + fstyle_small.points *= zoom_factor; + fstyle_small.points *= 0.8f; + + rcti text_rect = { + .xmax = x + UI_UNIT_X * zoom_factor, + .xmin = x, + .ymax = y, + .ymin = y, + }; + + UI_fontstyle_draw(&fstyle_small, + &text_rect, + text_overlay->text, + sizeof(text_overlay->text), + text_color, + &(struct uiFontStyleDraw_Params){ + .align = UI_STYLE_TEXT_RIGHT, + }); + text_width = (float)UI_fontstyle_string_width(&fstyle_small, text_overlay->text) / UI_UNIT_X / + zoom_factor; + } + + /* Draw the actual icon. */ + if (!show_indicator && g_icon_draw_cache.enabled) { icon_draw_texture_cached(x, y, w, h, ix, iy, iw, ih, alpha, rgb, with_border); return; } @@ -1735,7 +1789,7 @@ static void icon_draw_texture(float x, GPUTexture *texture = with_border ? icongltex.tex[1] : icongltex.tex[0]; - GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR); + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_ICON); GPU_shader_bind(shader); const int img_binding = GPU_shader_get_texture_binding(shader, "image"); @@ -1752,6 +1806,7 @@ static void icon_draw_texture(float x, GPU_shader_uniform_vector(shader, rect_tex_loc, 4, 1, (float[4]){x1, y1, x2, y2}); GPU_shader_uniform_vector(shader, rect_geom_loc, 4, 1, (float[4]){x, y, x + w, y + h}); + GPU_shader_uniform_1f(shader, "text_width", text_width); GPU_texture_bind_ex(texture, GPU_SAMPLER_ICON, img_binding, false); @@ -1786,7 +1841,8 @@ static void icon_draw_size(float x, int draw_size, const float desaturate, const uchar mono_rgba[4], - const bool mono_border) + const bool mono_border, + const IconTextOverlay *text_overlay) { bTheme *btheme = UI_GetTheme(); const float fdraw_size = (float)draw_size; @@ -1874,7 +1930,8 @@ static void icon_draw_size(float x, di->data.texture.h, alpha, NULL, - false); + false, + text_overlay); } else if (di->type == ICON_TYPE_MONO_TEXTURE) { /* Monochrome icon that uses text or theme color. */ @@ -1908,7 +1965,8 @@ static void icon_draw_size(float x, di->data.texture.h + 2 * border_texel, color[3], color, - with_border); + with_border, + text_overlay); } else if (di->type == ICON_TYPE_BUFFER) { @@ -1956,7 +2014,7 @@ static void ui_id_preview_image_render_size( const bContext *C, Scene *scene, ID *id, PreviewImage *pi, int size, const bool use_job) { /* changed only ever set by dynamic icons */ - if (((pi->flag[size] & PRV_CHANGED) || !pi->rect[size])) { + if ((pi->flag[size] & PRV_CHANGED) || !pi->rect[size]) { /* create the rect if necessary */ icon_set_image(C, scene, id, pi, size, use_job); @@ -2425,17 +2483,27 @@ int UI_icon_color_from_collection(const Collection *collection) void UI_icon_draw(float x, float y, int icon_id) { - UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false); + UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, 1.0f, 0.0f, NULL, false, UI_NO_ICON_OVERLAY_TEXT); } void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha) { - UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false); + UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false, UI_NO_ICON_OVERLAY_TEXT); } void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size) { - icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL, false); + icon_draw_size(x, + y, + icon_id, + aspect, + alpha, + ICON_SIZE_PREVIEW, + size, + false, + NULL, + false, + UI_NO_ICON_OVERLAY_TEXT); } void UI_icon_draw_ex(float x, @@ -2445,7 +2513,8 @@ void UI_icon_draw_ex(float x, float alpha, float desaturate, const uchar mono_color[4], - const bool mono_border) + const bool mono_border, + const IconTextOverlay *text_overlay) { const int draw_size = get_draw_size(ICON_SIZE_ICON); icon_draw_size(x, @@ -2457,7 +2526,19 @@ void UI_icon_draw_ex(float x, draw_size, desaturate, mono_color, - mono_border); + mono_border, + text_overlay); +} + +void UI_icon_text_overlay_init_from_count(IconTextOverlay *text_overlay, + const int icon_indicator_number) +{ + /* The icon indicator is used as an aggregator, no need to show if it is 1. */ + if (icon_indicator_number < 2) { + text_overlay->text[0] = '\0'; + return; + } + BLI_str_format_integer_unit(text_overlay->text, icon_indicator_number); } /* ********** Alert Icons ********** */ diff --git a/source/blender/editors/interface/interface_icons_event.c b/source/blender/editors/interface/interface_icons_event.c index e892a989191..b5cbc92741e 100644 --- a/source/blender/editors/interface/interface_icons_event.c +++ b/source/blender/editors/interface/interface_icons_event.c @@ -66,7 +66,7 @@ static void icon_draw_rect_input_text( BLF_batch_draw_flush(); const int font_id = BLF_default(); BLF_color4fv(font_id, color); - BLF_size(font_id, font_size * U.pixelsize, U.dpi); + BLF_size(font_id, font_size * U.dpi_fac); float width, height; BLF_width_and_height(font_id, str, BLF_DRAW_STR_DUMMY_MAX, &width, &height); const float x = trunc(rect->xmin + (((rect->xmax - rect->xmin) - width) / 2.0f)); diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 0c842084de6..982ac1753e1 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -23,6 +23,7 @@ struct ARegion; struct AnimationEvalContext; struct CurveMapping; struct CurveProfile; +struct IconTextOverlay; struct ID; struct ImBuf; struct Main; @@ -275,6 +276,9 @@ struct uiBut { uiButPushedStateFunc pushed_state_func; const void *pushed_state_arg; + /** Little indicator (e.g., counter) displayed on top of some icons. */ + struct IconTextOverlay icon_overlay_text; + /* pointer back */ uiBlock *block; }; @@ -307,6 +311,8 @@ typedef struct uiButSearch { uiButSearchCreateFn popup_create_fn; uiButSearchUpdateFn items_update_fn; + uiButSearchListenFn listen_fn; + void *item_active; void *arg; @@ -471,6 +477,12 @@ typedef enum uiButtonGroupFlag { } uiButtonGroupFlag; ENUM_OPERATORS(uiButtonGroupFlag, UI_BUTTON_GROUP_PANEL_HEADER); +typedef struct uiBlockDynamicListener { + struct uiBlockDynamicListener *next, *prev; + + void (*listener_func)(const struct wmRegionListenerParams *params); +} uiBlockDynamicListener; + struct uiBlock { uiBlock *next, *prev; @@ -493,6 +505,8 @@ struct uiBlock { * state that is persistent over redraws (e.g. collapsed tree-view items). */ ListBase views; + ListBase dynamic_listeners; /* #uiBlockDynamicListener */ + char name[UI_MAX_NAME_STR]; float winmat[4][4]; @@ -1534,6 +1548,8 @@ void ui_interface_tag_script_reload_queries(void); /* interface_view.cc */ void ui_block_free_views(struct uiBlock *block); +void ui_block_views_listen(const uiBlock *block, + const struct wmRegionListenerParams *listener_params); uiViewHandle *ui_block_view_find_matching_in_old_block(const uiBlock *new_block, const uiViewHandle *new_view); diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 2f91461c89b..ad74328e8fc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -694,7 +694,7 @@ static void ui_item_array(uiLayout *layout, else { /* Even if 'expand' is false, we expand anyway. */ - /* layout for known array subtypes */ + /* Layout for known array sub-types. */ char str[3] = {'\0'}; if (!icon_only && show_text) { @@ -2112,11 +2112,11 @@ void uiItemFullR(uiLayout *layout, icon = ICON_CHECKBOX_DEHLT; /* but->iconadd will set to correct icon */ } else if (is_array) { - icon = (RNA_property_boolean_get_index(ptr, prop, index)) ? ICON_CHECKBOX_HLT : - ICON_CHECKBOX_DEHLT; + icon = RNA_property_boolean_get_index(ptr, prop, index) ? ICON_CHECKBOX_HLT : + ICON_CHECKBOX_DEHLT; } else { - icon = (RNA_property_boolean_get(ptr, prop)) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; + icon = RNA_property_boolean_get(ptr, prop) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; } } } @@ -3235,7 +3235,7 @@ static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon) return but; } -void uiItemL_ex( +uiBut *uiItemL_ex( uiLayout *layout, const char *name, int icon, const bool highlight, const bool redalert) { uiBut *but = uiItemL_(layout, name, icon); @@ -3248,6 +3248,8 @@ void uiItemL_ex( if (redalert) { UI_but_flag_enable(but, UI_BUT_REDALERT); } + + return but; } void uiItemL(uiLayout *layout, const char *name, int icon) @@ -5812,6 +5814,14 @@ void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout) printf("%s: opening menu \"%s\"\n", __func__, mt->idname); } + if (mt->listener) { + /* Forward the menu type listener to the block we're drawing in. */ + uiBlock *block = uiLayoutGetBlock(layout); + uiBlockDynamicListener *listener = MEM_mallocN(sizeof(*listener), "uiBlockDynamicListener"); + listener->listener_func = mt->listener; + BLI_addtail(&block->dynamic_listeners, listener); + } + if (layout->context) { CTX_store_set(C, layout->context); } diff --git a/source/blender/editors/interface/interface_ops.cc b/source/blender/editors/interface/interface_ops.cc index a5b0193a86d..2d06dd2c465 100644 --- a/source/blender/editors/interface/interface_ops.cc +++ b/source/blender/editors/interface/interface_ops.cc @@ -270,7 +270,7 @@ static bool copy_python_command_button_poll(bContext *C) return false; } -static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op)) +static int copy_python_command_button_exec(bContext *C, wmOperator * /*op*/) { uiBut *but = UI_context_active_but_get(C); @@ -421,7 +421,7 @@ static bool assign_default_button_poll(bContext *C) return false; } -static int assign_default_button_exec(bContext *C, wmOperator *UNUSED(op)) +static int assign_default_button_exec(bContext *C, wmOperator * /*op*/) { PointerRNA ptr; PropertyRNA *prop; @@ -461,7 +461,7 @@ static void UI_OT_assign_default_button(wmOperatorType *ot) /** \name Unset Property Button Operator * \{ */ -static int unset_property_button_exec(bContext *C, wmOperator *UNUSED(op)) +static int unset_property_button_exec(bContext *C, wmOperator * /*op*/) { PointerRNA ptr; PropertyRNA *prop; @@ -609,9 +609,7 @@ static int override_type_set_button_exec(bContext *C, wmOperator *op) return operator_button_property_finish(C, &ptr, prop); } -static int override_type_set_button_invoke(bContext *C, - wmOperator *op, - const wmEvent *UNUSED(event)) +static int override_type_set_button_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { #if 0 /* Disabled for now */ return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_DEFAULT); @@ -806,7 +804,7 @@ static bool override_idtemplate_make_poll(bContext *C) return override_idtemplate_poll(C, true); } -static int override_idtemplate_make_exec(bContext *C, wmOperator *UNUSED(op)) +static int override_idtemplate_make_exec(bContext *C, wmOperator * /*op*/) { ID *owner_id, *id; PointerRNA owner_ptr; @@ -869,7 +867,7 @@ static bool override_idtemplate_reset_poll(bContext *C) return override_idtemplate_poll(C, false); } -static int override_idtemplate_reset_exec(bContext *C, wmOperator *UNUSED(op)) +static int override_idtemplate_reset_exec(bContext *C, wmOperator * /*op*/) { ID *owner_id, *id; PointerRNA owner_ptr; @@ -917,7 +915,7 @@ static bool override_idtemplate_clear_poll(bContext *C) return override_idtemplate_poll(C, false); } -static int override_idtemplate_clear_exec(bContext *C, wmOperator *UNUSED(op)) +static int override_idtemplate_clear_exec(bContext *C, wmOperator * /*op*/) { ID *owner_id, *id; PointerRNA owner_ptr; @@ -939,6 +937,7 @@ static int override_idtemplate_clear_exec(bContext *C, wmOperator *UNUSED(op)) if (BKE_lib_override_library_is_hierarchy_leaf(bmain, id)) { id_new = id->override_library->reference; bool do_remap_active = false; + BKE_view_layer_synced_ensure(scene, view_layer); if (BKE_view_layer_active_object_get(view_layer) == (Object *)id) { BLI_assert(GS(id->name) == ID_OB); BLI_assert(GS(id_new->name) == ID_OB); @@ -991,7 +990,7 @@ static void UI_OT_override_idtemplate_clear(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -static bool override_idtemplate_menu_poll(const bContext *C_const, MenuType *UNUSED(mt)) +static bool override_idtemplate_menu_poll(const bContext *C_const, MenuType * /*mt*/) { bContext *C = (bContext *)C_const; ID *owner_id, *id; @@ -1007,7 +1006,7 @@ static bool override_idtemplate_menu_poll(const bContext *C_const, MenuType *UNU return true; } -static void override_idtemplate_menu_draw(const bContext *UNUSED(C), Menu *menu) +static void override_idtemplate_menu_draw(const bContext * /*C*/, Menu *menu) { uiLayout *layout = menu->layout; uiItemO(layout, IFACE_("Make"), ICON_NONE, "UI_OT_override_idtemplate_make"); @@ -1502,14 +1501,16 @@ static bool jump_to_target_ptr(bContext *C, PointerRNA ptr, const bool poll) } /* Find the containing Object. */ + const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Base *base = nullptr; const short id_type = GS(ptr.owner_id->name); if (id_type == ID_OB) { + BKE_view_layer_synced_ensure(scene, view_layer); base = BKE_view_layer_base_find(view_layer, (Object *)ptr.owner_id); } else if (OB_DATA_SUPPORT_ID(id_type)) { - base = ED_object_find_first_by_data_id(view_layer, ptr.owner_id); + base = ED_object_find_first_by_data_id(scene, view_layer, ptr.owner_id); } bool ok = false; @@ -1577,7 +1578,7 @@ static bool jump_to_target_button(bContext *C, bool poll) int found = 0; /* Jump to target only works with search properties currently, not search callbacks yet. * See ui_but_add_search. */ - if (coll_search->search_prop != NULL) { + if (coll_search->search_prop != nullptr) { found = RNA_property_collection_lookup_string( &coll_search->search_ptr, coll_search->search_prop, str_ptr, &target_ptr); } @@ -1601,7 +1602,7 @@ bool ui_jump_to_target_button_poll(bContext *C) return jump_to_target_button(C, true); } -static int jump_to_target_button_exec(bContext *C, wmOperator *UNUSED(op)) +static int jump_to_target_button_exec(bContext *C, wmOperator * /*op*/) { const bool success = jump_to_target_button(C, false); @@ -1632,7 +1633,7 @@ static void UI_OT_jump_to_target_button(wmOperatorType *ot) #ifdef WITH_PYTHON /* ------------------------------------------------------------------------- */ -/* EditSource Utility funcs and operator, +/* EditSource Utility functions and operator, * NOTE: this includes utility functions and button matching checks. */ struct uiEditSourceStore { @@ -1844,7 +1845,7 @@ static void UI_OT_editsource(wmOperatorType *ot) * \{ */ /** - * EditTranslation utility funcs and operator, + * EditTranslation utility functions and operator. * * \note this includes utility functions and button matching checks. * this only works in conjunction with a Python operator! @@ -1858,8 +1859,7 @@ static void edittranslation_find_po_file(const char *root, /* First, full lang code. */ BLI_snprintf(tstr, sizeof(tstr), "%s.po", uilng); - BLI_join_dirfile(path, maxlen, root, uilng); - BLI_path_append(path, maxlen, tstr); + BLI_path_join(path, maxlen, root, uilng, tstr); if (BLI_is_file(path)) { return; } @@ -1884,7 +1884,7 @@ static void edittranslation_find_po_file(const char *root, BLI_strncpy(tstr + szt, tc, sizeof(tstr) - szt); } - BLI_join_dirfile(path, maxlen, root, tstr); + BLI_path_join(path, maxlen, root, tstr); strcat(tstr, ".po"); BLI_path_append(path, maxlen, tstr); if (BLI_is_file(path)) { @@ -2030,7 +2030,7 @@ static void UI_OT_edittranslation_init(wmOperatorType *ot) /** \name Reload Translation Operator * \{ */ -static int reloadtranslation_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) +static int reloadtranslation_exec(bContext * /*C*/, wmOperator * /*op*/) { BLT_lang_init(); BLF_cache_clear(); @@ -2113,7 +2113,7 @@ static void UI_OT_button_execute(wmOperatorType *ot) /** \name Text Button Clear Operator * \{ */ -static int button_string_clear_exec(bContext *C, wmOperator *UNUSED(op)) +static int button_string_clear_exec(bContext *C, wmOperator * /*op*/) { uiBut *but = UI_context_active_but_get_respect_menu(C); @@ -2141,7 +2141,7 @@ static void UI_OT_button_string_clear(wmOperatorType *ot) /** \name Drop Color Operator * \{ */ -bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED(event)) +bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent * /*event*/) { /* should only return true for regions that include buttons, for now * return true always */ @@ -2162,7 +2162,7 @@ bool UI_drop_color_poll(struct bContext *C, wmDrag *drag, const wmEvent *UNUSED( return false; } -void UI_drop_color_copy(bContext *UNUSED(C), wmDrag *drag, wmDropBox *drop) +void UI_drop_color_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop) { uiDragColorHandle *drag_info = static_cast<uiDragColorHandle *>(drag->poin); @@ -2260,7 +2260,7 @@ static bool drop_name_poll(bContext *C) return true; } -static int drop_name_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +static int drop_name_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { uiBut *but = UI_but_active_drop_name_button(C); char *str = RNA_string_get_alloc(op->ptr, "string", nullptr, 0, nullptr); @@ -2320,7 +2320,7 @@ static bool ui_list_unhide_filter_options(uiList *list) return true; } -static int ui_list_start_filter_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int ui_list_start_filter_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) { ARegion *region = CTX_wm_region(C); uiList *list = UI_list_find_mouse_over(region, event); @@ -2366,7 +2366,7 @@ static bool ui_view_drop_poll(bContext *C) return hovered_item != nullptr; } -static int ui_view_drop_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int ui_view_drop_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) { if (event->custom != EVT_DATA_DRAGDROP) { return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; @@ -2416,7 +2416,7 @@ static bool ui_view_item_rename_poll(bContext *C) return active_item != nullptr && UI_view_item_can_rename(active_item); } -static int ui_view_item_rename_exec(bContext *C, wmOperator *UNUSED(op)) +static int ui_view_item_rename_exec(bContext *C, wmOperator * /*op*/) { ARegion *region = CTX_wm_region(C); uiViewItemHandle *active_item = UI_region_views_find_active_item(region); diff --git a/source/blender/editors/interface/interface_panel.cc b/source/blender/editors/interface/interface_panel.cc index 745a2201dc1..05b6ecf29d5 100644 --- a/source/blender/editors/interface/interface_panel.cc +++ b/source/blender/editors/interface/interface_panel.cc @@ -142,7 +142,7 @@ static bool panel_active_animation_changed(ListBase *lb, } /* Detect changes in panel expansions. */ - if ((bool)(panel->runtime_flag & PANEL_WAS_CLOSED) != UI_panel_is_closed(panel)) { + if (bool(panel->runtime_flag & PANEL_WAS_CLOSED) != UI_panel_is_closed(panel)) { *r_panel_animation = panel; return false; } @@ -1112,7 +1112,8 @@ static void panel_draw_aligned_widgets(const uiStyle *style, 0.7f, 0.0f, title_color, - false); + false, + UI_NO_ICON_OVERLAY_TEXT); GPU_blend(GPU_BLEND_NONE); } @@ -1140,7 +1141,8 @@ static void panel_draw_aligned_widgets(const uiStyle *style, 1.0f, 0.0f, title_color, - false); + false, + UI_NO_ICON_OVERLAY_TEXT); GPU_blend(GPU_BLEND_NONE); } @@ -1232,7 +1234,7 @@ void ui_draw_aligned_panel(const uiStyle *style, rect->xmin, rect->xmax, rect->ymax, - rect->ymax + (int)floor(PNL_HEADER / block->aspect + 0.001f), + rect->ymax + int(floor(PNL_HEADER / block->aspect + 0.001f)), }; if (show_background) { @@ -1343,7 +1345,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active) BLF_enable(fontid, BLF_ROTATION); BLF_rotation(fontid, M_PI_2); ui_fontscale(&fstyle_points, aspect); - BLF_size(fontid, fstyle_points * U.pixelsize, U.dpi); + BLF_size(fontid, fstyle_points * U.dpi_fac); /* Check the region type supports categories to avoid an assert * for showing 3D view panels in the properties space. */ @@ -1368,7 +1370,7 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active) } if (y_ofs > BLI_rcti_size_y(&v2d->mask)) { - scaletabs = (float)BLI_rcti_size_y(&v2d->mask) / (float)y_ofs; + scaletabs = float(BLI_rcti_size_y(&v2d->mask)) / float(y_ofs); LISTBASE_FOREACH (PanelCategoryDyn *, pc_dyn, ®ion->panels_category) { rcti *rct = &pc_dyn->rect; @@ -1705,12 +1707,12 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra } if (ps->new_offset_x != ps->panel->ofsx) { - const float x = interpf((float)ps->new_offset_x, (float)ps->panel->ofsx, factor); + const float x = interpf(float(ps->new_offset_x), float(ps->panel->ofsx), factor); ps->panel->ofsx = round_fl_to_int(x); changed = true; } if (ps->new_offset_y != ps->panel->ofsy) { - const float y = interpf((float)ps->new_offset_y, (float)ps->panel->ofsy, factor); + const float y = interpf(float(ps->new_offset_y), float(ps->panel->ofsy), factor); ps->panel->ofsy = round_fl_to_int(y); changed = true; } @@ -1804,7 +1806,7 @@ static void panels_layout_begin_clear_flags(ListBase *lb) } } -void UI_panels_begin(const bContext *UNUSED(C), ARegion *region) +void UI_panels_begin(const bContext * /*C*/, ARegion *region) { /* Set all panels as inactive, so that at the end we know which ones were used. Also * clear other flags so we know later that their values were set for the current redraw. */ @@ -1875,13 +1877,13 @@ static void ui_do_drag(const bContext *C, const wmEvent *event, Panel *panel) /* Keep the drag position in the region with a small pad to keep the panel visible. */ const int y = clamp_i(event->xy[1], region->winrct.ymin, region->winrct.ymax + DRAG_REGION_PAD); - float dy = (float)(y - data->starty); + float dy = float(y - data->starty); /* Adjust for region zoom. */ - dy *= BLI_rctf_size_y(®ion->v2d.cur) / (float)BLI_rcti_size_y(®ion->winrct); + dy *= BLI_rctf_size_y(®ion->v2d.cur) / float(BLI_rcti_size_y(®ion->winrct)); /* Add the movement of the view due to edge scrolling while dragging. */ - dy += ((float)region->v2d.cur.ymin - data->start_cur_ymin); + dy += (float(region->v2d.cur.ymin) - data->start_cur_ymin); panel->ofsy = data->startofsy + round_fl_to_int(dy); @@ -1902,16 +1904,16 @@ static uiPanelMouseState ui_panel_mouse_state_get(const uiBlock *block, const int mx, const int my) { - if (!IN_RANGE((float)mx, block->rect.xmin, block->rect.xmax)) { + if (!IN_RANGE(float(mx), block->rect.xmin, block->rect.xmax)) { return PANEL_MOUSE_OUTSIDE; } - if (IN_RANGE((float)my, block->rect.ymax, block->rect.ymax + PNL_HEADER)) { + if (IN_RANGE(float(my), block->rect.ymax, block->rect.ymax + PNL_HEADER)) { return PANEL_MOUSE_INSIDE_HEADER; } if (!UI_panel_is_closed(panel)) { - if (IN_RANGE((float)my, block->rect.ymin, block->rect.ymax + PNL_HEADER)) { + if (IN_RANGE(float(my), block->rect.ymin, block->rect.ymax + PNL_HEADER)) { return PANEL_MOUSE_INSIDE_CONTENT; } } @@ -1924,7 +1926,7 @@ struct uiPanelDragCollapseHandle { int xy_init[2]; }; -static void ui_panel_drag_collapse_handler_remove(bContext *UNUSED(C), void *userdata) +static void ui_panel_drag_collapse_handler_remove(bContext * /*C*/, void *userdata) { uiPanelDragCollapseHandle *dragcol_data = static_cast<uiPanelDragCollapseHandle *>(userdata); MEM_freeN(dragcol_data); @@ -1937,8 +1939,8 @@ static void ui_panel_drag_collapse(const bContext *C, ARegion *region = CTX_wm_region(C); LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { - float xy_a_block[2] = {(float)dragcol_data->xy_init[0], (float)dragcol_data->xy_init[1]}; - float xy_b_block[2] = {(float)xy_dst[0], (float)xy_dst[1]}; + float xy_a_block[2] = {float(dragcol_data->xy_init[0]), float(dragcol_data->xy_init[1])}; + float xy_b_block[2] = {float(xy_dst[0]), float(xy_dst[1])}; Panel *panel = block->panel; if (panel == nullptr || (panel->type && (panel->type->flag & PANEL_TYPE_NO_HEADER))) { @@ -2024,7 +2026,7 @@ static void ui_panel_drag_collapse_handler_add(const bContext *C, const bool was ui_panel_drag_collapse_handler, ui_panel_drag_collapse_handler_remove, dragcol_data, - 0); + eWM_EventHandlerFlag(0)); } /** @@ -2508,8 +2510,12 @@ static void panel_handle_data_ensure(const bContext *C, { if (panel->activedata == nullptr) { panel->activedata = MEM_callocN(sizeof(uiHandlePanelData), __func__); - WM_event_add_ui_handler( - C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, panel, 0); + WM_event_add_ui_handler(C, + &win->modalhandlers, + ui_handler_panel, + ui_handler_remove_panel, + panel, + eWM_EventHandlerFlag(0)); } uiHandlePanelData *data = static_cast<uiHandlePanelData *>(panel->activedata); diff --git a/source/blender/editors/interface/interface_query.cc b/source/blender/editors/interface/interface_query.cc index f084f3e06cb..7ff6acee945 100644 --- a/source/blender/editors/interface/interface_query.cc +++ b/source/blender/editors/interface/interface_query.cc @@ -84,7 +84,7 @@ bool ui_but_is_interactive_ex(const uiBut *but, const bool labeledit, const bool return false; } if ((but->type == UI_BTYPE_TEXT) && - (ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS)) && !labeledit) { + ELEM(but->emboss, UI_EMBOSS_NONE, UI_EMBOSS_NONE_OR_STATUS) && !labeledit) { return false; } if ((but->type == UI_BTYPE_LISTROW) && labeledit) { @@ -103,7 +103,7 @@ bool UI_but_is_utf8(const uiBut *but) { if (but->rnaprop) { const int subtype = RNA_property_subtype(but->rnaprop); - return !(ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING)); + return !ELEM(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME, PROP_BYTESTRING); } return !(but->flag & UI_BUT_NO_UTF8); } @@ -182,7 +182,7 @@ void ui_but_pie_dir(RadialDirection dir, float vec[2]) BLI_assert(dir != UI_RADIAL_NONE); - angle = DEG2RADF((float)ui_radial_dir_to_angle[dir]); + angle = DEG2RADF(float(ui_radial_dir_to_angle[dir])); vec[0] = cosf(angle); vec[1] = sinf(angle); } @@ -251,7 +251,7 @@ bool ui_but_contains_point_px_icon(const uiBut *but, ARegion *region, const wmEv /* use button size itself */ } else if (but->drawflag & UI_BUT_ICON_LEFT) { - rect.xmax = rect.xmin + (BLI_rcti_size_y(&rect)); + rect.xmax = rect.xmin + BLI_rcti_size_y(&rect); } else { const int delta = BLI_rcti_size_x(&rect) - BLI_rcti_size_y(&rect); @@ -424,7 +424,7 @@ uiBut *ui_list_find_from_row(const ARegion *region, const uiBut *row_but) return ui_but_find(region, ui_but_is_listbox_with_row, row_but); } -static bool ui_but_is_listrow(const uiBut *but, const void *UNUSED(customdata)) +static bool ui_but_is_listrow(const uiBut *but, const void * /*customdata*/) { return but->type == UI_BTYPE_LISTROW; } @@ -456,7 +456,7 @@ uiBut *ui_list_row_find_from_index(const ARegion *region, const int index, uiBut return ui_but_find(region, ui_but_is_listrow_at_index, &data); } -static bool ui_but_is_view_item_fn(const uiBut *but, const void *UNUSED(customdata)) +static bool ui_but_is_view_item_fn(const uiBut *but, const void * /*customdata*/) { return but->type == UI_BTYPE_VIEW_ITEM; } @@ -466,7 +466,7 @@ uiBut *ui_view_item_find_mouse_over(const ARegion *region, const int xy[2]) return ui_but_find_mouse_over_ex(region, xy, false, false, ui_but_is_view_item_fn, nullptr); } -static bool ui_but_is_active_view_item(const uiBut *but, const void *UNUSED(customdata)) +static bool ui_but_is_active_view_item(const uiBut *but, const void * /*customdata*/) { if (but->type != UI_BTYPE_VIEW_ITEM) { return false; diff --git a/source/blender/editors/interface/interface_region_color_picker.cc b/source/blender/editors/interface/interface_region_color_picker.cc index db1e5e653de..0b2c538331a 100644 --- a/source/blender/editors/interface/interface_region_color_picker.cc +++ b/source/blender/editors/interface/interface_region_color_picker.cc @@ -52,10 +52,10 @@ static void ui_color_picker_rgb_round(float rgb[3]) * all color space conversions would be expensive, but for the color picker * we can do the extra work. */ for (int i = 0; i < 3; i++) { - if (fabsf(rgb[i]) < 1e-6f) { + if (fabsf(rgb[i]) < 5e-5f) { rgb[i] = 0.0f; } - else if (fabsf(1.0f - rgb[i]) < 1e-6f) { + else if (fabsf(1.0f - rgb[i]) < 5e-5f) { rgb[i] = 1.0f; } } @@ -245,7 +245,7 @@ static void ui_update_color_picker_buts_rgb(uiBut *from_but, } } -static void ui_colorpicker_rgba_update_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_colorpicker_rgba_update_cb(bContext * /*C*/, void *bt1, void * /*arg*/) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -264,7 +264,7 @@ static void ui_colorpicker_rgba_update_cb(bContext *UNUSED(C), void *bt1, void * } } -static void ui_colorpicker_hsv_update_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_colorpicker_hsv_update_cb(bContext * /*C*/, void *bt1, void * /*arg*/) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -279,7 +279,7 @@ static void ui_colorpicker_hsv_update_cb(bContext *UNUSED(C), void *bt1, void *U } } -static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexcl) +static void ui_colorpicker_hex_rna_cb(bContext * /*C*/, void *bt1, void *hexcl) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -302,7 +302,7 @@ static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexc } } -static void ui_popup_close_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_popup_close_cb(bContext * /*C*/, void *bt1, void * /*arg*/) { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; @@ -336,7 +336,7 @@ static void ui_colorpicker_hide_reveal(uiBlock *block, ePickerType colormode) } } -static void ui_colorpicker_create_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) +static void ui_colorpicker_create_mode_cb(bContext * /*C*/, void *bt1, void * /*arg*/) { uiBut *bt = static_cast<uiBut *>(bt1); const short colormode = ui_but_value_get(bt); @@ -542,7 +542,7 @@ static void ui_block_colorpicker(uiBlock *block, UI_UNIT_Y, &colormode, 0.0, - (float)PICKER_TYPE_RGB, + float(PICKER_TYPE_RGB), 0, 0, ""); @@ -820,7 +820,7 @@ static void ui_block_colorpicker(uiBlock *block, ui_colorpicker_hide_reveal(block, (ePickerType)colormode); } -static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), +static int ui_colorpicker_small_wheel_cb(const bContext * /*C*/, uiBlock *block, const wmEvent *event) { diff --git a/source/blender/editors/interface/interface_region_hud.cc b/source/blender/editors/interface/interface_region_hud.cc index aca36686dea..9c13a776db0 100644 --- a/source/blender/editors/interface/interface_region_hud.cc +++ b/source/blender/editors/interface/interface_region_hud.cc @@ -87,7 +87,7 @@ static void hud_region_hide(ARegion *region) /** \name Redo Panel * \{ */ -static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt)) +static bool hud_panel_operator_redo_poll(const bContext *C, PanelType * /*pt*/) { ScrArea *area = CTX_wm_area(C); ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HUD); diff --git a/source/blender/editors/interface/interface_region_menu_pie.cc b/source/blender/editors/interface/interface_region_menu_pie.cc index becdfaf4e25..f443dd43a3a 100644 --- a/source/blender/editors/interface/interface_region_menu_pie.cc +++ b/source/blender/editors/interface/interface_region_menu_pie.cc @@ -49,7 +49,7 @@ struct uiPieMenu { int mx, my; }; -static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handle, void *arg_pie) +static uiBlock *ui_block_func_PIE(bContext * /*C*/, uiPopupBlockHandle *handle, void *arg_pie) { uiBlock *block; uiPieMenu *pie = static_cast<uiPieMenu *>(arg_pie); @@ -222,7 +222,7 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } - pie = UI_pie_menu_begin(C, IFACE_(mt->label), ICON_NONE, event); + pie = UI_pie_menu_begin(C, CTX_IFACE_(mt->translation_context, mt->label), ICON_NONE, event); layout = UI_pie_menu_layout(pie); UI_menutype_draw(C, mt, layout); diff --git a/source/blender/editors/interface/interface_region_menu_popup.cc b/source/blender/editors/interface/interface_region_menu_popup.cc index 0647e1a4a70..8fd6731d2ec 100644 --- a/source/blender/editors/interface/interface_region_menu_popup.cc +++ b/source/blender/editors/interface/interface_region_menu_popup.cc @@ -10,6 +10,7 @@ #include <cstdarg> #include <cstdlib> #include <cstring> +#include <functional> #include "MEM_guardedalloc.h" @@ -166,31 +167,80 @@ struct uiPopupMenu { uiBut *but; ARegion *butregion; + /* Menu hash is created from this, to keep a memory of recently opened menus. */ + const char *title; + int mx, my; bool popup, slideout; - uiMenuCreateFunc menu_func; - void *menu_arg; + std::function<void(bContext *C, uiLayout *layout)> menu_func; }; +/** + * \param title: Optional. If set, it will be used to store recently opened menus so they can be + * opened with the mouse over the last chosen entry again. + */ +static void ui_popup_menu_create_block(bContext *C, + uiPopupMenu *pup, + const char *title, + const char *block_name) +{ + const uiStyle *style = UI_style_get_dpi(); + + pup->block = UI_block_begin(C, nullptr, block_name, UI_EMBOSS_PULLDOWN); + if (!pup->but) { + pup->block->flag |= UI_BLOCK_NO_FLIP; + } + if (title && title[0]) { + pup->block->flag |= UI_BLOCK_POPUP_MEMORY; + pup->block->puphash = ui_popup_menu_hash(title); + } + pup->layout = UI_block_layout( + pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, UI_MENU_PADDING, style); + + /* NOTE: this intentionally differs from the menu & sub-menu default because many operators + * use popups like this to select one of their options - + * where having invoke doesn't make sense. + * When the menu was opened from a button, use invoke still for compatibility. This used to be + * the default and changing now could cause issues. */ + const wmOperatorCallContext opcontext = pup->but ? WM_OP_INVOKE_REGION_WIN : + WM_OP_EXEC_REGION_WIN; + + uiLayoutSetOperatorContext(pup->layout, opcontext); + + if (pup->but) { + if (pup->but->context) { + uiLayoutContextCopy(pup->layout, pup->but->context); + } + } +} + static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, void *arg_pup) { - uiBlock *block; uiPopupMenu *pup = static_cast<uiPopupMenu *>(arg_pup); - int minwidth, width, height; - char direction; - bool flip; - if (pup->menu_func) { - pup->block->handle = handle; - pup->menu_func(C, pup->layout, pup->menu_arg); - pup->block->handle = nullptr; + int minwidth = 0; + + if (!pup->layout) { + ui_popup_menu_create_block(C, pup, pup->title, __func__); + + if (pup->menu_func) { + pup->block->handle = handle; + pup->menu_func(C, pup->layout); + pup->block->handle = nullptr; + } + + if (uiLayoutGetUnitsX(pup->layout) != 0.0f) { + /* Use the minimum width from the layout if it's set. */ + minwidth = uiLayoutGetUnitsX(pup->layout) * UI_UNIT_X; + } + + pup->layout = nullptr; } /* Find block minimum width. */ - if (uiLayoutGetUnitsX(pup->layout) != 0.0f) { - /* Use the minimum width from the layout if it's set. */ - minwidth = uiLayoutGetUnitsX(pup->layout) * UI_UNIT_X; + if (minwidth) { + /* Skip. */ } else if (pup->but) { /* Minimum width to enforce. */ @@ -207,6 +257,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi } /* Find block direction. */ + char direction; if (pup->but) { if (pup->block->direction != 0) { /* allow overriding the direction from menu_func */ @@ -220,9 +271,9 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi direction = UI_DIR_DOWN; } - flip = (direction == UI_DIR_DOWN); + bool flip = (direction == UI_DIR_DOWN); - block = pup->block; + uiBlock *block = pup->block; /* in some cases we create the block before the region, * so we set it delayed here if necessary */ @@ -232,49 +283,56 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi block->direction = direction; + int width, height; UI_block_layout_resolve(block, &width, &height); - UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); + UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_NUMSELECT); if (pup->popup) { - int offset[2]; + int offset[2] = {0, 0}; uiBut *but_activate = nullptr; - UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT); + UI_block_flag_enable(block, UI_BLOCK_LOOP); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); UI_block_direction_set(block, direction); /* offset the mouse position, possibly based on earlier selection */ - uiBut *bt; - if ((block->flag & UI_BLOCK_POPUP_MEMORY) && (bt = ui_popup_menu_memory_get(block))) { - /* position mouse on last clicked item, at 0.8*width of the - * button, so it doesn't overlap the text too much, also note - * the offset is negative because we are inverse moving the - * block to be under the mouse */ - offset[0] = -(bt->rect.xmin + 0.8f * BLI_rctf_size_x(&bt->rect)); - offset[1] = -(bt->rect.ymin + 0.5f * UI_UNIT_Y); - - if (ui_but_is_editable(bt)) { - but_activate = bt; - } - } - else { - /* position mouse at 0.8*width of the button and below the tile - * on the first item */ - offset[0] = 0; - LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { - offset[0] = min_ii(offset[0], - -(but_iter->rect.xmin + 0.8f * BLI_rctf_size_x(&but_iter->rect))); + if (!handle->refresh) { + uiBut *bt; + if ((block->flag & UI_BLOCK_POPUP_MEMORY) && (bt = ui_popup_menu_memory_get(block))) { + /* position mouse on last clicked item, at 0.8*width of the + * button, so it doesn't overlap the text too much, also note + * the offset is negative because we are inverse moving the + * block to be under the mouse */ + offset[0] = -(bt->rect.xmin + 0.8f * BLI_rctf_size_x(&bt->rect)); + offset[1] = -(bt->rect.ymin + 0.5f * UI_UNIT_Y); + + if (ui_but_is_editable(bt)) { + but_activate = bt; + } } + else { + /* position mouse at 0.8*width of the button and below the tile + * on the first item */ + offset[0] = 0; + LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { + offset[0] = min_ii(offset[0], + -(but_iter->rect.xmin + 0.8f * BLI_rctf_size_x(&but_iter->rect))); + } - offset[1] = 2.1 * UI_UNIT_Y; + offset[1] = 2.1 * UI_UNIT_Y; - LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { - if (ui_but_is_editable(but_iter)) { - but_activate = but_iter; - break; + LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { + if (ui_but_is_editable(but_iter)) { + but_activate = but_iter; + break; + } } } + copy_v2_v2_int(handle->prev_bounds_offset, offset); + } + else { + copy_v2_v2_int(offset, handle->prev_bounds_offset); } /* in rare cases this is needed since moving the popup @@ -313,28 +371,35 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi return pup->block; } -uiPopupBlockHandle *ui_popup_menu_create( - bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg) +static void ui_block_free_func_POPUP(void *arg_pup) +{ + uiPopupMenu *pup = static_cast<uiPopupMenu *>(arg_pup); + MEM_delete(pup); +} + +static uiPopupBlockHandle *ui_popup_menu_create( + bContext *C, + ARegion *butregion, + uiBut *but, + const char *title, + std::function<void(bContext *, uiLayout *)> menu_func) { wmWindow *window = CTX_wm_window(C); - const uiStyle *style = UI_style_get_dpi(); - uiPopupBlockHandle *handle; - uiPopupMenu *pup = MEM_cnew<uiPopupMenu>(__func__); - pup->block = UI_block_begin(C, nullptr, __func__, UI_EMBOSS_PULLDOWN); - pup->block->flag |= UI_BLOCK_NUMSELECT; /* default menus to numselect */ - pup->layout = UI_block_layout( - pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, UI_MENU_PADDING, style); - pup->slideout = but ? ui_block_is_menu(but->block) : false; - pup->but = but; - uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN); + uiPopupMenu *pup = MEM_new<uiPopupMenu>(__func__); + pup->title = title; + /* menu is created from a callback */ + pup->menu_func = menu_func; + if (but) { + pup->slideout = ui_block_is_menu(but->block); + pup->but = but; + } if (!but) { /* no button to start from, means we are a popup */ pup->mx = window->eventstate->xy[0]; pup->my = window->eventstate->xy[1]; pup->popup = true; - pup->block->flag |= UI_BLOCK_NO_FLIP; } /* some enums reversing is strange, currently we have no good way to * reverse some enum's but not others, so reverse all so the first menu @@ -348,16 +413,10 @@ uiPopupBlockHandle *ui_popup_menu_create( pup->block->flag |= UI_BLOCK_NO_FLIP; } #endif - if (but->context) { - uiLayoutContextCopy(pup->layout, but->context); - } } - /* menu is created from a callback */ - pup->menu_func = menu_func; - pup->menu_arg = arg; - - handle = ui_popup_block_create(C, butregion, but, nullptr, ui_block_func_POPUP, pup, nullptr); + uiPopupBlockHandle *handle = ui_popup_block_create( + C, butregion, but, nullptr, ui_block_func_POPUP, pup, ui_block_free_func_POPUP); if (!but) { handle->popup = true; @@ -366,69 +425,75 @@ uiPopupBlockHandle *ui_popup_menu_create( WM_event_add_mousemove(window); } - MEM_freeN(pup); - return handle; } +uiPopupBlockHandle *ui_popup_menu_create( + bContext *C, ARegion *butregion, uiBut *but, uiMenuCreateFunc menu_func, void *arg) +{ + return ui_popup_menu_create( + C, butregion, but, nullptr, [menu_func, arg](bContext *C, uiLayout *layout) { + menu_func(C, layout, arg); + }); +} + /** \} */ /* -------------------------------------------------------------------- */ /** \name Popup Menu API with begin & end * \{ */ +static void create_title_button(uiLayout *layout, const char *title, int icon) +{ + uiBlock *block = uiLayoutGetBlock(layout); + char titlestr[256]; + + if (icon) { + BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); + uiDefIconTextBut(block, + UI_BTYPE_LABEL, + 0, + icon, + titlestr, + 0, + 0, + 200, + UI_UNIT_Y, + nullptr, + 0.0, + 0.0, + 0, + 0, + ""); + } + else { + uiBut *but = uiDefBut( + block, UI_BTYPE_LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, nullptr, 0.0, 0.0, 0, 0, ""); + but->drawflag = UI_BUT_TEXT_LEFT; + } + + uiItemS(layout); +} + +/* Used to directly create a popup menu that is not refreshed on redraw. */ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, const char *title, const char *block_name, int icon) { - const uiStyle *style = UI_style_get_dpi(); - uiPopupMenu *pup = MEM_cnew<uiPopupMenu>(__func__); - uiBut *but; + uiPopupMenu *pup = MEM_new<uiPopupMenu>(__func__); - pup->block = UI_block_begin(C, nullptr, block_name, UI_EMBOSS_PULLDOWN); - pup->block->flag |= UI_BLOCK_POPUP_MEMORY | UI_BLOCK_IS_FLIP; - pup->block->puphash = ui_popup_menu_hash(title); - pup->layout = UI_block_layout( - pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_MENU, 0, 0, 200, 0, UI_MENU_PADDING, style); + pup->title = title; - /* NOTE: this intentionally differs from the menu & sub-menu default because many operators - * use popups like this to select one of their options - - * where having invoke doesn't make sense */ - uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); + ui_popup_menu_create_block(C, pup, title, block_name); + /* Further buttons will be laid out top to bottom by default. */ + pup->block->flag |= UI_BLOCK_IS_FLIP; /* create in advance so we can let buttons point to retval already */ pup->block->handle = MEM_cnew<uiPopupBlockHandle>(__func__); - /* create title button */ if (title[0]) { - char titlestr[256]; - - if (icon) { - BLI_snprintf(titlestr, sizeof(titlestr), " %s", title); - uiDefIconTextBut(pup->block, - UI_BTYPE_LABEL, - 0, - icon, - titlestr, - 0, - 0, - 200, - UI_UNIT_Y, - nullptr, - 0.0, - 0.0, - 0, - 0, - ""); - } - else { - but = uiDefBut( - pup->block, UI_BTYPE_LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, nullptr, 0.0, 0.0, 0, 0, ""); - but->drawflag = UI_BUT_TEXT_LEFT; - } - - uiItemS(pup->layout); + create_title_button(pup->layout, title, icon); } return pup; @@ -448,26 +513,26 @@ void UI_popup_menu_but_set(uiPopupMenu *pup, struct ARegion *butregion, uiBut *b void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) { wmWindow *window = CTX_wm_window(C); - uiPopupBlockHandle *menu; - uiBut *but = nullptr; - ARegion *butregion = nullptr; pup->popup = true; pup->mx = window->eventstate->xy[0]; pup->my = window->eventstate->xy[1]; + uiBut *but = nullptr; + ARegion *butregion = nullptr; if (pup->but) { but = pup->but; butregion = pup->butregion; } - menu = ui_popup_block_create(C, butregion, but, nullptr, ui_block_func_POPUP, pup, nullptr); + uiPopupBlockHandle *menu = ui_popup_block_create( + C, butregion, but, nullptr, ui_block_func_POPUP, pup, nullptr); menu->popup = true; UI_popup_handlers_add(C, &window->modalhandlers, menu, 0); WM_event_add_mousemove(window); - MEM_freeN(pup); + MEM_delete(pup); } bool UI_popup_menu_end_or_cancel(bContext *C, uiPopupMenu *pup) @@ -479,7 +544,7 @@ bool UI_popup_menu_end_or_cancel(bContext *C, uiPopupMenu *pup) UI_block_layout_resolve(pup->block, nullptr, nullptr); MEM_freeN(pup->block->handle); UI_block_free(C, pup->block); - MEM_freeN(pup); + MEM_delete(pup); return false; } @@ -543,10 +608,24 @@ void UI_popup_menu_reports(bContext *C, ReportList *reports) } } +static void ui_popup_menu_create_from_menutype(bContext *C, + MenuType *mt, + const char *title, + const int icon) +{ + uiPopupBlockHandle *handle = ui_popup_menu_create( + C, nullptr, nullptr, title, [mt, title, icon](bContext *C, uiLayout *layout) -> void { + if (title && title[0]) { + create_title_button(layout, title, icon); + } + ui_item_menutype_func(C, layout, mt); + }); + + handle->can_refresh = true; +} + int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) { - uiPopupMenu *pup; - uiLayout *layout; MenuType *mt = WM_menutype_find(idname, true); if (mt == nullptr) { @@ -558,13 +637,21 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) /* cancel but allow event to pass through, just like operators do */ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } + /* For now always recreate menus on redraw that were invoked with this function. Maybe we want to + * make that optional somehow. */ + const bool allow_refresh = true; - pup = UI_popup_menu_begin(C, IFACE_(mt->label), ICON_NONE); - layout = UI_popup_menu_layout(pup); - - UI_menutype_draw(C, mt, layout); - - UI_popup_menu_end(C, pup); + const char *title = CTX_IFACE_(mt->translation_context, mt->label); + if (allow_refresh) { + ui_popup_menu_create_from_menutype(C, mt, title, ICON_NONE); + } + else { + /* If no refresh is needed, create the block directly. */ + uiPopupMenu *pup = UI_popup_menu_begin(C, title, ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); + UI_menutype_draw(C, mt, layout); + UI_popup_menu_end(C, pup); + } return OPERATOR_INTERFACE; } @@ -579,9 +666,9 @@ void UI_popup_block_invoke_ex( bContext *C, uiBlockCreateFunc func, void *arg, uiFreeArgFunc arg_free, bool can_refresh) { wmWindow *window = CTX_wm_window(C); - uiPopupBlockHandle *handle; - handle = ui_popup_block_create(C, nullptr, nullptr, func, nullptr, arg, arg_free); + uiPopupBlockHandle *handle = ui_popup_block_create( + C, nullptr, nullptr, func, nullptr, arg, arg_free); handle->popup = true; /* It can be useful to disable refresh (even though it will work) @@ -607,9 +694,9 @@ void UI_popup_block_ex(bContext *C, wmOperator *op) { wmWindow *window = CTX_wm_window(C); - uiPopupBlockHandle *handle; - handle = ui_popup_block_create(C, nullptr, nullptr, func, nullptr, arg, nullptr); + uiPopupBlockHandle *handle = ui_popup_block_create( + C, nullptr, nullptr, func, nullptr, arg, nullptr); handle->popup = true; handle->retvalue = 1; handle->can_refresh = true; diff --git a/source/blender/editors/interface/interface_region_popover.cc b/source/blender/editors/interface/interface_region_popover.cc index 17c8d890755..431571c1376 100644 --- a/source/blender/editors/interface/interface_region_popover.cc +++ b/source/blender/editors/interface/interface_region_popover.cc @@ -146,8 +146,8 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v ui_block_to_window_fl(handle->ctx_region, pup->but->block, ¢er[0], ¢er[1]); /* These variables aren't used for popovers, * we could add new variables if there is a conflict. */ - block->bounds_offset[0] = (int)center[0]; - block->bounds_offset[1] = (int)center[1]; + block->bounds_offset[0] = int(center[0]); + block->bounds_offset[1] = int(center[1]); copy_v2_v2_int(handle->prev_bounds_offset, block->bounds_offset); } else { @@ -245,7 +245,7 @@ uiPopupBlockHandle *ui_popover_panel_create( /* Scale width by changes to Text Style point size. */ const int text_points_max = MAX2(style->widget.points, style->widgetlabel.points); pup->ui_size_x = ui_units_x * U.widget_unit * - (text_points_max / (float)UI_DEFAULT_TEXT_POINTS); + (text_points_max / float(UI_DEFAULT_TEXT_POINTS)); } pup->menu_func = menu_func; @@ -355,7 +355,7 @@ uiPopover *UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_but return pup; } -static void popover_keymap_fn(wmKeyMap *UNUSED(keymap), wmKeyMapItem *UNUSED(kmi), void *user_data) +static void popover_keymap_fn(wmKeyMap * /*keymap*/, wmKeyMapItem * /*kmi*/, void *user_data) { uiPopover *pup = static_cast<uiPopover *>(user_data); pup->block->handle->menuretval = UI_RETURN_OK; diff --git a/source/blender/editors/interface/interface_region_popup.cc b/source/blender/editors/interface/interface_region_popup.cc index daa46b150a3..e574cb30b23 100644 --- a/source/blender/editors/interface/interface_region_popup.cc +++ b/source/blender/editors/interface/interface_region_popup.cc @@ -69,7 +69,6 @@ static void ui_popup_block_position(wmWindow *window, /* Compute button position in window coordinates using the source * button region/block, to position the popup attached to it. */ rctf butrct; - if (!handle->refresh) { ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect); @@ -165,10 +164,10 @@ static void ui_popup_block_position(wmWindow *window, dir1 &= (UI_DIR_UP | UI_DIR_DOWN); } - if ((dir2 == 0) && (ELEM(dir1, UI_DIR_LEFT, UI_DIR_RIGHT))) { + if ((dir2 == 0) && ELEM(dir1, UI_DIR_LEFT, UI_DIR_RIGHT)) { dir2 = UI_DIR_DOWN; } - if ((dir2 == 0) && (ELEM(dir1, UI_DIR_UP, UI_DIR_DOWN))) { + if ((dir2 == 0) && ELEM(dir1, UI_DIR_UP, UI_DIR_DOWN)) { dir2 = UI_DIR_LEFT; } @@ -417,14 +416,13 @@ static void ui_popup_block_clip(wmWindow *window, uiBlock *block) { const float xmin_orig = block->rect.xmin; const int margin = UI_SCREEN_MARGIN; - int winx, winy; if (block->flag & UI_BLOCK_NO_WIN_CLIP) { return; } - winx = WM_window_pixels_x(window); - winy = WM_window_pixels_y(window); + const int winx = WM_window_pixels_x(window); + const int winy = WM_window_pixels_y(window); /* shift to left if outside of view */ if (block->rect.xmax > winx - margin) { @@ -549,7 +547,6 @@ uiBlock *ui_popup_block_refresh(bContext *C, void *arg = handle->popup_create_vars.arg; uiBlock *block_old = static_cast<uiBlock *>(region->uiblocks.first); - uiBlock *block; handle->refresh = (block_old != nullptr); @@ -561,6 +558,7 @@ uiBlock *ui_popup_block_refresh(bContext *C, #endif /* create ui block */ + uiBlock *block; if (create_func) { block = create_func(C, region, arg); } @@ -618,16 +616,14 @@ uiBlock *ui_popup_block_refresh(bContext *C, if (block->flag & UI_BLOCK_RADIAL) { const int win_width = UI_SCREEN_MARGIN; - int winx, winy; - - int x_offset = 0, y_offset = 0; - winx = WM_window_pixels_x(window); - winy = WM_window_pixels_y(window); + const int winx = WM_window_pixels_x(window); + const int winy = WM_window_pixels_y(window); copy_v2_v2(block->pie_data.pie_center_init, block->pie_data.pie_center_spawned); /* only try translation if area is large enough */ + int x_offset = 0; if (BLI_rctf_size_x(&block->rect) < winx - (2.0f * win_width)) { if (block->rect.xmin < win_width) { x_offset += win_width - block->rect.xmin; @@ -637,6 +633,7 @@ uiBlock *ui_popup_block_refresh(bContext *C, } } + int y_offset = 0; if (BLI_rctf_size_y(&block->rect) < winy - (2.0f * win_width)) { if (block->rect.ymin < win_width) { y_offset += win_width - block->rect.ymin; @@ -756,9 +753,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, { wmWindow *window = CTX_wm_window(C); uiBut *activebut = UI_context_active_but_get(C); - static ARegionType type; - ARegion *region; - uiBlock *block; /* disable tooltips from buttons below */ if (activebut) { @@ -787,9 +781,10 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, handle->can_refresh = false; /* create area region */ - region = ui_region_temp_add(CTX_wm_screen(C)); + ARegion *region = ui_region_temp_add(CTX_wm_screen(C)); handle->region = region; + static ARegionType type; memset(&type, 0, sizeof(ARegionType)); type.draw = ui_block_region_draw; type.layout = ui_block_region_refresh; @@ -798,7 +793,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, UI_region_handlers_add(®ion->handlers); - block = ui_popup_block_refresh(C, handle, butregion, but); + uiBlock *block = ui_popup_block_refresh(C, handle, butregion, but); handle = block->handle; /* keep centered on window resizing */ diff --git a/source/blender/editors/interface/interface_region_search.cc b/source/blender/editors/interface/interface_region_search.cc index 6bb47666afd..8def878c6af 100644 --- a/source/blender/editors/interface/interface_region_search.cc +++ b/source/blender/editors/interface/interface_region_search.cc @@ -10,6 +10,7 @@ #include <cstdarg> #include <cstdlib> #include <cstring> +#include <iostream> #include "DNA_ID.h" #include "MEM_guardedalloc.h" @@ -43,7 +44,7 @@ #include "interface_intern.h" #include "interface_regions_intern.hh" -#define MENU_BORDER (int)(0.3f * U.widget_unit) +#define MENU_BORDER int(0.3f * U.widget_unit) /* -------------------------------------------------------------------- */ /** \name Search Box Creation @@ -86,6 +87,10 @@ struct uiSearchboxData { * Used so we can show leading text to menu items less prominently (not related to 'use_sep'). */ const char *sep_string; + + /* Owned by uiButSearch */ + void *search_arg; + uiButSearchListenFn search_listener; }; #define SEARCH_ITEMS 10 @@ -302,8 +307,8 @@ bool ui_searchbox_apply(uiBut *but, ARegion *region) static struct ARegion *wm_searchbox_tooltip_init(struct bContext *C, struct ARegion *region, - int *UNUSED(r_pass), - double *UNUSED(pass_delay), + int * /*r_pass*/, + double * /*pass_delay*/, bool *r_exit_on_event) { *r_exit_on_event = true; @@ -689,6 +694,14 @@ static void ui_searchbox_region_free_fn(ARegion *region) region->regiondata = nullptr; } +static void ui_searchbox_region_listen_fn(const wmRegionListenerParams *params) +{ + uiSearchboxData *data = static_cast<uiSearchboxData *>(params->region->regiondata); + if (data->search_listener) { + data->search_listener(params, data->search_arg); + } +} + static ARegion *ui_searchbox_create_generic_ex(bContext *C, ARegion *butregion, uiButSearch *search_but, @@ -707,11 +720,14 @@ static ARegion *ui_searchbox_create_generic_ex(bContext *C, memset(&type, 0, sizeof(ARegionType)); type.draw = ui_searchbox_region_draw_fn; type.free = ui_searchbox_region_free_fn; + type.listener = ui_searchbox_region_listen_fn; type.regionid = RGN_TYPE_TEMPORARY; region->type = &type; /* Create search-box data. */ uiSearchboxData *data = MEM_cnew<uiSearchboxData>(__func__); + data->search_arg = search_but->arg; + data->search_listener = search_but->listen_fn; /* Set font, get the bounding-box. */ data->fstyle = style->widget; /* copy struct */ @@ -887,7 +903,7 @@ static void str_tolower_titlecaps_ascii(char *str, const size_t len) } } -static void ui_searchbox_region_draw_cb__operator(const bContext *UNUSED(C), ARegion *region) +static void ui_searchbox_region_draw_cb__operator(const bContext * /*C*/, ARegion *region) { uiSearchboxData *data = static_cast<uiSearchboxData *>(region->regiondata); @@ -981,7 +997,7 @@ void ui_searchbox_free(bContext *C, ARegion *region) ui_region_temp_remove(C, CTX_wm_screen(C), region); } -static void ui_searchbox_region_draw_cb__menu(const bContext *UNUSED(C), ARegion *UNUSED(region)) +static void ui_searchbox_region_draw_cb__menu(const bContext * /*C*/, ARegion * /*region*/) { /* Currently unused. */ } diff --git a/source/blender/editors/interface/interface_region_tooltip.cc b/source/blender/editors/interface/interface_region_tooltip.cc index a6e37d3f36f..2a06267d90b 100644 --- a/source/blender/editors/interface/interface_region_tooltip.cc +++ b/source/blender/editors/interface/interface_region_tooltip.cc @@ -56,7 +56,7 @@ #include "interface_regions_intern.hh" #define UI_TIP_PAD_FAC 1.3f -#define UI_TIP_PADDING (int)(UI_TIP_PAD_FAC * UI_UNIT_Y) +#define UI_TIP_PADDING int(UI_TIP_PAD_FAC * UI_UNIT_Y) #define UI_TIP_MAXWIDTH 600 #define UI_TIP_STR_MAX 1024 @@ -109,8 +109,7 @@ struct uiTooltipData { #define UI_TIP_LC_MAX 6 -BLI_STATIC_ASSERT(UI_TIP_LC_MAX == static_cast<int>(uiTooltipFormat::ColorID::Alert) + 1, - "invalid lc-max"); +BLI_STATIC_ASSERT(UI_TIP_LC_MAX == int(uiTooltipFormat::ColorID::Alert) + 1, "invalid lc-max"); BLI_STATIC_ASSERT(sizeof(uiTooltipFormat) <= sizeof(int), "oversize"); static uiTooltipField *text_field_add_only(uiTooltipData *data) @@ -158,7 +157,7 @@ static void rgb_tint(float col[3], float h, float h_strength, float v, float v_s hsv_to_rgb_v(col_hsv_to, col); } -static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region) +static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region) { const float pad_px = UI_TIP_PADDING; uiTooltipData *data = static_cast<uiTooltipData *>(region->regiondata); @@ -168,12 +167,12 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region uchar drawcol[4] = {0, 0, 0, 255}; /* to store color in while drawing (alpha is always 255) */ /* The color from the theme. */ - float *main_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Main)]; - float *value_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Value)]; - float *active_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Active)]; - float *normal_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Normal)]; - float *python_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Python)]; - float *alert_color = tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Alert)]; + float *main_color = tip_colors[int(uiTooltipFormat::ColorID::Main)]; + float *value_color = tip_colors[int(uiTooltipFormat::ColorID::Value)]; + float *active_color = tip_colors[int(uiTooltipFormat::ColorID::Active)]; + float *normal_color = tip_colors[int(uiTooltipFormat::ColorID::Normal)]; + float *python_color = tip_colors[int(uiTooltipFormat::ColorID::Python)]; + float *alert_color = tip_colors[int(uiTooltipFormat::ColorID::Alert)]; float background_color[3]; @@ -224,7 +223,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region fs_params.word_wrap = true; /* Draw header and active data (is done here to be able to change color). */ - rgb_float_to_uchar(drawcol, tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Main)]); + rgb_float_to_uchar(drawcol, tip_colors[int(uiTooltipFormat::ColorID::Main)]); UI_fontstyle_set(&data->fstyle); UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); @@ -235,8 +234,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.xmin += xofs; bbox.ymax -= yofs; - rgb_float_to_uchar(drawcol, - tip_colors[static_cast<int>(uiTooltipFormat::ColorID::Active)]); + rgb_float_to_uchar(drawcol, tip_colors[int(uiTooltipFormat::ColorID::Active)]); UI_fontstyle_draw( &data->fstyle, &bbox, field->text_suffix, UI_TIP_STR_MAX, drawcol, &fs_params); @@ -254,8 +252,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region UI_fontstyle_set(&fstyle_mono); /* XXX: needed because we don't have mono in 'U.uifonts'. */ - BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); - rgb_float_to_uchar(drawcol, tip_colors[static_cast<int>(field->format.color_id)]); + BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.dpi_fac); + rgb_float_to_uchar(drawcol, tip_colors[int(field->format.color_id)]); UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } else { @@ -265,7 +263,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region fs_params.word_wrap = true; /* Draw remaining data. */ - rgb_float_to_uchar(drawcol, tip_colors[static_cast<int>(field->format.color_id)]); + rgb_float_to_uchar(drawcol, tip_colors[int(field->format.color_id)]); UI_fontstyle_set(&data->fstyle); UI_fontstyle_draw(&data->fstyle, &bbox, field->text, UI_TIP_STR_MAX, drawcol, &fs_params); } @@ -1133,7 +1131,7 @@ static ARegion *ui_tooltip_create_with_data(bContext *C, int font_id; if (field->format.style == uiTooltipFormat::Style::Mono) { - BLF_size(blf_mono_font, data->fstyle.points * U.pixelsize, U.dpi); + BLF_size(blf_mono_font, data->fstyle.points * U.dpi_fac); font_id = blf_mono_font; } else { @@ -1398,8 +1396,7 @@ ARegion *UI_tooltip_create_from_gizmo(bContext *C, wmGizmo *gz) { wmWindow *win = CTX_wm_window(C); const float aspect = 1.0f; - float init_position[2] = {static_cast<float>(win->eventstate->xy[0]), - static_cast<float>(win->eventstate->xy[1])}; + float init_position[2] = {float(win->eventstate->xy[0]), float(win->eventstate->xy[1])}; uiTooltipData *data = ui_tooltip_data_from_gizmo(C, gz); if (data == nullptr) { diff --git a/source/blender/editors/interface/interface_regions.cc b/source/blender/editors/interface/interface_regions.cc index 1770805cf59..63c4a6f9c42 100644 --- a/source/blender/editors/interface/interface_regions.cc +++ b/source/blender/editors/interface/interface_regions.cc @@ -45,6 +45,6 @@ void ui_region_temp_remove(bContext *C, bScreen *screen, ARegion *region) } ED_region_exit(C, region); - BKE_area_region_free(nullptr, region); /* nullptr: no spacetype */ + BKE_area_region_free(nullptr, region); /* nullptr: no space-type. */ BLI_freelinkN(&screen->regionbase, region); } diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc index 904765f6dc4..9493f40548d 100644 --- a/source/blender/editors/interface/interface_style.cc +++ b/source/blender/editors/interface/interface_style.cc @@ -319,20 +319,20 @@ const uiStyle *UI_style_get_dpi(void) _style = *style; - _style.paneltitle.shadx = (short)(UI_DPI_FAC * _style.paneltitle.shadx); - _style.paneltitle.shady = (short)(UI_DPI_FAC * _style.paneltitle.shady); - _style.grouplabel.shadx = (short)(UI_DPI_FAC * _style.grouplabel.shadx); - _style.grouplabel.shady = (short)(UI_DPI_FAC * _style.grouplabel.shady); - _style.widgetlabel.shadx = (short)(UI_DPI_FAC * _style.widgetlabel.shadx); - _style.widgetlabel.shady = (short)(UI_DPI_FAC * _style.widgetlabel.shady); - - _style.columnspace = (short)(UI_DPI_FAC * _style.columnspace); - _style.templatespace = (short)(UI_DPI_FAC * _style.templatespace); - _style.boxspace = (short)(UI_DPI_FAC * _style.boxspace); - _style.buttonspacex = (short)(UI_DPI_FAC * _style.buttonspacex); - _style.buttonspacey = (short)(UI_DPI_FAC * _style.buttonspacey); - _style.panelspace = (short)(UI_DPI_FAC * _style.panelspace); - _style.panelouter = (short)(UI_DPI_FAC * _style.panelouter); + _style.paneltitle.shadx = short(UI_DPI_FAC * _style.paneltitle.shadx); + _style.paneltitle.shady = short(UI_DPI_FAC * _style.paneltitle.shady); + _style.grouplabel.shadx = short(UI_DPI_FAC * _style.grouplabel.shadx); + _style.grouplabel.shady = short(UI_DPI_FAC * _style.grouplabel.shady); + _style.widgetlabel.shadx = short(UI_DPI_FAC * _style.widgetlabel.shadx); + _style.widgetlabel.shady = short(UI_DPI_FAC * _style.widgetlabel.shady); + + _style.columnspace = short(UI_DPI_FAC * _style.columnspace); + _style.templatespace = short(UI_DPI_FAC * _style.templatespace); + _style.boxspace = short(UI_DPI_FAC * _style.boxspace); + _style.buttonspacex = short(UI_DPI_FAC * _style.buttonspacex); + _style.buttonspacey = short(UI_DPI_FAC * _style.buttonspacey); + _style.panelspace = short(UI_DPI_FAC * _style.panelspace); + _style.panelouter = short(UI_DPI_FAC * _style.panelouter); return &_style; } @@ -340,7 +340,7 @@ const uiStyle *UI_style_get_dpi(void) int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) { UI_fontstyle_set(fs); - return (int)BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + return int(BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX)); } int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs, @@ -359,7 +359,7 @@ int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs, if (aspect != 1.0f) { /* While in most cases rounding up isn't important, it can make a difference * with small fonts (3px or less), zooming out in the node-editor for e.g. */ - width = (int)ceilf(width * aspect); + width = int(ceilf(width * aspect)); } return width; } @@ -496,5 +496,5 @@ void UI_fontstyle_set(const uiFontStyle *fs) { uiFont *font = uifont_to_blfont(fs->uifont_id); - BLF_size(font->blf_id, fs->points * U.pixelsize, U.dpi); + BLF_size(font->blf_id, fs->points * U.dpi_fac); } diff --git a/source/blender/editors/interface/interface_template_asset_view.cc b/source/blender/editors/interface/interface_template_asset_view.cc index d3ed462b85d..2673c5aa168 100644 --- a/source/blender/editors/interface/interface_template_asset_view.cc +++ b/source/blender/editors/interface/interface_template_asset_view.cc @@ -58,7 +58,6 @@ static void asset_view_item_but_drag_set(uiBut *but, but, asset_handle, BLI_strdup(blend_path), - ED_asset_handle_get_metadata(asset_handle), FILE_ASSET_IMPORT_APPEND, ED_assetlist_asset_preview_icon_id_request(&list_data->asset_library_ref, asset_handle), imbuf, @@ -67,15 +66,15 @@ static void asset_view_item_but_drag_set(uiBut *but, } static void asset_view_draw_item(uiList *ui_list, - const bContext *UNUSED(C), + const bContext * /*C*/, uiLayout *layout, - PointerRNA *UNUSED(dataptr), + PointerRNA * /*dataptr*/, PointerRNA *itemptr, - int UNUSED(icon), - PointerRNA *UNUSED(active_dataptr), - const char *UNUSED(active_propname), - int UNUSED(index), - int UNUSED(flt_flag)) + int /*icon*/, + PointerRNA * /*active_dataptr*/, + const char * /*active_propname*/, + int /*index*/, + int /*flt_flag*/) { AssetViewListData *list_data = (AssetViewListData *)ui_list->dyn_data->customdata; diff --git a/source/blender/editors/interface/interface_template_list.cc b/source/blender/editors/interface/interface_template_list.cc index f0c91588f98..2b581f187a6 100644 --- a/source/blender/editors/interface/interface_template_list.cc +++ b/source/blender/editors/interface/interface_template_list.cc @@ -83,15 +83,15 @@ struct TemplateListVisualInfo { }; static void uilist_draw_item_default(struct uiList *ui_list, - const struct bContext *UNUSED(C), + const struct bContext * /*C*/, struct uiLayout *layout, - struct PointerRNA *UNUSED(dataptr), + struct PointerRNA * /*dataptr*/, struct PointerRNA *itemptr, int icon, - struct PointerRNA *UNUSED(active_dataptr), - const char *UNUSED(active_propname), - int UNUSED(index), - int UNUSED(flt_flag)) + struct PointerRNA * /*active_dataptr*/, + const char * /*active_propname*/, + int /*index*/, + int /*flt_flag*/) { PropertyRNA *nameprop = RNA_struct_name_property(itemptr->type); @@ -114,7 +114,7 @@ static void uilist_draw_item_default(struct uiList *ui_list, } static void uilist_draw_filter_default(struct uiList *ui_list, - const struct bContext *UNUSED(C), + const struct bContext * /*C*/, struct uiLayout *layout) { PointerRNA listptr; @@ -160,7 +160,7 @@ static int cmpstringp(const void *p1, const void *p2) } static void uilist_filter_items_default(struct uiList *ui_list, - const struct bContext *UNUSED(C), + const struct bContext * /*C*/, struct PointerRNA *dataptr, const char *propname) { @@ -519,8 +519,8 @@ static void uilist_prepare(uiList *ui_list, int activei_row; if (columns > 1) { - dyn_data->height = (int)ceil((double)items->tot_items / (double)columns); - activei_row = (int)floor((double)items->active_item_idx / (double)columns); + dyn_data->height = int(ceil(double(items->tot_items) / double(columns))); + activei_row = int(floor(double(items->active_item_idx) / double(columns))); } else { dyn_data->height = items->tot_items; @@ -561,14 +561,14 @@ static void uilist_prepare(uiList *ui_list, items->tot_items); } -static void uilist_resize_update_cb(bContext *C, void *arg1, void *UNUSED(arg2)) +static void uilist_resize_update_cb(bContext *C, void *arg1, void * /*arg2*/) { uiList *ui_list = static_cast<uiList *>(arg1); uiListDyn *dyn_data = ui_list->dyn_data; /* This way we get diff in number of additional items to show (positive) or hide (negative). */ - const int diff = round_fl_to_int((float)(dyn_data->resize - dyn_data->resize_prev) / - (float)UI_UNIT_Y); + const int diff = round_fl_to_int(float(dyn_data->resize - dyn_data->resize_prev) / + float(UI_UNIT_Y)); if (diff != 0) { ui_list->list_grip += diff; @@ -592,7 +592,7 @@ static void *uilist_item_use_dynamic_tooltip(PointerRNA *itemptr, const char *pr return nullptr; } -static char *uilist_item_tooltip_func(bContext *UNUSED(C), void *argN, const char *tip) +static char *uilist_item_tooltip_func(bContext * /*C*/, void *argN, const char *tip) { char *dyn_tooltip = static_cast<char *>(argN); return BLI_sprintfN("%s - %s", tip, dyn_tooltip); @@ -767,7 +767,7 @@ static void ui_template_list_layout_draw(const bContext *C, uiItemL(col, "", ICON_NONE); } - /* add scrollbar */ + /* Add scroll-bar. */ if (items->tot_items > visual_info.visual_items) { uiLayoutColumn(row, false); uiDefButI(block, @@ -916,7 +916,7 @@ static void ui_template_list_layout_draw(const bContext *C, uiItemL(subrow, "", ICON_NONE); } - /* add scrollbar */ + /* Add scroll-bar. */ if (items->tot_items > visual_info.visual_items) { /* col = */ uiLayoutColumn(row, false); uiDefButI(block, @@ -940,7 +940,7 @@ static void ui_template_list_layout_draw(const bContext *C, box = uiLayoutListBox(layout, ui_list, &input_data->active_dataptr, input_data->activeprop); /* For grip button. */ glob = uiLayoutColumn(box, true); - /* For scrollbar. */ + /* For scroll-bar. */ row = uiLayoutRow(glob, false); const bool show_names = (flags & UI_TEMPLATE_LIST_NO_NAMES) == 0; diff --git a/source/blender/editors/interface/interface_template_search_menu.cc b/source/blender/editors/interface/interface_template_search_menu.cc index 5160b061ac6..574ac051322 100644 --- a/source/blender/editors/interface/interface_template_search_menu.cc +++ b/source/blender/editors/interface/interface_template_search_menu.cc @@ -191,7 +191,7 @@ static bool menu_items_from_ui_create_item_from_button(MenuSearch_Data *data, if (drawstr_is_empty) { if (prop_type == PROP_ENUM) { - const int value_enum = (int)but->hardmax; + const int value_enum = int(but->hardmax); EnumPropertyItem enum_item; if (RNA_property_enum_item_from_value_gettexted((bContext *)but->block->evil_C, &but->rnapoin, @@ -227,7 +227,7 @@ static bool menu_items_from_ui_create_item_from_button(MenuSearch_Data *data, item->rna.index = but->rnaindex; if (prop_type == PROP_ENUM) { - item->rna.enum_value = (int)but->hardmax; + item->rna.enum_value = int(but->hardmax); } } } @@ -473,8 +473,7 @@ static MenuSearch_Data *menu_items_from_ui_create( * as the outliner only exposes functionality via the context menu. */ GHashIterator iter; - for (WM_menutype_iter(&iter); (!BLI_ghashIterator_done(&iter)); - (BLI_ghashIterator_step(&iter))) { + for (WM_menutype_iter(&iter); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) { MenuType *mt = (MenuType *)BLI_ghashIterator_getValue(&iter); if (BLI_str_endswith(mt->idname, "_context_menu")) { BLI_gset_add(menu_tagged, mt); @@ -544,8 +543,8 @@ static MenuSearch_Data *menu_items_from_ui_create( if (wm_contexts[space_type_ui_index].space_type_ui_index != -1) { ScrArea *area_best = wm_contexts[space_type_ui_index].area; - const uint value_best = (uint)area_best->winx * (uint)area_best->winy; - const uint value_test = (uint)area->winx * (uint)area->winy; + const uint value_best = uint(area_best->winx) * uint(area_best->winy); + const uint value_test = uint(area->winx) * uint(area->winy); if (value_best > value_test) { continue; } @@ -933,7 +932,7 @@ static void menu_search_arg_free_fn(void *data_v) MEM_freeN(data); } -static void menu_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2) +static void menu_search_exec_fn(bContext *C, void * /*arg1*/, void *arg2) { MenuSearch_Item *item = (MenuSearch_Item *)arg2; if (item == nullptr) { @@ -996,11 +995,11 @@ static void menu_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2) } } -static void menu_search_update_fn(const bContext *UNUSED(C), +static void menu_search_update_fn(const bContext * /*C*/, void *arg, const char *str, uiSearchItems *items, - const bool UNUSED(is_first)) + const bool /*is_first*/) { MenuSearch_Data *data = (MenuSearch_Data *)arg; @@ -1079,7 +1078,7 @@ static bool ui_search_menu_create_context_menu(struct bContext *C, static struct ARegion *ui_search_menu_create_tooltip(struct bContext *C, struct ARegion *region, - const rcti *UNUSED(item_rect), + const rcti * /*item_rect*/, void *arg, void *active) { diff --git a/source/blender/editors/interface/interface_template_search_operator.cc b/source/blender/editors/interface/interface_template_search_operator.cc index 0d0a5f01744..58f44de5278 100644 --- a/source/blender/editors/interface/interface_template_search_operator.cc +++ b/source/blender/editors/interface/interface_template_search_operator.cc @@ -34,7 +34,7 @@ /** \name Operator Search Template Implementation * \{ */ -static void operator_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2) +static void operator_search_exec_fn(bContext *C, void * /*arg1*/, void *arg2) { wmOperatorType *ot = static_cast<wmOperatorType *>(arg2); @@ -44,10 +44,10 @@ static void operator_search_exec_fn(bContext *C, void *UNUSED(arg1), void *arg2) } static void operator_search_update_fn(const bContext *C, - void *UNUSED(arg), + void * /*arg*/, const char *str, uiSearchItems *items, - const bool UNUSED(is_first)) + const bool /*is_first*/) { GHashIterator iter; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 0b72c358dc9..b32aa82ad9e 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -910,6 +910,11 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) const char *undo_push_label = NULL; switch (event) { + case UI_ID_NOP: + /* Don't do anything, typically set for buttons that execute an operator instead. They may + * still assign the callback so the button can be identified as part of an ID-template. See + * #UI_context_active_but_prop_get_templateID(). */ + break; case UI_ID_BROWSE: case UI_ID_PIN: RNA_warning("warning, id event %d shouldn't come here", event); @@ -1410,7 +1415,7 @@ static void template_ID(const bContext *C, UI_but_funcN_set( but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_ALONE)); - if ((!BKE_id_copy_is_allowed(id)) || (idfrom && idfrom->lib) || (!editable) || + if (!BKE_id_copy_is_allowed(id) || (idfrom && idfrom->lib) || (!editable) || /* object in editmode - don't change data */ (idfrom && GS(idfrom->name) == ID_OB && (((Object *)idfrom)->mode & OB_MODE_EDIT))) { UI_but_flag_enable(but, UI_BUT_DISABLED); @@ -1437,7 +1442,7 @@ static void template_ID(const bContext *C, UI_UNIT_Y, NULL); } - else if (!(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS)) && + else if (!ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_OB, ID_WS) && (hide_buttons == false)) { uiDefIconButR(block, UI_BTYPE_ICON_TOGGLE, @@ -1543,7 +1548,8 @@ static void template_ID(const bContext *C, UI_UNIT_Y, NULL); /* so we can access the template from operators, font unlinking needs this */ - UI_but_funcN_set(but, NULL, MEM_dupallocN(template_ui), NULL); + UI_but_funcN_set( + but, template_id_cb, MEM_dupallocN(template_ui), POINTER_FROM_INT(UI_ID_NOP)); } else { if ((RNA_property_flag(template_ui->prop) & PROP_NEVER_UNLINK) == 0) { @@ -3263,7 +3269,7 @@ void uiTemplatePreview(uiLayout *layout, uiDefButS(block, UI_BTYPE_ROW, B_MATPRV, - IFACE_("World"), + CTX_IFACE_(BLT_I18NCONTEXT_ID_WORLD, "World"), 0, 0, UI_UNIT_X * 10, @@ -3659,7 +3665,7 @@ static void colorband_buttons_layout(uiLayout *layout, UI_UNIT_Y, &coba->cur, 0.0, - (float)(MAX2(0, coba->tot - 1)), + (float)MAX2(0, coba->tot - 1), 0, 0, TIP_("Choose active color stop")); @@ -3667,13 +3673,9 @@ static void colorband_buttons_layout(uiLayout *layout, row = uiLayoutRow(split, false); uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE); - bt = block->buttons.last; - UI_but_func_set(bt, colorband_update_cb, bt, coba); row = uiLayoutRow(layout, false); uiItemR(row, &ptr, "color", 0, "", ICON_NONE); - bt = block->buttons.last; - UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); } else { split = uiLayoutSplit(layout, 0.5f, false); @@ -3690,7 +3692,7 @@ static void colorband_buttons_layout(uiLayout *layout, UI_UNIT_Y, &coba->cur, 0.0, - (float)(MAX2(0, coba->tot - 1)), + (float)MAX2(0, coba->tot - 1), 0, 0, TIP_("Choose active color stop")); @@ -3698,13 +3700,28 @@ static void colorband_buttons_layout(uiLayout *layout, row = uiLayoutRow(subsplit, false); uiItemR(row, &ptr, "position", UI_ITEM_R_SLIDER, IFACE_("Pos"), ICON_NONE); - bt = block->buttons.last; - UI_but_func_set(bt, colorband_update_cb, bt, coba); row = uiLayoutRow(split, false); uiItemR(row, &ptr, "color", 0, "", ICON_NONE); - bt = block->buttons.last; - UI_but_funcN_set(bt, rna_update_cb, MEM_dupallocN(cb), NULL); + } + + /* Some special (rather awkward) treatment to update UI state on certain property changes. */ + LISTBASE_FOREACH_BACKWARD (uiBut *, but, &block->buttons) { + if (but->rnapoin.data != ptr.data) { + continue; + } + if (!but->rnaprop) { + continue; + } + + const char *prop_identifier = RNA_property_identifier(but->rnaprop); + if (STREQ(prop_identifier, "position")) { + UI_but_func_set(but, colorband_update_cb, but, coba); + } + + if (STREQ(prop_identifier, "color")) { + UI_but_funcN_set(but, rna_update_cb, MEM_dupallocN(cb), NULL); + } } } } diff --git a/source/blender/editors/interface/interface_utils.cc b/source/blender/editors/interface/interface_utils.cc index 4b94834ce97..423eefce3f3 100644 --- a/source/blender/editors/interface/interface_utils.cc +++ b/source/blender/editors/interface/interface_utils.cc @@ -435,7 +435,7 @@ eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout, /* Only buttons that can be edited as text. */ const bool use_activate_init = ((prop == prop_activate_init) && - (ELEM(type, PROP_STRING, PROP_INT, PROP_FLOAT))); + ELEM(type, PROP_STRING, PROP_INT, PROP_FLOAT)); if (use_activate_init) { uiLayoutSetActivateInit(col, true); @@ -495,7 +495,7 @@ static bool add_collection_search_item(CollItemSearch *cis, cis->name, cis->data, cis->iconid, - cis->has_sep_char ? (int)UI_BUT_HAS_SEP_CHAR : 0, + cis->has_sep_char ? int(UI_BUT_HAS_SEP_CHAR) : 0, name_prefix_offset); } @@ -787,7 +787,7 @@ int UI_calc_float_precision(int prec, double value) */ value = fabs(value); if ((value < pow10_neg[prec]) && (value > (1.0 / max_pow))) { - int value_i = (int)lround(value * max_pow); + int value_i = int(lround(value * max_pow)); if (value_i != 0) { const int prec_span = 3; /* show: 0.01001, 5 would allow 0.0100001 for eg. */ int test_prec; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ba2afce4349..0ef26de035f 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -197,16 +197,16 @@ static void color_mul_hsl_v3(uchar ch[3], float h_factor, float s_factor, float * \{ */ /** - * - in: roundbox codes for corner types and radius - * - return: array of `[size][2][x, y]` points, the edges of the roundbox, + UV coords + * - in: `roundbox` codes for corner types and radius + * - return: array of `[size][2][x, y]` points, the edges of the `roundbox`, + UV coords * - * - draw black box with alpha 0 on exact button boundbox - * - for every AA step: + * - Draw black box with alpha 0 on exact button bounding-box. + * - For every AA step: * - draw the inner part for a round filled box, with color blend codes or texture coords * - draw outline in outline color * - draw outer part, bottom half, extruded 1 pixel to bottom, for emboss shadow * - draw extra decorations - * - draw background color box with alpha 1 on exact button boundbox + * - Draw background color box with alpha 1 on exact button bounding-box. */ /* fill this struct with polygon info to draw AA'ed */ @@ -693,7 +693,7 @@ static void round_box__edges( { float vec[WIDGET_CURVE_RESOLU][2], veci[WIDGET_CURVE_RESOLU][2]; const float minx = rect->xmin, miny = rect->ymin, maxx = rect->xmax, maxy = rect->ymax; - const float minxi = minx + U.pixelsize; /* boundbox inner */ + const float minxi = minx + U.pixelsize; /* Bounding-box inner. */ const float maxxi = maxx - U.pixelsize; const float minyi = miny + U.pixelsize; const float maxyi = maxy - U.pixelsize; @@ -1371,7 +1371,7 @@ static void widget_draw_icon( alpha = 0.75f; } } - else if ((but->type == UI_BTYPE_LABEL)) { + else if (but->type == UI_BTYPE_LABEL) { /* extra feature allows more alpha blending */ if (but->a1 == 1.0f) { alpha *= but->a2; @@ -1420,21 +1420,25 @@ static void widget_draw_icon( /* to indicate draggable */ if (ui_but_drag_is_draggable(but) && (but->flag & UI_ACTIVE)) { - UI_icon_draw_ex(xs, ys, icon, aspect, 1.25f, 0.0f, color, has_theme); + UI_icon_draw_ex( + xs, ys, icon, aspect, 1.25f, 0.0f, color, has_theme, &but->icon_overlay_text); } - else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW))) { - UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, has_theme); + else if (but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW)) { + UI_icon_draw_ex( + xs, ys, icon, aspect, alpha, 0.0f, color, has_theme, &but->icon_overlay_text); } else if (!((but->icon != ICON_NONE) && UI_but_is_tool(but))) { if (has_theme) { alpha *= 0.8f; } - UI_icon_draw_ex(xs, ys, icon, aspect, alpha, 0.0f, color, has_theme); + UI_icon_draw_ex( + xs, ys, icon, aspect, alpha, 0.0f, color, has_theme, &but->icon_overlay_text); } else { const bTheme *btheme = UI_GetTheme(); const float desaturate = 1.0 - btheme->tui.icon_saturation; - UI_icon_draw_ex(xs, ys, icon, aspect, alpha, desaturate, color, has_theme); + UI_icon_draw_ex( + xs, ys, icon, aspect, alpha, desaturate, color, has_theme, &but->icon_overlay_text); } } @@ -1858,33 +1862,6 @@ static void widget_draw_text_ime_underline(const uiFontStyle *fstyle, } #endif /* WITH_INPUT_IME */ -struct UnderlineData { - size_t str_offset; /* The string offset of the underlined character. */ - int width_px; /* The underline width in pixels. */ - int r_offset_px[2]; /* Write the X,Y offset here. */ -}; - -static bool widget_draw_text_underline_calc_position(const char *UNUSED(str), - const size_t str_step_ofs, - const rcti *glyph_step_bounds, - const int UNUSED(glyph_advance_x), - const rcti *glyph_bounds, - const int UNUSED(glyph_bearing[2]), - void *user_data) -{ - struct UnderlineData *ul_data = user_data; - if (ul_data->str_offset == str_step_ofs) { - /* Full width of this glyph including both bearings. */ - const int width = glyph_bounds->xmin + BLI_rcti_size_x(glyph_bounds) + glyph_bounds->xmin; - ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) / 2); - /* One line-width below the lower glyph bounds. */ - ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize; - /* Early exit. */ - return false; - } - return true; -} - static void widget_draw_text(const uiFontStyle *fstyle, const uiWidgetColors *wcol, uiBut *but, @@ -2150,26 +2127,18 @@ static void widget_draw_text(const uiFontStyle *fstyle, } if (ul_index != -1) { - int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2)); - - struct UnderlineData ul_data = { - .str_offset = ul_index, - .width_px = ul_width, - }; - - BLF_boundbox_foreach_glyph(fstyle->uifont_id, - drawstr_ofs, - ul_index + 1, - widget_draw_text_underline_calc_position, - &ul_data); - - const int pos_x = rect->xmin + font_xofs + ul_data.r_offset_px[0]; - const int pos_y = rect->ymin + font_yofs + ul_data.r_offset_px[1]; - - /* Use text output because direct drawing doesn't always work. See T89246. */ - BLF_position(fstyle->uifont_id, pos_x, pos_y, 0.0f); - BLF_color4ubv(fstyle->uifont_id, wcol->text); - BLF_draw(fstyle->uifont_id, "_", 2); + rcti bounds; + if (BLF_str_offset_to_glyph_bounds(fstyle->uifont_id, drawstr_ofs, ul_index, &bounds) && + !BLI_rcti_is_empty(&bounds)) { + int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2)); + int pos_x = rect->xmin + font_xofs + bounds.xmin + + (bounds.xmax - bounds.xmin - ul_width) / 2; + int pos_y = rect->ymin + font_yofs + bounds.ymin - U.pixelsize; + /* Use text output because direct drawing doesn't always work. See T89246. */ + BLF_position(fstyle->uifont_id, (float)pos_x, pos_y, 0.0f); + BLF_color4ubv(fstyle->uifont_id, wcol->text); + BLF_draw(fstyle->uifont_id, "_", 2); + } } } } @@ -5461,7 +5430,8 @@ void ui_draw_menu_item(const uiFontStyle *fstyle, GPU_blend(GPU_BLEND_ALPHA); /* XXX scale weak get from fstyle? */ - UI_icon_draw_ex(xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text, false); + UI_icon_draw_ex( + xs, ys, iconid, aspect, 1.0f, 0.0f, wt->wcol.text, false, UI_NO_ICON_OVERLAY_TEXT); GPU_blend(GPU_BLEND_NONE); } diff --git a/source/blender/editors/interface/view2d.cc b/source/blender/editors/interface/view2d.cc index bb459f227f9..bb660d6bf7d 100644 --- a/source/blender/editors/interface/view2d.cc +++ b/source/blender/editors/interface/view2d.cc @@ -53,16 +53,16 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize); BLI_INLINE int clamp_float_to_int(const float f) { - const float min = (float)INT_MIN; - const float max = (float)INT_MAX; + const float min = float(INT_MIN); + const float max = float(INT_MAX); if (UNLIKELY(f < min)) { return min; } if (UNLIKELY(f > max)) { - return (int)max; + return int(max); } - return (int)f; + return int(f); } /** @@ -87,11 +87,11 @@ BLI_INLINE void clamp_rctf_to_rcti(rcti *dst, const rctf *src) * \{ */ /** - * helper to allow scrollbars to dynamically hide - * - returns a copy of the scrollbar settings with the flags to display - * horizontal/vertical scrollbars removed - * - input scroll value is the v2d->scroll var - * - hide flags are set per region at drawtime + * Helper to allow scroll-bars to dynamically hide: + * - Returns a copy of the scroll-bar settings with the flags to display + * horizontal/vertical scroll-bars removed. + * - Input scroll value is the v2d->scroll var. + * - Hide flags are set per region at draw-time. */ static int view2d_scroll_mapped(int scroll) { @@ -115,7 +115,7 @@ void UI_view2d_mask_from_win(const View2D *v2d, rcti *r_mask) /** * Called each time #View2D.cur changes, to dynamically update masks. * - * \param mask_scroll: Optionally clamp scrollbars by this region. + * \param mask_scroll: Optionally clamp scroll-bars by this region. */ static void view2d_masks(View2D *v2d, const rcti *mask_scroll) { @@ -177,7 +177,7 @@ static void view2d_masks(View2D *v2d, const rcti *mask_scroll) /* Currently, all regions that have vertical scale handles, * also have the scrubbing area at the top. - * So the scrollbar has to move down a bit. */ + * So the scroll-bar has to move down a bit. */ if (scroll & V2D_SCROLL_VERTICAL_HANDLES) { v2d->vert.ymax -= UI_TIME_SCRUB_MARGIN_Y; } @@ -193,6 +193,18 @@ static void view2d_masks(View2D *v2d, const rcti *mask_scroll) v2d->hor = *mask_scroll; v2d->hor.ymin = v2d->hor.ymax - scroll_height; } + + /* adjust vertical scroller if there's a horizontal scroller, to leave corner free */ + if (scroll & V2D_SCROLL_VERTICAL) { + if (scroll & V2D_SCROLL_BOTTOM) { + /* on bottom edge of region */ + v2d->vert.ymin = v2d->hor.ymax; + } + else if (scroll & V2D_SCROLL_TOP) { + /* on upper edge of region */ + v2d->vert.ymax = v2d->hor.ymin; + } + } } } @@ -232,8 +244,8 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) v2d->keeptot = V2D_KEEPTOT_BOUNDS; if (do_init) { v2d->tot.xmin = v2d->tot.ymin = 0.0f; - v2d->tot.xmax = (float)(winx - 1); - v2d->tot.ymax = (float)(winy - 1); + v2d->tot.xmax = float(winx - 1); + v2d->tot.ymax = float(winy - 1); v2d->cur = v2d->tot; } @@ -250,7 +262,6 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) /* tot rect has strictly regulated placement, and must only occur in +/- quadrant */ v2d->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_POS_Y); v2d->keeptot = V2D_KEEPTOT_STRICT; - v2d->keepofs = (V2D_KEEPOFS_X | V2D_KEEPOFS_Y); tot_changed = do_init; /* scroller settings are currently not set here... that is left for regions... */ @@ -267,7 +278,6 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */ v2d->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y); v2d->keeptot = V2D_KEEPTOT_STRICT; - v2d->keepofs = (V2D_KEEPOFS_X | V2D_KEEPOFS_Y); tot_changed = do_init; /* scroller settings are currently not set here... that is left for regions... */ @@ -287,8 +297,8 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy) v2d->tot.ymax = winy; v2d->cur = v2d->tot; - v2d->min[0] = v2d->max[0] = (float)(winx - 1); - v2d->min[1] = v2d->max[1] = (float)(winy - 1); + v2d->min[0] = v2d->max[0] = float(winx - 1); + v2d->min[1] = v2d->max[1] = float(winy - 1); } /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */ v2d->align = (V2D_ALIGN_NO_NEG_X | V2D_ALIGN_NO_NEG_Y); @@ -377,9 +387,9 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize) rctf *cur, *tot; /* use mask as size of region that View2D resides in, as it takes into account - * scrollbars already - keep in sync with zoomx/zoomy in view_zoomstep_apply_ex! */ - winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1); - winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1); + * scroll-bars already - keep in sync with zoomx/zoomy in #view_zoomstep_apply_ex! */ + winx = float(BLI_rcti_size_x(&v2d->mask) + 1); + winy = float(BLI_rcti_size_y(&v2d->mask) + 1); /* get pointers to rcts for less typing */ cur = &v2d->cur; @@ -485,7 +495,7 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize) } /* check if we should restore aspect ratio (if view size changed) */ - if (v2d->keepzoom & V2D_KEEPASPECT && !(v2d->keeptot == V2D_KEEPTOT_STRICT)) { + if (v2d->keepzoom & V2D_KEEPASPECT) { bool do_x = false, do_y = false, do_cur; float curRatio, winRatio; @@ -524,17 +534,58 @@ static void ui_view2d_curRect_validate_resize(View2D *v2d, bool resize) /* do_win = do_y; */ /* UNUSED */ if (do_cur) { - /* portrait window: correct for x */ - width = height / winRatio; + if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winx != v2d->oldwinx)) { + /* Special exception for Outliner (and later channel-lists): + * - The view may be moved left to avoid contents + * being pushed out of view when view shrinks. + * - The keeptot code will make sure cur->xmin will not be less than tot->xmin + * (which cannot be allowed). + * - width is not adjusted for changed ratios here. + */ + if (winx < v2d->oldwinx) { + const float temp = v2d->oldwinx - winx; + + cur->xmin -= temp; + cur->xmax -= temp; + + /* width does not get modified, as keepaspect here is just set to make + * sure visible area adjusts to changing view shape! + */ + } + } + else { + /* portrait window: correct for x */ + width = height / winRatio; + } } else { - /* landscape window: correct for y */ - height = width * winRatio; + if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winy != v2d->oldwiny)) { + /* special exception for Outliner (and later channel-lists): + * - Currently, no actions need to be taken here... + */ + + if (winy < v2d->oldwiny) { + const float temp = v2d->oldwiny - winy; + + if (v2d->align & V2D_ALIGN_NO_NEG_Y) { + cur->ymin -= temp; + cur->ymax -= temp; + } + else { /* Assume V2D_ALIGN_NO_POS_Y or combination */ + cur->ymin += temp; + cur->ymax += temp; + } + } + } + else { + /* landscape window: correct for y */ + height = width * winRatio; + } } /* store region size for next time */ - v2d->oldwinx = (short)winx; - v2d->oldwiny = (short)winy; + v2d->oldwinx = short(winx); + v2d->oldwiny = short(winy); } /* Step 2: apply new sizes to cur rect, @@ -865,8 +916,8 @@ void UI_view2d_curRect_reset(View2D *v2d) float width, height; /* assume width and height of 'cur' rect by default, should be same size as mask */ - width = (float)(BLI_rcti_size_x(&v2d->mask) + 1); - height = (float)(BLI_rcti_size_y(&v2d->mask) + 1); + width = float(BLI_rcti_size_x(&v2d->mask) + 1); + height = float(BLI_rcti_size_y(&v2d->mask) + 1); /* handle width - posx and negx flags are mutually exclusive, so watch out */ if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { @@ -929,17 +980,17 @@ void UI_view2d_totRect_set_resize(View2D *v2d, int width, int height, bool resiz /* handle width - posx and negx flags are mutually exclusive, so watch out */ if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) { /* width is in negative-x half */ - v2d->tot.xmin = (float)-width; + v2d->tot.xmin = float(-width); v2d->tot.xmax = 0.0f; } else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) { /* width is in positive-x half */ v2d->tot.xmin = 0.0f; - v2d->tot.xmax = (float)width; + v2d->tot.xmax = float(width); } else { /* width is centered around (x == 0) */ - const float dx = (float)width / 2.0f; + const float dx = float(width) / 2.0f; v2d->tot.xmin = -dx; v2d->tot.xmax = dx; @@ -948,17 +999,17 @@ void UI_view2d_totRect_set_resize(View2D *v2d, int width, int height, bool resiz /* handle height - posx and negx flags are mutually exclusive, so watch out */ if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) { /* height is in negative-y half */ - v2d->tot.ymin = (float)-height; + v2d->tot.ymin = float(-height); v2d->tot.ymax = 0.0f; } else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) { /* height is in positive-y half */ v2d->tot.ymin = 0.0f; - v2d->tot.ymax = (float)height; + v2d->tot.ymax = float(height); } else { /* height is centered around (y == 0) */ - const float dy = (float)height / 2.0f; + const float dy = float(height) / 2.0f; v2d->tot.ymin = -dy; v2d->tot.ymax = dy; @@ -1011,17 +1062,17 @@ static void view2d_map_cur_using_mask(const View2D *v2d, rctf *r_curmasked) const float dy = BLI_rctf_size_y(&v2d->cur) / (sizey + 1); if (v2d->mask.xmin != 0) { - r_curmasked->xmin -= dx * (float)v2d->mask.xmin; + r_curmasked->xmin -= dx * float(v2d->mask.xmin); } if (v2d->mask.xmax + 1 != v2d->winx) { - r_curmasked->xmax += dx * (float)(v2d->winx - v2d->mask.xmax - 1); + r_curmasked->xmax += dx * float(v2d->winx - v2d->mask.xmax - 1); } if (v2d->mask.ymin != 0) { - r_curmasked->ymin -= dy * (float)v2d->mask.ymin; + r_curmasked->ymin -= dy * float(v2d->mask.ymin); } if (v2d->mask.ymax + 1 != v2d->winy) { - r_curmasked->ymax += dy * (float)(v2d->winy - v2d->mask.ymax - 1); + r_curmasked->ymax += dy * float(v2d->winy - v2d->mask.ymax - 1); } } } @@ -1100,7 +1151,7 @@ void UI_view2d_view_restore(const bContext *C) const int width = BLI_rcti_size_x(®ion->winrct) + 1; const int height = BLI_rcti_size_y(®ion->winrct) + 1; - wmOrtho2(0.0f, (float)width, 0.0f, (float)height); + wmOrtho2(0.0f, float(width), 0.0f, float(height)); GPU_matrix_identity_set(); // ED_region_pixelspace(CTX_wm_region(C)); @@ -1126,8 +1177,8 @@ void UI_view2d_multi_grid_draw( /* Make an estimate of at least how many vertices will be needed */ uint vertex_count = 4; - vertex_count += 2 * ((int)((v2d->cur.xmax - v2d->cur.xmin) / lstep) + 1); - vertex_count += 2 * ((int)((v2d->cur.ymax - v2d->cur.ymin) / lstep) + 1); + vertex_count += 2 * (int((v2d->cur.xmax - v2d->cur.xmin) / lstep) + 1); + vertex_count += 2 * (int((v2d->cur.ymax - v2d->cur.ymin) / lstep) + 1); GPUVertFormat *format = immVertexFormat(); const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -1144,7 +1195,7 @@ void UI_view2d_multi_grid_draw( * or high contrast grid lines. This only has an effect if colorid != TH_GRID. */ UI_GetThemeColorBlendShade3ubv(colorid, TH_GRID, 0.25f, offset, grid_line_color); - int i = (int)(v2d->cur.xmin / lstep); + int i = int(v2d->cur.xmin / lstep); if (v2d->cur.xmin > 0.0f) { i++; } @@ -1161,7 +1212,7 @@ void UI_view2d_multi_grid_draw( immVertex2f(pos, start, v2d->cur.ymax); } - i = (int)(v2d->cur.ymin / lstep); + i = int(v2d->cur.ymin / lstep); if (v2d->cur.ymin > 0.0f) { i++; } @@ -1205,10 +1256,10 @@ static void grid_axis_start_and_count( { *r_start = min; if (*r_start < 0.0f) { - *r_start += -(float)fmod(min, step); + *r_start += -float(fmod(min, step)); } else { - *r_start += step - (float)fabs(fmod(min, step)); + *r_start += step - float(fabs(fmod(min, step))); } if (*r_start > max) { @@ -1229,7 +1280,7 @@ void UI_view2d_dot_grid_draw(const View2D *v2d, return; } - const float zoom_x = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); + const float zoom_x = float(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); GPUVertFormat *format = immVertexFormat(); const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -1245,7 +1296,7 @@ void UI_view2d_dot_grid_draw(const View2D *v2d, const int subdivision_scale = 5; const float view_level = logf(min_step / zoom_x) / logf(subdivision_scale); - const int largest_visible_level = (int)view_level; + const int largest_visible_level = int(view_level); for (int level_offset = 0; level_offset <= grid_subdivisions; level_offset++) { const int level = largest_visible_level - level_offset; @@ -1326,8 +1377,8 @@ struct View2DScrollers { /* focus bubbles */ /* focus bubbles */ /* focus bubbles */ - int vert_min, vert_max; /* vertical scrollbar */ - int hor_min, hor_max; /* horizontal scrollbar */ + int vert_min, vert_max; /* vertical scroll-bar */ + int hor_min, hor_max; /* horizontal scroll-bar */ /** Exact size of slider backdrop. */ rcti hor, vert; @@ -1357,7 +1408,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, vert.ymax -= UI_HEADER_OFFSET; /* width of sliders */ - smaller = (int)(0.1f * U.widget_unit); + smaller = int(0.1f * U.widget_unit); if (scroll & V2D_SCROLL_BOTTOM) { hor.ymin += smaller; } @@ -1380,7 +1431,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, r_scrollers->hor = hor; /* scroller 'buttons': - * - These should always remain within the visible region of the scrollbar + * - These should always remain within the visible region of the scroll-bar * - They represent the region of 'tot' that is visible in 'cur' */ @@ -1388,7 +1439,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, if (scroll & V2D_SCROLL_HORIZONTAL) { /* scroller 'button' extents */ totsize = BLI_rctf_size_x(&v2d->tot); - scrollsize = (float)BLI_rcti_size_x(&hor); + scrollsize = float(BLI_rcti_size_x(&hor)); if (totsize == 0.0f) { totsize = 1.0f; /* avoid divide by zero */ } @@ -1398,7 +1449,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, r_scrollers->hor_min = hor.xmin; } else { - r_scrollers->hor_min = (int)(hor.xmin + (fac1 * scrollsize)); + r_scrollers->hor_min = int(hor.xmin + (fac1 * scrollsize)); } fac2 = (v2d->cur.xmax - v2d->tot.xmin) / totsize; @@ -1406,7 +1457,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, r_scrollers->hor_max = hor.xmax; } else { - r_scrollers->hor_max = (int)(hor.xmin + (fac2 * scrollsize)); + r_scrollers->hor_max = int(hor.xmin + (fac2 * scrollsize)); } /* prevent inverted sliders */ @@ -1426,7 +1477,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, if (scroll & V2D_SCROLL_VERTICAL) { /* scroller 'button' extents */ totsize = BLI_rctf_size_y(&v2d->tot); - scrollsize = (float)BLI_rcti_size_y(&vert); + scrollsize = float(BLI_rcti_size_y(&vert)); if (totsize == 0.0f) { totsize = 1.0f; /* avoid divide by zero */ } @@ -1436,7 +1487,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, r_scrollers->vert_min = vert.ymin; } else { - r_scrollers->vert_min = (int)(vert.ymin + (fac1 * scrollsize)); + r_scrollers->vert_min = int(vert.ymin + (fac1 * scrollsize)); } fac2 = (v2d->cur.ymax - v2d->tot.ymin) / totsize; @@ -1444,7 +1495,7 @@ void UI_view2d_scrollers_calc(View2D *v2d, r_scrollers->vert_max = vert.ymax; } else { - r_scrollers->vert_max = (int)(vert.ymin + (fac2 * scrollsize)); + r_scrollers->vert_max = int(vert.ymin + (fac2 * scrollsize)); } /* prevent inverted sliders */ @@ -1473,14 +1524,14 @@ void UI_view2d_scrollers_draw_ex(View2D *v2d, const rcti *mask_custom, bool use_ uchar scrollers_back_color[4]; - /* Color for scrollbar backs */ + /* Color for scroll-bar backs. */ UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color); /* make copies of rects for less typing */ vert = scrollers.vert; hor = scrollers.hor; - /* horizontal scrollbar */ + /* Horizontal scroll-bar. */ if (scroll & V2D_SCROLL_HORIZONTAL) { uiWidgetColors wcol = btheme->tui.wcol_scroll; /* 0..255 -> min...1 */ @@ -1515,7 +1566,7 @@ void UI_view2d_scrollers_draw_ex(View2D *v2d, const rcti *mask_custom, bool use_ UI_draw_widget_scroll(&wcol, &hor, &slider, state); } - /* vertical scrollbar */ + /* Vertical scroll-bar. */ if (scroll & V2D_SCROLL_VERTICAL) { uiWidgetColors wcol = btheme->tui.wcol_scroll; rcti slider; @@ -1622,8 +1673,8 @@ void UI_view2d_region_to_view( void UI_view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) { const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; - const float mask_size[2] = {(float)BLI_rcti_size_x(&v2d->mask), - (float)BLI_rcti_size_y(&v2d->mask)}; + const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)), + float(BLI_rcti_size_y(&v2d->mask))}; rect_dst->xmin = (v2d->cur.xmin + (cur_size[0] * (rect_src->xmin - v2d->mask.xmin) / mask_size[0])); @@ -1655,8 +1706,8 @@ bool UI_view2d_view_to_region_clip( /* check if values are within bounds */ if ((x >= 0.0f) && (x <= 1.0f) && (y >= 0.0f) && (y <= 1.0f)) { - *r_region_x = (int)(v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask))); - *r_region_y = (int)(v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask))); + *r_region_x = int(v2d->mask.xmin + (x * BLI_rcti_size_x(&v2d->mask))); + *r_region_y = int(v2d->mask.ymin + (y * BLI_rcti_size_y(&v2d->mask))); return true; } @@ -1719,10 +1770,10 @@ bool UI_view2d_view_to_region_segment_clip(const View2D *v2d, r_region_a[0] = r_region_b[0] = r_region_a[1] = r_region_b[1] = V2D_IS_CLIPPED; if (BLI_rctf_isect_segment(&rect_unit, s_a, s_b)) { - r_region_a[0] = (int)(v2d->mask.xmin + (s_a[0] * BLI_rcti_size_x(&v2d->mask))); - r_region_a[1] = (int)(v2d->mask.ymin + (s_a[1] * BLI_rcti_size_y(&v2d->mask))); - r_region_b[0] = (int)(v2d->mask.xmin + (s_b[0] * BLI_rcti_size_x(&v2d->mask))); - r_region_b[1] = (int)(v2d->mask.ymin + (s_b[1] * BLI_rcti_size_y(&v2d->mask))); + r_region_a[0] = int(v2d->mask.xmin + (s_a[0] * BLI_rcti_size_x(&v2d->mask))); + r_region_a[1] = int(v2d->mask.ymin + (s_a[1] * BLI_rcti_size_y(&v2d->mask))); + r_region_b[0] = int(v2d->mask.xmin + (s_b[0] * BLI_rcti_size_x(&v2d->mask))); + r_region_b[1] = int(v2d->mask.ymin + (s_b[1] * BLI_rcti_size_y(&v2d->mask))); return true; } @@ -1733,8 +1784,8 @@ bool UI_view2d_view_to_region_segment_clip(const View2D *v2d, void UI_view2d_view_to_region_rcti(const View2D *v2d, const rctf *rect_src, rcti *rect_dst) { const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; - const float mask_size[2] = {(float)BLI_rcti_size_x(&v2d->mask), - (float)BLI_rcti_size_y(&v2d->mask)}; + const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)), + float(BLI_rcti_size_y(&v2d->mask))}; rctf rect_tmp; /* Step 1: express given coordinates as proportional values. */ @@ -1763,8 +1814,8 @@ void UI_view2d_view_to_region_m4(const View2D *v2d, float matrix[4][4]) bool UI_view2d_view_to_region_rcti_clip(const View2D *v2d, const rctf *rect_src, rcti *rect_dst) { const float cur_size[2] = {BLI_rctf_size_x(&v2d->cur), BLI_rctf_size_y(&v2d->cur)}; - const float mask_size[2] = {(float)BLI_rcti_size_x(&v2d->mask), - (float)BLI_rcti_size_y(&v2d->mask)}; + const float mask_size[2] = {float(BLI_rcti_size_x(&v2d->mask)), + float(BLI_rcti_size_y(&v2d->mask))}; rctf rect_tmp; BLI_assert(rect_src->xmin <= rect_src->xmax && rect_src->ymin <= rect_src->ymax); @@ -2100,12 +2151,22 @@ void UI_view2d_text_cache_draw(ARegion *region) col_pack_prev = v2s->col.pack; } - BLF_enable(font_id, BLF_CLIPPING); - BLF_clipping( - font_id, v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4); - BLF_draw_default( - v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f, v2s->str, BLF_DRAW_STR_DUMMY_MAX); - BLF_disable(font_id, BLF_CLIPPING); + /* Don't use clipping if `v2s->rect` is not set. */ + if (BLI_rcti_size_x(&v2s->rect) == 0 && BLI_rcti_size_y(&v2s->rect) == 0) { + BLF_draw_default(float(v2s->mval[0] + xofs), + float(v2s->mval[1] + yofs), + 0.0, + v2s->str, + BLF_DRAW_STR_DUMMY_MAX); + } + else { + BLF_enable(font_id, BLF_CLIPPING); + BLF_clipping( + font_id, v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4); + BLF_draw_default( + v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f, v2s->str, BLF_DRAW_STR_DUMMY_MAX); + BLF_disable(font_id, BLF_CLIPPING); + } } g_v2d_strings = nullptr; diff --git a/source/blender/editors/interface/view2d_draw.cc b/source/blender/editors/interface/view2d_draw.cc index ea4cf399a57..a8d6d6c78de 100644 --- a/source/blender/editors/interface/view2d_draw.cc +++ b/source/blender/editors/interface/view2d_draw.cc @@ -319,11 +319,11 @@ static void draw_horizontal_scale_indicators(const ARegion *region, const float right_text_width = BLF_width(font_id, text, strlen(text)); const float max_text_width = max_ff(left_text_width, right_text_width); const float max_label_count = BLI_rcti_size_x(&v2d->mask) / (max_text_width + 10.0f); - draw_frequency = ceil((float)steps / max_label_count); + draw_frequency = ceil(float(steps) / max_label_count); } if (draw_frequency != 0) { - const int start_index = abs((int)(start / distance)) % draw_frequency; + const int start_index = abs(int(start / distance)) % draw_frequency; for (uint i = start_index; i < steps; i += draw_frequency) { const float xpos_view = start + i * distance; const float xpos_region = UI_view2d_view_to_region_x(v2d, xpos_view); @@ -408,9 +408,9 @@ static void draw_vertical_scale_indicators(const ARegion *region, } static void view_to_string__frame_number( - void *UNUSED(user_data), float v2d_pos, float UNUSED(v2d_step), uint max_len, char *r_str) + void * /*user_data*/, float v2d_pos, float /*v2d_step*/, uint max_len, char *r_str) { - BLI_snprintf(r_str, max_len, "%d", (int)v2d_pos); + BLI_snprintf(r_str, max_len, "%d", int(v2d_pos)); } static void view_to_string__time( @@ -424,14 +424,14 @@ static void view_to_string__time( } BLI_timecode_string_from_time( - r_str, max_len, brevity_level, v2d_pos / (float)FPS, FPS, U.timecode_style); + r_str, max_len, brevity_level, v2d_pos / float(FPS), FPS, U.timecode_style); } static void view_to_string__value( - void *UNUSED(user_data), float v2d_pos, float v2d_step, uint max_len, char *r_str) + void * /*user_data*/, float v2d_pos, float v2d_step, uint max_len, char *r_str) { if (v2d_step >= 1.0f) { - BLI_snprintf(r_str, max_len, "%d", (int)v2d_pos); + BLI_snprintf(r_str, max_len, "%d", int(v2d_pos)); } else if (v2d_step >= 0.1f) { BLI_snprintf(r_str, max_len, "%.1f", v2d_pos); diff --git a/source/blender/editors/interface/view2d_edge_pan.cc b/source/blender/editors/interface/view2d_edge_pan.cc index 82959d96043..897a638dfe5 100644 --- a/source/blender/editors/interface/view2d_edge_pan.cc +++ b/source/blender/editors/interface/view2d_edge_pan.cc @@ -80,10 +80,10 @@ void UI_view2d_edge_pan_init(bContext *C, vpd->enabled = false; /* Calculate translation factor, based on size of view. */ - const float winx = (float)(BLI_rcti_size_x(&vpd->region->winrct) + 1); - const float winy = (float)(BLI_rcti_size_y(&vpd->region->winrct) + 1); - vpd->facx = (BLI_rctf_size_x(&vpd->v2d->cur)) / winx; - vpd->facy = (BLI_rctf_size_y(&vpd->v2d->cur)) / winy; + const float winx = float(BLI_rcti_size_x(&vpd->region->winrct) + 1); + const float winy = float(BLI_rcti_size_y(&vpd->region->winrct) + 1); + vpd->facx = BLI_rctf_size_x(&vpd->v2d->cur) / winx; + vpd->facy = BLI_rctf_size_y(&vpd->v2d->cur) / winy; UI_view2d_edge_pan_reset(vpd); } @@ -165,16 +165,16 @@ static float edge_pan_speed(View2DEdgePanData *vpd, /* Apply a fade in to the speed based on a start time delay. */ const double start_time = x_dir ? vpd->edge_pan_start_time_x : vpd->edge_pan_start_time_y; const float delay_factor = vpd->delay > 0.01f ? - smootherstep(vpd->delay, (float)(current_time - start_time)) : + smootherstep(vpd->delay, float(current_time - start_time)) : 1.0f; /* Zoom factor increases speed when zooming in and decreases speed when zooming out. */ - const float zoomx = (float)(BLI_rcti_size_x(®ion->winrct) + 1) / + const float zoomx = float(BLI_rcti_size_x(®ion->winrct) + 1) / BLI_rctf_size_x(®ion->v2d.cur); const float zoom_factor = 1.0f + CLAMPIS(vpd->zoom_influence, 0.0f, 1.0f) * (zoomx - 1.0f); return distance_factor * delay_factor * zoom_factor * vpd->max_speed * U.widget_unit * - (float)U.dpi_fac; + float(U.dpi_fac); } static void edge_pan_apply_delta(bContext *C, View2DEdgePanData *vpd, float dx, float dy) @@ -252,15 +252,15 @@ void UI_view2d_edge_pan_apply(bContext *C, View2DEdgePanData *vpd, const int xy[ edge_pan_manage_delay_timers(vpd, pan_dir_x, pan_dir_y, current_time); /* Calculate the delta since the last time the operator was called. */ - const float dtime = (float)(current_time - vpd->edge_pan_last_time); + const float dtime = float(current_time - vpd->edge_pan_last_time); float dx = 0.0f, dy = 0.0f; if (pan_dir_x != 0) { const float speed = edge_pan_speed(vpd, xy[0], true, current_time); - dx = dtime * speed * (float)pan_dir_x; + dx = dtime * speed * float(pan_dir_x); } if (pan_dir_y != 0) { const float speed = edge_pan_speed(vpd, xy[1], false, current_time); - dy = dtime * speed * (float)pan_dir_y; + dy = dtime * speed * float(pan_dir_y); } vpd->edge_pan_last_time = current_time; diff --git a/source/blender/editors/interface/view2d_gizmo_navigate.cc b/source/blender/editors/interface/view2d_gizmo_navigate.cc index fae28833e4f..78549a33fc5 100644 --- a/source/blender/editors/interface/view2d_gizmo_navigate.cc +++ b/source/blender/editors/interface/view2d_gizmo_navigate.cc @@ -113,7 +113,7 @@ struct NavigateWidgetGroup { int region_size[2]; }; -static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt)) +static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType * /*gzgt*/) { if ((U.uiflag & USER_SHOW_GIZMO_NAVIGATE) == 0) { return false; @@ -141,7 +141,7 @@ static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType *UNUSE return true; } -static void WIDGETGROUP_navigate_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) +static void WIDGETGROUP_navigate_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { NavigateWidgetGroup *navgroup = MEM_cnew<NavigateWidgetGroup>(__func__); diff --git a/source/blender/editors/interface/view2d_ops.cc b/source/blender/editors/interface/view2d_ops.cc index ec15c4ffc9f..30c5e79a794 100644 --- a/source/blender/editors/interface/view2d_ops.cc +++ b/source/blender/editors/interface/view2d_ops.cc @@ -127,10 +127,10 @@ static void view_pan_init(bContext *C, wmOperator *op) vpd->v2d = &vpd->region->v2d; /* calculate translation factor - based on size of view */ - const float winx = (float)(BLI_rcti_size_x(&vpd->region->winrct) + 1); - const float winy = (float)(BLI_rcti_size_y(&vpd->region->winrct) + 1); - vpd->facx = (BLI_rctf_size_x(&vpd->v2d->cur)) / winx; - vpd->facy = (BLI_rctf_size_y(&vpd->v2d->cur)) / winy; + const float winx = float(BLI_rcti_size_x(&vpd->region->winrct) + 1); + const float winy = float(BLI_rcti_size_y(&vpd->region->winrct) + 1); + vpd->facx = BLI_rctf_size_x(&vpd->v2d->cur) / winx; + vpd->facy = BLI_rctf_size_y(&vpd->v2d->cur) / winy; vpd->v2d->flag |= V2D_IS_NAVIGATING; } @@ -293,7 +293,7 @@ static int view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_RUNNING_MODAL; } -static void view_pan_cancel(bContext *UNUSED(C), wmOperator *op) +static void view_pan_cancel(bContext * /*C*/, wmOperator *op) { view_pan_exit(op); } @@ -330,7 +330,7 @@ static void VIEW2D_OT_pan(wmOperatorType *ot) * \{ */ /* set up modal operator and relevant settings */ -static int view_edge_pan_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +static int view_edge_pan_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/) { op->customdata = MEM_callocN(sizeof(View2DEdgePanData), "View2DEdgePanData"); View2DEdgePanData *vpd = static_cast<View2DEdgePanData *>(op->customdata); @@ -358,7 +358,7 @@ static int view_edge_pan_modal(bContext *C, wmOperator *op, const wmEvent *event return OPERATOR_PASS_THROUGH; } -static void view_edge_pan_cancel(bContext *UNUSED(C), wmOperator *op) +static void view_edge_pan_cancel(bContext * /*C*/, wmOperator *op) { v2dViewPanData *vpd = static_cast<v2dViewPanData *>(op->customdata); vpd->v2d->flag &= ~V2D_IS_NAVIGATING; @@ -712,7 +712,7 @@ static void view_zoomstep_apply_ex(bContext *C, if (vzd->zoom_to_mouse_pos) { /* get zoom fac the same way as in * ui_view2d_curRect_validate_resize - better keep in sync! */ - const float zoomx = (float)(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); + const float zoomx = float(BLI_rcti_size_x(&v2d->mask) + 1) / BLI_rctf_size_x(&v2d->cur); /* only move view to mouse if zoom fac is inside minzoom/maxzoom */ if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || @@ -747,7 +747,7 @@ static void view_zoomstep_apply_ex(bContext *C, if (vzd->zoom_to_mouse_pos) { /* get zoom fac the same way as in * ui_view2d_curRect_validate_resize - better keep in sync! */ - const float zoomy = (float)(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); + const float zoomy = float(BLI_rcti_size_y(&v2d->mask) + 1) / BLI_rctf_size_y(&v2d->cur); /* only move view to mouse if zoom fac is inside minzoom/maxzoom */ if (((v2d->keepzoom & V2D_LIMITZOOM) == 0) || @@ -958,7 +958,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op) * never uses the "Continuous" zoom method, and the 'timer' is not initialized. */ if ((U.viewzoom == USER_ZOOM_CONTINUE) && vzd->timer) { /* XXX store this setting as RNA prop? */ const double time = PIL_check_seconds_timer(); - const float time_step = (float)(time - vzd->timer_lastdraw); + const float time_step = float(time - vzd->timer_lastdraw); dx *= time_step * 5.0f; dy *= time_step * 5.0f; @@ -1583,10 +1583,10 @@ void UI_view2d_smooth_view(const bContext *C, if (changed) { sms.orig_cur = v2d->cur; - sms.time_allowed = (double)smooth_viewtx / 1000.0; + sms.time_allowed = double(smooth_viewtx) / 1000.0; /* scale the time allowed the change in view */ - sms.time_allowed *= (double)fac; + sms.time_allowed *= double(fac); /* keep track of running timer! */ if (v2d->sms == nullptr) { @@ -1614,7 +1614,7 @@ void UI_view2d_smooth_view(const bContext *C, } /* only meant for timer usage */ -static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +static int view2d_smoothview_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *event) { wmWindow *win = CTX_wm_window(C); ARegion *region = CTX_wm_region(C); @@ -1628,7 +1628,7 @@ static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const w float step; if (sms->time_allowed != 0.0) { - step = (float)((v2d->smooth_timer->duration) / sms->time_allowed); + step = float((v2d->smooth_timer->duration) / sms->time_allowed); } else { step = 1.0f; @@ -1821,11 +1821,11 @@ static bool scroller_activate_poll(bContext *C) View2D *v2d = ®ion->v2d; wmEvent *event = win->eventstate; - /* check if mouse in scrollbars, if they're enabled */ + /* Check if mouse in scroll-bars, if they're enabled. */ return (UI_view2d_mouse_in_scrollers(region, v2d, event->xy) != 0); } -/* initialize customdata for scroller manipulation operator */ +/* Initialize #wmOperator.customdata for scroller manipulation operator. */ static void scroller_activate_init(bContext *C, wmOperator *op, const wmEvent *event, @@ -1859,11 +1859,11 @@ static void scroller_activate_init(bContext *C, if (in_scroller == 'h') { /* horizontal scroller - calculate adjustment factor first */ - const float mask_size = (float)BLI_rcti_size_x(&v2d->hor); + const float mask_size = float(BLI_rcti_size_x(&v2d->hor)); vsm->fac = BLI_rctf_size_x(&tot_cur_union) / mask_size; /* pixel rounding */ - vsm->fac_round = (BLI_rctf_size_x(&v2d->cur)) / (float)(BLI_rcti_size_x(®ion->winrct) + 1); + vsm->fac_round = BLI_rctf_size_x(&v2d->cur) / float(BLI_rcti_size_x(®ion->winrct) + 1); /* get 'zone' (i.e. which part of scroller is activated) */ vsm->zone = mouse_in_scroller_handle( @@ -1879,11 +1879,11 @@ static void scroller_activate_init(bContext *C, } else { /* vertical scroller - calculate adjustment factor first */ - const float mask_size = (float)BLI_rcti_size_y(&v2d->vert); + const float mask_size = float(BLI_rcti_size_y(&v2d->vert)); vsm->fac = BLI_rctf_size_y(&tot_cur_union) / mask_size; /* pixel rounding */ - vsm->fac_round = (BLI_rctf_size_y(&v2d->cur)) / (float)(BLI_rcti_size_y(®ion->winrct) + 1); + vsm->fac_round = BLI_rctf_size_y(&v2d->cur) / float(BLI_rcti_size_y(®ion->winrct) + 1); /* get 'zone' (i.e. which part of scroller is activated) */ vsm->zone = mouse_in_scroller_handle( @@ -2000,11 +2000,11 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *e switch (vsm->scroller) { case 'h': /* horizontal scroller - so only horizontal movement * ('cur' moves opposite to mouse) */ - vsm->delta = (float)(event->xy[0] - vsm->lastx); + vsm->delta = float(event->xy[0] - vsm->lastx); break; case 'v': /* vertical scroller - so only vertical movement * ('cur' moves opposite to mouse) */ - vsm->delta = (float)(event->xy[1] - vsm->lasty); + vsm->delta = float(event->xy[1] - vsm->lasty); break; } } @@ -2013,11 +2013,11 @@ static int scroller_activate_modal(bContext *C, wmOperator *op, const wmEvent *e switch (vsm->scroller) { case 'h': /* horizontal scroller - so only horizontal movement * ('cur' moves with mouse) */ - vsm->delta = (float)(vsm->lastx - event->xy[0]); + vsm->delta = float(vsm->lastx - event->xy[0]); break; case 'v': /* vertical scroller - so only vertical movement * ('cur' moves with to mouse) */ - vsm->delta = (float)(vsm->lasty - event->xy[1]); + vsm->delta = float(vsm->lasty - event->xy[1]); break; } } @@ -2065,7 +2065,7 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent * ARegion *region = CTX_wm_region(C); View2D *v2d = ®ion->v2d; - /* check if mouse in scrollbars, if they're enabled */ + /* check if mouse in scroll-bars, if they're enabled */ const char in_scroller = UI_view2d_mouse_in_scrollers(region, v2d, event->xy); /* if in a scroller, init customdata then set modal handler which will @@ -2080,11 +2080,11 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent * switch (vsm->scroller) { case 'h': /* horizontal scroller - so only horizontal movement * ('cur' moves opposite to mouse) */ - vsm->delta = (float)(event->xy[0] - vsm->scrollbar_orig); + vsm->delta = float(event->xy[0] - vsm->scrollbar_orig); break; case 'v': /* vertical scroller - so only vertical movement * ('cur' moves opposite to mouse) */ - vsm->delta = (float)(event->xy[1] - vsm->scrollbar_orig); + vsm->delta = float(event->xy[1] - vsm->scrollbar_orig); break; } scroller_activate_apply(C, op); @@ -2169,7 +2169,7 @@ static void VIEW2D_OT_scroller_activate(wmOperatorType *ot) /** \name View Reset Operator * \{ */ -static int reset_exec(bContext *C, wmOperator *UNUSED(op)) +static int reset_exec(bContext *C, wmOperator * /*op*/) { const uiStyle *style = UI_style_get(); ARegion *region = CTX_wm_region(C); @@ -2177,8 +2177,8 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op)) const int snap_test = ED_region_snap_size_test(region); /* zoom 1.0 */ - const int winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1); - const int winy = (float)(BLI_rcti_size_y(&v2d->mask) + 1); + const int winx = float(BLI_rcti_size_x(&v2d->mask) + 1); + const int winy = float(BLI_rcti_size_y(&v2d->mask) + 1); v2d->cur.xmax = v2d->cur.xmin + winx; v2d->cur.ymax = v2d->cur.ymin + winy; diff --git a/source/blender/editors/interface/views/abstract_view_item.cc b/source/blender/editors/interface/views/abstract_view_item.cc index f73183d07e9..101cb66bfa9 100644 --- a/source/blender/editors/interface/views/abstract_view_item.cc +++ b/source/blender/editors/interface/views/abstract_view_item.cc @@ -112,7 +112,7 @@ static AbstractViewItem *find_item_from_rename_button(const uiBut &rename_but) return nullptr; } -static void rename_button_fn(bContext *UNUSED(C), void *arg, char *UNUSED(origstr)) +static void rename_button_fn(bContext * /*C*/, void *arg, char * /*origstr*/) { const uiBut *rename_but = static_cast<uiBut *>(arg); AbstractViewItem *item = find_item_from_rename_button(*rename_but); diff --git a/source/blender/editors/interface/views/grid_view.cc b/source/blender/editors/interface/views/grid_view.cc index 52ff1460cbd..ee2fa87b1dc 100644 --- a/source/blender/editors/interface/views/grid_view.cc +++ b/source/blender/editors/interface/views/grid_view.cc @@ -237,7 +237,7 @@ IndexRange BuildOnlyVisibleButtonsHelper::get_visible_range() const const float scroll_ofs_y = abs(v2d_.cur.ymax - v2d_.tot.ymax); if (!IS_EQF(scroll_ofs_y, 0)) { - const int scrolled_away_rows = (int)scroll_ofs_y / style_.tile_height; + const int scrolled_away_rows = int(scroll_ofs_y) / style_.tile_height; first_idx_in_view = scrolled_away_rows * cols_per_row_; } @@ -263,7 +263,7 @@ void BuildOnlyVisibleButtonsHelper::fill_layout_before_visible(uiBlock &block) c return; } - const int scrolled_away_rows = (int)scroll_ofs_y / style_.tile_height; + const int scrolled_away_rows = int(scroll_ofs_y) / style_.tile_height; add_spacer_button(block, scrolled_away_rows); } diff --git a/source/blender/editors/interface/views/interface_view.cc b/source/blender/editors/interface/views/interface_view.cc index c568a8cab74..71974b4d2f9 100644 --- a/source/blender/editors/interface/views/interface_view.cc +++ b/source/blender/editors/interface/views/interface_view.cc @@ -81,7 +81,7 @@ void ui_block_free_views(uiBlock *block) } } -void UI_block_views_listen(const uiBlock *block, const wmRegionListenerParams *listener_params) +void ui_block_views_listen(const uiBlock *block, const wmRegionListenerParams *listener_params) { ARegion *region = listener_params->region; |