1 /**
2 * \brief Filter Effects dialog
3 *
4 * Authors:
5 * Nicholas Bishop <nicholasbishop@gmail.com>
6 *
7 * Copyright (C) 2007 Authors
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
12 #ifndef INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
13 #define INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
15 #include <gtkmm/adjustment.h>
16 #include <gtkmm/alignment.h>
17 #include <gtkmm/box.h>
18 #include <gtkmm/buttonbox.h>
19 #include <gtkmm/comboboxtext.h>
20 #include <gtkmm/drawingarea.h>
21 #include <gtkmm/frame.h>
22 #include <gtkmm/liststore.h>
23 #include <gtkmm/menu.h>
24 #include <gtkmm/sizegroup.h>
25 #include <gtkmm/treeview.h>
27 #include "attributes.h"
28 #include "dialog.h"
29 #include "sp-filter.h"
30 #include "ui/widget/combo-enums.h"
31 #include "ui/widget/spin-slider.h"
33 using namespace Inkscape::UI::Widget;
35 namespace Inkscape {
36 namespace UI {
37 namespace Dialog {
39 class DualSpinButton;
40 class MultiSpinButton;
41 class FilterEffectsDialog : public Dialog {
42 public:
43 ~FilterEffectsDialog();
45 void set_attrs_locked(const bool);
47 static FilterEffectsDialog *create() { return new FilterEffectsDialog(); }
48 private:
49 class SignalObserver;
51 class FilterModifier : public Gtk::VBox
52 {
53 public:
54 FilterModifier(FilterEffectsDialog&);
55 ~FilterModifier();
57 SPFilter* get_selected_filter();
58 void select_filter(const SPFilter*);
60 sigc::signal<void>& signal_filter_changed()
61 {
62 return _signal_filter_changed;
63 }
64 private:
65 class Columns : public Gtk::TreeModel::ColumnRecord
66 {
67 public:
68 Columns()
69 {
70 add(filter);
71 add(label);
72 add(sel);
73 }
75 Gtk::TreeModelColumn<SPFilter*> filter;
76 Gtk::TreeModelColumn<Glib::ustring> label;
77 Gtk::TreeModelColumn<int> sel;
78 };
80 class CellRendererSel : public Gtk::CellRenderer
81 {
82 public:
83 CellRendererSel();
85 Glib::PropertyProxy<int> property_sel()
86 {
87 return _sel.get_proxy();
88 }
89 protected:
90 virtual void get_size_vfunc(Gtk::Widget&, const Gdk::Rectangle*,
91 int*, int*, int*, int*) const;
92 virtual void render_vfunc(const Glib::RefPtr<Gdk::Drawable>& win, Gtk::Widget& w,
93 const Gdk::Rectangle& bg_area, const Gdk::Rectangle& cell_area,
94 const Gdk::Rectangle& expose_area, Gtk::CellRendererState flags);
95 private:
96 const int _size;
97 Glib::Property<int> _sel;
98 };
100 static void on_activate_desktop(Application*, SPDesktop*, FilterModifier*);
101 void on_document_replaced(SPDesktop*, SPDocument*)
102 {
103 update_filters();
104 }
106 static void on_inkscape_change_selection(Application *, Selection *, FilterModifier*);
108 void update_selection(Selection *);
109 void on_filter_selection_changed();
111 void update_filters();
112 void filter_list_button_press(GdkEventButton*);
113 void filter_list_button_release(GdkEventButton*);
114 void add_filter();
115 void remove_filter();
116 void duplicate_filter();
117 void rename_filter();
119 sigc::connection _doc_replaced;
120 sigc::connection _resource_changed;
122 FilterEffectsDialog& _dialog;
123 Gtk::TreeView _list;
124 Glib::RefPtr<Gtk::ListStore> _model;
125 Columns _columns;
126 CellRendererSel _cell_sel;
127 Gtk::Button _add;
128 Glib::RefPtr<Gtk::Menu> _menu;
129 sigc::signal<void> _signal_filter_changed;
130 std::auto_ptr<SignalObserver> _observer;
131 };
133 class PrimitiveColumns : public Gtk::TreeModel::ColumnRecord
134 {
135 public:
136 PrimitiveColumns()
137 {
138 add(primitive);
139 add(type_id);
140 add(type);
141 add(id);
142 }
144 Gtk::TreeModelColumn<SPFilterPrimitive*> primitive;
145 Gtk::TreeModelColumn<NR::FilterPrimitiveType> type_id;
146 Gtk::TreeModelColumn<Glib::ustring> type;
147 Gtk::TreeModelColumn<Glib::ustring> id;
148 };
150 class CellRendererConnection : public Gtk::CellRenderer
151 {
152 public:
153 CellRendererConnection();
154 Glib::PropertyProxy<void*> property_primitive();
156 static const int size = 24;
158 void set_text_width(const int w);
159 int get_text_width() const;
160 protected:
161 virtual void get_size_vfunc(Gtk::Widget& widget, const Gdk::Rectangle* cell_area,
162 int* x_offset, int* y_offset, int* width, int* height) const;
163 private:
164 // void* should be SPFilterPrimitive*, some weirdness with properties prevents this
165 Glib::Property<void*> _primitive;
166 int _text_width;
167 };
169 class PrimitiveList : public Gtk::TreeView
170 {
171 public:
172 PrimitiveList(FilterEffectsDialog&);
174 sigc::signal<void>& signal_primitive_changed();
176 void update();
177 void set_menu(Glib::RefPtr<Gtk::Menu>);
179 SPFilterPrimitive* get_selected();
180 void select(SPFilterPrimitive *prim);
182 int primitive_count() const;
183 protected:
184 bool on_expose_signal(GdkEventExpose*);
185 bool on_button_press_event(GdkEventButton*);
186 bool on_motion_notify_event(GdkEventMotion*);
187 bool on_button_release_event(GdkEventButton*);
188 void on_drag_end(const Glib::RefPtr<Gdk::DragContext>&);
189 private:
190 int init_text();
192 bool do_connection_node(const Gtk::TreeIter& row, const int input, std::vector<Gdk::Point>& points,
193 const int ix, const int iy);
194 const Gtk::TreeIter find_result(const Gtk::TreeIter& start, const int attr, int& src_id);
195 int find_index(const Gtk::TreeIter& target);
196 void draw_connection(const Gtk::TreeIter&, const int attr, const int text_start_x,
197 const int x1, const int y1, const int row_count);
198 void sanitize_connections(const Gtk::TreeIter& prim_iter);
199 void on_primitive_selection_changed();
200 bool on_scroll_timeout();
202 FilterEffectsDialog& _dialog;
203 Glib::RefPtr<Gtk::ListStore> _model;
204 PrimitiveColumns _columns;
205 CellRendererConnection _connection_cell;
206 Glib::RefPtr<Gtk::Menu> _primitive_menu;
207 Glib::RefPtr<Pango::Layout> _vertical_layout;
208 int _in_drag;
209 SPFilterPrimitive* _drag_prim;
210 sigc::signal<void> _signal_primitive_changed;
211 sigc::connection _scroll_connection;
212 int _autoscroll;
213 std::auto_ptr<SignalObserver> _observer;
214 };
216 FilterEffectsDialog();
217 void init_settings_widgets();
219 // Handlers
220 void add_primitive();
221 void remove_primitive();
222 void duplicate_primitive();
223 void convolve_order_changed();
225 void set_attr_direct(const AttrWidget*);
226 void set_child_attr_direct(const AttrWidget*);
227 void set_attr(SPObject*, const SPAttributeEnum, const gchar* val);
228 void update_settings_view();
229 void update_settings_sensitivity();
230 void update_color_matrix();
232 // Filter effect selection
233 FilterModifier _filter_modifier;
235 // View/add primitives
236 Gtk::VBox _primitive_box;
237 PrimitiveList _primitive_list;
238 UI::Widget::ComboBoxEnum<NR::FilterPrimitiveType> _add_primitive_type;
239 Gtk::Button _add_primitive;
241 // Bottom pane (filter effect primitive settings)
242 Gtk::VBox _settings_box;
243 Gtk::Label _empty_settings;
245 class Settings;
246 class MatrixAttr;
247 class ColorMatrixValues;
248 class LightSourceControl;
249 Settings* _settings;
250 Glib::RefPtr<Gtk::SizeGroup> _sizegroup;
252 // Color Matrix
253 ColorMatrixValues* _color_matrix_values;
255 // Convolve Matrix
256 MatrixAttr* _convolve_matrix;
257 DualSpinButton* _convolve_order;
258 MultiSpinButton* _convolve_target;
260 // For controlling setting sensitivity
261 Gtk::Widget* _k1, *_k2, *_k3, *_k4;
262 Gtk::Widget* _ct_table, *_ct_slope, *_ct_intercept, *_ct_amplitude, *_ct_exponent, *_ct_offset;
264 // To prevent unwanted signals
265 bool _locked;
266 bool _attr_lock;
268 FilterEffectsDialog(FilterEffectsDialog const &d);
269 FilterEffectsDialog& operator=(FilterEffectsDialog const &d);
270 };
272 } // namespace Dialog
273 } // namespace UI
274 } // namespace Inkscape
276 #endif // INKSCAPE_UI_DIALOG_FILTER_EFFECTS_H
278 /*
279 Local Variables:
280 mode:c++
281 c-file-style:"stroustrup"
282 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
283 indent-tabs-mode:nil
284 fill-column:99
285 End:
286 */
287 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :