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