Inkscape
Vector Graphics Editor
anchor-selector.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * anchor-selector.cpp
4 *
5 * Created on: Mar 22, 2012
6 * Author: denis
7 *
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
11
12#include <utility>
13#include <gtkmm/image.h>
14#include <sigc++/adaptors/bind.h>
15#include <sigc++/functors/mem_fun.h>
16
17#include "ui/icon-loader.h"
18#include "ui/icon-names.h"
19
20namespace Inkscape::UI::Widget {
21
22void AnchorSelector::setupButton(const Glib::ustring& icon, Gtk::ToggleButton& button) {
23 auto const buttonIcon = Gtk::manage(sp_get_icon_image(icon, Gtk::IconSize::NORMAL));
24 button.set_has_frame(false);
25 button.set_child(*buttonIcon);
26 button.set_focusable(false);
27}
28
30{
31 set_halign(Gtk::Align::CENTER);
32 setupButton(INKSCAPE_ICON("boundingbox_top_left"), _buttons[0]);
33 setupButton(INKSCAPE_ICON("boundingbox_top"), _buttons[1]);
34 setupButton(INKSCAPE_ICON("boundingbox_top_right"), _buttons[2]);
35 setupButton(INKSCAPE_ICON("boundingbox_left"), _buttons[3]);
36 setupButton(INKSCAPE_ICON("boundingbox_center"), _buttons[4]);
37 setupButton(INKSCAPE_ICON("boundingbox_right"), _buttons[5]);
38 setupButton(INKSCAPE_ICON("boundingbox_bottom_left"), _buttons[6]);
39 setupButton(INKSCAPE_ICON("boundingbox_bottom"), _buttons[7]);
40 setupButton(INKSCAPE_ICON("boundingbox_bottom_right"), _buttons[8]);
41
42 _container.set_row_homogeneous();
43 _container.set_column_homogeneous(true);
44
45 for (std::size_t i = 0; i < _buttons.size(); ++i) {
46 _buttons[i].signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &AnchorSelector::btn_activated), i));
47
48 _container.attach(_buttons[i], i % 3, i / 3, 1, 1);
49 }
50
51 _selection = 4;
52 _buttons[_selection].set_active();
53
55}
56
57sigc::connection AnchorSelector::connectSelectionChanged(sigc::slot<void ()> slot)
58{
59 return _selectionChanged.connect(std::move(slot));
60}
61
63{
64 if (_selection == index && _buttons[index].get_active() == false) {
65 _buttons[index].set_active(true);
66 }
67 else if (_selection != index && _buttons[index].get_active()) {
68 int old_selection = _selection;
69 _selection = index;
70 _buttons[old_selection].set_active(false);
71 _selectionChanged.emit();
72 }
73}
74
75void AnchorSelector::setAlignment(int horizontal, int vertical)
76{
77 int index = 3 * vertical + horizontal;
78 if (index >= 0 && index < 9) {
79 _buttons[index].set_active(!_buttons[index].get_active());
80 }
81}
82
83} // namespace Inkscape::UI::Widget
84
85/*
86 Local Variables:
87 mode:c++
88 c-file-style:"stroustrup"
89 c-file-offsets:((innamespace . 0)(inline-open . 0))
90 indent-tabs-mode:nil
91 fill-column:99
92 End:
93*/
94// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
sigc::signal< void()> _selectionChanged
std::array< Gtk::ToggleButton, 9 > _buttons
void setupButton(const Glib::ustring &icon, Gtk::ToggleButton &button)
void setAlignment(int horizontal, int vertical)
sigc::connection connectSelectionChanged(sigc::slot< void()>)
Gtk::Image * sp_get_icon_image(Glib::ustring const &icon_name, int size)
Definition: icon-loader.cpp:27
Icon Loader.
Macro for icon names used in Inkscape.
Custom widgets.
Definition: desktop.h:127
static void append(std::vector< T > &target, std::vector< T > &&source)
Definition: shortcuts.cpp:515