WIP: Fix #104730: Make first visible CustomData layer active #104739
|
@ -2166,7 +2166,8 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
|
|||
eCDAllocType alloctype,
|
||||
void *layerdata,
|
||||
int totelem,
|
||||
const char *name);
|
||||
const char *name,
|
||||
bool isanonymous);
|
||||
|
||||
void CustomData_update_typemap(CustomData *data)
|
||||
{
|
||||
|
@ -2254,10 +2255,10 @@ bool CustomData_merge(const CustomData *source,
|
|||
|
||||
if ((alloctype == CD_ASSIGN) && (flag & CD_FLAG_NOFREE)) {
|
||||
newlayer = customData_add_layer__internal(
|
||||
dest, type, CD_REFERENCE, data, totelem, layer->name);
|
||||
dest, type, CD_REFERENCE, data, totelem, layer->name, layer->anonymous_id != nullptr);
|
||||
}
|
||||
else {
|
||||
newlayer = customData_add_layer__internal(dest, type, alloctype, data, totelem, layer->name);
|
||||
newlayer = customData_add_layer__internal(dest, type, alloctype, data, totelem, layer->name, layer->anonymous_id != nullptr);
|
||||
}
|
||||
|
||||
if (newlayer) {
|
||||
|
@ -2706,16 +2707,40 @@ static bool customData_resize(CustomData *data, const int amount)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool customData_has_nonanonymous_layer(const CustomData *data, const int type)
|
||||
{
|
||||
int layer = data->typemap[type];
|
||||
|
||||
if (layer <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (data->layers[layer].type == type) {
|
||||
if (data->layers[layer].anonymous_id != nullptr) {
|
||||
return true;
|
||||
}
|
||||
layer++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static CustomDataLayer *customData_add_layer__internal(CustomData *data,
|
||||
const int type,
|
||||
const eCDAllocType alloctype,
|
||||
void *layerdata,
|
||||
const int totelem,
|
||||
const char *name)
|
||||
const char *name,
|
||||
bool isanonymous)
|
||||
{
|
||||
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
|
||||
int flag = 0;
|
||||
|
||||
bool isfirstvisible = false;
|
||||
if (!isanonymous) {
|
||||
isfirstvisible = !customData_has_nonanonymous_layer(data, type);
|
||||
}
|
||||
|
||||
/* Some layer types only support a single layer. */
|
||||
if (!typeInfo->defaultname && CustomData_has_layer(data, type)) {
|
||||
/* This function doesn't support dealing with existing layer data for these layer types when
|
||||
|
@ -2834,6 +2859,13 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
|
|||
|
||||
customData_update_offsets(data);
|
||||
|
||||
if (isfirstvisible) {
|
||||
CustomData_set_layer_active_index(data, type, index);
|
||||
CustomData_set_layer_render_index(data, type, index);
|
||||
CustomData_set_layer_clone_index(data, type, index);
|
||||
CustomData_set_layer_stencil_index(data, type, index);
|
||||
}
|
||||
|
||||
return &data->layers[index];
|
||||
}
|
||||
|
||||
|
@ -2843,7 +2875,7 @@ void *CustomData_add_layer(
|
|||
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
|
||||
|
||||
CustomDataLayer *layer = customData_add_layer__internal(
|
||||
data, type, alloctype, layerdata, totelem, typeInfo->defaultname);
|
||||
data, type, alloctype, layerdata, totelem, typeInfo->defaultname, false);
|
||||
CustomData_update_typemap(data);
|
||||
|
||||
if (layer) {
|
||||
|
@ -2861,7 +2893,7 @@ void *CustomData_add_layer_named(CustomData *data,
|
|||
const char *name)
|
||||
{
|
||||
CustomDataLayer *layer = customData_add_layer__internal(
|
||||
data, type, alloctype, layerdata, totelem, name);
|
||||
data, type, alloctype, layerdata, totelem, name, false);
|
||||
CustomData_update_typemap(data);
|
||||
|
||||
if (layer) {
|
||||
|
@ -2880,7 +2912,7 @@ void *CustomData_add_layer_anonymous(CustomData *data,
|
|||
{
|
||||
const char *name = anonymous_id->name().c_str();
|
||||
CustomDataLayer *layer = customData_add_layer__internal(
|
||||
data, type, alloctype, layerdata, totelem, name);
|
||||
data, type, alloctype, layerdata, totelem, name, true);
|
||||
CustomData_update_typemap(data);
|
||||
|
||||
if (layer == nullptr) {
|
||||
|
|
Loading…
Reference in New Issue