Build rectanglular blines in the same handedness as all the other shapes.
[synfig.git] / synfig-studio / trunk / src / gtkmm / widget_waypointmodel.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file widget_waypointmodel.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 Paul Wise
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include <gtkmm/label.h>
34 #include <gtkmm/spinbutton.h>
35 #include <ETL/stringf>
36 #include "widget_value.h"
37 #include "app.h"
38 #include <gtkmm/menu.h>
39 #include <gtkmm/optionmenu.h>
40 #include "widget_time.h"
41 #include "widget_waypointmodel.h"
42 #include "general.h"
43
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_WaypointModel::Widget_WaypointModel():
60         Gtk::Table(4,3,false),
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         checkbutton_after(_("Out:")),
66         checkbutton_before(_("In:")),
67         checkbutton_tension(_("Tension:")),
68         checkbutton_continuity(_("Continuity:")),
69         checkbutton_bias(_("Bias:")),
70         checkbutton_temporal_tension(_("Temporal Tension:"))
71 {
72         before_options=manage(new class Gtk::Menu());
73         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("TCB Smooth")));
74         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Constant")));
75         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Linear")));
76         before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Ease In")));
77         // before_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Manual")));
78
79         after_options=manage(new class Gtk::Menu());
80         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("TCB Smooth")));
81         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Constant")));
82         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Linear")));
83         after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Ease Out")));
84         // after_options->items().push_back(Gtk::Menu_Helpers::MenuElem(_("Manual")));
85
86         before=manage(new class Gtk::OptionMenu());
87         before->show();
88         before->set_menu(*before_options);
89
90         after=manage(new class Gtk::OptionMenu());
91         after->show();
92         after->set_menu(*after_options);
93
94         spin_tension=manage(new class Gtk::SpinButton(adj_tension,0.1,3));
95         spin_tension->show();
96         spin_continuity=manage(new class Gtk::SpinButton(adj_continuity,0.1,3));
97         spin_continuity->show();
98         spin_bias=manage(new class Gtk::SpinButton(adj_bias,0.1,3));
99         spin_bias->show();
100         spin_temporal_tension=manage(new class Gtk::SpinButton(adj_temporal_tension,0.1,3));
101         spin_temporal_tension->show();
102
103         checkbutton_before.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
104         checkbutton_after.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
105         checkbutton_tension.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
106         checkbutton_continuity.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
107         checkbutton_bias.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
108         checkbutton_temporal_tension.signal_toggled().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
109
110         adj_tension.signal_value_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
111         adj_continuity.signal_value_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
112         adj_bias.signal_value_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
113         adj_temporal_tension.signal_value_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
114
115         before->signal_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
116         after->signal_changed().connect(sigc::mem_fun(*this,&Widget_WaypointModel::on_change));
117
118         attach(checkbutton_before, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
119         attach(*before, 1, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
120         attach(checkbutton_after, 2, 3, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
121         attach(*after, 3, 4, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
122
123         attach(checkbutton_tension, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
124         attach(*spin_tension, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
125         attach(checkbutton_continuity, 2, 3, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
126         attach(*spin_continuity, 3, 4, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
127         attach(checkbutton_bias, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
128         attach(*spin_bias, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
129         attach(checkbutton_temporal_tension, 2, 3, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
130         attach(*spin_temporal_tension, 3, 4, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
131
132         show_all();
133         hide();
134         updating=false;
135         on_change();
136 }
137
138 void
139 Widget_WaypointModel::on_change()
140 {
141         if(updating)
142                 return;
143
144         waypoint_model.set_before((Waypoint::Interpolation)before->get_history());
145         waypoint_model.set_after((Waypoint::Interpolation)after->get_history());
146
147         waypoint_model.set_tension(adj_tension.get_value());
148         waypoint_model.set_continuity(adj_continuity.get_value());
149         waypoint_model.set_bias(adj_bias.get_value());
150         waypoint_model.set_temporal_tension(adj_temporal_tension.get_value());
151
152         waypoint_model.set_before_flag(checkbutton_before.get_active());
153         waypoint_model.set_after_flag(checkbutton_after.get_active());
154         waypoint_model.set_tension_flag(checkbutton_tension.get_active());
155         waypoint_model.set_continuity_flag(checkbutton_continuity.get_active());
156         waypoint_model.set_bias_flag(checkbutton_bias.get_active());
157         waypoint_model.set_temporal_tension_flag(checkbutton_temporal_tension.get_active());
158
159         before->set_sensitive(checkbutton_before.get_active());
160         after->set_sensitive(checkbutton_after.get_active());
161         spin_tension->set_sensitive(checkbutton_tension.get_active());
162         spin_continuity->set_sensitive(checkbutton_continuity.get_active());
163         spin_bias->set_sensitive(checkbutton_bias.get_active());
164         spin_temporal_tension->set_sensitive(checkbutton_temporal_tension.get_active());
165 }
166
167 void
168 Widget_WaypointModel::set_waypoint_model(synfig::Waypoint::Model &x)
169 {
170         waypoint_model=x;
171         updating=true;
172
173         before->set_history((int)waypoint_model.get_before());
174         after->set_history((int)waypoint_model.get_after());
175
176         adj_tension.set_value(waypoint_model.get_tension());
177         adj_continuity.set_value(waypoint_model.get_continuity());
178         adj_bias.set_value(waypoint_model.get_bias());
179         adj_temporal_tension.set_value(waypoint_model.get_temporal_tension());
180
181         checkbutton_before.set_active(waypoint_model.get_before_flag());
182         checkbutton_after.set_active(waypoint_model.get_after_flag());
183         checkbutton_tension.set_active(waypoint_model.get_tension_flag());
184         checkbutton_continuity.set_active(waypoint_model.get_continuity_flag());
185         checkbutton_bias.set_active(waypoint_model.get_bias_flag());
186         checkbutton_temporal_tension.set_active(waypoint_model.get_temporal_tension_flag());
187
188         updating=false;
189
190         on_change();
191 }