home key to center the camera offset.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 3 Jul 2010 20:47:03 +0000 (20:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 3 Jul 2010 20:47:03 +0000 (20:47 +0000)
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/editors/space_view3d/view3d_ops.c

index 39c27bbff938511da7bd2e6b09c744974bacdf0b..82cba7759cad7c08233799c0973c705da135d96c 100644 (file)
@@ -728,7 +728,19 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
        }
 }
 
-static int ED_operator_view3d_rotate(bContext *C)
+static int view3d_camera_active_poll(bContext *C)
+{
+       if(ED_operator_view3d_active(C)) {
+               RegionView3D *rv3d= CTX_wm_region_view3d(C);
+               if(rv3d->persp==RV3D_CAMOB) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
+static int view3d_rotate_poll(bContext *C)
 {
        if (!ED_operator_view3d_active(C)) {
                return 0;
@@ -754,7 +766,7 @@ void VIEW3D_OT_rotate(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke= viewrotate_invoke;
        ot->modal= viewrotate_modal;
-       ot->poll= ED_operator_view3d_rotate;
+       ot->poll= view3d_rotate_poll;
 
        /* flags */
        ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
@@ -1294,6 +1306,18 @@ static int viewhome_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.
        return OPERATOR_FINISHED;
 }
 
+static int viewhome_poll(bContext *C)
+{
+       if(ED_operator_view3d_active(C)) {
+               RegionView3D *rv3d= CTX_wm_region_view3d(C);
+               if(rv3d->persp!=RV3D_CAMOB) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 void VIEW3D_OT_view_all(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1303,7 +1327,7 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= viewhome_exec;
-       ot->poll= ED_operator_view3d_active;
+       ot->poll= viewhome_poll;
 
        /* flags */
        ot->flag= 0;
@@ -1311,6 +1335,7 @@ void VIEW3D_OT_view_all(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "center", 0, "Center", "");
 }
 
+
 static int viewselected_exec(bContext *C, wmOperator *op) /* like a localview without local!, was centerview() in 2.4x */
 {
        ARegion *ar= CTX_wm_region(C);
@@ -1460,16 +1485,10 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        
        if (rv3d) {
-               if (rv3d->persp==RV3D_CAMOB) {
-                       /* center the camera offset */
-                       rv3d->camdx= rv3d->camdy= 0.0;
-               }
-               else {
-                       /* non camera center */
-                       float new_ofs[3];
-                       negate_v3_v3(new_ofs, give_cursor(scene, v3d));
-                       smooth_view(C, NULL, NULL, new_ofs, NULL, NULL, NULL);
-               }
+               /* non camera center */
+               float new_ofs[3];
+               negate_v3_v3(new_ofs, give_cursor(scene, v3d));
+               smooth_view(C, NULL, NULL, new_ofs, NULL, NULL, NULL);
                
                if (rv3d->viewlock & RV3D_BOXVIEW)
                        view3d_boxview_copy(CTX_wm_area(C), CTX_wm_region(C));
@@ -1493,6 +1512,32 @@ void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
        ot->flag= 0;
 }
 
+static int view3d_center_camera_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
+{
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+
+       rv3d->camdx= rv3d->camdy= 0.0f;
+
+       WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+
+       return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "View Camera Center";
+       ot->description = "Center the camera view";
+       ot->idname= "VIEW3D_OT_view_center_camera";
+
+       /* api callbacks */
+       ot->exec= view3d_center_camera_exec;
+       ot->poll= view3d_camera_active_poll;
+
+       /* flags */
+       ot->flag= 0;
+}
+
 /* ********************* Set render border operator ****************** */
 
 static int render_border_exec(bContext *C, wmOperator *op)
@@ -1543,15 +1588,6 @@ static int render_border_exec(bContext *C, wmOperator *op)
 
 }
 
-static int view3d_render_border_invoke(bContext *C, wmOperator *op, wmEvent *event)
-{
-       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
-
-       /* if not in camera view do not exec the operator*/
-       if (rv3d->persp == RV3D_CAMOB) return WM_border_select_invoke(C, op, event);
-       else return OPERATOR_PASS_THROUGH;
-}
-
 void VIEW3D_OT_render_border(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1560,11 +1596,11 @@ void VIEW3D_OT_render_border(wmOperatorType *ot)
        ot->idname= "VIEW3D_OT_render_border";
 
        /* api callbacks */
-       ot->invoke= view3d_render_border_invoke;
+       ot->invoke= WM_border_select_invoke;
        ot->exec= render_border_exec;
        ot->modal= WM_border_select_modal;
 
-       ot->poll= ED_operator_view3d_active;
+       ot->poll= view3d_camera_active_poll;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -2010,7 +2046,7 @@ void VIEW3D_OT_view_orbit(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= vieworbit_exec;
-       ot->poll= ED_operator_view3d_rotate;
+       ot->poll= view3d_rotate_poll;
 
        /* flags */
        ot->flag= 0;
index 69e4006770d8d3a2324a1c48d3b1a5cccc98f807..3e8bc71c351d2de47c10285734e773eb9502fb28 100644 (file)
@@ -75,6 +75,7 @@ void VIEW3D_OT_view_all(struct wmOperatorType *ot);
 void VIEW3D_OT_viewnumpad(struct wmOperatorType *ot);
 void VIEW3D_OT_view_selected(struct wmOperatorType *ot);
 void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot);
+void VIEW3D_OT_view_center_camera(struct wmOperatorType *ot);
 void VIEW3D_OT_view_pan(struct wmOperatorType *ot);
 void VIEW3D_OT_view_persportho(struct wmOperatorType *ot);
 void VIEW3D_OT_add_background_image(struct wmOperatorType *ot);
index 08658cd752df4e410ce5aacde72292ebdcd80d05..faeab482f729064e0ee4ece006b83e60cdff403d 100644 (file)
@@ -70,6 +70,7 @@ void view3d_operatortypes(void)
        WM_operatortype_append(VIEW3D_OT_remove_background_image);
        WM_operatortype_append(VIEW3D_OT_view_selected);
        WM_operatortype_append(VIEW3D_OT_view_center_cursor);
+       WM_operatortype_append(VIEW3D_OT_view_center_camera);
        WM_operatortype_append(VIEW3D_OT_select);
        WM_operatortype_append(VIEW3D_OT_select_border);
        WM_operatortype_append(VIEW3D_OT_clip_border);
@@ -150,7 +151,8 @@ void view3d_keymap(wmKeyConfig *keyconf)
        RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELINMOUSE, KM_PRESS, 0, 0)->ptr, "delta", 1);
        RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELOUTMOUSE, KM_PRESS, 0, 0)->ptr, "delta", -1);
 
-       RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0);
+       WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
+       RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0); /* only without camera view */
        RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1);
 
        /* numpad view hotkeys*/