Exemplo n.º 1
0
        private bool SetImage(RenderBreakViewModel viewModel)
        {
            bool   wasSet  = false;
            string texture = viewModel.Texture;

            if (System.IO.File.Exists(texture))
            {
                mPictureBox.Load(texture);



                if (mPictureBox.Image != null)
                {
                    bool      shouldCrop = false;
                    Rectangle cropArea   = new Rectangle();

                    GetCropArea(viewModel, ref shouldCrop, ref cropArea, mPictureBox.Image);

                    if (shouldCrop)
                    {
                        mPictureBox.Image = CropImage(mPictureBox.Image, cropArea);
                    }
                    mPictureBox.Width  = mPictureBox.Image.Width;
                    mPictureBox.Height = mPictureBox.Image.Height;
                }

                wasSet = true;
            }
            return(wasSet);
        }
Exemplo n.º 2
0
        private void GetCropArea(RenderBreakViewModel viewModel, ref bool shouldCrop, ref Rectangle cropArea, System.Drawing.Image image)
        {
            if (!ShowEntireTexture)
            {
                if (viewModel.ObjectCausingBreak is Sprite)
                {
                    var asSprite = viewModel.ObjectCausingBreak as Sprite;

                    if (asSprite.Texture != null)
                    {
                        cropArea = new Rectangle(
                            MathFunctions.RoundToInt(asSprite.LeftTexturePixel),
                            MathFunctions.RoundToInt(asSprite.TopTexturePixel),
                            MathFunctions.RoundToInt(asSprite.RightTexturePixel - asSprite.LeftTexturePixel),
                            MathFunctions.RoundToInt(asSprite.BottomTexturePixel - asSprite.TopTexturePixel));
                    }
                }
                // We don't want to have to include Gum dlls in this tool, nor do we want to force
                // users to have to include the dlls to use this, so we'll base it on reflection:
                else if (viewModel.ObjectCausingBreak.GetType().FullName == "RenderingLibrary.Graphics.Sprite")
                {
                    var field = viewModel.ObjectCausingBreak.GetType().GetField("SourceRectangle");

                    var sourceNullable = field.GetValue(viewModel.ObjectCausingBreak) as Rectangle?;

                    if (sourceNullable.HasValue)
                    {
                        var source = sourceNullable.Value;

                        cropArea = new Rectangle(
                            MathFunctions.RoundToInt(source.Left),
                            MathFunctions.RoundToInt(source.Top),
                            MathFunctions.RoundToInt(source.Width),
                            MathFunctions.RoundToInt(source.Height));
                    }
                }

                shouldCrop =
                    cropArea.X != 0 ||
                    cropArea.Y != 0 ||
                    cropArea.Width < image.Width ||
                    cropArea.Height < image.Height;

                // if the texture is displaying beyond its bounds, then
                // it's probably wrapping. We'll just display the entire texture
                // for now:
                if (cropArea.Width + cropArea.X > image.Width)
                {
                    shouldCrop = false;
                }

                if (cropArea.Height + cropArea.Y > image.Height)
                {
                    shouldCrop = false;
                }
            }
        }
Exemplo n.º 3
0
        private void GetRenderBreaksFromEngineInternal()
        {
            var list = FlatRedBall.Graphics.Renderer.LastFrameRenderBreakList;


            List <RenderBreakViewModel> viewModels = new List <RenderBreakViewModel>();

            foreach (var item in list)
            {
                viewModels.Add(RenderBreakViewModel.FromRenderBreak(item));
            }


            UpdateFromRenderBreakSaves(viewModels);
        }
Exemplo n.º 4
0
        public void LoadRenderBreaks(string fileName)
        {
            List <RenderBreakSave> loadedRenderBreaks =
                FileManager.XmlDeserialize <List <RenderBreakSave> >(fileName);

            List <RenderBreakViewModel> viewModels = new List <RenderBreakViewModel>();

            foreach (var item in loadedRenderBreaks)
            {
                viewModels.Add(RenderBreakViewModel.FromRenderBreakSave(item));
            }


            UpdateFromRenderBreakSaves(viewModels);
        }
Exemplo n.º 5
0
        public static RenderBreakViewModel FromRenderBreakSave(RenderBreakSave renderBreakSave)
        {
            RenderBreakViewModel toReturn = new RenderBreakViewModel();

            toReturn.LayerName = renderBreakSave.LayerName;
            toReturn.Texture   = renderBreakSave.Texture;

            toReturn.ColorOperation     = renderBreakSave.ColorOperation;
            toReturn.BlendOperation     = renderBreakSave.BlendOperation;
            toReturn.TextureFilter      = renderBreakSave.TextureFilter;
            toReturn.TextureAddressMode = renderBreakSave.TextureAddressMode;

#if DEBUG
            toReturn.Details = renderBreakSave.Details;
#endif
            return(toReturn);
        }
Exemplo n.º 6
0
        public static RenderBreakViewModel FromRenderBreakSave(RenderBreakSave renderBreakSave)
        {
            RenderBreakViewModel toReturn = new RenderBreakViewModel();

            toReturn.LayerName = renderBreakSave.LayerName;
            toReturn.Texture = renderBreakSave.Texture;

            toReturn.ColorOperation = renderBreakSave.ColorOperation;
            toReturn.BlendOperation = renderBreakSave.BlendOperation;
            toReturn.TextureFilter = renderBreakSave.TextureFilter;
            toReturn.TextureAddressMode = renderBreakSave.TextureAddressMode;

#if DEBUG
            toReturn.Details = renderBreakSave.Details;
#endif
            return toReturn;
        }
Exemplo n.º 7
0
        public static RenderBreakViewModel FromRenderBreak(RenderBreak renderBreak)
        {
            RenderBreakViewModel toReturn = new RenderBreakViewModel();

            toReturn.LayerName = renderBreak.LayerName;
            if (renderBreak.Texture != null)
            {
                toReturn.Texture = renderBreak.Texture.Name;
            }

            toReturn.ColorOperation     = renderBreak.ColorOperation;
            toReturn.BlendOperation     = renderBreak.BlendOperation;
            toReturn.TextureFilter      = renderBreak.TextureFilter;
            toReturn.TextureAddressMode = renderBreak.TextureAddressMode;

#if DEBUG
            toReturn.Details = renderBreak.Details;
#endif

            toReturn.ObjectCausingBreak = renderBreak.ObjectCausingBreak;

            return(toReturn);
        }
Exemplo n.º 8
0
        public static RenderBreakViewModel FromRenderBreak(RenderBreak renderBreak)
        {
            RenderBreakViewModel toReturn = new RenderBreakViewModel();

            toReturn.LayerName = renderBreak.LayerName;
            if (renderBreak.Texture != null)
            {
                toReturn.Texture = renderBreak.Texture.Name;
            }

            toReturn.ColorOperation = renderBreak.ColorOperation;
            toReturn.BlendOperation = renderBreak.BlendOperation;
            toReturn.TextureFilter = renderBreak.TextureFilter;
            toReturn.TextureAddressMode = renderBreak.TextureAddressMode;

#if DEBUG
            toReturn.Details = renderBreak.Details;
#endif

            toReturn.ObjectCausingBreak = renderBreak.ObjectCausingBreak;

            return toReturn;
        }