my log
[synfig.git] / synfig-studio / trunk / 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include <gtkmm/label.h>
32 #include "dialog_waypoint.h"
33 #include <gtk/gtk.h>
34 #include <gtkmm/spinbutton.h>
35 #include <gtkmm/combo.h>
36 #include <ETL/stringf>
37 #include "widget_value.h"
38 #include "app.h"
39 #include <gtkmm/menu.h>
40 #include <gtkmm/optionmenu.h>
41 #include "widget_time.h"
42 #include "widget_waypoint.h"
43 #endif
44
45 using namespace synfig;
46 using namespace std;
47 using namespace etl;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 Widget_Waypoint::Widget_Waypoint(etl::handle<synfig::Canvas> canvas):
59         Gtk::Table(4,3,false),
60         waypoint(synfig::ValueBase(),0),
61         adj_tension(0.0,-20,20,0.1,1),
62         adj_continuity(0.0,-20,20,0.1,1),
63         adj_bias(0.0,-20,20,0.1,1),
64         adj_temporal_tension(0.0,-20,20,0.1,1)
65 {
66         value_widget=manage(new Widget_ValueBase());
67         value_widget->set_canvas(canvas);
68         value_widget->show();
69         
70         value_node_label=manage(new Gtk::Label(_("(Non-static value)")));
71         
72         
73         time_widget=manage(new Widget_Time());
74         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
75         //spinbutton=manage(new Gtk::SpinButton(time_adjustment,0.05,3));
76         //spinbutton->set_update_policy(Gtk::UPDATE_ALWAYS);
77         //spinbutton->show();
78
79         before_options=manage(new class Gtk::Menu());
80         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("TCB Smooth"));
81         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Constant"));
82         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Linear"));
83         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Ease In"));
84         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Manual"));
85
86         after_options=manage(new class Gtk::Menu());
87         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("TCB Smooth"));
88         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Constant"));
89         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Linear"));
90         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Ease Out"));
91         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem("Manual"));
92
93         before=manage(new class Gtk::OptionMenu());
94         before->show();
95         before->set_menu(*before_options);
96
97         after=manage(new class Gtk::OptionMenu());
98         after->show();
99         after->set_menu(*after_options);
100
101         spin_tension=manage(new class Gtk::SpinButton(adj_tension,0.1,3));
102         spin_tension->show();
103         spin_continuity=manage(new class Gtk::SpinButton(adj_continuity,0.1,3));
104         spin_continuity->show();
105         spin_bias=manage(new class Gtk::SpinButton(adj_bias,0.1,3));
106         spin_bias->show();
107         spin_temporal_tension=manage(new class Gtk::SpinButton(adj_temporal_tension,0.1,3));
108         spin_temporal_tension->show();
109         
110         
111         Gtk::HBox *hbox(manage(new Gtk::HBox()));
112         hbox->show();
113         hbox->pack_start(*value_widget);
114         hbox->pack_start(*value_node_label);
115         
116         attach(*manage(new Gtk::Label(_("ValueBase:"))), 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);       
117         //attach(*value_widget, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
118         //attach(*value_node_label, 0, 4, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
119         attach(*manage(new Gtk::Label(_("Time:"))), 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
120         attach(*time_widget, 1, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
121         attach(*manage(new Gtk::Label(_("In:"))), 0, 1, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);      
122         attach(*before, 1, 2, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
123         attach(*manage(new Gtk::Label(_("Out:"))), 2, 3, 3, 4, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);     
124         attach(*after, 3, 4, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
125
126         attach(*manage(new Gtk::Label(_("Tension:"))), 0, 1, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0); 
127         attach(*spin_tension, 1, 2, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
128         attach(*manage(new Gtk::Label(_("Continuity:"))), 2, 3, 4, 5, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);      
129         attach(*spin_continuity, 3, 4, 4, 5, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
130         attach(*manage(new Gtk::Label(_("Bias:"))), 0, 1, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);    
131         attach(*spin_bias, 1, 2, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
132         attach(*manage(new Gtk::Label(_("Temporal Tension:"))), 2, 3, 5, 6, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);        
133         attach(*spin_temporal_tension, 3, 4, 5, 6, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
134
135         show_all();
136         hide();
137         attach(*hbox, 1, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
138         set_canvas(canvas);
139 }
140
141 void
142 Widget_Waypoint::set_canvas(synfig::Canvas::Handle x)
143 {
144         canvas=x;
145         assert(canvas);
146         
147         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
148         value_widget->set_canvas(canvas);
149 }
150
151 void
152 Widget_Waypoint::set_waypoint(synfig::Waypoint &x)
153 {
154         time_widget->set_fps(canvas->rend_desc().get_frame_rate());
155
156         waypoint=x;
157                         
158 #warning This really needs to be fixed to support value node waypoints!
159         if(waypoint.is_static())
160         {
161                 value_widget->set_value(waypoint.get_value());
162                 value_widget->show();
163                 value_node_label->hide();
164         }
165         else
166         {
167                 value_widget->hide();
168                 value_node_label->show();
169         }
170         
171         time_widget->set_value(waypoint.get_time());
172
173         before->set_history((int)waypoint.get_before());
174         after->set_history((int)waypoint.get_after());
175
176         adj_tension.set_value(waypoint.get_tension());
177         adj_continuity.set_value(waypoint.get_continuity());
178         adj_bias.set_value(waypoint.get_bias());
179         adj_temporal_tension.set_value(waypoint.get_temporal_tension());
180         
181 }
182 const synfig::Waypoint &
183 Widget_Waypoint::get_waypoint()const
184 {
185 #warning This too!
186         waypoint.set_time(time_widget->get_value());
187         waypoint.set_value(value_widget->get_value());
188         //int i;
189
190         waypoint.set_before((synfig::Waypoint::Interpolation)before->get_history());
191         waypoint.set_after((synfig::Waypoint::Interpolation)after->get_history());
192
193         waypoint.set_tension(adj_tension.get_value());
194         waypoint.set_continuity(adj_continuity.get_value());
195         waypoint.set_bias(adj_bias.get_value());
196         waypoint.set_temporal_tension(adj_temporal_tension.get_value());
197         return waypoint;
198 }