[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49828] trunk/blender/source/blender: smooth-view for 2d views, graph editor, sequencer, node view, works with border zoom, view selected, view all.
Campbell Barton
ideasman42 at gmail.com
Sun Aug 12 03:07:33 CEST 2012
Revision: 49828
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49828
Author: campbellbarton
Date: 2012-08-12 01:07:31 +0000 (Sun, 12 Aug 2012)
Log Message:
-----------
smooth-view for 2d views, graph editor, sequencer, node view, works with border zoom, view selected, view all.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_rect.h
trunk/blender/source/blender/blenlib/intern/rct.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/editors/include/UI_view2d.h
trunk/blender/source/blender/editors/interface/view2d_ops.c
trunk/blender/source/blender/editors/space_graph/graph_edit.c
trunk/blender/source/blender/editors/space_node/node_view.c
trunk/blender/source/blender/editors/space_sequencer/sequencer_edit.c
trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
trunk/blender/source/blender/editors/space_view3d/view3d_view.c
trunk/blender/source/blender/makesdna/DNA_view2d_types.h
trunk/blender/source/blender/makesdna/DNA_view3d_types.h
Modified: trunk/blender/source/blender/blenlib/BLI_rect.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_rect.h 2012-08-12 00:19:55 UTC (rev 49827)
+++ trunk/blender/source/blender/blenlib/BLI_rect.h 2012-08-12 01:07:31 UTC (rev 49828)
@@ -53,6 +53,10 @@
void BLI_rcti_translate(struct rcti *rect, int x, int y);
void BLI_rcti_resize(struct rcti *rect, int x, int y);
void BLI_rctf_resize(struct rctf *rect, float x, float y);
+void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct rctf *rect_b, const float fac);
+//void BLI_rcti_interp(struct rctf *rect, struct rctf *rect_a, struct rctf *rect_b, float fac);
+int BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, const float limit);
+int BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b);
int BLI_in_rcti(const struct rcti *rect, const int x, const int y);
int BLI_in_rcti_v(const struct rcti *rect, const int xy[2]);
int BLI_in_rctf(const struct rctf *rect, const float x, const float y);
Modified: trunk/blender/source/blender/blenlib/intern/rct.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/rct.c 2012-08-12 00:19:55 UTC (rev 49827)
+++ trunk/blender/source/blender/blenlib/intern/rct.c 2012-08-12 01:07:31 UTC (rev 49828)
@@ -270,6 +270,39 @@
rect->ymax = rect->ymin + y;
}
+void BLI_rctf_interp(rctf *rect, const rctf *rect_a, const rctf *rect_b, const float fac)
+{
+ const float ifac = 1.0f - fac;
+ rect->xmin = (rect_a->xmin * ifac) + (rect_b->xmin * fac);
+ rect->xmax = (rect_a->xmax * ifac) + (rect_b->xmax * fac);
+ rect->ymin = (rect_a->ymin * ifac) + (rect_b->ymin * fac);
+ rect->ymax = (rect_a->ymax * ifac) + (rect_b->ymax * fac);
+}
+
+/* BLI_rcti_interp() not needed yet */
+
+int BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, const float limit)
+{
+ if (fabsf(rect_a->xmin - rect_b->xmin) < limit)
+ if (fabsf(rect_a->xmax - rect_b->xmax) < limit)
+ if (fabsf(rect_a->ymin - rect_b->ymin) < limit)
+ if (fabsf(rect_a->ymax - rect_b->ymax) < limit)
+ return 1;
+
+ return 0;
+}
+
+int BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b)
+{
+ if (rect_a->xmin == rect_b->xmin)
+ if (rect_a->xmax == rect_b->xmax)
+ if (rect_a->ymin == rect_b->ymin)
+ if (rect_a->ymax == rect_b->ymax)
+ return 1;
+
+ return 0;
+}
+
int BLI_rctf_isect(const rctf *src1, const rctf *src2, rctf *dest)
{
float xmin, xmax;
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2012-08-12 00:19:55 UTC (rev 49827)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2012-08-12 01:07:31 UTC (rev 49828)
@@ -5725,6 +5725,7 @@
ar->v2d.tab_offset = NULL;
ar->v2d.tab_num = 0;
ar->v2d.tab_cur = 0;
+ ar->v2d.sms = NULL;
ar->handlers.first = ar->handlers.last = NULL;
ar->uiblocks.first = ar->uiblocks.last = NULL;
ar->headerstr = NULL;
Modified: trunk/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- trunk/blender/source/blender/editors/include/UI_view2d.h 2012-08-12 00:19:55 UTC (rev 49827)
+++ trunk/blender/source/blender/editors/include/UI_view2d.h 2012-08-12 01:07:31 UTC (rev 49828)
@@ -202,5 +202,8 @@
void UI_view2d_operatortypes(void);
void UI_view2d_keymap(struct wmKeyConfig *keyconf);
+void UI_view2d_smooth_view(struct bContext *C, struct ARegion *ar,
+ const struct rctf *cur);
+
#endif /* __UI_VIEW2D_H__ */
Modified: trunk/blender/source/blender/editors/interface/view2d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/interface/view2d_ops.c 2012-08-12 00:19:55 UTC (rev 49827)
+++ trunk/blender/source/blender/editors/interface/view2d_ops.c 2012-08-12 01:07:31 UTC (rev 49828)
@@ -1100,6 +1100,7 @@
ARegion *ar = CTX_wm_region(C);
View2D *v2d = &ar->v2d;
rctf rect;
+ rctf cur_new = v2d->cur;
int gesture_mode;
/* convert coordinates of rect to 'tot' rect coordinates */
@@ -1116,12 +1117,12 @@
* if zoom is allowed to be changed
*/
if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
- v2d->cur.xmin = rect.xmin;
- v2d->cur.xmax = rect.xmax;
+ cur_new.xmin = rect.xmin;
+ cur_new.xmax = rect.xmax;
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
- v2d->cur.ymin = rect.ymin;
- v2d->cur.ymax = rect.ymax;
+ cur_new.ymin = rect.ymin;
+ cur_new.ymax = rect.ymax;
}
}
else { /* if (gesture_mode == GESTURE_MODAL_OUT) */
@@ -1135,30 +1136,25 @@
/* TODO: is this zoom factor calculation valid? It seems to produce same results everytime... */
if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0) {
- size = (v2d->cur.xmax - v2d->cur.xmin);
+ size = (cur_new.xmax - cur_new.xmin);
zoom = size / (rect.xmax - rect.xmin);
- center = (v2d->cur.xmax + v2d->cur.xmin) * 0.5f;
+ center = (cur_new.xmax + cur_new.xmin) * 0.5f;
- v2d->cur.xmin = center - (size * zoom);
- v2d->cur.xmax = center + (size * zoom);
+ cur_new.xmin = center - (size * zoom);
+ cur_new.xmax = center + (size * zoom);
}
if ((v2d->keepzoom & V2D_LOCKZOOM_Y) == 0) {
- size = (v2d->cur.ymax - v2d->cur.ymin);
+ size = (cur_new.ymax - cur_new.ymin);
zoom = size / (rect.ymax - rect.ymin);
- center = (v2d->cur.ymax + v2d->cur.ymin) * 0.5f;
+ center = (cur_new.ymax + cur_new.ymin) * 0.5f;
- v2d->cur.ymin = center - (size * zoom);
- v2d->cur.ymax = center + (size * zoom);
+ cur_new.ymin = center - (size * zoom);
+ cur_new.ymax = center + (size * zoom);
}
}
- /* validate that view is in valid configuration after this operation */
- UI_view2d_curRect_validate(v2d);
+ UI_view2d_smooth_view(C, ar, &cur_new);
- /* request updates to be done... */
- ED_region_tag_redraw(ar);
- UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
-
return OPERATOR_FINISHED;
}
@@ -1182,6 +1178,127 @@
}
/* ********************************************************* */
+/* SMOOTH VIEW */
+
+struct SmoothView2DStore {
+ rctf orig_cur, new_cur;
+
+ double time_allowed;
+};
+
+/* will start timer if appropriate */
+/* the arguments are the desired situation */
+void UI_view2d_smooth_view(bContext *C, ARegion *ar,
+ const rctf *cur)
+{
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmWindow *win = CTX_wm_window(C);
+
+ View2D *v2d = &ar->v2d;
+ struct SmoothView2DStore sms = {{0}};
+ short ok = FALSE;
+
+ /* initialize sms */
+ sms.new_cur = v2d->cur;
+
+ /* store the options we want to end with */
+ if (cur) sms.new_cur = *cur;
+
+ if (C && U.smooth_viewtx) {
+ int changed = 0; /* zero means no difference */
+
+ if (BLI_rctf_compare(&sms.new_cur, &v2d->cur, FLT_EPSILON) == FALSE)
+ changed = 1;
+ changed=1;
+
+ /* The new view is different from the old one
+ * so animate the view */
+ if (changed) {
+ sms.orig_cur = v2d->cur;
+
+ sms.time_allowed = (double)U.smooth_viewtx / 1000.0;
+
+ /* keep track of running timer! */
+ if (v2d->sms == NULL)
+ v2d->sms = MEM_mallocN(sizeof(struct SmoothView2DStore), "smoothview v2d");
+ *v2d->sms = sms;
+ if (v2d->smooth_timer)
+ WM_event_remove_timer(wm, win, v2d->smooth_timer);
+ /* TIMER1 is hardcoded in keymap */
+ v2d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); /* max 30 frs/sec */
+
+ ok = TRUE;
+ }
+ }
+
+ /* if we get here nothing happens */
+ if (ok == FALSE) {
+ v2d->cur = sms.new_cur;
+
+ UI_view2d_curRect_validate(v2d);
+ ED_region_tag_redraw(ar);
+ UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+ }
+}
+
+/* only meant for timer usage */
+static int view2d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
+{
+ ARegion *ar = CTX_wm_region(C);
+ View2D *v2d = &ar->v2d;
+ struct SmoothView2DStore *sms = v2d->sms;
+ float step;
+
+ /* escape if not our timer */
+ if (v2d->smooth_timer == NULL || v2d->smooth_timer != event->customdata)
+ return OPERATOR_PASS_THROUGH;
+
+ if (sms->time_allowed != 0.0)
+ step = (float)((v2d->smooth_timer->duration) / sms->time_allowed);
+ else
+ step = 1.0f;
+
+ /* end timer */
+ if (step >= 1.0f) {
+ v2d->cur = sms->new_cur;
+
+ MEM_freeN(v2d->sms);
+ v2d->sms = NULL;
+
+ WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), v2d->smooth_timer);
+ v2d->smooth_timer = NULL;
+ }
+ else {
+ /* ease in/out */
+ step = (3.0f * step * step - 2.0f * step * step * step);
+
+ BLI_rctf_interp(&v2d->cur, &sms->orig_cur, &sms->new_cur, step);
+ }
+
+ UI_view2d_curRect_validate(v2d);
+ UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_FINISHED;
+}
+
+static void VIEW2D_OT_smoothview(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Smooth View 2D";
+ ot->description = "Zoom in the view to the nearest item contained in the border";
+ ot->idname = "VIEW2D_OT_smoothview";
+
+ /* api callbacks */
+ ot->invoke = view2d_smoothview_invoke;
+
+ ot->poll = view2d_poll;
+
+ /* rna */
+ WM_operator_properties_gesture_border(ot, FALSE);
+}
+
+/* ********************************************************* */
/* SCROLLERS */
/* Scrollers should behave in the following ways, when clicked on with LMB (and dragged):
@@ -1678,6 +1795,8 @@
WM_operatortype_append(VIEW2D_OT_zoom);
WM_operatortype_append(VIEW2D_OT_zoom_border);
+
+ WM_operatortype_append(VIEW2D_OT_smoothview);
WM_operatortype_append(VIEW2D_OT_scroller_activate);
@@ -1711,6 +1830,8 @@
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_out", PADMINUS, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW2D_OT_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
+ WM_keymap_verify_item(keymap, "VIEW2D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
+
/* scroll up/down - no modifiers, only when zoom fails */
/* these may fail if zoom is disallowed, in which case they should pass on event */
WM_keymap_add_item(keymap, "VIEW2D_OT_scroll_down", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
Modified: trunk/blender/source/blender/editors/space_graph/graph_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_edit.c 2012-08-12 00:19:55 UTC (rev 49827)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list