use ICON_NULL define rather then 0, makes UI calls less confusing. (no functional...
[blender.git] / source / blender / editors / space_view3d / view3d_header.c
index bf774442812cdb9aaedc6dc86f944c4c05e07735..0f2f182e951decdf434891afd8e2a5d3379bda3d 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2004-2008 Blender Foundation.
  * All rights reserved.
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "DNA_armature_types.h"
-#include "DNA_ID.h"
-#include "DNA_image_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_object_types.h"
-#include "DNA_space_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_userdef_types.h" /* U.smooth_viewtx */
-#include "DNA_view3d_types.h"
-#include "DNA_windowmanager_types.h"
+#include "DNA_object_types.h"
 
 #include "RNA_access.h"
 
 #include "MEM_guardedalloc.h"
 
-#include "BKE_action.h"
-#include "BKE_brush.h"
 #include "BKE_context.h"
-#include "BKE_curve.h"
 #include "BKE_depsgraph.h"
-#include "BKE_displist.h"
 #include "BKE_effect.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_paint.h"
-#include "BKE_particle.h"
 #include "BKE_screen.h"
-#include "BKE_utildefines.h" /* for VECCOPY */
 
-#include "ED_armature.h"
-#include "ED_particle.h"
-#include "ED_object.h"
 #include "ED_mesh.h"
 #include "ED_util.h"
 #include "ED_screen.h"
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
 
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
 
 #include "BLI_math.h"
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 
 #include "UI_interface.h"
-#include "UI_interface_icons.h"
 #include "UI_resources.h"
-#include "UI_view2d.h"
 
 #include "view3d_intern.h"
 
 #define TEST_EDITMESH  if(obedit==0) return; \
                                                if( (v3d->lay & obedit->lay)==0 ) return;
 
-/* XXX port over */    
-extern void borderselect();
-
 /* view3d handler codes */
 #define VIEW3D_HANDLER_BACKGROUND      1
 #define VIEW3D_HANDLER_PROPERTIES      2
@@ -155,11 +124,12 @@ static void handle_view3d_lock(bContext *C)
                if(v3d->localvd==NULL && v3d->scenelock && sa->spacetype==SPACE_VIEW3D) {
                        /* copy to scene */
                        scene->lay= v3d->lay;
+                       scene->layact= v3d->layact;
                        scene->camera= v3d->camera;
 
                        /* not through notifiery, listener don't have context
                           and non-open screens or spaces need to be updated too */
-                       ED_view3d_scene_layers_update(bmain, scene);
+                       BKE_screen_view3d_main_sync(&bmain->screen, scene);
                        
                        /* notifiers for scene update */
                        WM_event_add_notifier(C, NC_SCENE|ND_LAYER, scene);
@@ -169,6 +139,7 @@ static void handle_view3d_lock(bContext *C)
 
 static int layers_exec(bContext *C, wmOperator *op)
 {
+       Main *bmain= CTX_data_main(C);
        Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
@@ -177,16 +148,21 @@ static int layers_exec(bContext *C, wmOperator *op)
        
        if(nr < 0)
                return OPERATOR_CANCELLED;
-       
-       
+
        if(nr == 0) {
                /* all layers */
-               v3d->lay |= (1<<20)-1;
-
                if(!v3d->layact)
                        v3d->layact= 1;
+
+               if (toggle && v3d->lay == ((1<<20)-1)) {
+                       /* return to active layer only */
+                       v3d->lay = v3d->layact;
+               } else {
+                       v3d->lay |= (1<<20)-1;
+               }               
        }
        else {
+               int bit;
                nr--;
 
                if(RNA_boolean_get(op->ptr, "extend")) {
@@ -194,21 +170,30 @@ static int layers_exec(bContext *C, wmOperator *op)
                                v3d->lay &= ~(1<<nr);
                        else
                                v3d->lay |= (1<<nr);
-               } else
+               } 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;
+                                       }
+                               }
+                       }
+               }
                
                /* set active layer, ensure to always have one */
                if(v3d->lay & (1<<nr))
                   v3d->layact= 1<<nr;
                else if((v3d->lay & v3d->layact)==0) {
-                       int bit= 0;
-
-                       while(bit<32) {
+                       for(bit=0; bit<32; bit++) {
                                if(v3d->lay & (1<<bit)) {
                                        v3d->layact= 1<<bit;
                                        break;
                                }
-                               bit++;
                        }
                }
        }
@@ -216,7 +201,7 @@ static int layers_exec(bContext *C, wmOperator *op)
        if(v3d->scenelock) handle_view3d_lock(C);
        
        /* new layers might need unflushed events events */
-       DAG_scene_update_flags(scene, v3d->lay);        /* tags all that moves and flushes */
+       DAG_scene_update_flags(bmain, scene, v3d->lay, FALSE);  /* tags all that moves and flushes */
 
        ED_area_tag_redraw(sa);
        
@@ -251,7 +236,7 @@ void VIEW3D_OT_layers(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Layers";
-       ot->description= "Toggle layer(s) visibility.";
+       ot->description= "Toggle layer(s) visibility";
        ot->idname= "VIEW3D_OT_layers";
        
        /* api callbacks */
@@ -316,7 +301,7 @@ static char *view3d_modeselect_pup(Scene *scene)
 }
 
 
