private void EndSelectionHandling() { Moving = true; LevEditor.PreserveSelection(); AdjustForGrid(CurrentPos); _moveStartPosition = CurrentPos; }
public void MouseUp() { if (RectSelecting || FreeSelecting) { double selectionxMin = 0; double selectionxMax = 0; double selectionyMax = 0; double selectionyMin = 0; if (RectSelecting) { selectionxMin = Math.Min(CurrentPos.X, _selectionStartPoint.X); selectionxMax = Math.Max(CurrentPos.X, _selectionStartPoint.X); selectionyMax = Math.Max(CurrentPos.Y, _selectionStartPoint.Y); selectionyMin = Math.Min(CurrentPos.Y, _selectionStartPoint.Y); } var grassFilter = LevEditor.EffectiveGrassFilter; var groundFilter = LevEditor.EffectiveGroundFilter; var appleFilter = LevEditor.EffectiveAppleFilter; var killerFilter = LevEditor.EffectiveKillerFilter; var flowerFilter = LevEditor.EffectiveFlowerFilter; var pictureFilter = LevEditor.EffectivePictureFilter; var textureFilter = LevEditor.EffectiveTextureFilter; foreach (Polygon x in Lev.Polygons) { if ((x.IsGrass && grassFilter) || (!x.IsGrass && groundFilter)) { foreach (Vector t in x.Vertices) { if (RectSelecting) { MarkSelectedInArea(t, selectionxMin, selectionxMax, selectionyMin, selectionyMax); } else { MarkSelectedInArea(t, _selectionPoly); } } } } foreach (LevObject t in Lev.Objects) { ObjectType type = t.Type; if (type == ObjectType.Start || (type == ObjectType.Apple && appleFilter) || (type == ObjectType.Killer && killerFilter) || (type == ObjectType.Flower && flowerFilter)) { if (RectSelecting) { MarkSelectedInArea(t.Position, selectionxMin, selectionxMax, selectionyMin, selectionyMax); } else { MarkSelectedInArea(t.Position, _selectionPoly); } } } foreach (Picture z in Lev.Pictures) { if ((z.IsPicture && pictureFilter) || (!z.IsPicture && textureFilter)) { if (RectSelecting) { MarkSelectedInArea(z.Position, selectionxMin, selectionxMax, selectionyMin, selectionyMax); } else { MarkSelectedInArea(z.Position, _selectionPoly); } } } LevEditor.UpdateSelectionInfo(); LevEditor.PreserveSelection(); RectSelecting = false; FreeSelecting = false; } else if (Moving) { Moving = false; _lockingLines = false; if (_anythingMoved) { LevEditor.Modified = true; } } }
public void MouseDown(MouseEventArgs mouseData) { Vector p = CurrentPos; _anythingMoved = false; int nearestVertexIndex = GetNearestVertexIndex(p); int nearestObjectIndex = GetNearestObjectIndex(p); int nearestPictureIndex = GetNearestPictureIndex(p); switch (mouseData.Button) { case MouseButtons.Left: if (nearestVertexIndex >= -1 && Keyboard.IsKeyDown(Key.LeftAlt)) { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { MarkAllAs(VectorMark.None); } NearestPolygon.MarkVectorsAs(VectorMark.Selected); var inearest = NearestPolygon.ToIPolygon(); foreach (var polygon in Lev.Polygons.Where(polygon => polygon.ToIPolygon().Within(inearest))) { polygon.MarkVectorsAs(VectorMark.Selected); } foreach (var obj in Lev.Objects) { if (NearestPolygon.AreaHasPoint(obj.Position)) { obj.Position.Mark = VectorMark.Selected; } } foreach (var pic in Lev.Pictures) { if (NearestPolygon.AreaHasPoint(pic.Position)) { pic.Position.Mark = VectorMark.Selected; } } EndSelectionHandling(); } else if (nearestVertexIndex >= 0) { HandleMark(NearestPolygon[nearestVertexIndex]); if (Keyboard.IsKeyDown(Key.LeftShift)) { _lockCenter = NearestPolygon[nearestVertexIndex]; _lockPrev = NearestPolygon[nearestVertexIndex - 1]; _lockNext = NearestPolygon[nearestVertexIndex + 1]; _lockingLines = true; _moveStartPosition = _lockCenter; } } else if (nearestVertexIndex == -1) { int nearestSegmentIndex = NearestPolygon.GetNearestSegmentIndex(p); AdjustForGrid(p); if (Keyboard.IsKeyDown(Key.LeftShift)) { MarkAllAs(VectorMark.None); p.Mark = VectorMark.Selected; NearestPolygon.Insert(nearestSegmentIndex + 1, p); LevEditor.Modified = true; } else { if ( !(NearestPolygon[nearestSegmentIndex].Mark == VectorMark.Selected && NearestPolygon[nearestSegmentIndex + 1].Mark == VectorMark.Selected)) { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { MarkAllAs(VectorMark.None); NearestPolygon.MarkVectorsAs(VectorMark.Selected); } } if (Keyboard.IsKeyDown(Key.LeftCtrl)) { NearestPolygon.MarkVectorsAs( NearestPolygon.Vertices.TrueForAll(v => v.Mark == VectorMark.Selected) ? VectorMark.None : VectorMark.Selected); } } EndSelectionHandling(); } else if (nearestObjectIndex >= 0) { HandleMark(Lev.Objects[nearestObjectIndex].Position); } else if (nearestPictureIndex >= 0) { HandleMark(Lev.Pictures[nearestPictureIndex].Position); } else { if (!Keyboard.IsKeyDown(Key.LeftCtrl)) { MarkAllAs(VectorMark.None); LevEditor.PreserveSelection(); } if (Keyboard.IsKeyDown(Key.LeftShift)) { FreeSelecting = true; _selectionPoly = new Polygon(); _selectionPoly.Add(CurrentPos); _mouseTrip = 0; _lastMousePosition = CurrentPos; } else { _selectionStartPoint = p; RectSelecting = true; } } LevEditor.UpdateSelectionInfo(); break; case MouseButtons.Right: break; case MouseButtons.Middle: break; } }