control-point.h revision 0d68d82e47abab250c99dd534da2e2d26b697b2d
2521N/A/** @file
2521N/A * Desktop-bound visual control object
2521N/A */
3998N/A/* Authors:
2521N/A * Krzysztof KosiƄski <tweenk.pl@gmail.com>
2521N/A *
2521N/A * Copyright (C) 2009 Authors
2521N/A * Released under GNU GPL, read the file 'COPYING' for more information
2521N/A */
2521N/A
2521N/A#ifndef SEEN_UI_TOOL_CONTROL_POINT_H
2521N/A#define SEEN_UI_TOOL_CONTROL_POINT_H
2521N/A
2521N/A#include <boost/utility.hpp>
2521N/A#include <stddef.h>
2521N/A#include <sigc++/sigc++.h>
2521N/A#include <gdkmm.h>
2521N/A#include <gtkmm.h>
2521N/A#include <2geom/point.h>
2521N/A#include "util/accumulators.h"
2521N/A#include "display/sodipodi-ctrl.h"
2521N/A#include "event-context.h"
2521N/A
2521N/Aclass SPDesktop;
3998N/A
3998N/Anamespace Inkscape {
2521N/Anamespace UI {
2521N/A
2521N/A// most of the documentation is in the .cpp file
2521N/A
2521N/Aclass ControlPoint : boost::noncopyable, public sigc::trackable {
2521N/Apublic:
3998N/A typedef Inkscape::Util::ReverseInterruptible RInt;
3998N/A typedef Inkscape::Util::Interruptible Int;
3998N/A // these have to be public, because GCC doesn't allow protected types in constructors,
3998N/A // even if the constructors are protected themselves.
3998N/A struct ColorEntry {
3998N/A guint32 fill;
2892N/A guint32 stroke;
2892N/A };
2892N/A struct ColorSet {
2892N/A ColorEntry normal;
2892N/A ColorEntry mouseover;
3998N/A ColorEntry clicked;
3998N/A };
3998N/A enum State {
3998N/A STATE_NORMAL,
3998N/A STATE_MOUSEOVER,
3998N/A STATE_CLICKED
3998N/A };
4474N/A
3998N/A virtual ~ControlPoint();
3998N/A
2892N/A /// @name Adjust the position of the control point
2892N/A /// @{
5403N/A /** Current position of the control point. */
5403N/A Geom::Point const &position() const { return _position; }
5403N/A operator Geom::Point const &() { return _position; }
5403N/A virtual void move(Geom::Point const &pos);
5403N/A virtual void setPosition(Geom::Point const &pos);
5403N/A virtual void transform(Geom::Affine const &m);
5403N/A /// @}
5403N/A
5403N/A /// @name Toggle the point's visibility
5403N/A /// @{
5403N/A bool visible() const;
5403N/A virtual void setVisible(bool v);
5403N/A /// @}
5403N/A
5403N/A /// @name Transfer grab from another event handler
5403N/A /// @{
2521N/A void transferGrab(ControlPoint *from, GdkEventMotion *event);
2521N/A /// @}
2521N/A
2521N/A /// @name Receive notifications about control point events
2521N/A /// @{
5403N/A /*sigc::signal<void, Geom::Point const &, Geom::Point &, GdkEventMotion*> signal_dragged;
5403N/A sigc::signal<bool, GdkEventButton*>::accumulated<RInt> signal_clicked;
5403N/A sigc::signal<bool, GdkEventButton*>::accumulated<RInt> signal_doubleclicked;
5403N/A sigc::signal<bool, GdkEventMotion*>::accumulated<Int> signal_grabbed;
2521N/A sigc::signal<void, GdkEventButton*> signal_ungrabbed;*/
2521N/A /// @}
2521N/A
2521N/A /// @name Inspect the state of the control point
2521N/A /// @{
2521N/A State state() { return _state; }
2521N/A bool mouseovered() { return this == mouseovered_point; }
2521N/A /// @}
2521N/A
5403N/A static ControlPoint *mouseovered_point;
5403N/A static sigc::signal<void, ControlPoint*> signal_mouseover_change;
5403N/A static Glib::ustring format_tip(char const *format, ...) G_GNUC_PRINTF(1,2);
5403N/A
5403N/A // temporarily public, until snap delay is refactored a little
5403N/A virtual bool _eventHandler(SPEventContext *event_context, GdkEvent *event);
5403N/A
5403N/Aprotected:
5403N/A ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, Gtk::AnchorType anchor,
5403N/A SPCtrlShapeType shape, unsigned int size, ColorSet *cset = 0, SPCanvasGroup *group = 0);
5403N/A ControlPoint(SPDesktop *d, Geom::Point const &initial_pos, Gtk::AnchorType anchor,
5403N/A Glib::RefPtr<Gdk::Pixbuf> pixbuf, ColorSet *cset = 0, SPCanvasGroup *group = 0);
5403N/A
5403N/A /// @name Handle control point events in subclasses
5403N/A /// @{
5403N/A /**
5403N/A * Called when the user moves the point beyond the drag tolerance with the first button held
5403N/A * down. Return true if you called transferGrab() during this method.
5403N/A * @param event Motion event when drag tolerance was exceeded */
2521N/A virtual bool grabbed(GdkEventMotion *event);
2521N/A /**
2521N/A * Called while dragging, but before moving the knot to new position.
2521N/A * @param pos Old position, always equal to position()
2521N/A * @param new_pos New position (after drag). This is passed as a non-const reference,
2521N/A * so you can change it from the handler - that's how constrained dragging is implemented.
2521N/A * @param event Motion event */
2521N/A virtual void dragged(Geom::Point &new_pos, GdkEventMotion *event);
2521N/A /**
2521N/A * @var ControlPoint::signal_ungrabbed
2521N/A * Emitted when the control point finishes a drag.
2521N/A * @param event Button release event
2521N/A */
2521N/A virtual void ungrabbed(GdkEventButton *event);
2521N/A /**
5403N/A * Called when the control point is clicked, at mouse button release. Your override should
5403N/A * return true if the click had some effect. If it did nothing, return false. Improperly
5403N/A * implementing this method can cause the default context menu not to appear when a control
5403N/A * point is right-clicked.
5403N/A * @param event Button release event */
5403N/A virtual bool clicked(GdkEventButton *event);
5403N/A /**
5403N/A * Called when the control point is doubleclicked, at mouse button release.
5403N/A * @param event Button release event */
5403N/A virtual bool doubleclicked(GdkEventButton *);
5403N/A /// @}
5403N/A
5403N/A /// @name Manipulate the control point's appearance in subclasses
5403N/A /// @{
5403N/A virtual void _setState(State state);
5403N/A void _setColors(ColorEntry c);
5403N/A
5403N/A unsigned int _size() const;
5403N/A SPCtrlShapeType _shape() const;
5403N/A GtkAnchorType _anchor() const;
5403N/A Glib::RefPtr<Gdk::Pixbuf> _pixbuf();
5403N/A
5403N/A void _setSize(unsigned int size);
5403N/A void _setShape(SPCtrlShapeType shape);
5403N/A void _setAnchor(GtkAnchorType anchor);
5403N/A void _setPixbuf(Glib::RefPtr<Gdk::Pixbuf>);
5403N/A /// @}
5403N/A
5403N/A virtual Glib::ustring _getTip(unsigned /*state*/) { return ""; }
5403N/A virtual Glib::ustring _getDragTip(GdkEventMotion */*event*/) { return ""; }
5403N/A virtual bool _hasDragTips() { return false; }
5403N/A
5403N/A SPDesktop *const _desktop; ///< The desktop this control point resides on.
5403N/A SPCanvasItem * _canvas_item; ///< Visual representation of the control point.
5403N/A ColorSet *_cset; ///< Colors used to represent the point
5403N/A State _state;
5403N/A
5403N/A static Geom::Point const &_last_click_event_point() { return _drag_event_origin; }
5403N/A static Geom::Point const &_last_drag_origin() { return _drag_origin; }
5403N/A static bool _is_drag_cancelled(GdkEventMotion *event);
5403N/A static int const _grab_event_mask;
5403N/A
5403N/Aprivate:
5403N/A ControlPoint(ControlPoint const &other);
5403N/A void operator=(ControlPoint const &other);
5403N/A
5403N/A static int _event_handler(SPCanvasItem *item, GdkEvent *event, ControlPoint *point);
5403N/A static void _setMouseover(ControlPoint *, unsigned state);
5403N/A static void _clearMouseover();
5403N/A bool _updateTip(unsigned state);
5403N/A bool _updateDragTip(GdkEventMotion *event);
5403N/A void _setDefaultColors();
5403N/A void _commonInit();
5403N/A
5403N/A Geom::Point _position; ///< Current position in desktop coordinates
5403N/A gulong _event_handler_connection;
5403N/A
5403N/A static Geom::Point _drag_event_origin;
5403N/A static Geom::Point _drag_origin;
5403N/A static bool _event_grab;
5403N/A static bool _drag_initiated;
5403N/A};
5403N/A
5403N/Aextern ControlPoint::ColorSet invisible_cset;
5403N/A
5403N/A
5403N/A} // namespace UI
5403N/A} // namespace Inkscape
5403N/A
2521N/A#endif
2521N/A
4538N/A/*
4538N/A Local Variables:
4538N/A mode:c++
4538N/A c-file-style:"stroustrup"
4538N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
4538N/A indent-tabs-mode:nil
4538N/A fill-column:99
4538N/A End:
4538N/A*/
4538N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
4538N/A