// WPF events for input. public void MouseMove(object sender, MouseEventArgs e) { if (_mouseDown) { _mouseX = (float)e.GetPosition(MainWindow.mainWindow.MainView).X; _mouseY = (float)e.GetPosition(MainWindow.mainWindow.MainView).Y; worldMousePosition = Vector2.Transform(new Vector2(_mouseX, _mouseY), Matrix.Invert(MainCamera.Transform)); worldMousePosition = new Vector2((int)worldMousePosition.X, (int)worldMousePosition.Y); // Moving selected object if (sprBoxSelected != "enginereserved_null") { Spritebox sprBox; previewObject.GetSpriteBoxes().TryGetValue(sprBoxSelected, out sprBox); if (sprBox != null && new Rectangle(sprBox.GetRectangle().X + (int)previewObject.GetPosition().X, sprBox.GetRectangle().Y + (int)previewObject.GetPosition().Y, sprBox.GetWidth(), sprBox.GetHeight()).Intersects(new Rectangle((int)worldMousePosition.X, (int)worldMousePosition.Y, 1, 1))) { bool resizing = false; foreach (Drawable drawable in selectionBox.GetChildren()) { ResizeBox resizeBox = (ResizeBox)drawable; if (resizeBox.GetSelected()) { resizing = true; } } if (!resizing) { sprBox.SetPosition(worldMousePosition + grabPosition); } } } oldWorldMousePosition = worldMousePosition; } if (previouseMouseInit != false) { if (e.MiddleButton == MouseButtonState.Pressed) { Vector2 worldNew = Vector2.Transform(new Vector2((float)e.GetPosition(MainWindow.mainWindow.MainView).X, (float)e.GetPosition(MainWindow.mainWindow.MainView).Y), Matrix.Invert(MainCamera.Transform)); Vector2 worldOld = Vector2.Transform(new Vector2(previousMousePos.X, previousMousePos.Y), Matrix.Invert(MainCamera.Transform)); MainCamera.Position = MainCamera.Position + (worldNew - worldOld); } } previouseMouseInit = true; previousMousePos = new Vector2((float)e.GetPosition(MainWindow.mainWindow.MainView).X, (float)e.GetPosition(MainWindow.mainWindow.MainView).Y); foreach (Drawable drawable in SpriteManager.GetSprites()) { drawable.MouseMove(sender, e, worldMousePosition); } }
/// <summary> /// Constructor /// </summary> /// <param name="label">Associated label</param> /// <param name="caption">Caption control</param> /// <param name="captionEditor">Caption editor</param> /// <param name="post">The "Post" acion</param> /// <param name="resize">The Resize event handler</param> public NonstandardLabel(IObjectLabelUI label, Control[] caption, TextBox captionEditor, Action post, EventHandler resize) { this.label = label; this.caption = caption; this.captionEditor = captionEditor; this.post = post; this.resize = resize; x = label.X; y = label.Y; Control c = label.Control as Control; w = c.Width; h = c.Height; if (captionEditor != null) { captionEditor.KeyUp += KeyUp; } // box = new MovedBox(label); rbox = new ResizeBox(label); c.Paint += Paint; }
public ResizeControl(Control target, Boolean showResizeBoxes) { _Target = target; target.Parent.Paint += Parent_Paint; topBox = new ResizeBox(ResizeBox.BoxPosition.Top); bottomBox = new ResizeBox(ResizeBox.BoxPosition.Bottom); leftBox = new ResizeBox(ResizeBox.BoxPosition.Left); rightBox = new ResizeBox(ResizeBox.BoxPosition.Right); topLeftBox = new ResizeBox(ResizeBox.BoxPosition.TopLeft); topRightBox = new ResizeBox(ResizeBox.BoxPosition.TopRight); bottomLeftBox = new ResizeBox(ResizeBox.BoxPosition.BottomLeft); bottomRightBox = new ResizeBox(ResizeBox.BoxPosition.BottomRight); topLeftBox.MouseDown += Boxes_MouseDown; topBox.MouseDown += Boxes_MouseDown; topRightBox.MouseDown += Boxes_MouseDown; leftBox.MouseDown += Boxes_MouseDown; rightBox.MouseDown += Boxes_MouseDown; bottomLeftBox.MouseDown += Boxes_MouseDown; bottomBox.MouseDown += Boxes_MouseDown; bottomRightBox.MouseDown += Boxes_MouseDown; topLeftBox.MouseMove += topLeftBox_MouseMove; topBox.MouseMove += topBox_MouseMove; topRightBox.MouseMove += topRightBox_MouseMove; leftBox.MouseMove += leftBox_MouseMove; rightBox.MouseMove += rightBox_MouseMove; bottomLeftBox.MouseMove += bottomLeftBox_MouseMove; bottomBox.MouseMove += bottomBox_MouseMove; bottomRightBox.MouseMove += bottomRightBox_MouseMove; if (showResizeBoxes) { ShowResizeBoxes(); } }