static int node_borderselect_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	ARegion *ar = CTX_wm_region(C);
	bNode *node;
	rcti rect;
	rctf rectf;
	int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
	int extend = RNA_boolean_get(op->ptr, "extend");
	
	WM_operator_properties_border_to_rcti(op, &rect);

	UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);
	UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);
	
	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (BLI_rctf_isect(&rectf, &node->totr, NULL)) {
			nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT));
		}
		else if (!extend) {
			nodeSetSelected(node, FALSE);
		}
	}
	
	ED_node_sort(snode->edittree);
	
	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);

	return OPERATOR_FINISHED;
}
Beispiel #2
0
static int previewrange_define_exec(bContext *C, wmOperator *op)
{
    Scene *scene= CTX_data_scene(C);
    ARegion *ar= CTX_wm_region(C);
    float sfra, efra;
    int xmin, xmax;

    /* get min/max values from border select rect (already in region coordinates, not screen) */
    xmin= RNA_int_get(op->ptr, "xmin");
    xmax= RNA_int_get(op->ptr, "xmax");

    /* convert min/max values to frames (i.e. region to 'tot' rect) */
    UI_view2d_region_to_view(&ar->v2d, xmin, 0, &sfra, NULL);
    UI_view2d_region_to_view(&ar->v2d, xmax, 0, &efra, NULL);

    /* set start/end frames for preview-range
     *	- must clamp within allowable limits
     *	- end must not be before start (though this won't occur most of the time)
     */
    FRAMENUMBER_MIN_CLAMP(sfra);
    FRAMENUMBER_MIN_CLAMP(efra);
    if (efra < sfra) efra= sfra;

    scene->r.flag |= SCER_PRV_RANGE;
    scene->r.psfra= (int)floor(sfra + 0.5f);
    scene->r.pefra= (int)floor(efra + 0.5f);

    /* send notifiers */
    WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);

    return OPERATOR_FINISHED;
}
Beispiel #3
0
static int outliner_border_select_exec(bContext *C, wmOperator *op)
{
	Scene *scene= CTX_data_scene(C);
	SpaceOops *soops= CTX_wm_space_outliner(C);
	ARegion *ar= CTX_wm_region(C);
	TreeElement *te;
	rcti rect;
	rctf rectf;
	int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");

	rect.xmin= RNA_int_get(op->ptr, "xmin");
	rect.ymin= RNA_int_get(op->ptr, "ymin");
	UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin);

	rect.xmax= RNA_int_get(op->ptr, "xmax");
	rect.ymax= RNA_int_get(op->ptr, "ymax");
	UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax);

	for(te= soops->tree.first; te; te= te->next) {
		outliner_item_border_select(scene, soops, &rectf, te, gesture_mode);
	}

	WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
	ED_region_tag_redraw(ar);

	return OPERATOR_FINISHED;
}
Beispiel #4
0
static void borderselect_nla_strips(bAnimContext *ac, rcti rect, short mode, short selectmode)
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale;
	int filter;
	
	SpaceNla *snla = (SpaceNla *)ac->sl;
	View2D *v2d = &ac->ar->v2d;
	rctf rectf;
	float ymin /* =(float)(-NLACHANNEL_HEIGHT(snla)) */ /* UNUSED */, ymax = 0;
	
	/* convert border-region to view coordinates */
	UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin + 2, &rectf.xmin, &rectf.ymin);
	UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax - 2, &rectf.xmax, &rectf.ymax);
	
	/* filter data */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
	
	/* convert selection modes to selection modes */
	selectmode = selmodes_to_flagmodes(selectmode);
	
	/* loop over data, doing border select */
	for (ale = anim_data.first; ale; ale = ale->next) {
		ymin = ymax - NLACHANNEL_STEP(snla);
		
		/* perform vertical suitability check (if applicable) */
		if ((mode == NLA_BORDERSEL_FRAMERANGE) ||
		    !((ymax < rectf.ymin) || (ymin > rectf.ymax)))
		{
			/* loop over data selecting (only if NLA-Track) */
			if (ale->type == ANIMTYPE_NLATRACK) {
				NlaTrack *nlt = (NlaTrack *)ale->data;
				NlaStrip *strip;
				
				/* only select strips if they fall within the required ranges (if applicable) */
				for (strip = nlt->strips.first; strip; strip = strip->next) {
					if ((mode == NLA_BORDERSEL_CHANNELS) ||
					    BKE_nlastrip_within_bounds(strip, rectf.xmin, rectf.xmax))
					{
						/* set selection */
						ACHANNEL_SET_FLAG(strip, selectmode, NLASTRIP_FLAG_SELECT);
						
						/* clear active flag */
						strip->flag &= ~NLASTRIP_FLAG_ACTIVE;
					}
				}
			}
		}
		
		/* set minimum extent to be the maximum of the next channel */
		ymax = ymin;
	}
	
	/* cleanup */
	ANIM_animdata_freelist(&anim_data);
}
Beispiel #5
0
void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser)
{
    float newuv[2], olduv[2];
    ImagePaintState *s = ps;
    BrushPainter *painter = s->painter;
    ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL);
    const bool is_data = (ibuf && ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA);

    if (!ibuf)
        return;

    s->blend = s->brush->blend;
    if (eraser)
        s->blend = IMB_BLEND_ERASE_ALPHA;

    UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
    UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]);

    newuv[0] *= ibuf->x;
    newuv[1] *= ibuf->y;

    olduv[0] *= ibuf->x;
    olduv[1] *= ibuf->y;

    if (painter->firsttouch) {
        float startuv[2];

        UI_view2d_region_to_view(s->v2d, 0, 0, &startuv[0], &startuv[1]);

        /* paint exactly once on first touch */
        painter->startpaintpos[0] = startuv[0] * ibuf->x;
        painter->startpaintpos[1] = startuv[1] * ibuf->y;

        painter->firsttouch = 0;
        copy_v2_v2(painter->lastpaintpos, newuv);
    }
    else {
        copy_v2_v2(painter->lastpaintpos, olduv);
    }

    /* OCIO_TODO: float buffers are now always linear, so always use color correction
     *            this should probably be changed when texture painting color space is supported
     */
    brush_painter_2d_require_imbuf(painter, (ibuf->rect_float != NULL), !is_data, s->do_masking);

    brush_painter_2d_refresh_cache(s, painter, newuv, mval);

    if (paint_2d_op(s, painter->cache.ibuf, painter->cache.mask, olduv, newuv))
        s->need_redraw = true;

    BKE_image_release_ibuf(s->image, ibuf, NULL);
}
Beispiel #6
0
static int node_circleselect_exec(bContext *C, wmOperator *op)
{
	SpaceNode *snode = CTX_wm_space_node(C);
	ARegion *ar = CTX_wm_region(C);
	bNode *node;

	int x, y, radius, gesture_mode;
	float offset[2];

	float zoom  = (float)(BLI_rcti_size_x(&ar->winrct)) / (float)(BLI_rctf_size_x(&ar->v2d.cur));

	gesture_mode = RNA_int_get(op->ptr, "gesture_mode");

	/* get operator properties */
	x = RNA_int_get(op->ptr, "x");
	y = RNA_int_get(op->ptr, "y");
	radius = RNA_int_get(op->ptr, "radius");

	UI_view2d_region_to_view(&ar->v2d, x, y, &offset[0], &offset[1]);

	for (node = snode->edittree->nodes.first; node; node = node->next) {
		if (BLI_rctf_isect_circle(&node->totr, offset, radius / zoom)) {
			nodeSetSelected(node, (gesture_mode == GESTURE_MODAL_SELECT));
		}
	}

	WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL);

	return OPERATOR_FINISHED;
}
Beispiel #7
0
/* takes event->mval */
void ED_mask_mouse_pos(ScrArea *sa, ARegion *ar, const int mval[2], float co[2])
{
	if (sa) {
		switch (sa->spacetype) {
			case SPACE_CLIP:
			{
				SpaceClip *sc = sa->spacedata.first;
				ED_clip_mouse_pos(sc, ar, mval, co);
				BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co);
				break;
			}
			case SPACE_SEQ:
			{
				UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &co[0], &co[1]);
				break;
			}
			case SPACE_IMAGE:
			{
				SpaceImage *sima = sa->spacedata.first;
				ED_image_mouse_pos(sima, ar, mval, co);
				BKE_mask_coord_from_image(sima->image, &sima->iuser, co, co);
				break;
			}
			default:
				/* possible other spaces from which mask editing is available */
				BLI_assert(0);
				zero_v2(co);
				break;
		}
	}
	else {
		BLI_assert(0);
		zero_v2(co);
	}
}
Beispiel #8
0
int file_highlight_set(SpaceFile *sfile, ARegion *ar, int mx, int my)
{
	View2D *v2d = &ar->v2d;
	FileSelectParams *params;
	int numfiles, origfile;

	if (sfile == NULL || sfile->files == NULL) return 0;

	numfiles = filelist_numfiles(sfile->files);
	params = ED_fileselect_get_params(sfile);

	origfile = params->active_file;

	mx -= ar->winrct.xmin;
	my -= ar->winrct.ymin;

	if (BLI_rcti_isect_pt(&ar->v2d.mask, mx, my)) {
		float fx, fy;
		int active_file;

		UI_view2d_region_to_view(v2d, mx, my, &fx, &fy);

		active_file = ED_fileselect_layout_offset(sfile->layout, (int)(v2d->tot.xmin + fx), (int)(v2d->tot.ymax - fy));

		if ((active_file >= 0) && (active_file < numfiles))
			params->active_file = active_file;
		else
			params->active_file = -1;
	}
	else
		params->active_file = -1;

	return (params->active_file != origfile);
}
Beispiel #9
0
static int graphkeys_select_leftright_invoke (bContext *C, wmOperator *op, wmEvent *event)
{
	bAnimContext ac;
	short leftright = RNA_enum_get(op->ptr, "mode");
	
	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;
		
	/* handle mode-based testing */
	if (leftright == GRAPHKEYS_LRSEL_TEST) {
		Scene *scene= ac.scene;
		ARegion *ar= ac.ar;
		View2D *v2d= &ar->v2d;
		
		short mval[2];
		float x;
		
		/* get mouse coordinates (in region coordinates) */
		mval[0]= (event->x - ar->winrct.xmin);
		mval[1]= (event->y - ar->winrct.ymin);
		
		/* determine which side of the current frame mouse is on */
		UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, NULL);
		if (x < CFRA)
			RNA_int_set(op->ptr, "mode", GRAPHKEYS_LRSEL_LEFT);
		else 	
			RNA_int_set(op->ptr, "mode", GRAPHKEYS_LRSEL_RIGHT);
	}
	
	/* perform selection */
	return graphkeys_select_leftright_exec(C, op);
}
Beispiel #10
0
static int node_toggle_visibility(SpaceNode *snode, ARegion *ar, const int mval[2])
{
	bNode *node;
	float mx, my;
	
	mx= (float)mval[0];
	my= (float)mval[1];
	
	UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &mx, &my);
	
	for(node=snode->edittree->nodes.last; node; node=node->prev) {
		if(node->flag & NODE_HIDDEN) {
			if(do_header_hidden_node(node, mx, my)) {
				ED_region_tag_redraw(ar);
				return 1;
			}
		}
		else {
			if(do_header_node(snode, node, mx, my)) {
				ED_region_tag_redraw(ar);
				return 1;
			}
		}
	}
	return 0;
}
Beispiel #11
0
static int paintcurve_cursor_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
  ePaintMode mode = BKE_paintmode_get_active_from_context(C);

  switch (mode) {
    case PAINT_MODE_TEXTURE_2D: {
      ARegion *ar = CTX_wm_region(C);
      SpaceImage *sima = CTX_wm_space_image(C);
      float location[2];

      if (!sima) {
        return OPERATOR_CANCELLED;
      }

      UI_view2d_region_to_view(
          &ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
      copy_v2_v2(sima->cursor, location);
      WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL);
      break;
    }
    default:
      ED_view3d_cursor3d_update(C, event->mval, true, V3D_CURSOR_ORIENT_VIEW);
      break;
  }

  return OPERATOR_FINISHED;
}
Beispiel #12
0
static int ed_marker_select(bContext *C, wmEvent *evt, int extend)
{
	ListBase *markers= context_get_markers(C);
	View2D *v2d= UI_view2d_fromcontext(C);
	float viewx;
	int x, y, cfra;
	
	if(markers == NULL)
		return OPERATOR_PASS_THROUGH;

	x= evt->x - CTX_wm_region(C)->winrct.xmin;
	y= evt->y - CTX_wm_region(C)->winrct.ymin;
	
	UI_view2d_region_to_view(v2d, x, y, &viewx, NULL);	
	
	cfra= ED_markers_find_nearest_marker_time(markers, viewx);
	
	if (extend)
		select_timeline_marker_frame(markers, cfra, 1);
	else
		select_timeline_marker_frame(markers, cfra, 0);
	
	WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);

	/* allowing tweaks */
	return OPERATOR_PASS_THROUGH;
}
/* set the operator properties from the initial event */
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
{
	Scene *scene = CTX_data_scene(C);
	ARegion *ar = CTX_wm_region(C);
	float viewx, viewy;
	int frame;
	
	/* abort if not active region (should not really be possible) */
	if (ar == NULL)
		return;
	
	/* convert from region coordinates to View2D 'tot' space */
	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
	
	/* frame is rounded to the nearest int, since frames are ints */
	frame = iroundf(viewx);
	
	if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
		CLAMP(frame, PSFRA, PEFRA);
	}
	
	/* store the values in the operator properties */
	RNA_int_set(op->ptr, "frame", frame);
	RNA_float_set(op->ptr, "value", viewy);
}
static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	bAnimContext ac;
	short leftright = RNA_enum_get(op->ptr, "mode");
	
	/* get editor data */
	if (ANIM_animdata_get_context(C, &ac) == 0)
		return OPERATOR_CANCELLED;
		
	/* handle mode-based testing */
	if (leftright == ACTKEYS_LRSEL_TEST) {
		Scene *scene = ac.scene;
		ARegion *ar = ac.ar;
		View2D *v2d = &ar->v2d;
		float x;

		/* determine which side of the current frame mouse is on */
		UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, NULL);
		if (x < CFRA)
			RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_LEFT);
		else
			RNA_enum_set(op->ptr, "mode", ACTKEYS_LRSEL_RIGHT);
	}
	
	/* perform selection */
	return actkeys_select_leftright_exec(C, op);
}
Beispiel #15
0
/* ---------- FILE SELECTION ------------ */
static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion* ar, const rcti* rect)
{
	FileSelection sel;
	float fxmin,fymin,fxmax, fymax;
	
	View2D* v2d = &ar->v2d;
	rcti rect_view;

	UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin, &fxmin, &fymin);
	UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax, &fxmax, &fymax);

	BLI_init_rcti(&rect_view, (int)(v2d->tot.xmin + fxmin), (int)(v2d->tot.xmin + fxmax), (int)(v2d->tot.ymax - fymin), (int)(v2d->tot.ymax - fymax));

	sel  = ED_fileselect_layout_offset_rect(sfile->layout, &rect_view);
	
	return sel;
}
static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	ARegion *ar = CTX_wm_region(C);
	float co[2];

	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
	RNA_float_set_array(op->ptr, "location", co);

	return select_exec(C, op);
}
Beispiel #17
0
static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
{
	View2D *v2d= UI_view2d_fromcontext(C);
	ListBase *markers= context_get_markers(C);
	TimeMarker *marker;
	float xminf, xmaxf, yminf, ymaxf;
	int event_type= RNA_int_get(op->ptr, "event_type");
	int xmin= RNA_int_get(op->ptr, "xmin");
	int xmax= RNA_int_get(op->ptr, "xmax");
	int ymin= RNA_int_get(op->ptr, "ymin");
	int ymax= RNA_int_get(op->ptr, "ymax");
	
	UI_view2d_region_to_view(v2d, xmin, ymin, &xminf, &yminf);	
	UI_view2d_region_to_view(v2d, xmax, ymax, &xmaxf, &ymaxf);	
	
	/* XXX disputable */
	if(yminf > 30.0f || ymaxf < 0.0f)
		return 0;
	
	if(markers == NULL)
		return 0;
	
	/* XXX marker context */
	for(marker= markers->first; marker; marker= marker->next) {
		if ((marker->frame > xminf) && (marker->frame <= xmaxf)) {
			/* XXX weak... */
			switch (event_type) {
				case LEFTMOUSE:
					if ((marker->flag & SELECT) == 0) 
						marker->flag |= SELECT;
					break;
				case RIGHTMOUSE:
					if (marker->flag & SELECT) 
						marker->flag &= ~SELECT;
					break;
			}
		}
	}
	
	WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);

	return 1;
}
Beispiel #18
0
static int dopesheet_select_channel_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
	ARegion *ar = CTX_wm_region(C);
	float location[2];

	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
	RNA_float_set_array(op->ptr, "location", location);

	return dopesheet_select_channel_exec(C, op);
}
Beispiel #19
0
/* Get frame from mouse coordinates */
static int frame_from_event(bContext *C, wmEvent *event)
{
    ARegion *region= CTX_wm_region(C);
    float viewx;

    /* convert from region coordinates to View2D 'tot' space */
    UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, NULL);

    /* round result to nearest int (frames are ints!) */
    return (int)floor(viewx+0.5f);
}
Beispiel #20
0
static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
{
	View2D *v2d= UI_view2d_fromcontext(C);
	ListBase *markers= ED_context_get_markers(C);
	TimeMarker *marker;
	float xminf, xmaxf, yminf, ymaxf;
	int gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
	int xmin= RNA_int_get(op->ptr, "xmin");
	int xmax= RNA_int_get(op->ptr, "xmax");
	int ymin= RNA_int_get(op->ptr, "ymin");
	int ymax= RNA_int_get(op->ptr, "ymax");
	int extend= RNA_boolean_get(op->ptr, "extend");
	
	UI_view2d_region_to_view(v2d, xmin, ymin, &xminf, &yminf);	
	UI_view2d_region_to_view(v2d, xmax, ymax, &xmaxf, &ymaxf);	
	
	if (markers == NULL)
		return 0;
	
	/* XXX marker context */
	for (marker= markers->first; marker; marker= marker->next) {
		if ((marker->frame > xminf) && (marker->frame <= xmaxf)) {
			switch (gesture_mode) {
				case GESTURE_MODAL_SELECT:
					marker->flag |= SELECT;
					break;
				case GESTURE_MODAL_DESELECT:
					marker->flag &= ~SELECT;
					break;
			}
		}
		else if (!extend) {
			marker->flag &= ~SELECT;
		}
	}
	
	WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
	WM_event_add_notifier(C, NC_ANIMATION|ND_MARKERS, NULL);

	return 1;
}
Beispiel #21
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);
}
Beispiel #22
0
static int outliner_item_rename(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
{
	ARegion *ar= CTX_wm_region(C);
	SpaceOops *soops= CTX_wm_space_outliner(C);
	TreeElement *te;
	float fmval[2];
	
	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval+1);
	
	for(te= soops->tree.first; te; te= te->next) {
		if(do_outliner_item_rename(C, ar, soops, te, fmval)) break;
	}
	
	return OPERATOR_FINISHED;
}
Beispiel #23
0
/* event can enterkey, then it opens/closes */
static int outliner_item_activate(bContext *C, wmOperator *op, wmEvent *event)
{
	Scene *scene= CTX_data_scene(C);
	ARegion *ar= CTX_wm_region(C);
	SpaceOops *soops= CTX_wm_space_outliner(C);
	TreeElement *te;
	float fmval[2];
	int extend= RNA_boolean_get(op->ptr, "extend");

	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval+1);

	if ( !ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP) &&
	     !(soops->flag & SO_HIDE_RESTRICTCOLS) &&
	     (fmval[0] > ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX))
	{
		return OPERATOR_CANCELLED;
	}

	for(te= soops->tree.first; te; te= te->next) {
		if(do_outliner_item_activate(C, scene, ar, soops, te, extend, fmval)) break;
	}
	
	if(te) {
		ED_undo_push(C, "Outliner click event");
	}
	else {
		short selecting= -1;
		int row;
		
		/* get row number - 100 here is just a dummy value since we don't need the column */
		UI_view2d_listview_view_to_cell(&ar->v2d, 1000, UI_UNIT_Y, 0.0f, OL_Y_OFFSET, 
						fmval[0], fmval[1], NULL, &row);
		
		/* select relevant row */
		if(outliner_select(soops, &soops->tree, &row, &selecting)) {
		
			soops->storeflag |= SO_TREESTORE_REDRAW;
		
			/* no need for undo push here, only changing outliner data which is
			 * scene level - campbell */
			/* ED_undo_push(C, "Outliner selection event"); */
		}
	}
	
	ED_region_tag_redraw(ar);

	return OPERATOR_FINISHED;
}
Beispiel #24
0
/* set the operator properties from the initial event */
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
{
	ARegion *ar = CTX_wm_region(C);
	float viewx, viewy;
	
	/* abort if not active region (should not really be possible) */
	if (ar == NULL)
		return;
	
	/* convert from region coordinates to View2D 'tot' space */
	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
	
	/* store the values in the operator properties */
	/* NOTE: we don't clamp frame here, as it might be used for the drivers cursor */
	RNA_float_set(op->ptr, "frame", viewx);
	RNA_float_set(op->ptr, "value", viewy);
}
Beispiel #25
0
/* set the operator properties from the initial event */
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
{
	ARegion *ar = CTX_wm_region(C);
	float viewx, viewy;

	/* abort if not active region (should not really be possible) */
	if (ar == NULL)
		return;

	/* convert from region coordinates to View2D 'tot' space */
	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
	
	/* store the values in the operator properties */
	/* frame is rounded to the nearest int, since frames are ints */
	RNA_int_set(op->ptr, "frame", iroundf(viewx));
	RNA_float_set(op->ptr, "value", viewy);
}
Beispiel #26
0
static int outliner_operation(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
	Scene *scene = CTX_data_scene(C);
	ARegion *ar = CTX_wm_region(C);
	SpaceOops *soops = CTX_wm_space_outliner(C);
	TreeElement *te;
	float fmval[2];

	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
	
	for (te = soops->tree.first; te; te = te->next) {
		if (do_outliner_operation_event(C, scene, ar, soops, te, event, fmval)) {
			break;
		}
	}
	
	return OPERATOR_FINISHED;
}
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_item_openclose(bContext *C, wmOperator *op, const wmEvent *event)
{
    ARegion             *ar         = CTX_wm_region(C);
    SpaceLDB            *slivedb    = CTX_wm_space_mat_livedb(C);
    int                 all         = RNA_boolean_get(op->ptr, "all");
    LiveDbTreeElement   *te;
    float               fmval[2];
    
    UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
    
    for (te = slivedb->tree.first; te; te = te->next) {
        if (do_mat_livedb_item_openclose(C, slivedb, te, all, fmval)) 
            break;
    }
    ED_region_tag_redraw(ar);
    
    return OPERATOR_FINISHED;
} /* mat_livedb_item_openclose() */
/* /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
static int mat_livedb_item_rename(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
    ARegion             *ar         = CTX_wm_region(C);
    SpaceLDB            *slivedb    = CTX_wm_space_mat_livedb(C);
    bool                change      = false;
    LiveDbTreeElement   *te;
    float               fmval[2];
    
    UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
    
    for (te = slivedb->tree.first; te; te = te->next) {
        if (do_mat_livedb_item_rename(C, ar, slivedb, te, fmval)) {
            change = true;
            break;
        }
    }
    return change ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
} /* mat_livedb_item_rename() */
Beispiel #29
0
static int node_border_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	const bool tweak = RNA_boolean_get(op->ptr, "tweak");
	
	if (tweak) {
		/* prevent initiating the border select if the mouse is over a node */
		/* this allows border select on empty space, but drag-translate on nodes */
		SpaceNode *snode = CTX_wm_space_node(C);
		ARegion *ar = CTX_wm_region(C);
		float mx, my;

		UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my);
		
		if (node_under_mouse_tweak(snode->edittree, mx, my))
			return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
	}
	
	return WM_border_select_invoke(C, op, event);
}
Beispiel #30
0
/* event can enterkey, then it opens/closes */
static int outliner_item_openclose(bContext *C, wmOperator *op, wmEvent *event)
{
	ARegion *ar= CTX_wm_region(C);
	SpaceOops *soops= CTX_wm_space_outliner(C);
	TreeElement *te;
	float fmval[2];
	int all= RNA_boolean_get(op->ptr, "all");
	
	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval+1);
	
	for(te= soops->tree.first; te; te= te->next) {
		if(do_outliner_item_openclose(C, soops, te, all, fmval)) 
			break;
	}

	ED_region_tag_redraw(ar);
	
	return OPERATOR_FINISHED;
}