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;
35 sp_canvas_force_full_redraw_after_interruptions(_desktop->canvas, 5);
36 }
38 void Inkscape::Rubberband::stop()
39 {
40 if (_canvas) {
41 gtk_object_destroy((GtkObject *) _canvas);
42 _canvas = NULL;
43 sp_canvas_end_forced_full_redraws(_desktop->canvas);
44 }
45 }
47 void Inkscape::Rubberband::move(NR::Point const &p)
48 {
49 if (_canvas == NULL) {
50 _canvas = static_cast<CtrlRect *>(sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRLRECT, NULL));
51 }
53 _desktop->scroll_to_point(&p);
54 _end = p;
56 _canvas->setRectangle(NR::Rect(_start, _end));
57 }
59 NR::Maybe<NR::Rect> Inkscape::Rubberband::getRectangle() const
60 {
61 if (_canvas == NULL) {
62 return NR::Nothing();
63 }
65 return NR::Rect(_start, _end);
66 }
68 Inkscape::Rubberband *Inkscape::Rubberband::get()
69 {
70 if (_instance == NULL) {
71 _instance = new Inkscape::Rubberband;
72 }
74 return _instance;
75 }
77 /*
78 Local Variables:
79 mode:c++
80 c-file-style:"stroustrup"
81 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
82 indent-tabs-mode:nil
83 fill-column:99
84 End:
85 */
86 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :