diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-04 18:24:14 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-04 18:24:14 +0300 |
commit | 432ad4c63278762079a79fc2a8ddc2647a2228cc (patch) | |
tree | c9932b22f4a27913ddeb362d32fd2c802a4ead65 /source | |
parent | 9c962b2e2b3d772af8106cadd0b58142d28fea69 (diff) |
Cleanup: Move interface.c to C++
This is similar to 4537eb0c3b1678a62
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.cc (renamed from source/blender/editors/interface/interface.c) | 517 |
2 files changed, 280 insertions, 239 deletions
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 0bc52fd3a38..444bb08f3fb 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -25,7 +25,7 @@ set(INC ) set(SRC - interface.c + interface.cc interface_align.c interface_anim.c interface_button_group.c diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.cc index e83a8761e12..9bd0498fcfb 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.cc @@ -5,12 +5,12 @@ * \ingroup edinterface */ -#include <ctype.h> -#include <float.h> -#include <limits.h> -#include <math.h> -#include <stddef.h> /* `offsetof()` */ -#include <string.h> +#include <cctype> +#include <cfloat> +#include <climits> +#include <cmath> +#include <cstddef> /* `offsetof()` */ +#include <cstring> #include "MEM_guardedalloc.h" @@ -20,7 +20,6 @@ #include "DNA_userdef_types.h" #include "DNA_workspace_types.h" -#include "BLI_alloca.h" #include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_math.h" @@ -28,6 +27,7 @@ #include "BLI_string.h" #include "BLI_string_search.h" #include "BLI_string_utf8.h" +#include "BLI_vector.hh" #include "BLI_utildefines.h" @@ -75,11 +75,13 @@ #include "interface_intern.h" +using blender::Vector; + /* prototypes. */ static void ui_but_to_pixelrect(struct rcti *rect, const struct ARegion *region, struct uiBlock *block, - struct uiBut *but); + 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); @@ -276,7 +278,7 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block) } rcti rect; - ui_but_to_pixelrect(&rect, region, block, block->buttons.last); + 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; @@ -285,20 +287,18 @@ static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block) } /* We could get rid of this loop if we agree on a max number of spacer */ - int *spacers_pos = alloca(sizeof(*spacers_pos) * (size_t)sepr_flex_len); - int i = 0; + Vector<int, 8> spacers_pos; LISTBASE_FOREACH (uiBut *, but, &block->buttons) { if (but->type == UI_BTYPE_SEPR_SPACER) { ui_but_to_pixelrect(&rect, region, block, but); - spacers_pos[i] = rect.xmax + UI_HEADER_OFFSET; - i++; + spacers_pos.append(rect.xmax + UI_HEADER_OFFSET); } } const float view_scale_x = UI_view2d_scale_get_x(®ion->v2d); const float segment_width = region_width / (float)sepr_flex_len; float offset = 0, remaining_space = region_width - buttons_width; - i = 0; + int i = 0; LISTBASE_FOREACH (uiBut *, but, &block->buttons) { BLI_rctf_translate(&but->rect, offset / view_scale_x, 0); if (but->type == UI_BTYPE_SEPR_SPACER) { @@ -341,7 +341,7 @@ static void ui_update_window_matrix(const wmWindow *window, const ARegion *regio void ui_region_winrct_get_no_margin(const struct ARegion *region, struct rcti *r_rect) { - uiBlock *block = region->uiblocks.first; + uiBlock *block = static_cast<uiBlock *>(region->uiblocks.first); if (block && (block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_RADIAL) == 0) { BLI_rcti_rctf_copy_floor(r_rect, &block->rect); BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin); @@ -376,7 +376,7 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset) UI_fontstyle_set(&style->widget); - uiBut *init_col_bt = block->buttons.first; + uiBut *init_col_bt = static_cast<uiBut *>(block->buttons.first); LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { if (!ELEM(bt->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER)) { j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr)); @@ -402,7 +402,7 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset) } /* Give the following code the last button in the alignment group, there might have to be a * split immediately after. */ - bt = col_bt ? col_bt->prev : NULL; + bt = col_bt ? col_bt->prev : nullptr; } if (bt && bt->next && bt->rect.xmin < bt->next->rect.xmin) { @@ -468,7 +468,7 @@ void ui_block_bounds_calc(uiBlock *block) block->rect.xmax = block->rect.xmin + max_ff(BLI_rctf_size_x(&block->rect), block->minbounds); /* hardcoded exception... but that one is annoying with larger safety */ - uiBut *bt = block->buttons.first; + uiBut *bt = static_cast<uiBut *>(block->buttons.first); const int xof = ((bt && STRPREFIX(bt->str, "ERROR")) ? 10 : 40) * U.dpi_fac; block->safety.xmin = block->rect.xmin - xof; @@ -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] = { - block->pie_data.pie_center_spawned[0], - 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]); @@ -581,7 +581,7 @@ static void ui_block_bounds_calc_popup( void UI_block_bounds_set_normal(uiBlock *block, int addval) { - if (block == NULL) { + if (block == nullptr) { return; } @@ -599,7 +599,7 @@ void UI_block_bounds_set_popup(uiBlock *block, int addval, const int bounds_offs { block->bounds = addval; block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MOUSE; - if (bounds_offset != NULL) { + if (bounds_offset != nullptr) { block->bounds_offset[0] = bounds_offset[0]; block->bounds_offset[1] = bounds_offset[1]; } @@ -613,7 +613,7 @@ void UI_block_bounds_set_menu(uiBlock *block, int addval, const int bounds_offse { block->bounds = addval; block->bounds_type = UI_BLOCK_BOUNDS_POPUP_MENU; - if (bounds_offset != NULL) { + if (bounds_offset != nullptr) { copy_v2_v2_int(block->bounds_offset, bounds_offset); } else { @@ -775,7 +775,7 @@ uiBut *ui_but_find_old(uiBlock *block_old, const uiBut *but_new) return but; } } - return NULL; + return nullptr; } uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old) @@ -785,7 +785,7 @@ uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old) return but; } } - return NULL; + return nullptr; } static bool ui_but_extra_icons_equals_old(const uiButExtraOpIcon *new_extra_icon, @@ -803,7 +803,7 @@ static uiButExtraOpIcon *ui_but_extra_icon_find_old(const uiButExtraOpIcon *new_ return op_icon; } } - return NULL; + return nullptr; } static void ui_but_extra_icons_update_from_old_but(const uiBut *new_but, const uiBut *old_but) @@ -937,7 +937,7 @@ static bool ui_but_update_from_old_block(const bContext *C, uiBut *oldbut = ui_but_find_old(oldblock, but); UNUSED_VARS(but_old_p); #else - BLI_assert(*but_old_p == NULL || BLI_findindex(&oldblock->buttons, *but_old_p) != -1); + BLI_assert(*but_old_p == nullptr || BLI_findindex(&oldblock->buttons, *but_old_p) != -1); /* As long as old and new buttons are aligned, avoid loop-in-loop (calling #ui_but_find_old). */ uiBut *oldbut; @@ -948,7 +948,7 @@ static bool ui_but_update_from_old_block(const bContext *C, /* Fallback to block search. */ oldbut = ui_but_find_old(oldblock, but); } - (*but_old_p) = oldbut ? oldbut->next : NULL; + (*but_old_p) = oldbut ? oldbut->next : nullptr; #endif bool found_active = false; @@ -1136,7 +1136,7 @@ static void ui_menu_block_set_keyaccels(uiBlock *block) continue; } - if (but->str == NULL || but->str[0] == '\0') { + if (but->str == nullptr || but->str[0] == '\0') { continue; } @@ -1197,7 +1197,7 @@ void ui_but_add_shortcut(uiBut *but, const char *shortcut_str, const bool do_str } /* without this, just allow stripping of the shortcut */ - if (shortcut_str == NULL) { + if (shortcut_str == nullptr) { return; } @@ -1228,9 +1228,11 @@ static bool ui_but_event_operator_string_from_operator(const bContext *C, char *buf, const size_t buf_len) { - BLI_assert(op_call_params->optype != NULL); + BLI_assert(op_call_params->optype != nullptr); bool found = false; - IDProperty *prop = (op_call_params->opptr) ? op_call_params->opptr->data : NULL; + IDProperty *prop = reinterpret_cast<IDProperty *>(op_call_params->opptr) ? + static_cast<IDProperty *>(op_call_params->opptr->data) : + nullptr; if (WM_key_event_operator_string(C, op_call_params->optype->idname, @@ -1250,7 +1252,7 @@ static bool ui_but_event_operator_string_from_menu(const bContext *C, const size_t buf_len) { MenuType *mt = UI_but_menutype_get(but); - BLI_assert(mt != NULL); + BLI_assert(mt != nullptr); bool found = false; @@ -1275,35 +1277,28 @@ static bool ui_but_event_operator_string_from_panel(const bContext *C, { /** Nearly exact copy of #ui_but_event_operator_string_from_menu */ PanelType *pt = UI_but_paneltype_get(but); - BLI_assert(pt != NULL); + BLI_assert(pt != nullptr); bool found = false; /* annoying, create a property */ - const IDPropertyTemplate val = {0}; - IDProperty *prop_panel = IDP_New(IDP_GROUP, &val, __func__); /* Dummy, name is unimportant. */ + const IDPropertyTemplate group_val = {0}; + IDProperty *prop_panel = IDP_New( + IDP_GROUP, &group_val, __func__); /* Dummy, name is unimportant. */ IDP_AddToGroup(prop_panel, IDP_NewString(pt->idname, "name", sizeof(pt->idname))); - IDP_AddToGroup(prop_panel, - IDP_New(IDP_INT, - &(IDPropertyTemplate){ - .i = pt->space_type, - }, - "space_type")); - IDP_AddToGroup(prop_panel, - IDP_New(IDP_INT, - &(IDPropertyTemplate){ - .i = pt->region_type, - }, - "region_type")); + IDPropertyTemplate space_type_val = {0}; + space_type_val.i = pt->space_type; + IDP_AddToGroup(prop_panel, IDP_New(IDP_INT, &space_type_val, "space_type")); + IDPropertyTemplate region_type_val = {0}; + region_type_val.i = pt->region_type; + IDP_AddToGroup(prop_panel, IDP_New(IDP_INT, ®ion_type_val, "region_type")); for (int i = 0; i < 2; i++) { /* FIXME(campbell): We can't reasonably search all configurations - long term. */ - IDP_ReplaceInGroup(prop_panel, - IDP_New(IDP_INT, - &(IDPropertyTemplate){ - .i = i, - }, - "keep_open")); + IDPropertyTemplate val = {0}; + val.i = i; + + IDP_ReplaceInGroup(prop_panel, IDP_New(IDP_INT, &val, "keep_open")); if (WM_key_event_operator_string( C, "WM_OT_call_panel", WM_OP_INVOKE_REGION_WIN, prop_panel, true, buf, buf_len)) { found = true; @@ -1322,18 +1317,17 @@ static bool ui_but_event_operator_string(const bContext *C, { bool found = false; - if (but->optype != NULL) { - found = ui_but_event_operator_string_from_operator( - C, - &(wmOperatorCallParams){ - .optype = but->optype, .opptr = but->opptr, .opcontext = but->opcontext}, - buf, - buf_len); + if (but->optype != nullptr) { + wmOperatorCallParams params = {}; + params.optype = but->optype; + params.opptr = but->opptr; + params.opcontext = but->opcontext; + found = ui_but_event_operator_string_from_operator(C, ¶ms, buf, buf_len); } - else if (UI_but_menutype_get(but) != NULL) { + else if (UI_but_menutype_get(but) != nullptr) { found = ui_but_event_operator_string_from_menu(C, but, buf, buf_len); } - else if (UI_but_paneltype_get(but) != NULL) { + else if (UI_but_paneltype_get(but) != nullptr) { found = ui_but_event_operator_string_from_panel(C, but, buf, buf_len); } @@ -1370,17 +1364,17 @@ static bool ui_but_event_property_operator_string(const bContext *C, "WM_OT_context_cycle_enum", "WM_OT_context_cycle_array", "WM_OT_context_menu_enum", - NULL, + nullptr, }; const char *ctx_enum_opnames[] = { "WM_OT_context_set_enum", - NULL, + nullptr, }; const char *ctx_enum_opnames_for_Area_ui_type[] = { "SCREEN_OT_space_type_set_or_cycle", - NULL, + nullptr, }; const char **opnames = ctx_toggle_opnames; @@ -1393,7 +1387,7 @@ static bool ui_but_event_property_operator_string(const bContext *C, PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; int prop_index = but->rnaindex; - if ((but->type == UI_BTYPE_BUT_MENU) && (but->block->handle != NULL)) { + if ((but->type == UI_BTYPE_BUT_MENU) && (but->block->handle != nullptr)) { uiBut *but_parent = but->block->handle->popup_create_vars.but; if ((but->type == UI_BTYPE_BUT_MENU) && (but_parent && but_parent->rnaprop) && (RNA_property_type(but_parent->rnaprop) == PROP_ENUM) && @@ -1411,9 +1405,9 @@ static bool ui_but_event_property_operator_string(const bContext *C, } } /* Don't use the button again. */ - but = NULL; + but = nullptr; - if (prop == NULL) { + if (prop == nullptr) { return false; } @@ -1452,25 +1446,23 @@ static bool ui_but_event_property_operator_string(const bContext *C, /* Create a property to host the "data_path" property we're sending to the operators. */ IDProperty *prop_path; - const IDPropertyTemplate val = {0}; - prop_path = IDP_New(IDP_GROUP, &val, __func__); + const IDPropertyTemplate group_val = {0}; + prop_path = IDP_New(IDP_GROUP, &group_val, __func__); if (data_path) { IDP_AddToGroup(prop_path, IDP_NewString(data_path, "data_path", strlen(data_path) + 1)); } if (prop_enum_value_ok) { const EnumPropertyItem *item; bool free; - RNA_property_enum_items((bContext *)C, ptr, prop, &item, NULL, &free); + RNA_property_enum_items((bContext *)C, ptr, prop, &item, nullptr, &free); const int index = RNA_enum_from_value(item, prop_enum_value); if (index != -1) { IDProperty *prop_value; if (prop_enum_value_is_int) { const int value = item[index].value; - prop_value = IDP_New(IDP_INT, - &(IDPropertyTemplate){ - .i = value, - }, - prop_enum_value_id); + IDPropertyTemplate val = {}; + val.i = value; + prop_value = IDP_New(IDP_INT, &val, prop_enum_value_id); } else { const char *id = item[index].identifier; @@ -1627,25 +1619,23 @@ void ui_but_override_flag(Main *bmain, uiBut *but) /** * Predefined types for generic extra operator icons (uiButExtraOpIcon). */ -typedef enum PredefinedExtraOpIconType { +enum PredefinedExtraOpIconType { PREDEFINED_EXTRA_OP_ICON_NONE = 1, PREDEFINED_EXTRA_OP_ICON_CLEAR, PREDEFINED_EXTRA_OP_ICON_EYEDROPPER, -} PredefinedExtraOpIconType; +}; static PointerRNA *ui_but_extra_operator_icon_add_ptr(uiBut *but, wmOperatorType *optype, wmOperatorCallContext opcontext, int icon) { - uiButExtraOpIcon *extra_op_icon = MEM_mallocN(sizeof(*extra_op_icon), __func__); + uiButExtraOpIcon *extra_op_icon = MEM_new<uiButExtraOpIcon>(__func__); extra_op_icon->icon = (BIFIconID)icon; - extra_op_icon->optype_params = MEM_callocN(sizeof(*extra_op_icon->optype_params), - "uiButExtraOpIcon.optype_params"); + extra_op_icon->optype_params = MEM_cnew<wmOperatorCallParams>(__func__); extra_op_icon->optype_params->optype = optype; - extra_op_icon->optype_params->opptr = MEM_callocN(sizeof(*extra_op_icon->optype_params->opptr), - "uiButExtraOpIcon.optype_params.opptr"); + extra_op_icon->optype_params->opptr = MEM_cnew<PointerRNA>(__func__); WM_operator_properties_create_ptr(extra_op_icon->optype_params->opptr, extra_op_icon->optype_params->optype); extra_op_icon->optype_params->opcontext = opcontext; @@ -1684,12 +1674,12 @@ PointerRNA *UI_but_extra_operator_icon_add(uiBut *but, return ui_but_extra_operator_icon_add_ptr(but, optype, opcontext, icon); } - return NULL; + return nullptr; } wmOperatorType *UI_but_extra_operator_icon_optype_get(uiButExtraOpIcon *extra_icon) { - return extra_icon ? extra_icon->optype_params->optype : NULL; + return extra_icon ? extra_icon->optype_params->optype : nullptr; } PointerRNA *UI_but_extra_operator_icon_opptr_get(uiButExtraOpIcon *extra_icon) @@ -1706,21 +1696,22 @@ static bool ui_but_icon_extra_is_visible_text_clear(const uiBut *but) static bool ui_but_icon_extra_is_visible_search_unlink(const uiBut *but) { BLI_assert(ELEM(but->type, UI_BTYPE_SEARCH_MENU)); - return ((but->editstr == NULL) && (but->drawstr[0] != '\0') && (but->flag & UI_BUT_VALUE_CLEAR)); + return ((but->editstr == nullptr) && (but->drawstr[0] != '\0') && + (but->flag & UI_BUT_VALUE_CLEAR)); } static bool ui_but_icon_extra_is_visible_search_eyedropper(uiBut *but) { BLI_assert(but->type == UI_BTYPE_SEARCH_MENU && (but->flag & UI_BUT_VALUE_CLEAR)); - if (but->rnaprop == NULL) { + if (but->rnaprop == nullptr) { return false; } StructRNA *type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); const short idcode = RNA_type_to_ID_code(type); - return ((but->editstr == NULL) && (idcode == ID_OB || OB_DATA_SUPPORT_ID(idcode))); + return ((but->editstr == nullptr) && (idcode == ID_OB || OB_DATA_SUPPORT_ID(idcode))); } static PredefinedExtraOpIconType ui_but_icon_extra_get(uiBut *but) @@ -1757,12 +1748,12 @@ static PredefinedExtraOpIconType ui_but_icon_extra_get(uiBut *but) static void ui_but_predefined_extra_operator_icons_add(uiBut *but) { const PredefinedExtraOpIconType extra_icon = ui_but_icon_extra_get(but); - wmOperatorType *optype = NULL; + wmOperatorType *optype = nullptr; BIFIconID icon = ICON_NONE; switch (extra_icon) { case PREDEFINED_EXTRA_OP_ICON_EYEDROPPER: { - static wmOperatorType *id_eyedropper_ot = NULL; + static wmOperatorType *id_eyedropper_ot = nullptr; if (!id_eyedropper_ot) { id_eyedropper_ot = WM_operatortype_find("UI_OT_eyedropper_id", false); } @@ -1774,7 +1765,7 @@ static void ui_but_predefined_extra_operator_icons_add(uiBut *but) break; } case PREDEFINED_EXTRA_OP_ICON_CLEAR: { - static wmOperatorType *clear_ot = NULL; + static wmOperatorType *clear_ot = nullptr; if (!clear_ot) { clear_ot = WM_operatortype_find("UI_OT_button_string_clear", false); } @@ -1809,7 +1800,7 @@ void UI_block_update_from_old(const bContext *C, uiBlock *block) return; } - uiBut *but_old = block->oldblock->buttons.first; + uiBut *but_old = static_cast<uiBut *>(block->oldblock->buttons.first); if (BLI_listbase_is_empty(&block->oldblock->butstore) == false) { UI_butstore_update(block); @@ -1831,7 +1822,7 @@ void UI_block_update_from_old(const bContext *C, uiBlock *block) block->tooltipdisabled = block->oldblock->tooltipdisabled; BLI_movelisttolist(&block->color_pickers.list, &block->oldblock->color_pickers.list); - block->oldblock = NULL; + block->oldblock = nullptr; } #ifndef NDEBUG @@ -1865,7 +1856,7 @@ bool ui_but_context_poll_operator_ex(bContext *C, result = WM_operator_poll_context(C, optype_params->optype, optype_params->opcontext); if (but && but->context) { - CTX_store_set(C, NULL); + CTX_store_set(C, nullptr); } return result; @@ -1874,8 +1865,10 @@ bool ui_but_context_poll_operator_ex(bContext *C, bool ui_but_context_poll_operator(bContext *C, wmOperatorType *ot, const uiBut *but) { const wmOperatorCallContext opcontext = but ? but->opcontext : WM_OP_INVOKE_DEFAULT; - return ui_but_context_poll_operator_ex( - C, but, &(wmOperatorCallParams){.optype = ot, .opcontext = opcontext}); + wmOperatorCallParams params = {}; + params.optype = ot; + params.opcontext = opcontext; + return ui_but_context_poll_operator_ex(C, but, ¶ms); } void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_xy[2]) @@ -1903,7 +1896,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x if (but->optype) { wmOperatorType *ot = but->optype; - if (ot == NULL || !ui_but_context_poll_operator((bContext *)C, ot, but)) { + if (ot == nullptr || !ui_but_context_poll_operator((bContext *)C, ot, but)) { but->flag |= UI_BUT_DISABLED; } } @@ -1929,7 +1922,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x /* handle pending stuff */ if (block->layouts.first) { - UI_block_layout_resolve(block, NULL, NULL); + UI_block_layout_resolve(block, nullptr, nullptr); } ui_block_align_calc(block, CTX_wm_region(C)); if ((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) { @@ -1980,7 +1973,7 @@ void UI_block_end(const bContext *C, uiBlock *block) { wmWindow *window = CTX_wm_window(C); - UI_block_end_ex(C, block, window->eventstate->xy, NULL); + UI_block_end_ex(C, block, window->eventstate->xy, nullptr); } /* ************** BLOCK DRAWING FUNCTION ************* */ @@ -1990,8 +1983,11 @@ void ui_fontscale(float *points, float aspect) *points /= aspect; } -/* Project button or block (but==NULL) to pixels in region-space. */ -static void ui_but_to_pixelrect(rcti *rect, const ARegion *region, uiBlock *block, uiBut *but) +/* Project button or block (but==nullptr) to pixels in region-space. */ +static void ui_but_to_pixelrect(rcti *rect, + const ARegion *region, + uiBlock *block, + const uiBut *but) { rctf rectf; @@ -2004,7 +2000,7 @@ static bool ui_but_pixelrect_in_view(const ARegion *region, const rcti *rect) { rcti rect_winspace = *rect; BLI_rcti_translate(&rect_winspace, region->winrct.xmin, region->winrct.ymin); - return BLI_rcti_isect(®ion->winrct, &rect_winspace, NULL); + return BLI_rcti_isect(®ion->winrct, &rect_winspace, nullptr); } void UI_block_draw(const bContext *C, uiBlock *block) @@ -2032,7 +2028,7 @@ void UI_block_draw(const bContext *C, uiBlock *block) /* scale block min/max to rect */ rcti rect; - ui_but_to_pixelrect(&rect, region, block, NULL); + ui_but_to_pixelrect(&rect, region, block, nullptr); /* pixel space for AA widgets */ GPU_matrix_push_projection(); @@ -2094,7 +2090,7 @@ void UI_block_draw(const bContext *C, uiBlock *block) static void ui_block_message_subscribe(ARegion *region, struct wmMsgBus *mbus, uiBlock *block) { - uiBut *but_prev = NULL; + uiBut *but_prev = nullptr; /* possibly we should keep the region this block is contained in? */ LISTBASE_FOREACH (uiBut *, but, &block->buttons) { if (but->rnapoin.type && but->rnaprop) { @@ -2104,15 +2100,11 @@ static void ui_block_message_subscribe(ARegion *region, struct wmMsgBus *mbus, u (but_prev->rnapoin.data == but->rnapoin.data) && (but_prev->rnapoin.owner_id == but->rnapoin.owner_id)) == false) { /* TODO: could make this into utility function. */ - WM_msg_subscribe_rna(mbus, - &but->rnapoin, - but->rnaprop, - &(const wmMsgSubscribeValue){ - .owner = region, - .user_data = region, - .notify = ED_region_do_msg_notify_tag_redraw, - }, - __func__); + wmMsgSubscribeValue value = {}; + value.owner = region; + value.user_data = region; + value.notify = ED_region_do_msg_notify_tag_redraw; + WM_msg_subscribe_rna(mbus, &but->rnapoin, but->rnaprop, &value, __func__); but_prev = but; } } @@ -2256,7 +2248,7 @@ void UI_block_lock_set(uiBlock *block, bool val, const char *lockstr) void UI_block_lock_clear(uiBlock *block) { block->lock = false; - block->lockstr = NULL; + block->lockstr = nullptr; } /* *********************** data get/set *********************** @@ -2299,7 +2291,7 @@ void ui_but_v3_get(uiBut *but, float vec[3]) copy_v3_v3(vec, fp); } else { - if (but->editvec == NULL) { + if (but->editvec == nullptr) { fprintf(stderr, "%s: can't get color, should never happen\n", __func__); zero_v3(vec); } @@ -2449,7 +2441,7 @@ bool ui_but_is_compatible(const uiBut *but_a, const uiBut *but_b) bool ui_but_is_rna_valid(uiBut *but) { - if (but->rnaprop == NULL || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) { + if (but->rnaprop == nullptr || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) { return true; } printf("property removed %s: %p\n", but->drawstr, but->rnaprop); @@ -2461,7 +2453,7 @@ bool ui_but_supports_cycling(const uiBut *but) return (ELEM(but->type, UI_BTYPE_ROW, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER, UI_BTYPE_LISTBOX) || (but->type == UI_BTYPE_MENU && ui_but_menu_step_poll(but)) || (but->type == UI_BTYPE_COLOR && ((uiButColor *)but)->is_pallete_color) || - (but->menu_step_func != NULL)); + (but->menu_step_func != nullptr)); } double ui_but_value_get(uiBut *but) @@ -2471,7 +2463,7 @@ double ui_but_value_get(uiBut *but) if (but->editval) { return *(but->editval); } - if (but->poin == NULL && but->rnapoin.data == NULL) { + if (but->poin == nullptr && but->rnapoin.data == nullptr) { return 0.0; } @@ -2635,7 +2627,7 @@ int ui_but_string_get_max_length(uiBut *but) uiBut *ui_but_drag_multi_edit_get(uiBut *but) { - uiBut *return_but = NULL; + uiBut *return_but = nullptr; BLI_assert(but->flag & UI_BUT_DRAG_MULTI); @@ -2656,7 +2648,7 @@ static double ui_get_but_scale_unit(uiBut *but, double value) /* Time unit is a bit special, not handled by BKE_scene_unit_scale() for now. */ if (unit_type == PROP_UNIT_TIME) { /* WARNING: using evil_C :| */ - Scene *scene = CTX_data_scene(but->block->evil_C); + Scene *scene = CTX_data_scene(static_cast<const bContext *>(but->block->evil_C)); return FRA2TIME(value); } return BKE_scene_unit_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value); @@ -2768,7 +2760,7 @@ void ui_but_string_get_ex(uiBut *but, const PropertyType type = RNA_property_type(but->rnaprop); int buf_len; - const char *buf = NULL; + const char *buf = nullptr; if ((but->type == UI_BTYPE_TAB) && (but->custom_data)) { StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop); PointerRNA ptr; @@ -2785,7 +2777,11 @@ void ui_but_string_get_ex(uiBut *but, else if (type == PROP_ENUM) { /* RNA enum */ const int value = RNA_property_enum_get(&but->rnapoin, but->rnaprop); - if (RNA_property_enum_name(but->block->evil_C, &but->rnapoin, but->rnaprop, value, &buf)) { + if (RNA_property_enum_name(static_cast<bContext *>(but->block->evil_C), + &but->rnapoin, + but->rnaprop, + value, + &buf)) { BLI_strncpy(str, buf, maxlen); buf = str; } @@ -2799,7 +2795,7 @@ void ui_but_string_get_ex(uiBut *but, BLI_assert(0); } - if (buf == NULL) { + if (buf == nullptr) { str[0] = '\0'; } else if (buf != str) { @@ -2881,12 +2877,12 @@ void ui_but_string_get_ex(uiBut *but, } void ui_but_string_get(uiBut *but, char *str, const size_t maxlen) { - ui_but_string_get_ex(but, str, maxlen, -1, false, NULL); + ui_but_string_get_ex(but, str, maxlen, -1, false, nullptr); } char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) { - char *str = NULL; + char *str = nullptr; *r_str_size = 1; if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) { @@ -2894,15 +2890,18 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) if (type == PROP_STRING) { /* RNA string */ - str = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, NULL, 0, r_str_size); + str = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, nullptr, 0, r_str_size); (*r_str_size) += 1; } else if (type == PROP_ENUM) { /* RNA enum */ const int value = RNA_property_enum_get(&but->rnapoin, but->rnaprop); const char *value_id; - if (!RNA_property_enum_name( - but->block->evil_C, &but->rnapoin, but->rnaprop, value, &value_id)) { + if (!RNA_property_enum_name(static_cast<bContext *>(but->block->evil_C), + &but->rnapoin, + but->rnaprop, + value, + &value_id)) { value_id = ""; } @@ -2912,7 +2911,7 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) else if (type == PROP_POINTER) { /* RNA pointer */ PointerRNA ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop); - str = RNA_struct_name_get_alloc(&ptr, NULL, 0, r_str_size); + str = RNA_struct_name_get_alloc(&ptr, nullptr, 0, r_str_size); (*r_str_size) += 1; } else { @@ -2923,7 +2922,7 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) BLI_assert(0); } - if (UNLIKELY(str == NULL)) { + if (UNLIKELY(str == nullptr)) { /* should never happen, paranoid check */ *r_str_size = 1; str = BLI_strdup(""); @@ -2942,7 +2941,7 @@ char *ui_but_string_get_dynamic(uiBut *but, int *r_str_size) static bool ui_number_from_string_units( bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value) { - char *error = NULL; + char *error = nullptr; const bool ok = user_string_to_number(C, str, unit, unit_type, r_value, true, &error); if (error) { ReportList *reports = CTX_wm_reports(C); @@ -2966,11 +2965,10 @@ static bool ui_number_from_string(bContext *C, const char *str, double *r_value) { bool ok; #ifdef WITH_PYTHON - struct BPy_RunErrInfo err_info = { - .reports = CTX_wm_reports(C), - .report_prefix = UI_NUMBER_EVAL_ERROR_PREFIX, - }; - ok = BPY_run_string_as_number(C, NULL, str, &err_info, r_value); + BPy_RunErrInfo err_info = {}; + err_info.reports = CTX_wm_reports(C); + err_info.report_prefix = UI_NUMBER_EVAL_ERROR_PREFIX; + ok = BPY_run_string_as_number(C, nullptr, str, &err_info, r_value); #else UNUSED_VARS(C); *r_value = atof(str); @@ -3041,11 +3039,11 @@ bool ui_but_string_eval_number(bContext *C, const uiBut *but, const char *str, d static void ui_but_string_set_internal(uiBut *but, const char *str, size_t str_len) { BLI_assert(str_len == strlen(str)); - BLI_assert(but->str == NULL); + BLI_assert(but->str == nullptr); str_len += 1; if (str_len > UI_MAX_NAME_STR) { - but->str = MEM_mallocN(str_len, "ui_def_but str"); + but->str = static_cast<char *>(MEM_mallocN(str_len, "ui_def_but str")); } else { but->str = but->strdata; @@ -3060,7 +3058,7 @@ static void ui_but_string_free_internal(uiBut *but) MEM_freeN(but->str); } /* must call 'ui_but_string_set_internal' after */ - but->str = NULL; + but->str = nullptr; } } @@ -3078,11 +3076,12 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) if (type == PROP_POINTER) { if (str[0] == '\0') { - RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL, NULL); + RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL, nullptr); return true; } - uiButSearch *search_but = (but->type == UI_BTYPE_SEARCH_MENU) ? (uiButSearch *)but : NULL; + uiButSearch *search_but = (but->type == UI_BTYPE_SEARCH_MENU) ? (uiButSearch *)but : + nullptr; /* RNA pointer */ PointerRNA rptr; @@ -3095,14 +3094,14 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) if (search_but && search_but->rnasearchprop && RNA_property_collection_lookup_string( &search_but->rnasearchpoin, search_but->rnasearchprop, str, &rptr)) { - RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, NULL); + RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, nullptr); } - else if (search_but->item_active != NULL) { - RNA_pointer_create(NULL, + else if (search_but->item_active != nullptr) { + RNA_pointer_create(nullptr, RNA_property_pointer_type(&but->rnapoin, but->rnaprop), search_but->item_active, &rptr); - RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, NULL); + RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, nullptr); } return true; @@ -3110,8 +3109,11 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str) if (type == PROP_ENUM) { int value; - if (RNA_property_enum_value( - but->block->evil_C, &but->rnapoin, but->rnaprop, str, &value)) { + if (RNA_property_enum_value(static_cast<bContext *>(but->block->evil_C), + &but->rnapoin, + but->rnaprop, + str, + &value)) { RNA_property_enum_set(&but->rnapoin, but->rnaprop, value); return true; } @@ -3222,7 +3224,7 @@ static double soft_range_round_down(double value, double max) void ui_but_range_set_hard(uiBut *but) { - if (but->rnaprop == NULL) { + if (but->rnaprop == nullptr) { return; } @@ -3358,7 +3360,7 @@ static void ui_but_free_type_specific(uiBut *but) if (search_but->arg_free_fn) { search_but->arg_free_fn(search_but->arg); - search_but->arg = NULL; + search_but->arg = nullptr; } break; } @@ -3367,7 +3369,7 @@ static void ui_but_free_type_specific(uiBut *but) } } -/* can be called with C==NULL */ +/* can be called with C==nullptr */ static void ui_but_free(const bContext *C, uiBut *but) { if (but->opptr) { @@ -3425,7 +3427,7 @@ void UI_block_free(const bContext *C, uiBlock *block) UI_butstore_clear(block); uiBut *but; - while ((but = BLI_pophead(&block->buttons))) { + while ((but = static_cast<uiBut *>(BLI_pophead(&block->buttons)))) { ui_but_free(C, but); } @@ -3482,12 +3484,12 @@ void UI_blocklist_free(const bContext *C, ARegion *region) { ListBase *lb = ®ion->uiblocks; uiBlock *block; - while ((block = BLI_pophead(lb))) { + while ((block = static_cast<uiBlock *>(BLI_pophead(lb)))) { UI_block_free(C, block); } - if (region->runtime.block_name_map != NULL) { - BLI_ghash_free(region->runtime.block_name_map, NULL, NULL); - region->runtime.block_name_map = NULL; + if (region->runtime.block_name_map != nullptr) { + BLI_ghash_free(region->runtime.block_name_map, nullptr, nullptr); + region->runtime.block_name_map = nullptr; } } @@ -3501,10 +3503,11 @@ void UI_blocklist_free_inactive(const bContext *C, ARegion *region) block->active = false; } else { - if (region->runtime.block_name_map != NULL) { - uiBlock *b = BLI_ghash_lookup(region->runtime.block_name_map, block->name); + if (region->runtime.block_name_map != nullptr) { + uiBlock *b = static_cast<uiBlock *>( + BLI_ghash_lookup(region->runtime.block_name_map, block->name)); if (b == block) { - BLI_ghash_remove(region->runtime.block_name_map, b->name, NULL, NULL); + BLI_ghash_remove(region->runtime.block_name_map, b->name, nullptr, nullptr); } } BLI_remlink(lb, block); @@ -3517,25 +3520,25 @@ void UI_blocklist_free_inactive(const bContext *C, ARegion *region) void UI_block_region_set(uiBlock *block, ARegion *region) { ListBase *lb = ®ion->uiblocks; - uiBlock *oldblock = NULL; + uiBlock *oldblock = nullptr; /* each listbase only has one block with this name, free block * if is already there so it can be rebuilt from scratch */ if (lb) { - if (region->runtime.block_name_map == NULL) { + if (region->runtime.block_name_map == nullptr) { region->runtime.block_name_map = BLI_ghash_str_new(__func__); } oldblock = (uiBlock *)BLI_ghash_lookup(region->runtime.block_name_map, block->name); if (oldblock) { oldblock->active = false; - oldblock->panel = NULL; - oldblock->handle = NULL; + oldblock->panel = nullptr; + oldblock->handle = nullptr; } /* at the beginning of the list! for dynamical menus/blocks */ BLI_addhead(lb, block); - BLI_ghash_reinsert(region->runtime.block_name_map, block->name, block, NULL, NULL); + BLI_ghash_reinsert(region->runtime.block_name_map, block->name, block, nullptr, nullptr); } block->oldblock = oldblock; @@ -3546,7 +3549,7 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, eU wmWindow *window = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); - uiBlock *block = MEM_callocN(sizeof(uiBlock), "uiBlock"); + uiBlock *block = MEM_cnew<uiBlock>(__func__); block->active = true; block->emboss = emboss; block->evil_C = (void *)C; /* XXX */ @@ -3562,7 +3565,7 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, eU STRNCPY(block->display_device, scene->display_settings.display_device); /* copy to avoid crash when scene gets deleted with ui still open */ - block->unit = MEM_mallocN(sizeof(scene->unit), "UI UnitSettings"); + block->unit = MEM_new<UnitSettings>(__func__); memcpy(block->unit, &scene->unit, sizeof(scene->unit)); } else { @@ -3694,7 +3697,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate) /* only update soft range while not editing */ if (!ui_but_is_editing(but)) { - if ((but->rnaprop != NULL) || (but->poin && (but->pointype & UI_BUT_POIN_TYPES))) { + if ((but->rnaprop != nullptr) || (but->poin && (but->pointype & UI_BUT_POIN_TYPES))) { ui_but_range_set_soft(but); } } @@ -3720,7 +3723,8 @@ static void ui_but_update_ex(uiBut *but, const bool validate) case UI_BTYPE_ICON_TOGGLE: case UI_BTYPE_ICON_TOGGLE_N: - if ((but->rnaprop == NULL) || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) { + if ((but->rnaprop == nullptr) || + (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE)) { if (but->rnaprop && RNA_property_flag(but->rnaprop) & PROP_ICONS_REVERSE) { but->drawflag |= UI_BUT_ICON_REVERSE; } @@ -3749,11 +3753,15 @@ static void ui_but_update_ex(uiBut *but, const bool validate) EnumPropertyItem item; if (RNA_property_enum_item_from_value_gettexted( - but->block->evil_C, &but->rnapoin, but->rnaprop, value_enum, &item)) { + static_cast<bContext *>(but->block->evil_C), + &but->rnapoin, + but->rnaprop, + value_enum, + &item)) { const size_t slen = strlen(item.name); ui_but_string_free_internal(but); ui_but_string_set_internal(but, item.name, slen); - but->icon = item.icon; + but->icon = (BIFIconID)item.icon; } } } @@ -3973,9 +3981,9 @@ static uiBut *ui_but_alloc(const eButType type) { size_t alloc_size; const char *alloc_str; - ui_but_alloc_info(type, &alloc_size, &alloc_str, NULL); + ui_but_alloc_info(type, &alloc_size, &alloc_str, nullptr); - return MEM_callocN(alloc_size, alloc_str); + return static_cast<uiBut *>(MEM_callocN(alloc_size, alloc_str)); } uiBut *ui_but_change_type(uiBut *but, eButType new_type) @@ -3993,7 +4001,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type) /* Remove old button address */ BLI_remlink(&but->block->buttons, but); - ui_but_alloc_info(but->type, NULL, NULL, &old_has_custom_type); + ui_but_alloc_info(but->type, nullptr, nullptr, &old_has_custom_type); ui_but_alloc_info(new_type, &alloc_size, &alloc_str, &new_has_custom_type); if (new_has_custom_type || old_has_custom_type) { @@ -4002,7 +4010,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type) const bool has_str_ptr_to_self = but->str == but->strdata; const bool has_poin_ptr_to_self = but->poin == (char *)but; - but = MEM_recallocN_id(but, alloc_size, alloc_str); + but = static_cast<uiBut *>(MEM_recallocN_id(but, alloc_size, alloc_str)); but->type = new_type; if (has_str_ptr_to_self) { but->str = but->strdata; @@ -4021,7 +4029,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type) } #ifdef WITH_PYTHON if (UI_editsource_enable_check()) { - UI_editsource_but_replace(old_but_ptr, but); + UI_editsource_but_replace(static_cast<const uiBut *>(old_but_ptr), but); } #endif } @@ -4059,21 +4067,21 @@ static uiBut *ui_def_but(uiBlock *block, /* we could do some more error checks here */ if ((type & BUTTYPE) == UI_BTYPE_LABEL) { - BLI_assert((poin != NULL || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || + BLI_assert((poin != nullptr || min != 0.0f || max != 0.0f || (a1 == 0.0f && a2 != 0.0f) || (a1 != 0.0f && a1 != 1.0f)) == false); } if (type & UI_BUT_POIN_TYPES) { /* a pointer is required */ - if (poin == NULL) { + if (poin == nullptr) { BLI_assert(0); - return NULL; + return nullptr; } } - uiBut *but = ui_but_alloc(type & BUTTYPE); + uiBut *but = ui_but_alloc((eButType)(type & BUTTYPE)); - but->type = type & BUTTYPE; - but->pointype = type & UI_BUT_POIN_TYPES; + but->type = (eButType)(type & BUTTYPE); + but->pointype = (eButPointerType)(type & UI_BUT_POIN_TYPES); but->bit = type & UI_BUT_POIN_BIT; but->bitnr = type & 31; but->icon = ICON_NONE; @@ -4089,7 +4097,7 @@ static uiBut *ui_def_but(uiBlock *block, but->rect.xmax = but->rect.xmin + width; but->rect.ymax = but->rect.ymin + height; - but->poin = poin; + but->poin = (char *)poin; but->hardmin = but->softmin = min; but->hardmax = but->softmax = max; but->a1 = a1; @@ -4201,7 +4209,9 @@ static uiBut *ui_def_but(uiBlock *block, void ui_def_but_icon(uiBut *but, const int icon, const int flag) { if (icon) { - ui_icon_ensure_deferred(but->block->evil_C, icon, (flag & UI_BUT_ICON_PREVIEW) != 0); + ui_icon_ensure_deferred(static_cast<const bContext *>(but->block->evil_C), + icon, + (flag & UI_BUT_ICON_PREVIEW) != 0); } but->icon = (BIFIconID)icon; but->flag |= flag; @@ -4230,8 +4240,12 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); bool free; - RNA_property_enum_items_gettexted( - block->evil_C, &but->rnapoin, but->rnaprop, &item_array, NULL, &free); + RNA_property_enum_items_gettexted(static_cast<bContext *>(block->evil_C), + &but->rnapoin, + but->rnaprop, + &item_array, + nullptr, + &free); /* We don't want nested rows, cols in menus. */ UI_block_layout_set_current(block, layout); @@ -4274,8 +4288,20 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu if (title[0] && (categories == 0) && (block->flag & UI_BLOCK_NO_FLIP)) { /* Title at the top for menus with categories. */ - uiDefBut( - block, UI_BTYPE_LABEL, 0, title, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + uiDefBut(block, + UI_BTYPE_LABEL, + 0, + title, + 0, + 0, + UI_UNIT_X * 5, + UI_UNIT_Y, + nullptr, + 0.0, + 0.0, + 0, + 0, + ""); uiItemS(layout); } @@ -4287,7 +4313,7 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu bool new_column; int column_end = 0; - uiLayout *column = NULL; + uiLayout *column = nullptr; for (int a = 0; a < totitems; a++) { new_column = (a == column_end); if (new_column) { @@ -4331,7 +4357,7 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu 0, UI_UNIT_X * 5, UI_UNIT_Y, - NULL, + nullptr, 0.0, 0.0, 0, @@ -4381,8 +4407,20 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu if (title[0] && (categories == 0) && !(block->flag & UI_BLOCK_NO_FLIP)) { /* Title at the bottom for menus without categories. */ uiItemS(layout); - uiDefBut( - block, UI_BTYPE_LABEL, 0, title, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + uiDefBut(block, + UI_BTYPE_LABEL, + 0, + title, + 0, + 0, + UI_UNIT_X * 5, + UI_UNIT_Y, + nullptr, + 0.0, + 0.0, + 0, + 0, + ""); } UI_block_layout_set_current(block, layout); @@ -4396,8 +4434,8 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu static void ui_def_but_rna__panel_type(bContext *C, uiLayout *layout, void *but_p) { - uiBut *but = but_p; - const char *panel_type = but->func_argN; + uiBut *but = static_cast<uiBut *>(but_p); + const char *panel_type = static_cast<const char *>(but->func_argN); PanelType *pt = WM_paneltype_find(panel_type, true); if (pt) { ui_item_paneltype_func(C, layout, pt); @@ -4425,8 +4463,8 @@ bool ui_but_menu_draw_as_popover(const uiBut *but) static void ui_def_but_rna__menu_type(bContext *C, uiLayout *layout, void *but_p) { - uiBut *but = but_p; - const char *menu_type = but->func_argN; + uiBut *but = static_cast<uiBut *>(but_p); + const char *menu_type = static_cast<const char *>(but->func_argN); MenuType *mt = WM_menutype_find(menu_type, true); if (mt) { ui_item_menutype_func(C, layout, mt); @@ -4480,7 +4518,7 @@ static uiBut *ui_def_but_rna(uiBlock *block, { const PropertyType proptype = RNA_property_type(prop); int icon = 0; - uiMenuCreateFunc func = NULL; + uiMenuCreateFunc func = nullptr; const bool always_set_a1_a2 = ELEM(type, UI_BTYPE_NUM); if (ELEM(type, UI_BTYPE_COLOR, UI_BTYPE_HSVCIRCLE, UI_BTYPE_HSVCUBE)) { @@ -4491,7 +4529,8 @@ static uiBut *ui_def_but_rna(uiBlock *block, if ((proptype == PROP_ENUM) && ELEM(type, UI_BTYPE_MENU, UI_BTYPE_ROW, UI_BTYPE_LISTROW)) { bool free; const EnumPropertyItem *item; - RNA_property_enum_items(block->evil_C, ptr, prop, &item, NULL, &free); + RNA_property_enum_items( + static_cast<bContext *>(block->evil_C), ptr, prop, &item, nullptr, &free); int value; /* UI_BTYPE_MENU is handled a little differently here */ @@ -4588,7 +4627,7 @@ static uiBut *ui_def_but_rna(uiBlock *block, /* now create button */ uiBut *but = ui_def_but( - block, type, retval, str, x, y, width, height, NULL, min, max, a1, a2, tip); + block, type, retval, str, x, y, width, height, nullptr, min, max, a1, a2, tip); if (but->type == UI_BTYPE_NUM) { /* Set default values, can be overridden later. */ @@ -4685,7 +4724,7 @@ static uiBut *ui_def_but_rna_propname(uiBlock *block, } else { but = ui_def_but( - block, type, retval, propname, x, y, width, height, NULL, min, max, a1, a2, tip); + block, type, retval, propname, x, y, width, height, nullptr, min, max, a1, a2, tip); UI_but_disable(but, "Unknown Property."); } @@ -4706,7 +4745,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, { if (!str) { if (ot && ot->srna) { - str = WM_operatortype_name(ot, NULL); + str = WM_operatortype_name(ot, nullptr); } else { str = ""; @@ -4717,7 +4756,7 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, tip = RNA_struct_ui_description(ot->srna); } - uiBut *but = ui_def_but(block, type, -1, str, x, y, width, height, NULL, 0, 0, 0, 0, tip); + uiBut *but = ui_def_but(block, type, -1, str, x, y, width, height, nullptr, 0, 0, 0, 0, tip); but->optype = ot; but->opcontext = opcontext; but->flag &= ~UI_BUT_UNDO; /* no need for ui_but_is_rna_undo(), we never need undo here */ @@ -4772,7 +4811,7 @@ uiBut *uiDefButImage( uiBut *uiDefButAlert(uiBlock *block, int icon, int x, int y, short width, short height) { - struct ImBuf *ibuf = UI_icon_alert_imbuf_get(icon); + struct ImBuf *ibuf = UI_icon_alert_imbuf_get((eAlertIcon)icon); bTheme *btheme = UI_GetTheme(); return uiDefButImage(block, ibuf, x, y, width, height, btheme->tui.wcol_menu_back.text); } @@ -4828,10 +4867,10 @@ AutoComplete *UI_autocomplete_begin(const char *startname, size_t maxlen) { AutoComplete *autocpl; - autocpl = MEM_callocN(sizeof(AutoComplete), "AutoComplete"); + autocpl = MEM_cnew<AutoComplete>(__func__); autocpl->maxlen = maxlen; autocpl->matches = 0; - autocpl->truncate = MEM_callocN(sizeof(char) * maxlen, "AutoCompleteTruncate"); + autocpl->truncate = static_cast<char *>(MEM_callocN(sizeof(char) * maxlen, __func__)); autocpl->startname = startname; return autocpl; @@ -4921,7 +4960,7 @@ static uiBut *uiDefButBit(uiBlock *block, { const int bitIdx = findBitIndex(bit); if (bitIdx == -1) { - return NULL; + return nullptr; } return uiDefBut(block, type | UI_BUT_POIN_BIT | bitIdx, @@ -5225,8 +5264,8 @@ uiBut *uiDefButO(uiBlock *block, short height, const char *tip) { - wmOperatorType *ot = WM_operatortype_find(opname, 0); - if (str == NULL && ot == NULL) { + wmOperatorType *ot = WM_operatortype_find(opname, false); + if (str == nullptr && ot == nullptr) { str = opname; } return uiDefButO_ptr(block, type, ot, opcontext, str, x, y, width, height, tip); @@ -5270,7 +5309,7 @@ static uiBut *uiDefIconButBit(uiBlock *block, { const int bitIdx = findBitIndex(bit); if (bitIdx == -1) { - return NULL; + return nullptr; } return uiDefIconBut(block, type | UI_BUT_POIN_BIT | bitIdx, @@ -5515,7 +5554,7 @@ uiBut *uiDefIconButO(uiBlock *block, short height, const char *tip) { - wmOperatorType *ot = WM_operatortype_find(opname, 0); + wmOperatorType *ot = WM_operatortype_find(opname, false); return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip); } @@ -5682,7 +5721,7 @@ uiBut *uiDefIconTextButO(uiBlock *block, short height, const char *tip) { - wmOperatorType *ot = WM_operatortype_find(opname, 0); + wmOperatorType *ot = WM_operatortype_find(opname, false); if (str && str[0] == '\0') { return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip); } @@ -5836,7 +5875,7 @@ void UI_but_drag_set_asset(uiBut *but, * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its * copy callback. * */ - asset_drag->evil_C = but->block->evil_C; + asset_drag->evil_C = static_cast<bContext *>(but->block->evil_C); but->dragtype = WM_DRAG_ASSET; ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */ @@ -5905,7 +5944,7 @@ void UI_but_drag_set_image( PointerRNA *UI_but_operator_ptr_get(uiBut *but) { if (but->optype && !but->opptr) { - but->opptr = MEM_callocN(sizeof(PointerRNA), "uiButOpPtr"); + but->opptr = MEM_cnew<PointerRNA>(__func__); WM_operator_properties_create_ptr(but->opptr, but->optype); } @@ -5930,7 +5969,7 @@ int UI_but_unit_type_get(const uiBut *but) * default value provided in RNA in a few special cases (i.e. Active Keyframe in Graph Edit) */ /* XXX: this doesn't allow clearing unit completely, though the same could be said for icons */ - if ((ownUnit != 0) || (but->rnaprop == NULL)) { + if ((ownUnit != 0) || (but->rnaprop == nullptr)) { return ownUnit << 16; } return RNA_SUBTYPE_UNIT(RNA_property_subtype(but->rnaprop)); @@ -6057,7 +6096,7 @@ uiBut *uiDefBlockButN(uiBlock *block, const char *tip) { uiBut *but = ui_def_but( - block, UI_BTYPE_BLOCK, 0, str, x, y, width, height, NULL, 0.0, 0.0, 0.0, 0.0, tip); + block, UI_BTYPE_BLOCK, 0, str, x, y, width, height, nullptr, 0.0, 0.0, 0.0, 0.0, tip); but->block_create_func = func; if (but->func_argN) { MEM_freeN(but->func_argN); @@ -6298,13 +6337,13 @@ void UI_but_func_search_set(uiBut *but, /* needed since callers don't have access to internal functions * (as an alternative we could expose it) */ - if (search_create_fn == NULL) { + if (search_create_fn == nullptr) { search_create_fn = ui_searchbox_create_generic; } - if (search_but->arg_free_fn != NULL) { + if (search_but->arg_free_fn != nullptr) { search_but->arg_free_fn(search_but->arg); - search_but->arg = NULL; + search_but->arg = nullptr; } search_but->popup_create_fn = search_create_fn; @@ -6322,12 +6361,12 @@ void UI_but_func_search_set(uiBut *but, __func__); } #endif - /* Handling will pass the active item as arg2 later, so keep it NULL here. */ + /* Handling will pass the active item as arg2 later, so keep it nullptr here. */ if (free_arg) { - UI_but_funcN_set(but, search_exec_fn, search_but->arg, NULL); + UI_but_funcN_set(but, search_exec_fn, search_but->arg, nullptr); } else { - UI_but_func_set(but, search_exec_fn, search_but->arg, NULL); + UI_but_func_set(but, search_exec_fn, search_but->arg, nullptr); } } @@ -6383,7 +6422,7 @@ static void operator_enum_search_update_fn(const struct bContext *C, wmOperatorType *ot = ((uiBut *)but)->optype; PropertyRNA *prop = ot->prop; - if (prop == NULL) { + if (prop == nullptr) { printf("%s: %s has no enum property set\n", __func__, ot->idname); } else if (RNA_property_type(prop) != PROP_ENUM) { @@ -6393,11 +6432,12 @@ static void operator_enum_search_update_fn(const struct bContext *C, RNA_property_identifier(prop)); } else { - PointerRNA *ptr = UI_but_operator_ptr_get(but); /* Will create it if needed! */ + /* Will create it if needed! */ + PointerRNA *ptr = UI_but_operator_ptr_get(static_cast<uiBut *>(but)); bool do_free; const EnumPropertyItem *all_items; - RNA_property_enum_items_gettexted((bContext *)C, ptr, prop, &all_items, NULL, &do_free); + RNA_property_enum_items_gettexted((bContext *)C, ptr, prop, &all_items, nullptr, &do_free); StringSearch *search = BLI_string_search_new(); for (const EnumPropertyItem *item = all_items; item->identifier; item++) { @@ -6429,7 +6469,8 @@ 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) { wmOperatorType *ot = ((uiBut *)but)->optype; - PointerRNA *opptr = UI_but_operator_ptr_get(but); /* Will create it if needed! */ + /* Will create it if needed! */ + PointerRNA *opptr = UI_but_operator_ptr_get(static_cast<uiBut *>(but)); if (ot) { if (ot->prop) { @@ -6440,7 +6481,7 @@ static void operator_enum_search_exec_fn(struct bContext *UNUSED(C), void *but, * because one of its parameters is the button itself! */ } else { - printf("%s: op->prop for '%s' is NULL\n", __func__, ot->idname); + printf("%s: op->prop for '%s' is nullptr\n", __func__, ot->idname); } } } @@ -6466,9 +6507,9 @@ uiBut *uiDefSearchButO_ptr(uiBlock *block, operator_enum_search_update_fn, but, false, - NULL, + nullptr, operator_enum_search_exec_fn, - NULL); + nullptr); but->optype = ot; but->opcontext = WM_OP_EXEC_DEFAULT; @@ -6529,7 +6570,7 @@ void UI_but_focus_on_enter_event(wmWindow *win, uiBut *but) event.type = EVT_BUT_OPEN; event.val = KM_PRESS; - event.flag = 0; + event.flag = static_cast<eWM_EventFlag>(0); event.customdata = but; event.customdata_free = false; @@ -6547,14 +6588,14 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) va_list args; uiStringInfo *si; - const EnumPropertyItem *items = NULL, *item = NULL; + const EnumPropertyItem *items = nullptr, *item = nullptr; int totitems; bool free_items = false; va_start(args, but); while ((si = (uiStringInfo *)va_arg(args, void *))) { uiStringInfoType type = si->type; - char *tmp = NULL; + char *tmp = nullptr; if (type == BUT_GET_LABEL) { if (but->str && but->str[0]) { @@ -6650,19 +6691,19 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) } } - if (tmp == NULL) { - wmOperatorType *ot = UI_but_operatortype_get_from_enum_menu(but, NULL); + if (tmp == nullptr) { + wmOperatorType *ot = UI_but_operatortype_get_from_enum_menu(but, nullptr); if (ot) { if (type == BUT_GET_RNA_LABEL) { - tmp = BLI_strdup(WM_operatortype_name(ot, NULL)); + tmp = BLI_strdup(WM_operatortype_name(ot, nullptr)); } else { - tmp = WM_operatortype_description(C, ot, NULL); + tmp = WM_operatortype_description(C, ot, nullptr); } } } - if (tmp == NULL) { + if (tmp == nullptr) { PanelType *pt = UI_but_paneltype_get(but); if (pt) { if (type == BUT_GET_RNA_LABEL) { @@ -6698,8 +6739,8 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...) tmp = BLI_strdup(_tmp); } else if (ELEM(type, BUT_GET_RNAENUM_IDENTIFIER, BUT_GET_RNAENUM_LABEL, BUT_GET_RNAENUM_TIP)) { - PointerRNA *ptr = NULL; - PropertyRNA *prop = NULL; + PointerRNA *ptr = nullptr; + PropertyRNA *prop = nullptr; int value = 0; /* get the enum property... */ @@ -6791,7 +6832,7 @@ void UI_but_extra_icon_string_info_get(struct bContext *C, uiButExtraOpIcon *ext va_start(args, extra_icon); while ((si = (uiStringInfo *)va_arg(args, void *))) { - char *tmp = NULL; + char *tmp = nullptr; switch (si->type) { case BUT_GET_LABEL: |