Allow PasteCanvas layers with unset canvas parameters to be exported.
[synfig.git] / synfig-studio / trunk / src / gtkmm / widget_waypoint.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file widget_waypoint.cpp
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2008 Chris Moore
10 **  Copyright (c) 2008 Paul Wise
11 **
12 **      This package is free software; you can redistribute it and/or
13 **      modify it under the terms of the GNU General Public License as
14 **      published by the Free Software Foundation; either version 2 of
15 **      the License, or (at your option) any later version.
16 **
17 **      This package is distributed in the hope that it will be useful,
18 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **      General Public License for more details.
21 **      \endlegal
22 */
23 /* ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include <gtkmm/label.h>
35 #include <gtkmm/frame.h>
36 #include <gtkmm/alignment.h>
37 #include "dialog_waypoint.h"
38 #include <gtk/gtk.h>
39 #include <gtkmm/spinbutton.h>
40 #include <gtkmm/combo.h>
41 #include <ETL/stringf>
42 #include "widget_value.h"
43 #include "app.h"
44 #include <gtkmm/menu.h>
45 #include <gtkmm/optionmenu.h>
46 #include "widget_time.h"
47 #include "widget_waypoint.h"
48 #include "general.h"
49
50 #endif
51
52 using namespace synfig;
53 using namespace std;
54 using namespace etl;
55 using namespace studio;
56
57 /* === M A C R O S ========================================================= */
58
59 /* === G L O B A L S ======================================================= */
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 Widget_Waypoint::Widget_Waypoint(etl::handle<synfig::Canvas> canvas):
66         Gtk::Alignment(0, 0, 1, 1),
67         waypoint(synfig::ValueBase(),0),
68         adj_tension(0.0,-20,20,0.1,1),
69         adj_continuity(0.0,-20,20,0.1,1),
70         adj_bias(0.0,-20,20,0.1,1),
71         adj_temporal_tension(0.0,-20,20,0.1,1)
72 {
73         value_widget=manage(new Widget_ValueBase());
74         value_widget->set_canvas(canvas);
75         value_widget->show();
76
77         value_node_label=manage(new Gtk::Label(_("(Non-static value)")));
78
79
80         time_widget=manage(new Widget_Time());
81         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
82         //spinbutton=manage(new Gtk::SpinButton(time_adjustment,0.05,3));
83         //spinbutton->set_update_policy(Gtk::UPDATE_ALWAYS);
84         //spinbutton->show();
85
86         before_options=manage(new class Gtk::Menu());
87         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("TCB Smooth")));
88         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Constant")));
89         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Linear")));
90         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Ease In")));
91         // before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Manual")));
92
93         after_options=manage(new class Gtk::Menu());
94         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("TCB Smooth")));
95         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Constant")));
96         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Linear")));
97         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Ease Out")));
98         // after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Manual")));
99
100         before=manage(new class Gtk::OptionMenu());
101         before->show();
102         before->set_menu(*before_options);
103
104         after=manage(new class Gtk::OptionMenu());
105         after->show();
106         after->set_menu(*after_options);
107
108         spin_tension=manage(new class Gtk::SpinButton(adj_tension,0.1,3));
109         spin_tension->show();
110         spin_continuity=manage(new class Gtk::SpinButton(adj_continuity,0.1,3));
111         spin_continuity->show();
112         spin_bias=manage(new class Gtk::SpinButton(adj_bias,0.1,3));
113         spin_bias->show();
114         spin_temporal_tension=manage(new class Gtk::SpinButton(adj_temporal_tension,0.1,3));
115         spin_temporal_tension->show();
116
117         set_padding(12, 12, 12, 12);
118
119         Gtk::VBox *widgetBox = manage(new Gtk::VBox(false, 12));
120         add(*widgetBox);
121
122         Gtk::Frame *waypointFrame = manage(new Gtk::Frame(_("Waypoint")));
123         waypointFrame->set_shadow_type(Gtk::SHADOW_NONE);
124         ((Gtk::Label *) waypointFrame->get_label_widget())->set_markup(_("<b>Waypoint</b>"));
125         widgetBox->pack_start(*waypointFrame, false, false, 0);
126
127         Gtk::Alignment *waypointPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
128         waypointPadding->set_padding(6, 0, 24, 0);
129         waypointFrame->add(*waypointPadding);
130
131         Gtk::Table *waypointTable = manage(new Gtk::Table(2, 2, false));
132         waypointTable->set_row_spacings(6);
133         waypointTable->set_col_spacings(12);
134         waypointPadding->add(*waypointTable);
135
136         Gtk::Label *waypointValueLabel = manage(new Gtk::Label(_("_Value"), true));
137         waypointValueLabel->set_alignment(0, 0.5);
138         waypointValueLabel->set_mnemonic_widget(*value_widget);
139         waypointTable->attach(*waypointValueLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
140         waypointTable->attach(*value_widget, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
141         waypointTable->attach(*value_node_label, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
142
143         Gtk::Label *waypointTimeLabel = manage(new Gtk::Label(_("_Time"), true));
144         waypointTimeLabel->set_alignment(0, 0.5);
145         waypointTimeLabel->set_mnemonic_widget(*time_widget);
146         waypointTable->attach(*waypointTimeLabel, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
147         waypointTable->attach(*time_widget, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
148
149         Gtk::Frame *interpolationFrame = manage(new Gtk::Frame(_("Interpolation")));
150         interpolationFrame->set_shadow_type(Gtk::SHADOW_NONE);
151         ((Gtk::Label *) interpolationFrame->get_label_widget())->set_markup(_("<b>Interpolation</b>"));
152         widgetBox->pack_start(*interpolationFrame, false, false, 0);
153
154         Gtk::Alignment *interpolationPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
155         interpolationPadding->set_padding(6, 0, 24, 0);
156         interpolationFrame->add(*interpolationPadding);
157
158         Gtk::Table *interpolationTable = manage(new Gtk::Table(2, 2, false));
159         interpolationTable->set_row_spacings(6);
160         interpolationTable->set_col_spacings(12);
161         interpolationPadding->add(*interpolationTable);
162
163         Gtk::Label *interpolationInLabel = manage(new Gtk::Label(_("_In Interpolation"), true));
164         interpolationInLabel->set_alignment(0, 0.5);
165         interpolationInLabel->set_mnemonic_widget(*before);
166         interpolationTable->attach(*interpolationInLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
167         interpolationTable->attach(*before, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
168
169         Gtk::Label *interpolationOutLabel = manage(new Gtk::Label(_("_Out Interpolation"), true));
170         interpolationOutLabel->set_alignment(0, 0.5);
171         interpolationOutLabel->set_mnemonic_widget(*after);
172         interpolationTable->attach(*interpolationOutLabel, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
173         interpolationTable->attach(*after, 1, 2, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
174
175         Gtk::Frame *tcbFrame = manage(new Gtk::Frame(_("TCB Parameters")));
176         tcbFrame->set_shadow_type(Gtk::SHADOW_NONE);
177         ((Gtk::Label *) tcbFrame->get_label_widget())->set_markup(_("<b>TCB Parameter</b>"));
178         widgetBox->pack_start(*tcbFrame, false, false, 0);
179
180         Gtk::Alignment *tcbPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
181         tcbPadding->set_padding(6, 0, 24, 0);
182         tcbFrame->add(*tcbPadding);
183
184         Gtk::Table *tcbTable = manage(new Gtk::Table(4, 2, false));
185         tcbTable->set_row_spacings(6);
186         tcbTable->set_col_spacings(12);
187         tcbPadding->add(*tcbTable);
188
189         Gtk::Label *tensionLabel = manage(new Gtk::Label(_("T_ension"), true));
190         tensionLabel->set_alignment(0, 0.5);
191         tensionLabel->set_mnemonic_widget(*spin_tension);
192         spin_tension->set_alignment(1);
193         tcbTable->attach(*tensionLabel, 0, 1, 0, 1, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
194         tcbTable->attach(*spin_tension, 1, 2, 0, 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
195
196         Gtk::Label *continuityLabel = manage(new Gtk::Label(_("_Continuity"), true));
197         continuityLabel->set_alignment(0, 0.5);
198         continuityLabel->set_mnemonic_widget(*spin_continuity);
199         spin_continuity->set_alignment(1);
200         tcbTable->attach(*continuityLabel, 0, 1, 1, 2, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
201         tcbTable->attach(*spin_continuity, 1, 2, 1, 2, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
202
203         Gtk::Label *biasLabel = manage(new Gtk::Label(_("_Bias"), true));
204         biasLabel->set_alignment(0, 0.5);
205         biasLabel->set_mnemonic_widget(*spin_bias);
206         spin_bias->set_alignment(1);
207         tcbTable->attach(*biasLabel, 0, 1, 2, 3, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
208         tcbTable->attach(*spin_bias, 1, 2, 2, 3, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
209
210         Gtk::Label *temporalTensionLabel = manage(new Gtk::Label(_("Te_mporal Tension"), true));
211         temporalTensionLabel->set_alignment(0, 0.5);
212         temporalTensionLabel->set_mnemonic_widget(*spin_temporal_tension);
213         spin_temporal_tension->set_alignment(1);
214         tcbTable->attach(*temporalTensionLabel, 0, 1, 3, 4, Gtk::SHRINK | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
215         tcbTable->attach(*spin_temporal_tension, 1, 2, 3, 4, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, 0, 0);
216
217         show_all();
218         hide();
219         //attach(*hbox, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
220         set_canvas(canvas);
221 }
222
223 void
224 Widget_Waypoint::set_canvas(synfig::Canvas::Handle x)
225 {
226         canvas=x;
227         assert(canvas);
228
229         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
230         value_widget->set_canvas(canvas);
231 }
232
233 void
234 Widget_Waypoint::set_waypoint(synfig::Waypoint &x)
235 {
236         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
237
238         waypoint=x;
239
240         //! \todo This really needs to be fixed to support value node waypoints!
241         if(waypoint.is_static())
242         {
243                 value_widget->set_value(waypoint.get_value());
244                 value_widget->show();
245                 value_node_label->hide();
246         }
247         else
248         {
249                 value_widget->hide();
250                 value_node_label->show();
251         }
252
253         time_widget->set_value(waypoint.get_time());
254
255         before->set_history((int)waypoint.get_before());
256         after->set_history((int)waypoint.get_after());
257
258         adj_tension.set_value(waypoint.get_tension());
259         adj_continuity.set_value(waypoint.get_continuity());
260         adj_bias.set_value(waypoint.get_bias());
261         adj_temporal_tension.set_value(waypoint.get_temporal_tension());
262
263 }
264 const synfig::Waypoint &
265 Widget_Waypoint::get_waypoint()const
266 {
267         //! \todo This too!
268         waypoint.set_time(time_widget->get_value());
269         if(waypoint.is_static())
270                 waypoint.set_value(value_widget->get_value());
271         //int i;
272
273         waypoint.set_before((synfig::Waypoint::Interpolation)before->get_history());
274         waypoint.set_after((synfig::Waypoint::Interpolation)after->get_history());
275
276         waypoint.set_tension(adj_tension.get_value());
277         waypoint.set_continuity(adj_continuity.get_value());
278         waypoint.set_bias(adj_bias.get_value());
279         waypoint.set_temporal_tension(adj_temporal_tension.get_value());
280         return waypoint;
281 }