Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Stockner <lukas.stockner@freenet.de>2018-06-14 23:46:30 +0300
committerLukas Stockner <lukas.stockner@freenet.de>2018-06-14 23:46:30 +0300
commit525be2f579c994777328bd7ac206be4769d3e6a4 (patch)
tree40c37d025adf13865647ab24267d212c0b2076e1 /source/blender/makesrna/intern/rna_image.c
parent51f1ed8221042f2e273f5ee47a6053f506a783fc (diff)
Image: Refactor render slots to a dynamic list
Previously, render slots were hardcoded to a fixed amount. With this change, render slots now are stored in a list. Therefore, users can add and/or remove as many slots as they want. Credit to brecht for the UI part. Reviewers: brecht, sergey Differential Revision: https://developer.blender.org/D3474
Diffstat (limited to 'source/blender/makesrna/intern/rna_image.c')
-rw-r--r--source/blender/makesrna/intern/rna_image.c77
1 files changed, 51 insertions, 26 deletions
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index 5736643ab0e..d2b9ee47765 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -462,16 +462,19 @@ static PointerRNA rna_Image_packed_file_get(PointerRNA *ptr)
}
}
-static void rna_Image_render_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+static void rna_RenderSlot_clear(ID *id, RenderSlot *slot, ImageUser *iuser)
{
- Image *image = (Image *)ptr->id.data;
- rna_iterator_array_begin(iter, (void *)image->render_slots, sizeof(RenderSlot), IMA_MAX_RENDER_SLOT, 0, NULL);
+ Image *image = (Image *) id;
+ int index = BLI_findindex(&image->renderslots, slot);
+ BKE_image_clear_renderslot(image, iuser, index);
+
+ WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, image);
}
static PointerRNA rna_render_slots_active_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->id.data;
- RenderSlot *render_slot = &image->render_slots[image->render_slot];
+ RenderSlot *render_slot = BKE_image_get_renderslot(image, image->render_slot);
return rna_pointer_inherit_refine(ptr, &RNA_RenderSlot, render_slot);
}
@@ -480,9 +483,9 @@ static void rna_render_slots_active_set(PointerRNA *ptr, PointerRNA value)
{
Image *image = (Image *)ptr->id.data;
if (value.id.data == image) {
- RenderSlot *render_slot = (RenderSlot *)value.data;
- int index = render_slot - image->render_slots;
- image->render_slot = CLAMPIS(index, 0, IMA_MAX_RENDER_SLOT - 1);
+ RenderSlot *slot = (RenderSlot *)value.data;
+ int index = BLI_findindex(&image->renderslots, slot);
+ if (index != -1) image->render_slot = index;
}
}
@@ -495,8 +498,17 @@ static int rna_render_slots_active_index_get(PointerRNA *ptr)
static void rna_render_slots_active_index_set(PointerRNA *ptr, int value)
{
Image *image = (Image *)ptr->id.data;
+ int num_slots = BLI_listbase_count(&image->renderslots);
image->render_slot = value;
- CLAMP(image->render_slot, 0, IMA_MAX_RENDER_SLOT - 1);
+ CLAMP(image->render_slot, 0, num_slots - 1);
+}
+
+static void rna_render_slots_active_index_range(PointerRNA *ptr, int *min, int *max,
+ int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ Image *image = (Image *)ptr->id.data;
+ *min = 0;
+ *max = max_ii(0, BLI_listbase_count(&image->renderslots) - 1);
}
#else
@@ -596,7 +608,9 @@ static void rna_def_image_packed_files(BlenderRNA *brna)
static void rna_def_render_slot(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
+ PropertyRNA *prop, *parm;
+ FunctionRNA *func;
+
srna = RNA_def_struct(brna, "RenderSlot", NULL);
RNA_def_struct_ui_text(srna, "Render Slot", "Parameters defining the render slot");
@@ -604,32 +618,45 @@ static void rna_def_render_slot(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "name");
RNA_def_property_ui_text(prop, "Name", "Render slot name");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
+
+ func = RNA_def_function(srna, "clear", "rna_RenderSlot_clear");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Clear the render slot");
+ parm = RNA_def_pointer(func, "iuser", "ImageUser", "ImageUser", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
}
-static void rna_def_render_slots(BlenderRNA *brna)
+static void rna_def_render_slots(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
- PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *prop, *parm;
+ RNA_def_property_srna(cprop, "RenderSlots");
srna = RNA_def_struct(brna, "RenderSlots", NULL);
- RNA_def_struct_sdna(srna, "RenderSlot");
- RNA_def_struct_ui_text(srna, "Render Slots", "Collection of the render slots");
+ RNA_def_struct_sdna(srna, "Image");
+ RNA_def_struct_ui_text(srna, "Render Layers", "Collection of render layers");
+
+ prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "render_slot");
+ RNA_def_property_int_funcs(prop, "rna_render_slots_active_index_get",
+ "rna_render_slots_active_index_set",
+ "rna_render_slots_active_index_range");
+ RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
+ RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "RenderSlot");
RNA_def_property_pointer_funcs(prop, "rna_render_slots_active_get", "rna_render_slots_active_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
- prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
- RNA_def_property_int_funcs(prop, "rna_render_slots_active_index_get",
- "rna_render_slots_active_index_set",
- NULL);
- RNA_def_property_range(prop, 0, IMA_MAX_RENDER_SLOT);
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_ui_text(prop, "Active Index", "Index of an active render slot of the image");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
+ func = RNA_def_function(srna, "new", "BKE_image_add_renderslot");
+ RNA_def_function_ui_description(func, "Add a render slot to the image");
+ parm = RNA_def_string(func, "name", NULL, 0, "Name", "New name for the render slot");
+ parm = RNA_def_pointer(func, "result", "RenderSlot", "", "Newly created render layer");
+ RNA_def_function_return(func, parm);
}
static void rna_def_image(BlenderRNA *brna)
@@ -811,10 +838,9 @@ static void rna_def_image(BlenderRNA *brna)
prop = RNA_def_property(srna, "render_slots", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "RenderSlot");
+ RNA_def_property_collection_sdna(prop, NULL, "renderslots", NULL);
RNA_def_property_ui_text(prop, "Render Slots", "Render slots of the image");
- RNA_def_property_collection_funcs(prop, "rna_Image_render_slots_begin", "rna_iterator_array_next",
- "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
- RNA_def_property_srna(prop, "RenderSlots");
+ rna_def_render_slots(brna, prop);
/*
* Image.has_data and Image.depth are temporary,
@@ -897,7 +923,6 @@ static void rna_def_image(BlenderRNA *brna)
void RNA_def_image(BlenderRNA *brna)
{
rna_def_render_slot(brna);
- rna_def_render_slots(brna);
rna_def_image(brna);
rna_def_imageuser(brna);
rna_def_image_packed_files(brna);