-static void do_view3d_header_buttons(bContext *C, void *arg, int event)
+static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
 {
        wmWindow *win= CTX_wm_window(C);
        ToolSettings *ts= CTX_data_tool_settings(C);
@@ -371,8 +356,9 @@ static void do_view3d_header_buttons(bContext *C, void *arg, int event)
        case B_SEL_FACE:
                if(em) {
                        if( shift==0 || em->selectmode==0){
-                               if( ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((ts->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)){
-                                       if(ctrl) EM_convertsel(em, (ts->selectmode ^ SCE_SELECT_FACE),SCE_SELECT_FACE);
+                               if( ((em->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_VERTEX) || ((em->selectmode ^ SCE_SELECT_FACE) == SCE_SELECT_EDGE)){
+                                       if(ctrl)
+                                               EM_convertsel(em, (em->selectmode ^ SCE_SELECT_FACE),SCE_SELECT_FACE);
                                }
                                em->selectmode = SCE_SELECT_FACE;
                        }
@@ -387,25 +373,25 @@ static void do_view3d_header_buttons(bContext *C, void *arg, int event)
                if( shift==0 || v3d->twtype==0) {
                        v3d->twtype= V3D_MANIP_TRANSLATE;
                }
-        ED_area_tag_redraw(sa);
-        break;
+               ED_area_tag_redraw(sa);
+               break;
        case B_MAN_ROT:
                if( shift==0 || v3d->twtype==0) {
-            v3d->twtype= V3D_MANIP_ROTATE;
+                       v3d->twtype= V3D_MANIP_ROTATE;
                }
-        ED_area_tag_redraw(sa);
+               ED_area_tag_redraw(sa);
                break;
        case B_MAN_SCALE:
                if( shift==0 || v3d->twtype==0) {
-            v3d->twtype= V3D_MANIP_SCALE;
+                       v3d->twtype= V3D_MANIP_SCALE;
                }
-        ED_area_tag_redraw(sa);
+               ED_area_tag_redraw(sa);
                break;
        case B_NDOF:
-        ED_area_tag_redraw(sa);
+               ED_area_tag_redraw(sa);
                break;
        case B_MAN_MODE:
-        ED_area_tag_redraw(sa);
+               ED_area_tag_redraw(sa);
                break;
        default:
                break;
@@ -442,7 +428,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
        uiBlock *block;
        uiLayout *row;
        
-       RNA_pointer_create(&screen->id, &RNA_Space3DView, v3d, &v3dptr);        
+       RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);        
        RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
        RNA_pointer_create(&scene->id, &RNA_Scene, scene, &sceneptr);
 
@@ -457,16 +443,6 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
                v3d->modeselect = ob->mode;
        else
                v3d->modeselect = OB_MODE_OBJECT;
-               
-       v3d->flag &= ~V3D_MODE;
-       
-       /* not sure what the v3d->flag is useful for now... modeselect is confusing */
-       if(obedit) v3d->flag |= V3D_EDITMODE;
-       if(ob && (ob->mode & OB_MODE_POSE)) v3d->flag |= V3D_POSEMODE;
-       if(ob && (ob->mode & OB_MODE_VERTEX_PAINT)) v3d->flag |= V3D_VERTEXPAINT;
-       if(ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) v3d->flag |= V3D_WEIGHTPAINT;
-       if(ob && (ob->mode & OB_MODE_TEXTURE_PAINT)) v3d->flag |= V3D_TEXTUREPAINT;
-       if(paint_facesel_test(ob)) v3d->flag |= V3D_FACESELECT;
 
        uiBlockBeginAlign(block);
        uiDefIconTextButS(block, MENU, B_MODESELECT, object_mode_icon(v3d->modeselect), view3d_modeselect_pup(scene) , 
@@ -474,7 +450,7 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
        uiBlockEndAlign(block);
        
        /* Draw type */
-       uiItemR(layout, "", 0, &v3dptr, "viewport_shading", UI_ITEM_R_ICON_ONLY);
+       uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
 
        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 */
@@ -482,13 +458,13 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
                PointerRNA meshptr;
 
                RNA_pointer_create(&ob->id, &RNA_Mesh, ob->data, &meshptr);
-               uiItemR(layout, "", 0, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY);
+               uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
        } else {
-               char *str_menu;
+               const char *str_menu;
 
                row= uiLayoutRow(layout, 1);
-               uiItemR(row, "", 0, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY);
-               uiItemR(row, "", 0, &v3dptr, "pivot_point_align", UI_ITEM_R_ICON_ONLY);
+               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
@@ -496,14 +472,14 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
                        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");   
+                                         0,0,XIC,YIC,
+                                         &v3d->ndoffilter, 0, 1, 0, 0, "dominant axis");       
                }
                 */
 
                /* Transform widget / manipulators */
                row= uiLayoutRow(layout, 1);
-               uiItemR(row, "", 0, &v3dptr, "manipulator", UI_ITEM_R_ICON_ONLY);
+               uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                block= uiLayoutGetBlock(row);
                
                if(v3d->twflag & V3D_USE_MANIPULATOR) {
@@ -518,20 +494,20 @@ 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");
-               MEM_freeN(str_menu);
+               MEM_freeN((void *)str_menu);
        }
                
        if(obedit==NULL && v3d->localvd==NULL) {
-               int ob_lay = ob ? ob->lay : 0;
+               unsigned int ob_lay = ob ? ob->lay : 0;
                
                /* Layers */
                if (v3d->scenelock)
-                       uiTemplateLayers(layout, &sceneptr, "visible_layers", &v3dptr, "used_layers", ob_lay);
+                       uiTemplateLayers(layout, &sceneptr, "layers", &v3dptr, "layers_used", ob_lay);
                else
-                       uiTemplateLayers(layout, &v3dptr, "visible_layers", &v3dptr, "used_layers", ob_lay);
+                       uiTemplateLayers(layout, &v3dptr, "layers", &v3dptr, "layers_used", ob_lay);
 
                /* Scene lock */
-               uiItemR(layout, "", 0, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY);
+               uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
        }
        
        /* selection modus, dont use python for this since it cant do the toggle buttons with shift+click as well as clicking to set one. */