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