[Bf-blender-cvs] [486d27d32aa] master: Cleanup: Move paint.c to C++

Hans Goudey noreply at git.blender.org
Tue Aug 23 18:02:17 CEST 2022


Commit: 486d27d32aa27ed3431f8aedbad5253b140a1590
Author: Hans Goudey
Date:   Tue Aug 23 12:01:37 2022 -0400
Branches: master
https://developer.blender.org/rB486d27d32aa27ed3431f8aedbad5253b140a1590

Cleanup: Move paint.c to C++

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/CMakeLists.txt
R087	source/blender/blenkernel/intern/paint.c	source/blender/blenkernel/intern/paint.cc

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index fa67ff08383..202ff4514d2 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -98,6 +98,7 @@ typedef enum ePaintOverlayControlFlags {
   PAINT_OVERLAY_OVERRIDE_PRIMARY = (1 << 5),
   PAINT_OVERLAY_OVERRIDE_SECONDARY = (1 << 6),
 } ePaintOverlayControlFlags;
+ENUM_OPERATORS(ePaintOverlayControlFlags, PAINT_OVERLAY_OVERRIDE_SECONDARY);
 
 #define PAINT_OVERRIDE_MASK \
   (PAINT_OVERLAY_OVERRIDE_SECONDARY | PAINT_OVERLAY_OVERRIDE_PRIMARY | \
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 1183a05c3ea..0d76bf994b7 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -239,7 +239,7 @@ set(SRC
   intern/ocean_spectrum.c
   intern/outliner_treehash.cc
   intern/packedFile.c
-  intern/paint.c
+  intern/paint.cc
   intern/paint_canvas.cc
   intern/paint_toolslots.c
   intern/particle.c
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.cc
similarity index 87%
rename from source/blender/blenkernel/intern/paint.c
rename to source/blender/blenkernel/intern/paint.cc
index e9107bf4a1e..cc3355a9a36 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -5,8 +5,8 @@
  * \ingroup bke
  */
 
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
 
 #include "MEM_guardedalloc.h"
 
@@ -113,38 +113,38 @@ static void palette_undo_preserve(BlendLibReader *UNUSED(reader), ID *id_new, ID
   /* NOTE: We do not care about potential internal references to self here, Palette has none. */
   /* NOTE: We do not swap IDProperties, as dealing with potential ID pointers in those would be
    *       fairly delicate. */
-  BKE_lib_id_swap(NULL, id_new, id_old);
+  BKE_lib_id_swap(nullptr, id_new, id_old);
   SWAP(IDProperty *, id_new->properties, id_old->properties);
 }
 
 IDTypeInfo IDType_ID_PAL = {
-    .id_code = ID_PAL,
-    .id_filter = FILTER_ID_PAL,
-    .main_listbase_index = INDEX_ID_PAL,
-    .struct_size = sizeof(Palette),
-    .name = "Palette",
-    .name_plural = "palettes",
-    .translation_context = BLT_I18NCONTEXT_ID_PALETTE,
-    .flags = IDTYPE_FLAGS_NO_ANIMDATA,
-    .asset_type_info = NULL,
-
-    .init_data = palette_init_data,
-    .copy_data = palette_copy_data,
-    .free_data = palette_free_data,
-    .make_local = NULL,
-    .foreach_id = NULL,
-    .foreach_cache = NULL,
-    .foreach_path = NULL,
-    .owner_get = NULL,
-
-    .blend_write = palette_blend_write,
-    .blend_read_data = palette_blend_read_data,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
-
-    .blend_read_undo_preserve = palette_undo_preserve,
-
-    .lib_override_apply_post = NULL,
+    /* id_code */ ID_PAL,
+    /* id_filter */ FILTER_ID_PAL,
+    /* main_listbase_index */ INDEX_ID_PAL,
+    /* struct_size */ sizeof(Palette),
+    /* name */ "Palette",
+    /* name_plural */ "palettes",
+    /* translation_context */ BLT_I18NCONTEXT_ID_PALETTE,
+    /* flags */ IDTYPE_FLAGS_NO_ANIMDATA,
+    /* asset_type_info */ nullptr,
+
+    /* init_data */ palette_init_data,
+    /* copy_data */ palette_copy_data,
+    /* free_data */ palette_free_data,
+    /* make_local */ nullptr,
+    /* foreach_id */ nullptr,
+    /* foreach_cache */ nullptr,
+    /* foreach_path */ nullptr,
+    /* owner_get */ nullptr,
+
+    /* blend_write */ palette_blend_write,
+    /* blend_read_data */ palette_blend_read_data,
+    /* blend_read_lib */ nullptr,
+    /* blend_read_expand */ nullptr,
+
+    /* blend_read_undo_preserve */ palette_undo_preserve,
+
+    /* lib_override_apply_post */ nullptr,
 };
 
 static void paint_curve_copy_data(Main *UNUSED(bmain),
@@ -156,7 +156,8 @@ static void paint_curve_copy_data(Main *UNUSED(bmain),
   const PaintCurve *paint_curve_src = (const PaintCurve *)id_src;
 
   if (paint_curve_src->tot_points != 0) {
-    paint_curve_dst->points = MEM_dupallocN(paint_curve_src->points);
+    paint_curve_dst->points = static_cast<PaintCurvePoint *>(
+        MEM_dupallocN(paint_curve_src->points));
   }
 }
 
@@ -185,33 +186,33 @@ static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)
 }
 
 IDTypeInfo IDType_ID_PC = {
-    .id_code = ID_PC,
-    .id_filter = FILTER_ID_PC,
-    .main_listbase_index = INDEX_ID_PC,
-    .struct_size = sizeof(PaintCurve),
-    .name = "PaintCurve",
-    .name_plural = "paint_curves",
-    .translation_context = BLT_I18NCONTEXT_ID_PAINTCURVE,
-    .flags = IDTYPE_FLAGS_NO_ANIMDATA,
-    .asset_type_info = NULL,
-
-    .init_data = NULL,
-    .copy_data = paint_curve_copy_data,
-    .free_data = paint_curve_free_data,
-    .make_local = NULL,
-    .foreach_id = NULL,
-    .foreach_cache = NULL,
-    .foreach_path = NULL,
-    .owner_get = NULL,
-
-    .blend_write = paint_curve_blend_write,
-    .blend_read_data = paint_curve_blend_read_data,
-    .blend_read_lib = NULL,
-    .blend_read_expand = NULL,
-
-    .blend_read_undo_preserve = NULL,
-
-    .lib_override_apply_post = NULL,
+    /* id_code */ ID_PC,
+    /* id_filter */ FILTER_ID_PC,
+    /* main_listbase_index */ INDEX_ID_PC,
+    /* struct_size */ sizeof(PaintCurve),
+    /* name */ "PaintCurve",
+    /* name_plural */ "paint_curves",
+    /* translation_context */ BLT_I18NCONTEXT_ID_PAINTCURVE,
+    /* flags */ IDTYPE_FLAGS_NO_ANIMDATA,
+    /* asset_type_info */ nullptr,
+
+    /* init_data */ nullptr,
+    /* copy_data */ paint_curve_copy_data,
+    /* free_data */ paint_curve_free_data,
+    /* make_local */ nullptr,
+    /* foreach_id */ nullptr,
+    /* foreach_cache */ nullptr,
+    /* foreach_path */ nullptr,
+    /* owner_get */ nullptr,
+
+    /* blend_write */ paint_curve_blend_write,
+    /* blend_read_data */ paint_curve_blend_read_data,
+    /* blend_read_lib */ nullptr,
+    /* blend_read_expand */ nullptr,
+
+    /* blend_read_undo_preserve */ nullptr,
+
+    /* lib_override_apply_post */ nullptr,
 };
 
 const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
@@ -219,7 +220,7 @@ const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
 
-static ePaintOverlayControlFlags overlay_flags = 0;
+static ePaintOverlayControlFlags overlay_flags = (ePaintOverlayControlFlags)0;
 
 void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
 {
@@ -244,7 +245,7 @@ void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const
 void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve)
 {
   Paint *p = BKE_paint_get_active(scene, view_layer);
-  if (p == NULL) {
+  if (p == nullptr) {
     return;
   }
 
@@ -291,10 +292,10 @@ void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag)
 bool BKE_paint_ensure_from_paintmode(Scene *sce, ePaintMode mode)
 {
   ToolSettings *ts = sce->toolsettings;
-  Paint **paint_ptr = NULL;
+  Paint **paint_ptr = nullptr;
   /* Some paint modes don't store paint settings as pointer, for these this can be set and
    * referenced by paint_ptr. */
-  Paint *paint_tmp = NULL;
+  Paint *paint_tmp = nullptr;
 
   switch (mode) {
     case PAINT_MODE_SCULPT:
@@ -367,13 +368,13 @@ Paint *BKE_paint_get_active_from_paintmode(Scene *sce, ePaintMode mode)
       case PAINT_MODE_SCULPT_CURVES:
         return &ts->curves_sculpt->paint;
       case PAINT_MODE_INVALID:
-        return NULL;
+        return nullptr;
       default:
         return &ts->imapaint.paint;
     }
   }
 
-  return NULL;
+  return nullptr;
 }
 
 const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode)
