summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/dash-selector.h
blob: 21b370a8eecdbde2eea0dc171d9eb5219473f92a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_SP_DASH_SELECTOR_NEW_H
#define SEEN_SP_DASH_SELECTOR_NEW_H

/* Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   Maximilian Albert <maximilian.albert> (gtkmm-ification)
 *
 * Copyright (C) 2002 Lauris Kaplinski
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "ui/widget/spinbutton.h"
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
#include <gtkmm/liststore.h>

#include <sigc++/signal.h>

#include "scrollprotected.h"

namespace Inkscape {
namespace UI {
namespace Widget {

/**
 * Class that wraps a combobox and spinbutton for selecting dash patterns.
 */
class DashSelector : public Gtk::Box {
public:
    DashSelector();
    ~DashSelector() override;

    /**
     * Get and set methods for dashes
     */
    void set_dash(const std::vector<double>& dash, double offset);

    const std::vector<double>& get_dash(double* offset) const;

    sigc::signal<void ()> changed_signal;

    double get_offset();

private:

    /**
     * Initialize dashes list from preferences
     */
    static void init_dashes();

    /**
     * Fill a pixbuf with the dash pattern using standard cairo drawing
     */
    Cairo::RefPtr<Cairo::Surface> sp_dash_to_pixbuf(const std::vector<double>& pattern);

    /**
     * Fill a pixbuf with text standard cairo drawing
     */
    Cairo::RefPtr<Cairo::Surface> sp_text_to_pixbuf(const char* text);

    /**
     * Callback for combobox image renderer
     */
    void prepareImageRenderer( Gtk::TreeModel::const_iterator const &row );

    /**
     * Callback for offset adjustment changing
     */
    void offset_value_changed();

    /**
     * Callback for combobox selection changing
     */
    void on_selection();

    /**
     * Combobox columns
     */
    class DashColumns : public Gtk::TreeModel::ColumnRecord {
    public:
        Gtk::TreeModelColumn<std::size_t> dash;
        DashColumns() {
            add(dash);
        }
    };
    DashColumns dash_columns;
    Glib::RefPtr<Gtk::ListStore> _dash_store;
    ScrollProtected<Gtk::ComboBox> _dash_combo;
    Gtk::CellRendererPixbuf _image_renderer;
    Glib::RefPtr<Gtk::Adjustment> _offset;
    Inkscape::UI::Widget::SpinButton *_sb;
    static gchar const *const _prefs_path;
    int _preview_width;
    int _preview_height;
    int _preview_lineheight;
    std::vector<double>* _pattern = nullptr;
};

} // namespace Widget
} // namespace UI
} // namespace Inkscape

#endif // SEEN_SP_DASH_SELECTOR_NEW_H

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :