Skip to content

Commit b172e37

Browse files
feat: added the ability to rotate guides in the canvas (synfig#2777)
Now the guide lines are able to rotate by holding Control while moving the cursor. A dialog which is accessed by right clicking the guide to manually set the rotation. Related to synfig#2593
1 parent 99aae13 commit b172e37

File tree

12 files changed

+540
-195
lines changed

12 files changed

+540
-195
lines changed

synfig-studio/po/POTFILES.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ src/gui/dialogs/dialog_template.cpp
5252
src/gui/dialogs/dialog_template.h
5353
src/gui/dialogs/dialog_waypoint.cpp
5454
src/gui/dialogs/dialog_waypoint.h
55+
src/gui/dialogs/dialog_guide.cpp
56+
src/gui/dialogs/dialog_guide.h
5557
src/gui/dialogs/dialog_workspaces.cpp
5658
src/gui/dialogs/dialog_workspaces.h
5759
src/gui/dialogs/vectorizersettings.cpp

synfig-studio/src/gui/dialogs/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ target_sources(synfigstudio
1717
"${CMAKE_CURRENT_LIST_DIR}/dialog_ffmpegparam.cpp"
1818
"${CMAKE_CURRENT_LIST_DIR}/dialog_spritesheetparam.cpp"
1919
"${CMAKE_CURRENT_LIST_DIR}/dialog_waypoint.cpp"
20+
"${CMAKE_CURRENT_LIST_DIR}/dialog_guide.cpp"
2021
"${CMAKE_CURRENT_LIST_DIR}/dialog_workspaces.cpp"
2122
"${CMAKE_CURRENT_LIST_DIR}/dialog_template.cpp"
2223
"${CMAKE_CURRENT_LIST_DIR}/vectorizersettings.cpp"
24+
2325
)

synfig-studio/src/gui/dialogs/Makefile_insert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DIALOGS_HH = \
1616
dialogs/dialog_ffmpegparam.h \
1717
dialogs/dialog_spritesheetparam.h \
1818
dialogs/dialog_waypoint.h \
19+
dialogs/dialog_guide.h \
1920
dialogs/dialog_workspaces.h \
2021
dialogs/dialog_template.h \
2122
dialogs/vectorizersettings.h
@@ -38,6 +39,7 @@ DIALOGS_CC = \
3839
dialogs/dialog_ffmpegparam.cpp \
3940
dialogs/dialog_spritesheetparam.cpp \
4041
dialogs/dialog_waypoint.cpp \
42+
dialogs/dialog_guide.cpp \
4143
dialogs/dialog_workspaces.cpp \
4244
dialogs/dialog_template.cpp \
4345
dialogs/vectorizersettings.cpp
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/* === S Y N F I G ========================================================= */
2+
/*! \file Dialog_Guide.cpp
3+
** \brief Dialog for editing guides.
4+
**
5+
** \legal
6+
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7+
**
8+
** This file is part of Synfig.
9+
**
10+
** Synfig is free software: you can redistribute it and/or modify
11+
** it under the terms of the GNU General Public License as published by
12+
** the Free Software Foundation, either version 2 of the License, or
13+
** (at your option) any later version.
14+
**
15+
** Synfig 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
18+
** GNU General Public License for more details.
19+
**
20+
** You should have received a copy of the GNU General Public License
21+
** along with Synfig. If not, see <https://www.gnu.org/licenses/>.
22+
** \endlegal
23+
*/
24+
/* ========================================================================= */
25+
26+
/* === H E A D E R S ======================================================= */
27+
28+
#ifdef USING_PCH
29+
# include "pch.h"
30+
#else
31+
#ifdef HAVE_CONFIG_H
32+
# include <config.h>
33+
#endif
34+
35+
#include <gui/dialogs/dialog_guide.h>
36+
37+
#include <gui/localization.h>
38+
39+
#include <gtkmm/box.h>
40+
#include <gtkmm/frame.h>
41+
#include <gtkmm/grid.h>
42+
43+
#include <gui/workarea.h>
44+
#include <gui/duckmatic.h>
45+
#include <gui/app.h>
46+
47+
#endif
48+
49+
using namespace synfig;
50+
using namespace studio;
51+
52+
/* === M A C R O S ========================================================= */
53+
54+
/* === G L O B A L S ======================================================= */
55+
/* === P R O C E D U R E S ================================================= */
56+
57+
/* === M E T H O D S ======================================================= */
58+
59+
Dialog_Guide::Dialog_Guide(Gtk::Window& parent, etl::handle<synfig::Canvas> canvas, WorkArea* work_area):
60+
Dialog(_("Guide Editor"),parent),
61+
canvas(canvas),
62+
current_work_area(work_area),
63+
angle_adjustment(Gtk::Adjustment::create(0,-2000000000,2000000000,1,1,0)),
64+
degrees(true)
65+
{
66+
this->set_resizable(false);
67+
assert(canvas);
68+
69+
//Box start
70+
Gtk::Box *guide_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
71+
72+
angle_widget=manage(new Gtk::SpinButton(angle_adjustment,15,2));
73+
angle_widget->show();
74+
75+
Gtk::Frame* angleFrame = manage(new Gtk::Frame(_("Rotate Guide")));
76+
angleFrame->set_shadow_type(Gtk::SHADOW_NONE);
77+
(static_cast<Gtk::Label*>(angleFrame->get_label_widget()))->set_markup(_("<b>Rotate Guide</b>"));
78+
angleFrame->set_margin_bottom(5);
79+
angleFrame->set_margin_top(5);
80+
81+
82+
auto guideGrid = manage(new Gtk::Grid());
83+
guideGrid->get_style_context()->add_class("dialog-secondary-content");
84+
guideGrid->set_row_spacing(6);
85+
guideGrid->set_column_spacing(8);
86+
87+
angle_type_picker.append("Degree", _("Degree"));
88+
angle_type_picker.append("Radian", _("Radian"));
89+
angle_type_picker.set_active(0);
90+
angle_type_picker.signal_changed().connect(sigc::mem_fun(*this, &Dialog_Guide::set_angle_type));
91+
92+
Gtk::Label* rotationAngleLabel = manage(new Gtk::Label(_("_Rotation Angle"), true));
93+
rotationAngleLabel->set_halign(Gtk::ALIGN_CENTER);
94+
rotationAngleLabel->set_mnemonic_widget(*angle_widget);
95+
guideGrid->attach(*rotationAngleLabel, 0, 0, 1, 1);
96+
guideGrid->attach(*angle_widget , 1, 0, 1, 1);
97+
guideGrid->attach(angle_type_picker , 2, 0, 1, 1);
98+
99+
guide_box->add(*angleFrame);
100+
guide_box->add(*guideGrid);
101+
guide_box->set_margin_bottom(5);
102+
103+
//Box end
104+
get_content_area()->pack_start(*guide_box);
105+
106+
Gtk::Button *apply_button(manage(new Gtk::Button(_("_Apply"), true)));
107+
apply_button->show();
108+
add_action_widget(*apply_button, Gtk::RESPONSE_APPLY);
109+
apply_button->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Dialog_Guide::on_ok_or_apply_pressed), false));
110+
111+
Gtk::Button *ok_button(manage(new Gtk::Button(_("_OK"), true)));
112+
ok_button->show();
113+
add_action_widget(*ok_button, Gtk::RESPONSE_OK);
114+
ok_button->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &Dialog_Guide::on_ok_or_apply_pressed), true));
115+
116+
guide_box->show_all();
117+
}
118+
119+
Dialog_Guide::~Dialog_Guide()
120+
{
121+
}
122+
123+
void
124+
Dialog_Guide::set_current_guide(GuideList::iterator current_guide)
125+
{
126+
curr_guide = current_guide;
127+
init_widget_values();
128+
}
129+
130+
131+
void
132+
Dialog_Guide::on_ok_or_apply_pressed(bool ok)
133+
{
134+
if (degrees && synfig::Angle::deg(curr_guide->angle).get() != angle_widget->get_value()) {
135+
curr_guide->angle = synfig::Angle::deg(angle_widget->get_value());
136+
} else if (!degrees && curr_guide->angle.get() != angle_widget->get_value()) {
137+
curr_guide->angle = synfig::Angle::rad(angle_widget->get_value());
138+
}
139+
140+
if (ok)
141+
hide();
142+
else
143+
current_work_area->get_drawing_area()->queue_draw();
144+
}
145+
146+
void
147+
Dialog_Guide::set_angle_type()
148+
{
149+
Glib::ustring text = angle_type_picker.get_active_text();
150+
if (text == "Degree")
151+
degrees=true;
152+
else if (text == "Radian")
153+
degrees=false;
154+
}
155+
156+
void
157+
Dialog_Guide::init_widget_values()
158+
{
159+
if(degrees)
160+
angle_widget->set_value(synfig::Angle::deg(curr_guide->angle).get());
161+
else
162+
angle_widget->set_value(curr_guide->angle.get());
163+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* === S Y N F I G ========================================================= */
2+
/*! \file dialogs/Dialog_Guide.h
3+
** \brief Dialog for editing guides.
4+
**
5+
** \legal
6+
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
7+
**
8+
** This file is part of Synfig.
9+
**
10+
** Synfig is free software: you can redistribute it and/or modify
11+
** it under the terms of the GNU General Public License as published by
12+
** the Free Software Foundation, either version 2 of the License, or
13+
** (at your option) any later version.
14+
**
15+
** Synfig 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
18+
** GNU General Public License for more details.
19+
**
20+
** You should have received a copy of the GNU General Public License
21+
** along with Synfig. If not, see <https://www.gnu.org/licenses/>.
22+
** \endlegal
23+
*/
24+
/* ========================================================================= */
25+
26+
/* === S T A R T =========================================================== */
27+
28+
#ifndef SYNFIG_STUDIO_DIALOG_GUIDE_H
29+
#define SYNFIG_STUDIO_DIALOG_GUIDE_H
30+
31+
32+
/* === H E A D E R S ======================================================= */
33+
34+
#include <gtkmm/dialog.h>
35+
#include <gtkmm/spinbutton.h>
36+
#include <gtkmm/comboboxtext.h>
37+
38+
#include <synfigapp/value_desc.h>
39+
40+
/* === M A C R O S ========================================================= */
41+
42+
/* === T Y P E D E F S ===================================================== */
43+
44+
45+
/* === C L A S S E S & S T R U C T S ======================================= */
46+
47+
namespace studio {
48+
49+
class Widget_Waypoint;
50+
class Widget_ValueBase;
51+
class WorkArea;
52+
struct Guide;
53+
54+
class Dialog_Guide : public Gtk::Dialog
55+
{
56+
typedef std::list<Guide> GuideList;
57+
58+
synfig::Canvas::Handle canvas;
59+
WorkArea* current_work_area;
60+
61+
Gtk::SpinButton* angle_widget;
62+
Glib::RefPtr<Gtk::Adjustment> angle_adjustment;
63+
64+
Gtk::ComboBoxText angle_type_picker;
65+
66+
void on_ok_or_apply_pressed(bool ok);
67+
void set_angle_type();
68+
void init_widget_values();
69+
70+
GuideList::iterator curr_guide;
71+
72+
bool menu_guide_is_x;
73+
bool degrees;
74+
75+
public:
76+
Dialog_Guide(Gtk::Window& parent, etl::handle<synfig::Canvas> canvas, WorkArea* work_area);
77+
~Dialog_Guide();
78+
void set_current_guide(GuideList::iterator current_guide);
79+
80+
}; // END of Dialog_Guide
81+
82+
}; // END of namespace studio
83+
84+
/* === E N D =============================================================== */
85+
86+
#endif // DIALOG_GUIDE_H

0 commit comments

Comments
 (0)