Cleanup: PaintCurve: Move to IDTypeInfo and remove unused BKE API.

This commit is contained in:
Bastien Montagne 2020-03-09 12:35:25 +01:00
parent b57d3afb76
commit b9d1026ce0
6 changed files with 44 additions and 46 deletions

View File

@ -156,7 +156,7 @@ extern IDTypeInfo IDType_ID_WM;
// extern IDTypeInfo IDType_ID_MSK;
// extern IDTypeInfo IDType_ID_LS;
// extern IDTypeInfo IDType_ID_PAL;
// extern IDTypeInfo IDType_ID_PC;
extern IDTypeInfo IDType_ID_PC;
extern IDTypeInfo IDType_ID_CF;
extern IDTypeInfo IDType_ID_WS;
extern IDTypeInfo IDType_ID_LP;

View File

@ -145,13 +145,7 @@ void BKE_palette_clear(struct Palette *palette);
/* paint curves */
struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name);
void BKE_paint_curve_free(struct PaintCurve *pc);
void BKE_paint_curve_copy_data(struct Main *bmain,
struct PaintCurve *pc_dst,
const struct PaintCurve *pc_src,
const int flag);
struct PaintCurve *BKE_paint_curve_copy(struct Main *bmain, const struct PaintCurve *pc);
void BKE_paint_curve_make_local(struct Main *bmain, struct PaintCurve *pc, const int flags);
bool BKE_paint_ensure(struct ToolSettings *ts, struct Paint **r_paint);
void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, const char col[3]);

View File

@ -83,7 +83,7 @@ static void id_type_init(void)
// INIT_TYPE(ID_MSK);
// INIT_TYPE(ID_LS);
// INIT_TYPE(ID_PAL);
// INIT_TYPE(ID_PC);
INIT_TYPE(ID_PC);
INIT_TYPE(ID_CF);
INIT_TYPE(ID_WS);
INIT_TYPE(ID_LP);

View File

@ -563,9 +563,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
}
return true;
case ID_PC:
if (!test) {
BKE_paint_curve_make_local(bmain, (PaintCurve *)id, flags);
}
BLI_assert(0);
return true;
case ID_CF:
BLI_assert(0);
@ -767,7 +765,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
BKE_palette_copy_data(bmain, (Palette *)*r_newid, (Palette *)id, flag);
break;
case ID_PC:
BKE_paint_curve_copy_data(bmain, (PaintCurve *)*r_newid, (PaintCurve *)id, flag);
BLI_assert(0);
break;
case ID_CF:
BLI_assert(0);
@ -1377,7 +1375,7 @@ void BKE_libblock_init_empty(ID *id)
/* Nothing to do. */
break;
case ID_PC:
/* Nothing to do. */
BLI_assert(0);
break;
case ID_GD:
/* Nothing to do. */

View File

@ -235,7 +235,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
BKE_palette_free((Palette *)id);
break;
case ID_PC:
BKE_paint_curve_free((PaintCurve *)id);
BLI_assert(0);
break;
case ID_CF:
BLI_assert(0);

View File

@ -53,6 +53,7 @@
#include "BKE_context.h"
#include "BKE_crazyspace.h"
#include "BKE_gpencil.h"
#include "BKE_idtype.h"
#include "BKE_image.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
@ -74,6 +75,43 @@
#include "bmesh.h"
static void paint_curve_copy_data(Main *UNUSED(bmain),
ID *id_dst,
const ID *id_src,
const int UNUSED(flag))
{
PaintCurve *paint_curve_dst = (PaintCurve *)id_dst;
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);
}
}
static void paint_curve_free_data(ID *id)
{
PaintCurve *paint_curve = (PaintCurve *)id;
MEM_SAFE_FREE(paint_curve->points);
paint_curve->tot_points = 0;
}
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 = 0,
.init_data = NULL,
.copy_data = paint_curve_copy_data,
.free_data = paint_curve_free_data,
.make_local = NULL,
};
const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
const char PAINT_CURSOR_VERTEX_PAINT[3] = {255, 255, 255};
const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
@ -474,13 +512,6 @@ uint BKE_paint_get_brush_tool_offset_from_paintmode(const ePaintMode mode)
return 0;
}
/** Free (or release) any data used by this paint curve (does not free the pcurve itself). */
void BKE_paint_curve_free(PaintCurve *pc)
{
MEM_SAFE_FREE(pc->points);
pc->tot_points = 0;
}
PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
{
PaintCurve *pc;
@ -490,26 +521,6 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name)
return pc;
}
/**
* Only copy internal data of PaintCurve ID from source to
* already allocated/initialized destination.
* You probably never want to use that directly,
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
*
* WARNING! This function will not handle ID user count!
*
* \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
*/
void BKE_paint_curve_copy_data(Main *UNUSED(bmain),
PaintCurve *pc_dst,
const PaintCurve *pc_src,
const int UNUSED(flag))
{
if (pc_src->tot_points != 0) {
pc_dst->points = MEM_dupallocN(pc_src->points);
}
}
PaintCurve *BKE_paint_curve_copy(Main *bmain, const PaintCurve *pc)
{
PaintCurve *pc_copy;
@ -517,11 +528,6 @@ PaintCurve *BKE_paint_curve_copy(Main *bmain, const PaintCurve *pc)
return pc_copy;
}
void BKE_paint_curve_make_local(Main *bmain, PaintCurve *pc, const int flags)
{
BKE_lib_id_make_local_generic(bmain, &pc->id, flags);
}
Palette *BKE_paint_palette(Paint *p)
{
return p ? p->palette : NULL;