Code

switch to sigc++ signal for "release"
[inkscape.git] / src / rubberband.cpp
1 #define __RUBBERBAND_C__
3 /**
4  * \file src/rubberband.cpp
5  * \brief Rubberbanding selector
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * Copyright (C) 1999-2002 Lauris Kaplinski
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "display/sodipodi-ctrlrect.h"
16 #include "desktop.h"
17 #include "inkscape.h"
18 #include "desktop-handles.h"
19 #include "rubberband.h"
21 Inkscape::Rubberband *Inkscape::Rubberband::_instance = NULL;
23 Inkscape::Rubberband::Rubberband()
24     : _desktop(SP_ACTIVE_DESKTOP), _canvas(NULL)
25 {
27 }
29 void Inkscape::Rubberband::start(SPDesktop *d, NR::Point const &p)
30 {
31     stop();
32     _desktop = d;
33     _start = p;
34 }
36 void Inkscape::Rubberband::stop()
37 {
38     if (_canvas) {
39         gtk_object_destroy((GtkObject *) _canvas);
40         _canvas = NULL;
41     }
42 }
44 void Inkscape::Rubberband::move(NR::Point const &p)
45 {
46     if (_canvas == NULL) {
47         _canvas = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL));
48     }
50     _desktop->scroll_to_point(&p);
51     _end = p;
53     _canvas->setRectangle(NR::Rect(_start, _end));
54 }
56 NR::Maybe<NR::Rect> Inkscape::Rubberband::getRectangle() const
57 {
58     if (_canvas == NULL) {
59         return NR::Nothing();
60     }
62     return NR::Rect(_start, _end);
63 }
65 Inkscape::Rubberband *Inkscape::Rubberband::get()
66 {
67     if (_instance == NULL) {
68         _instance = new Inkscape::Rubberband;
69     }
71     return _instance;
72 }
74 /*
75   Local Variables:
76   mode:c++
77   c-file-style:"stroustrup"
78   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79   indent-tabs-mode:nil
80   fill-column:99
81   End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :