Ejemplo n.º 1
0
static int logic_view_all_exec(bContext *C, wmOperator *UNUSED(op))
{
    ARegion *ar = CTX_wm_region(C);
    rctf cur_new = ar->v2d.tot;
    float aspect = BLI_rctf_size_y(&ar->v2d.cur) / BLI_rctf_size_x(&ar->v2d.cur);

    /* force the view2d code to zoom to width, not height */
    cur_new.ymin = cur_new.ymax - BLI_rctf_size_x(&cur_new) * aspect;

    UI_view2d_smooth_view(C, ar, &cur_new);

    return OPERATOR_FINISHED;
}
Ejemplo n.º 2
0
void ANIM_center_frame(struct bContext *C, int smooth_viewtx)
{
	ARegion *ar = CTX_wm_region(C);
	Scene *scene = CTX_data_scene(C);
	float w = BLI_rctf_size_x(&ar->v2d.cur);
	rctf newrct;
	int nextfra, prevfra;

	switch (U.view_frame_type) {
		case ZOOM_FRAME_MODE_SECONDS:
		{
			const float fps = FPS;
			newrct.xmax = scene->r.cfra + U.view_frame_seconds * fps + 1;
			newrct.xmin = scene->r.cfra - U.view_frame_seconds * fps - 1;
			newrct.ymax = ar->v2d.cur.ymax;
			newrct.ymin = ar->v2d.cur.ymin;
			break;
		}

		/* hardest case of all, look for all keyframes around frame and display those */
		case ZOOM_FRAME_MODE_KEYFRAMES:
			if (find_prev_next_keyframes(C, &nextfra, &prevfra)) {
				newrct.xmax = nextfra;
				newrct.xmin = prevfra;
				newrct.ymax = ar->v2d.cur.ymax;
				newrct.ymin = ar->v2d.cur.ymin;
				break;
			}
			/* else drop through, keep range instead */
			ATTR_FALLTHROUGH;

		case ZOOM_FRAME_MODE_KEEP_RANGE:
		default:
			newrct.xmax = scene->r.cfra + (w / 2);
			newrct.xmin = scene->r.cfra - (w / 2);
			newrct.ymax = ar->v2d.cur.ymax;
			newrct.ymin = ar->v2d.cur.ymin;
			break;
	}

	UI_view2d_smooth_view(C, ar, &newrct, smooth_viewtx);
}
Ejemplo n.º 3
0
int space_node_view_flag(bContext *C, SpaceNode *snode, ARegion *ar,
                         const int node_flag, const int smooth_viewtx)
{
    bNode *node;
    rctf cur_new;
    float oldwidth, oldheight, width, height;
    float oldasp, asp;
    int tot = 0;
    bool has_frame = false;

    oldwidth  = BLI_rctf_size_x(&ar->v2d.cur);
    oldheight = BLI_rctf_size_y(&ar->v2d.cur);

    oldasp = oldwidth / oldheight;

    BLI_rctf_init_minmax(&cur_new);

    if (snode->edittree) {
        for (node = snode->edittree->nodes.first; node; node = node->next) {
            if ((node->flag & node_flag) == node_flag) {
                BLI_rctf_union(&cur_new, &node->totr);
                tot++;

                if (node->type == NODE_FRAME) {
                    has_frame = TRUE;
                }
            }
        }
    }

    if (tot) {
        width  = BLI_rctf_size_x(&cur_new);
        height = BLI_rctf_size_y(&cur_new);
        asp = width / height;

        /* for single non-frame nodes, don't zoom in, just pan view,
         * but do allow zooming out, this allows for big nodes to be zoomed out */
        if ((tot == 1) &&
                (has_frame == FALSE) &&
                ((oldwidth * oldheight) > (width * height)))
        {
            /* center, don't zoom */
            BLI_rctf_resize(&cur_new, oldwidth, oldheight);
        }
        else {
            if (oldasp < asp) {
                const float height_new = width / oldasp;
                cur_new.ymin = cur_new.ymin - height_new / 2.0f;
                cur_new.ymax = cur_new.ymax + height_new / 2.0f;
            }
            else {
                const float width_new = height * oldasp;
                cur_new.xmin = cur_new.xmin - width_new / 2.0f;
                cur_new.xmax = cur_new.xmax + width_new / 2.0f;
            }

            /* add some padding */
            BLI_rctf_scale(&cur_new, 1.1f);
        }

        UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx);
    }

    return (tot != 0);
}