clone and stencil layer access added, renamed mask to stencil layer internally
[blender.git] / source / blender / makesrna / intern / rna_mesh.c
index a4fda162dc5944d4f81699aa3ff0498256b23833..c298d83850b0a24ad2494b9c97163a6dc5767457 100644 (file)
 #include "WM_api.h"
 #include "WM_types.h"
 
-static void rna_Mesh_update_data(bContext *C, PointerRNA *ptr)
+static void rna_Mesh_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
        DAG_id_flush_update(id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
+       WM_main_add_notifier(NC_GEOM|ND_DATA, id);
 }
 
-static void rna_Mesh_update_select(bContext *C, PointerRNA *ptr)
+static void rna_Mesh_update_select(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
-       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, id);
+       WM_main_add_notifier(NC_GEOM|ND_SELECT, id);
 }
 
-void rna_Mesh_update_draw(bContext *C, PointerRNA *ptr)
+void rna_Mesh_update_draw(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
        ID *id= ptr->id.data;
 
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, id);
+       WM_main_add_notifier(NC_GEOM|ND_DATA, id);
 }
 
 static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value)
@@ -268,6 +268,15 @@ static int rna_CustomDataLayer_active_get(PointerRNA *ptr, int type, int render)
        else return (n == CustomData_get_active_layer_index(fdata, type));
 }
 
+static int rna_CustomDataLayer_clone_get(PointerRNA *ptr, int type, int render)
+{
+       Mesh *me= (Mesh*)ptr->id.data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       int n= ((CustomDataLayer*)ptr->data) - fdata->layers;
+
+       return (n == CustomData_get_clone_layer_index(fdata, type));
+}
+
 static void rna_CustomDataLayer_active_set(PointerRNA *ptr, int value, int type, int render)
 {
        Mesh *me= (Mesh*)ptr->id.data;
@@ -281,6 +290,18 @@ static void rna_CustomDataLayer_active_set(PointerRNA *ptr, int value, int type,
        else CustomData_set_layer_active_index(fdata, type, n);
 }
 
+static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, int value, int type, int render)
+{
+       Mesh *me= (Mesh*)ptr->id.data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       int n= ((CustomDataLayer*)ptr->data) - fdata->layers;
+
+       if(value == 0)
+               return;
+
+       CustomData_set_layer_clone_index(fdata, type, n);
+}
+
 static int rna_uv_texture_check(CollectionPropertyIterator *iter, void *data)
 {
        CustomDataLayer *layer= (CustomDataLayer*)data;
@@ -309,6 +330,26 @@ static PointerRNA rna_Mesh_active_uv_texture_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
 }
 
+static PointerRNA rna_Mesh_uv_texture_clone_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       int index= CustomData_get_clone_layer_index(fdata, CD_MTFACE);
+       CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];
+
+       return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
+}
+
+static PointerRNA rna_Mesh_uv_texture_stencil_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       int index= CustomData_get_stencil_layer_index(fdata, CD_MTFACE);
+       CustomDataLayer *cdl= (index == -1)? NULL: &fdata->layers[index];
+
+       return rna_pointer_inherit_refine(ptr, &RNA_MeshTextureFaceLayer, cdl);
+}
+
 static void rna_Mesh_active_uv_texture_set(PointerRNA *ptr, PointerRNA value)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -325,6 +366,36 @@ static void rna_Mesh_active_uv_texture_set(PointerRNA *ptr, PointerRNA value)
        }
 }
 
+static void rna_Mesh_uv_texture_clone_set(PointerRNA *ptr, PointerRNA value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       CustomDataLayer *cdl;
+       int a;
+
+       for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
+               if(value.data == cdl) {
+                       CustomData_set_layer_clone_index(fdata, CD_MTFACE, a);
+                       return;
+               }
+       }
+}
+
+static void rna_Mesh_uv_texture_stencil_set(PointerRNA *ptr, PointerRNA value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       CustomDataLayer *cdl;
+       int a;
+
+       for(cdl=fdata->layers, a=0; a<fdata->totlayer; cdl++, a++) {
+               if(value.data == cdl) {
+                       CustomData_set_layer_stencil_index(fdata, CD_MTFACE, a);
+                       return;
+               }
+       }
+}
+
 static int rna_Mesh_active_uv_texture_index_get(PointerRNA *ptr)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -332,6 +403,20 @@ static int rna_Mesh_active_uv_texture_index_get(PointerRNA *ptr)
        return CustomData_get_active_layer(fdata, CD_MTFACE);
 }
 
+static int rna_Mesh_uv_texture_clone_index_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       return CustomData_get_clone_layer(fdata, CD_MTFACE);
+}
+
+static int rna_Mesh_uv_texture_stencil_index_get(PointerRNA *ptr)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+       return CustomData_get_stencil_layer(fdata, CD_MTFACE);
+}
+
 static void rna_Mesh_active_uv_texture_index_set(PointerRNA *ptr, int value)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -341,6 +426,22 @@ static void rna_Mesh_active_uv_texture_index_set(PointerRNA *ptr, int value)
        mesh_update_customdata_pointers(me);
 }
 
+static void rna_Mesh_uv_texture_clone_index_set(PointerRNA *ptr, int value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+
+       CustomData_set_layer_clone(fdata, CD_MTFACE, value);
+}
+
+static void rna_Mesh_uv_texture_stencil_index_set(PointerRNA *ptr, int value)
+{
+       Mesh *me= (Mesh*)ptr->data;
+       CustomData *fdata= rna_mesh_fdata(me);
+
+       CustomData_set_layer_stencil(fdata, CD_MTFACE, value);
+}
+
 static void rna_Mesh_active_uv_texture_index_range(PointerRNA *ptr, int *min, int *max)
 {
        Mesh *me= (Mesh*)ptr->data;
@@ -480,6 +581,11 @@ static int rna_MeshTextureFaceLayer_active_get(PointerRNA *ptr)
        return rna_CustomDataLayer_active_get(ptr, CD_MTFACE, 0);
 }
 
+static int rna_MeshTextureFaceLayer_clone_get(PointerRNA *ptr)
+{
+       return rna_CustomDataLayer_clone_get(ptr, CD_MTFACE, 0);
+}
+
 static void rna_MeshTextureFaceLayer_active_render_set(PointerRNA *ptr, int value)
 {
        rna_CustomDataLayer_active_set(ptr, value, CD_MTFACE, 1);
@@ -490,6 +596,11 @@ static void rna_MeshTextureFaceLayer_active_set(PointerRNA *ptr, int value)
        rna_CustomDataLayer_active_set(ptr, value, CD_MTFACE, 0);
 }
 
+static void rna_MeshTextureFaceLayer_clone_set(PointerRNA *ptr, int value)
+{
+       rna_CustomDataLayer_clone_set(ptr, value, CD_MTFACE, 0);
+}
+
 static void rna_MeshTextureFaceLayer_name_set(PointerRNA *ptr, const char *value)
 {
        Mesh *me= (Mesh*)ptr->id.data;
@@ -1108,6 +1219,12 @@ static void rna_def_mtface(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Active Render", "Sets the layer as active for rendering");
        RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 
+       prop= RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "active_clone", 0);
+       RNA_def_property_boolean_funcs(prop, "rna_MeshTextureFaceLayer_clone_get", "rna_MeshTextureFaceLayer_clone_set");
+       RNA_def_property_ui_text(prop, "Active Clone", "Sets the layer as active for cloning");
+       RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
        prop= RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_struct_type(prop, "MeshTextureFace");
        RNA_def_property_ui_text(prop, "Data", "");
@@ -1438,6 +1555,27 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable)
        RNA_def_property_ui_text(prop, "Materials", "");
 }
 
+
+/* scene.objects */
+static void rna_def_mesh_faces(BlenderRNA *brna, PropertyRNA *cprop)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+//     FunctionRNA *func;
+//     PropertyRNA *parm;
+
+       RNA_def_property_srna(cprop, "MeshFaces");
+       srna= RNA_def_struct(brna, "MeshFaces", NULL);
+       RNA_def_struct_sdna(srna, "Mesh");
+       RNA_def_struct_ui_text(srna, "Mesh Faces", "Collection of mesh faces.");
+
+       prop= RNA_def_property(srna, "active", PROP_INT, PROP_NONE);
+       RNA_def_property_int_sdna(prop, NULL, "act_face");
+       RNA_def_property_ui_text(prop, "Active Face", "The active face for this mesh");
+}
+
+
 static void rna_def_mesh(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1461,6 +1599,7 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mface", "totface");
        RNA_def_property_struct_type(prop, "MeshFace");
        RNA_def_property_ui_text(prop, "Faces", "Faces of the mesh.");
+       rna_def_mesh_faces(brna, prop);
 
        prop= RNA_def_property(srna, "sticky", PROP_COLLECTION, PROP_NONE);
        RNA_def_property_collection_sdna(prop, NULL, "msticky", "totvert");
@@ -1492,6 +1631,26 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Active UV Texture Index", "Active UV texture index.");
        RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 
+       prop= RNA_def_property(srna, "uv_texture_clone", PROP_POINTER, PROP_UNSIGNED);
+       RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_clone_get", "rna_Mesh_uv_texture_clone_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Clone UV Texture", "UV texture to be used as cloning source.");
+
+       prop= RNA_def_property(srna, "uv_texture_clone_index", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_clone_index_get", "rna_Mesh_uv_texture_clone_index_set", "rna_Mesh_active_uv_texture_index_range");
+       RNA_def_property_ui_text(prop, "Clone UV Texture Index", "Clone UV texture index.");
+
+       prop= RNA_def_property(srna, "uv_texture_stencil", PROP_POINTER, PROP_UNSIGNED);
+       RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
+       RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_stencil_get", "rna_Mesh_uv_texture_stencil_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Mask UV Texture", "UV texture to mask the painted area.");
+
+       prop= RNA_def_property(srna, "uv_texture_stencil_index", PROP_INT, PROP_UNSIGNED);
+       RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_stencil_index_get", "rna_Mesh_uv_texture_stencil_index_set", "rna_Mesh_active_uv_texture_index_range");
+       RNA_def_property_ui_text(prop, "Mask UV Texture Index", "Mask UV texture index.");
+
        /* Vertex colors */
 
        prop= RNA_def_property(srna, "vertex_colors", PROP_COLLECTION, PROP_NONE);
@@ -1636,7 +1795,8 @@ static void rna_def_mesh(BlenderRNA *brna)
        prop= RNA_def_property(srna, "use_paint_mask", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "editflag", ME_EDIT_PAINT_MASK);
        RNA_def_property_ui_text(prop, "Paint Mask", "Face selection masking for painting");
-
+       RNA_def_property_ui_icon(prop, ICON_FACESEL_HLT, 0);
+       RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
 
 
        rna_def_texmat_common(srna, "rna_Mesh_texspace_editable");