The zblur plugin (aka as DoF) integrated in render. Compared to patch
[blender.git] / source / blender / src / buttons_editing.c
index 7829aa467bd002e23736a56b54274e5d323cb806..c55574d97915216243799134c32ca05ef883cbed 100644 (file)
 #include "BKE_constraint.h"
 #include "BKE_curve.h"
 #include "BKE_displist.h"
+#include "BKE_DerivedMesh.h"
 #include "BKE_effect.h"
 #include "BKE_font.h"
 #include "BKE_ika.h"
@@ -264,7 +265,6 @@ static void decimate_faces(void)
 
        if(LOD_LoadMesh(&lod) ) {
                if( LOD_PreprocessMesh(&lod) ) {
-                       DispList *dl;
                        DispListMesh *dlm;
                        MFace *mfaceint;
 
@@ -275,11 +275,11 @@ static void decimate_faces(void)
                        }
 
                        /* ok, put back the stuff in a displist */
-                       freedisplist(&(ob->disp));
-                       dl= MEM_callocN(sizeof(DispList), "disp");
-                       BLI_addtail(&ob->disp, dl);
-                       dl->type= DL_MESH;
-                       dlm=dl->mesh= MEM_callocN(sizeof(DispListMesh), "dispmesh");
+                       if (me->decimated) {
+                               displistmesh_free(me->decimated);
+                       }
+
+                       dlm= me->decimated= MEM_callocN(sizeof(DispListMesh), "dispmesh");
                        dlm->mvert= MEM_callocN(lod.vertex_num*sizeof(MVert), "mvert");
                        dlm->mface= MEM_callocN(lod.face_num*sizeof(MFace), "mface");
                        dlm->totvert= lod.vertex_num;
@@ -320,8 +320,14 @@ static void decimate_cancel(void)
 
        ob= OBACT;
        if(ob) {
-               freedisplist(&ob->disp);
-               makeDispList(ob);
+               if (ob->type==OB_MESH) {
+                       Mesh *me = ob->data;
+                       
+                       if (me->decimated) {
+                               displistmesh_free(me->decimated);
+                               me->decimated = NULL;
+                       }
+               }
        }
        allqueue(REDRAWVIEW3D, 0);
 }
