Exemple #1
0
/* operator init */
static int pose_slide_init(bContext *C, wmOperator *op, short mode)
{
	tPoseSlideOp *pso;
	bAction *act = NULL;
	
	/* init slide-op data */
	pso = op->customdata = MEM_callocN(sizeof(tPoseSlideOp), "tPoseSlideOp");
	
	/* get info from context */
	pso->scene = CTX_data_scene(C);
	pso->ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
	pso->arm = (pso->ob) ? pso->ob->data : NULL;
	pso->sa = CTX_wm_area(C); /* only really needed when doing modal() */
	pso->ar = CTX_wm_region(C); /* only really needed when doing modal() */
	
	pso->cframe = pso->scene->r.cfra;
	pso->mode = mode;
	
	/* set range info from property values - these may get overridden for the invoke() */
	pso->percentage = RNA_float_get(op->ptr, "percentage");
	pso->prevFrame = RNA_int_get(op->ptr, "prev_frame");
	pso->nextFrame = RNA_int_get(op->ptr, "next_frame");
	
	/* check the settings from the context */
	if (ELEM(NULL, pso->ob, pso->arm, pso->ob->adt, pso->ob->adt->action))
		return 0;
	else
		act = pso->ob->adt->action;
	
	/* for each Pose-Channel which gets affected, get the F-Curves for that channel 
	 * and set the relevant transform flags...
	 */
	poseAnim_mapping_get(C, &pso->pfLinks, pso->ob, act);
	
	/* set depsgraph flags */
	/* make sure the lock is set OK, unlock can be accidentally saved? */
	pso->ob->pose->flag |= POSE_LOCKED;
	pso->ob->pose->flag &= ~POSE_DO_UNLOCK;
	
	/* do basic initialize of RB-BST used for finding keyframes, but leave the filling of it up 
	 * to the caller of this (usually only invoke() will do it, to make things more efficient).
	 */
	BLI_dlrbTree_init(&pso->keys);
	
	/* initialise numeric input */
	initNumInput(&pso->num);
	pso->num.idx_max = 0; /* one axis */
	pso->num.val_flag[0] |= NUM_NO_NEGATIVE;
	pso->num.unit_type[0] = B_UNIT_NONE; /* percentages don't have any units... */
	
	/* return status is whether we've got all the data we were requested to get */
	return 1;
}
Exemple #2
0
/* free stuff */
static void ed_marker_move_exit(bContext *C, wmOperator *op)
{
	MarkerMove *mm= op->customdata;
	
	/* free data */
	MEM_freeN(mm->oldframe);
	MEM_freeN(op->customdata);
	op->customdata= NULL;
	
	/* clear custom header prints */
	ED_area_headerprint(CTX_wm_area(C), NULL);
}
Exemple #3
0
void WM_redraw_windows(bContext *C)
{
	wmWindow *win_prev = CTX_wm_window(C);
	ScrArea *area_prev = CTX_wm_area(C);
	ARegion *ar_prev = CTX_wm_region(C);

	wm_draw_update(C);

	CTX_wm_window_set(C, win_prev);
	CTX_wm_area_set(C, area_prev);
	CTX_wm_region_set(C, ar_prev);
}
Exemple #4
0
static int file_highlight_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
	ARegion *ar= CTX_wm_region(C);
	SpaceFile *sfile= CTX_wm_space_file(C);

	if(!file_hilight_set(sfile, ar, event->x, event->y))
		return OPERATOR_CANCELLED;

	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
