Exemplo n.º 1
0
/* delete active frame - wrapper around API calls */
static int gp_actframe_delete_exec(bContext *C, wmOperator *op)
{
	Scene *scene = CTX_data_scene(C);
	bGPdata *gpd = gpencil_data_get_active(C);
	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
	bGPDframe *gpf = gpencil_layer_getframe(gpl, CFRA, 0);
	
	/* if there's no existing Grease-Pencil data there, add some */
	if (gpd == NULL) {
		BKE_report(op->reports, RPT_ERROR, "No grease pencil data");
		return OPERATOR_CANCELLED;
	}
	if (ELEM(NULL, gpl, gpf)) {
		BKE_report(op->reports, RPT_ERROR, "No active frame to delete");
		return OPERATOR_CANCELLED;
	}
	
	/* delete it... */
	gpencil_layer_delframe(gpl, gpf);
	
	/* notifiers */
	WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
	
	return OPERATOR_FINISHED;
}
Exemplo n.º 2
0
static int gp_actframe_delete_poll(bContext *C)
{
	bGPdata *gpd = gpencil_data_get_active(C);
	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
	
	/* only if there's an active layer with an active frame */
	return (gpl && gpl->actframe);
}
Exemplo n.º 3
0
static int gp_convert_poll(bContext *C)
{
	bGPdata *gpd = gpencil_data_get_active(C);
	ScrArea *sa = CTX_wm_area(C);
	Scene *scene = CTX_data_scene(C);

	/* only if there's valid data, and the current view is 3D View */
	return ((sa && sa->spacetype == SPACE_VIEW3D) && gpencil_layer_getactive(gpd) && (scene->obedit == NULL));
}
Exemplo n.º 4
0
/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly 
 * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes
 */
void draw_gpencil_3dview (bContext *C, short only3d)
{
	ARegion *ar= CTX_wm_region(C);
	Scene *scene= CTX_data_scene(C);
	bGPdata *gpd;
	int dflag = 0;
	
	/* check that we have grease-pencil stuff to draw */
	gpd= gpencil_data_get_active(C); // XXX
	if (gpd == NULL) return;
	
	/* draw it! */
	if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS);
	gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag);
}
Exemplo n.º 5
0
static int gp_convert_poll(bContext *C)
{
	bGPdata *gpd = gpencil_data_get_active(C);
	bGPDlayer *gpl = NULL;
	bGPDframe *gpf = NULL;
	ScrArea *sa = CTX_wm_area(C);
	Scene *scene = CTX_data_scene(C);

	/* only if the current view is 3D View, if there's valid data (i.e. at least one stroke!),
	 * and if we are not in edit mode!
	 */
	return ((sa && sa->spacetype == SPACE_VIEW3D) &&
	        (gpl = gpencil_layer_getactive(gpd)) &&
	        (gpf = gpencil_layer_getframe(gpl, CFRA, 0)) &&
	        (gpf->strokes.first) &&
	        (scene->obedit == NULL));
}
Exemplo n.º 6
0
/* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly 
 * Note: this gets called twice - first time with onlyv2d=1 to draw 'canvas' strokes, second time with onlyv2d=0 for screen-aligned strokes
 */
void draw_gpencil_2dview (bContext *C, short onlyv2d)
{
	ScrArea *sa= CTX_wm_area(C);
	ARegion *ar= CTX_wm_region(C);
	Scene *scene= CTX_data_scene(C);
	bGPdata *gpd;
	int dflag = 0;
	
	/* check that we have grease-pencil stuff to draw */
	if (sa == NULL) return;
	gpd= gpencil_data_get_active(C); // XXX
	if (gpd == NULL) return;
	
	/* special hack for Image Editor */
	// FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled
	if (sa->spacetype == SPACE_IMAGE)
		dflag |= GP_DRAWDATA_IEDITHACK;
	
	/* draw it! */
	if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D|GP_DRAWDATA_NOSTATUS);
	gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag);
}
Exemplo n.º 7
0
static int gp_convert_layer_exec(bContext *C, wmOperator *op)
{
	bGPdata *gpd = gpencil_data_get_active(C);
	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
	Scene *scene = CTX_data_scene(C);
	int mode = RNA_enum_get(op->ptr, "type");

	/* check if there's data to work with */
	if (gpd == NULL) {
		BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data to work on");
		return OPERATOR_CANCELLED;
	}

	gp_layer_to_curve(C, gpd, gpl, mode);

	/* notifiers */
	WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, NULL);
	WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);

	/* done */
	return OPERATOR_FINISHED;
}
Exemplo n.º 8
0
// XXX porting note, ogl render will probably be a window with one 3d region
void draw_gpencil_oglrender (bContext *C)
{
	ScrArea *sa= CTX_wm_area(C);
	View3D *v3d= (View3D *)sa->spacedata.first;
	ARegion *ar= CTX_wm_region(C);
	Scene *scene= CTX_data_scene(C);
	bGPdata *gpd;
	
	/* assume gpencil data comes from v3d */
	if (v3d == NULL) return;
	gpd= gpencil_data_get_active(C);
	if (gpd == NULL) return;
	
	/* pass 1: draw 3d-strokes ------------ > */
	gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, (GP_DRAWDATA_NOSTATUS|GP_DRAWDATA_ONLY3D));
	
	/* pass 2: draw 2d-strokes ------------ > */
		/* adjust view matrices */
	wmOrtho2(-0.375f, (float)(ar->winx)-0.375f, -0.375f, (float)(ar->winy)-0.375f); // XXX may not be correct anymore
	glLoadIdentity();
	
		/* draw it! */
	gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, GP_DRAWDATA_NOSTATUS);
}
Exemplo n.º 9
0
/* draw grease-pencil sketches to specified 2d-view that uses ibuf corrections */
void draw_gpencil_2dimage (bContext *C, ImBuf *ibuf)
{
	ScrArea *sa= CTX_wm_area(C);
	ARegion *ar= CTX_wm_region(C);
	Scene *scene= CTX_data_scene(C);
	bGPdata *gpd;
	int offsx, offsy, sizex, sizey;
	int dflag = GP_DRAWDATA_NOSTATUS;
	
	/* check that we have grease-pencil stuff to draw */
	if (ELEM(NULL, sa, ibuf)) return;
	gpd= gpencil_data_get_active(C); // XXX
	if (gpd == NULL) return;
	
	/* calculate rect */
	switch (sa->spacetype) {
		case SPACE_IMAGE: /* image */
		{
			
			/* just draw using standard scaling (settings here are currently ignored anyways) */
			// FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled
			offsx= 0;
			offsy= 0;
			sizex= ar->winx;
			sizey= ar->winy;
			
			wmOrtho2(ar->v2d.cur.xmin, ar->v2d.cur.xmax, ar->v2d.cur.ymin, ar->v2d.cur.ymax);
			
			dflag |= GP_DRAWDATA_ONLYV2D|GP_DRAWDATA_IEDITHACK;
		}
			break;
			
		case SPACE_SEQ: /* sequence */
		{
			SpaceSeq *sseq= (SpaceSeq *)sa->spacedata.first;
			float zoom, zoomx, zoomy;
			
			/* calculate accessory values */
			zoom= (float)(SEQ_ZOOM_FAC(sseq->zoom));
			if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
				/* XXX sequencer zoom should store it? */
				zoomx = zoom; //  * ((float)G.scene->r.xasp / (float)G.scene->r.yasp);
				zoomy = zoom;
			} 
			else
				zoomx = zoomy = zoom;
			
			/* calculate transforms (Note: we use ibuf here, as we have it) */
			sizex= (int)(zoomx * ibuf->x);
			sizey= (int)(zoomy * ibuf->y);
			offsx= (int)( (ar->winx-sizex)/2 + sseq->xof );
			offsy= (int)( (ar->winy-sizey)/2 + sseq->yof );
			
			dflag |= GP_DRAWDATA_ONLYI2D;
		}
			break;
			
		default: /* for spacetype not yet handled */
			offsx= 0;
			offsy= 0;
			sizex= ar->winx;
			sizey= ar->winy;
			
			dflag |= GP_DRAWDATA_ONLYI2D;
			break;
	}
	
	
	/* draw it! */
	gp_draw_data(gpd, offsx, offsy, sizex, sizey, CFRA, dflag);
}
Exemplo n.º 10
0
static int gp_convert_layer_exec(bContext *C, wmOperator *op)
{
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_timing_data");
	bGPdata *gpd = gpencil_data_get_active(C);
	bGPDlayer *gpl = gpencil_layer_getactive(gpd);
	Scene *scene = CTX_data_scene(C);
	int mode = RNA_enum_get(op->ptr, "type");
	int norm_weights = RNA_boolean_get(op->ptr, "use_normalize_weights");
	float rad_fac = RNA_float_get(op->ptr, "radius_multiplier");
	int link_strokes = RNA_boolean_get(op->ptr, "use_link_strokes");
	int valid_timing;
	tGpTimingData gtd;
	
	/* check if there's data to work with */
	if (gpd == NULL) {
		BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data to work on");
		return OPERATOR_CANCELLED;
	}
	
	if (!RNA_property_is_set(op->ptr, prop) && !gp_convert_check_has_valid_timing(C, gpl, op)) {
		BKE_report(op->reports, RPT_WARNING,
		           "Current Grease Pencil strokes have no valid timing data, most timing options will be hidden!");
	}
	valid_timing = RNA_property_boolean_get(op->ptr, prop);
	
	gtd.mode = RNA_enum_get(op->ptr, "timing_mode");
	/* Check for illegal timing mode! */
	if (!valid_timing && !ELEM(gtd.mode, GP_STROKECONVERT_TIMING_NONE, GP_STROKECONVERT_TIMING_LINEAR)) {
		gtd.mode = GP_STROKECONVERT_TIMING_LINEAR;
		RNA_enum_set(op->ptr, "timing_mode", gtd.mode);
	}
	if (!link_strokes) {
		gtd.mode = GP_STROKECONVERT_TIMING_NONE;
	}
	
	/* grab all relevant settings */
	gtd.frame_range = RNA_int_get(op->ptr, "frame_range");
	gtd.start_frame = RNA_int_get(op->ptr, "start_frame");
	gtd.realtime = valid_timing ? RNA_boolean_get(op->ptr, "use_realtime") : FALSE;
	gtd.end_frame = RNA_int_get(op->ptr, "end_frame");
	gtd.gap_duration = RNA_float_get(op->ptr, "gap_duration");
	gtd.gap_randomness = RNA_float_get(op->ptr, "gap_randomness");
	gtd.gap_randomness = min_ff(gtd.gap_randomness, gtd.gap_duration);
	gtd.seed = RNA_int_get(op->ptr, "seed");
	gtd.num_points = gtd.cur_point = 0;
	gtd.dists = gtd.times = NULL;
	gtd.tot_dist = gtd.tot_time = gtd.gap_tot_time = 0.0f;
	gtd.inittime = 0.0;
	
	/* perform conversion */
	gp_layer_to_curve(C, op->reports, gpd, gpl, mode, norm_weights, rad_fac, link_strokes, &gtd);
	
	/* free temp memory */
	if (gtd.dists) {
		MEM_freeN(gtd.dists);
		gtd.dists = NULL;
	}
	if (gtd.times) {
		MEM_freeN(gtd.times);
		gtd.times = NULL;
	}
	
	/* notifiers */
	WM_event_add_notifier(C, NC_OBJECT | NA_ADDED, NULL);
	WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
	
	/* done */
	return OPERATOR_FINISHED;
}