[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32879] trunk/blender/source/blender/ editors/interface/view2d_ops.c: 'Continue' zoom method for 2d views wasn' t continuously updating.
Campbell Barton
ideasman42 at gmail.com
Fri Nov 5 04:54:55 CET 2010
Revision: 32879
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32879
Author: campbellbarton
Date: 2010-11-05 04:54:54 +0100 (Fri, 05 Nov 2010)
Log Message:
-----------
'Continue' zoom method for 2d views wasn't continuously updating. added a timer so it works like the 3D view.
Modified Paths:
--------------
trunk/blender/source/blender/editors/interface/view2d_ops.c
Modified: trunk/blender/source/blender/editors/interface/view2d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/view2d_ops.c 2010-11-05 02:49:01 UTC (rev 32878)
+++ trunk/blender/source/blender/editors/interface/view2d_ops.c 2010-11-05 03:54:54 UTC (rev 32879)
@@ -46,6 +46,8 @@
#include "UI_view2d.h"
+#include "PIL_time.h" /* USER_ZOOM_CONT */
+
static int view2d_poll(bContext *C)
{
ARegion *ar= CTX_wm_region(C);
@@ -493,7 +495,11 @@
typedef struct v2dViewZoomData {
View2D *v2d; /* view2d we're operating in */
ARegion *ar;
-
+
+ /* needed for continuous zoom */
+ wmTimer *timer;
+ double timer_lastdraw;
+
int lastx, lasty; /* previous x/y values of mouse in window */
float dx, dy; /* running tally of previous delta values (for obtaining final zoom) */
float mx_2d, my_2d; /* initial mouse location in v2d coords */
@@ -773,7 +779,18 @@
/* get amount to move view by */
dx= RNA_float_get(op->ptr, "deltax");
dy= RNA_float_get(op->ptr, "deltay");
-
+
+ /* continous zoom shouldn't move that fast... */
+ if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
+ double time= PIL_check_seconds_timer();
+ float time_step= (float)(time - vzd->timer_lastdraw);
+
+ dx *= time_step * 0.5f;
+ dy *= time_step * 0.5f;
+
+ vzd->timer_lastdraw= time;
+ }
+
/* only move view on an axis if change is allowed */
if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0) {
if (v2d->keepofs & V2D_LOCKOFS_X) {
@@ -823,9 +840,14 @@
}
/* cleanup temp customdata */
-static void view_zoomdrag_exit(wmOperator *op)
+static void view_zoomdrag_exit(bContext *C, wmOperator *op)
{
if (op->customdata) {
+ v2dViewZoomData *vzd= op->customdata;
+
+ if(vzd->timer)
+ WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), vzd->timer);
+
MEM_freeN(op->customdata);
op->customdata= NULL;
}
@@ -838,7 +860,7 @@
return OPERATOR_PASS_THROUGH;
view_zoomdrag_apply(C, op);
- view_zoomdrag_exit(op);
+ view_zoomdrag_exit(C, op);
return OPERATOR_FINISHED;
}
@@ -873,7 +895,7 @@
RNA_float_set(op->ptr, "deltay", dy);
view_zoomdrag_apply(C, op);
- view_zoomdrag_exit(op);
+ view_zoomdrag_exit(C, op);
return OPERATOR_FINISHED;
}
@@ -902,6 +924,12 @@
/* add temp handler */
WM_event_add_modal_handler(C, op);
+ if (U.viewzoom == USER_ZOOM_CONT) {
+ /* needs a timer to continue redrawing */
+ vzd->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
+ vzd->timer_lastdraw= PIL_check_seconds_timer();
+ }
+
return OPERATOR_RUNNING_MODAL;
}
@@ -912,85 +940,87 @@
View2D *v2d= vzd->v2d;
/* execute the events */
- switch (event->type) {
- case MOUSEMOVE:
- {
- float dx, dy;
+ if (event->type == TIMER && event->customdata == vzd->timer) {
+ view_zoomdrag_apply(C, op);
+ }
+ else if(event->type == MOUSEMOVE) {
+ float dx, dy;
+
+ /* calculate new delta transform, based on zooming mode */
+ if (U.viewzoom == USER_ZOOM_SCALE) {
+ /* 'scale' zooming */
+ float dist;
- /* calculate new delta transform, based on zooming mode */
- if (U.viewzoom == USER_ZOOM_SCALE) {
- /* 'scale' zooming */
- float dist;
+ /* x-axis transform */
+ dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
+ dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
+ dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
+
+ /* y-axis transform */
+ dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
+ dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
+ dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
+ }
+ else {
+ /* 'continuous' or 'dolly' */
+ float fac;
+
+ /* x-axis transform */
+ fac= 0.01f * (event->x - vzd->lastx);
+ dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
+
+ /* y-axis transform */
+ fac= 0.01f * (event->y - vzd->lasty);
+ dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
+#if 0
+ /* continous zoom shouldn't move that fast... */
+ if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
+ double time= PIL_check_seconds_timer();
+ float time_step= (float)(time - vzd->timer_lastdraw);
+
+ dx /= (0.1f / time_step);
+ dy /= (0.1f / time_step);
- /* x-axis transform */
- dist = (v2d->mask.xmax - v2d->mask.xmin) / 2.0f;
- dx= 1.0f - ((float)fabs(vzd->lastx - dist) + 2.0f) / ((float)fabs(event->x - dist) + 2.0f);
- dx*= 0.5f * (v2d->cur.xmax - v2d->cur.xmin);
-
- /* y-axis transform */
- dist = (v2d->mask.ymax - v2d->mask.ymin) / 2.0f;
- dy= 1.0f - ((float)fabs(vzd->lasty - dist) + 2.0f) / ((float)fabs(event->y - dist) + 2.0f);
- dy*= 0.5f * (v2d->cur.ymax - v2d->cur.ymin);
+ vzd->timer_lastdraw= time;
}
- else {
- /* 'continuous' or 'dolly' */
- float fac;
+#endif
+ }
+
+ /* set transform amount, and add current deltas to stored total delta (for redo) */
+ RNA_float_set(op->ptr, "deltax", dx);
+ RNA_float_set(op->ptr, "deltay", dy);
+ vzd->dx += dx;
+ vzd->dy += dy;
+
+ /* store mouse coordinates for next time, if not doing continuous zoom
+ * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
+ */
+ if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
+ vzd->lastx= event->x;
+ vzd->lasty= event->y;
+ }
+
+ /* apply zooming */
+ view_zoomdrag_apply(C, op);
+ } else if (ELEM(event->type, LEFTMOUSE, MIDDLEMOUSE)) {
+ if (event->val==KM_RELEASE) {
+ /* for redo, store the overall deltas - need to respect zoom-locks here... */
+ if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
+ RNA_float_set(op->ptr, "deltax", vzd->dx);
+ else
+ RNA_float_set(op->ptr, "deltax", 0);
- /* x-axis transform */
- fac= 0.01f * (event->x - vzd->lastx);
- dx= fac * (v2d->cur.xmax - v2d->cur.xmin);
-
- /* y-axis transform */
- fac= 0.01f * (event->y - vzd->lasty);
- dy= fac * (v2d->cur.ymax - v2d->cur.ymin);
-
- /* continous zoom shouldn't move that fast... */
- if (U.viewzoom == USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
- dx /= 20.0f;
- dy /= 20.0f;
- }
- }
+ if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
+ RNA_float_set(op->ptr, "deltay", vzd->dy);
+ else
+ RNA_float_set(op->ptr, "deltay", 0);
- /* set transform amount, and add current deltas to stored total delta (for redo) */
- RNA_float_set(op->ptr, "deltax", dx);
- RNA_float_set(op->ptr, "deltay", dy);
- vzd->dx += dx;
- vzd->dy += dy;
+ /* free customdata */
+ view_zoomdrag_exit(C, op);
+ WM_cursor_restore(CTX_wm_window(C));
- /* store mouse coordinates for next time, if not doing continuous zoom
- * - continuous zoom only depends on distance of mouse to starting point to determine rate of change
- */
- if (U.viewzoom != USER_ZOOM_CONT) { // XXX store this setting as RNA prop?
- vzd->lastx= event->x;
- vzd->lasty= event->y;
- }
-
- /* apply zooming */
- view_zoomdrag_apply(C, op);
+ return OPERATOR_FINISHED;
}
- break;
-
- case LEFTMOUSE:
- case MIDDLEMOUSE:
- if (event->val==KM_RELEASE) {
- /* for redo, store the overall deltas - need to respect zoom-locks here... */
- if ((v2d->keepzoom & V2D_LOCKZOOM_X)==0)
- RNA_float_set(op->ptr, "deltax", vzd->dx);
- else
- RNA_float_set(op->ptr, "deltax", 0);
-
- if ((v2d->keepzoom & V2D_LOCKZOOM_Y)==0)
- RNA_float_set(op->ptr, "deltay", vzd->dy);
- else
- RNA_float_set(op->ptr, "deltay", 0);
-
- /* free customdata */
- view_zoomdrag_exit(op);
- WM_cursor_restore(CTX_wm_window(C));
-
- return OPERATOR_FINISHED;
- }
- break;
}
return OPERATOR_RUNNING_MODAL;
More information about the Bf-blender-cvs
mailing list