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 OnMouseDragBegin(MouseEventArgs e) { // Draw a new selecion box. if (e.Button == MouseButtons.Left) { isCreatingSelectionBox = true; Point2I mousePos = new Point2I(e.X, e.Y); dragBeginTileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); LevelDisplayControl.SetSelectionBox(dragBeginTileCoord, Point2I.One); } }
public override void OnMouseDragMove(MouseEventArgs e) { // Update selection box. if (e.Button == MouseButtons.Left && isCreatingSelectionBox) { Point2I mousePos = new Point2I(e.X, e.Y); Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); Point2I minCoord = GMath.Min(dragBeginTileCoord, tileCoord); Point2I maxCoord = GMath.Max(dragBeginTileCoord, tileCoord); LevelDisplayControl.SetSelectionBox(minCoord, maxCoord - minCoord + Point2I.One); } }
//----------------------------------------------------------------------------- // Internal methods //----------------------------------------------------------------------------- private void ActivateTile(MouseEventArgs e) { Point2I mousePos = new Point2I(e.X, e.Y); Point2I levelTileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); // Limit tiles to the selection box if there is one. if (LevelDisplayControl.SelectionGridArea.IsEmpty || LevelDisplayControl.SelectionGridArea.Contains(levelTileCoord)) { Room room = LevelDisplayControl.Level.GetRoom((LevelTileCoord)levelTileCoord); if (room != null) { Point2I tileLocation = LevelDisplayControl.Level.GetTileLocation((LevelTileCoord)levelTileCoord); ActivateTile(e.Button, room, tileLocation); } } }
public override void OnMouseDragEnd(MouseEventArgs e) { if (e.Button == MouseButtons.Left && isCreatingSelectionBox) { isCreatingSelectionBox = false; Point2I mousePos = new Point2I(e.X, e.Y); Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); Point2I minCoord = GMath.Min(dragBeginTileCoord, tileCoord); Point2I maxCoord = GMath.Max(dragBeginTileCoord, tileCoord); Point2I totalSize = editorControl.Level.Dimensions * editorControl.Level.RoomSize; for (int x = minCoord.X; x <= maxCoord.X && x < totalSize.X; x++) { for (int y = minCoord.Y; y <= maxCoord.Y && y < totalSize.Y; y++) { ActivateTile(e.Button, new Point2I(x, y)); } } LevelDisplayControl.ClearSelectionBox(); } }
public override void OnMouseMove(MouseEventArgs e) { // Check if mouse is over selection. Point2I point = new Point2I(e.X, e.Y); Point2I tileCoord = LevelDisplayControl.SampleLevelTileCoordinates(point) * GameSettings.TILE_SIZE; if (!isCreatingSelectionBox && EditorControl.Level == LevelDisplayControl.SelectionGridLevel && LevelDisplayControl.SelectionBox.Contains(tileCoord)) { MouseCursor = Cursors.SizeAll; editorControl.HighlightMouseTile = false; } else { MouseCursor = Cursors.Default; editorControl.HighlightMouseTile = true; } base.OnMouseMove(e); }
public override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); Point2I mousePos = new Point2I(e.X, e.Y); Room room = LevelDisplayControl.SampleRoom(mousePos); Point2I tileCoord = LevelDisplayControl.SampleTileCoordinates(mousePos); Point2I target = LevelDisplayControl.SampleLevelTileCoordinates(mousePos); if (!EditorControl.EventMode) { if (e.Button == MouseButtons.Middle) { // Select/sample tiles. TileDataInstance selectedTile = room.GetTile(tileCoord, editorControl.CurrentLayer); if (selectedTile != null) { Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord); EditorControl.PropertyGrid.OpenProperties(selectedTile.Properties, selectedTile); editorControl.SelectedTilesetTile = -Point2I.One; editorControl.SelectedTilesetTileData = selectedTile.TileData; } else { EditorControl.PropertyGrid.CloseProperties(); } } else if (editorControl.CurrentLayer == 0 || GetTileAt(target) != null) { // Fill tiles. TileData fillData = editorControl.SelectedTilesetTileData as TileData; if (fillData != null) { if (e.Button == MouseButtons.Right) { fillData = null; } Fill(target, fillData); } } } else { if (e.Button == MouseButtons.Middle) { // Select events. EventTileDataInstance selectedEventTile = LevelDisplayControl.SampleEventTile(mousePos); if (selectedEventTile != null) { Point2I levelTileCoord = LevelDisplayControl.ToLevelTileCoordinates(room, tileCoord); EditorControl.PropertyGrid.OpenProperties(selectedEventTile.Properties, selectedEventTile); } else { EditorControl.PropertyGrid.CloseProperties(); } } } }
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); } } }