Code

0de3cd763a7dd99b8a98b49014b2947b060b2c80
[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), _started(false)
25 {
27 }
29 void Inkscape::Rubberband::start(SPDesktop *d, NR::Point const &p)
30 {
31     stop();
32     _desktop = d;
33     _start = p;
34     _started = true;
36     sp_canvas_force_full_redraw_after_interruptions(_desktop->canvas, 5);
37 }
39 void Inkscape::Rubberband::stop()
40 {
41     _started = false;
43     if (_canvas) {
44         GtkObject *temp = _canvas;
45         _canvas = NULL;
46         gtk_object_destroy(temp);
47         sp_canvas_end_forced_full_redraws(_desktop->canvas);
48     }
49 }
51 void Inkscape::Rubberband::move(NR::Point const &p)
52 {
53     if (_canvas == NULL) {
54         _canvas = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL));
55     }
57     _desktop->scroll_to_point(&p);
58     _end = p;
60     _canvas->setRectangle(NR::Rect(_start, _end));
61 }
63 NR::Maybe<NR::Rect> Inkscape::Rubberband::getRectangle() const
64 {
65     if (_canvas == NULL) {
66         return NR::Nothing();
67     }
69     return NR::Rect(_start, _end);
70 }
72 Inkscape::Rubberband *Inkscape::Rubberband::get()
73 {
74     if (_instance == NULL) {
75         _instance = new Inkscape::Rubberband;
76     }
78     return _instance;
79 }
81 bool Inkscape::Rubberband::is_started()
82 {
83     return _started;
84 }
86 /*
87   Local Variables:
88   mode:c++
89   c-file-style:"stroustrup"
90   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91   indent-tabs-mode:nil
92   fill-column:99
93   End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :