code cleanup and minor changes
authorCampbell Barton <ideasman42@gmail.com>
Sat, 22 Dec 2012 01:08:42 +0000 (01:08 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 22 Dec 2012 01:08:42 +0000 (01:08 +0000)
- use DummyRNA_NULL_items to replace empty enums.
- replace calloc with malloc in copy_dverts since its copied over after.
- add wmGesture->userdata, so operators that use gestures have somewhere to store their own data (not used yet).

source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/mesh.c
source/blender/editors/armature/poselib.c
source/blender/editors/interface/view2d_ops.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/space_outliner/outliner_tools.c
source/blender/windowmanager/WM_types.h
source/blender/windowmanager/intern/wm_gesture.c

index 5515509e92dc32331187bd1a106a840d732d04a0..7b6f57f9a09258fe62b352ead2f6ea7aa6e6286f 100644 (file)
@@ -152,7 +152,7 @@ void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase,
                                   int **orco_index_ptr);
 void BKE_mesh_from_curve(struct Scene *scene, struct Object *ob);
 void free_dverts(struct MDeformVert *dvert, int totvert);
-void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */
+void copy_dverts(struct MDeformVert *dst, const struct MDeformVert *src, int totvert);
 void BKE_mesh_delete_material_index(struct Mesh *me, short index);
 void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth);
 void BKE_mesh_convert_mfaces_to_mpolys(struct Mesh *mesh);
index 960607154dad0d6869f49e1e1d504964aa8fefa6..1e6f667c40b5a59517a39f37df1ff10360d7157d 100644 (file)
@@ -430,7 +430,7 @@ void BKE_mesh_free(Mesh *me, int unlink)
        if (me->edit_btmesh) MEM_freeN(me->edit_btmesh);
 }
 
-void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
+void copy_dverts(MDeformVert *dst, const MDeformVert *src, int copycount)
 {
        /* Assumes dst is already set up */
        int i;
@@ -442,7 +442,7 @@ void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
        
        for (i = 0; i < copycount; i++) {
                if (src[i].dw) {
-                       dst[i].dw = MEM_callocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight");
+                       dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight");
                        memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight);
                }
        }
index ae3d496b641bf6b986cb905bae28af4dcd75ff13..04815b9c33c0c836ade8f0d7c9cab69b3ad01052 100644 (file)
@@ -687,9 +687,6 @@ static int poselib_rename_exec(bContext *C, wmOperator *op)
 void POSELIB_OT_pose_rename(wmOperatorType *ot)
 {
        PropertyRNA *prop;
-       static EnumPropertyItem prop_poses_dummy_types[] = {
-               {0, NULL, 0, NULL, NULL}
-       };
        
        /* identifiers */
        ot->name = "PoseLib Rename Pose";
@@ -707,7 +704,7 @@ void POSELIB_OT_pose_rename(wmOperatorType *ot)
        /* properties */
        /* NOTE: name not pose is the operator's "main" property, so that it will get activated in the popup for easy renaming */
        ot->prop = RNA_def_string(ot->srna, "name", "RenamedPose", 64, "New Pose Name", "New name for pose");
-       prop = RNA_def_enum(ot->srna, "pose", prop_poses_dummy_types, 0, "Pose", "The pose to rename");
+       prop = RNA_def_enum(ot->srna, "pose", DummyRNA_NULL_items, 0, "Pose", "The pose to rename");
        RNA_def_enum_funcs(prop, poselib_stored_pose_itemf);
 }
 
index 4a3daaf71c2e032a0a90bf25393848cbbd4081a9..006644bf366083d3e9af41ffae7847bab29c6e96 100644 (file)
@@ -1020,7 +1020,7 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, wmEvent *event)
                        
                        /* y-axis transform */
                        dist = BLI_rcti_size_y(&v2d->mask) / 2.0f;
