diff options
author | Hans Goudey <h.goudey@me.com> | 2022-04-02 23:07:36 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-04-02 23:07:36 +0300 |
commit | 6450f380acc6e1ded72ff8372adcd79dd486abc0 (patch) | |
tree | 9a179ed7b182c4fef20fd652b8e1075fd8beb6d7 | |
parent | 1051c17af3714f43ee9004092f11ce0a2c01154c (diff) |
Cleanup: Move more interface files to C++
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 6 | ||||
-rw-r--r-- | source/blender/editors/interface/CMakeLists.txt | 18 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_color_picker.cc (renamed from source/blender/editors/interface/interface_region_color_picker.c) | 71 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_hud.cc (renamed from source/blender/editors/interface/interface_region_hud.c) | 64 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_menu_pie.cc (renamed from source/blender/editors/interface/interface_region_menu_pie.c) | 39 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_menu_popup.cc (renamed from source/blender/editors/interface/interface_region_menu_popup.c) | 81 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.cc (renamed from source/blender/editors/interface/interface_region_popover.c) | 57 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popup.cc (renamed from source/blender/editors/interface/interface_region_popup.c) | 44 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.cc (renamed from source/blender/editors/interface/interface_regions.c) | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.cc (renamed from source/blender/editors/interface/interface_style.c) | 50 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_utils.cc (renamed from source/blender/editors/interface/interface_utils.c) | 129 |
12 files changed, 288 insertions, 277 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 74797f91046..a4508cb5b6d 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -634,7 +634,7 @@ uiPopupMenu *UI_popup_menu_begin_ex(struct bContext *C, * Set the whole structure to work. */ void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *pup); -bool UI_popup_menu_end_or_cancel(struct bContext *C, struct uiPopupMenu *head); +bool UI_popup_menu_end_or_cancel(struct bContext *C, struct uiPopupMenu *pup); struct uiLayout *UI_popup_menu_layout(uiPopupMenu *pup); void UI_popup_menu_reports(struct bContext *C, struct ReportList *reports) ATTR_NONNULL(); @@ -1595,13 +1595,15 @@ typedef enum { } eButLabelAlign; /* Return info for uiDefAutoButsRNA */ -typedef enum { +typedef enum eAutoPropButsReturn { /* Returns when no buttons were added */ UI_PROP_BUTS_NONE_ADDED = 1 << 0, /* Returned when any property failed the custom check callback (check_prop) */ UI_PROP_BUTS_ANY_FAILED_CHECK = 1 << 1, } eAutoPropButsReturn; +ENUM_OPERATORS(eAutoPropButsReturn, UI_PROP_BUTS_ANY_FAILED_CHECK); + uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index e298d595294..a1ee5c38838 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -47,16 +47,16 @@ set(SRC interface_ops.c interface_panel.c interface_query.cc - interface_region_color_picker.c - interface_region_hud.c - interface_region_menu_pie.c - interface_region_menu_popup.c - interface_region_popover.c - interface_region_popup.c + interface_region_color_picker.cc + interface_region_hud.cc + interface_region_menu_pie.cc + interface_region_menu_popup.cc + interface_region_popover.cc + interface_region_popup.cc interface_region_search.cc interface_region_tooltip.c - interface_regions.c - interface_style.c + interface_regions.cc + interface_style.cc interface_template_asset_view.cc interface_template_attribute_search.cc interface_template_list.cc @@ -64,7 +64,7 @@ set(SRC interface_template_search_operator.c interface_templates.c interface_undo.c - interface_utils.c + interface_utils.cc interface_view.cc interface_widgets.c resources.c diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index ddea37e8dfe..e619b14fb69 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -954,7 +954,7 @@ void ui_pie_menu_level_create(uiBlock *block, const EnumPropertyItem *items, int totitem, wmOperatorCallContext context, - int flag); + wmOperatorCallContext flag); /* interface_region_popup.c */ diff --git a/source/blender/editors/interface/interface_region_color_picker.c b/source/blender/editors/interface/interface_region_color_picker.cc index 9fb6f538191..ab0a6039cdc 100644 --- a/source/blender/editors/interface/interface_region_color_picker.c +++ b/source/blender/editors/interface/interface_region_color_picker.cc @@ -7,9 +7,9 @@ * Color Picker Region & Color Utils */ -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> +#include <cstdarg> +#include <cstdlib> +#include <cstring> #include "MEM_guardedalloc.h" @@ -168,7 +168,7 @@ static void ui_color_picker_update_hsv(ColorPicker *cpicker, void ui_but_hsv_set(uiBut *but) { float rgb_perceptual[3]; - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data); float *hsv_perceptual = cpicker->hsv_perceptual; ui_color_picker_hsv_to_rgb(hsv_perceptual, rgb_perceptual); @@ -255,7 +255,8 @@ static void ui_colorpicker_rgba_update_cb(bContext *UNUSED(C), void *bt1, void * if (prop) { RNA_property_float_get_array(&ptr, prop, rgb_scene_linear); - ui_update_color_picker_buts_rgb(but, but->block, but->custom_data, rgb_scene_linear); + ui_update_color_picker_buts_rgb( + but, but->block, static_cast<ColorPicker *>(but->custom_data), rgb_scene_linear); } if (popup) { @@ -268,7 +269,7 @@ static void ui_colorpicker_hsv_update_cb(bContext *UNUSED(C), void *bt1, void *U uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; float rgb_scene_linear[3]; - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data); ui_color_picker_hsv_to_rgb(cpicker->hsv_scene_linear, rgb_scene_linear); ui_update_color_picker_buts_rgb(but, but->block, cpicker, rgb_scene_linear); @@ -282,7 +283,7 @@ static void ui_colorpicker_hex_rna_cb(bContext *UNUSED(C), void *bt1, void *hexc { uiBut *but = (uiBut *)bt1; uiPopupBlockHandle *popup = but->block->handle; - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data); char *hexcol = (char *)hexcl; float rgb[3]; @@ -307,7 +308,7 @@ static void ui_popup_close_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) uiPopupBlockHandle *popup = but->block->handle; if (popup) { - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data); BLI_assert(cpicker->is_init); popup->menuretval = (equals_v3v3(cpicker->hsv_perceptual, cpicker->hsv_perceptual_init) ? UI_RETURN_CANCEL : @@ -315,7 +316,7 @@ static void ui_popup_close_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) } } -static void ui_colorpicker_hide_reveal(uiBlock *block, enum ePickerType colormode) +static void ui_colorpicker_hide_reveal(uiBlock *block, ePickerType colormode) { /* tag buttons */ LISTBASE_FOREACH (uiBut *, bt, &block->buttons) { @@ -337,9 +338,9 @@ static void ui_colorpicker_hide_reveal(uiBlock *block, enum ePickerType colormod static void ui_colorpicker_create_mode_cb(bContext *UNUSED(C), void *bt1, void *UNUSED(arg)) { - uiBut *bt = bt1; + uiBut *bt = static_cast<uiBut *>(bt1); const short colormode = ui_but_value_get(bt); - ui_colorpicker_hide_reveal(bt->block, colormode); + ui_colorpicker_hide_reveal(bt->block, (ePickerType)colormode); } #define PICKER_H (7.5f * U.widget_unit) @@ -374,7 +375,7 @@ static void ui_colorpicker_circle(uiBlock *block, 0.0, 0, TIP_("Color")); - UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr); bt->custom_data = cpicker; /* value */ @@ -396,7 +397,7 @@ static void ui_colorpicker_circle(uiBlock *block, 0, "Lightness"); hsv_but->gradient_type = UI_GRAD_L_ALT; - UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, NULL); + UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, nullptr); } else { hsv_but = (uiButHSVCube *)uiDefButR_prop(block, @@ -416,7 +417,7 @@ static void ui_colorpicker_circle(uiBlock *block, 0, TIP_("Value")); hsv_but->gradient_type = UI_GRAD_V_ALT; - UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, NULL); + UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, nullptr); } hsv_but->but.custom_data = cpicker; } @@ -449,7 +450,7 @@ static void ui_colorpicker_square(uiBlock *block, 0, TIP_("Color")); hsv_but->gradient_type = type; - UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, NULL); + UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, nullptr); hsv_but->but.custom_data = cpicker; /* value */ @@ -469,8 +470,8 @@ static void ui_colorpicker_square(uiBlock *block, 0, 0, TIP_("Value")); - hsv_but->gradient_type = type + 3; - UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, NULL); + hsv_but->gradient_type = (eButGradientType)(type + 3); + UI_but_func_set(&hsv_but->but, ui_colorpicker_rgba_update_cb, &hsv_but->but, nullptr); hsv_but->but.custom_data = cpicker; } @@ -547,7 +548,7 @@ static void ui_block_colorpicker(uiBlock *block, ""); UI_but_flag_disable(bt, UI_BUT_UNDO); UI_but_drawflag_disable(bt, UI_BUT_TEXT_LEFT); - UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, nullptr); bt->custom_data = cpicker; bt = uiDefButC(block, UI_BTYPE_ROW, @@ -565,7 +566,7 @@ static void ui_block_colorpicker(uiBlock *block, ""); UI_but_flag_disable(bt, UI_BUT_UNDO); UI_but_drawflag_disable(bt, UI_BUT_TEXT_LEFT); - UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, nullptr); bt->custom_data = cpicker; bt = uiDefButC(block, UI_BTYPE_ROW, @@ -583,7 +584,7 @@ static void ui_block_colorpicker(uiBlock *block, ""); UI_but_flag_disable(bt, UI_BUT_UNDO); UI_but_drawflag_disable(bt, UI_BUT_TEXT_LEFT); - UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_create_mode_cb, bt, nullptr); bt->custom_data = cpicker; UI_block_align_end(block); @@ -598,10 +599,10 @@ static void ui_block_colorpicker(uiBlock *block, yco, UI_UNIT_X, UI_UNIT_Y, - NULL); + nullptr); UI_but_flag_disable(bt, UI_BUT_UNDO); UI_but_drawflag_disable(bt, UI_BUT_ICON_LEFT); - UI_but_func_set(bt, ui_popup_close_cb, bt, NULL); + UI_but_func_set(bt, ui_popup_close_cb, bt, nullptr); bt->custom_data = cpicker; } @@ -625,7 +626,7 @@ static void ui_block_colorpicker(uiBlock *block, 0, 3, TIP_("Red")); - UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr); bt->custom_data = cpicker; bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, @@ -643,7 +644,7 @@ static void ui_block_colorpicker(uiBlock *block, 0, 3, TIP_("Green")); - UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr); bt->custom_data = cpicker; bt = uiDefButR_prop(block, UI_BTYPE_NUM_SLIDER, @@ -661,7 +662,7 @@ static void ui_block_colorpicker(uiBlock *block, 0, 3, TIP_("Blue")); - UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr); bt->custom_data = cpicker; /* Could use: @@ -686,7 +687,7 @@ static void ui_block_colorpicker(uiBlock *block, 3, TIP_("Hue")); UI_but_flag_disable(bt, UI_BUT_UNDO); - UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, nullptr); bt->custom_data = cpicker; bt = uiDefButF(block, UI_BTYPE_NUM_SLIDER, @@ -703,7 +704,7 @@ static void ui_block_colorpicker(uiBlock *block, 3, TIP_("Saturation")); UI_but_flag_disable(bt, UI_BUT_UNDO); - UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, nullptr); bt->custom_data = cpicker; if (U.color_picker_type == USER_CP_CIRCLE_HSL) { bt = uiDefButF(block, @@ -740,7 +741,7 @@ static void ui_block_colorpicker(uiBlock *block, UI_but_flag_disable(bt, UI_BUT_UNDO); bt->hardmax = hardmax; /* not common but rgb may be over 1.0 */ - UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_hsv_update_cb, bt, nullptr); bt->custom_data = cpicker; UI_block_align_end(block); @@ -762,7 +763,7 @@ static void ui_block_colorpicker(uiBlock *block, 0, 3, TIP_("Alpha")); - UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, NULL); + UI_but_func_set(bt, ui_colorpicker_rgba_update_cb, bt, nullptr); bt->custom_data = cpicker; } else { @@ -809,14 +810,14 @@ static void ui_block_colorpicker(uiBlock *block, yco - UI_UNIT_Y, butwidth, UI_UNIT_Y, - NULL, + nullptr, 0.0, 0.0, 0, 0, ""); - ui_colorpicker_hide_reveal(block, colormode); + ui_colorpicker_hide_reveal(block, (ePickerType)colormode); } static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), @@ -834,9 +835,9 @@ static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), if (add != 0.0f) { LISTBASE_FOREACH (uiBut *, but, &block->buttons) { - if (but->type == UI_BTYPE_HSVCUBE && but->active == NULL) { + if (but->type == UI_BTYPE_HSVCUBE && but->active == nullptr) { uiPopupBlockHandle *popup = block->handle; - ColorPicker *cpicker = but->custom_data; + ColorPicker *cpicker = static_cast<ColorPicker *>(but->custom_data); float *hsv_perceptual = cpicker->hsv_perceptual; float rgb_perceptual[3]; @@ -865,7 +866,7 @@ static int ui_colorpicker_small_wheel_cb(const bContext *UNUSED(C), uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_but) { - uiBut *but = arg_but; + uiBut *but = static_cast<uiBut *>(arg_but); uiBlock *block; bool show_picker = true; @@ -901,7 +902,7 @@ uiBlock *ui_block_func_COLOR(bContext *C, uiPopupBlockHandle *handle, void *arg_ ColorPicker *ui_block_colorpicker_create(struct uiBlock *block) { - ColorPicker *cpicker = MEM_callocN(sizeof(ColorPicker), "color_picker"); + ColorPicker *cpicker = MEM_cnew<ColorPicker>(__func__); BLI_addhead(&block->color_pickers.list, cpicker); return cpicker; diff --git a/source/blender/editors/interface/interface_region_hud.c b/source/blender/editors/interface/interface_region_hud.cc index 4d72cd5382c..d6166694a4a 100644 --- a/source/blender/editors/interface/interface_region_hud.c +++ b/source/blender/editors/interface/interface_region_hud.cc @@ -7,7 +7,7 @@ * Floating Persistent Region */ -#include <string.h> +#include <cstring> #include "MEM_guardedalloc.h" @@ -49,7 +49,7 @@ struct HudRegionData { static bool last_redo_poll(const bContext *C, short region_type) { wmOperator *op = WM_operator_last_redo(C); - if (op == NULL) { + if (op == nullptr) { return false; } @@ -60,7 +60,8 @@ static bool last_redo_poll(const bContext *C, short region_type) * wrong context. */ ScrArea *area = CTX_wm_area(C); - ARegion *region_op = (region_type != -1) ? BKE_area_find_region_type(area, region_type) : NULL; + ARegion *region_op = (region_type != -1) ? BKE_area_find_region_type(area, region_type) : + nullptr; ARegion *region_prev = CTX_wm_region(C); CTX_wm_region_set((bContext *)C, region_op); @@ -90,9 +91,9 @@ static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt { ScrArea *area = CTX_wm_area(C); ARegion *region = BKE_area_find_region_type(area, RGN_TYPE_HUD); - if (region != NULL) { - struct HudRegionData *hrd = region->regiondata; - if (hrd != NULL) { + if (region != nullptr) { + HudRegionData *hrd = static_cast<HudRegionData *>(region->regiondata); + if (hrd != nullptr) { return last_redo_poll(C, hrd->regionid); } } @@ -108,7 +109,7 @@ static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *panel) static void hud_panel_operator_redo_draw(const bContext *C, Panel *panel) { wmOperator *op = WM_operator_last_redo(C); - if (op == NULL) { + if (op == nullptr) { return; } if (!WM_operator_check_ui_enabled(C, op->type->name)) { @@ -120,9 +121,7 @@ static void hud_panel_operator_redo_draw(const bContext *C, Panel *panel) static void hud_panels_register(ARegionType *art, int space_type, int region_type) { - PanelType *pt; - - pt = MEM_callocN(sizeof(PanelType), __func__); + PanelType *pt = MEM_cnew<PanelType>(__func__); strcpy(pt->idname, "OPERATOR_PT_redo"); strcpy(pt->label, N_("Redo")); strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA); @@ -155,8 +154,8 @@ static void hud_region_free(ARegion *region) static void hud_region_layout(const bContext *C, ARegion *region) { - struct HudRegionData *hrd = region->regiondata; - if (hrd == NULL || !last_redo_poll(C, hrd->regionid)) { + HudRegionData *hrd = static_cast<HudRegionData *>(region->regiondata); + if (hrd == nullptr || !last_redo_poll(C, hrd->regionid)) { ED_region_tag_redraw(region); hud_region_hide(region); return; @@ -205,19 +204,17 @@ static void hud_region_draw(const bContext *C, ARegion *region) GPU_clear_color(0.0f, 0.0f, 0.0f, 0.0f); if ((region->flag & RGN_FLAG_HIDDEN) == 0) { - ui_draw_menu_back(NULL, - NULL, - &(rcti){ - .xmax = region->winx, - .ymax = region->winy, - }); + rcti reset_rect = {}; + reset_rect.xmax = region->winx; + reset_rect.ymax = region->winy; + ui_draw_menu_back(nullptr, nullptr, &reset_rect); ED_region_panels_draw(C, region); } } ARegionType *ED_area_type_hud(int space_type) { - ARegionType *art = MEM_callocN(sizeof(ARegionType), __func__); + ARegionType *art = MEM_cnew<ARegionType>(__func__); art->regionid = RGN_TYPE_HUD; art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D; art->layout = hud_region_layout; @@ -238,7 +235,7 @@ ARegionType *ED_area_type_hud(int space_type) static ARegion *hud_region_add(ScrArea *area) { - ARegion *region = MEM_callocN(sizeof(ARegion), "area region"); + ARegion *region = MEM_cnew<ARegion>(__func__); ARegion *region_win = BKE_area_find_region_type(area, RGN_TYPE_WINDOW); if (region_win) { BLI_insertlinkbefore(&area->regionbase, region_win, region); @@ -288,7 +285,7 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) ED_area_type_hud_clear(wm, area); ARegionType *art = BKE_regiontype_from_id(area->type, RGN_TYPE_HUD); - if (art == NULL) { + if (art == nullptr) { return; } @@ -301,9 +298,9 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) } bool init = false; - const bool was_hidden = region == NULL || region->visible == false; + const bool was_hidden = region == nullptr || region->visible == false; ARegion *region_op = CTX_wm_region(C); - BLI_assert((region_op == NULL) || (region_op->regiontype != RGN_TYPE_HUD)); + BLI_assert((region_op == nullptr) || (region_op->regiontype != RGN_TYPE_HUD)); if (!last_redo_poll(C, region_op ? region_op->regiontype : -1)) { if (region) { ED_region_tag_redraw(region); @@ -312,7 +309,7 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) return; } - if (region == NULL) { + if (region == nullptr) { init = true; region = hud_region_add(area); region->type = art; @@ -332,9 +329,9 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) } { - struct HudRegionData *hrd = region->regiondata; - if (hrd == NULL) { - hrd = MEM_callocN(sizeof(*hrd), __func__); + HudRegionData *hrd = static_cast<HudRegionData *>(region->regiondata); + if (hrd == nullptr) { + hrd = MEM_cnew<HudRegionData>(__func__); region->regiondata = hrd; } if (region_op) { @@ -355,10 +352,10 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) ED_region_tag_redraw(region); /* Reset zoom level (not well supported). */ - region->v2d.cur = region->v2d.tot = (rctf){ - .xmax = region->winx, - .ymax = region->winy, - }; + rctf reset_rect = {}; + reset_rect.xmax = region->winx; + reset_rect.ymax = region->winy; + region->v2d.cur = region->v2d.tot = reset_rect; region->v2d.minzoom = 1.0f; region->v2d.maxzoom = 1.0f; @@ -373,10 +370,7 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *area) if (was_hidden) { region->winx = region->v2d.winx; region->winy = region->v2d.winy; - region->v2d.cur = region->v2d.tot = (rctf){ - .xmax = region->winx, - .ymax = region->winy, - }; + region->v2d.cur = region->v2d.tot = reset_rect; } CTX_wm_region_set((bContext *)C, region_prev); } diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.cc index 74e128f3098..586aeef44fd 100644 --- a/source/blender/editors/interface/interface_region_menu_pie.c +++ b/source/blender/editors/interface/interface_region_menu_pie.cc @@ -7,9 +7,9 @@ * Pie Menu Region */ -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> +#include <cstdarg> +#include <cstdlib> +#include <cstring> #include "MEM_guardedalloc.h" @@ -51,7 +51,7 @@ struct uiPieMenu { static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handle, void *arg_pie) { uiBlock *block; - uiPieMenu *pie = arg_pie; + uiPieMenu *pie = static_cast<uiPieMenu *>(arg_pie); int minwidth, width, height; minwidth = UI_MENU_WIDTH_MIN; @@ -89,14 +89,13 @@ static float ui_pie_menu_title_width(const char *name, int icon) uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, const wmEvent *event) { const uiStyle *style = UI_style_get_dpi(); - uiPieMenu *pie; short event_type; wmWindow *win = CTX_wm_window(C); - pie = MEM_callocN(sizeof(*pie), "pie menu"); + uiPieMenu *pie = MEM_cnew<uiPieMenu>(__func__); - pie->block_radial = UI_block_begin(C, NULL, __func__, UI_EMBOSS); + pie->block_radial = UI_block_begin(C, nullptr, __func__, UI_EMBOSS); /* may be useful later to allow spawning pies * from old positions */ /* pie->block_radial->flag |= UI_BLOCK_POPUP_MEMORY; */ @@ -153,7 +152,7 @@ uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, co 0, w, UI_UNIT_Y, - NULL, + nullptr, 0.0, 0.0, 0, @@ -170,7 +169,7 @@ uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, co 0, w, UI_UNIT_Y, - NULL, + nullptr, 0.0, 0.0, 0, @@ -191,7 +190,7 @@ void UI_pie_menu_end(bContext *C, uiPieMenu *pie) wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *menu; - menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_PIE, pie, NULL); + menu = ui_popup_block_create(C, nullptr, nullptr, nullptr, ui_block_func_PIE, pie, nullptr); menu->popup = true; menu->towardstime = PIL_check_seconds_timer(); @@ -212,7 +211,7 @@ int UI_pie_menu_invoke(struct bContext *C, const char *idname, const wmEvent *ev uiLayout *layout; MenuType *mt = WM_menutype_find(idname, true); - if (mt == NULL) { + if (mt == nullptr) { printf("%s: named menu \"%s\" not found\n", __func__, idname); return OPERATOR_CANCELLED; } @@ -263,7 +262,7 @@ int UI_pie_menu_invoke_from_rna_enum(struct bContext *C, uiPieMenu *pie; uiLayout *layout; - RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); + RNA_pointer_create(nullptr, &RNA_Context, C, &ctx_ptr); if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) { return OPERATOR_CANCELLED; @@ -280,7 +279,7 @@ int UI_pie_menu_invoke_from_rna_enum(struct bContext *C, layout = UI_pie_menu_layout(pie); layout = uiLayoutRadial(layout); - uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0); + uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, nullptr, 0); UI_pie_menu_end(C, pie); @@ -304,7 +303,7 @@ int UI_pie_menu_invoke_from_rna_enum(struct bContext *C, * - Julian (Feb 2016) * \{ */ -typedef struct PieMenuLevelData { + struct PieMenuLevelData { char title[UI_MAX_NAME_STR]; /* parent pie title, copied for level */ int icon; /* parent pie icon, copied for level */ int totitem; /* total count of *remaining* items */ @@ -314,7 +313,7 @@ typedef struct PieMenuLevelData { const char *propname; IDProperty *properties; wmOperatorCallContext context, flag; -} PieMenuLevelData; +} ; /** * Invokes a new pie menu for a new level. @@ -362,17 +361,17 @@ void ui_pie_menu_level_create(uiBlock *block, const EnumPropertyItem *items, int totitem, wmOperatorCallContext context, - int flag) + wmOperatorCallContext flag) { const int totitem_parent = PIE_MAX_ITEMS - 1; const int totitem_remain = totitem - totitem_parent; const size_t array_size = sizeof(EnumPropertyItem) * totitem_remain; /* used as but->func_argN so freeing is handled elsewhere */ - EnumPropertyItem *remaining = MEM_mallocN(array_size + sizeof(EnumPropertyItem), - "pie_level_item_array"); + EnumPropertyItem *remaining = static_cast<EnumPropertyItem *>( + MEM_mallocN(array_size + sizeof(EnumPropertyItem), "pie_level_item_array")); memcpy(remaining, items + totitem_parent, array_size); - /* A NULL terminating sentinel element is required. */ + /* A nullptr terminating sentinel element is required. */ memset(&remaining[totitem_remain], 0, sizeof(EnumPropertyItem)); /* yuk, static... issue is we can't reliably free this without doing dangerous changes */ @@ -395,7 +394,7 @@ void ui_pie_menu_level_create(uiBlock *block, 0, UI_UNIT_X * 3, UI_UNIT_Y, - NULL, + nullptr, 0.0f, 0.0f, 0.0f, diff --git a/source/blender/editors/interface/interface_region_menu_popup.c b/source/blender/editors/interface/interface_region_menu_popup.cc index 7d8f4315710..e843a275d08 100644 --- a/source/blender/editors/interface/interface_region_menu_popup.c +++ b/source/blender/editors/interface/interface_region_menu_popup.cc @@ -7,9 +7,9 @@ * PopUp Menu Region */ -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> +#include <cstdarg> +#include <cstdlib> +#include <cstring> #include "MEM_guardedalloc.h" @@ -50,7 +50,7 @@ bool ui_but_menu_step_poll(const uiBut *but) BLI_assert(but->type == UI_BTYPE_MENU); /* currently only RNA buttons */ - return ((but->menu_step_func != NULL) || + return ((but->menu_step_func != nullptr) || (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM)); } @@ -58,12 +58,16 @@ int ui_but_menu_step(uiBut *but, int direction) { if (ui_but_menu_step_poll(but)) { if (but->menu_step_func) { - return but->menu_step_func(but->block->evil_C, direction, but->poin); + return but->menu_step_func( + static_cast<bContext *>(but->block->evil_C), direction, but->poin); } const int curval = RNA_property_enum_get(&but->rnapoin, but->rnaprop); - return RNA_property_enum_step( - but->block->evil_C, &but->rnapoin, but->rnaprop, curval, direction); + return RNA_property_enum_step(static_cast<bContext *>(but->block->evil_C), + &but->rnapoin, + but->rnaprop, + curval, + direction); } printf("%s: cannot cycle button '%s'\n", __func__, but->str); @@ -85,7 +89,7 @@ static uint ui_popup_string_hash(const char *str, const bool use_sep) { /* sometimes button contains hotkey, sometimes not, strip for proper compare */ int hash; - const char *delimit = use_sep ? strrchr(str, UI_SEP_CHAR) : NULL; + const char *delimit = use_sep ? strrchr(str, UI_SEP_CHAR) : nullptr; if (delimit) { hash = BLI_ghashutil_strhash_n(str, delimit - str); @@ -102,7 +106,7 @@ uint ui_popup_menu_hash(const char *str) return BLI_ghashutil_strhash(str); } -/* but == NULL read, otherwise set */ +/* but == nullptr read, otherwise set */ static uiBut *ui_popup_menu_memory__internal(uiBlock *block, uiBut *but) { static uint mem[256]; @@ -114,13 +118,13 @@ static uiBut *ui_popup_menu_memory__internal(uiBlock *block, uiBut *but) if (first) { /* init */ memset(mem, -1, sizeof(mem)); - first = 0; + first = false; } if (but) { /* set */ mem[hash_mod] = ui_popup_string_hash(but->str, but->flag & UI_BUT_HAS_SEP_CHAR); - return NULL; + return nullptr; } /* get */ @@ -131,12 +135,12 @@ static uiBut *ui_popup_menu_memory__internal(uiBlock *block, uiBut *but) } } - return NULL; + return nullptr; } uiBut *ui_popup_menu_memory_get(uiBlock *block) { - return ui_popup_menu_memory__internal(block, NULL); + return ui_popup_menu_memory__internal(block, nullptr); } void ui_popup_menu_memory_set(uiBlock *block, uiBut *but) @@ -166,7 +170,7 @@ struct uiPopupMenu { static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, void *arg_pup) { uiBlock *block; - uiPopupMenu *pup = arg_pup; + uiPopupMenu *pup = static_cast<uiPopupMenu *>(arg_pup); int minwidth, width, height; char direction; bool flip; @@ -174,7 +178,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi if (pup->menu_func) { pup->block->handle = handle; pup->menu_func(C, pup->layout, pup->menu_arg); - pup->block->handle = NULL; + pup->block->handle = nullptr; } /* Find block minimum width. */ @@ -229,7 +233,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi if (pup->popup) { int offset[2]; - uiBut *but_activate = NULL; + uiBut *but_activate = nullptr; UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_NUMSELECT); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); UI_block_direction_set(block, direction); @@ -309,10 +313,9 @@ uiPopupBlockHandle *ui_popup_menu_create( wmWindow *window = CTX_wm_window(C); const uiStyle *style = UI_style_get_dpi(); uiPopupBlockHandle *handle; - uiPopupMenu *pup; - pup = MEM_callocN(sizeof(uiPopupMenu), __func__); - pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS_PULLDOWN); + 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); @@ -348,7 +351,7 @@ uiPopupBlockHandle *ui_popup_menu_create( pup->menu_func = menu_func; pup->menu_arg = arg; - handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup, NULL); + handle = ui_popup_block_create(C, butregion, but, nullptr, ui_block_func_POPUP, pup, nullptr); if (!but) { handle->popup = true; @@ -374,10 +377,10 @@ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, int icon) { const uiStyle *style = UI_style_get_dpi(); - uiPopupMenu *pup = MEM_callocN(sizeof(uiPopupMenu), "popup menu"); + uiPopupMenu *pup = MEM_cnew<uiPopupMenu>(__func__); uiBut *but; - pup->block = UI_block_begin(C, NULL, block_name, UI_EMBOSS_PULLDOWN); + 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( @@ -389,7 +392,7 @@ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, uiLayoutSetOperatorContext(pup->layout, WM_OP_EXEC_REGION_WIN); /* create in advance so we can let buttons point to retval already */ - pup->block->handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); + pup->block->handle = MEM_cnew<uiPopupBlockHandle>(__func__); /* create title button */ if (title[0]) { @@ -406,7 +409,7 @@ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, 0, 200, UI_UNIT_Y, - NULL, + nullptr, 0.0, 0.0, 0, @@ -415,7 +418,7 @@ uiPopupMenu *UI_popup_menu_begin_ex(bContext *C, } else { but = uiDefBut( - pup->block, UI_BTYPE_LABEL, 0, title, 0, 0, 200, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); + 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; } @@ -440,8 +443,8 @@ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *menu; - uiBut *but = NULL; - ARegion *butregion = NULL; + uiBut *but = nullptr; + ARegion *butregion = nullptr; pup->popup = true; pup->mx = window->eventstate->xy[0]; @@ -452,7 +455,7 @@ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) butregion = pup->butregion; } - menu = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup, NULL); + 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); @@ -467,7 +470,7 @@ bool UI_popup_menu_end_or_cancel(bContext *C, uiPopupMenu *pup) UI_popup_menu_end(C, pup); return true; } - UI_block_layout_resolve(pup->block, NULL, NULL); + UI_block_layout_resolve(pup->block, nullptr, nullptr); MEM_freeN(pup->block->handle); UI_block_free(C, pup->block); MEM_freeN(pup); @@ -487,7 +490,7 @@ uiLayout *UI_popup_menu_layout(uiPopupMenu *pup) void UI_popup_menu_reports(bContext *C, ReportList *reports) { - uiPopupMenu *pup = NULL; + uiPopupMenu *pup = nullptr; uiLayout *layout; if (!CTX_wm_window(C)) { @@ -502,7 +505,7 @@ void UI_popup_menu_reports(bContext *C, ReportList *reports) continue; } - if (pup == NULL) { + if (pup == nullptr) { char title[UI_MAX_DRAW_STR]; BLI_snprintf(title, sizeof(title), "%s: %s", IFACE_("Report"), report->typestr); /* popup_menu stuff does just what we need (but pass meaningful block name) */ @@ -540,7 +543,7 @@ int UI_popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) uiLayout *layout; MenuType *mt = WM_menutype_find(idname, true); - if (mt == NULL) { + if (mt == nullptr) { BKE_reportf(reports, RPT_ERROR, "Menu \"%s\" not found", idname); return OPERATOR_CANCELLED; } @@ -572,7 +575,7 @@ void UI_popup_block_invoke_ex( wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *handle; - handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg, arg_free); + 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) @@ -580,7 +583,8 @@ void UI_popup_block_invoke_ex( handle->can_refresh = can_refresh; UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); - UI_block_active_only_flagged_buttons(C, handle->region, handle->region->uiblocks.first); + UI_block_active_only_flagged_buttons( + C, handle->region, static_cast<uiBlock *>(handle->region->uiblocks.first)); WM_event_add_mousemove(window); } @@ -599,7 +603,7 @@ void UI_popup_block_ex(bContext *C, wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *handle; - handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg, NULL); + handle = ui_popup_block_create(C, nullptr, nullptr, func, nullptr, arg, nullptr); handle->popup = true; handle->retvalue = 1; handle->can_refresh = true; @@ -611,7 +615,8 @@ void UI_popup_block_ex(bContext *C, // handle->opcontext = opcontext; UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); - UI_block_active_only_flagged_buttons(C, handle->region, handle->region->uiblocks.first); + UI_block_active_only_flagged_buttons( + C, handle->region, static_cast<uiBlock *>(handle->region->uiblocks.first)); WM_event_add_mousemove(window); } @@ -621,7 +626,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, wmO wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *handle; - handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op, NULL); + handle = ui_popup_block_create(C, nullptr, nullptr, func, nullptr, op, nullptr); handle->popup = 1; handle->retvalue = 1; handle->can_refresh = true; @@ -638,7 +643,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, wmO void UI_popup_block_close(bContext *C, wmWindow *win, uiBlock *block) { - /* if loading new .blend while popup is open, window will be NULL */ + /* if loading new .blend while popup is open, window will be nullptr */ if (block->handle) { if (win) { const bScreen *screen = WM_window_get_active_screen(win); diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.cc index 7c7c9e887dd..2e10261a4f7 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.cc @@ -80,7 +80,7 @@ static void ui_popover_create_block(bContext *C, uiPopover *pup, wmOperatorCallC const uiStyle *style = UI_style_get_dpi(); - pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS); + pup->block = UI_block_begin(C, nullptr, __func__, UI_EMBOSS); UI_block_flag_enable(pup->block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER); #ifdef USE_UI_POPOVER_ONCE if (pup->is_once) { @@ -104,7 +104,7 @@ static void ui_popover_create_block(bContext *C, uiPopover *pup, wmOperatorCallC static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, void *arg_pup) { - uiPopover *pup = arg_pup; + uiPopover *pup = static_cast<uiPopover *>(arg_pup); /* Create UI block and layout now if it wasn't done between begin/end. */ if (!pup->layout) { @@ -113,10 +113,10 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v if (pup->menu_func) { pup->block->handle = handle; pup->menu_func(C, pup->layout, pup->menu_arg); - pup->block->handle = NULL; + pup->block->handle = nullptr; } - pup->layout = NULL; + pup->layout = nullptr; } /* Setup and resolve UI layout for block. */ @@ -185,10 +185,10 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v block->minbounds = UI_MENU_WIDTH_MIN; if (!handle->refresh) { - uiBut *but = NULL; - uiBut *but_first = NULL; + uiBut *but = nullptr; + uiBut *but_first = nullptr; LISTBASE_FOREACH (uiBut *, but_iter, &block->buttons) { - if ((but_first == NULL) && ui_but_is_editable(but_iter)) { + if ((but_first == nullptr) && ui_but_is_editable(but_iter)) { but_first = but_iter; } if (but_iter->flag & (UI_SELECT | UI_SELECT_DRAW)) { @@ -219,8 +219,8 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v static void ui_block_free_func_POPOVER(void *arg_pup) { - uiPopover *pup = arg_pup; - if (pup->keymap != NULL) { + uiPopover *pup = static_cast<uiPopover *>(arg_pup); + if (pup->keymap != nullptr) { wmWindow *window = pup->window; WM_event_remove_keymap_handler(&window->modalhandlers, pup->keymap); } @@ -235,7 +235,7 @@ uiPopupBlockHandle *ui_popover_panel_create( const PanelType *panel_type = (PanelType *)arg; /* Create popover, buttons are created from callback. */ - uiPopover *pup = MEM_callocN(sizeof(uiPopover), __func__); + uiPopover *pup = MEM_cnew<uiPopover>(__func__); pup->but = but; /* FIXME: maybe one day we want non panel popovers? */ @@ -262,7 +262,7 @@ uiPopupBlockHandle *ui_popover_panel_create( /* Create popup block. */ uiPopupBlockHandle *handle; handle = ui_popup_block_create( - C, butregion, but, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); + C, butregion, but, nullptr, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); handle->can_refresh = true; /* Add handlers. If attached to a button, the button will already @@ -286,7 +286,7 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep { uiLayout *layout; PanelType *pt = WM_paneltype_find(idname, true); - if (pt == NULL) { + if (pt == nullptr) { BKE_reportf(reports, RPT_ERROR, "Panel \"%s\" not found", idname); return OPERATOR_CANCELLED; } @@ -296,23 +296,23 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } - uiBlock *block = NULL; + uiBlock *block = nullptr; if (keep_open) { uiPopupBlockHandle *handle = ui_popover_panel_create( - C, NULL, NULL, ui_item_paneltype_func, pt); - uiPopover *pup = handle->popup_create_vars.arg; + C, nullptr, nullptr, ui_item_paneltype_func, pt); + uiPopover *pup = static_cast<uiPopover *>(handle->popup_create_vars.arg); block = pup->block; } else { uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x, false); layout = UI_popover_layout(pup); UI_paneltype_draw(C, pt, layout); - UI_popover_end(C, pup, NULL); + UI_popover_end(C, pup, nullptr); block = pup->block; } if (block) { - uiPopupBlockHandle *handle = block->handle; + uiPopupBlockHandle *handle = static_cast<uiPopupBlockHandle *>(block->handle); UI_block_active_only_flagged_buttons(C, handle->region, block); } return OPERATOR_INTERFACE; @@ -326,20 +326,20 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep uiPopover *UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_button) { - uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu"); + uiPopover *pup = MEM_cnew<uiPopover>(__func__); if (ui_menu_width == 0) { ui_menu_width = U.widget_unit * UI_POPOVER_WIDTH_UNITS; } pup->ui_size_x = ui_menu_width; - ARegion *butregion = NULL; - uiBut *but = NULL; + ARegion *butregion = nullptr; + uiBut *but = nullptr; if (from_active_button) { butregion = CTX_wm_region(C); but = UI_region_active_but_get(butregion); - if (but == NULL) { - butregion = NULL; + if (but == nullptr) { + butregion = nullptr; } } @@ -350,14 +350,14 @@ uiPopover *UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_but ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN); /* create in advance so we can let buttons point to retval already */ - pup->block->handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); + pup->block->handle = MEM_cnew<uiPopupBlockHandle>(__func__); return pup; } static void popover_keymap_fn(wmKeyMap *UNUSED(keymap), wmKeyMapItem *UNUSED(kmi), void *user_data) { - uiPopover *pup = user_data; + uiPopover *pup = static_cast<uiPopover *>(user_data); pup->block->handle->menuretval = UI_RETURN_OK; } @@ -376,8 +376,13 @@ void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap) WM_event_set_keymap_handler_post_callback(pup->keymap_handler, popover_keymap_fn, pup); } - handle = ui_popup_block_create( - C, pup->butregion, pup->but, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); + handle = ui_popup_block_create(C, + pup->butregion, + pup->but, + nullptr, + ui_block_func_POPOVER, + pup, + ui_block_free_func_POPOVER); /* Add handlers. */ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.cc index 2f2556225b5..74c228e3338 100644 --- a/source/blender/editors/interface/interface_region_popup.c +++ b/source/blender/editors/interface/interface_region_popup.cc @@ -7,9 +7,9 @@ * PopUp Region (Generic) */ -#include <stdarg.h> -#include <stdlib.h> -#include <string.h> +#include <cstdarg> +#include <cstdlib> +#include <cstring> #include "MEM_guardedalloc.h" @@ -120,7 +120,7 @@ static void ui_popup_block_position(wmWindow *window, short dir1 = 0, dir2 = 0; if (!handle->refresh) { - bool left = 0, right = 0, top = 0, down = 0; + bool left = false, right = false, top = false, down = false; const int win_x = WM_window_pixels_x(window); const int win_y = WM_window_pixels_y(window); @@ -131,24 +131,24 @@ static void ui_popup_block_position(wmWindow *window, /* check if there's space at all */ if (butrct.xmin - max_size_x + center_x > 0.0f) { - left = 1; + left = true; } if (butrct.xmax + max_size_x - center_x < win_x) { - right = 1; + right = true; } if (butrct.ymin - max_size_y + center_y > 0.0f) { - down = 1; + down = true; } if (butrct.ymax + max_size_y - center_y < win_y) { - top = 1; + top = true; } if (top == 0 && down == 0) { if (butrct.ymin - max_size_y < win_y - butrct.ymax - max_size_y) { - top = 1; + top = true; } else { - down = 1; + down = true; } } @@ -335,7 +335,7 @@ static void ui_popup_block_position(wmWindow *window, } /* Keep a list of these, needed for pull-down menus. */ - uiSafetyRct *saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); + uiSafetyRct *saferct = MEM_cnew<uiSafetyRct>(__func__); saferct->parent = butrct; saferct->safety = block->safety; BLI_freelistN(&block->saferct); @@ -520,7 +520,7 @@ static void ui_popup_block_remove(bContext *C, uiPopupBlockHandle *handle) CTX_wm_window_set(C, win); ui_region_temp_remove(C, screen, handle->region); - /* Reset context (area and region were NULL'ed when changing context window). */ + /* Reset context (area and region were nullptr'ed when changing context window). */ CTX_wm_window_set(C, ctx_win); CTX_wm_area_set(C, ctx_area); CTX_wm_region_set(C, ctx_region); @@ -548,10 +548,10 @@ uiBlock *ui_popup_block_refresh(bContext *C, const uiBlockHandleCreateFunc handle_create_func = handle->popup_create_vars.handle_create_func; void *arg = handle->popup_create_vars.arg; - uiBlock *block_old = region->uiblocks.first; + uiBlock *block_old = static_cast<uiBlock *>(region->uiblocks.first); uiBlock *block; - handle->refresh = (block_old != NULL); + handle->refresh = (block_old != nullptr); BLI_assert(!handle->refresh || handle->can_refresh); @@ -573,7 +573,7 @@ uiBlock *ui_popup_block_refresh(bContext *C, /* ensure we don't use mouse coords here! */ #ifdef DEBUG - window->eventstate = NULL; + window->eventstate = nullptr; #endif if (block->handle) { @@ -588,7 +588,7 @@ uiBlock *ui_popup_block_refresh(bContext *C, region->regiondata = handle; /* set UI_BLOCK_NUMSELECT before UI_block_end() so we get alphanumeric keys assigned */ - if (but == NULL) { + if (but == nullptr) { block->flag |= UI_BLOCK_POPUP; } @@ -596,7 +596,7 @@ uiBlock *ui_popup_block_refresh(bContext *C, UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); /* defer this until blocks are translated (below) */ - block->oldblock = NULL; + block->oldblock = nullptr; if (!block->endblock) { UI_block_end_ex( @@ -610,9 +610,8 @@ uiBlock *ui_popup_block_refresh(bContext *C, handle->direction = block->direction; } else { - uiSafetyRct *saferct; /* Keep a list of these, needed for pull-down menus. */ - saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct"); + uiSafetyRct *saferct = MEM_cnew<uiSafetyRct>(__func__); saferct->safety = block->safety; BLI_addhead(&block->saferct, saferct); } @@ -760,7 +759,6 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, static ARegionType type; ARegion *region; uiBlock *block; - uiPopupBlockHandle *handle; /* disable tooltips from buttons below */ if (activebut) { @@ -770,7 +768,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, WM_cursor_set(window, WM_CURSOR_DEFAULT); /* create handle */ - handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle"); + uiPopupBlockHandle *handle = MEM_cnew<uiPopupBlockHandle>(__func__); /* store context for operator */ handle->ctx_area = CTX_wm_area(C); @@ -782,7 +780,7 @@ uiPopupBlockHandle *ui_popup_block_create(bContext *C, handle->popup_create_vars.arg = arg; handle->popup_create_vars.arg_free = arg_free; handle->popup_create_vars.but = but; - handle->popup_create_vars.butregion = but ? butregion : NULL; + handle->popup_create_vars.butregion = but ? butregion : nullptr; copy_v2_v2_int(handle->popup_create_vars.event_xy, window->eventstate->xy); /* don't allow by default, only if popup type explicitly supports it */ @@ -816,7 +814,7 @@ void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle) /* If this popup is created from a popover which does NOT have keep-open flag set, * then close the popover too. We could extend this to other popup types too. */ ARegion *region = handle->popup_create_vars.butregion; - if (region != NULL) { + if (region != nullptr) { LISTBASE_FOREACH (uiBlock *, block, ®ion->uiblocks) { if (block->handle && (block->flag & UI_BLOCK_POPOVER) && (block->flag & UI_BLOCK_KEEP_OPEN) == 0) { diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.cc index ea6d293e52f..1a2c1f7919c 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.cc @@ -25,7 +25,7 @@ ARegion *ui_region_temp_add(bScreen *screen) { - ARegion *region = MEM_callocN(sizeof(ARegion), __func__); + ARegion *region = MEM_cnew<ARegion>(__func__); BLI_addtail(&screen->regionbase, region); region->regiontype = RGN_TYPE_TEMPORARY; @@ -45,6 +45,6 @@ void ui_region_temp_remove(bContext *C, bScreen *screen, ARegion *region) } ED_region_exit(C, region); - BKE_area_region_free(NULL, region); /* NULL: no spacetype */ + BKE_area_region_free(nullptr, region); /* nullptr: no spacetype */ BLI_freelinkN(&screen->regionbase, region); } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.cc index 76023f3033f..b4e97f8a396 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.cc @@ -5,11 +5,11 @@ * \ingroup edinterface */ -#include <limits.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <climits> +#include <cmath> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include "MEM_guardedalloc.h" @@ -57,7 +57,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id) { - uiStyle *style = MEM_callocN(sizeof(uiStyle), "new style"); + uiStyle *style = MEM_cnew<uiStyle>(__func__); BLI_addtail(styles, style); BLI_strncpy(style->name, name, MAX_STYLE_NAME); @@ -108,14 +108,14 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name, short uifont_id static uiFont *uifont_to_blfont(int id) { - uiFont *font = U.uifonts.first; + uiFont *font = static_cast<uiFont *>(U.uifonts.first); for (; font; font = font->next) { if (font->uifont_id == id) { return font; } } - return U.uifonts.first; + return static_cast<uiFont *>(U.uifonts.first); } /* *************** draw ************************ */ @@ -198,7 +198,7 @@ void UI_fontstyle_draw(const uiFontStyle *fs, const uchar col[4], const struct uiFontStyleDraw_Params *fs_params) { - UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, NULL, NULL, NULL); + UI_fontstyle_draw_ex(fs, rect, str, str_len, col, fs_params, nullptr, nullptr, nullptr); } void UI_fontstyle_draw_rotated(const uiFontStyle *fs, @@ -284,17 +284,13 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, const float decent = BLF_descender(fs->uifont_id); const float margin = height / 4.0f; + rctf rect; + rect.xmin = x - margin; + rect.xmax = x + width + margin; + rect.ymin = (y + decent) - margin; + rect.ymax = (y + decent) + height + margin; UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_draw_roundbox_4fv( - &(const rctf){ - .xmin = x - margin, - .xmax = x + width + margin, - .ymin = (y + decent) - margin, - .ymax = (y + decent) + height + margin, - }, - true, - margin, - col_bg); + UI_draw_roundbox_4fv(&rect, true, margin, col_bg); } BLF_position(fs->uifont_id, x, y, 0.0f); @@ -307,12 +303,12 @@ void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, const uiStyle *UI_style_get(void) { #if 0 - uiStyle *style = NULL; + uiStyle *style = nullptr; /* offset is two struct uiStyle pointers */ style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2); - return (style != NULL) ? style : U.uistyles.first; + return (style != nullptr) ? style : U.uistyles.first; #else - return U.uistyles.first; + return static_cast<const uiStyle *>(U.uistyles.first); #endif } @@ -378,7 +374,7 @@ int UI_fontstyle_height_max(const uiFontStyle *fs) void uiStyleInit(void) { - const uiStyle *style = U.uistyles.first; + const uiStyle *style = static_cast<uiStyle *>(U.uistyles.first); /* recover from uninitialized dpi */ if (U.dpi == 0) { @@ -400,11 +396,11 @@ void uiStyleInit(void) blf_mono_font_render = -1; } - uiFont *font_first = U.uifonts.first; + uiFont *font_first = static_cast<uiFont *>(U.uifonts.first); /* default builtin */ - if (font_first == NULL) { - font_first = MEM_callocN(sizeof(uiFont), "ui font"); + if (font_first == nullptr) { + font_first = MEM_cnew<uiFont>(__func__); BLI_addtail(&U.uifonts, font_first); } @@ -439,7 +435,7 @@ void uiStyleInit(void) } } - if (style == NULL) { + if (style == nullptr) { style = ui_style_new(&U.uistyles, "Default Style", UIFONT_DEFAULT); } diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.cc index 728d42a9353..b796f07c24b 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.cc @@ -5,17 +5,16 @@ * \ingroup edinterface */ -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <cctype> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include "DNA_object_types.h" #include "DNA_screen_types.h" #include "ED_screen.h" -#include "BLI_alloca.h" #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_string.h" @@ -55,12 +54,12 @@ uiBut *uiDefAutoButR(uiBlock *block, int width, int height) { - uiBut *but = NULL; + uiBut *but = nullptr; switch (RNA_property_type(prop)) { case PROP_BOOLEAN: { if (RNA_property_array_check(prop) && index == -1) { - return NULL; + return nullptr; } if (icon && name && name[0] == '\0') { @@ -79,7 +78,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else if (icon) { but = uiDefIconTextButR_prop(block, @@ -98,7 +97,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else { but = uiDefButR_prop(block, @@ -116,7 +115,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } break; } @@ -139,10 +138,10 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, 0, 0, - NULL); + nullptr); } else { - return NULL; + return nullptr; } } else if (RNA_property_subtype(prop) == PROP_PERCENTAGE || @@ -162,11 +161,25 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else { - but = uiDefButR_prop( - block, UI_BTYPE_NUM, 0, name, x, y, width, height, ptr, prop, index, 0, 0, 0, 0, NULL); + but = uiDefButR_prop(block, + UI_BTYPE_NUM, + 0, + name, + x, + y, + width, + height, + ptr, + prop, + index, + 0, + 0, + 0, + 0, + nullptr); } if (RNA_property_flag(prop) & PROP_TEXTEDIT_UPDATE) { @@ -191,14 +204,14 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else if (icon) { but = uiDefIconTextButR_prop(block, UI_BTYPE_MENU, 0, icon, - NULL, + nullptr, x, y, width, @@ -210,7 +223,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else { but = uiDefButR_prop(block, @@ -228,7 +241,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } break; case PROP_STRING: @@ -248,7 +261,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else if (icon) { but = uiDefIconTextButR_prop(block, @@ -267,7 +280,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } else { but = uiDefButR_prop(block, @@ -285,7 +298,7 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); + nullptr); } if (RNA_property_flag(prop) & PROP_TEXTEDIT_UPDATE) { @@ -319,20 +332,21 @@ uiBut *uiDefAutoButR(uiBlock *block, 0, -1, -1, - NULL); - ui_but_add_search(but, ptr, prop, NULL, NULL); + nullptr); + ui_but_add_search(but, ptr, prop, nullptr, nullptr); break; } case PROP_COLLECTION: { char text[256]; BLI_snprintf( text, sizeof(text), IFACE_("%d items"), RNA_property_collection_length(ptr, prop)); - but = uiDefBut(block, UI_BTYPE_LABEL, 0, text, x, y, width, height, NULL, 0, 0, 0, 0, NULL); + but = uiDefBut( + block, UI_BTYPE_LABEL, 0, text, x, y, width, height, nullptr, 0, 0, 0, 0, nullptr); UI_but_flag_enable(but, UI_BUT_DISABLED); break; } default: - but = NULL; + but = nullptr; break; } @@ -414,7 +428,7 @@ eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout, case UI_BUT_LABEL_ALIGN_NONE: default: col = layout; - name = NULL; /* no smart label alignment, show default name with button */ + name = nullptr; /* no smart label alignment, show default name with button */ break; } @@ -440,7 +454,7 @@ eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout, /* *** RNA collection search menu *** */ -typedef struct CollItemSearch { +struct CollItemSearch { struct CollItemSearch *next, *prev; void *data; char *name; @@ -449,7 +463,7 @@ typedef struct CollItemSearch { bool is_id; int name_prefix_offset; uint has_sep_char : 1; -} CollItemSearch; +}; static bool add_collection_search_item(CollItemSearch *cis, const bool requires_exact_data_name, @@ -462,10 +476,11 @@ static bool add_collection_search_item(CollItemSearch *cis, * name prefix for showing the library status. */ int name_prefix_offset = cis->name_prefix_offset; if (!has_id_icon && cis->is_id && !requires_exact_data_name) { - cis->iconid = UI_icon_from_library(cis->data); + cis->iconid = UI_icon_from_library(static_cast<const ID *>(cis->data)); /* No need to re-allocate, string should be shorter than before (lib status prefix is * removed). */ - BKE_id_full_name_ui_prefix_get(name_buf, cis->data, false, UI_SEP_CHAR, &name_prefix_offset); + BKE_id_full_name_ui_prefix_get( + name_buf, static_cast<const ID *>(cis->data), false, UI_SEP_CHAR, &name_prefix_offset); BLI_assert(strlen(name_buf) <= MEM_allocN_len(cis->name)); strcpy(cis->name, name_buf); } @@ -478,15 +493,12 @@ static bool add_collection_search_item(CollItemSearch *cis, name_prefix_offset); } -void ui_rna_collection_search_update_fn(const struct bContext *C, - void *arg, - const char *str, - uiSearchItems *items, - const bool is_first) +void ui_rna_collection_search_update_fn( + const bContext *C, void *arg, const char *str, uiSearchItems *items, const bool is_first) { - uiRNACollectionSearch *data = arg; + uiRNACollectionSearch *data = static_cast<uiRNACollectionSearch *>(arg); const int flag = RNA_property_flag(data->target_prop); - ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list"); + ListBase *items_list = MEM_cnew<ListBase>("items_list"); const bool is_ptr_target = (RNA_property_type(data->target_prop) == PROP_POINTER); /* For non-pointer properties, UI code acts entirely based on the item's name. So the name has to * match the RNA name exactly. So only for pointer properties, the name can be modified to add @@ -497,7 +509,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, char *name; bool has_id_icon = false; - StringSearch *search = skip_filter ? NULL : BLI_string_search_new(); + StringSearch *search = skip_filter ? nullptr : BLI_string_search_new(); /* build a temporary list of relevant items first */ int item_index = 0; @@ -522,18 +534,17 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, const bool is_id = itemptr.type && RNA_struct_is_ID(itemptr.type); if (is_id) { - iconid = ui_id_icon_get(C, itemptr.data, false); + iconid = ui_id_icon_get(C, static_cast<ID *>(itemptr.data), false); if (!ELEM(iconid, 0, ICON_BLANK1)) { has_id_icon = true; } if (requires_exact_data_name) { - name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL); + name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), nullptr); } else { - const ID *id = itemptr.data; - BKE_id_full_name_ui_prefix_get( - name_buf, itemptr.data, true, UI_SEP_CHAR, &name_prefix_offset); + const ID *id = static_cast<ID *>(itemptr.data); + BKE_id_full_name_ui_prefix_get(name_buf, id, true, UI_SEP_CHAR, &name_prefix_offset); BLI_STATIC_ASSERT(sizeof(name_buf) >= MAX_ID_FULL_NAME_UI, "Name string buffer should be big enough to hold full UI ID name"); name = name_buf; @@ -541,11 +552,11 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, } } else { - name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), NULL); + name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), nullptr); } if (name) { - CollItemSearch *cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch"); + CollItemSearch *cis = MEM_cnew<CollItemSearch>(__func__); cis->data = itemptr.data; cis->name = BLI_strdup(name); cis->index = item_index; @@ -597,7 +608,7 @@ void ui_rna_collection_search_update_fn(const struct bContext *C, int UI_icon_from_id(const ID *id) { - if (id == NULL) { + if (id == nullptr) { return ICON_NONE; } @@ -608,7 +619,7 @@ int UI_icon_from_id(const ID *id) if (ob->type == OB_EMPTY) { return ICON_EMPTY_DATA; } - return UI_icon_from_id(ob->data); + return UI_icon_from_id(static_cast<const ID *>(ob->data)); } /* otherwise get it through RNA, creating the pointer @@ -761,7 +772,7 @@ bool UI_but_online_manual_id(const uiBut *but, char *r_str, size_t maxlength) return false; } -bool UI_but_online_manual_id_from_active(const struct bContext *C, char *r_str, size_t maxlength) +bool UI_but_online_manual_id_from_active(const bContext *C, char *r_str, size_t maxlength) { uiBut *but = UI_context_active_but_get(C); @@ -861,7 +872,7 @@ void UI_but_ensure_in_view(const bContext *C, ARegion *region, const uiBut *but) * Modal Button Store API. * * Store for modal operators & handlers to register button pointers - * which are maintained while drawing or NULL when removed. + * which are maintained while drawing or nullptr when removed. * * This is needed since button pointers are continuously freed and re-allocated. * @@ -880,7 +891,7 @@ struct uiButStoreElem { uiButStore *UI_butstore_create(uiBlock *block) { - uiButStore *bs_handle = MEM_callocN(sizeof(uiButStore), __func__); + uiButStore *bs_handle = MEM_cnew<uiButStore>(__func__); bs_handle->block = block; BLI_addtail(&block->butstore, bs_handle); @@ -899,7 +910,7 @@ void UI_butstore_free(uiBlock *block, uiButStore *bs_handle) * Ideally we would manage moving the 'uiButStore', keeping a correct state. * All things considered this is the most straightforward fix - Campbell. */ - if (block != bs_handle->block && bs_handle->block != NULL) { + if (block != bs_handle->block && bs_handle->block != nullptr) { block = bs_handle->block; } @@ -912,7 +923,7 @@ void UI_butstore_free(uiBlock *block, uiButStore *bs_handle) bool UI_butstore_is_valid(uiButStore *bs) { - return (bs->block != NULL); + return (bs->block != nullptr); } bool UI_butstore_is_registered(uiBlock *block, uiBut *but) @@ -930,7 +941,7 @@ bool UI_butstore_is_registered(uiBlock *block, uiBut *but) void UI_butstore_register(uiButStore *bs_handle, uiBut **but_p) { - uiButStoreElem *bs_elem = MEM_callocN(sizeof(uiButStoreElem), __func__); + uiButStoreElem *bs_elem = MEM_cnew<uiButStoreElem>(__func__); BLI_assert(*but_p); bs_elem->but_p = but_p; @@ -968,9 +979,9 @@ bool UI_butstore_register_update(uiBlock *block, uiBut *but_dst, const uiBut *bu void UI_butstore_clear(uiBlock *block) { LISTBASE_FOREACH (uiButStore *, bs_handle, &block->butstore) { - bs_handle->block = NULL; + bs_handle->block = nullptr; LISTBASE_FOREACH (uiButStoreElem *, bs_elem, &bs_handle->items) { - *bs_elem->but_p = NULL; + *bs_elem->but_p = nullptr; } } } @@ -984,14 +995,14 @@ void UI_butstore_update(uiBlock *block) } } - if (LIKELY(block->butstore.first == NULL)) { + if (LIKELY(block->butstore.first == nullptr)) { return; } /* warning, loop-in-loop, in practice we only store <10 buttons at a time, * so this isn't going to be a problem, if that changes old-new mapping can be cached first */ LISTBASE_FOREACH (uiButStore *, bs_handle, &block->butstore) { - BLI_assert(ELEM(bs_handle->block, NULL, block) || + BLI_assert(ELEM(bs_handle->block, nullptr, block) || (block->oldblock && block->oldblock == bs_handle->block)); if (bs_handle->block == block->oldblock) { @@ -1001,7 +1012,7 @@ void UI_butstore_update(uiBlock *block) if (*bs_elem->but_p) { uiBut *but_new = ui_but_find_new(block, *bs_elem->but_p); - /* can be NULL if the buttons removed, + /* can be nullptr if the buttons removed, * NOTE: we could allow passing in a callback when buttons are removed * so the caller can cleanup */ *bs_elem->but_p = but_new; |