/// <summary> /// Collisions mode mouse down. /// </summary> private void CollisionsMouseDown(MouseEventArgs mouse) { // Get snapped position. Size tileSize = ProjectManager.Room.TileSize; Point snap = GetSnappedPoint(mouse.Location, new Size(_gridX, _gridY)); // If a shape was selected, return; if (CollisionContains(mouse.Location, true) == true) return; // Create a new rectangle. GMareCollision shape = new GMareCollision(); shape.Level = _level; // Add a new shape to the shapes list. ProjectManager.Room.Shapes.Add(shape); // Set selected shape. _selectedShape = shape; }
/// <summary> /// Reset the control to empty state. /// </summary> public void Reset() { _selection = null; _selectedInstance = null; _selectedObject = null; _selectedShape = null; _selectionClip = null; _instanceClip = null; // Delete textures. GraphicsManager.DeleteTextures(); GraphicsManager.DeleteTilemaps(); }
/// <summary> /// Sets the shape under the mouse, if there is one. /// </summary> /// <param name="point">The point to check.</param> /// <param name="set">If the item should be selected if within bounds.</param> /// <returns>Whether a shape was selected or not.</returns> private bool CollisionContains(Point point, bool set) { // Set cursor this.Cursor = Cursors.Arrow; // Offset scroll position. point.X += Offset.X; point.Y += Offset.Y; // Iterate through room shapes, search for a selection. foreach (GMareCollision shape in ProjectManager.Room.Shapes) { // Iterate through nodes. for (int i = 0; i < shape.Nodes.Length; i++) { // If the mouse lies within the shape node. if (shape.Nodes[i].Contains(point)) { // If the shape and node should be set. if (set == true) { // Set the slected shape, and node. _selectedShape = shape; _selectedPoint = i; // Allow dragging. _dragging = true; } // Set cursor. this.Cursor = Cursors.SizeAll; // Selected a shape. return true; } // If the mouse lies within the shape. if (shape.Contains(point)) { // Set the selected shape. if (set == true) _selectedShape = shape; // Selected a shape. return true; } } } // The point is not contained by any shape or node. return false; }