From ad4d061091584dadcb2d2e8dd6ddf59af45b65f1 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Sun, 21 Dec 2008 11:56:42 +0000 Subject: View2D - Vertical (within area) syncing for channel lists to stay in sync with the relevant keyframes... I still need to work out how to get this to work correctly as soon as an Action Editor instance is created. --- source/blender/blenloader/intern/readfile.c | 3 + source/blender/editors/animation/anim_ops.c | 14 ++-- source/blender/editors/include/UI_view2d.h | 3 +- source/blender/editors/interface/view2d.c | 93 +++++++++++++++------- source/blender/editors/interface/view2d_ops.c | 8 +- source/blender/editors/space_action/space_action.c | 9 ++- source/blender/editors/space_time/time_header.c | 6 +- source/blender/makesdna/DNA_view2d_types.h | 16 ++-- 8 files changed, 98 insertions(+), 54 deletions(-) (limited to 'source') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index bea8a8aacab..c0d23c8c495 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5102,6 +5102,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->regiontype= RGN_TYPE_CHANNELS; ar->alignment= RGN_ALIGN_LEFT; ar->v2d.scroll= V2D_SCROLL_BOTTOM; + ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; break; case SPACE_NLA: ar= MEM_callocN(sizeof(ARegion), "area region from do_versions"); @@ -5179,6 +5180,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL); ar->v2d.scroll |= (V2D_SCROLL_RIGHT); ar->v2d.align = V2D_ALIGN_NO_POS_Y; + ar->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL; //ar->v2d.flag |= V2D_IS_INITIALISED; break; } @@ -5190,6 +5192,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb) ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL); ar->v2d.scroll |= (V2D_SCROLL_RIGHT); ar->v2d.align = V2D_ALIGN_NO_POS_Y; + ar->v2d.flag |= V2D_VIEWSYNC_AREA_VERTICAL; //ar->v2d.flag |= V2D_IS_INITIALISED; break; } diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 077dd110269..4321c89f730 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -228,11 +228,11 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) float sfra, efra; int xmin, xmax; - /* convert min/max values from borderselect to region coordinates */ - xmin= RNA_int_get(op->ptr, "xmin")/* - ar->winrct.xmin*/; - xmax= RNA_int_get(op->ptr, "xmax")/* - ar->winrct.xmin*/; + /* get min/max values from border select rect (already in region coordinates, not screen) */ + xmin= RNA_int_get(op->ptr, "xmin"); + xmax= RNA_int_get(op->ptr, "xmax"); - /* convert min/max values to frames */ + /* convert min/max values to frames (i.e. region to 'tot' rect) */ UI_view2d_region_to_view(&ar->v2d, xmin, 0, &sfra, NULL); UI_view2d_region_to_view(&ar->v2d, xmax, 0, &efra, NULL); @@ -244,10 +244,10 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) if (efra < 1) efra = 1.0f; if (efra < sfra) efra= sfra; - scene->r.psfra= (int)sfra; - scene->r.pefra= (int)efra; + scene->r.psfra= (int)floor(sfra + 0.5f); + scene->r.pefra= (int)floor(efra + 0.5f); - //BIF_undo_push("Clear Preview Range"); + //BIF_undo_push("Set Preview Range"); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 479468296f2..99cb2a1b84c 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -125,6 +125,7 @@ struct View2DScrollers; struct wmWindowManager; struct bScreen; +struct ScrArea; struct bContext; typedef struct View2DGrid View2DGrid; @@ -138,6 +139,7 @@ void UI_view2d_region_reinit(struct View2D *v2d, short type, int winx, int winy) void UI_view2d_curRect_validate(struct View2D *v2d); void UI_view2d_curRect_reset(struct View2D *v2d); +void UI_view2d_sync(struct bScreen *screen, struct ScrArea *sa, struct View2D *v2dcur, int flag); void UI_view2d_totRect_set(struct View2D *v2d, int width, int height); @@ -165,7 +167,6 @@ void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, short *re struct View2D *UI_view2d_fromcontext(const struct bContext *C); struct View2D *UI_view2d_fromcontext_rwin(const struct bContext *C); void UI_view2d_getscale(struct View2D *v2d, float *x, float *y); -void UI_view2d_sync(struct bScreen *screen, struct View2D *v2dcur, int flag); /* operators */ void ui_view2d_operatortypes(void); diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 0d479478f9b..447286336bf 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -508,6 +508,70 @@ void UI_view2d_curRect_validate(View2D *v2d) /* ------------------ */ +/* Called by menus to activate it, or by view2d operators to make sure 'related' views stay in synchrony */ +void UI_view2d_sync(bScreen *screen, ScrArea *area, View2D *v2dcur, int flag) +{ + ScrArea *sa; + ARegion *ar; + + /* don't continue if no view syncing to be done */ + if ((v2dcur->flag & (V2D_VIEWSYNC_SCREEN_TIME|V2D_VIEWSYNC_AREA_VERTICAL)) == 0) + return; + + /* check if doing within area syncing (i.e. channels/vertical) */ + if (v2dcur->flag & V2D_VIEWSYNC_AREA_VERTICAL) { + for (ar= area->regionbase.first; ar; ar= ar->next) { + /* don't operate on self */ + if (v2dcur != &ar->v2d) { + /* only if view has vertical locks enabled */ + if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) { + if (flag == V2D_LOCK_COPY) { + /* other views with locks on must copy active */ + ar->v2d.cur.ymin= v2dcur->cur.ymin; + ar->v2d.cur.ymax= v2dcur->cur.ymax; + } + else { /* V2D_LOCK_SET */ + /* active must copy others */ + v2dcur->cur.ymin= ar->v2d.cur.ymin; + v2dcur->cur.ymax= ar->v2d.cur.ymax; + } + + /* region possibly changed, so refresh */ + ED_region_tag_redraw(ar); + } + } + } + } + + /* check if doing whole screen syncing (i.e. time/horizontal) */ + if (v2dcur->flag & V2D_VIEWSYNC_SCREEN_TIME) { + for (sa= screen->areabase.first; sa; sa= sa->next) { + for (ar= sa->regionbase.first; ar; ar= ar->next) { + /* don't operate on self */ + if (v2dcur != &ar->v2d) { + /* only if view has horizontal locks enabled */ + if (ar->v2d.flag & V2D_VIEWSYNC_SCREEN_TIME) { + if (flag == V2D_LOCK_COPY) { + /* other views with locks on must copy active */ + ar->v2d.cur.xmin= v2dcur->cur.xmin; + ar->v2d.cur.xmax= v2dcur->cur.xmax; + } + else { /* V2D_LOCK_SET */ + /* active must copy others */ + v2dcur->cur.xmin= ar->v2d.cur.xmin; + v2dcur->cur.xmax= ar->v2d.cur.xmax; + } + + /* region possibly changed, so refresh */ + ED_region_tag_redraw(ar); + } + } + } + } + } +} + + /* Restore 'cur' rect to standard orientation (i.e. optimal maximum view of tot) * This does not take into account if zooming the view on an axis will improve the view (if allowed) */ @@ -1549,32 +1613,3 @@ void UI_view2d_getscale(View2D *v2d, float *x, float *y) if (y) *y = (v2d->mask.ymax - v2d->mask.ymin) / (v2d->cur.ymax - v2d->cur.ymin); } -/* called by menus to activate it, or by view2d operators */ -void UI_view2d_sync(bScreen *screen, View2D *v2dcur, int flag) -{ - ScrArea *sa; - ARegion *ar; - - if(!(v2dcur->flag & V2D_VIEWSYNC_X)) - return; - - for(sa= screen->areabase.first; sa; sa= sa->next) { - for(ar= sa->regionbase.first; ar; ar= ar->next) { - if(v2dcur != &ar->v2d) { - if(ar->v2d.flag & V2D_VIEWSYNC_X) { - if(flag == V2D_LOCK_COPY) { - - ar->v2d.cur.xmin= v2dcur->cur.xmin; - ar->v2d.cur.xmax= v2dcur->cur.xmax; - } - else { /* V2D_LOCK_SET */ - v2dcur->cur.xmin= ar->v2d.cur.xmin; - v2dcur->cur.xmax= ar->v2d.cur.xmax; - } - ED_region_tag_redraw(ar); - } - } - } - } -} - diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index b45d8ea6cbb..e6dbcd60023 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -166,7 +166,7 @@ static void view_pan_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), v2d, V2D_LOCK_COPY); + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); } /* cleanup temp customdata */ @@ -497,7 +497,7 @@ static void view_zoomstep_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), v2d, V2D_LOCK_COPY); + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); } /* --------------- Individual Operators ------------------- */ @@ -650,7 +650,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), v2d, V2D_LOCK_COPY); + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); } /* cleanup temp customdata */ @@ -1031,7 +1031,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), v2d, V2D_LOCK_COPY); + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY); } /* handle user input for scrollers - calculations of mouse-movement need to be done here, not in the apply callback! */ diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index 105d9b3806c..93e5ee0e16a 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -89,7 +89,7 @@ static SpaceLink *action_new(void) /* only need to set scroll settings, as this will use 'listview' v2d configuration */ ar->v2d.scroll = V2D_SCROLL_BOTTOM; - ar->v2d.flag = V2D_VIEWSYNC_Y; + ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; /* main area */ ar= MEM_callocN(sizeof(ARegion), "main area for action"); @@ -119,6 +119,7 @@ static SpaceLink *action_new(void) ar->v2d.scroll |= (V2D_SCROLL_RIGHT); ar->v2d.keepzoom= V2D_LOCKZOOM_Y; ar->v2d.align= V2D_ALIGN_NO_POS_Y; + ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL; return (SpaceLink *)saction; } @@ -245,7 +246,11 @@ static void action_channel_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(C, v2d); /* data... */ - + // temp... line for testing + glColor3f(0, 0, 0); + glLineWidth(2.0f); + sdrawline(10, 0, 190, 0); + glLineWidth(1.0f); /* reset view matrix */ UI_view2d_view_restore(C); diff --git a/source/blender/editors/space_time/time_header.c b/source/blender/editors/space_time/time_header.c index 48b29849ca3..d664cb28ee5 100644 --- a/source/blender/editors/space_time/time_header.c +++ b/source/blender/editors/space_time/time_header.c @@ -194,8 +194,8 @@ static void do_time_viewmenu(bContext *C, void *arg, int event) break; case 11: if(v2d) { - v2d->flag ^= V2D_VIEWSYNC_X; - UI_view2d_sync(CTX_wm_screen(C), v2d, V2D_LOCK_SET); + v2d->flag ^= V2D_VIEWSYNC_SCREEN_TIME; + UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_SET); } break; case 12: /* only show keyframes from selected data */ @@ -240,7 +240,7 @@ static uiBlock *time_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Center View|C", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, ""); uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "View All|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, ""); - uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_X)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, + uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, "Lock Time to Other Windows|", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 11, ""); // if (!curarea->full) diff --git a/source/blender/makesdna/DNA_view2d_types.h b/source/blender/makesdna/DNA_view2d_types.h index 20b14b178ac..c4148e80a95 100644 --- a/source/blender/makesdna/DNA_view2d_types.h +++ b/source/blender/makesdna/DNA_view2d_types.h @@ -89,15 +89,15 @@ typedef struct View2D { /* general refresh settings (v2d->flag) */ /* global view2d horizontal locking (for showing same time interval) */ -#define V2D_VIEWSYNC_X (1<<0) - /* within region view2d vertical locking */ -#define V2D_VIEWSYNC_Y (1<<1) - /* apply pixel offsets on x-axis */ -#define V2D_PIXELOFS_X (1<<2) - /* apply pixel offsets on y-axis */ -#define V2D_PIXELOFS_Y (1<<3) +#define V2D_VIEWSYNC_SCREEN_TIME (1<<0) + /* within area (i.e. between regions) view2d vertical locking */ +#define V2D_VIEWSYNC_AREA_VERTICAL (1<<1) + /* apply pixel offsets on x-axis when setting view matrices */ +#define V2D_PIXELOFS_X (1<<2) + /* apply pixel offsets on y-axis when setting view matrices */ +#define V2D_PIXELOFS_Y (1<<3) /* view settings need to be set still... */ -#define V2D_IS_INITIALISED (1<<10) +#define V2D_IS_INITIALISED (1<<10) /* scroller flags for View2D (v2d->scroll) */ /* left scrollbar */ -- cgit v1.2.3