| 158 | |
| 159 | template<class FeatureType> |
| 160 | void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) { |
| 161 | bool left_click = event.LeftDown(); |
| 162 | bool left_double = event.LeftDClick(); |
| 163 | shift_down = event.ShiftDown(); |
| 164 | ctrl_down = event.CmdDown(); |
| 165 | alt_down = event.AltDown(); |
| 166 | |
| 167 | mouse_pos = event.GetPosition(); |
| 168 | |
| 169 | if (event.Leaving()) { |
| 170 | mouse_pos = Vector2D(); |
| 171 | parent->Render(); |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | if (!dragging) { |
| 176 | int max_layer = INT_MIN; |
| 177 | active_feature = nullptr; |
| 178 | for (auto& feature : features) { |
| 179 | if (feature.IsMouseOver(mouse_pos) && feature.layer >= max_layer) { |
| 180 | active_feature = &feature; |
| 181 | max_layer = feature.layer; |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | if (dragging) { |
| 187 | // continue drag |
| 188 | if (event.LeftIsDown()) { |
| 189 | for (auto sel : sel_features) |
| 190 | sel->UpdateDrag(mouse_pos - drag_start, shift_down); |
| 191 | for (auto sel : sel_features) |
| 192 | UpdateDrag(sel); |
| 193 | Commit(); |
| 194 | } |
| 195 | // end drag |
| 196 | else { |
| 197 | dragging = false; |
| 198 | |
| 199 | // mouse didn't move, fiddle with selection |
| 200 | if (active_feature && !active_feature->HasMoved()) { |
| 201 | // Don't deselect stuff that was selected in this click's mousedown event |
| 202 | if (!sel_changed) { |
| 203 | if (ctrl_down) |
| 204 | RemoveSelection(active_feature); |
| 205 | else |
| 206 | SetSelection(active_feature, true); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | active_feature = nullptr; |
| 211 | parent->ReleaseMouse(); |
| 212 | parent->SetFocus(); |
| 213 | } |
| 214 | } |
| 215 | else if (holding) { |
| 216 | if (!event.LeftIsDown()) { |
| 217 | holding = false; |
nothing calls this directly
no test coverage detected