@@ -329,9 +335,6 @@ static void decimate_cancel(void)
 static void decimate_apply(void)
 {
        Object *ob;
-       DispList *dl;
-       DispListMesh *dlm;
-       Mesh *me;
        MFace *mface;
        MFace *mfaceint;
        int a;
@@ -339,11 +342,11 @@ static void decimate_apply(void)
        if(G.obedit) return;
 
        ob= OBACT;
-       if(ob) {
-               dl= ob->disp.first;
-               if(dl && dl->mesh) {
-                       dlm= dl->mesh;
-                       me= ob->data;
+       if(ob && ob->type==OB_MESH) {
+               Mesh *me = ob->data;
+
+               if (me->decimated) {
+                       DispListMesh *dlm= me->decimated;
 
                        // vertices
                        if(me->mvert) MEM_freeN(me->mvert);
@@ -369,7 +372,8 @@ static void decimate_apply(void)
                                test_index_mface(mface, 3);
                        }
 
-                       freedisplist(&ob->disp);
+                       displistmesh_free(me->decimated);
+                       me->decimated= NULL;
 
                        G.obedit= ob;
                        make_editMesh();
@@ -652,11 +656,7 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me)
        uiBlock *block;
        float val;
        /* Hope to support more than two subsurf algorithms */
-#ifdef USE_CCGSUBSURFLIB
-       char subsurfmenu[]="Subsurf Type%t|Catmull-Clark%x0|CCGSubSurf%x2|Simple Subdiv.%x1";
-#else
        char subsurfmenu[]="Subsurf Type%t|Catmull-Clark%x0|Simple Subdiv.%x1";
-#endif
 
        block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_type", UI_EMBOSS, UI_HELV, curarea->win);
        if( uiNewPanel(curarea, block, "Mesh", "Editing", 320, 0, 318, 204)==0) return;
@@ -667,12 +667,12 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me)
 
        uiBlockBeginAlign(block);
        uiBlockSetCol(block, TH_BUT_SETTING1);
-       uiDefButS(block, TOG|BIT|7, B_MAKEDISP, "SubSurf",      10,134,70,19, &me->flag, 0, 0, 0, 0, "Treats the active object as a Subdivision Surface");
-       uiDefButS(block, MENU, B_MAKEDISP, subsurfmenu,         80,134,84,19, &(me->subsurftype), 0, 0, 0, 0, "Selects type of Subsurf algorithm.");
+       uiDefButS(block, TOG|BIT|7, B_SUBSURFTYPE, "SubSurf",   10,134,70,19, &me->flag, 0, 0, 0, 0, "Treats the active object as a Subdivision Surface");
+       uiDefButS(block, MENU, B_SUBSURFTYPE, subsurfmenu,              80,134,84,19, &(me->subsurftype), 0, 0, 0, 0, "Selects type of Subsurf algorithm.");
        uiBlockSetCol(block, TH_AUTO);
-       uiDefButS(block, NUM, B_MAKEDISP, "Subdiv:",            10, 114,110,19, &me->subdiv, 0, 6, 0, 0, "Defines the level of subdivision to display in real time interactively");
+       uiDefButS(block, NUM, B_SUBSURFTYPE, "Subdiv:",         10, 114,110,19, &me->subdiv, 0, 6, 0, 0, "Defines the level of subdivision to display in real time interactively");
        uiDefButS(block, NUM, B_DIFF, "",                               120,114, 44, 19, &me->subdivr, 0, 6, 0, 0, "Defines the level of subdivision to apply during rendering");
-       uiDefButS(block, TOG|BIT|8, B_MAKEDISP, "Optimal",      10, 94,154,19, &me->flag, 0, 0, 0, 0, "Only draws optimal wireframe");
+       uiDefButS(block, TOG|BIT|8, B_SUBSURFTYPE, "Optimal",   10, 94,154,19, &me->flag, 0, 0, 0, 0, "Only draws optimal wireframe");
 
        uiBlockBeginAlign(block);
 
@@ -709,11 +709,11 @@ static void editing_panel_mesh_type(Object *ob, Mesh *me)
        /* decimator */
        if(G.obedit==NULL) {
                int tottria= decimate_count_tria(ob);
-               DispList *dl;
+               Mesh *me = ob->data;
 
-               // wacko, wait for new displist system (ton)
-               if( (dl=ob->disp.first) && dl->mesh);
-               else decim_faces= tottria;
+               if (!me->decimated) {
+                       decim_faces= tottria;
+               }
 
                uiBlockBeginAlign(block);
                uiBlockSetCol(block, TH_BUT_SETTING1);
@@ -1085,22 +1085,33 @@ void do_curvebuts(unsigned short event)
                        allqueue(REDRAWVIEW3D, 0);
                }
                break;
+       case B_SUBSURFTYPE:
+                       /* Icky, find better system */
+               if(ob->type==OB_MESH && G.obedit && ob->data==G.obedit->data) {
+                       if(G.editMesh->derived) {
+                               G.editMesh->derived->release(G.editMesh->derived);
+                               G.editMesh->derived= NULL;
+                       }
+               }
+               /* fallthrough */
        case B_MAKEDISP:
-               if(ob->type==OB_FONT) text_to_curve(ob, 0);
-               makeDispList(ob);
-               if(ob!=G.obedit) { // subsurf with linked dupli will crash
-                       /* we need signal to send to other users of same data to recalc... */
-                       base= FIRSTBASE;
-                       while(base) {
-                               if(base->lay & G.vd->lay) {
-                                       if(base->object->data==ob->data && base->object!=ob)
-                                               makeDispList(base->object);
+               if(G.vd) {
+                       if(ob->type==OB_FONT) text_to_curve(ob, 0);
+                       makeDispList(ob);
+                       if(ob!=G.obedit) { // subsurf with linked dupli will crash
+                               /* we need signal to send to other users of same data to recalc... */
+                               base= FIRSTBASE;
+                               while(base) {
+                                       if(base->lay & G.vd->lay) {
+                                               if(base->object->data==ob->data && base->object!=ob)
+                                                       makeDispList(base->object);
+                                       }
+                                       base= base->next;
                                }
-                               base= base->next;
                        }
+                       allqueue(REDRAWVIEW3D, 0);
+                       allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
                }
-               allqueue(REDRAWVIEW3D, 0);
-               allqueue(REDRAWINFO, 1);        /* 1, because header->win==0! */
                break;
 
        case B_SUBDIVCURVE:
@@ -1109,8 +1120,7 @@ void do_curvebuts(unsigned short event)
        case B_SPINNURB:
                /* bad bad bad!!! use brackets!!! In case you wondered:
                  {==,!=} goes before & goes before || */
-               if( (G.obedit==0) ||
-                   (G.obedit->type!=OB_SURF) ||
+               if( (G.obedit==NULL) || (G.obedit->type!=OB_SURF) || (G.vd==NULL) ||
                        ((G.obedit->lay & G.vd->lay) == 0) ) return;
                spinNurb(0, 0);
                countall();
@@ -1210,9 +1220,9 @@ static void editing_panel_curve_tools(Object *ob, Curve *cu)
                        sp= &(nu->orderv);
                        uiDefButS(block, NUM, B_SETORDER, "V:",         670,90,50, 19, sp, 2.0, 6.0, 0, 0, "Nurbs only; the amount of control points involved");
                        sp= &(nu->resolu);
-                       uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 19, sp, 1.0, 128.0, 0, 0, "The amount of new points interpolated per control vertex pair");
+                       uiDefButS(block, NUM, B_MAKEDISP, "Resol U:", 565,70,102, 19, sp, 1.0, 1024.0, 0, 0, "The amount of new points interpolated per control vertex pair");
                        sp= &(nu->resolv);
-                       uiDefButS(block, NUM, B_MAKEDISP, "V:",         670,70,50, 19, sp, 1.0, 128.0, 0, 0, "The amount of new points interpolated per control vertex pair");
+                       uiDefButS(block, NUM, B_MAKEDISP, "V:",         670,70,50, 19, sp, 1.0, 1024.0, 0, 0, "The amount of new points interpolated per control vertex pair");
                }
        }
 
@@ -1285,7 +1295,7 @@ static void editing_panel_curve_type(Object *ob, Curve *cu)
                }
 
                uiBlockBeginAlign(block);
-               uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 128.0, 0, 0, "Default resolution");
+               uiDefButS(block, NUM, B_MAKEDISP, "DefResolU:", 760,160,120,19, &cu->resolu, 1.0, 1024.0, 0, 0, "Default resolution");
                uiDefBut(block, BUT, B_SETRESOLU, "Set",                880,160,30,19, 0, 0, 0, 0, 0, "Set resolution for interpolation");
 
                uiBlockBeginAlign(block);
@@ -1334,10 +1344,10 @@ static void editing_panel_camera_type(Object *ob, Camera *cam)
 
        uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
 
-       uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
+       uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho",            470,29,61,60, &cam->type, 0, 0, 0, 0, "Render orthogonally");
        uiBlockBeginAlign(block);
-       uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
-       uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist", 533,49,97,20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
+       uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,59,97,30, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
+       uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist",  533,29,97,30, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
        uiBlockEndAlign(block);
 }
 
