コード例 #1
0
static int view_all_exec(bContext *C, wmOperator *op)
{
	SpaceClip *sc;
	ARegion *ar;
	int w, h, width, height;
	float aspx, aspy;
	int fit_view = RNA_boolean_get(op->ptr, "fit_view");
	float zoomx, zoomy;

	/* retrieve state */
	sc = CTX_wm_space_clip(C);
	ar = CTX_wm_region(C);

	ED_space_clip_get_size(sc, &w, &h);
	ED_space_clip_get_aspect(sc, &aspx, &aspy);

	w = w * aspx;
	h = h * aspy;

	/* check if the image will fit in the image with zoom == 1 */
	width  = BLI_rcti_size_x(&ar->winrct) + 1;
	height = BLI_rcti_size_y(&ar->winrct) + 1;

	if (fit_view) {
		const int margin = 5; /* margin from border */

		zoomx = (float) width / (w + 2 * margin);
		zoomy = (float) height / (h + 2 * margin);

		sclip_zoom_set(C, min_ff(zoomx, zoomy), NULL);
	}
	else {
		if ((w >= width || h >= height) && (width > 0 && height > 0)) {
			zoomx = (float) width / w;
			zoomy = (float) height / h;

			/* find the zoom value that will fit the image in the image space */
			sclip_zoom_set(C, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL);
		}
		else
			sclip_zoom_set(C, 1.0f, NULL);
	}

	sc->xof = sc->yof = 0.0f;

	ED_region_tag_redraw(CTX_wm_region(C));

	return OPERATOR_FINISHED;
}
コード例 #2
0
static int view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	ViewZoomData *vpd = op->customdata;
	float delta, factor;

	switch (event->type) {
		case MOUSEMOVE:
			delta = event->x - vpd->x + event->y - vpd->y;

			if (U.uiflag & USER_ZOOM_INVERT)
				delta *= -1;

			factor = 1.0f + delta / 300.0f;
			RNA_float_set(op->ptr, "factor", factor);
			sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
			ED_region_tag_redraw(CTX_wm_region(C));
			break;
		default:
			if (event->type == vpd->event_type && event->val == KM_RELEASE) {
				view_zoom_exit(C, op, 0);

				return OPERATOR_FINISHED;
			}
			break;
	}

	return OPERATOR_RUNNING_MODAL;
}
コード例 #3
0
static int view_zoom_ratio_exec(bContext *C, wmOperator *op)
{
	SpaceClip *sc = CTX_wm_space_clip(C);

	sclip_zoom_set(C, RNA_float_get(op->ptr, "ratio"), NULL);

	/* ensure pixel exact locations for draw */
	sc->xof = (int) sc->xof;
	sc->yof = (int) sc->yof;

	ED_region_tag_redraw(CTX_wm_region(C));

	return OPERATOR_FINISHED;
}
コード例 #4
0
ファイル: clip_ops.c プロジェクト: pawkoz/dyplom
static void view_zoom_apply(bContext *C,
                            ViewZoomData *vpd,
                            wmOperator *op,
                            const wmEvent *event)
{
	float factor;

	if (U.viewzoom == USER_ZOOM_CONT) {
		SpaceClip *sclip = CTX_wm_space_clip(C);
		double time = PIL_check_seconds_timer();
		float time_step = (float)(time - vpd->timer_lastdraw);
		float fac;
		float zfac;

		if (U.uiflag & USER_ZOOM_HORIZ) {
			fac = (float)(event->x - vpd->x);
		}
		else {
			fac = (float)(event->y - vpd->y);
		}

		if (U.uiflag & USER_ZOOM_INVERT) {
			fac = -fac;
		}

		zfac = 1.0f + ((fac / 20.0f) * time_step);
		vpd->timer_lastdraw = time;
		factor = (sclip->zoom * zfac) / vpd->zoom;
	}
	else {
		float delta = event->x - vpd->x + event->y - vpd->y;

		if (U.uiflag & USER_ZOOM_INVERT) {
			delta *= -1;
		}

		factor = 1.0f + delta / 300.0f;
	}

	RNA_float_set(op->ptr, "factor", factor);
	sclip_zoom_set(C, vpd->zoom * factor, vpd->location);
	ED_region_tag_redraw(CTX_wm_region(C));
}
コード例 #5
0
static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float location[2])
{
	SpaceClip *sc = CTX_wm_space_clip(C);

	sclip_zoom_set(C, sc->zoom * zoomfac, location);
}