[Bf-blender-cvs] [432ad4c6327] master: Cleanup: Move interface.c to C++

Hans Goudey noreply at git.blender.org
Mon Apr 4 17:24:22 CEST 2022


Commit: 432ad4c63278762079a79fc2a8ddc2647a2228cc
Author: Hans Goudey
Date:   Mon Apr 4 10:24:14 2022 -0500
Branches: master
https://developer.blender.org/rB432ad4c63278762079a79fc2a8ddc2647a2228cc

Cleanup: Move interface.c to C++

This is similar to 4537eb0c3b1678a62

===================================================================

M	source/blender/editors/interface/CMakeLists.txt
R093	source/blender/editors/interface/interface.c	source/blender/editors/interface/interface.cc

===================================================================

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
similarity index 93%
rename from source/blender/editors/interface/interface.c
rename to 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(&region->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. */
+  cons

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list