Code

Force non-interruptible canvas redraws to ensure accurate display while creating...
[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     sp_canvas_clear_forced_full_redraws(_desktop->canvas);
40     if (_canvas) {
41         gtk_object_destroy((GtkObject *) _canvas);
42         _canvas = NULL;
43     }
44 }
46 void Inkscape::Rubberband::move(NR::Point const &p)
47 {
48     if (_canvas == NULL) {
49         _canvas = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL));
50     }
52     _desktop->scroll_to_point(&p);
53     _end = p;
55     sp_canvas_force_full_redraws(_desktop->canvas, 2);
57     _canvas->setRectangle(NR::Rect(_start, _end));
58 }
60 NR::Maybe<NR::Rect> Inkscape::Rubberband::getRectangle() const
61 {
62     if (_canvas == NULL) {
63         return NR::Nothing();
64     }
66     return NR::Rect(_start, _end);
67 }
69 Inkscape::Rubberband *Inkscape::Rubberband::get()
70 {
71     if (_instance == NULL) {
72         _instance = new Inkscape::Rubberband;
73     }
75     return _instance;
76 }
78 /*
79   Local Variables:
80   mode:c++
81   c-file-style:"stroustrup"
82   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83   indent-tabs-mode:nil
84   fill-column:99
85   End:
86 */
87 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :