Merged 38822-39182
[blender.git] / source / blender / editors / space_view3d / view3d_header.c
index 2656127..993c28f 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/space_view3d/view3d_header.c
+ *  \ingroup spview3d
+ */
+
+
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -137,13 +142,31 @@ static void handle_view3d_lock(bContext *C)
        }
 }
 
+/* layer code is on three levels actually:
+- here for operator
+- uiTemplateLayers in interface/ code for buttons
+- ED_view3d_scene_layer_set for RNA
+ */
+static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
+{
+       /* sanity check - when in editmode disallow switching the editmode layer off since its confusing
+        * an alternative would be to always draw the editmode object. */
+       if(scene->obedit && (scene->obedit->lay & v3d->lay)==0) {
+               int bit;
+               for(bit=0; bit<32; bit++) {
+                       if(scene->obedit->lay & (1<<bit)) {
+                               v3d->lay |= 1<<bit;
+                               break;
+                       }
+               }
+       }
+}
+
 static int view3d_layers_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
-       Base *base;
-       int oldlay= v3d->lay;
        int nr= RNA_int_get(op->ptr, "nr");
        int toggle= RNA_boolean_get(op->ptr, "toggle");
        
@@ -158,7 +181,10 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
                if (toggle && v3d->lay == ((1<<20)-1)) {
                        /* return to active layer only */
                        v3d->lay = v3d->layact;
-               } else {
+
+                       view3d_layers_editmode_ensure(scene, v3d);
+               }
+               else {
                        v3d->lay |= (1<<20)-1;
                }               
        }
@@ -173,19 +199,10 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
                                v3d->lay |= (1<<nr);
                } else {
                        v3d->lay = (1<<nr);
-
-                       /* sanity check - when in editmode disallow switching the editmode layer off since its confusing
-                        * an alternative would be to always draw the editmode object. */
-                       if(scene->obedit && (scene->obedit->lay & v3d->lay)==0) {
-                               for(bit=0; bit<32; bit++) {
-                                       if(scene->obedit->lay & (1<<bit)) {
-                                               v3d->lay |= 1<<bit;
-                                               break;
-                                       }
-                               }
-                       }
                }
-               
+
+               view3d_layers_editmode_ensure(scene, v3d);
+
                /* set active layer, ensure to always have one */
                if(v3d->lay & (1<<nr))
                   v3d->layact= 1<<nr;
@@ -201,14 +218,7 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
        
        if(v3d->scenelock) handle_view3d_lock(C);
        
-       /* XXX new layers might need updates, there is no provision yet to detect if that's needed */
-       oldlay= ~oldlay & v3d->lay;
-       for (base= scene->base.first; base; base= base->next) {
-               if(base->lay & oldlay)
-                       base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
-               if(base->lay & oldlay)
-                       printf("recalc %s\n", base->object->id.name+2);
-       }
+       DAG_on_visible_update(CTX_data_main(C), FALSE);
 
        ED_area_tag_redraw(sa);
        
@@ -262,7 +272,7 @@ void VIEW3D_OT_layers(wmOperatorType *ot)
 static char *view3d_modeselect_pup(Scene *scene)
 {
        Object *ob= OBACT;
-       static char string[1024];
+       static char string[256];
        static char formatstr[] = "|%s %%x%d %%i%d";
        char *str = string;
 
@@ -270,7 +280,8 @@ static char *view3d_modeselect_pup(Scene *scene)
        
        str += sprintf(str, formatstr, "Object Mode", OB_MODE_OBJECT, ICON_OBJECT_DATA);
        
-       if(ob==NULL) return string;
+       if(ob==NULL || ob->data==NULL) return string;
+       if(ob->id.lib || ((ID *)ob->data)->lib) return string;
        
        /* if active object is editable */
        if ( ((ob->type == OB_MESH)
@@ -303,7 +314,7 @@ static char *view3d_modeselect_pup(Scene *scene)
        if (ob->particlesystem.first || modifiers_findByType(ob, eModifierType_Cloth) || modifiers_findByType(ob, eModifierType_Softbody)) {
                str += sprintf(str, formatstr, "Particle Mode", OB_MODE_PARTICLE_EDIT, ICON_PARTICLEMODE);
        }
-
+       (void)str;
        return (string);
 }
 
@@ -422,6 +433,27 @@ static int object_mode_icon(int mode)
        return ICON_OBJECT_DATAMODE;
 }
 
+void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       uiBlock *block= uiLayoutGetBlock(layout);
+
+       uiBlockSetHandleFunc(block, do_view3d_header_buttons, NULL);
+
+       if(obedit && (obedit->type == OB_MESH)) {
+               EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
+               uiLayout *row;
+
+               row= uiLayoutRow(layout, 1);
+               block= uiLayoutGetBlock(row);
+               uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
+               uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
+               uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, 0,0,UI_UNIT_X,UI_UNIT_Y, &em->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
+
+               BKE_mesh_end_editmesh(obedit->data, em);
+       }
+}
+
 void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
 {
        bScreen *screen= CTX_wm_screen(C);
@@ -434,6 +466,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
        Object *obedit = CTX_data_edit_object(C);
        uiBlock *block;
        uiLayout *row;
+       const float dpi_fac= UI_DPI_FAC;
        
        RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);        
        RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
@@ -453,46 +486,41 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
 
        uiBlockBeginAlign(block);
        uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene) , 
-                         0,0,126,20, &(v3d->modeselect), 0, 0, 0, 0, "Mode");
+                         0,0,126 * dpi_fac, UI_UNIT_Y, &(v3d->modeselect), 0, 0, 0, 0, "Mode");
        uiBlockEndAlign(block);
        
        /* Draw type */
-       uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+       uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
 
        if (obedit==NULL && ((ob && ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT|OB_MODE_TEXTURE_PAINT)))) {
                /* Manipulators aren't used in weight paint mode */
                
                PointerRNA meshptr;
-
                RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr);
-               uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+               if(ob->mode & (OB_MODE_TEXTURE_PAINT|OB_MODE_VERTEX_PAINT)) {
+                       uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+               } else {
+                       // Jason
+                       row= uiLayoutRow(layout, 1);
+                       uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+                       uiItemR(row, &meshptr, "wp_vert_sel", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+               }
        } else {
                const char *str_menu;
 
                row= uiLayoutRow(layout, 1);
-               uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
-               uiItemR(row, &v3dptr, "use_pivot_point_align", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
-
-               /* NDOF */
-               /* Not implemented yet
-                if (G.ndofdevice ==0 ) {
-                       uiDefIconTextButC(block, ICONTEXTROW,B_NDOF, ICON_NDOF_TURN, ndof_pup(), 0,0,XIC+10,YIC, &(v3d->ndofmode), 0, 3.0, 0, 0, "Ndof mode");
-               
-                       uiDefIconButC(block, TOG, B_NDOF,  ICON_NDOF_DOM,
-                                         0,0,XIC,YIC,
-                                         &v3d->ndoffilter, 0, 1, 0, 0, "dominant axis");       
-               }
-                */
+               uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+               uiItemR(row, &v3dptr, "use_pivot_point_align", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
 
                /* Transform widget / manipulators */
                row= uiLayoutRow(layout, 1);
-               uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+               uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
                block= uiLayoutGetBlock(row);
                
                if(v3d->twflag & V3D_USE_MANIPULATOR) {
-                       uiDefIconButBitS(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, 0,0,XIC,YIC, &v3d->twtype, 1.0, 0.0, 0, 0, "Translate manipulator mode");
-                       uiDefIconButBitS(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT, 0,0,XIC,YIC, &v3d->twtype, 1.0, 0.0, 0, 0, "Rotate manipulator mode");
-                       uiDefIconButBitS(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE, 0,0,XIC,YIC, &v3d->twtype, 1.0, 0.0, 0, 0, "Scale manipulator mode");
+                       uiDefIconButBitC(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, "Translate manipulator mode");
+                       uiDefIconButBitC(block, TOG, V3D_MANIP_ROTATE, B_MAN_ROT, ICON_MAN_ROT, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, "Rotate manipulator mode");
+                       uiDefIconButBitC(block, TOG, V3D_MANIP_SCALE, B_MAN_SCALE, ICON_MAN_SCALE, 0,0,UI_UNIT_X,UI_UNIT_Y, &v3d->twtype, 1.0, 0.0, 0, 0, "Scale manipulator mode");
                }
                        
                if (v3d->twmode > (BIF_countTransformOrientation(C) - 1) + V3D_MANIP_CUSTOM) {
@@ -500,10 +528,10 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
                }
                        
                str_menu = BIF_menustringTransformOrientation(C, "Orientation");
-               uiDefButS(block, MENU, B_MAN_MODE, str_menu,0,0,70,YIC, &v3d->twmode, 0, 0, 0, 0, "Transform Orientation");
+               uiDefButC(block, MENU, B_MAN_MODE, str_menu,0,0,70 * dpi_fac, UI_UNIT_Y, &v3d->twmode, 0, 0, 0, 0, "Transform Orientation");
                MEM_freeN((void *)str_menu);
        }
-               
+
        if(obedit==NULL && v3d->localvd==NULL) {
                unsigned int ob_lay = ob ? ob->lay : 0;
                
@@ -514,19 +542,9 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
                        uiTemplateLayers(layout, &v3dptr, "layers", &v3dptr, "layers_used", ob_lay);
 
                /* Scene lock */
-               uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
+               uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
        }
        
-       /* selection modus, dont use python for this since it cant do the toggle buttons with shift+click as well as clicking to set one. */
-       if(obedit && (obedit->type == OB_MESH)) {
-               EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
-
-               row= uiLayoutRow(layout, 1);
-               block= uiLayoutGetBlock(row);
-               uiDefIconButBitS(block, TOG, SCE_SELECT_VERTEX, B_SEL_VERT, ICON_VERTEXSEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Vertex select mode");
-               uiDefIconButBitS(block, TOG, SCE_SELECT_EDGE, B_SEL_EDGE, ICON_EDGESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Edge select mode");
-               uiDefIconButBitS(block, TOG, SCE_SELECT_FACE, B_SEL_FACE, ICON_FACESEL, 0,0,XIC,YIC, &em->selectmode, 1.0, 0.0, 0, 0, "Face select mode");
-
-               BKE_mesh_end_editmesh(obedit->data, em);
-       }
+       uiTemplateEditModeSelection(layout, C);
 }
+