Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_03 / synfig-studio / src / gtkmm / widget_waypoint.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dialog_waypoint.cpp
3 **      \brief Template Header
4 **
5 **      $Id: widget_waypoint.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
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 "dialog_waypoint.h"
34 #include <gtk/gtk.h>
35 #include <gtkmm/spinbutton.h>
36 #include <gtkmm/combo.h>
37 #include <ETL/stringf>
38 #include "widget_value.h"
39 #include "app.h"
40 #include <gtkmm/menu.h>
41 #include <gtkmm/optionmenu.h>
42 #include "widget_time.h"
43 #include "widget_waypoint.h"
44 #endif
45
46 using namespace synfig;
47 using namespace std;
48 using namespace etl;
49 using namespace studio;
50
51 /* === M A C R O S ========================================================= */
52
53 /* === G L O B A L S ======================================================= */
54
55 /* === P R O C E D U R E S ================================================= */
56
57 /* === M E T H O D S ======================================================= */
58
59 Widget_Waypoint::Widget_Waypoint(etl::handle<synfig::Canvas> canvas):
60         Gtk::Table(4,3,false),
61         waypoint(synfig::ValueBase(),0),
62         adj_tension(0.0,-20,20,0.1,1),
63         adj_continuity(0.0,-20,20,0.1,1),
64         adj_bias(0.0,-20,20,0.1,1),
65         adj_temporal_tension(0.0,-20,20,0.1,1)
66 {
67         value_widget=manage(new Widget_ValueBase());
68         value_widget->set_canvas(canvas);
69         value_widget->show();
70         
71         value_node_label=manage(new Gtk::Label(_("(Non-static value)")));
72         
73         
74         time_widget=manage(new Widget_Time());
75         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
76         //spinbutton=manage(new Gtk::SpinButton(time_adjustment,0.05,3));
77         //spinbutton->set_update_policy(Gtk::UPDATE_ALWAYS);
78         //spinbutton->show();
79
80         before_options=manage(new class Gtk::Menu());
81         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("TCB Smooth"));
82         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Constant"));
83         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Linear"));
84         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Ease In"));
85         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Manual"));
86
87         after_options=manage(new class Gtk::Menu());
88         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("TCB Smooth"));
89         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Constant"));
90         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Linear"));
91         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Ease Out"));
92         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Manual"));
93
94         before=manage(new class Gtk::OptionMenu());
95         before->show();
96         before->set_menu(*before_options);
97
98         after=manage(new class Gtk::OptionMenu());
99         after->show();
100         after->set_menu(*after_options);
101
102         spin_tension=manage(new class Gtk::SpinButton(adj_tension,0.1,3));
103         spin_tension->show();
104         spin_continuity=manage(new class Gtk::SpinButton(adj_continuity,0.1,3));
105         spin_continuity->show();
106         spin_bias=manage(new class Gtk::SpinButton(adj_bias,0.1,3));
107         spin_bias->show();
108         spin_temporal_tension=manage(new class Gtk::SpinButton(adj_temporal_tension,0.1,3));
109         spin_temporal_tension->show();
110         
111         
112         Gtk::HBox *hbox(manage(new Gtk::HBox()));
113         hbox->show();
114         hbox->pack_start(*value_widget);
115         hbox->pack_start(*value_node_label);
116         
117         attach(*manage(new Gtk::Label(_("ValueBase:"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);       
118         //attach(*value_widget, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
119         //attach(*value_node_label, 0, 4, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
120         attach(*manage(new Gtk::Label(_("Time:"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
121         attach(*time_widget, 1, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
122         attach(*manage(new Gtk::Label(_("In:"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);      
123         attach(*before, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
124         attach(*manage(new Gtk::Label(_("Out:"))), 2, 3, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);     
125         attach(*after, 3, 4, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
126
127         attach(*manage(new Gtk::Label(_("Tension:"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0); 
128         attach(*spin_tension, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
129         attach(*manage(new Gtk::Label(_("Continuity:"))), 2, 3, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);      
130         attach(*spin_continuity, 3, 4, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
131         attach(*manage(new Gtk::Label(_("Bias:"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
132         attach(*spin_bias, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
133         attach(*manage(new Gtk::Label(_("Temporal Tension:"))), 2, 3, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
134         attach(*spin_temporal_tension, 3, 4, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
135
136         show_all();
137         hide();
138         attach(*hbox, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
139         set_canvas(canvas);
140 }
141
142 void
143 Widget_Waypoint::set_canvas(synfig::Canvas::Handle x)
144 {
145         canvas=x;
146         assert(canvas);
147         
148         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
149         value_widget->set_canvas(canvas);
150 }
151
152 void
153 Widget_Waypoint::set_waypoint(synfig::Waypoint &x)
154 {
155         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
156
157         waypoint=x;
158                         
159 #warning This really needs to be fixed to support value node waypoints!
160         if(waypoint.is_static())
161         {
162                 value_widget->set_value(waypoint.get_value());
163                 value_widget->show();
164                 value_node_label->hide();
165         }
166         else
167         {
168                 value_widget->hide();
169                 value_node_label->show();
170         }
171         
172         time_widget->set_value(waypoint.get_time());
173
174         before->set_history((int)waypoint.get_before());
175         after->set_history((int)waypoint.get_after());
176
177         adj_tension.set_value(waypoint.get_tension());
178         adj_continuity.set_value(waypoint.get_continuity());
179         adj_bias.set_value(waypoint.get_bias());
180         adj_temporal_tension.set_value(waypoint.get_temporal_tension());
181         
182 }
183 const synfig::Waypoint &
184 Widget_Waypoint::get_waypoint()const
185 {
186 #warning This too!
187         waypoint.set_time(time_widget->get_value());
188         waypoint.set_value(value_widget->get_value());
189         //int i;
190
191         waypoint.set_before((synfig::Waypoint::Interpolation)before->get_history());
192         waypoint.set_after((synfig::Waypoint::Interpolation)after->get_history());
193
194         waypoint.set_tension(adj_tension.get_value());
195         waypoint.set_continuity(adj_continuity.get_value());
196         waypoint.set_bias(adj_bias.get_value());
197         waypoint.set_temporal_tension(adj_temporal_tension.get_value());
198         return waypoint;
199 }