From e1f3cb22be90099ebb28f2638cf0472ff93486c1 Mon Sep 17 00:00:00 2001 From: gballintijn Date: Sat, 21 Feb 2009 13:56:32 +0000 Subject: [PATCH] #2579838: Apply default fore- or background color to multiple layers This patch implements the application of the "apply default color" popup menu in the parameter panel in the case that multiple layers are selected. Allowing the animator to change the color of multiple layers at once. It also extends this ability to applying either the foreground color or the background color. git-svn-id: https://synfig.svn.sourceforge.net/svnroot/synfig@2347 1f10aa63-cdf2-0310-b900-c93c546f37ac --- synfig-studio/trunk/src/synfigapp/action.cpp | 3 +- .../trunk/src/synfigapp/actions/colorset.cpp | 95 ++++++++++++++-------- .../trunk/src/synfigapp/actions/colorset.h | 25 +++++- 3 files changed, 87 insertions(+), 36 deletions(-) diff --git a/synfig-studio/trunk/src/synfigapp/action.cpp b/synfig-studio/trunk/src/synfigapp/action.cpp index 7379d33..d3b4393 100644 --- a/synfig-studio/trunk/src/synfigapp/action.cpp +++ b/synfig-studio/trunk/src/synfigapp/action.cpp @@ -226,7 +226,8 @@ Action::Main::Main() ADD_ACTION(Action::BLinePointTangentSplit); ADD_ACTION(Action::GradientSet); - ADD_ACTION(Action::ColorSet); + ADD_ACTION(Action::ColorSetFromFG); + ADD_ACTION(Action::ColorSetFromBG); ADD_ACTION(Action::TimepointsMove); ADD_ACTION(Action::TimepointsCopy); diff --git a/synfig-studio/trunk/src/synfigapp/actions/colorset.cpp b/synfig-studio/trunk/src/synfigapp/actions/colorset.cpp index a280858..55bae1d 100644 --- a/synfig-studio/trunk/src/synfigapp/actions/colorset.cpp +++ b/synfig-studio/trunk/src/synfigapp/actions/colorset.cpp @@ -50,14 +50,23 @@ using namespace Action; /* === M A C R O S ========================================================= */ -ACTION_INIT(Action::ColorSet); -ACTION_SET_NAME(Action::ColorSet,"ColorSet"); -ACTION_SET_LOCAL_NAME(Action::ColorSet,N_("Apply Default Color")); -ACTION_SET_TASK(Action::ColorSet,"set"); -ACTION_SET_CATEGORY(Action::ColorSet,Action::CATEGORY_VALUEDESC); -ACTION_SET_PRIORITY(Action::ColorSet,0); -ACTION_SET_VERSION(Action::ColorSet,"0.0"); -ACTION_SET_CVS_ID(Action::ColorSet,"$Id$"); +ACTION_INIT(Action::ColorSetFromFG); +ACTION_SET_NAME(Action::ColorSetFromFG, "ColorSetFromFG"); +ACTION_SET_LOCAL_NAME(Action::ColorSetFromFG, N_("Apply Foreground Color")); +ACTION_SET_TASK(Action::ColorSetFromFG, "set"); +ACTION_SET_CATEGORY(Action::ColorSetFromFG, Action::CATEGORY_VALUEDESC); +ACTION_SET_PRIORITY(Action::ColorSetFromFG, 0); +ACTION_SET_VERSION(Action::ColorSetFromFG, "0.0"); +ACTION_SET_CVS_ID(Action::ColorSetFromFG, "$Id$"); + +ACTION_INIT(Action::ColorSetFromBG); +ACTION_SET_NAME(Action::ColorSetFromBG, "ColorSetFromBG"); +ACTION_SET_LOCAL_NAME(Action::ColorSetFromBG, N_("Apply Background Color")); +ACTION_SET_TASK(Action::ColorSetFromBG, "set"); +ACTION_SET_CATEGORY(Action::ColorSetFromBG, Action::CATEGORY_VALUEDESC); +ACTION_SET_PRIORITY(Action::ColorSetFromBG, 0); +ACTION_SET_VERSION(Action::ColorSetFromBG, "0.0"); +ACTION_SET_CVS_ID(Action::ColorSetFromBG, "$Id$"); /* === G L O B A L S ======================================================= */ @@ -65,8 +74,8 @@ ACTION_SET_CVS_ID(Action::ColorSet,"$Id$"); /* === M E T H O D S ======================================================= */ -Action::ColorSet::ColorSet(): - time(0) +Action::ColorSet::ColorSet(bool use_fg_color): + time(0), use_fg_color(use_fg_color) { } @@ -77,6 +86,7 @@ Action::ColorSet::get_param_vocab() ret.push_back(ParamDesc("value_desc",Param::TYPE_VALUEDESC) .set_local_name(_("ValueDesc")) + .set_supports_multiple() ); ret.push_back(ParamDesc("time",Param::TYPE_TIME) @@ -90,40 +100,57 @@ Action::ColorSet::get_param_vocab() bool Action::ColorSet::is_candidate(const ParamList &x) { - if(!candidate_check(get_param_vocab(),x)) + if (!candidate_check(get_param_vocab(), x)) return false; - return x.find("value_desc")->second.get_value_desc().get_value_type()==ValueBase::TYPE_COLOR; + + std::multimap::const_iterator iter; + for (iter = x.begin(); iter != x.end(); ++iter) + { + if (iter->first == "value_desc" && + iter->second.get_value_desc().get_value_type() != ValueBase::TYPE_COLOR) + return false; + } + + return true; } bool Action::ColorSet::set_param(const synfig::String& name, const Action::Param ¶m) { - if(name=="value_desc" && param.get_type()==Param::TYPE_VALUEDESC) + if (name == "value_desc" && param.get_type() == Param::TYPE_VALUEDESC) { // Grab the value_desc - value_desc=param.get_value_desc(); + ValueDesc value_desc = param.get_value_desc(); + if (value_desc.get_value_type() != ValueBase::TYPE_COLOR) + return false; + + value_desc_list.push_back(value_desc); - // Grab the current color - color=synfigapp::Main::get_foreground_color(); + // Grab the current fore- or background color + if (use_fg_color) + color = synfigapp::Main::get_foreground_color(); + else + color = synfigapp::Main::get_background_color(); - return value_desc.get_value_type()==ValueBase::TYPE_COLOR; + return true; } - if(name=="time" && param.get_type()==Param::TYPE_TIME) + if (name == "time" && param.get_type() == Param::TYPE_TIME) { - time=param.get_time(); + time = param.get_time(); return true; } - return Action::CanvasSpecific::set_param(name,param); + return Action::CanvasSpecific::set_param(name, param); } bool -Action::ColorSet::is_ready()const +Action::ColorSet::is_ready() const { - if(!value_desc || value_desc.get_value_type()!=ValueBase::TYPE_COLOR) + if (value_desc_list.size() == 0) return false; + return Action::CanvasSpecific::is_ready(); } @@ -132,17 +159,21 @@ Action::ColorSet::prepare() { clear(); - Action::Handle action; - action=Action::create("ValueDescSet"); + std::list::iterator iter; + for (iter = value_desc_list.begin(); iter != value_desc_list.end(); ++iter) + { + ValueDesc& value_desc(*iter); - action->set_param("canvas",get_canvas()); - action->set_param("canvas_interface",get_canvas_interface()); - action->set_param("value_desc",value_desc); - action->set_param("new_value",ValueBase(color)); - action->set_param("time",time); + Action::Handle action = Action::create("ValueDescSet"); + action->set_param("canvas", get_canvas()); + action->set_param("canvas_interface", get_canvas_interface()); + action->set_param("value_desc", value_desc); + action->set_param("new_value", ValueBase(color)); + action->set_param("time", time); - if(!action->is_ready()) - throw Error(Error::TYPE_NOTREADY); + if (!action->is_ready()) + throw Error(Error::TYPE_NOTREADY); - add_action_front(action); + add_action_front(action); + } } diff --git a/synfig-studio/trunk/src/synfigapp/actions/colorset.h b/synfig-studio/trunk/src/synfigapp/actions/colorset.h index 15e0c90..6462ffa 100644 --- a/synfig-studio/trunk/src/synfigapp/actions/colorset.h +++ b/synfig-studio/trunk/src/synfigapp/actions/colorset.h @@ -46,23 +46,42 @@ class ColorSet : { private: - ValueDesc value_desc; + std::list value_desc_list; synfig::Color color; synfig::Time time; + bool use_fg_color; public: - ColorSet(); + ColorSet(bool use_fg_color); static ParamVocab get_param_vocab(); static bool is_candidate(const ParamList &x); virtual bool set_param(const synfig::String& name, const Param &); - virtual bool is_ready()const; + virtual bool is_ready() const; virtual void prepare(); +}; + +class ColorSetFromFG : public ColorSet +{ +public: + + ColorSetFromFG() : ColorSet(true) {} + + ACTION_MODULE_EXT + +}; + +class ColorSetFromBG : public ColorSet +{ +public: + + ColorSetFromBG() : ColorSet(false) {} ACTION_MODULE_EXT + }; }; // END of namespace action -- 2.7.4