Esempio n. 1
0
        /// <summary>
        /// Add a sprite image to the sprite sheet.
        /// </summary>
        /// <param name="path">File path and name of image to load.</param>
        public void AddSprite(string path)
        {
            Image2 img = new Image2(path, mSpritesList.Count);

            //getnextimage will return a bool representing if there is room for new image.
            if (!GetNextImagePosition(img))
            {
                if (PopNotEnoughRoom() == MessageBoxResult.Yes)
                {
                    //set to auto resize
                    AutoResize = true;
                    GetNextImagePosition(img);
                }
                else
                {
                    return;
                }
            }
            mWindow.canvasControl.Children.Add(img.ImageControl);
            HasChanged = true;

            mSpritesList.Add(img);

            mAtlasDoc.AddSprite(
                img.ID.ToString(),
                ((int)img.Left).ToString(),
                ((int)img.Top).ToString(),
                ((int)img.Width).ToString(),
                ((int)img.Height).ToString());
        }
Esempio n. 2
0
 public ImageHighlight(Image2 image)
 {
     mImage               = image;
     mRec.Width           = mImage.Width;
     mRec.Height          = mImage.Height;
     mRec.Stroke          = new SolidColorBrush(mStrokeColor);
     mRec.StrokeThickness = mStrokeThickness;
     mRec.StrokeDashArray = mStrokeDashArray;
 }
Esempio n. 3
0
        private bool GetNextImagePosition(Image2 newImage)
        {
            //position will be default values 0,0
            if (mSpritesList.Count == 0)
            {
                //need to check if image fits
                if (Width > newImage.Width && Height > newImage.Height)
                {
                    return(true);
                }
                else
                {
                    if (!AutoResize)
                    {
                        return(false);
                    }
                    else//auto resize so adjust the canvas
                    {
                        if (Width > newImage.Width)
                        {
                            Width = newImage.Width;
                        }
                        if (Height > newImage.Height)
                        {
                            Height = newImage.Height;
                        }
                        return(true);
                    }
                }
            }

            Image2 lastImage = mSpritesList[mSpritesList.Count - 1];
            //check if need new row
            double highestYInRow = GetHighestYInRow();

            if (lastImage.Left + lastImage.Width + newImage.Width > Width)
            {
                ////wont fit in this row, will fit in new row?
                if (highestYInRow + newImage.Height > Height || newImage.Width > Width)
                {
                    if (!AutoResize)
                    {
                        return(false);
                    }
                    else
                    {
                        //resize the canvas
                        if (newImage.Width > Width)
                        {
                            Width = newImage.Width;
                        }
                        if (highestYInRow + newImage.Height > Height)
                        {
                            Height = highestYInRow + newImage.Height;
                        }
                    }
                }

                newImage.Left = 0;
                newImage.Top  = highestYInRow;
            }
            else
            {
                if (lastImage.Top + newImage.Height > Height)
                {
                    if (!AutoResize)
                    {
                        return(false);
                    }
                    else
                    {
                        Height = lastImage.Top + newImage.Height;
                    }
                }
                newImage.Left = lastImage.Left + lastImage.Width;
                newImage.Top  = lastImage.Top;
            }
            return(true);
        }