static void render_view3d_do(RenderEngine *engine, const bContext *C)
{
	wmJob *wm_job;
	RenderPreview *rp;
	Scene *scene = CTX_data_scene(C);
	ARegion *ar = CTX_wm_region(C);
	int width = ar->winx, height = ar->winy;
	int divider = 1;
	int resolution_threshold = scene->r.preview_start_resolution *
	                           scene->r.preview_start_resolution;

	if (CTX_wm_window(C) == NULL)
		return;
	if (!render_view3d_flag_changed(engine, C))
		return;

	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), CTX_wm_region(C), "Render Preview",
	                     WM_JOB_EXCL_RENDER, WM_JOB_TYPE_RENDER_PREVIEW);
	rp = MEM_callocN(sizeof(RenderPreview), "render preview");
	rp->job = wm_job;

	while (width * height > resolution_threshold) {
		width = max_ii(1, width / 2);
		height = max_ii(1, height / 2);
		divider *= 2;
	}

	/* customdata for preview thread */
	rp->scene = scene;
	rp->engine = engine;
	rp->sa = CTX_wm_area(C);
	rp->ar = CTX_wm_region(C);
	rp->v3d = rp->sa->spacedata.first;
	rp->rv3d = CTX_wm_region_view3d(C);
	rp->bmain = CTX_data_main(C);
	rp->resolution_divider = divider;
	rp->start_resolution_divider = divider;
	rp->has_freestyle = (scene->r.mode & R_EDGE_FRS) != 0;
	copy_m4_m4(rp->viewmat, rp->rv3d->viewmat);
	
	/* clear info text */
	engine->text[0] = '\0';
	
	/* setup job */
	WM_jobs_customdata_set(wm_job, rp, render_view3d_free);
	WM_jobs_timer(wm_job, 0.1, NC_SPACE | ND_SPACE_VIEW3D, NC_SPACE | ND_SPACE_VIEW3D);
	WM_jobs_callbacks(wm_job, render_view3d_startjob, NULL, NULL, NULL);
	
	WM_jobs_start(CTX_wm_manager(C), wm_job);
	
	engine->flag &= ~RE_ENGINE_DO_UPDATE;
}
Exemple #6
0
static void change_frame_seq_preview_begin(bContext *C, const wmEvent *event)
{
	ScrArea *sa = CTX_wm_area(C);
	bScreen *screen = CTX_wm_screen(C);
	if (sa && sa->spacetype == SPACE_SEQ) {
		SpaceSeq *sseq = sa->spacedata.first;
		if (ED_space_sequencer_check_show_strip(sseq)) {
			ED_sequencer_special_preview_set(C, event->mval);
		}
	}
	if (screen)
		screen->scrubbing = true;
}
Exemple #7
0
static int add_feather_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar = CTX_wm_region(C);

	float co[2];

	ED_mask_mouse_pos(sa, ar, event->mval, co);

	RNA_float_set_array(op->ptr, "location", co);

	return add_feather_vertex_exec(C, op);
}
Exemple #8
0
/* Check if the operator can be run from the current context */
static int change_frame_poll(bContext *C)
{
    ScrArea *curarea= CTX_wm_area(C);

    /* XXX temp? prevent changes during render */
    if(G.rendering) return 0;

    /* as long as there is an active area, and it isn't a Graph Editor
     * (since the Graph Editor has its own version which does extra stuff),
     * we're fine
     */
    return ((curarea) && (curarea->spacetype != SPACE_IPO));
}
Exemple #9
0
/* Temporary wrapper for driver operators for buttons to make it easier to create
 * such drivers by rerouting all paths through the active object instead so that
 * they will get picked up by the dependency system.
 *
 * < C: context pointer - for getting active data 
 * <> ptr: RNA pointer for property's datablock. May be modified as result of path remapping.
 * < prop: RNA definition of property to add for
 *
 * > returns: MEM_alloc'd string representing the path to the property from the given PointerRNA
 */
static char *get_driver_path_hack(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
{
	ID *id = (ID *)ptr->id.data;
	ScrArea *sa = CTX_wm_area(C);
	
	/* get standard path which may be extended */
	char *basepath = RNA_path_from_ID_to_property(ptr, prop);
	char *path = basepath; /* in case no remapping is needed */
	
	
	/* Remapping will only be performed in the Properties Editor, as only this 
	 * restricts the subspace of options to the 'active' data (a manageable state)
	 */
	// TODO: watch out for pinned context?
	if ((sa) && (sa->spacetype == SPACE_BUTS)) {
		Object *ob = CTX_data_active_object(C);
		
		if (ob && id) {
			/* only id-types which can be remapped to go through objects should be considered */
			switch (GS(id->name)) {
				case ID_TE: /* textures */
				{
					Material *ma = give_current_material(ob, ob->actcol);
					Tex *tex = give_current_material_texture(ma);
					
					/* assumes: texture will only be shown if it is active material's active texture it's ok */
					if ((ID *)tex == id) {
						/* create new path */
						// TODO: use RNA path functions to construct step by step instead?
						// FIXME: maybe this isn't even needed anymore...
						path = BLI_sprintfN("material_slots[\"%s\"].material.texture_slots[\"%s\"].texture.%s", 
						                    ma->id.name + 2, tex->id.name + 2, basepath);
							
						/* free old one */
						MEM_freeN(basepath);
					}
				}
				break;
			}
			
			/* fix RNA pointer, as we've now changed the ID root by changing the paths */
			if (basepath != path) {
				/* rebase provided pointer so that it starts from object... */
				RNA_pointer_create(&ob->id, ptr->type, ptr->data, ptr);
			}
		}
	}
	
	/* the path should now have been corrected for use */
	return path;
}
Exemple #10
0
static int select_report_pick_exec(bContext *C, wmOperator *op)
{
	int report_index = RNA_int_get(op->ptr, "report_index");
	Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);

	if (!report)
		return OPERATOR_CANCELLED;

	report->flag ^= SELECT; /* toggle */

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemple #11
0
static int clip_prefetch_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
	/* no running blender, remove handler and pass through */
	if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH))
		return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;

	/* running render */
	switch (event->type) {
		case ESCKEY:
			return OPERATOR_RUNNING_MODAL;
	}

	return OPERATOR_PASS_THROUGH;
}
Exemple #12
0
static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op))
{
	wmJob *wm_job;
	ProxyJob *pj;
	Scene *scene = CTX_data_scene(C);
	ScrArea *sa = CTX_wm_area(C);
	SpaceClip *sc = CTX_wm_space_clip(C);
	MovieClip *clip = ED_space_clip_get_clip(sc);

	if ((clip->flag & MCLIP_USE_PROXY) == 0)
		return OPERATOR_CANCELLED;

	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Building Proxies",
	                     WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_BUILD_PROXY);

	pj = MEM_callocN(sizeof(ProxyJob), "proxy rebuild job");
	pj->scene = scene;
	pj->main = CTX_data_main(C);
	pj->clip = clip;
	pj->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;

	if (clip->anim) {
		pj->index_context = IMB_anim_index_rebuild_context(clip->anim, clip->proxy.build_tc_flag,
		                                                   clip->proxy.build_size_flag, clip->proxy.quality);
	}

	WM_jobs_customdata_set(wm_job, pj, proxy_freejob);
	WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
	WM_jobs_callbacks(wm_job, proxy_startjob, NULL, NULL, proxy_endjob);

	G.is_break = FALSE;
	WM_jobs_start(CTX_wm_manager(C), wm_job);

	ED_area_tag_redraw(CTX_wm_area(C));

	return OPERATOR_FINISHED;
}
Exemple #13
0
/* standard header buttons for Animation Editors */
short ANIM_headerUI_standard_buttons (const bContext *C, bDopeSheet *ads, uiBlock *block, short xco, short yco)
{
    Main *mainptr= CTX_data_main(C);
    ScrArea *sa= CTX_wm_area(C);
    short nlaActive= ((sa) && (sa->spacetype==SPACE_NLA));

    /* check if the DopeSheet data exists, just in case... */
    if (ads) {
        /* more 'generic' filtering options */
        if (nlaActive) uiBlockBeginAlign(block);
        uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Only display selected Objects");
        if (nlaActive) uiDefIconButBitI(block, TOGN, ADS_FILTER_NLA_NOACT, B_REDR, ICON_ACTION,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Include AnimData blocks with no NLA Data");
        if (nlaActive) uiBlockEndAlign(block);
        xco += 5;

        /* datatype based - only available datatypes are shown */
        uiBlockBeginAlign(block);
        uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSCE, B_REDR, ICON_SCENE_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Scene Animation");
        uiDefIconButBitI(block, TOGN, ADS_FILTER_NOWOR, B_REDR, ICON_WORLD_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display World Animation");
        if (mainptr && mainptr->key.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_SHAPEKEY_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display ShapeKeys");
        if (mainptr && mainptr->mat.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Material Data");
        if (mainptr && mainptr->lamp.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Lamp Data");
        if (mainptr && mainptr->camera.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Camera Data");
        if (mainptr && mainptr->curve.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Curve Data");
        if (mainptr && mainptr->mball.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMBA, B_REDR, ICON_META_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display MetaBall Data");
        if (mainptr && mainptr->armature.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOARM, B_REDR, ICON_ARMATURE_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Armature Data");
        if (mainptr && mainptr->particle.first)
            uiDefIconButBitI(block, TOGN, ADS_FILTER_NOPART, B_REDR, ICON_PARTICLE_DATA,	(short)(xco+=XIC),yco,XIC,YIC, &(ads->filterflag), 0, 0, 0, 0, "Display Particle Data");
        uiBlockEndAlign(block);
        xco += 30;
    }
    else {
        // XXX this case shouldn't happen at all... for now, just pad out same amount of space
        printf("ERROR: dopesheet data not available when drawing Animation Editor header \n");
        xco += 11*XIC + 30;
    }

    // TODO: include auto-snapping menu here too...

    /* return the width of the buttons */
    return xco;
}
Exemple #14
0
void ED_animedit_unlink_action(bContext *C, ID *id, AnimData *adt, bAction *act, ReportList *reports)
{
	ScrArea *sa = CTX_wm_area(C);
	
	/* If the old action only has a single user (that it's about to lose),
	 * warn user about it
	 *
	 * TODO: Maybe we should just save it for them? But then, there's the problem of
	 *       trying to get rid of stuff that's actually unwanted!
	 */
	if (act->id.us == 1) {
		BKE_reportf(reports, RPT_WARNING,
		            "Action '%s' will not be saved, create Fake User or Stash in NLA Stack to retain",
		            act->id.name + 2);
	}
	
	/* If in Tweak Mode, don't unlink. Instead, this 
	 * becomes a shortcut to exit Tweak Mode instead
	 */
	if ((adt) && (adt->flag & ADT_NLA_EDIT_ON)) {
		/* Exit Tweak Mode */
		BKE_nla_tweakmode_exit(adt);
		
		/* Flush this to the Action Editor (if that's where this change was initiated) */
		if (sa->spacetype == SPACE_ACTION) {
			actedit_change_action(C, NULL);
		}
	}
	else {
		/* Unlink normally - Setting it to NULL should be enough to get the old one unlinked */
		if (sa->spacetype == SPACE_ACTION) {
			/* clear action editor -> action */
			actedit_change_action(C, NULL);
		}
		else {
			/* clear AnimData -> action */
			PointerRNA ptr;
			PropertyRNA *prop;
			
			/* create AnimData RNA pointers */
			RNA_pointer_create(id, &RNA_AnimData, adt, &ptr);
			prop = RNA_struct_find_property(&ptr, "action");
			
			/* clear... */
			RNA_property_pointer_set(&ptr, prop, PointerRNA_NULL);
			RNA_property_update(C, &ptr, prop);
		}
	}
}
Exemple #15
0
static int toggle_time_exec(bContext *C, wmOperator *UNUSED(op))
{
    ScrArea *curarea= CTX_wm_area(C);

    if (curarea == NULL)
        return OPERATOR_CANCELLED;

    /* simply toggle draw frames flag in applicable spaces */
    // XXX or should relevant spaces define their own version of this?
    switch (curarea->spacetype) {
    case SPACE_TIME: /* TimeLine */
    {
        SpaceTime *stime= CTX_wm_space_time(C);
        stime->flag ^= TIME_DRAWFRAMES;
    }
    break;
    case SPACE_ACTION: /* Action Editor */
    {
        SpaceAction *saction= CTX_wm_space_action(C);
        saction->flag ^= SACTION_DRAWTIME;
    }
    break;
    case SPACE_IPO: /* Graph Editor */
    {
        SpaceIpo *sipo= CTX_wm_space_graph(C);
        sipo->flag ^= SIPO_DRAWTIME;
    }
    break;
    case SPACE_NLA: /* NLA Editor */
    {
        SpaceNla *snla= CTX_wm_space_nla(C);
        snla->flag ^= SNLA_DRAWTIME;
    }
    break;
    case SPACE_SEQ: /* Sequencer */
    {
        SpaceSeq *sseq= CTX_wm_space_seq(C);
        sseq->flag ^= SEQ_DRAWFRAMES;
    }
    break;

    default: /* editor doesn't show frames */
        return OPERATOR_CANCELLED; // XXX or should we pass through instead?
    }

    ED_area_tag_redraw(curarea);

    return OPERATOR_FINISHED;
}
Exemple #16
0
static wmKeyMapItem *wm_keymap_item_find_props(
    const bContext *C, const char *opname, int opcontext,
    IDProperty *properties, int compare_props, int hotkey, wmKeyMap **keymap_r)
{
	wmWindow *win = CTX_wm_window(C);
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar = CTX_wm_region(C);
	wmKeyMapItem *found = NULL;

	/* look into multiple handler lists to find the item */
	if (win)
		found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
	

	if (sa && found == NULL)
		found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);

	if (found == NULL) {
		if (ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) {
			if (sa) {
				if (!(ar && ar->regiontype == RGN_TYPE_WINDOW))
					ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
				
				if (ar)
					found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
			}
		}
		else if (ELEM(opcontext, WM_OP_EXEC_REGION_CHANNELS, WM_OP_INVOKE_REGION_CHANNELS)) {
			if (!(ar && ar->regiontype == RGN_TYPE_CHANNELS))
				ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);

			if (ar)
				found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
		}
		else if (ELEM(opcontext, WM_OP_EXEC_REGION_PREVIEW, WM_OP_INVOKE_REGION_PREVIEW)) {
			if (!(ar && ar->regiontype == RGN_TYPE_PREVIEW))
				ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);

			if (ar)
				found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
		}
		else {
			if (ar)
				found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, compare_props, hotkey, keymap_r);
		}
	}
	
	return found;
}
Exemple #17
0
static void do_node_add(bContext *C, bNodeTemplate *ntemp)
{
	Main *bmain = CTX_data_main(C);
	Scene *scene = CTX_data_scene(C);
	SpaceNode *snode = CTX_wm_space_node(C);
	ScrArea *sa = CTX_wm_area(C);
	ARegion *ar;
	bNode *node, *node_new;
	
	/* get location to add node at mouse */
	for (ar = sa->regionbase.first; ar; ar = ar->next) {
		if (ar->regiontype == RGN_TYPE_WINDOW) {
			wmWindow *win = CTX_wm_window(C);
			int x = win->eventstate->x - ar->winrct.xmin;
			int y = win->eventstate->y - ar->winrct.ymin;
			
			if (y < 60) y += 60;
			UI_view2d_region_to_view(&ar->v2d, x, y, &snode->cursor[0], &snode->cursor[1]);
		}
	}
	
	/* store selection in temp test flag */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_SELECT) node->flag |= NODE_TEST;
		else node->flag &= ~NODE_TEST;
	}
	
	node_new = node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]);
	
	/* select previous selection before autoconnect */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_TEST) node->flag |= NODE_SELECT;
	}
	
	/* deselect after autoconnection */
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT;
	}

	/* once this is called from an operator, this should be removed */
	if (node_new) {
		char undostr[BKE_UNDO_STR_MAX];
		BLI_snprintf(undostr, sizeof(undostr), "Add Node %s", nodeLabel(node_new));
		BKE_write_undo(C, undostr);
	}

	snode_notify(C, snode);
	snode_dag_update(C, snode);
}
Exemple #18
0
static int actkeys_viewall(bContext *C, const bool only_sel, const bool only_xaxis)
{
	bAnimContext ac;
	View2D *v2d;
	float extra;
	bool found;
	
	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;
	v2d = &ac.ar->v2d;
	
	/* set the horizontal range, with an extra offset so that the extreme keys will be in view */
	found = get_keyframe_extents(&ac, &v2d->cur.xmin, &v2d->cur.xmax, only_sel);

	if (only_sel && (found == false))
		return OPERATOR_CANCELLED;
	
	extra = 0.1f * BLI_rctf_size_x(&v2d->cur);
	v2d->cur.xmin -= extra;
	v2d->cur.xmax += extra;
	
	/* set vertical range */
	if (only_xaxis == false) {
		v2d->cur.ymax = 0.0f;
		v2d->cur.ymin = (float)-BLI_rcti_size_y(&v2d->mask);
	}
	
	/* do View2D syncing */
	UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
	
	/* just redraw this view */
	ED_area_tag_redraw(CTX_wm_area(C));
	
	return OPERATOR_FINISHED;
}
Exemple #19
0
int ED_maskedit_mask_poll(bContext *C)
{
	ScrArea *sa = CTX_wm_area(C);
	if (sa) {
		switch (sa->spacetype) {
			case SPACE_CLIP:
				return ED_space_clip_maskedit_mask_poll(C);
			case SPACE_SEQ:
				return ED_space_sequencer_maskedit_mask_poll(C);
			case SPACE_IMAGE:
				return ED_space_image_maskedit_mask_poll(C);
		}
	}
	return FALSE;
}
Exemple #20
0
 /* XXX C can be zero */