-                       dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin- dist) + 2.0f) / (fabsf(event->mval[1] - dist) + 2.0f);
+                       dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / (fabsf(event->mval[1] - dist) + 2.0f);
                        dy *= 0.5f * BLI_rctf_size_y(&v2d->cur);
                }
                else {
index 4fcec28a26b9fbc1afff0e4613fdec925497a4f0..a1978f110ac0a09544d79904640b1df6c4b6c972 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "RNA_define.h"
 #include "RNA_access.h"
+#include "RNA_enum_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_noise.h"
@@ -2528,7 +2529,6 @@ static void edbm_blend_from_shape_ui(bContext *C, wmOperator *op)
 void MESH_OT_blend_from_shape(wmOperatorType *ot)
 {
        PropertyRNA *prop;
-       static EnumPropertyItem shape_items[] = {{0, NULL, 0, NULL, NULL}};
 
        /* identifiers */
        ot->name = "Blend From Shape";
@@ -2545,7 +2545,7 @@ void MESH_OT_blend_from_shape(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* properties */
-       prop = RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending");
+       prop = RNA_def_enum(ot->srna, "shape", DummyRNA_NULL_items, 0, "Shape", "Shape key to use for blending");
        RNA_def_enum_funcs(prop, shape_itemf);
        RNA_def_float(ot->srna, "blend", 1.0f, -FLT_MAX, FLT_MAX, "Blend", "Blending factor", -2.0f, 2.0f);
        RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather than blend between shapes");
index 12edb3e8edb4b05e949bb6c45957f0921efa3d87..c9492d8f68391ce98e4d008f8f1f2efa2722ebde 100644 (file)
@@ -1676,10 +1676,6 @@ static EnumPropertyItem game_properties_copy_operations[] = {
        {0, NULL, 0, NULL, NULL}
 };
 
-static EnumPropertyItem gameprops_items[] = {
-       {0, NULL, 0, NULL, NULL}
-};
-
 static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
 {      
        Object *ob = ED_object_active_context(C);
@@ -1689,7 +1685,7 @@ static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), P
        int a, totitem = 0;
        
        if (!ob)
-               return gameprops_items;
+               return DummyRNA_NULL_items;
 
        for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
                tmp.value = a;
@@ -1760,7 +1756,7 @@ void OBJECT_OT_game_property_copy(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
-       prop = RNA_def_enum(ot->srna, "property", gameprops_items, 0, "Property", "Properties to copy");
+       prop = RNA_def_enum(ot->srna, "property", DummyRNA_NULL_items, 0, "Property", "Properties to copy");
        RNA_def_property_flag(prop, PROP_SKIP_SAVE);
        RNA_def_enum_funcs(prop, gameprops_itemf);
        ot->prop = prop;
index f3e792def1744472ecdc29ff9dfd11ffec2552a3..40e8fe72e8c9d9807cd8eca2e759ee5777d737c6 100644 (file)
@@ -65,6 +65,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -3369,10 +3370,6 @@ void OBJECT_OT_vertex_group_transfer_weight(wmOperatorType *ot)
        ot->prop = RNA_def_enum(ot->srna, "WT_replace_mode", WT_replace_mode_item, 1, "Replace", "");
 }
 
-static EnumPropertyItem vgroup_items[] = {
-       {0, NULL, 0, NULL, NULL}
-};
-
 static int set_active_group_exec(bContext *C, wmOperator *op)
 {
        Object *ob = ED_object_context(C);
@@ -3396,7 +3393,7 @@ static EnumPropertyItem *vgroup_itemf(bContext *C, PointerRNA *UNUSED(ptr), Prop
        int a, totitem = 0;
        
        if (!ob)
-               return vgroup_items;
+               return DummyRNA_NULL_items;
        
        for (a = 0, def = ob->defbase.first; def; def = def->next, a++) {
                tmp.value = a;
@@ -3430,7 +3427,7 @@ void OBJECT_OT_vertex_group_set_active(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
        /* properties */
-       prop = RNA_def_enum(ot->srna, "group", vgroup_items, 0, "Group", "Vertex group to set as active");
+       prop = RNA_def_enum(ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "Vertex group to set as active");
        RNA_def_enum_funcs(prop, vgroup_itemf);
        ot->prop = prop;
 }
index 9bbf99ff3cf0a1e18245a9dd1be8e436870ef46c..7134f1c23671247bda2876fe093ca45b8da704b8 100644 (file)
@@ -402,12 +402,28 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
        return -1;
 }
 
-static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot)
+static void free_vpaint_prev(VPaint *vp)
 {
        if (vp->vpaint_prev) {
                MEM_freeN(vp->vpaint_prev);
                vp->vpaint_prev = NULL;
+               vp->tot = 0;
+       }
+}
+
+static void free_wpaint_prev(VPaint *vp)
+{
+       if (vp->wpaint_prev) {
+               MEM_freeN(vp->wpaint_prev);
+               vp->wpaint_prev = NULL;
+               vp->tot = 0;
        }
+}
+
+static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot)
+{
+       free_vpaint_prev(vp);
+
        vp->tot = tot;
        
        if (lcol == NULL || tot == 0) return;
@@ -419,10 +435,7 @@ static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot)
 
 static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount)
 {
-       if (wp->wpaint_prev) {
-               free_dverts(wp->wpaint_prev, wp->tot);
-               wp->wpaint_prev = NULL;
-       }
+       free_wpaint_prev(wp);
        
        if (dverts && dcount) {
                
@@ -432,7 +445,6 @@ static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount)
        }
 }
 
-
 void vpaint_fill(Object *ob, unsigned int paintcol)
 {
        Mesh *me;
index 3b83279e09d32d048aadf94fc948a63eb243cbbc..b2070cc2f1c331b2963679c696434ec723905042 100644 (file)
@@ -764,7 +764,7 @@ static EnumPropertyItem prop_id_op_types[] = {
        {OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""},
        {OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""},
        {OUTLINER_IDOP_FAKE_ADD, "ADD_FAKE", 0, "Add Fake User",
-     "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"},
+        "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"},
        {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""},
        {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""},
        {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
index 347f46c816688b12fcdff6605d71318449ad5dec..96a7b156cd89c480205273e7dd73e329c1a2e96b 100644 (file)
@@ -407,6 +407,9 @@ typedef struct wmGesture {
        /* customdata for circle is recti, (xmin, ymin) is center, xmax radius */
        /* customdata for lasso is short array */
        /* customdata for straight line is a recti: (xmin,ymin) is start, (xmax, ymax) is end */
+
+       /* free pointer to use for operator allocs (if set, its freed on exit)*/
+       void *userdata;
 } wmGesture;
 
 /* ************** wmEvent ************************ */
index a80386e98606a168863e96f1c808fc714428dbac..1cf44a69c1778a105b883ae54fa1958821c997e7 100644 (file)
@@ -113,6 +113,9 @@ void WM_gesture_end(bContext *C, wmGesture *gesture)
                win->tweak = NULL;
        BLI_remlink(&win->gesture, gesture);
        MEM_freeN(gesture->customdata);
+       if (gesture->userdata) {
+               MEM_freeN(gesture->userdata);
+       }
        MEM_freeN(gesture);
 }