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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "state_normal.h"
34 #include "event_mouse.h"
35 #include "event_layerclick.h"
37 #include "dialog_tooloptions.h"
38 #include <gtkmm/dialog.h>
39 #include "widget_waypointmodel.h"
40 #include <synfig/valuenode_animated.h>
41 #include <synfig/valuenode_composite.h>
42 #include <synfig/valuenode_const.h>
43 #include "canvasview.h"
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === C L A S S E S & S T R U C T S ======================================= */
59 class studio::StateNormal_Context : public sigc::trackable
61 CanvasView *canvas_view;
63 CanvasView* get_canvas_view() { return canvas_view; }
64 Canvas::Handle get_canvas() { return canvas_view->get_canvas(); }
65 WorkArea* get_work_area() { return canvas_view->get_work_area(); }
66 etl::handle<synfigapp::CanvasInterface> get_canvas_interface() { return canvas_view->canvas_interface(); }
69 StateNormal_Context(CanvasView *canvas_view);
70 ~StateNormal_Context();
72 Smach::event_result event_stop_handler(const Smach::event& x);
74 Smach::event_result event_refresh_handler(const Smach::event& x);
76 Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
78 Smach::event_result event_undo_handler(const Smach::event& x);
80 Smach::event_result event_redo_handler(const Smach::event& x);
82 Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
84 Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
86 Smach::event_result event_refresh_tool_options(const Smach::event& x);
88 Smach::event_result event_layer_click(const Smach::event& x);
90 void edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list);
92 void refresh_tool_options();
93 }; // END of class StateNormal_Context
95 /* === G L O B A L S ======================================================= */
97 StateNormal studio::state_normal;
99 /* === P R O C E D U R E S ================================================= */
101 /* === M E T H O D S ======================================================= */
103 StateNormal::StateNormal():
104 Smach::state<StateNormal_Context>("normal")
106 insert(event_def(EVENT_STOP,&StateNormal_Context::event_stop_handler));
107 insert(event_def(EVENT_REFRESH,&StateNormal_Context::event_refresh_handler));
108 insert(event_def(EVENT_REFRESH_DUCKS,&StateNormal_Context::event_refresh_ducks_handler));
109 insert(event_def(EVENT_UNDO,&StateNormal_Context::event_undo_handler));
110 insert(event_def(EVENT_REDO,&StateNormal_Context::event_redo_handler));
111 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateNormal_Context::event_mouse_button_down_handler));
112 insert(event_def(EVENT_WORKAREA_MULTIPLE_DUCKS_CLICKED,&StateNormal_Context::event_multiple_ducks_clicked_handler));
113 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateNormal_Context::event_refresh_tool_options));
114 insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateNormal_Context::event_layer_click));
117 StateNormal::~StateNormal()
121 StateNormal_Context::StateNormal_Context(CanvasView *canvas_view):
122 canvas_view(canvas_view)
124 synfig::info("Entered Normal State");
127 StateNormal_Context::~StateNormal_Context()
129 synfig::info("Left Normal State");
133 StateNormal_Context::refresh_tool_options()
135 App::dialog_tool_options->clear();
136 App::dialog_tool_options->set_name("normal");
140 StateNormal_Context::event_refresh_tool_options(const Smach::event& /*x*/)
142 refresh_tool_options();
143 return Smach::RESULT_ACCEPT;
147 StateNormal_Context::event_stop_handler(const Smach::event& /*x*/)
149 // synfig::info("STATE NORMAL: Received Stop Event");
151 return Smach::RESULT_ACCEPT;
155 StateNormal_Context::event_refresh_handler(const Smach::event& /*x*/)
157 // synfig::info("STATE NORMAL: Received Refresh Event");
158 canvas_view->rebuild_tables();
159 canvas_view->work_area->queue_render_preview();
160 return Smach::RESULT_ACCEPT;
164 StateNormal_Context::event_refresh_ducks_handler(const Smach::event& /*x*/)
166 // synfig::info("STATE NORMAL: Received Refresh Ducks");
167 canvas_view->queue_rebuild_ducks();
168 return Smach::RESULT_ACCEPT;
172 StateNormal_Context::event_undo_handler(const Smach::event& /*x*/)
174 // synfig::info("STATE NORMAL: Received Undo Event");
175 canvas_view->get_instance()->undo();
176 return Smach::RESULT_ACCEPT;
180 StateNormal_Context::event_redo_handler(const Smach::event& /*x*/)
182 // synfig::info("STATE NORMAL: Received Redo Event");
183 canvas_view->get_instance()->redo();
184 return Smach::RESULT_ACCEPT;
188 StateNormal_Context::event_mouse_button_down_handler(const Smach::event& x)
190 // synfig::info("STATE NORMAL: Received mouse button down Event");
192 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
197 canvas_view->popup_main_menu();
198 return Smach::RESULT_ACCEPT;
200 return Smach::RESULT_OK;
205 StateNormal_Context::event_layer_click(const Smach::event& x)
207 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
211 // synfig::info("STATE NORMAL: Received layer click Event, \"%s\"",event.layer->get_name().c_str());
215 // synfig::info("STATE NORMAL: Received layer click Event with an empty layer.");
221 if(!(event.modifier&Gdk::CONTROL_MASK))
222 canvas_view->get_selection_manager()->clear_selected_layers();
225 std::list<Layer::Handle> layer_list(canvas_view->get_selection_manager()->get_selected_layers());
226 std::set<Layer::Handle> layers(layer_list.begin(),layer_list.end());
227 if(layers.count(event.layer))
229 layers.erase(event.layer);
230 layer_list=std::list<Layer::Handle>(layers.begin(),layers.end());
231 canvas_view->get_selection_manager()->clear_selected_layers();
232 canvas_view->get_selection_manager()->set_selected_layers(layer_list);
236 canvas_view->get_selection_manager()->set_selected_layer(event.layer);
239 return Smach::RESULT_ACCEPT;
241 canvas_view->popup_layer_menu(event.layer);
242 return Smach::RESULT_ACCEPT;
244 return Smach::RESULT_OK;
250 StateNormal_Context::edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list)
253 "Edit Multiple Waypoints", // Title
255 true // use_separator
258 Widget_WaypointModel widget_waypoint_model;
259 widget_waypoint_model.show();
261 dialog.get_vbox()->pack_start(widget_waypoint_model);
264 dialog.add_button(Gtk::StockID("gtk-apply"),1);
265 dialog.add_button(Gtk::StockID("gtk-cancel"),0);
270 synfigapp::Action::PassiveGrouper group(get_canvas_interface()->get_instance().get(),_("Set Waypoints"));
272 std::list<synfigapp::ValueDesc>::iterator iter;
273 for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
275 synfigapp::ValueDesc value_desc(*iter);
277 if(!value_desc.is_valid())
280 ValueNode_Animated::Handle value_node;
282 // If this value isn't a ValueNode_Animated, but
283 // it is somewhat constant, then go ahead and convert
284 // it to a ValueNode_Animated.
285 if(!value_desc.is_value_node() || ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node()))
288 if(value_desc.is_value_node())
289 value=ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node())->get_value();
291 value=value_desc.get_value();
293 value_node=ValueNode_Animated::create(value,get_canvas()->get_time());
295 synfigapp::Action::Handle action;
297 if(!value_desc.is_value_node())
299 action=synfigapp::Action::create("value_desc_connect");
300 action->set_param("dest",value_desc);
301 action->set_param("src",ValueNode::Handle(value_node));
305 action=synfigapp::Action::create("value_node_replace");
306 action->set_param("dest",value_desc.get_value_node());
307 action->set_param("src",ValueNode::Handle(value_node));
310 action->set_param("canvas",get_canvas());
311 action->set_param("canvas_interface",get_canvas_interface());
314 if(!get_canvas_interface()->get_instance()->perform_action(action))
316 get_canvas_view()->get_ui_interface()->error(_("Unable to convert to animated waypoint"));
323 if(value_desc.is_value_node())
324 value_node=ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node());
331 synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set_smart"));
335 get_canvas_view()->get_ui_interface()->error(_("Unable to find waypoint_set_smart action"));
341 action->set_param("canvas",get_canvas());
342 action->set_param("canvas_interface",get_canvas_interface());
343 action->set_param("value_node",ValueNode::Handle(value_node));
344 action->set_param("time",get_canvas()->get_time());
345 action->set_param("model",widget_waypoint_model.get_waypoint_model());
347 if(!get_canvas_interface()->get_instance()->perform_action(action))
349 get_canvas_view()->get_ui_interface()->error(_("Unable to set a specific waypoint"));
356 //get_canvas_view()->get_ui_interface()->error(_("Unable to animate a specific valuedesc"));
366 StateNormal_Context::event_multiple_ducks_clicked_handler(const Smach::event& /*x*/)
368 // synfig::info("STATE NORMAL: Received multiple duck click event");
370 //const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
372 std::list<synfigapp::ValueDesc> value_desc_list;
374 // Create a list of value_descs associated with selection
375 const DuckList selected_ducks(get_work_area()->get_selected_ducks());
376 DuckList::const_iterator iter;
377 for(iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
379 synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
381 if(!value_desc.is_valid())
384 if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
386 value_desc_list.push_back(
387 synfigapp::ValueDesc(
388 ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())
394 value_desc_list.push_back(value_desc);
397 Gtk::Menu *menu=manage(new Gtk::Menu());
398 menu->signal_hide().connect(sigc::bind(sigc::ptr_fun(&delete_widget), menu));
400 canvas_view->get_instance()->make_param_menu(menu,canvas_view->get_canvas(),value_desc_list);
403 synfigapp::Action::ParamList param_list;
404 param_list=get_canvas_interface()->generate_param_list(value_desc_list);
406 canvas_view->add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
408 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Edit Waypoints"),
412 &studio::StateNormal_Context::edit_several_waypoints
418 menu->popup(3,gtk_get_current_event_time());
420 return Smach::RESULT_ACCEPT;