Code

moving trunk for module inkscape
[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 "desktop-handles.h"
18 #include "rubberband.h"
20 Inkscape::Rubberband *Inkscape::Rubberband::_instance = NULL;
22 Inkscape::Rubberband::Rubberband()
23     : _desktop(NULL), _canvas(NULL)
24 {
25     
26 }
28 void Inkscape::Rubberband::start(SPDesktop *d, NR::Point const &p)
29 {
30     stop();
31     _desktop = d;
32     _start = p;
33 }
35 void Inkscape::Rubberband::stop()
36 {
37     if (_canvas) {
38         gtk_object_destroy((GtkObject *) _canvas);
39         _canvas = NULL;
40     }
41 }
43 void Inkscape::Rubberband::move(NR::Point const &p)
44 {
45     if (_canvas == NULL) {
46         _canvas = static_cast<CtrlRect *>(sp_canvas_item_new(SP_DT_CONTROLS(_desktop), SP_TYPE_CTRLRECT, NULL));
47     }
49     _desktop->scroll_to_point(&p);
50     _end = p;
52     _canvas->setRectangle(NR::Rect(_start, _end));
53 }
55 NR::Maybe<NR::Rect> Inkscape::Rubberband::getRectangle() const
56 {
57     if (_canvas == NULL) {
58         return NR::Nothing();
59     }
61     return NR::Rect(_start, _end);
62 }
64 Inkscape::Rubberband *Inkscape::Rubberband::get()
65 {
66     if (_instance == NULL) {
67         _instance = new Inkscape::Rubberband;
68     }
70     return _instance;
71 }
73 /*
74   Local Variables:
75   mode:c++
76   c-file-style:"stroustrup"
77   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
78   indent-tabs-mode:nil
79   fill-column:99
80   End:
81 */
82 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :