1 /* === S Y N F I G ========================================================= */
2 /*! \file state_normal.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "state_normal.h"
35 #include "event_mouse.h"
36 #include "event_layerclick.h"
38 #include "dialog_tooloptions.h"
39 #include <gtkmm/dialog.h>
40 #include "widget_waypointmodel.h"
41 #include <synfig/valuenode_animated.h>
42 #include <synfig/valuenode_composite.h>
43 #include <synfig/valuenode_const.h>
44 #include "canvasview.h"
49 /* === U S I N G =========================================================== */
53 using namespace synfig;
54 using namespace studio;
56 /* === M A C R O S ========================================================= */
58 /* === C L A S S E S & S T R U C T S ======================================= */
60 class studio::StateNormal_Context : public sigc::trackable
62 CanvasView *canvas_view;
64 CanvasView* get_canvas_view() { return canvas_view; }
65 Canvas::Handle get_canvas() { return canvas_view->get_canvas(); }
66 WorkArea* get_work_area() { return canvas_view->get_work_area(); }
67 etl::handle<synfigapp::CanvasInterface> get_canvas_interface() { return canvas_view->canvas_interface(); }
70 StateNormal_Context(CanvasView *canvas_view);
71 ~StateNormal_Context();
73 Smach::event_result event_stop_handler(const Smach::event& x);
75 Smach::event_result event_refresh_handler(const Smach::event& x);
77 Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
79 Smach::event_result event_undo_handler(const Smach::event& x);
81 Smach::event_result event_redo_handler(const Smach::event& x);
83 Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
85 Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
87 Smach::event_result event_refresh_tool_options(const Smach::event& x);
89 Smach::event_result event_layer_click(const Smach::event& x);
91 void edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list);
93 void refresh_tool_options();
94 }; // END of class StateNormal_Context
96 /* === G L O B A L S ======================================================= */
98 StateNormal studio::state_normal;
100 /* === P R O C E D U R E S ================================================= */
102 /* === M E T H O D S ======================================================= */
104 StateNormal::StateNormal():
105 Smach::state<StateNormal_Context>("normal")
107 insert(event_def(EVENT_STOP,&StateNormal_Context::event_stop_handler));
108 insert(event_def(EVENT_REFRESH,&StateNormal_Context::event_refresh_handler));
109 insert(event_def(EVENT_REFRESH_DUCKS,&StateNormal_Context::event_refresh_ducks_handler));
110 insert(event_def(EVENT_UNDO,&StateNormal_Context::event_undo_handler));
111 insert(event_def(EVENT_REDO,&StateNormal_Context::event_redo_handler));
112 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateNormal_Context::event_mouse_button_down_handler));
113 insert(event_def(EVENT_WORKAREA_MULTIPLE_DUCKS_CLICKED,&StateNormal_Context::event_multiple_ducks_clicked_handler));
114 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateNormal_Context::event_refresh_tool_options));
115 insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateNormal_Context::event_layer_click));
118 StateNormal::~StateNormal()
122 StateNormal_Context::StateNormal_Context(CanvasView *canvas_view):
123 canvas_view(canvas_view)
125 // synfig::info("Entered Normal State");
128 StateNormal_Context::~StateNormal_Context()
130 // synfig::info("Left Normal State");
134 StateNormal_Context::refresh_tool_options()
136 App::dialog_tool_options->clear();
137 App::dialog_tool_options->set_name("normal");
141 StateNormal_Context::event_refresh_tool_options(const Smach::event& /*x*/)
143 refresh_tool_options();
144 return Smach::RESULT_ACCEPT;
148 StateNormal_Context::event_stop_handler(const Smach::event& /*x*/)
150 // synfig::info("STATE NORMAL: Received Stop Event");
152 return Smach::RESULT_ACCEPT;
156 StateNormal_Context::event_refresh_handler(const Smach::event& /*x*/)
158 // synfig::info("STATE NORMAL: Received Refresh Event");
159 canvas_view->rebuild_tables();
160 canvas_view->work_area->queue_render_preview();
161 return Smach::RESULT_ACCEPT;
165 StateNormal_Context::event_refresh_ducks_handler(const Smach::event& /*x*/)
167 // synfig::info("STATE NORMAL: Received Refresh Ducks");
168 canvas_view->queue_rebuild_ducks();
169 return Smach::RESULT_ACCEPT;
173 StateNormal_Context::event_undo_handler(const Smach::event& /*x*/)
175 // synfig::info("STATE NORMAL: Received Undo Event");
176 canvas_view->get_instance()->undo();
177 return Smach::RESULT_ACCEPT;
181 StateNormal_Context::event_redo_handler(const Smach::event& /*x*/)
183 // synfig::info("STATE NORMAL: Received Redo Event");
184 canvas_view->get_instance()->redo();
185 return Smach::RESULT_ACCEPT;
189 StateNormal_Context::event_mouse_button_down_handler(const Smach::event& x)
191 // synfig::info("STATE NORMAL: Received mouse button down Event");
193 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
198 canvas_view->popup_main_menu();
199 return Smach::RESULT_ACCEPT;
201 return Smach::RESULT_OK;
206 StateNormal_Context::event_layer_click(const Smach::event& x)
208 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
212 // synfig::info("STATE NORMAL: Received layer click Event, \"%s\"",event.layer->get_name().c_str());
216 // synfig::info("STATE NORMAL: Received layer click Event with an empty layer.");
222 if(!(event.modifier&Gdk::CONTROL_MASK))
223 canvas_view->get_selection_manager()->clear_selected_layers();
226 std::list<Layer::Handle> layer_list(canvas_view->get_selection_manager()->get_selected_layers());
227 std::set<Layer::Handle> layers(layer_list.begin(),layer_list.end());
228 if(layers.count(event.layer))
230 layers.erase(event.layer);
231 layer_list=std::list<Layer::Handle>(layers.begin(),layers.end());
232 canvas_view->get_selection_manager()->clear_selected_layers();
233 canvas_view->get_selection_manager()->set_selected_layers(layer_list);
237 canvas_view->get_selection_manager()->set_selected_layer(event.layer);
240 return Smach::RESULT_ACCEPT;
242 canvas_view->popup_layer_menu(event.layer);
243 return Smach::RESULT_ACCEPT;
245 return Smach::RESULT_OK;
251 StateNormal_Context::edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list)
254 "Edit Multiple Waypoints", // Title
256 true // use_separator
259 Widget_WaypointModel widget_waypoint_model;
260 widget_waypoint_model.show();
262 dialog.get_vbox()->pack_start(widget_waypoint_model);
265 dialog.add_button(Gtk::StockID("gtk-apply"),1);
266 dialog.add_button(Gtk::StockID("gtk-cancel"),0);
271 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Set Waypoints"));
273 std::list<synfigapp::ValueDesc>::iterator iter;
274 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
276 synfigapp::ValueDesc value_desc(*iter);
278 if(!value_desc.is_valid())
281 ValueNode_Animated::Handle value_node;
283 // If this value isn't a ValueNode_Animated, but
284 // it is somewhat constant, then go ahead and convert
285 // it to a ValueNode_Animated.
286 if(!value_desc.is_value_node() || ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
289 if(value_desc.is_value_node())
290 value=ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node())->get_value();
292 value=value_desc.get_value();
294 value_node=ValueNode_Animated::create(value,get_canvas()->get_time());
296 synfigapp::Action::Handle action;
298 if(!value_desc.is_value_node())
300 action=synfigapp::Action::create("value_desc_connect");
301 action->set_param("dest",value_desc);
302 action->set_param("src",ValueNode::Handle(value_node));
306 action=synfigapp::Action::create("value_node_replace");
307 action->set_param("dest",value_desc.get_value_node());
308 action->set_param("src",ValueNode::Handle(value_node));
311 action->set_param("canvas",get_canvas());
312 action->set_param("canvas_interface",get_canvas_interface());
315 if(!get_canvas_interface()->get_instance()->perform_action(action))
317 get_canvas_view()->get_ui_interface()->error(_("Unable to convert to animated waypoint"));
324 if(value_desc.is_value_node())
325 value_node=ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node());
332 synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set_smart"));
336 get_canvas_view()->get_ui_interface()->error(_("Unable to find waypoint_set_smart action"));
342 action->set_param("canvas",get_canvas());
343 action->set_param("canvas_interface",get_canvas_interface());
344 action->set_param("value_node",ValueNode::Handle(value_node));
345 action->set_param("time",get_canvas()->get_time());
346 action->set_param("model",widget_waypoint_model.get_waypoint_model());
348 if(!get_canvas_interface()->get_instance()->perform_action(action))
350 get_canvas_view()->get_ui_interface()->error(_("Unable to set a specific waypoint"));
357 //get_canvas_view()->get_ui_interface()->error(_("Unable to animate a specific valuedesc"));
367 StateNormal_Context::event_multiple_ducks_clicked_handler(const Smach::event& /*x*/)
369 // synfig::info("STATE NORMAL: Received multiple duck click event");
371 //const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
373 std::list<synfigapp::ValueDesc> value_desc_list;
375 // Create a list of value_descs associated with selection
376 const DuckList selected_ducks(get_work_area()->get_selected_ducks());
377 DuckList::const_iterator iter;
378 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
380 synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
382 if(!value_desc.is_valid())
385 if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
387 value_desc_list.push_back(
388 synfigapp::ValueDesc(
389 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())
395 value_desc_list.push_back(value_desc);
398 Gtk::Menu *menu=manage(new Gtk::Menu());
399 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
401 canvas_view->get_instance()->make_param_menu(menu,canvas_view->get_canvas(),value_desc_list);
404 synfigapp::Action::ParamList param_list;
405 param_list=get_canvas_interface()->generate_param_list(value_desc_list);
407 canvas_view->add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
409 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Edit Waypoints"),
413 &studio::StateNormal_Context::edit_several_waypoints
419 menu->popup(3,gtk_get_current_event_time());
421 return Smach::RESULT_ACCEPT;