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"
46 /* === U S I N G =========================================================== */
50 using namespace synfig;
51 using namespace studio;
53 /* === M A C R O S ========================================================= */
55 /* === C L A S S E S & S T R U C T S ======================================= */
57 class studio::StateNormal_Context : public sigc::trackable
59 CanvasView *canvas_view;
61 CanvasView* get_canvas_view() { return canvas_view; }
62 Canvas::Handle get_canvas() { return canvas_view->get_canvas(); }
63 WorkArea* get_work_area() { return canvas_view->get_work_area(); }
64 etl::handle<synfigapp::CanvasInterface> get_canvas_interface() { return canvas_view->canvas_interface(); }
67 StateNormal_Context(CanvasView *canvas_view);
68 ~StateNormal_Context();
70 Smach::event_result event_stop_handler(const Smach::event& x);
72 Smach::event_result event_refresh_handler(const Smach::event& x);
74 Smach::event_result event_refresh_ducks_handler(const Smach::event& x);
76 Smach::event_result event_undo_handler(const Smach::event& x);
78 Smach::event_result event_redo_handler(const Smach::event& x);
80 Smach::event_result event_mouse_button_down_handler(const Smach::event& x);
82 Smach::event_result event_multiple_ducks_clicked_handler(const Smach::event& x);
84 Smach::event_result event_refresh_tool_options(const Smach::event& x);
86 Smach::event_result event_layer_click(const Smach::event& x);
88 void edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list);
90 void refresh_tool_options();
91 }; // END of class StateNormal_Context
93 /* === G L O B A L S ======================================================= */
95 StateNormal studio::state_normal;
97 /* === P R O C E D U R E S ================================================= */
99 /* === M E T H O D S ======================================================= */
101 StateNormal::StateNormal():
102 Smach::state<StateNormal_Context>("normal")
104 insert(event_def(EVENT_STOP,&StateNormal_Context::event_stop_handler));
105 insert(event_def(EVENT_REFRESH,&StateNormal_Context::event_refresh_handler));
106 insert(event_def(EVENT_REFRESH_DUCKS,&StateNormal_Context::event_refresh_ducks_handler));
107 insert(event_def(EVENT_UNDO,&StateNormal_Context::event_undo_handler));
108 insert(event_def(EVENT_REDO,&StateNormal_Context::event_redo_handler));
109 insert(event_def(EVENT_WORKAREA_MOUSE_BUTTON_DOWN,&StateNormal_Context::event_mouse_button_down_handler));
110 insert(event_def(EVENT_WORKAREA_MULTIPLE_DUCKS_CLICKED,&StateNormal_Context::event_multiple_ducks_clicked_handler));
111 insert(event_def(EVENT_REFRESH_TOOL_OPTIONS,&StateNormal_Context::event_refresh_tool_options));
112 insert(event_def(EVENT_WORKAREA_LAYER_CLICKED,&StateNormal_Context::event_layer_click));
115 StateNormal::~StateNormal()
119 StateNormal_Context::StateNormal_Context(CanvasView *canvas_view):
120 canvas_view(canvas_view)
122 synfig::info("Enterted Normal State");
125 StateNormal_Context::~StateNormal_Context()
127 synfig::info("Left Normal State");
131 StateNormal_Context::refresh_tool_options()
133 App::dialog_tool_options->clear();
134 App::dialog_tool_options->set_name("normal");
138 StateNormal_Context::event_refresh_tool_options(const Smach::event& x)
140 refresh_tool_options();
141 return Smach::RESULT_ACCEPT;
145 StateNormal_Context::event_stop_handler(const Smach::event& x)
147 synfig::info("STATE NORMAL: Received Stop Event");
149 return Smach::RESULT_ACCEPT;
153 StateNormal_Context::event_refresh_handler(const Smach::event& x)
155 synfig::info("STATE NORMAL: Received Refresh Event");
156 canvas_view->rebuild_tables();
157 canvas_view->work_area->queue_render_preview();
158 return Smach::RESULT_ACCEPT;
162 StateNormal_Context::event_refresh_ducks_handler(const Smach::event& x)
164 synfig::info("STATE NORMAL: Received Refresh Ducks");
165 canvas_view->queue_rebuild_ducks();
166 return Smach::RESULT_ACCEPT;
170 StateNormal_Context::event_undo_handler(const Smach::event& x)
172 synfig::info("STATE NORMAL: Received Undo Event");
173 canvas_view->get_instance()->undo();
174 return Smach::RESULT_ACCEPT;
178 StateNormal_Context::event_redo_handler(const Smach::event& x)
180 synfig::info("STATE NORMAL: Received Redo Event");
181 canvas_view->get_instance()->redo();
182 return Smach::RESULT_ACCEPT;
186 StateNormal_Context::event_mouse_button_down_handler(const Smach::event& x)
188 synfig::info("STATE NORMAL: Received mouse button down Event");
190 const EventMouse& event(*reinterpret_cast<const EventMouse*>(&x));
195 canvas_view->popup_main_menu();
196 return Smach::RESULT_ACCEPT;
198 return Smach::RESULT_OK;
203 StateNormal_Context::event_layer_click(const Smach::event& x)
205 const EventLayerClick& event(*reinterpret_cast<const EventLayerClick*>(&x));
209 synfig::info("STATE NORMAL: Received layer click Event, \"%s\"",event.layer->get_name().c_str());
213 synfig::info("STATE NORMAL: Received layer click Event with an empty layer.");
219 if(!(event.modifier&Gdk::CONTROL_MASK))
220 canvas_view->get_selection_manager()->clear_selected_layers();
223 std::list<Layer::Handle> layer_list(canvas_view->get_selection_manager()->get_selected_layers());
224 std::set<Layer::Handle> layers(layer_list.begin(),layer_list.end());
225 if(layers.count(event.layer))
227 layers.erase(event.layer);
228 layer_list=std::list<Layer::Handle>(layers.begin(),layers.end());
229 canvas_view->get_selection_manager()->clear_selected_layers();
230 canvas_view->get_selection_manager()->set_selected_layers(layer_list);
234 canvas_view->get_selection_manager()->set_selected_layer(event.layer);
237 return Smach::RESULT_ACCEPT;
239 canvas_view->popup_layer_menu(event.layer);
240 return Smach::RESULT_ACCEPT;
242 return Smach::RESULT_OK;
248 StateNormal_Context::edit_several_waypoints(std::list<synfigapp::ValueDesc> value_desc_list)
251 "Edit Multiple Waypoints", // Title
253 true // use_separator
256 Widget_WaypointModel widget_waypoint_model;
257 widget_waypoint_model.show();
259 dialog.get_vbox()->pack_start(widget_waypoint_model);
262 dialog.add_button(Gtk::StockID("gtk-apply"),1);
263 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());
399 canvas_view->get_instance()->make_param_menu(menu,canvas_view->get_canvas(),value_desc_list);
402 synfigapp::Action::ParamList param_list;
403 param_list=get_canvas_interface()->generate_param_list(value_desc_list);
405 canvas_view->add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
407 menu->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Edit Waypoints"),
411 &studio::StateNormal_Context::edit_several_waypoints
417 menu->popup(3,gtk_get_current_event_time());
419 return Smach::RESULT_ACCEPT;