diff options
Diffstat (limited to 'src/ui/tools/select-tool.cpp')
| -rw-r--r-- | src/ui/tools/select-tool.cpp | 257 |
1 files changed, 112 insertions, 145 deletions
diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 905e38f2b..b5ec3d88e 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -65,7 +65,7 @@ static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so t static gint drag_escaped = 0; // if non-zero, drag was canceled by esc const std::string& SelectTool::getPrefsPath() { - return SelectTool::prefsPath; + return SelectTool::prefsPath; } const std::string SelectTool::prefsPath = "/tools/select"; @@ -111,7 +111,6 @@ SelectTool::SelectTool() //static gint tolerance = 0; //static bool within_tolerance = false; static bool is_cycling = false; -static bool moved_while_cycling = false; SelectTool::~SelectTool() { @@ -297,7 +296,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } else { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); - this->dragging = TRUE; + this->dragging = TRUE; this->moved = FALSE; gdk_window_set_cursor(window, CursorSelectDragging); @@ -347,11 +346,11 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { break; } case GDK_LEAVE_NOTIFY: - if (!desktop->isWaitingCursor() && !this->dragging) { + if (!desktop->isWaitingCursor() && !this->dragging) { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, this->cursor); - } + } break; case GDK_KEY_PRESS: @@ -379,61 +378,75 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } if (!ret) { - ret = ToolBase::item_handler(item, event); + ret = ToolBase::item_handler(item, event); } return ret; } void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) { - if (this->cycling_cur_item == this->cycling_items.end()) { + if ( this->cycling_items.empty() ) return; - } Inkscape::DrawingItem *arenaitem; - SPItem *item = *cycling_cur_item; - g_assert(item != NULL); - // Deactivate current item - if (std::find(cycling_items_selected_before.begin(), cycling_items_selected_before.end(), item) == cycling_items_selected_before.end() && selection->includes(item)) { - selection->remove(item); + if(cycling_cur_item) { + arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey); + arenaitem->setOpacity(0.3); } - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(0.3); - // Find next item and activate it - std::vector<SPItem *>::iterator next = this->cycling_cur_item; + + + std::vector<SPItem *>::iterator next = cycling_items.end(); + if (scroll_event->direction == GDK_SCROLL_UP) { - ++next; - if (next == this->cycling_items.end() && this->cycling_wrap) { - next = this->cycling_items.begin(); + if (! cycling_cur_item) { + next = cycling_items.begin(); + } else { + next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item ); + g_assert (next != cycling_items.end()); + next++; + if (next == cycling_items.end()) + if ( cycling_wrap ) + next = cycling_items.begin(); + else + next--; } - } else { - if(next == this->cycling_items.begin()) { - next = this->cycling_items.end(); + } else { + if (! cycling_cur_item) { + next = cycling_items.end(); + next--; + } else { + next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item ); + g_assert (next != cycling_items.end()); + if (next == cycling_items.begin()){ + if ( cycling_wrap ) { + next = cycling_items.end(); + next--; + } + } else { + next--; + } } - --next; } - if (next!=this->cycling_items.end()) { - this->cycling_cur_item = next; - item = *next; - g_assert(item != NULL); - } + this->cycling_cur_item = *next; + g_assert(next != cycling_items.end()); + g_assert(cycling_cur_item != NULL); - arenaitem = item->get_arenaitem(desktop->dkey); + arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(1.0); if (shift_pressed) { - selection->add(item); + selection->add(cycling_cur_item); } else { - selection->set(item); + selection->set(cycling_cur_item); } } void SelectTool::sp_select_context_reset_opacities() { - for (std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l ) { + for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l ) { SPItem *item = *l; if (item) { Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey); @@ -443,10 +456,8 @@ void SelectTool::sp_select_context_reset_opacities() { } } - this->cycling_items.clear(); - this->cycling_items_selected_before.clear(); - this->cycling_cur_item = this->cycling_items.end(); this->cycling_items_cmp.clear(); + this->cycling_cur_item = NULL; } bool SelectTool::root_handler(GdkEvent* event) { @@ -533,11 +544,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_MOTION_NOTIFY: { - if (is_cycling) { - moved_while_cycling = true; - } - - tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { Geom::Point const motion_pt(event->motion.x, event->motion.y); @@ -703,7 +710,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->is_started() && !within_tolerance) { // this was a rubberband drag - std::vector<SPItem*> items; + std::vector<SPItem*> items; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); @@ -796,107 +803,67 @@ bool SelectTool::root_handler(GdkEvent* event) { break; case GDK_SCROLL: { - GdkEventScroll *scroll_event = (GdkEventScroll*) event; - - if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed - if (moved_while_cycling) { - moved_while_cycling = false; - this->sp_select_context_reset_opacities(); - } - - is_cycling = true; - - bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; - - /* Rebuild list of items underneath the mouse pointer */ - Geom::Point p = desktop->d2w(desktop->point()); - SPItem *item = desktop->getItemAtPoint(p, true, NULL); - - // Save pointer to current cycle-item so that we can find it again later, in the freshly built list - SPItem *tmp_cur_item = this->cycling_cur_item!=this->cycling_items.end() ? (*(this->cycling_cur_item)) : NULL; - this->cycling_items.clear(); - this->cycling_cur_item = this->cycling_items.end(); - while(item != NULL) { - this->cycling_items.push_back(item); - item = desktop->getItemAtPoint(p, true, item); - } - - /* Compare current item list with item list during previous scroll ... */ - bool item_lists_differ = this->cycling_items != this->cycling_items_cmp; - /* If list of items under mouse pointer hasn't changed ... */ - if (!item_lists_differ) { - // ... find current item in the freshly built list and continue cycling ... - // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead - this->cycling_cur_item = std::find(this->cycling_items.begin(), this->cycling_items.end(), tmp_cur_item); - g_assert(this->cycling_cur_item != this->cycling_items.end() || this->cycling_items.empty()); - } else { - // ... otherwise reset opacities for outdated items ... - Inkscape::DrawingItem *arenaitem; - - for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) { - SPItem *item = *l; - if (item) { - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(1.0); - //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) - if (std::find(this->cycling_items_selected_before.begin(),this->cycling_items_selected_before.end(), item)==this->cycling_items_selected_before.end() && selection->includes(item)) { - selection->remove(item); - } - } - } + GdkEventScroll *scroll_event = (GdkEventScroll*) event; - // ... clear the lists ... + if ( ! (scroll_event->state & GDK_MOD1_MASK)) // do nothing specific if alt was not pressed + break; - this->cycling_items_cmp.clear(); - this->cycling_items_selected_before.clear(); - this->cycling_cur_item = this->cycling_items.end(); + bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; + is_cycling = true; - // ... and rebuild them with the new items. - this->cycling_items_cmp = (this->cycling_items); + /* Rebuild list of items underneath the mouse pointer */ + Geom::Point p = desktop->d2w(desktop->point()); + SPItem *item = desktop->getItemAtPoint(p, true, NULL); + this->cycling_items.clear(); - for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) { - SPItem *item =*l; - if (item) { - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(0.3); + SPItem *tmp = NULL; + while(item != NULL) { + this->cycling_items.push_back(item); + item = desktop->getItemAtPoint(p, true, item); + if (selection->includes(item)) tmp = item; + } - if (selection->includes(item)) { - // already selected items are stored separately, too - this->cycling_items_selected_before.push_back(item); - } - } else { - g_assert_not_reached(); - } + /* Compare current item list with item list during previous scroll ... */ + bool item_lists_differ = this->cycling_items != this->cycling_items_cmp; + + if(item_lists_differ) { + this->sp_select_context_reset_opacities(); + for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) + selection->remove(*l); // deselects the previous content of the cycling loop + this->cycling_items_cmp = (this->cycling_items); + + // set opacities in new stack + for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) { + SPItem *item =*l; + if (item) { + Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey); + arenaitem->setOpacity(0.3); } - - // set the current item to the bottommost one so that the cycling step below re-starts at the top - this->cycling_cur_item = this->cycling_items.end(); - this->cycling_cur_item--; } + } + if(!cycling_cur_item) cycling_cur_item = tmp; - this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); + this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); - // Cycle through the items underneath the mouse pointer, one-by-one - this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed); + // Cycle through the items underneath the mouse pointer, one-by-one + this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed); - ret = TRUE; + ret = TRUE; - GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); - if (w) - { - gtk_window_present(w); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - } + GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); + if (w) { + gtk_window_present(w); + gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); } break; } case GDK_KEY_PRESS: // keybindings for select context - { - { - guint keyval = get_group0_keyval(&event->key); - + { + { + guint keyval = get_group0_keyval(&event->key); + bool alt = ( MOD__ALT(event) || (keyval == GDK_KEY_Alt_L) || (keyval == GDK_KEY_Alt_R) @@ -924,7 +891,7 @@ bool SelectTool::root_handler(GdkEvent* event) { // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectDragging); } @@ -945,15 +912,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift } else { - sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift } else { - sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift } } @@ -968,15 +935,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift } else { - sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift } else { - sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift } } @@ -991,15 +958,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift } else { - sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift } else { - sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift } } @@ -1014,15 +981,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift } else { - sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift } else { - sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift } } @@ -1166,7 +1133,7 @@ bool SelectTool::root_handler(GdkEvent* event) { break; } break; - } + } case GDK_KEY_RELEASE: { guint keyval = get_group0_keyval(&event->key); if (key_is_a_modifier (keyval)) { @@ -1207,7 +1174,7 @@ bool SelectTool::root_handler(GdkEvent* event) { } if (!ret) { - ret = ToolBase::root_handler(event); + ret = ToolBase::root_handler(event); } return ret; |