static Object *get_poselib_object (bContext *C)
{
	ScrArea *sa;
	
	/* sanity check */
	if (C == NULL)
		return NULL;
	
	sa = CTX_wm_area(C);
	
	if (sa && (sa->spacetype == SPACE_BUTS)) 
		return ED_object_context(C);
	else
		return object_pose_armature_get(CTX_data_active_object(C));
}
Exemple #21
0
void ED_mask_draw(const bContext *C,
                  const char draw_flag, const char draw_type)
{
	ScrArea *sa = CTX_wm_area(C);

	Mask *mask = CTX_data_edit_mask(C);
	int width, height;

	if (!mask)
		return;

	ED_mask_get_size(sa, &width, &height);

	draw_masklays(C, mask, draw_flag, draw_type, width, height);
}
static int reset_recent_exec(bContext *C, wmOperator *UNUSED(op))
{
	ScrArea *sa = CTX_wm_area(C);
	char name[FILE_MAX];
	struct FSMenu *fsmenu = fsmenu_get();
	
	while (fsmenu_get_entry(fsmenu, FS_CATEGORY_RECENT, 0) != NULL) {
		fsmenu_remove_entry(fsmenu, FS_CATEGORY_RECENT, 0);
	}
	BLI_make_file_string("/", name, BLI_get_folder_create(BLENDER_USER_CONFIG, NULL), BLENDER_BOOKMARK_FILE);
	fsmenu_write_file(fsmenu, name);
	ED_area_tag_redraw(sa);
		
	return OPERATOR_FINISHED;
}
Exemple #23
0
/* matches logic with ED_operator_posemode_context() */
Object *ED_pose_object_from_context(bContext *C)
{
	ScrArea *sa = CTX_wm_area(C);
	Object *ob;

	/* since this call may also be used from the buttons window, we need to check for where to get the object */
	if (sa && sa->spacetype == SPACE_BUTS) {
		ob = ED_object_context(C);
	}
	else {
		ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
	}

	return ob;
}
Exemple #24
0
void ED_view3d_smooth_view(
        bContext *C,
        View3D *v3d, ARegion *ar, Object *oldcamera, Object *camera,
        const float *ofs, const float *quat, const float *dist, const float *lens,
        const int smooth_viewtx)
{
	wmWindowManager *wm = CTX_wm_manager(C);
	wmWindow *win = CTX_wm_window(C);
	ScrArea *sa = CTX_wm_area(C);

	ED_view3d_smooth_view_ex(
	        wm, win, sa,
	        v3d, ar, oldcamera, camera,
	        ofs, quat, dist, lens, smooth_viewtx);
}
Exemple #25
0
/* Check if there are any visible + editable keyframes (for editing tools) */
int graphop_editable_keyframes_poll(bContext *C)
{
	bAnimContext ac;
	bAnimListElem *ale;
	ListBase anim_data = {NULL, NULL};
	ScrArea *sa = CTX_wm_area(C);
	size_t items;
	int filter;
	short found = 0;
	
	/* firstly, check if in Graph Editor */
	// TODO: also check for region?
	if ((sa == NULL) || (sa->spacetype != SPACE_IPO))
		return 0;
		
	/* try to init Anim-Context stuff ourselves and check */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return 0;
	
	/* loop over the editable F-Curves, and see if they're suitable
	 * stopping on the first successful match
	 */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
	items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
	if (items == 0) 
		return 0;
	
	for (ale = anim_data.first; ale; ale = ale->next) {
		FCurve *fcu = (FCurve *)ale->data;
		
		/* editable curves must fulfill the following criteria:
		 *	- it has bezier keyframes
		 *	- it must not be protected from editing (this is already checked for with the foredit flag
		 *	- F-Curve modifiers do not interfere with the result too much 
		 *	  (i.e. the modifier-control drawing check returns false)
		 */
		if (fcu->bezt == NULL)
			continue;
		if (fcurve_is_keyframable(fcu)) {
			found = 1;
			break;
		}
	}
	
	/* cleanup and return findings */
	BLI_freelistN(&anim_data);
	return found;
}
Exemple #26
0
static int screencast_exec(bContext *C, wmOperator *op)
{
    wmWindowManager *wm = CTX_wm_manager(C);
    wmWindow *win = CTX_wm_window(C);
    bScreen *screen = CTX_wm_screen(C);
    wmJob *wm_job;
    ScreenshotJob *sj;

    /* if called again, stop the running job */
    if (WM_jobs_test(wm, screen, WM_JOB_TYPE_SCREENCAST))
        WM_jobs_stop(wm, screen, screenshot_startjob);

    wm_job = WM_jobs_get(wm, win, screen, "Screencast", 0, WM_JOB_TYPE_SCREENCAST);
    sj = MEM_callocN(sizeof(ScreenshotJob), "screenshot job");

    /* setup sj */
    if (RNA_boolean_get(op->ptr, "full")) {
        sj->x = 0;
        sj->y = 0;
        sj->dumpsx = WM_window_pixels_x(win);
        sj->dumpsy = WM_window_pixels_y(win);
    }
    else {
        ScrArea *curarea = CTX_wm_area(C);
        sj->x = curarea->totrct.xmin;
        sj->y = curarea->totrct.ymin;
        sj->dumpsx = curarea->totrct.xmax - sj->x;
        sj->dumpsy = curarea->totrct.ymax - sj->y;
    }
    sj->bmain = CTX_data_main(C);
    sj->scene = CTX_data_scene(C);
    sj->wm = wm;

    BKE_reports_init(&sj->reports, RPT_PRINT);

    /* setup job */
    WM_jobs_customdata_set(wm_job, sj, screenshot_freejob);
    WM_jobs_timer(wm_job, 0.1, 0, NC_SCREEN | ND_SCREENCAST);
    WM_jobs_callbacks(wm_job, screenshot_startjob, NULL, screenshot_updatejob, screenshot_endjob);

    WM_jobs_start(sj->wm, wm_job);

    screencast_cursor_toggle(sj->wm, 1);

    WM_event_add_notifier(C, NC_SCREEN | ND_SCREENCAST, screen);

    return OPERATOR_FINISHED;
}
/* the python exec operator uses this */
static int console_history_cycle_exec(bContext *C, wmOperator *op)
{
	SpaceConsole *sc = CTX_wm_space_console(C);
	ARegion *ar = CTX_wm_region(C);

	ConsoleLine *ci = console_history_verify(C); /* TODO - stupid, just prevents crashes when no command line */
	const bool reverse = RNA_boolean_get(op->ptr, "reverse"); /* assumes down, reverse is up */
	int prev_len = ci->len;

	/* keep a copy of the line above so when history is cycled
	 * this is the only function that needs to know about the double-up */
	if (ci->prev) {
		ConsoleLine *ci_prev = (ConsoleLine *)ci->prev;

		if (STREQ(ci->line, ci_prev->line))
			console_history_free(sc, ci_prev);
	}

	if (reverse) { /* last item in history */
		ci = sc->history.last;
		BLI_remlink(&sc->history, ci);
		BLI_addhead(&sc->history, ci);
	}
	else {
		ci = sc->history.first;
		BLI_remlink(&sc->history, ci);
		BLI_addtail(&sc->history, ci);
	}

	{   /* add a duplicate of the new arg and remove all other instances */
		ConsoleLine *cl;
		while ((cl = console_history_find(sc, ci->line, ci)))
			console_history_free(sc, cl);

		console_history_add(sc, (ConsoleLine *)sc->history.last);
	}
	
	ci = sc->history.last;
	console_select_offset(sc, ci->len - prev_len);

	/* could be wrapped so update scroll rect */
	console_textview_update_rect(sc, ar);
	ED_area_tag_redraw(CTX_wm_area(C));

	console_scroll_bottom(ar);

	return OPERATOR_FINISHED;
}
Exemple #28
0
static int primitive_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
	ScrArea *sa = CTX_wm_area(C);
	float cursor[2];
	int width, height;

	ED_mask_get_size(sa, &width, &height);
	ED_mask_cursor_location_get(sa, cursor);

	cursor[0] *= width;
	cursor[1] *= height;

	RNA_float_set_array(op->ptr, "location", cursor);

	return op->type->exec(C, op);
}
Exemple #29
0
static int game_engine_poll(bContext *C)
{
	/* we need a context and area to launch BGE
	it's a temporary solution to avoid crash at load time
	if we try to auto run the BGE. Ideally we want the
	context to be set as soon as we load the file. */

	if(CTX_wm_window(C)==NULL) return 0;
	if(CTX_wm_screen(C)==NULL) return 0;
	if(CTX_wm_area(C)==NULL) return 0;

	if(CTX_data_mode_enum(C)!=CTX_MODE_OBJECT)
		return 0;

	return 1;
}
Exemple #30
0
static int file_filenum_exec(bContext *C, wmOperator *op)
{
	SpaceFile *sfile= CTX_wm_space_file(C);
	ScrArea *sa= CTX_wm_area(C);
	
	int inc = RNA_int_get(op->ptr, "increment");
	if(sfile->params && (inc != 0)) {
		BLI_newname(sfile->params->file, inc);
		ED_area_tag_redraw(sa);
		file_draw_check_cb(C, NULL, NULL);
		// WM_event_add_notifier(C, NC_WINDOW, NULL);
	}
	
	return OPERATOR_FINISHED;

}