@@ -1369,6 +1379,23 @@ static void editing_panel_camera_yafraydof(Object *ob, Camera *cam)
 
 }
 
+/* **************************** CAMERA *************************** */
+
+void do_cambuts(unsigned short event)
+{
+       Object *ob;
+       Camera *cam;
+       
+       ob= OBACT;
+       if (ob==0) return;
+       cam= ob->data;
+
+       switch(event) {
+       case 0:
+               ;
+               break;
+       }
+}
 
 /* *************************** MBALL ******************************** */
 
@@ -1393,17 +1420,17 @@ static void editing_panel_mball_type(Object *ob, MetaBall *mb)
        mb= ob->data;
 
        uiBlockBeginAlign(block);
-       uiDefButF(block, NUM, B_RECALCMBALL, "Wiresize:",       470,178,250,19, &mb->wiresize, 0.05, 1.0, 0, 0, "Polygonization resolution in 3d window");
-       uiDefButF(block, NUM, 0, "Rendersize:",                 470,158,250,19, &mb->rendersize, 0.05, 1.0, 0, 0, "Polygonization resolution in rendering");
-       uiDefButF(block, NUM, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 0, 0, "Defines influence of meta elements");
+       uiDefButF(block, NUM, B_RECALCMBALL, "Wiresize:", 470,178,250,19, &mb->wiresize, 0.05, 1.0, 1, 0, "Polygonization resolution in 3d window");
+       uiDefButF(block, NUM, 0, "Rendersize:", 470,158,250,19, &mb->rendersize, 0.05, 1.0, 1, 0, "Polygonization resolution in rendering");
+       uiDefButF(block, NUM, B_RECALCMBALL, "Threshold:", 470,138,250,19, &mb->thresh, 0.0001, 5.0, 1, 0, "Defines influence of meta elements");
 
        uiBlockBeginAlign(block);
        uiBlockSetCol(block, TH_BUT_SETTING1);
-       uiDefBut(block, LABEL, 0, "Update:",            471,108,120,19, 0, 0, 0, 0, 0, "");
+       uiDefBut(block, LABEL, 0, "Update:", 471,108,120,19, 0, 0, 0, 0, 0, "");
        uiDefButS(block, ROW, B_DIFF, "Always", 471, 85, 120, 19, &mb->flag, 0.0, 0.0, 0, 0, "While editing, always updates");
-       uiDefButS(block, ROW, B_DIFF, "Half Res",       471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "While editing, updates in half resolution");
-       uiDefButS(block, ROW, B_DIFF, "Fast",           471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "While editing, updates without polygonization");
-       uiDefButS(block, ROW, B_DIFF, "Never",          471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "While editing, doesn't update");
+       uiDefButS(block, ROW, B_DIFF, "Half Res", 471, 65, 120, 19, &mb->flag, 0.0, 1.0, 0, 0, "While editing, updates in half resolution");
+       uiDefButS(block, ROW, B_DIFF, "Fast", 471, 45, 120, 19, &mb->flag, 0.0, 2.0, 0, 0, "While editing, updates without polygonization");
+       uiDefButS(block, ROW, B_DIFF, "Never", 471, 25, 120, 19, &mb->flag, 0.0, 3.0, 0, 0, "While editing, doesn't update");
 
 }
 
@@ -1417,22 +1444,22 @@ static void editing_panel_mball_tools(Object *ob, MetaBall *mb)
 
        if(ob==G.obedit && lastelem) {
                uiBlockBeginAlign(block);
-               uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 0, 0, "Stiffness for active meta");
+               uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 750,178,250,19, &lastelem->s, 0.0, 10.0, 1, 0, "Stiffness for active meta");
                if(lastelem->type!=MB_BALL)
-               uiDefButF(block, NUM, B_RECALCMBALL, "dx:",             750,158,250,19, &lastelem->expx, 0.0, 20.0, 0, 0, "X size for active meta");
+               uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 750,158,250,19, &lastelem->expx, 0.0, 20.0, 1, 0, "X size for active meta");
                if((lastelem->type!=MB_BALL)&&(lastelem->type!=MB_TUBE))
-               uiDefButF(block, NUM, B_RECALCMBALL, "dy:",             750,138,250,19, &lastelem->expy, 0.0, 20.0, 0, 0, "Y size for active meta");
+               uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 750,138,250,19, &lastelem->expy, 0.0, 20.0, 1, 0, "Y size for active meta");
 
                if((lastelem->type==MB_CUBE)||(lastelem->type==MB_ELIPSOID))
-               uiDefButF(block, NUM, B_RECALCMBALL, "dz:",             750,118,250,19, &lastelem->expz, 0.0, 20.0, 0, 0, "Z size for active meta");
+               uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 750,118,250,19, &lastelem->expz, 0.0, 20.0, 1, 0, "Z size for active meta");
                uiBlockEndAlign(block);
 
-               uiDefButS(block, ROW, B_RECALCMBALL, "Ball",                    753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "Draw active meta as Ball");
+               uiDefButS(block, ROW, B_RECALCMBALL, "Ball", 753,83,60,19, &lastelem->type, 1.0, 0.0, 0, 0, "Draw active meta as Ball");
                uiBlockBeginAlign(block);
-               uiDefButS(block, ROW, B_RECALCMBALL, "Tube",                    753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "Draw active meta as Ball");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Plane",                   814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "Draw active meta as Plane");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid",                876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "Draw active meta as Ellipsoid");
-               uiDefButS(block, ROW, B_RECALCMBALL, "Cube",                    938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "Draw active meta as Cube");
+               uiDefButS(block, ROW, B_RECALCMBALL, "Tube", 753,62,60,19, &lastelem->type, 1.0, 4.0, 0, 0, "Draw active meta as Ball");
+               uiDefButS(block, ROW, B_RECALCMBALL, "Plane", 814,62,60,19, &lastelem->type, 1.0, 5.0, 0, 0, "Draw active meta as Plane");
+               uiDefButS(block, ROW, B_RECALCMBALL, "Elipsoid", 876,62,60,19, &lastelem->type, 1.0, 6.0, 0, 0, "Draw active meta as Ellipsoid");
+               uiDefButS(block, ROW, B_RECALCMBALL, "Cube", 938,62,60,19, &lastelem->type, 1.0, 7.0, 0, 0, "Draw active meta as Cube");
                uiBlockEndAlign(block);
 
                uiBlockBeginAlign(block);
@@ -1460,6 +1487,7 @@ void do_latticebuts(unsigned short event)
                if(ob) {
                        if(ob==G.obedit) resizelattice(editLatt);
                        else resizelattice(ob->data);
+                       ob->softflag |= OB_SB_REDO;
                }
                allqueue(REDRAWVIEW3D, 0);
                break;
@@ -1810,14 +1838,14 @@ static void editing_panel_armature_bones(Object *ob, bArmature *arm)
 
                        uiDefBut(block, LABEL, 0, "child of", bx+107,by,73,18, NULL, 0.0, 0.0, 0.0, 0.0, "");
 
-                       boneString = malloc((BLI_countlist(&G.edbo) * 64)+64);
+                       boneString = MEM_mallocN((BLI_countlist(&G.edbo) * 64)+64, "Bone str");
                        build_bonestring (boneString, curBone);
 
                        curBone->parNr = editbone_to_parnr(curBone->parent);
                        but = uiDefButI(block, MENU,REDRAWVIEW3D, boneString, bx+180,by,120,18, &curBone->parNr, 0.0, 0.0, 0.0, 0.0, "Parent");
                        uiButSetFunc(but, parnr_to_editbone_cb, curBone, NULL);
 
-                       free(boneString);
+                       MEM_freeN(boneString);
 
                        /* IK to parent flag */
                        if (curBone->parent){
@@ -2155,6 +2183,49 @@ static void editing_panel_mesh_tools1(Object *ob, Mesh *me)
 
 }
 
