76028dd82d3ee0204344800dd7681b8c3dec3bd6
1 /** @file
2 * Desktop-bound selectable control object - implementation
3 */
4 /* Authors:
5 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
6 *
7 * Copyright (C) 2009 Authors
8 * Released under GNU GPL, read the file 'COPYING' for more information
9 */
11 #include "ui/tool/control-point-selection.h"
12 #include "ui/tool/event-utils.h"
13 #include "ui/tool/selectable-control-point.h"
15 namespace Inkscape {
16 namespace UI {
18 static SelectableControlPoint::ColorSet default_scp_color_set = {
19 {
20 {0xffffff00, 0x01000000}, // normal fill, stroke
21 {0xff0000ff, 0x01000000}, // mouseover fill, stroke
22 {0x0000ffff, 0x01000000} // clicked fill, stroke
23 },
24 {0x0000ffff, 0x000000ff}, // normal fill, stroke when selected
25 {0xff000000, 0x000000ff}, // mouseover fill, stroke when selected
26 {0xff000000, 0x000000ff} // clicked fill, stroke when selected
27 };
29 SelectableControlPoint::SelectableControlPoint(SPDesktop *d, Geom::Point const &initial_pos,
30 Gtk::AnchorType anchor, SPCtrlShapeType shape, unsigned int size,
31 ControlPointSelection &sel, ColorSet *cset, SPCanvasGroup *group)
32 : ControlPoint (d, initial_pos, anchor, shape, size,
33 cset ? reinterpret_cast<ControlPoint::ColorSet*>(cset)
34 : reinterpret_cast<ControlPoint::ColorSet*>(&default_scp_color_set), group)
35 , _selection (sel)
36 {
37 _selection.allPoints().insert(this);
38 }
39 SelectableControlPoint::SelectableControlPoint(SPDesktop *d, Geom::Point const &initial_pos,
40 Gtk::AnchorType anchor, Glib::RefPtr<Gdk::Pixbuf> pixbuf,
41 ControlPointSelection &sel, ColorSet *cset, SPCanvasGroup *group)
42 : ControlPoint (d, initial_pos, anchor, pixbuf,
43 cset ? reinterpret_cast<ControlPoint::ColorSet*>(cset)
44 : reinterpret_cast<ControlPoint::ColorSet*>(&default_scp_color_set), group)
45 , _selection (sel)
46 {
47 _selection.allPoints().insert(this);
48 }
50 SelectableControlPoint::~SelectableControlPoint()
51 {
52 _selection.erase(this);
53 _selection.allPoints().erase(this);
54 }
56 bool SelectableControlPoint::grabbed(GdkEventMotion *)
57 {
58 // if a point is dragged while not selected, it should select itself
59 if (!selected()) {
60 _takeSelection();
61 }
62 _selection._pointGrabbed(this);
63 return false;
64 }
66 void SelectableControlPoint::dragged(Geom::Point &new_pos, GdkEventMotion *event)
67 {
68 _selection._pointDragged(new_pos, event);
69 }
71 void SelectableControlPoint::ungrabbed(GdkEventButton *)
72 {
73 _selection._pointUngrabbed();
74 }
76 bool SelectableControlPoint::clicked(GdkEventButton *event)
77 {
78 if (_selection._pointClicked(this, event))
79 return true;
81 if (event->button != 1) return false;
82 if (held_shift(*event)) {
83 if (selected()) {
84 _selection.erase(this);
85 } else {
86 _selection.insert(this);
87 }
88 } else {
89 _takeSelection();
90 }
91 return true;
92 }
94 void SelectableControlPoint::_takeSelection()
95 {
96 _selection.clear();
97 _selection.insert(this);
98 }
100 bool SelectableControlPoint::selected() const
101 {
102 SelectableControlPoint *p = const_cast<SelectableControlPoint*>(this);
103 return _selection.find(p) != _selection.end();
104 }
106 void SelectableControlPoint::_setState(State state)
107 {
108 if (!selected()) {
109 ControlPoint::_setState(state);
110 return;
111 }
113 ColorSet *cset = reinterpret_cast<ColorSet*>(_cset);
114 ColorEntry current = {0, 0};
115 switch (state) {
116 case STATE_NORMAL:
117 current = cset->selected_normal; break;
118 case STATE_MOUSEOVER:
119 current = cset->selected_mouseover; break;
120 case STATE_CLICKED:
121 current = cset->selected_clicked; break;
122 }
123 _setColors(current);
124 _state = state;
125 }
127 } // namespace UI
128 } // namespace Inkscape
130 /*
131 Local Variables:
132 mode:c++
133 c-file-style:"stroustrup"
134 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
135 indent-tabs-mode:nil
136 fill-column:99
137 End:
138 */
139 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :