示例#1
0
/* takes event->mval */
void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], float co[2])
{
	int sx, sy, width, height;
	float zoomx, zoomy;

	ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
	ED_space_image_get_size(sima, &width, &height);

	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);

	co[0] = ((mval[0] - sx) / zoomx) / width;
	co[1] = ((mval[1] - sy) / zoomy) / height;
}
示例#2
0
void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2], float r_co[2])
{
	float zoomx, zoomy;
	int width, height;
	int sx, sy;

	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
	ED_space_image_get_size(sima, &width, &height);
	ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);

	r_co[0] = (co[0] * width  * zoomx) + (float)sx;
	r_co[1] = (co[1] * height * zoomy) + (float)sy;
}
示例#3
0
void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr)
{
	int sx, sy, width, height;
	float zoomx, zoomy;

	ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
	ED_space_image_get_size(sima, &width, &height);

	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);

	*xr = ((x - sx) / zoomx) / width;
	*yr = ((y - sy) / zoomy) / height;
}
示例#4
0
// TODO: should we return if we hit something?
static void nearest_fcurve_vert_store (ListBase *matches, View2D *v2d, FCurve *fcu, BezTriple *bezt, FPoint *fpt, short hpoint, int mval[2])
{
	/* Keyframes or Samples? */
	if (bezt) {
		int screen_co[2], dist;
		
		/* convert from data-space to screen coordinates 
		 * NOTE: hpoint+1 gives us 0,1,2 respectively for each handle, 
		 * 	needed to access the relevant vertex coordinates in the 3x3 
		 * 	'vec' matrix
		 */
		UI_view2d_view_to_region(v2d, bezt->vec[hpoint+1][0], bezt->vec[hpoint+1][1], &screen_co[0], &screen_co[1]);
		
		/* check if distance from mouse cursor to vert in screen space is within tolerance */
			// XXX: inlined distance calculation, since we cannot do this on ints using the math lib...
		//dist = len_v2v2(mval, screen_co);
		dist = sqrt((mval[0] - screen_co[0])*(mval[0] - screen_co[0]) + 
					(mval[1] - screen_co[1])*(mval[1] - screen_co[1]));
		
		if (dist <= GVERTSEL_TOL) {
			tNearestVertInfo *nvi = (tNearestVertInfo *)matches->last;
			short replace = 0;
			
			/* if there is already a point for the F-Curve, check if this point is closer than that was */
			if ((nvi) && (nvi->fcu == fcu)) {
				/* replace if we are closer, or if equal and that one wasn't selected but we are... */
				if ( (nvi->dist > dist) || ((nvi->sel == 0) && BEZSELECTED(bezt)) )
					replace= 1;
			}
			/* add new if not replacing... */
			if (replace == 0)
				nvi = MEM_callocN(sizeof(tNearestVertInfo), "Nearest Graph Vert Info - Bezt");
			
			/* store values */
			nvi->fcu = fcu;
			nvi->bezt = bezt;
			nvi->hpoint = hpoint;
			nvi->dist = dist;
			
			nvi->sel= BEZSELECTED(bezt); // XXX... should this use the individual verts instead?
			
			/* add to list of matches if appropriate... */
			if (replace == 0)
				BLI_addtail(matches, nvi);
		}
	}
	else if (fpt) {
		// TODO...
	}
} 
示例#5
0
static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
{
	unsigned char *display_buffer;
	unsigned int *rect;
	int dx, dy, sx, sy, x, y;
	void *cache_handle;

	/* verify valid values, just leave this a while */
	if (ima->xrep < 1) return;
	if (ima->yrep < 1) return;

	if (ima->flag & IMA_VIEW_AS_RENDER)
		display_buffer = IMB_display_buffer_acquire(ibuf, &scene->view_settings, &scene->display_settings, &cache_handle);
	else
		display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &scene->display_settings, &cache_handle);

	if (!display_buffer)
		return;

	glPixelZoom(zoomx, zoomy);

	if (sima->curtile >= ima->xrep * ima->yrep)
		sima->curtile = ima->xrep * ima->yrep - 1;
	
	/* retrieve part of image buffer */
	dx = max_ii(ibuf->x / ima->xrep, 1);
	dy = max_ii(ibuf->y / ima->yrep, 1);
	sx = (sima->curtile % ima->xrep) * dx;
	sy = (sima->curtile / ima->xrep) * dy;
	rect = get_part_from_buffer((unsigned int *)display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy);
	
	/* draw repeated */
	for (sy = 0; sy + dy <= ibuf->y; sy += dy) {
		for (sx = 0; sx + dx <= ibuf->x; sx += dx) {
			UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y);

			glaDrawPixelsSafe(x, y, dx, dy, dx, GL_RGBA, GL_UNSIGNED_BYTE, rect);
		}
	}

	glPixelZoom(1.0f, 1.0f);

	IMB_display_buffer_release(cache_handle);

	MEM_freeN(rect);
}
示例#6
0
static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
{
	int x, y;

	/* set zoom */
	glPixelZoom(zoomx, zoomy);

	glaDefine2DArea(&ar->winrct);
	
	/* find window pixel coordinates of origin */
	UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y);

	/* this part is generic image display */
	if (sima->flag & SI_SHOW_ALPHA) {
		if (ibuf->rect)
			sima_draw_alpha_pixels(x, y, ibuf->x, ibuf->y, ibuf->rect);
		else if (ibuf->rect_float && ibuf->channels == 4)
			sima_draw_alpha_pixelsf(x, y, ibuf->x, ibuf->y, ibuf->rect_float);
	}
	else if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
		if (ibuf->zbuf)
			sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf);
		else if (ibuf->zbuf_float)
			sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float);
		else if (ibuf->channels == 1)
			sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float);
	}
	else {
		if (sima->flag & SI_USE_ALPHA) {
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			fdrawcheckerboard(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy);
		}

		glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);

		if (sima->flag & SI_USE_ALPHA)
			glDisable(GL_BLEND);
	}

	/* reset zoom */
	glPixelZoom(1.0f, 1.0f);
}
示例#7
0
static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
                                  int width, int height, float zoomx, float zoomy)
{
	MovieClip *clip = ED_space_clip_get_clip(sc);
	int filter = GL_LINEAR;
	int x, y;

	/* find window pixel coordinates of origin */
	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);

	/* checkerboard for case alpha */
	if (ibuf->planes == 32) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
	}

	/* non-scaled proxy shouldn't use filtering */
	if ((clip->flag & MCLIP_USE_PROXY) == 0 ||
	    ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100))
	{
		filter = GL_NEAREST;
	}

	/* set zoom */
	glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y);

	glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter);
	/* reset zoom */
	glPixelZoom(1.0f, 1.0f);


	if (sc->flag & SC_SHOW_METADATA) {
		rctf frame;
		BLI_rctf_init(&frame, 0.0f, ibuf->x, 0.0f, ibuf->y);
		ED_region_image_metadata_draw(x, y, ibuf, &frame, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
	}

	if (ibuf->planes == 32)
		glDisable(GL_BLEND);
}
示例#8
0
/**
 * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords.
 * better name here? view_to_track / track_to_view or so?
 */
