Exemplo n.º 1
0
        /// <summary>
        /// Instance paste.
        /// </summary>
        public void tsmi_InstancePaste_Click(object sender, EventArgs e)
        {
            // If the instance clip is empty, return.
            if (_instanceClip == null)
                return;

            // Get object.
            GMareObject obj = ProjectManager.Room.Objects.Find(delegate(GMareObject o) { return o.Resource.Id == _instanceClip.ObjectId; });

            // If no parent object was found, return.
            if (obj == null)
                return;

            // Get the smallest canvas size.
            Size size = GetSmallestCanvas();

            // Add new instance.
            GMareInstance inst = _instanceClip.Clone();
            inst.X = ((int)(size.Width / Zoom) / 2) + (obj.Image.Width / 2) + Offset.X;
            inst.Y = ((int)(size.Height / Zoom) / 2) + (obj.Image.Height / 2) + Offset.Y;

            // Add the new instance.
            ProjectManager.Room.Instances.Add(inst);

            // Set selected instance.
            _selectedInstance = inst;

            // Fire selected instance changed event.
            SelectedInstanceChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instance copy.
        /// </summary>
        public void tsmi_InstanceCopy_Click(object sender, EventArgs e)
        {
            // If no instance has been selected, return.
            if (_selectedInstance == null)
                return;

            // Set instance clipboard.
            _instanceClip = _selectedInstance.Clone();

            // Clipboard changed.
            ClipboardChanged();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Instance cut.
        /// </summary>
        public void tsmi_InstanceCut_Click(object sender, EventArgs e)
        {
            // If no instance has been selected, return.
            if (_selectedInstance == null)
                return;

            // Room changed, instance deleted.
            RoomChanging();

            // Set instance clipboard.
            _instanceClip = _selectedInstance.Clone();

            // Remove selected instance.
            ProjectManager.Room.Instances.Remove(_selectedInstance);
            _selectedInstance = null;

            // Selected instance changed.
            SelectedInstanceChanged();
        }
Exemplo n.º 4
0
        /// <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();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Instance send front.
        /// </summary>
        private void tsmi_InstanceSendFront_Click(object sender, EventArgs e)
        {
            // If the selected instance is empty, return.
            if (_selectedInstance == null)
                return;

            // Room changed, instance index changed.
            RoomChanging();

            // Send the selected instance to the end of the list.
            ProjectManager.Room.Instances.Add(_selectedInstance.Clone());
            ProjectManager.Room.Instances.Remove(_selectedInstance);

            // Select newly placed instance.
            _selectedInstance = ProjectManager.Room.Instances[ProjectManager.Room.Instances.Count - 1];

            // The selected instance changed.
            SelectedInstanceChanged();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Instances mouse up.
        /// </summary>
        private void InstancesMouseUp()
        {
            // If no object was selected, or not in a dragging operation return.
            if (_selectedObject == null || _dragging == false || _selectedInstance != null)
                return;

            // Room changed, instance added.
            RoomChanging();

            // Create a new instance, based off of selected object.
            GMareInstance inst = new GMareInstance();
            inst.ObjectId = _selectedObject.Resource.Id;
            inst.Name = _selectedObject.Resource.Name;
            inst.Depth = _selectedObject.Depth;
            inst.X = _posX - _selectedObject.OriginX;
            inst.Y = _posY - _selectedObject.OriginY;

            // Add the new instance.
            ProjectManager.Room.Instances.Add(inst);

            // Set selected instance.
            _selectedInstance = inst;

            // Fire selected instance changed event.
            SelectedInstanceChanged();

            // Force redraw.
            Invalidate();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Check's if a point is within an instance. Optionally sets it as selected if it is.
        /// </summary>
        /// <param name="point">The point to check.</param>
        /// <param name="set">If the item should be selected if within bounds.</param>
        private bool CheckInstance(Point point, bool set)
        {
            // Set cursor
            this.Cursor = Cursors.Arrow;

            // Offset scroll position.
            point.X += (int)(Offset.X * Zoom);
            point.Y += (int)(Offset.Y * Zoom);

            // Iterate through instances backwards (Top items have more priority).
            for (int i = ProjectManager.Room.Instances.Count - 1; i > -1; i--)
            {
                // Get instance.
                GMareInstance instance = ProjectManager.Room.Instances[i];

                // Get the instance rectangle.
                Size size = GraphicsManager.Sprites[instance.ObjectId].Size;
                Rectangle rect = new Rectangle((int)(instance.X * Zoom), (int)(instance.Y * Zoom), (int)(size.Width * Zoom), (int)(size.Height * Zoom));

                // If the rectangle contains the mouse.
                if (rect.Contains(point))
                {
                    // Get location on the sprite.
                    int x = point.X - (int)(instance.X * Zoom);
                    int y = point.Y - (int)(instance.Y * Zoom);

                    // Get the pixel from the sprite.
                    Color color = Color.FromArgb(GraphicsManager.Sprites[instance.ObjectId].Pixels[(int)(x / Zoom), (int)(y / Zoom)]);

                    // If not on a transparent pixel. (Pixels arranged in GDI format) :P
                    if (color.B != 0)
                    {
                        // If the instance should be selected.
                        if (set == true)
                        {
                            // Set dragging instance.
                            _selectedInstance = instance;

                            // Fire selected instance changed event.
                            SelectedInstanceChanged();
                        }

                        // Set cursor.
                        this.Cursor = Cursors.SizeAll;
                        return true;
                    }
                }
            }

            // If an instance needs to be set, clear selected instance for a new one.
            if (set == true)
                _selectedInstance = null;

            return false;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a shallow copy of this instance.
        /// </summary>
        /// <returns>A shallow copy of this instance.</returns>
        public GMareInstance Clone()
        {
            // Create new instance.
            GMareInstance instance = new GMareInstance();

            // Set properties.
            instance.CreationCode = (string)CreationCode.Clone();
            instance.Depth = Depth;
            instance.Id = Id;
            instance.LastChanged = LastChanged;
            instance.Locked = Locked;
            instance.Name = (string)Name.Clone();
            instance.ObjectId = ObjectId;
            instance.X = X;
            instance.Y = Y;

            // Return instance.
            return instance;
        }