Example #1
0
bool
Layer_Composite::set_param(const String & param, const ValueBase &value)
{
	if(param=="amount" && value.same_type_as(amount))
	{
		amount=value.get(amount);
		set_param_static(param,value.get_static());
	}
	else
	if(param=="blend_method" && value.same_type_as(int()))
	{
		blend_method = static_cast<Color::BlendMethod>(value.get(int()));
		set_param_static(param,value.get_static());

		if (blend_method < 0 || blend_method >= Color::BLEND_END)
		{
			warning("illegal value (%d) for blend_method - using Composite instead", blend_method);
			blend_method = Color::BLEND_COMPOSITE;
			return false;
		}

		if (blend_method == Color::BLEND_STRAIGHT && !reads_context())
		{
			Canvas::Handle canvas(get_canvas());
			if (canvas)
			{
				String version(canvas->get_version());

				if (version == "0.1" || version == "0.2")
				{
					if (get_name() == "PasteCanvas")
						warning("loaded a version %s canvas with a 'Straight' blended PasteCanvas (%s) - check it renders OK",
								version.c_str(), get_non_empty_description().c_str());
					else
					{
						blend_method = Color::BLEND_COMPOSITE;
						converted_blend_ = true;

						// if this layer has a transparent color, go back and set the color again
						// now that we know we are converting the blend method as well.  that will
						// make the color non-transparent, and change the blend method to alpha over
						if (transparent_color_)
							set_param("color", get_param("color"));
					}
				}
			}
		}
	}
	else
		return Layer::set_param(param,value);
	return true;
}
Example #2
0
bool
Star::set_param(const String & param, const ValueBase &value)
{
	if(	param=="radius1" && value.same_type_as(radius1))
	{
		value.put(&radius1);
		sync();
		set_param_static(param, value.get_static());
		return true;
	}

	if(	param=="radius2" && value.same_type_as(radius2))
	{
		value.put(&radius2);
		sync();
		set_param_static(param, value.get_static());
		return true;
	}

	if(	param=="points" && value.same_type_as(points))
	{
		value.put(&points);
		if(points<2)points=2;
		sync();
		set_param_static(param, value.get_static());
		return true;
	}

	if(	param=="angle" && value.same_type_as(angle))
	{
		value.put(&angle);
		sync();
		set_param_static(param, value.get_static());
		return true;
	}

	if(param=="regular_polygon" && value.same_type_as(regular_polygon))
	{
		value.put(&regular_polygon);
		sync();
		set_param_static(param, value.get_static());
		return true;
	}

	if(param=="vector_list")
		return false;

	return Layer_Polygon::set_param(param,value);
}
Example #3
0
bool
Layer_PasteCanvas::set_param(const String & param, const ValueBase &value)
{
	IMPORT_VALUE(param_origin);
	IMPORT_VALUE(param_focus);

	// IMPORT(canvas);
	if(param=="canvas" && value.same_type_as(Canvas::Handle()))
	{
		set_sub_canvas(value.get(Canvas::Handle()));
		return true;
	}
	//! \todo this introduces bug 1844764 if enabled; it was introduced in r954.
	// http://synfig.org/images/3/3d/Moving-waypoints.sifz is an
	// example of an animation that has its waypoints displayed
	// incorrectly without this fix; select the outer layer and drag
	// the time slider.  The linear waypoints don't take effect until
	// 5s, but the time slider appears to pass the first one at 3s.
#if 0
	if (param=="time_offset" && value.same_type_as(time_offset))
	{
		if (time_offset != value.get(Time()))
		{
			value.put(&time_offset);
			// notify that the time_offset has changed so we can update the
			// waypoint positions in parent layers
			changed();
		}
		return true;
	}
#else
	IMPORT_VALUE(param_time_offset);
#endif

	IMPORT_VALUE(param_children_lock);
	IMPORT_VALUE(param_zoom);
	IMPORT_VALUE(param_outline_grow);
	IMPORT_VALUE(param_curr_time);
	IMPORT_VALUE(param_z_range);
	IMPORT_VALUE(param_z_range_position);
	IMPORT_VALUE(param_z_range_depth);
	IMPORT_VALUE(param_z_range_blur);
	return Layer_Composite::set_param(param,value);
}
Example #4
0
bool
Instance::save_as(const synfig::String &file_name)
{
	save_canvas_into_container_ = false;
	bool embed_data = false;
	bool extract_data = false;
	std::string canvas_filename = file_name;

	// save all layers
	std::set<Layer::Handle> layers_to_save_set;
	for(std::list<Layer::Handle>::iterator i = layers_to_save.begin(); i != layers_to_save.end(); i++)
		layers_to_save_set.insert(*i);
	for(std::set<Layer::Handle>::iterator i = layers_to_save_set.begin(); i != layers_to_save_set.end(); i++)
	{
		etl::handle<Layer_Bitmap> layer_bitmap = etl::handle<Layer_Bitmap>::cast_dynamic(*i);
		if (!layer_bitmap) continue;
		if (!layer_bitmap->get_canvas()) continue;
		if (!(*i)->get_param_list().count("filename")) continue;
		ValueBase value = (*i)->get_param("filename");
		if (!value.same_type_as(String())) continue;
		String filename = value.get(String());
		// TODO: literals '#' and 'images/'
		if (!filename.empty() && filename[0] == '#')
			filename.insert(1, "images/");
		save_surface(layer_bitmap->surface, filename);
	}

	if (filename_extension(file_name) == ".sfg")
	{
		save_canvas_reference_directory_ = "#images/";
		save_canvas_reference_local_directory_ = "#images/";
		canvas_filename = "#project.sifz";
		save_canvas_into_container_ = true;
		embed_data = filename_extension(get_canvas()->get_file_name()) != ".sfg";
	} else
	{
		save_canvas_reference_directory_ =
			filename_sans_extension(file_name)
		  + ".images"
		  + ETL_DIRECTORY_SEPARATOR;
		save_canvas_reference_local_directory_ =
			filename_sans_extension(basename(file_name))
		  + ".images"
		  + ETL_DIRECTORY_SEPARATOR;
		extract_data = filename_extension(get_canvas()->get_file_name()) == ".sfg";
	}

	if (embed_data) import_external_canvases();

	bool ret;

	String old_file_name(get_file_name());

	set_file_name(file_name);
	get_canvas()->set_identifier(file_system_->get_identifier(canvas_filename));

	if (embed_data || extract_data)
		set_save_canvas_external_file_callback(save_canvas_callback, this);
	else
		set_save_canvas_external_file_callback(NULL, NULL);

	ret = save_canvas(file_system_->get_identifier(canvas_filename),canvas_,!save_canvas_into_container_);

	if (ret && save_canvas_into_container_)
	   ret = container_->save_changes(file_name, false);

	if (ret && (embed_data || extract_data))
		update_references_in_canvas(get_canvas());
	set_save_canvas_external_file_callback(NULL, NULL);
	save_canvas_references_.clear();

	if(ret)
	{
		reset_action_count();
		signal_saved_();
	}
	else
		set_file_name(old_file_name);

	signal_filename_changed_();

	return ret;
}