public override void OnMouseDragMove(MouseEventArgs e) { Point2I mousePos = new Point2I(e.X, e.Y); Point2I pointInLevel = LevelDisplayControl.SampleLevelPixelPosition(mousePos); // Update selection box. if (e.Button == MouseButtons.Left && isCreatingSelectionBox) { Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); Level level = EditorControl.Level; Rectangle2I selectionBox; if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE)) { Point2I roomCoord1 = level.GetRoomLocation((LevelTileCoord)dragBeginTileCoord); Point2I roomCoord2 = level.GetRoomLocation((LevelTileCoord)tileCoord); Point2I roomCoordMin = GMath.Min(roomCoord1, roomCoord2); Point2I roomCoordMax = GMath.Max(roomCoord1, roomCoord2); Rectangle2I levelDimensions = new Rectangle2I(Point2I.Zero, level.Dimensions); selectionBox = new Rectangle2I(roomCoordMin, roomCoordMax - roomCoordMin + Point2I.One); selectionBox = Rectangle2I.Intersect(selectionBox, levelDimensions); selectionBox.Point *= level.RoomSize; selectionBox.Size *= level.RoomSize; } else { Point2I minCoord = GMath.Min(dragBeginTileCoord, tileCoord); Point2I maxCoord = GMath.Max(dragBeginTileCoord, tileCoord); Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions); selectionBox = new Rectangle2I(minCoord, maxCoord - minCoord + Point2I.One); //selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds); } LevelDisplayControl.SetSelectionGridArea(selectionBox, level); } else if (e.Button == MouseButtons.Left && isMovingSelectionBox) { Point2I moveAmount; if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE)) { moveAmount = pointInLevel - dragBeginPoint; moveAmount = (Point2I)GMath.Round((Vector2F)moveAmount / (editorControl.Level.RoomSize * GameSettings.TILE_SIZE)); moveAmount *= editorControl.Level.RoomSize; } else { moveAmount = pointInLevel - dragBeginPoint; moveAmount = (Point2I)GMath.Round((Vector2F)moveAmount / GameSettings.TILE_SIZE); } Point2I selectionBoxPoint = selectionBoxBeginPoint + moveAmount; LevelDisplayControl.MoveSelectionGridArea(selectionBoxPoint); } }
public override void SelectAll() { isCreatingSelectionBox = false; isMovingSelectionBox = false; Level level = EditorControl.Level; Rectangle2I area = new Rectangle2I(Point2I.Zero, level.Dimensions * level.RoomSize); LevelDisplayControl.SetSelectionGridArea(area, level); }
public override void OnMouseDragBegin(MouseEventArgs e) { Point2I mousePos = new Point2I(e.X, e.Y); Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); Point2I point = LevelDisplayControl.SampleLevelPixelPosition(mousePos); if (isCreatingSelectionBox || isMovingSelectionBox) { return; } // Draw a new selecion box. if (e.Button == MouseButtons.Left) { if (EditorControl.Level == LevelDisplayControl.SelectionGridLevel && LevelDisplayControl.SelectionBox.Contains(point)) { // Begin moving the selection box. isMovingSelectionBox = true; dragBeginPoint = point; dragBeginTileCoord = tileCoord; selectionBoxBeginPoint = LevelDisplayControl.SelectionGridArea.Point; //LevelDisplayControl.PickupSelectionGrid(); // Duplicate selection if holding Ctrl. if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_DUPLICATE)) { LevelDisplayControl.DuplicateSelectionGrid(); } } else { LevelDisplayControl.PlaceSelectionGrid(); // Create a new selection box. isCreatingSelectionBox = true; dragBeginPoint = point; dragBeginTileCoord = tileCoord; Rectangle2I selectionBox; Level level = EditorControl.Level; if (System.Windows.Forms.Control.ModifierKeys.HasFlag(KEYMOD_ROOM_MODE)) { selectionBox = new Rectangle2I(level.GetRoomLocation( (LevelTileCoord)dragBeginTileCoord), Point2I.One); Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.Dimensions); selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds); selectionBox.Point *= level.RoomSize; selectionBox.Size *= level.RoomSize; } else { selectionBox = new Rectangle2I(dragBeginTileCoord, Point2I.One); Rectangle2I levelBounds = new Rectangle2I(Point2I.Zero, level.RoomSize * level.Dimensions); selectionBox = Rectangle2I.Intersect(selectionBox, levelBounds); } LevelDisplayControl.SetSelectionGridArea(selectionBox, level); } } }