protected void CheckMouseDown(Point screenPoint) { Point clientPoint = PointToClient(screenPoint); if (clientPoint.X < 7 && clientPoint.Y < 7) { sizingDirection = SizingDirection.SizingNW; } else if (clientPoint.X > Width - 7 && clientPoint.Y < 7) { sizingDirection = SizingDirection.SizingNE; } else if (clientPoint.X < 7 && clientPoint.Y > Height - 7) { sizingDirection = SizingDirection.SizingSW; } else if (clientPoint.X > Width - 7 && clientPoint.Y > Height - 7) { sizingDirection = SizingDirection.SizingSE; } else if (clientPoint.X < 7 && clientPoint.Y > ((Height - 7) / 2) && clientPoint.Y < ((Height + 7) / 2)) { sizingDirection = SizingDirection.SizingW; } else if (clientPoint.X > Width - 7 && clientPoint.Y > ((Height - 7) / 2) && clientPoint.Y < ((Height + 7) / 2)) { sizingDirection = SizingDirection.SizingE; } else if (clientPoint.Y < 7 && clientPoint.X > ((Width - 7) / 2) && clientPoint.X < ((Width + 7) / 2)) { sizingDirection = SizingDirection.SizingN; } else if (clientPoint.Y > Height - 7 && clientPoint.X > ((Width - 7) / 2) && clientPoint.X < ((Width + 7) / 2)) { sizingDirection = SizingDirection.SizingS; } else { isMoving = true; } isPositionPoint = screenPoint; }
private void OnMouseUp() { isMoving = false; sizingDirection = SizingDirection.None; Point topLeft = PointToScreen(new Point(control.Left, control.Top)); topLeft = Parent.PointToClient(topLeft); wixFiles.UndoManager.BeginNewCommandRange(); AssignIfChanged(xmlNode.Attributes["Width"], DialogGenerator.PixelsToDialogUnitsWidth(control.Width)); AssignIfChanged(xmlNode.Attributes["X"], DialogGenerator.PixelsToDialogUnitsWidth(topLeft.X)); AssignIfChanged(xmlNode.Attributes["Height"], DialogGenerator.PixelsToDialogUnitsHeight(control.Height)); AssignIfChanged(xmlNode.Attributes["Y"], DialogGenerator.PixelsToDialogUnitsHeight(topLeft.Y)); if (ItemChanged != null) { ItemChanged(xmlNode); } }
/// <summary> /// Called when the selector tool is selected and an event has been recieved. /// </summary> /// <param name="firedEvent">Event that caused this update to be called.</param> public void UpdateSelector(Event firedEvent) { if (firedEvent.ID == "mouse_move" && InputManager.KeyDown(KeyCodes.LeftMouse)) { if (_toolMoving == true) { _toolMovementDimensions.Width = InputManager.MouseX - _toolMovementDimensions.X; _toolMovementDimensions.Height = InputManager.MouseY - _toolMovementDimensions.Y; } else if (_movingObject == true) { ArrayList groupsMoved = new ArrayList(); foreach (EntityNode iterationEntity in _selectedEntityList) { if (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null && groupsMoved.Contains(iterationEntity.Parent) == true) continue; EntityNode entity = (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null) ? (GroupNode)iterationEntity.Parent : iterationEntity; entity.Move(_xAxisLocked == true ? 0.0f : ((InputManager.MouseX - _moveObjectDimensions.X) / Editor.GlobalInstance.CameraNode.Zoom), _yAxisLocked == true ? 0.0f : ((InputManager.MouseY - _moveObjectDimensions.Y) / Editor.GlobalInstance.CameraNode.Zoom), 0.0f); if (iterationEntity.Parent != null && iterationEntity.Parent as GroupNode != null) groupsMoved.Add(iterationEntity.Parent); } _moveObjectDimensions.X = InputManager.MouseX; _moveObjectDimensions.Y = InputManager.MouseY; _mapChangedSinceSave = true; } else if (_sizingObject == true) { int movementX = _xAxisLocked == true ? 0 : (int)((InputManager.MouseX - _moveObjectDimensions.X) / Editor.GlobalInstance.CameraNode.Zoom), movementY = _yAxisLocked == true ? 0 : (int)((InputManager.MouseY - _moveObjectDimensions.Y) / Editor.GlobalInstance.CameraNode.Zoom); _objectToSize.BoundingRectangle = _objectSizeOriginalBoundingBox; _objectToSize.Transformation = _objectSizeOriginalTransformation; if ((_sizingDirection & SizingDirection.Top) != 0) { _objectToSize.Resize(_objectToSize.BoundingRectangle.Width, Math.Max(_objectToSize.BoundingRectangle.Height + -movementY,_gridHeight)); _objectToSize.Position(_objectToSize.Transformation.X, _objectToSize.Transformation.Y + -(_objectToSize.BoundingRectangle.Height - _objectSizeOriginalBoundingBox.Height), _objectToSize.Transformation.Z); } if ((_sizingDirection & SizingDirection.Left) != 0) { _objectToSize.Resize(Math.Max(_objectToSize.BoundingRectangle.Width + -movementX, _gridWidth), _objectToSize.BoundingRectangle.Height); _objectToSize.Position(_objectToSize.Transformation.X + -(_objectToSize.BoundingRectangle.Width - _objectSizeOriginalBoundingBox.Width), _objectToSize.Transformation.Y, _objectToSize.Transformation.Z); } if ((_sizingDirection & SizingDirection.Bottom) != 0) _objectToSize.Resize(_objectToSize.BoundingRectangle.Width, Math.Max(_objectToSize.BoundingRectangle.Height + movementY, _gridHeight)); if ((_sizingDirection & SizingDirection.Right) != 0) _objectToSize.Resize(Math.Max(_objectToSize.BoundingRectangle.Width + movementX, _gridWidth), _objectToSize.BoundingRectangle.Height); _mapChangedSinceSave = true; } } else if (firedEvent.ID == "key_pressed" && ((InputEventData)firedEvent.Data).KeyCode == KeyCodes.LeftMouse) { bool touchingSizingPoint = false; Rectangle mouseRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1); foreach (EntityNode node in _selectedEntityList) if (node.RectangleSizingPointsIntersect(mouseRectangle, Editor.GlobalInstance.CameraNode)) touchingSizingPoint = true; // Was last click in same spot? If so we want to select the new object. if (touchingSizingPoint == false && ((_toolMovementDimensions.X == InputManager.MouseX && _toolMovementDimensions.Y == InputManager.MouseY) || (_toolMovementDimensions.Width == 0 || _toolMovementDimensions.Height == 0))) { if (InputManager.KeyDown(KeyCodes.LeftControl)) { Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1); foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes()) { EntityNode entity = node as EntityNode; if (entity == null) continue; if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true) { if (_selectedEntityList.Contains(entity)) RemoveEntityFromSelection(entity); else AddEntityToSelection(entity); break; } } SyncronizeWindow(); } else { Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1); bool canSelect = (_selectedEntityList.Count == 0); EntityNode selectEntity = null, firstEntity = null; foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes()) { EntityNode entity = node as EntityNode; if (entity == null) continue; if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true) { if (canSelect == true) { selectEntity = entity; break; } else if (firstEntity != null) firstEntity = entity; if (_selectedEntityList.Contains(entity)) canSelect = true; } } if (selectEntity == null) selectEntity = firstEntity; ClearSelection(); if (selectEntity != null) { AddEntityToSelection(selectEntity); SyncronizeWindow(); } _movingObject = true; _moveObjectDimensions.X = InputManager.MouseX; _moveObjectDimensions.Y = InputManager.MouseY; } } else { ArrayList removeList = new ArrayList(); Rectangle intersectRectangle = new Rectangle(InputManager.MouseX, InputManager.MouseY, 1, 1); foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes()) { EntityNode entity = node as EntityNode; if (entity == null) continue; if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == false && entity.RectangleSizingPointsIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == false) removeList.Add(entity); } if (!InputManager.KeyDown(KeyCodes.LeftControl)) { foreach (EntityNode entity in removeList) RemoveEntityFromSelection(entity); } _movingObject = true; _moveObjectDimensions.X = InputManager.MouseX; _moveObjectDimensions.Y = InputManager.MouseY; } // Lets select an object or size one. foreach (EntityNode entity in _selectedEntityList) { Transformation transformation = entity.CalculateTransformation(Editor.GlobalInstance.CameraNode); int x = (int)(transformation.X - (entity.SizingPointsSize / 2)), y = (int)(transformation.Y - (entity.SizingPointsSize / 2)); int w = (int)(entity.BoundingRectangle.Width * Editor.GlobalInstance.CameraNode.Zoom), h = (int)(entity.BoundingRectangle.Height * Editor.GlobalInstance.CameraNode.Zoom); bool previousMoving = _movingObject; _movingObject = false; _sizingObject = true; _objectToSize = entity; _objectSizeOriginalBoundingBox = _objectToSize.BoundingRectangle; _objectSizeOriginalTransformation = _objectToSize.Transformation; if (mouseRectangle.IntersectsWith(new Rectangle(x, y, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Top | SizingDirection.Left; Cursor = Cursors.SizeNWSE; } else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Top | SizingDirection.Right; Cursor = Cursors.SizeNESW; } else if (mouseRectangle.IntersectsWith(new Rectangle(x, y + h, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Bottom | SizingDirection.Left; Cursor = Cursors.SizeNESW; } else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y + h, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Bottom | SizingDirection.Right; Cursor = Cursors.SizeNWSE; } else if (mouseRectangle.IntersectsWith(new Rectangle(x + (w / 2), y, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Top; Cursor = Cursors.SizeNS; } else if (mouseRectangle.IntersectsWith(new Rectangle(x + (w / 2), y + h, entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Bottom; Cursor = Cursors.SizeNS; } else if (mouseRectangle.IntersectsWith(new Rectangle(x, y + (h / 2), entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Left; Cursor = Cursors.SizeWE; } else if (mouseRectangle.IntersectsWith(new Rectangle(x + w, y + (h / 2), entity.SizingPointsSize, entity.SizingPointsSize))) { _sizingDirection = SizingDirection.Right; Cursor = Cursors.SizeWE; } else { _sizingObject = false; _objectToSize = null; _movingObject = previousMoving; } } // If we are holding shift then we want to select multiple objects. if (InputManager.KeyDown(KeyCodes.LeftShift)) { _movingObject = false; _sizingObject = false; _toolMoving = true; } // Log the original transformations of the selected nodes. _originalEntityTransformations.Clear(); _originalEntityBoundingBoxs.Clear(); foreach (EntityNode entity in _selectedEntityList) { _originalEntityTransformations.Add(entity, entity.Transformation); _originalEntityBoundingBoxs.Add(entity, entity.BoundingRectangle); } _toolMovementDimensions.X = InputManager.MouseX; _toolMovementDimensions.Y = InputManager.MouseY; _toolMovementDimensions.Width = _selectedEntityList.Count > 0 ? 1 : 0; _toolMovementDimensions.Height = _selectedEntityList.Count > 0 ? 1 : 0; } else if (firedEvent.ID == "key_released" && ((InputEventData)firedEvent.Data).KeyCode == KeyCodes.LeftMouse) { if (_toolMoving == true) { _toolMoving = false; // Create a rectangle from which we can check intersection against. Rectangle intersectRectangle = new Rectangle(); // If we have a negative width then make it positive. if (_toolMovementDimensions.Width < 0) { intersectRectangle.X = _toolMovementDimensions.X + _toolMovementDimensions.Width; intersectRectangle.Width = Math.Abs(_toolMovementDimensions.Width); } else { intersectRectangle.X = _toolMovementDimensions.X; intersectRectangle.Width = _toolMovementDimensions.Width; } // If we have a negative height then make it positive. if (_toolMovementDimensions.Height < 0) { intersectRectangle.Y = _toolMovementDimensions.Y + _toolMovementDimensions.Height; intersectRectangle.Height = Math.Abs(_toolMovementDimensions.Height); } else { intersectRectangle.Y = _toolMovementDimensions.Y; intersectRectangle.Height = _toolMovementDimensions.Height; } // Unselect all the pervious entitys. ArrayList oldSelectionList = new ArrayList(); oldSelectionList.AddRange(_selectedEntityList); // Clear out old selection. if (InputManager.KeyDown(KeyCodes.LeftControl) == false) ClearSelection(); // Grab all the entitys within our selection rectangle and select them. bool canSelect = (oldSelectionList.Count == 0 || !(intersectRectangle.Width < 2 && intersectRectangle.Height < 2)); EntityNode selectEntity = null; foreach (SceneNode node in Engine.Engine.GlobalInstance.Map.SceneGraph.EnumerateNodes()) { EntityNode entity = node as EntityNode; if (entity == null) continue; if (entity.RectangleBoundingBoxIntersect(intersectRectangle, Editor.GlobalInstance.CameraNode) == true) { if (canSelect == true) { AddEntityToSelection(entity); if (intersectRectangle.Width < 2 && intersectRectangle.Height < 2) break; } else if (selectEntity == null) selectEntity = entity; if (oldSelectionList.Contains(entity)) canSelect = true; } } if (canSelect == false && selectEntity != null) AddEntityToSelection(selectEntity); } else if (_movingObject == true) { // Snap the objects to the grid. if (_snapToGrid == true) { foreach (EntityNode entity in _selectedEntityList) { entity.Position(((int)entity.Transformation.X / _gridWidth) * _gridWidth, ((int)entity.Transformation.Y / _gridHeight) * _gridHeight, entity.Transformation.Z); // Create a new transformation undo operation if transformation has changed. Transformation originalTransformation = (Transformation)_originalEntityTransformations[entity]; if (originalTransformation != entity.Transformation) PushUndoOperation(new TransformNodeUndoOperation(entity, originalTransformation, entity.Transformation)); } _originalEntityTransformations.Clear(); if (_entityPropertiesWindow != null && _entityPropertiesWindow.Entity != null) _entityPropertiesWindow.UpdateProperty("location", new Point((int)_entityPropertiesWindow.Entity.Transformation.X, (int)_entityPropertiesWindow.Entity.Transformation.Y)); } _movingObject = false; _mapChangedSinceSave = true; } else if (_sizingObject == true) { if (_snapToGrid == true) { _objectToSize.Position(((int)_objectToSize.Transformation.X / _gridWidth) * _gridWidth, ((int)_objectToSize.Transformation.Y / _gridHeight) * _gridHeight, _objectToSize.Transformation.Z); _objectToSize.BoundingRectangle = new Rectangle(_objectToSize.BoundingRectangle.X, _objectToSize.BoundingRectangle.Y, ((int)_objectToSize.BoundingRectangle.Width / _gridWidth) * _gridWidth, ((int)_objectToSize.BoundingRectangle.Height / _gridHeight) * _gridHeight); Rectangle newBoundingRectangle = _objectToSize.BoundingRectangle; if (newBoundingRectangle.Width < _gridWidth) newBoundingRectangle.Width = _gridWidth; if (newBoundingRectangle.Height < _gridHeight) newBoundingRectangle.Height = _gridHeight; _objectToSize.BoundingRectangle = newBoundingRectangle; // Create a new sizing undo operation if size has changed. Rectangle originalBoundingBox = (Rectangle)_originalEntityBoundingBoxs[_objectToSize]; if (!_objectToSize.BoundingRectangle.Equals(originalBoundingBox)) PushUndoOperation(new ResizeNodeUndoOperation(_objectToSize, originalBoundingBox, (Transformation)_originalEntityTransformations[_objectToSize], _objectToSize.BoundingRectangle, _objectToSize.Transformation)); } if (_entityPropertiesWindow != null && _entityPropertiesWindow.Entity != null) { _entityPropertiesWindow.UpdateProperty("bounding rectangle", new Rectangle(_entityPropertiesWindow.Entity.BoundingRectangle.X, _entityPropertiesWindow.Entity.BoundingRectangle.Y, _entityPropertiesWindow.Entity.BoundingRectangle.Width, _entityPropertiesWindow.Entity.BoundingRectangle.Height)); _entityPropertiesWindow.UpdateProperty("collision rectangle", new Rectangle(_entityPropertiesWindow.Entity.CollisionRectangle.X, _entityPropertiesWindow.Entity.CollisionRectangle.Y, _entityPropertiesWindow.Entity.CollisionRectangle.Width, _entityPropertiesWindow.Entity.CollisionRectangle.Height)); } Cursor = Cursors.Arrow; _sizingObject = false; _mapChangedSinceSave = true; } SyncronizeWindow(); } }
protected void CheckMouseDown(Point screenPoint) { Point clientPoint = PointToClient(screenPoint); if (clientPoint.X < 7 && clientPoint.Y < 7) { sizingDirection = SizingDirection.SizingNW; } else if (clientPoint.X > Width - 7 && clientPoint.Y < 7) { sizingDirection = SizingDirection.SizingNE; } else if (clientPoint.X < 7 && clientPoint.Y > Height - 7) { sizingDirection = SizingDirection.SizingSW; } else if (clientPoint.X > Width - 7 && clientPoint.Y > Height - 7) { sizingDirection = SizingDirection.SizingSE; } else if (clientPoint.X < 7 && clientPoint.Y > ((Height-7)/2) && clientPoint.Y < ((Height+7)/2)) { sizingDirection = SizingDirection.SizingW; } else if (clientPoint.X > Width - 7 && clientPoint.Y > ((Height-7)/2) && clientPoint.Y < ((Height+7)/2)) { sizingDirection = SizingDirection.SizingE; } else if (clientPoint.Y < 7 && clientPoint.X > ((Width-7)/2) && clientPoint.X < ((Width+7)/2)) { sizingDirection = SizingDirection.SizingN; } else if (clientPoint.Y > Height - 7 && clientPoint.X > ((Width-7)/2) && clientPoint.X < ((Width+7)/2)) { sizingDirection = SizingDirection.SizingS; } else { isMoving = true; } isPositionPoint = screenPoint; }