[Bf-blender-cvs] [162f0dcb2ff] master: Cleanup: Move six more interface files to C++

Hans Goudey noreply at git.blender.org
Sat Nov 26 17:14:07 CET 2022


Commit: 162f0dcb2ff3ac291e56b5352c7e32a2aa496fe4
Author: Hans Goudey
Date:   Fri Nov 25 23:48:02 2022 -0600
Branches: master
https://developer.blender.org/rB162f0dcb2ff3ac291e56b5352c7e32a2aa496fe4

Cleanup: Move six more interface files to C++

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

M	source/blender/editors/interface/CMakeLists.txt
R096	source/blender/editors/interface/interface_align.c	source/blender/editors/interface/interface_align.cc
R094	source/blender/editors/interface/interface_icons.c	source/blender/editors/interface/interface_icons.cc
M	source/blender/editors/interface/interface_intern.h
R088	source/blender/editors/interface/interface_layout.c	source/blender/editors/interface/interface_layout.cc
R089	source/blender/editors/interface/interface_templates.c	source/blender/editors/interface/interface_templates.cc
R096	source/blender/editors/interface/interface_widgets.c	source/blender/editors/interface/interface_widgets.cc
R092	source/blender/editors/interface/resources.c	source/blender/editors/interface/resources.cc

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

diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 0bee4b05a3b..4108800c518 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -35,7 +35,7 @@ set(SRC
   eyedroppers/eyedropper_gpencil_color.c
   eyedroppers/interface_eyedropper.c
   interface.cc
-  interface_align.c
+  interface_align.cc
   interface_anim.cc
   interface_button_group.cc
   interface_context_menu.cc
@@ -44,9 +44,9 @@ set(SRC
   interface_draw.cc
   interface_dropboxes.cc
   interface_handlers.c
-  interface_icons.c
+  interface_icons.cc
   interface_icons_event.cc
-  interface_layout.c
+  interface_layout.cc
   interface_ops.cc
   interface_panel.cc
   interface_query.cc
@@ -65,11 +65,11 @@ set(SRC
   interface_template_list.cc
   interface_template_search_menu.cc
   interface_template_search_operator.cc
-  interface_templates.c
+  interface_templates.cc
   interface_undo.cc
   interface_utils.cc
-  interface_widgets.c
-  resources.c
+  interface_widgets.cc
+  resources.cc
   view2d.cc
   view2d_draw.cc
   view2d_edge_pan.cc
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.cc
similarity index 96%
rename from source/blender/editors/interface/interface_align.c
rename to source/blender/editors/interface/interface_align.cc
index 3b897e23e35..d7a9f3bce97 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.cc
@@ -41,7 +41,7 @@
  *       This will probably not work in all possible cases,
  *       but not sure we want to support such exotic cases anyway.
  */
-typedef struct ButAlign {
+struct ButAlign {
   uiBut *but;
 
   /* Neighbor buttons */
@@ -56,7 +56,7 @@ typedef struct ButAlign {
   /* Flags, used to mark whether we should 'stitch'
    * the corners of this button with its neighbors' ones. */
   char flags[4];
-} ButAlign;
+};
 
 /* Side-related enums and flags. */
 enum {
@@ -168,7 +168,7 @@ static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other
             /* We found an as close or closer neighbor.
              * If both buttons are alignable, we set them as each other neighbors.
              * Else, we have an unalignable one, we need to reset the others matching
-             * neighbor to NULL if its 'proximity distance'
+             * neighbor to nullptr if its 'proximity distance'
              * is really lower with current one.
              *
              * NOTE: We cannot only execute that piece of code in case we found a
@@ -181,10 +181,10 @@ static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other
               butal_other->neighbors[side_opp] = butal;
             }
             else if (butal_can_align && (delta < butal->dists[side])) {
-              butal->neighbors[side] = NULL;
+              butal->neighbors[side] = nullptr;
             }
             else if (butal_other_can_align && (delta < butal_other->dists[side_opp])) {
-              butal_other->neighbors[side_opp] = NULL;
+              butal_other->neighbors[side_opp] = nullptr;
             }
             butal->dists[side] = butal_other->dists[side_opp] = delta;
           }
@@ -196,10 +196,10 @@ static void block_align_proximity_compute(ButAlign *butal, ButAlign *butal_other
             const int stitch = STITCH(side);
             const int stitch_opp = STITCH(side_opp);
 
-            if (butal->neighbors[side] == NULL) {
+            if (butal->neighbors[side] == nullptr) {
               butal->neighbors[side] = butal_other;
             }
-            if (butal_other->neighbors[side_opp] == NULL) {
+            if (butal_other->neighbors[side_opp] == nullptr) {
               butal_other->neighbors[side_opp] = butal;
             }
 
@@ -304,8 +304,8 @@ static void block_align_stitch_neighbors(ButAlign *butal,
  */
 static int ui_block_align_butal_cmp(const void *a, const void *b)
 {
-  const ButAlign *butal = a;
-  const ButAlign *butal_other = b;
+  const ButAlign *butal = static_cast<const ButAlign *>(a);
+  const ButAlign *butal_other = static_cast<const ButAlign *>(b);
 
   /* Sort by align group. */
   if (butal->but->alignnr != butal_other->but->alignnr) {
@@ -402,7 +402,8 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
     butal_array = butal_array_buf;
   }
   else {
-    butal_array = MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__);
+    butal_array = static_cast<ButAlign *>(
+        MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__));
   }
   memset(butal_array, 0, sizeof(*butal_array) * (size_t)num_buttons);
 
@@ -549,7 +550,7 @@ static bool buts_are_horiz(uiBut *but1, uiBut *but2)
 
 static void ui_block_align_calc_but(uiBut *first, short nr)
 {
-  uiBut *prev, *but = NULL, *next;
+  uiBut *prev, *but = nullptr, *next;
   int flag = 0, cols = 0, rows = 0;
 
   /* auto align */
@@ -569,10 +570,10 @@ static void ui_block_align_calc_but(uiBut *first, short nr)
 
   /* NOTE: manipulation of 'flag' in the loop below is confusing.
    * In some cases it's assigned, other times OR is used. */
-  for (but = first, prev = NULL; but && but->alignnr == nr; prev = but, but = but->next) {
+  for (but = first, prev = nullptr; but && but->alignnr == nr; prev = but, but = but->next) {
     next = but->next;
     if (next && next->alignnr != nr) {
-      next = NULL;
+      next = nullptr;
     }
 
     /* clear old flag */
@@ -593,7 +594,7 @@ static void ui_block_align_calc_but(uiBut *first, short nr)
         }
       }
     }
-    else if (next == NULL) { /* last case */
+    else if (next == nullptr) { /* last case */
       if (prev) {
         if (buts_are_horiz(prev, but)) {
           if (rows == 0) {
@@ -622,7 +623,7 @@ static void ui_block_align_calc_but(uiBut *first, short nr)
             }
             bt = bt->next;
           }
-          if (bt == NULL || bt->alignnr != nr) {
+          if (bt == nullptr || bt->alignnr != nr) {
             flag = UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_RIGHT;
           }
         }
@@ -704,7 +705,7 @@ static void ui_block_align_calc_but(uiBut *first, short nr)
   }
 }
 
-void ui_block_align_calc(uiBlock *block, const struct ARegion *UNUSED(region))
+void ui_block_align_calc(uiBlock *block, const struct ARegion *(region))
 {
   short nr;
 
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.cc
similarity index 94%
rename from source/blender/editors/interface/interface_icons.c
rename to source/blender/editors/interface/interface_icons.cc
index a5e2cd02f3b..1d0677843ff 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.cc
@@ -5,9 +5,9 @@
  * \ingroup edinterface
  */
 
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -74,15 +74,15 @@
 #  define ICON_GRID_H 32
 #endif /* WITH_HEADLESS */
 
-typedef struct IconImage {
+struct IconImage {
   int w;
   int h;
   uint *rect;
   const uchar *datatoc_rect;
   int datatoc_size;
-} IconImage;
+};
 
-typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
+using VectorDrawFunc = void (*)(int x, int y, int w, int h, float alpha);
 
 #define ICON_TYPE_PREVIEW 0
 #define ICON_TYPE_COLOR_TEXTURE 1
@@ -95,7 +95,7 @@ typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
 #define ICON_TYPE_GPLAYER 8
 #define ICON_TYPE_BLANK 9
 
-typedef struct DrawInfo {
+struct DrawInfo {
   int type;
 
   union {
@@ -123,26 +123,26 @@ typedef struct DrawInfo {
       struct DrawInfo *next;
     } input;
   } data;
-} DrawInfo;
+};
 
-typedef struct IconTexture {
-  struct GPUTexture *tex[2];
+struct IconTexture {
+  GPUTexture *tex[2];
   int num_textures;
   int w;
   int h;
   float invw;
   float invh;
-} IconTexture;
+};
 
-typedef struct IconType {
+struct IconType {
   int type;
   int theme_color;
-} IconType;
+};
 
 /* ******************* STATIC LOCAL VARS ******************* */
 /* Static here to cache results of icon directory scan, so it's not
  * scanning the file-system each time the menu is drawn. */
-static struct ListBase iconfilelist = {NULL, NULL};
+static ListBase iconfilelist = {NULL, NULL};
 static IconTexture icongltex = {{NULL, NULL}, 0, 0, 0, 0.0f, 0.0f};
 
 #ifndef WITH_HEADLESS
@@ -168,12 +168,12 @@ static const IconType icontypes[] = {
 static DrawInfo *def_internal_icon(
     ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type, int theme_color)
 {
-  Icon *new_icon = MEM_callocN(sizeof(Icon), "texicon");
+  Icon *new_icon = MEM_cnew<Icon>(__func__);
 
   new_icon->obj = NULL; /* icon is not for library object */
   new_icon->id_type = 0;
 
-  DrawInfo *di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
+  DrawInfo *di = MEM_cnew<DrawInfo>(__func__);
   di->type = type;
 
   if (ELEM(type, ICON_TYPE_COLOR_TEXTURE, ICON_TYPE_MONO_TEXTURE)) {
@@ -184,7 +184,7 @@ static DrawInfo *def_internal_icon(
     di->data.texture.h = size;
   }
   else if (type == ICON_TYPE_BUFFER) {
-    IconImage *iimg = MEM_callocN(sizeof(IconImage), "icon_img");
+    IconImage *iimg = MEM_cnew<IconImage>(__func__);
     iimg->w = size;
     iimg->h = size;
 
@@ -192,7 +192,7 @@ static DrawInfo *def_internal_icon(
     if (bbuf) {
       int y, imgsize;
 
-      iimg->rect = MEM_mallocN(size * size * sizeof(uint), "icon_rect");
+      iimg->rect = static_cast<uint *>(MEM_mallocN(size * size * sizeof(uint), __func__));
 
       /* Here we store the rect in the icon - same as before */
       if (size == bbuf->x && size == bbuf->y && xofs == 0 && yofs == 0) {
@@ -220,12 +220,12 @@ static DrawInfo *def_internal_icon(
 
 static void def_internal_vicon(int icon_id, VectorDrawFunc drawFunc)
 {
-  Icon *new_icon = MEM_callocN(sizeof(Icon), "texicon");
+  Icon *new_icon = MEM_cnew<Icon>("texicon");
 
   new_icon->obj = NULL; /* icon is not for library object */
   new_icon->id_type = 0;
 
-  DrawInfo *di = MEM_callocN(sizeof(DrawInfo), "drawinfo");
+  DrawInfo *di = MEM_cnew<DrawInfo>("drawinfo");
   di->t

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list