+char *get_vertexgroup_menustr(Object *ob)
+{
+       bDeformGroup *dg;
+       int defCount, min, index;
+       char (*qsort_ptr)[32] = NULL;
+       char *s, *menustr;
+       
+       defCount=BLI_countlist(&ob->defbase);
+       
+       if (!defCount) min=0;
+       else min=1;
+       
+       if (defCount > 0) {
+               /*
+                * This will hold the group names temporarily
+                * so we can sort them
+                */
+               qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
+                                                                "qsort_ptr");
+               for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
+                       snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
+                                         "%s%%x%d|", dg->name, index);
+               }
+               
+               qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
+                          ( int (*)(const void *, const void *) ) strcmp);
+       }
+       
+       s= menustr = MEM_callocN((32 * defCount)+30, "menustr");        // plus 30 for when defCount==0
+       if(defCount) {
+               for (index = 0; index < defCount; index++) {
+                       int cnt= sprintf (s, "%s", qsort_ptr[index]);
+                       if (cnt>0) s+= cnt;
+               }
+       }
+       else strcpy(menustr, "No Vertex Groups in Object");
+       
+       if (qsort_ptr)
+               MEM_freeN (qsort_ptr);
+       
+       return menustr;
+}
+
 static void editing_panel_links(Object *ob)
 {
        uiBlock *block;
@@ -2254,52 +2325,20 @@ static void editing_panel_links(Object *ob)
                uiBut *but;
                int     defCount;
                bDeformGroup    *defGroup;
-               char *s, *menustr;
-               bDeformGroup *dg;
-               int min, index;
-               char (*qsort_ptr)[32] = NULL;
-
+       
                uiDefBut(block, LABEL,0,"Vertex Groups",
                                 143,153,130,20, 0, 0, 0, 0, 0, "");
 
                defCount=BLI_countlist(&ob->defbase);
 
-               if (!defCount) min=0;
-               else min=1;
-
-               if (defCount > 0) {
-                       /*
-                        * This will hold the group names temporarily
-                        * so we can sort them
-                        */
-                       qsort_ptr = MEM_callocN (defCount * sizeof (qsort_ptr[0]),
-                                                                        "qsort_ptr");
-                       for (index = 1, dg = ob->defbase.first; dg; index++, dg=dg->next) {
-                               snprintf (qsort_ptr[index - 1], sizeof (qsort_ptr[0]),
-                                                 "%s%%x%d|", dg->name, index);
-                       }
-
-                       qsort (qsort_ptr, defCount, sizeof (qsort_ptr[0]),
-                                  ( int (*)(const void *, const void *) ) strcmp);
-               }
-
-               s= menustr = MEM_callocN((32 * defCount)+20, "menustr");
-               for (index = 0; index < defCount; index++) {
-                       int cnt= sprintf (s, "%s", qsort_ptr[index]);
-                       if (cnt>0) s+= cnt;
-               }
-
-               if (qsort_ptr)
-                 MEM_freeN (qsort_ptr);
-
                uiBlockBeginAlign(block);
-               if (defCount)
-                       uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr,
-                                         143, 132,18,21, &ob->actdef, min, defCount, 0, 0,
-                                         "Browses available vertex groups");
-
-               MEM_freeN (menustr);
-
+               if (defCount) {
+                       char *menustr= get_vertexgroup_menustr(ob);
+                       
+                       uiDefButS(block, MENU, REDRAWBUTSEDIT, menustr, 143, 132,18,21, &ob->actdef, 1, defCount, 0, 0, "Browses available vertex groups");
+                       MEM_freeN (menustr);
+               }
+               
                if (ob->actdef){
                        defGroup = BLI_findlink(&ob->defbase, ob->actdef-1);
                        but= uiDefBut(block, TEX,REDRAWBUTSEDIT,"",             161,132,140-18,21, defGroup->name, 0, 32, 0, 0, "Displays current vertex group name. Click to change. (Match bone name for deformation.)");