@@ -403,7 +404,7 @@ const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode)
     case PAINT_MODE_INVALID:
       break;
   }
-  return NULL;
+  return nullptr;
 }
 
 const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode)
@@ -435,7 +436,7 @@ const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode)
   }
 
   /* Invalid paint mode. */
-  return NULL;
+  return nullptr;
 }
 
 Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
@@ -464,7 +465,7 @@ Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
         case OB_MODE_SCULPT_CURVES:
           return &ts->curves_sculpt->paint;
         case OB_MODE_EDIT:
-          return ts->uvsculpt ? &ts->uvsculpt->paint : NULL;
+          return ts->uvsculpt ? &ts->uvsculpt->paint : nullptr;
         default:
           break;
       }
@@ -474,7 +475,7 @@ Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
     return &ts->imapaint.paint;
   }
 
-  return NULL;
+  return nullptr;
 }
 
 Paint *BKE_paint_get_active_from_context(const bContext *C)
@@ -485,13 +486,13 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
 
   if (sce && view_layer) {
     ToolSettings *ts = sce->toolsettings;
-    Object *obact = NULL;
+    Object *obact = nullptr;
 
     if (view_layer->basact && view_layer->basact->object) {
       obact = view_layer->basact->object;
     }
 
-    if ((sima = CTX_wm_space_image(C)) != NULL) {
+    if ((sima = CTX_wm_space_image(C)) != nullptr) {
       if (obact && obact->mode == OB_MODE_EDIT) {
         if (sima->mode == SI_MODE_PAINT) {
           return &ts->imapaint.paint;
@@ -509,7 +510,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
     }
   }
 
-  return NULL;
+  return nullptr;
 }
 
 ePaintMode BKE_paintmode_get_active_from_context(const bContext *C)
@@ -519,13 +520,13 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C)
   SpaceImage *sima;
 
   if (sce && view_layer) {
-    Object *obact = NULL;
+    Object *obact = nullptr;
 
     if (view_layer->basact && view_layer->basact->object) {
       obact = view_layer->basact->object;
     }
 
-    if ((sima = CTX_wm_space_image(C)) != NULL) {
+    if ((sima = CTX_wm_space_image(C)) != nullptr) {
       if (obact && obact->mode == OB_MODE_EDIT) {
         if (sima->mode == SI_MODE_PAINT) {
           return PAINT_MODE_TEXTURE_2D;
@@ -565,7 +5

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list