void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[2])
{
	float zoomx, zoomy;
	float pos[3];
	int width, height;
	int sx, sy;

	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
	ED_space_clip_get_size(sc, &width, &height);
	ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy);

	ED_clip_point_undistorted_pos(sc, co, pos);
	pos[2] = 0.0f;

	/* untested */
	mul_v3_m4v3(pos, sc->stabmat, pos);

	r_co[0] = (pos[0] * width  * zoomx) + (float)sx;
	r_co[1] = (pos[1] * height * zoomy) + (float)sy;
}
示例#9
0
static bool do_lasso_select_node(bContext *C, const int mcords[][2], short moves, short select)
{
    SpaceNode *snode = CTX_wm_space_node(C);
    bNode *node;

    ARegion *ar = CTX_wm_region(C);

    rcti rect;
    bool changed = false;

    /* get rectangle from operator */
    BLI_lasso_boundbox(&rect, mcords, moves);

    /* do actual selection */
    for (node = snode->edittree->nodes.first; node; node = node->next) {
        int screen_co[2];
        const float cent[2] = {BLI_rctf_cent_x(&node->totr),
                               BLI_rctf_cent_y(&node->totr)
                              };

        /* marker in screen coords */
        UI_view2d_view_to_region(&ar->v2d,
                                 cent[0], cent[1],
                                 &screen_co[0], &screen_co[1]);

        if (BLI_rcti_isect_pt(&rect, screen_co[0], screen_co[1]) &&
                BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], INT_MAX))
        {
            nodeSetSelected(node, select);
            changed = true;
        }
    }

    if (changed) {
        WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);
    }

    return changed;
}
示例#10
0
/* convert the coordinates from the given stroke point into 3d-coordinates 
 *	- assumes that the active space is the 3D-View
 */
static void gp_strokepoint_convertcoords(bContext *C, bGPDstroke *gps, bGPDspoint *pt, float p3d[3], rctf *subrect)
{
	Scene *scene = CTX_data_scene(C);
	View3D *v3d = CTX_wm_view3d(C);
	ARegion *ar = CTX_wm_region(C);
	
	if (gps->flag & GP_STROKE_3DSPACE) {
		/* directly use 3d-coordinates */
		copy_v3_v3(p3d, &pt->x);
	}
	else {
		const float *fp = give_cursor(scene, v3d);
		float mvalf[2];
		
		/* get screen coordinate */
		if (gps->flag & GP_STROKE_2DSPACE) {
			int mvali[2];
			View2D *v2d = &ar->v2d;
			UI_view2d_view_to_region(v2d, pt->x, pt->y, mvali, mvali + 1);
			VECCOPY2D(mvalf, mvali);
		}
		else {
			if (subrect) {
				mvalf[0] = (((float)pt->x / 100.0f) * BLI_rctf_size_x(subrect)) + subrect->xmin;
				mvalf[1] = (((float)pt->y / 100.0f) * BLI_rctf_size_y(subrect)) + subrect->ymin;
			}
			else {
				mvalf[0] = (float)pt->x / 100.0f * ar->winx;
				mvalf[1] = (float)pt->y / 100.0f * ar->winy;
			}
		}
		
		/* convert screen coordinate to 3d coordinates 
		 *	- method taken from editview.c - mouse_cursor() 
		 */
		ED_view3d_win_to_3d(ar, fp, mvalf, p3d);
	}
}
示例#11
0
static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int height, float zoomx, float zoomy)
{
	int x, y;
	MovieClip *clip = ED_space_clip_get_clip(sc);

	/* find window pixel coordinates of origin */
	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);

	/* draw boundary border for frame if stabilization is enabled */
	if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
		glColor3f(0.0f, 0.0f, 0.0f);

		GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
		GPU_basic_shader_line_stipple(3, 0xAAAA);

		glEnable(GL_COLOR_LOGIC_OP);
		glLogicOp(GL_NOR);

		glPushMatrix();
		glTranslatef(x, y, 0.0f);

		glScalef(zoomx, zoomy, 1.0f);
		glMultMatrixf(sc->stabmat);

		glBegin(GL_LINE_LOOP);
		glVertex2f(0.0f, 0.0f);
		glVertex2f(width, 0.0f);
		glVertex2f(width, height);
		glVertex2f(0.0f, height);
		glEnd();

		glPopMatrix();

		glDisable(GL_COLOR_LOGIC_OP);
		GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
	}
}
示例#12
0
static void draw_render_info(const bContext *C,
                             Scene *scene,
                             Image *ima,
                             ARegion *ar,
                             float zoomx,
                             float zoomy)
{
	RenderResult *rr;
	Render *re = RE_GetRender(scene->id.name);
	RenderData *rd = RE_engine_get_render_data(re);
	Scene *stats_scene = ED_render_job_get_scene(C);
	if (stats_scene == NULL) {
		stats_scene = CTX_data_scene(C);
	}

	rr = BKE_image_acquire_renderresult(stats_scene, ima);

	if (rr && rr->text) {
		float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
		ED_region_info_draw(ar, rr->text, 1, fill_color);
	}

	BKE_image_release_renderresult(stats_scene, ima);

	if (re) {
		int total_tiles;
		bool need_free_tiles;
		rcti *tiles;

		tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles);

		if (total_tiles) {
			int i, x, y;
			rcti *tile;

			/* find window pixel coordinates of origin */
			UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);

			glPushMatrix();
			glTranslatef(x, y, 0.0f);
			glScalef(zoomx, zoomy, 1.0f);

			if (rd->mode & R_BORDER) {
				glTranslatef((int)(-rd->border.xmin * rd->xsch * rd->size / 100.0f),
				             (int)(-rd->border.ymin * rd->ysch * rd->size / 100.0f),
				             0.0f);
			}

			UI_ThemeColor(TH_FACE_SELECT);

			for (i = 0, tile = tiles; i < total_tiles; i++, tile++) {
				glaDrawBorderCorners(tile, zoomx, zoomy);
			}

			if (need_free_tiles) {
				MEM_freeN(tiles);
			}

			glPopMatrix();
		}
	}
}
示例#13
0
/* sets up the opengl context.
 * width, height are to match the values from ED_mask_get_size() */
void ED_mask_draw_region(Mask *mask, ARegion *ar,
                         const char draw_flag, const char draw_type, const char overlay_mode,
                         const int width_i, const int height_i,  /* convert directly into aspect corrected vars */
                         const float aspx, const float aspy,
                         const bool do_scale_applied, const bool do_draw_cb,
                         float stabmat[4][4], /* optional - only used by clip */
                         const bContext *C    /* optional - only used when do_post_draw is set or called from clip editor */
                         )
{
	struct View2D *v2d = &ar->v2d;

	/* aspect always scales vertically in movie and image spaces */
	const float width = width_i, height = (float)height_i * (aspy / aspx);

	int x, y;
	/* int w, h; */
	float zoomx, zoomy;

	/* frame image */
	float maxdim;
	float xofs, yofs;

	/* find window pixel coordinates of origin */
	UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);


	/* w = BLI_rctf_size_x(&v2d->tot); */
	/* h = BLI_rctf_size_y(&v2d->tot); */


	zoomx = (float)(BLI_rcti_size_x(&ar->winrct) + 1) / BLI_rctf_size_x(&ar->v2d.cur);
	zoomy = (float)(BLI_rcti_size_y(&ar->winrct) + 1) / BLI_rctf_size_y(&ar->v2d.cur);

	if (do_scale_applied) {
		zoomx /= width;
		zoomy /= height;
	}

	x += v2d->tot.xmin * zoomx;
	y += v2d->tot.ymin * zoomy;

	/* frame the image */
	maxdim = max_ff(width, height);
	if (width == height) {
		xofs = yofs = 0;
	}
	else if (width < height) {
		xofs = ((height - width) / -2.0f) * zoomx;
		yofs = 0.0f;
	}
	else { /* (width > height) */
		xofs = 0.0f;
		yofs = ((width - height) / -2.0f) * zoomy;
	}

	if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
		float *buffer = threaded_mask_rasterize(mask, width, height);
		int format;

		if (overlay_mode == MASK_OVERLAY_ALPHACHANNEL) {
			glColor3f(1.0f, 1.0f, 1.0f);
			format = GL_LUMINANCE;
		}
		else {
			/* More blending types could be supported in the future. */
			glEnable(GL_BLEND);
			glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
			format = GL_ALPHA;
		}

		glPushMatrix();
		glTranslatef(x, y, 0);
		glScalef(zoomx, zoomy, 0);
		if (stabmat) {
			glMultMatrixf(stabmat);
		}
		glaDrawPixelsTex(0.0f, 0.0f, width, height, format, GL_FLOAT, GL_NEAREST, buffer);
		glPopMatrix();

		if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
			glDisable(GL_BLEND);
		}

		MEM_freeN(buffer);
	}

	/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
	glPushMatrix();

	if (stabmat) {
		glMultMatrixf(stabmat);
	}

	glTranslatef(x + xofs, y + yofs, 0);
	glScalef(maxdim * zoomx, maxdim * zoomy, 0);

	if (do_draw_cb) {
		ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
	}

	/* draw! */
	draw_masklays(C, mask, draw_flag, draw_type, width, height, maxdim * zoomx, maxdim * zoomy);

	if (do_draw_cb) {
		ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
	}

	glPopMatrix();
}