e59d6d5cfff64f9e09d9c21880a7b27c406973d1
1 /** @file
2 * Desktop-bound visual control object
3 */
4 /* Authors:
5 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
6 *
7 * Copyright (C) 2009 Authors
8 * Released under GNU GPL, read the file 'COPYING' for more information
9 */
11 #ifndef SEEN_UI_TOOL_CONTROL_POINT_H
12 #define SEEN_UI_TOOL_CONTROL_POINT_H
14 #include <boost/utility.hpp>
15 #include <sigc++/sigc++.h>
16 #include <gdkmm.h>
17 #include <gtkmm.h>
18 #include <2geom/point.h>
20 #include "display/display-forward.h"
21 #include "forward.h"
22 #include "util/accumulators.h"
23 #include "display/sodipodi-ctrl.h"
25 namespace Inkscape {
26 namespace UI {
28 // most of the documentation is in the .cpp file
30 class ControlPoint : boost::noncopyable, public sigc::trackable {
31 public:
32 typedef Inkscape::Util::ReverseInterruptible RInt;
33 typedef Inkscape::Util::Interruptible Int;
34 // these have to be public, because GCC doesn't allow protected types in constructors,
35 // even if the constructors are protected themselves.
36 struct ColorEntry {
37 guint32 fill;
38 guint32 stroke;
39 };
40 struct ColorSet {
41 ColorEntry normal;
42 ColorEntry mouseover;
43 ColorEntry clicked;
44 };
45 enum State {
46 STATE_NORMAL,
47 STATE_MOUSEOVER,
48 STATE_CLICKED
49 };
51 virtual ~ControlPoint();
53 /// @name Adjust the position of the control point
54 /// @{
55 /** Current position of the control point. */
56 Geom::Point const &position() const { return _position; }
57 operator Geom::Point const &() { return _position; }
58 virtual void move(Geom::Point const &pos);
59 virtual void setPosition(Geom::Point const &pos);
60 virtual void transform(Geom::Matrix const &m);
61 /// @}
63 /// @name Toggle the point's visibility
64 /// @{
65 bool visible() const;
66 virtual void setVisible(bool v);
67 /// @}
69 /// @name Transfer grab from another event handler
70 /// @{
71 void transferGrab(ControlPoint *from, GdkEventMotion *event);
72 /// @}
74 /// @name Receive notifications about control point events
75 /// @{
76 sigc::signal<void, Geom::Point const &, Geom::Point &, GdkEventMotion*> signal_dragged;
77 sigc::signal<bool, GdkEventButton*>::accumulated<RInt> signal_clicked;
78 sigc::signal<bool, GdkEventButton*>::accumulated<RInt> signal_doubleclicked;
79 sigc::signal<bool, GdkEventMotion*>::accumulated<Int> signal_grabbed;
80 sigc::signal<void, GdkEventButton*> signal_ungrabbed;
81 /// @}
83 /// @name Inspect the state of the control point
84 /// @{
85 State state() { return _state; }
86 bool mouseovered() { return this == mouseovered_point; }
87 /// @}
89 static ControlPoint *mouseovered_point;
90 static sigc::signal<void, ControlPoint*> signal_mouseover_change;
91 static Glib::ustring format_tip(char const *format, ...) G_GNUC_PRINTF(1,2);
93 // temporarily public, until snapping is refactored a little
94 virtual bool _eventHandler(GdkEvent *event);
96 protected:
97 ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, Gtk::AnchorType anchor,
98 SPCtrlShapeType shape, unsigned int size, ColorSet *cset = 0, SPCanvasGroup *group = 0);
99 ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, Gtk::AnchorType anchor,
100 Glib::RefPtr<Gdk::Pixbuf> pixbuf, ColorSet *cset = 0, SPCanvasGroup *group = 0);
102 /// @name Manipulate the control point's appearance in subclasses
103 /// @{
104 virtual void _setState(State state);
105 void _setColors(ColorEntry c);
107 unsigned int _size() const;
108 SPCtrlShapeType _shape() const;
109 GtkAnchorType _anchor() const;
110 Glib::RefPtr<Gdk::Pixbuf> _pixbuf();
112 void _setSize(unsigned int size);
113 void _setShape(SPCtrlShapeType shape);
114 void _setAnchor(GtkAnchorType anchor);
115 void _setPixbuf(Glib::RefPtr<Gdk::Pixbuf>);
116 /// @}
118 virtual Glib::ustring _getTip(unsigned /*state*/) { return ""; }
119 virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) { return ""; }
120 virtual bool _hasDragTips() { return false; }
122 SPDesktop *const _desktop; ///< The desktop this control point resides on.
123 SPCanvasItem * _canvas_item; ///< Visual representation of the control point.
124 ColorSet *_cset; ///< Colors used to represent the point
125 State _state;
127 static int const _grab_event_mask;
128 static Geom::Point const &_last_click_event_point() { return _drag_event_origin; }
129 static Geom::Point const &_last_drag_origin() { return _drag_origin; }
131 private:
132 ControlPoint(ControlPoint const &other);
133 void operator=(ControlPoint const &other);
135 static int _event_handler(SPCanvasItem *item, GdkEvent *event, ControlPoint *point);
136 static void _setMouseover(ControlPoint *, unsigned state);
137 static void _clearMouseover();
138 bool _updateTip(unsigned state);
139 bool _updateDragTip(GdkEventMotion *event);
140 void _setDefaultColors();
141 void _commonInit();
143 Geom::Point _position; ///< Current position in desktop coordinates
144 gulong _event_handler_connection;
146 static Geom::Point _drag_event_origin;
147 static Geom::Point _drag_origin;
148 static bool _event_grab;
149 static bool _drag_initiated;
150 };
152 extern ControlPoint::ColorSet invisible_cset;
155 } // namespace UI
156 } // namespace Inkscape
158 #endif
160 /*
161 Local Variables:
162 mode:c++
163 c-file-style:"stroustrup"
164 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165 indent-tabs-mode:nil
166 fill-column:99
167 End:
168 */
169 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :