2.5: Buttons View
[blender-staging.git] / source / blender / editors / interface / view2d_ops.c
index ee2a50d12a97ad11cb521d31b20bef9f5a69520c..1e8cda68e6de2159d059c6d88cc545e0c19723a4 100644 (file)
@@ -151,6 +151,7 @@ static void view_pan_apply(bContext *C, wmOperator *op)
        /* request updates to be done... */
        ED_area_tag_redraw(vpd->sa);
        UI_view2d_sync(vpd->sc, vpd->sa, v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
        
        /* exceptions */
        if(vpd->sa->spacetype==SPACE_OUTLINER) {
@@ -493,17 +494,33 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
 {
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
-       float dx, dy;
-       
-       /* calculate amount to move view by */
-       dx= (v2d->cur.xmax - v2d->cur.xmin) * (float)RNA_float_get(op->ptr, "zoomfacx");
-       dy= (v2d->cur.ymax - v2d->cur.ymin) * (float)RNA_float_get(op->ptr, "zoomfacy");
+       float dx, dy, facx, facy;
        
+       /* calculate amount to move view by, ensuring symmetry so the
+        * old zoom level is restored after zooming back the same amount */
+       facx= RNA_float_get(op->ptr, "zoomfacx");
+       facy= RNA_float_get(op->ptr, "zoomfacy");
+
+       if(facx >= 0.0f) {
+               dx= (v2d->cur.xmax - v2d->cur.xmin) * facx;
+               dy= (v2d->cur.ymax - v2d->cur.ymin) * facy;
+       }
+       else {
+               dx= ((v2d->cur.xmax - v2d->cur.xmin)/(1.0f + 2.0f*facx)) * facx;
+               dy= ((v2d->cur.ymax - v2d->cur.ymin)/(1.0f + 2.0f*facy)) * facy;
+       }
+
        /* only resize view on an axis if change is allowed */
        if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
                if (v2d->keepofs & V2D_LOCKOFS_X) {
                        v2d->cur.xmax -= 2*dx;
                }
+               else if (v2d->keepofs & V2D_KEEPOFS_X) {
+                       if(v2d->align & V2D_ALIGN_NO_POS_X)
+                               v2d->cur.xmin += 2*dx;
+                       else
+                               v2d->cur.xmax -= 2*dx;
+               }
                else {
                        v2d->cur.xmin += dx;
                        v2d->cur.xmax -= dx;
@@ -513,18 +530,25 @@ static void view_zoomstep_apply(bContext *C, wmOperator *op)
                if (v2d->keepofs & V2D_LOCKOFS_Y) {
                        v2d->cur.ymax -= 2*dy;
                }
+               else if (v2d->keepofs & V2D_KEEPOFS_Y) {
+                       if(v2d->align & V2D_ALIGN_NO_POS_Y)
+                               v2d->cur.ymin += 2*dy;
+                       else
+                               v2d->cur.ymax -= 2*dy;
+               }
                else {
                        v2d->cur.ymin += dy;
                        v2d->cur.ymax -= dy;
                }
        }
-       
+
        /* validate that view is in valid configuration after this operation */
        UI_view2d_curRect_validate(v2d);
-       
+
        /* request updates to be done... */
        ED_area_tag_redraw(CTX_wm_area(C));
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* --------------- Individual Operators ------------------- */
@@ -681,6 +705,7 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
        /* request updates to be done... */
        ED_area_tag_redraw(CTX_wm_area(C));
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* cleanup temp customdata  */
@@ -922,6 +947,7 @@ static int view_borderzoom_exec(bContext *C, wmOperator *op)
        /* request updates to be done... */
        ED_area_tag_redraw(CTX_wm_area(C));
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
        
        return OPERATOR_FINISHED;
 } 
@@ -1162,6 +1188,7 @@ static void scroller_activate_apply(bContext *C, wmOperator *op)
        /* request updates to be done... */
        ED_area_tag_redraw(CTX_wm_area(C));
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
 }
 
 /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */
@@ -1301,20 +1328,20 @@ static int reset_exec(bContext *C, wmOperator *op)
                /* posx and negx flags are mutually exclusive, so watch out */
                if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
                        v2d->cur.xmax= 0.0f;
-                       v2d->cur.xmin= v2d->winx*style->panelzoom;
+                       v2d->cur.xmin= -winx*style->panelzoom;
                }
                else if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & V2D_ALIGN_NO_POS_X)) {
-                       v2d->cur.xmax= (v2d->cur.xmax - v2d->cur.xmin)*style->panelzoom;
+                       v2d->cur.xmax= winx*style->panelzoom;
                        v2d->cur.xmin= 0.0f;
                }
 
                /* - posx and negx flags are mutually exclusive, so watch out */
                if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & V2D_ALIGN_NO_NEG_Y)) {
                        v2d->cur.ymax= 0.0f;
-                       v2d->cur.ymin= -v2d->winy*style->panelzoom;
+                       v2d->cur.ymin= -winy*style->panelzoom;
                }
                else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & V2D_ALIGN_NO_POS_Y)) {
-                       v2d->cur.ymax= (v2d->cur.ymax - v2d->cur.ymin)*style->panelzoom;
+                       v2d->cur.ymax= winy*style->panelzoom;
                        v2d->cur.ymin= 0.0f;
                }
        }
@@ -1325,6 +1352,7 @@ static int reset_exec(bContext *C, wmOperator *op)
        /* request updates to be done... */
        ED_area_tag_redraw(CTX_wm_area(C));
        UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+       WM_event_add_mousemove(C);
        
        return OPERATOR_FINISHED;
 }
@@ -1340,7 +1368,7 @@ void VIEW2D_OT_reset(wmOperatorType *ot)
        ot->poll= view2d_poll;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       // ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
  
 /* ********************************************************* */