///// protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (Manager.Room == null) { return; } Point snap = GetSnappedPoint(e.Location, new Size(_gridX / _zoom, _gridY / _zoom)); // If mouse left button clicked. if (e.Button == MouseButtons.Left) { //Invalidate(); _mouseX = snap.X; _mouseY = snap.Y; if (CurrentBrush == BrushMode.Move || CurrentBrush == BrushMode.Rotate) { _drag = true; if (CurrentBrush == BrushMode.Rotate) { Invalidate(); if (Manager.Project.SelectedInstance != null) { GmsRoomInstance p = Manager.Project.SelectedInstance; this._rotateStart = MathMethods.PointDirection(p.x, p.y, _mx, _my); Manager.MainWindow.statusLabelMousePos.Text = _rotateStart.ToString(); } } Manager.MainWindow.brushPlaceableUpdatePositionAndRotation(); } } }
private void DrawInstances() { if (Manager.Room != null) { int selectedLayerDepth = Manager.Room.Layers[Manager.MainWindow.tbLayerDropDown.SelectedIndex].LayerDepth; //int layerCounter = 0; //foreach (MapLayers layer in Manager.Room.Layers) //{ // if (layer.LayerDepth != selectedLayerDepth) // { // if (!layer.Active) continue; // } Color defaultLayerColor = Color.Gray; defaultLayerColor = Color.White;//todo - if proper layer //if (layer.LayerDepth == selectedLayerDepth) defaultLayerColor = Color.White; foreach (GmsRoomInstance instance in Manager.Room.instances) { //if (instance.editor_data.Layer != layer.LayerDepth) continue; Color color = defaultLayerColor; if (Manager.Project.HighlightedInstance == instance) { color = Color.Yellow; } if (Manager.Project.SelectedInstance == instance) { color = Color.Red; } if (instance.instance_of.sprite_index != null) { //GraphicsManager.DrawSprite(instance.Element.textureId, instance.XCenter / _zoom, instance.YCenter / _zoom, instance.Rotation, color); //try //{ GraphicsManager.DrawSprite( instance.instance_of.sprite_index.name, instance.x - instance.instance_of.sprite_index.origin_x, instance.y - instance.instance_of.sprite_index.origin_y, instance.scaleX, instance.scaleY, instance.rotation, color); //instance.linkedObj.sprite_index.name //} //catch (Exception e) //{ // MessageBox.Show(e.StackTrace.ToString()); //} /*if (instance.Element.MultiDraw) * { * GraphicsManager.DrawSprite(instance.Element.textureId, instance.XStart, instance.YStart, instance.Rotation + 90, color); * }*/ //GraphicsManager.draw } } // layerCounter++; //} if (CurrentBrush == BrushMode.Paint && Manager.Project.Instance != null) { try { int x, y; x = ((GridEnabled) ? _mouseX : _mx) - Manager.Project.Instance.sprite_index.origin_x; y = ((GridEnabled) ? _mouseY : _my) - Manager.Project.Instance.sprite_index.origin_y; GraphicsManager.DrawSprite( Manager.Project.Instance.sprite_index.name, x, y, 0, Color.Yellow); } catch { } } GraphicsManager.DrawSpriteBatch(false); if (_drag) { if (Manager.Project.SelectedInstance != null) { GmsRoomInstance p = Manager.Project.SelectedInstance; // drawing when moving if (CurrentBrush == BrushMode.Move) { GraphicsManager.DrawSprite( Manager.Project.SelectedInstance.editor_data.parent.instance_of.sprite_index.name, /*Manager.Project.SelectedInstance.X +*/ (_mouseX - Manager.Project.SelectedInstance.instance_of.sprite_index.origin_x), /*Manager.Project.SelectedInstance.Y +*/ (_mouseY - Manager.Project.SelectedInstance.instance_of.sprite_index.origin_y), Manager.Project.SelectedInstance.rotation, Color.Red); } // drawing when rotating if (CurrentBrush == BrushMode.Rotate) { Color green = Color.FromArgb(100, Color.Green); //GraphicsManager.DrawRectangle( // new Rectangle(p.XStart - 50, p.YStart - 50, p.Width + 100, p.Height + 100), // Color.FromArgb(100, Color.White), // false //); //GraphicsManager.DrawLineCache( // p.X - (int)lengthdir_x(p.Width, p.Rotation), // p.Y - (int)lengthdir_y(p.Height, p.Rotation), // p.X + (int)lengthdir_x(p.Width, p.Rotation), // p.Y + (int)lengthdir_y(p.Height, p.Rotation), // green //); //GraphicsManager.DrawLineCache( // p.X - (int)lengthdir_x(p.Width, p.Rotation + 90), // p.Y - (int)lengthdir_y(p.Height, p.Rotation + 90), // p.X + (int)lengthdir_x(p.Width, p.Rotation + 90), // p.Y + (int)lengthdir_y(p.Height, p.Rotation + 90), // green //); //GraphicsManager.DrawLineBatch(); //GraphicsManager.DrawSprite( // p.Element.textureId, // p.XStart, p.YStart, // p.Rotation, green //); // draw rotated one //double newRotation = (Manager.Project.SelectedInstance.Rotation + pointDistance(Manager.Project.SelectedInstance.XCenter, Manager.Project.SelectedInstance.YCenter, _mx, _my)) % 360; int newRotation = MathMethods.AngleDifference(MathMethods.PointDirection(p.x, p.y, _mx, _my), _rotateStart); _rotateCurrent = ((int)p.rotation + newRotation + 360) % 360; //Manager.MainWindow.statusLabelMousePos.Text = newRotation.ToString(); GraphicsManager.DrawSprite( p.instance_of.sprite_index.name, p.editor_data.XStart, p.editor_data.YStart, (float)_rotateCurrent, Color.Red ); //GraphicsManager.DrawLineCache( // p.XCenter - (int)lengthdir_x(p.Width, newRotation), // p.YCenter - (int)lengthdir_y(p.Height, newRotation), // p.XCenter + (int)lengthdir_x(p.Width, newRotation), // p.YCenter + (int)lengthdir_y(p.Height, newRotation), // Color.Red //); //GraphicsManager.DrawLineCache( // p.XCenter - (int)lengthdir_x(p.Width, newRotation + 90), // p.YCenter - (int)lengthdir_y(p.Height, newRotation + 90), // p.XCenter + (int)lengthdir_x(p.Width, newRotation + 90), // p.YCenter + (int)lengthdir_y(p.Height, newRotation + 90), // Color.Red //); GraphicsManager.DrawRectangleRotated( new Rectangle(p.editor_data.XStart, p.editor_data.YStart, p.editor_data.Width, p.editor_data.Height), _rotateCurrent, Color.FromArgb(150, Color.White), false ); //GraphicsManager.DrawLineBatch(); } } GraphicsManager.DrawSpriteBatch(false); } } }