Esempio n. 1
0
void wm_open_init_load_ui(wmOperator *op, bool use_prefs)
{
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "load_ui");
	if (!RNA_property_is_set(op->ptr, prop)) {
		bool value = use_prefs ?
		             ((U.flag & USER_FILENOUI) == 0) :
		             ((G.fileflags & G_FILE_NO_UI) == 0);

		RNA_property_boolean_set(op->ptr, prop, value);
	}
}
Esempio n. 2
0
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs)
{
	PropertyRNA *prop = RNA_struct_find_property(op->ptr, "use_scripts");
	if (!RNA_property_is_set(op->ptr, prop)) {
		/* use G_SCRIPT_AUTOEXEC rather than the userpref because this means if
		 * the flag has been disabled from the command line, then opening
		 * from the menu wont enable this setting. */
		bool value = use_prefs ?
		             ((U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0) :
		             ((G.f & G_SCRIPT_AUTOEXEC) != 0);

		RNA_property_boolean_set(op->ptr, prop, value);
	}
}
Esempio n. 3
0
static void bake_set_props(wmOperator *op, Scene *scene)
{
	PropertyRNA *prop;
	BakeData *bake = &scene->r.bake;

	prop = RNA_struct_find_property(op->ptr, "filepath");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_string_set(op->ptr, prop, bake->filepath);
	}

	prop =  RNA_struct_find_property(op->ptr, "width");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->width);
	}

	prop =  RNA_struct_find_property(op->ptr, "height");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->width);
	}

	prop = RNA_struct_find_property(op->ptr, "margin");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->margin);
	}

	prop = RNA_struct_find_property(op->ptr, "use_selected_to_active");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_TO_ACTIVE) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "cage_extrusion");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_float_set(op->ptr, prop, bake->cage_extrusion);
	}

	prop = RNA_struct_find_property(op->ptr, "cage_object");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_string_set(op->ptr, prop, bake->cage);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_space");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_space);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_r");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[0]);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_g");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[1]);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_b");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[2]);
	}

	prop = RNA_struct_find_property(op->ptr, "save_mode");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->save_mode);
	}

	prop = RNA_struct_find_property(op->ptr, "use_clear");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_CLEAR) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_cage");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_CAGE) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_split_materials");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_SPLIT_MAT) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_automatic_name");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_AUTO_NAME) != 0);
	}
}
Esempio n. 4
0
/**
 * \note RNA_struct_property_is_set_ex is used here because we want
 *       the previously used settings to be used here rather then overriding them */
short ED_fileselect_set_params(SpaceFile *sfile)
{
	FileSelectParams *params;
	wmOperator *op = sfile->op;

	/* create new parameters if necessary */
	if (!sfile->params) {
		sfile->params = MEM_callocN(sizeof(FileSelectParams), "fileselparams");
		/* set path to most recently opened .blend */
		BLI_split_dirfile(G.main->name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
		sfile->params->filter_glob[0] = '\0';
		/* set the default thumbnails size */
		sfile->params->thumbnail_size = 128;
	}

	params = sfile->params;

	/* set the parameters from the operator, if it exists */
	if (op) {
		PropertyRNA *prop;
		const bool is_files = (RNA_struct_find_property(op->ptr, "files") != NULL);
		const bool is_filepath = (RNA_struct_find_property(op->ptr, "filepath") != NULL);
		const bool is_filename = (RNA_struct_find_property(op->ptr, "filename") != NULL);
		const bool is_directory = (RNA_struct_find_property(op->ptr, "directory") != NULL);
		const bool is_relative_path = (RNA_struct_find_property(op->ptr, "relative_path") != NULL);

		BLI_strncpy_utf8(params->title, RNA_struct_ui_name(op->type->srna), sizeof(params->title));

		if ((prop = RNA_struct_find_property(op->ptr, "filemode"))) {
			params->type = RNA_property_int_get(op->ptr, prop);
		}
		else {
			params->type = FILE_SPECIAL;
		}

		if (is_filepath && RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
			char name[FILE_MAX];
			RNA_string_get(op->ptr, "filepath", name);
			if (params->type == FILE_LOADLIB) {
				BLI_strncpy(params->dir, name, sizeof(params->dir));
				sfile->params->file[0] = '\0';
			}
			else {
				BLI_split_dirfile(name, sfile->params->dir, sfile->params->file, sizeof(sfile->params->dir), sizeof(sfile->params->file));
			}
		}
		else {
			if (is_directory && RNA_struct_property_is_set_ex(op->ptr, "directory", false)) {
				RNA_string_get(op->ptr, "directory", params->dir);
				sfile->params->file[0] = '\0';
			}

			if (is_filename && RNA_struct_property_is_set_ex(op->ptr, "filename", false)) {
				RNA_string_get(op->ptr, "filename", params->file);
			}
		}

		if (params->dir[0]) {
			BLI_cleanup_dir(G.main->name, params->dir);
			BLI_path_abs(params->dir, G.main->name);
		}

		if (is_directory == true && is_filename == false && is_filepath == false && is_files == false) {
			params->flag |= FILE_DIRSEL_ONLY;
		}
		else {
			params->flag &= ~FILE_DIRSEL_ONLY;
		}

		params->filter = 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_blender")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_backup")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BLENDER_BACKUP : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_image")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_IMAGE : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_movie")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_MOVIE : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_python")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_PYSCRIPT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_font")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FTFONT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_sound")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_SOUND : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_text")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_TEXT : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_folder")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_FOLDER : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_btx")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_BTX : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_collada")))
			params->filter |= RNA_property_boolean_get(op->ptr, prop) ? FILE_TYPE_COLLADA : 0;
		if ((prop = RNA_struct_find_property(op->ptr, "filter_glob"))) {
			RNA_property_string_get(op->ptr, prop, params->filter_glob);
			params->filter |= (FILE_TYPE_OPERATOR | FILE_TYPE_FOLDER);
		}
		else {
			params->filter_glob[0] = '\0';
		}

		if (params->filter != 0) {
			if (U.uiflag & USER_FILTERFILEEXTS) {
				params->flag |= FILE_FILTER;
			}
			else {
				params->flag &= ~FILE_FILTER;
			}
		}

		if (U.uiflag & USER_HIDE_DOT) {
			params->flag |= FILE_HIDE_DOT;
		}
		else {
			params->flag &= ~FILE_HIDE_DOT;
		}
		

		if (params->type == FILE_LOADLIB) {
			params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0;
			params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0;
			params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
		}

		if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) {
			params->display = RNA_property_enum_get(op->ptr, prop);
		}

		if (params->display == FILE_DEFAULTDISPLAY) {
			if (U.uiflag & USER_SHOW_THUMBNAILS) {
				if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE))
					params->display = FILE_IMGDISPLAY;
				else
					params->display = FILE_SHORTDISPLAY;
			}
			else {
				params->display = FILE_SHORTDISPLAY;
			}
		}

		if (is_relative_path) {
			if ((prop = RNA_struct_find_property(op->ptr, "relative_path"))) {
				if (!RNA_property_is_set_ex(op->ptr, prop, false)) {
					RNA_property_boolean_set(op->ptr, prop, (U.flag & USER_RELPATHS) != 0);
				}
			}
		}
	}
	else {
		/* default values, if no operator */
		params->type = FILE_UNIX;
		params->flag |= FILE_HIDE_DOT;
		params->flag &= ~FILE_DIRSEL_ONLY;
		params->display = FILE_SHORTDISPLAY;
		params->filter = 0;
		params->filter_glob[0] = '\0';
	}

	/* operator has no setting for this */
	params->sort = FILE_SORT_ALPHA;
	params->active_file = -1;


	/* initialize the list with previous folders */
	if (!sfile->folders_prev)
		sfile->folders_prev = folderlist_new();

	if (!sfile->params->dir[0]) {
		if (G.main->name[0]) {
			BLI_split_dir_part(G.main->name, sfile->params->dir, sizeof(sfile->params->dir));
		}
		else {
			const char *doc_path = BKE_appdir_folder_default();
			if (doc_path) {
				BLI_strncpy(sfile->params->dir, doc_path, sizeof(sfile->params->dir));
			}
		}
	}

	folderlist_pushdir(sfile->folders_prev, sfile->params->dir);

	/* switching thumbnails needs to recalc layout [#28809] */
	if (sfile->layout) {
		sfile->layout->dirty = true;
	}

	return 1;
}
Esempio n. 5
0
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	BevelData *opdata = op->customdata;
	const bool has_numinput = hasNumInput(&opdata->num_input[opdata->value_mode]);

	/* Modal numinput active, try to handle numeric inputs first... */
	if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
		edbm_bevel_numinput_set_value(op);
		edbm_bevel_calc(op);
		edbm_bevel_update_header(C, op);
		return OPERATOR_RUNNING_MODAL;
	}
	else {
		bool handled = false;
		switch (event->type) {
			case ESCKEY:
			case RIGHTMOUSE:
				edbm_bevel_cancel(C, op);
				return OPERATOR_CANCELLED;

			case MOUSEMOVE:
				if (!has_numinput) {
					edbm_bevel_mouse_set_value(op, event);
					edbm_bevel_calc(op);
					edbm_bevel_update_header(C, op);
					handled = true;
				}
				break;

			case LEFTMOUSE:
			case PADENTER:
			case RETKEY:
				if (event->val == KM_PRESS) {
					edbm_bevel_calc(op);
					edbm_bevel_exit(C, op);
					return OPERATOR_FINISHED;
				}
				break;

			case MOUSEPAN: {
				float delta = 0.02f * (event->y - event->prevy);
				if (opdata->segments >= 1 && opdata->segments + delta < 1)
					opdata->segments = 1;
				else
					opdata->segments += delta;
				RNA_int_set(op->ptr, "segments", (int)opdata->segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
			}

			/* Note this will prevent padplus and padminus to ever activate modal numinput.
			 * This is not really an issue though, as we only expect positive values here...
			 * Else we could force them to only modify segments number when shift is pressed, or so.
			 */

			case WHEELUPMOUSE:  /* change number of segments */
			case PADPLUSKEY:
				if (event->val == KM_RELEASE)
					break;

				opdata->segments = opdata->segments + 1;
				RNA_int_set(op->ptr, "segments", (int)opdata->segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;

			case WHEELDOWNMOUSE:  /* change number of segments */
			case PADMINUS:
				if (event->val == KM_RELEASE)
					break;

				opdata->segments = max_ff(opdata->segments - 1, 1);
				RNA_int_set(op->ptr, "segments", (int)opdata->segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;

			case MKEY:
				if (event->val == KM_RELEASE)
					break;

				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
					int type = RNA_property_enum_get(op->ptr, prop);
					type++;
					if (type > BEVEL_AMT_PERCENT) {
						type = BEVEL_AMT_OFFSET;
					}
					if (opdata->value_mode == OFFSET_VALUE && type == BEVEL_AMT_PERCENT)
						opdata->value_mode = OFFSET_VALUE_PERCENT;
					else if (opdata->value_mode == OFFSET_VALUE_PERCENT && type != BEVEL_AMT_PERCENT)
						opdata->value_mode = OFFSET_VALUE;
					RNA_property_enum_set(op->ptr, prop, type);
					if (opdata->initial_length[opdata->value_mode] == -1.0f)
						edbm_bevel_calc_initial_length(op, event, true);
				}
				/* Update offset accordingly to new offset_type. */
				if (!has_numinput &&
				    (opdata->value_mode == OFFSET_VALUE || opdata->value_mode == OFFSET_VALUE_PERCENT))
				{
					edbm_bevel_mouse_set_value(op, event);
				}		
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
			case CKEY:
				if (event->val == KM_RELEASE)
					break;

				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap");
					RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
				}
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
			case PKEY:
				if (event->val == KM_RELEASE)
					break;
				if (opdata->value_mode == PROFILE_VALUE) {
					opdata->value_mode = OFFSET_VALUE;
				}
				else {
					opdata->value_mode = PROFILE_VALUE;
				}
				edbm_bevel_calc_initial_length(op, event, true);
				break;
			case SKEY:
				if (event->val == KM_RELEASE)
					break;
				if (opdata->value_mode == SEGMENTS_VALUE) {
					opdata->value_mode = OFFSET_VALUE;
				}
				else {
					opdata->value_mode = SEGMENTS_VALUE;
				}
				edbm_bevel_calc_initial_length(op, event, true);
				break;
			case VKEY:
				if (event->val == KM_RELEASE)
					break;
				
				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only");
					RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
				}
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
				
		}

		/* Modal numinput inactive, try to handle numeric inputs last... */
		if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input[opdata->value_mode], event)) {
			edbm_bevel_numinput_set_value(op);
			edbm_bevel_calc(op);
			edbm_bevel_update_header(C, op);
			return OPERATOR_RUNNING_MODAL;
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
Esempio n. 6
0
static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
	PointerRNA ptr;
	PropertyRNA *prop;
	bool is_undo;
	FileBrowseOp *fbo;
	char *str;

	if (CTX_wm_space_file(C)) {
		BKE_report(op->reports, RPT_ERROR, "Cannot activate a file selector, one already open");
		return OPERATOR_CANCELLED;
	}

	UI_context_active_but_prop_get_filebrowser(C, &ptr, &prop, &is_undo);

	if (!prop)
		return OPERATOR_CANCELLED;

	str = RNA_property_string_get_alloc(&ptr, prop, NULL, 0, NULL);

	/* useful yet irritating feature, Shift+Click to open the file
	 * Alt+Click to browse a folder in the OS's browser */
	if (event->shift || event->alt) {
		wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
		PointerRNA props_ptr;

		if (event->alt) {
			char *lslash = (char *)BLI_last_slash(str);
			if (lslash)
				*lslash = '\0';
		}


		WM_operator_properties_create_ptr(&props_ptr, ot);
		RNA_string_set(&props_ptr, "filepath", str);
		WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr);
		WM_operator_properties_free(&props_ptr);

		MEM_freeN(str);
		return OPERATOR_CANCELLED;
	}
	else {
		PropertyRNA *prop_relpath;
		const char *path_prop = RNA_struct_find_property(op->ptr, "directory") ? "directory" : "filepath";
		fbo = MEM_callocN(sizeof(FileBrowseOp), "FileBrowseOp");
		fbo->ptr = ptr;
		fbo->prop = prop;
		fbo->is_undo = is_undo;
		op->customdata = fbo;

		RNA_string_set(op->ptr, path_prop, str);
		MEM_freeN(str);

		/* normally ED_fileselect_get_params would handle this but we need to because of stupid
		 * user-prefs exception - campbell */
		if ((prop_relpath = RNA_struct_find_property(op->ptr, "relative_path"))) {
			if (!RNA_property_is_set(op->ptr, prop_relpath)) {
				/* annoying exception!, if were dealing with the user prefs, default relative to be off */
				RNA_property_boolean_set(op->ptr, prop_relpath, U.flag & USER_RELPATHS && (ptr.data != &U));
			}
		}
		WM_event_add_fileselect(C, op);

		return OPERATOR_RUNNING_MODAL;
	}
}
Esempio n. 7
0
static int edbm_bevel_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
	BevelData *opdata = op->customdata;
	int segments = RNA_int_get(op->ptr, "segments");
	const bool has_numinput = hasNumInput(&opdata->num_input);

	/* Modal numinput active, try to handle numeric inputs first... */
	if (event->val == KM_PRESS && has_numinput && handleNumInput(C, &opdata->num_input, event)) {
		float value = RNA_float_get(op->ptr, "offset");
		applyNumInput(&opdata->num_input, &value);
		RNA_float_set(op->ptr, "offset", value);
		edbm_bevel_calc(op);
		edbm_bevel_update_header(C, op);
		return OPERATOR_RUNNING_MODAL;
	}
	else {
		bool handled = false;
		switch (event->type) {
			case ESCKEY:
			case RIGHTMOUSE:
				edbm_bevel_cancel(C, op);
				return OPERATOR_CANCELLED;

			case MOUSEMOVE:
				if (!has_numinput) {
					const float factor = edbm_bevel_mval_factor(op, event);
					RNA_float_set(op->ptr, "offset", factor);

					edbm_bevel_calc(op);
					edbm_bevel_update_header(C, op);
					handled = true;
				}
				break;

			case LEFTMOUSE:
			case PADENTER:
			case RETKEY:
				if (event->val == KM_PRESS) {
					edbm_bevel_calc(op);
					edbm_bevel_exit(C, op);
					return OPERATOR_FINISHED;
				}
				break;

			/* Note this will prevent padplus and padminus to ever activate modal numinput.
			 * This is not really an issue though, as we only expect positive values here...
			 * Else we could force them to only modify segments number when shift is pressed, or so.
			 */

			case WHEELUPMOUSE:  /* change number of segments */
			case PADPLUSKEY:
				if (event->val == KM_RELEASE)
					break;

				segments++;
				RNA_int_set(op->ptr, "segments", segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;

			case WHEELDOWNMOUSE:  /* change number of segments */
			case PADMINUS:
				if (event->val == KM_RELEASE)
					break;

				segments = max_ii(segments - 1, 1);
				RNA_int_set(op->ptr, "segments", segments);
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;

			case MKEY:
				if (event->val == KM_RELEASE)
					break;

				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
					int type = RNA_property_enum_get(op->ptr, prop);
					type++;
					if (type > BEVEL_AMT_PERCENT) {
						type = BEVEL_AMT_OFFSET;
					}
					RNA_property_enum_set(op->ptr, prop, type);
				}
				/* Update factor accordingly to new offset_type. */
				if (!has_numinput) {
					RNA_float_set(op->ptr, "offset", edbm_bevel_mval_factor(op, event));
				}
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
			case CKEY:
				if (event->val == KM_RELEASE)
					break;

				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "clamp_overlap");
					RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
				}
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
			case VKEY:
				if (event->val == KM_RELEASE)
					break;
				
				{
					PropertyRNA *prop = RNA_struct_find_property(op->ptr, "vertex_only");
					RNA_property_boolean_set(op->ptr, prop, !RNA_property_boolean_get(op->ptr, prop));
				}
				edbm_bevel_calc(op);
				edbm_bevel_update_header(C, op);
				handled = true;
				break;
				
		}

		/* Modal numinput inactive, try to handle numeric inputs last... */
		if (!handled && event->val == KM_PRESS && handleNumInput(C, &opdata->num_input, event)) {
			float value = RNA_float_get(op->ptr, "offset");
			applyNumInput(&opdata->num_input, &value);
			RNA_float_set(op->ptr, "offset", value);
			edbm_bevel_calc(op);
			edbm_bevel_update_header(C, op);
			return OPERATOR_RUNNING_MODAL;
		}
	}

	return OPERATOR_RUNNING_MODAL;
}
Esempio n. 8
0
/* helper for apply() - perform sliding for custom properties or bbone properties */
static void pose_slide_apply_props(tPoseSlideOp *pso, tPChanFCurveLink *pfl, const char prop_prefix[])
{
	PointerRNA ptr = {{NULL}};
	LinkData *ld;
	int len = strlen(pfl->pchan_path);
	
	/* setup pointer RNA for resolving paths */
	RNA_pointer_create(NULL, &RNA_PoseBone, pfl->pchan, &ptr);
	
	/* - custom properties are just denoted using ["..."][etc.] after the end of the base path, 
	 *   so just check for opening pair after the end of the path
	 * - bbone properties are similar, but they always start with a prefix "bbone_*",
	 *   so a similar method should work here for those too
	 */
	for (ld = pfl->fcurves.first; ld; ld = ld->next) {
		FCurve *fcu = (FCurve *)ld->data;
		const char *bPtr, *pPtr;
		
		if (fcu->rna_path == NULL)
			continue;
		
		/* do we have a match? 
		 *	- bPtr is the RNA Path with the standard part chopped off
		 *	- pPtr is the chunk of the path which is left over
		 */
		bPtr = strstr(fcu->rna_path, pfl->pchan_path) + len;
		pPtr = strstr(bPtr, prop_prefix);
		
		if (pPtr) {
			/* use RNA to try and get a handle on this property, then, assuming that it is just
			 * numerical, try and grab the value as a float for temp editing before setting back
			 */
			PropertyRNA *prop = RNA_struct_find_property(&ptr, pPtr);
			
			if (prop) {
				switch (RNA_property_type(prop)) {
					/* continuous values that can be smoothly interpolated... */
					case PROP_FLOAT:
					{
						float tval = RNA_property_float_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_float_set(&ptr, prop, tval);
						break;
					}
					case PROP_INT:
					{
						float tval = (float)RNA_property_int_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_int_set(&ptr, prop, (int)tval);
						break;
					}
					
					/* values which can only take discrete values */
					case PROP_BOOLEAN:
					{
						float tval = (float)RNA_property_boolean_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_boolean_set(&ptr, prop, (int)tval); // XXX: do we need threshold clamping here?
						break;
					}
					case PROP_ENUM:
					{
						/* don't handle this case - these don't usually represent interchangeable
						 * set of values which should be interpolated between
						 */
						break;
					}
					
					default:
						/* cannot handle */
						//printf("Cannot Pose Slide non-numerical property\n");
						break;
				}
			}
		}
	}
}