Example #1
0
        public static TextureCompiler.CColor[] GetTilePixels(Image <Rgba32> tex, int size, int uc, int frames)
        {
            int unit_size = size * size * frames * 4;

            if (uc == 2)
            {
                return(GetTilePartsCompound(tex, size, uc, frames, 0, 0));
            }
            else if (uc == 4)
            {
                var result = new TextureCompiler.CColor[unit_size * 4];
                GetTilePartsCompound(tex, size, uc, frames, 1, 1).CopyTo(result, unit_size * 0);
                GetTilePartsCompound(tex, size, uc, frames, 1, 0).CopyTo(result, unit_size * 1);
                GetTilePartsCompound(tex, size, uc, frames, 0, 1).CopyTo(result, unit_size * 2);
                GetTilePartsCompound(tex, size, uc, frames, 0, 0).CopyTo(result, unit_size * 3);
                return(result);
            }
            else if (uc == 6)
            {
                var result = new TextureCompiler.CColor[unit_size * 5];
                GetTilePartsCompound(tex, size, uc, frames, 2, 2).CopyTo(result, unit_size * 0);
                GetTilePartsCompound(tex, size, uc, frames, 2, 1).CopyTo(result, unit_size * 1);
                GetTilePartsCompound(tex, size, uc, frames, 1, 2).CopyTo(result, unit_size * 2);
                GetTilePartsCompound(tex, size, uc, frames, 1, 1).CopyTo(result, unit_size * 3);
                GetTilePartsCompound(tex, size, uc, frames, 0, 0).CopyTo(result, unit_size * 4);
                return(result);
            }
            else
            {
                throw new Exception("Unsupported texture format.");
            }
        }
Example #2
0
        public static TextureCompiler.CColor[] GetTilePartsCompound(Image <Rgba32> tex, int size, int uc, int frames, int px, int py)
        {
            var result = new TextureCompiler.CColor[size * size * frames * 4];

            GetTilePartFrames(tex, size, uc, frames, px, py).CopyTo(result, size * size * frames * 0);
            GetTilePartFrames(tex, size, uc, frames, px, uc - 1 - py).CopyTo(result, size * size * frames * 1);
            GetTilePartFrames(tex, size, uc, frames, uc - 1 - px, uc - 1 - py).CopyTo(result, size * size * frames * 2);
            GetTilePartFrames(tex, size, uc, frames, uc - 1 - px, py).CopyTo(result, size * size * frames * 3);
            return(result);
        }
Example #3
0
        public static TextureCompiler.CColor[] GetTilePartFrames(Image <Rgba32> tex, int size, int uc, int frames, int px, int py)
        {
            var result = new TextureCompiler.CColor[size * size * frames];

            for (int f = 0; f < frames; f++)
            {
                GetTilePartPixels(tex, size, px, py + f * uc).CopyTo(result, f * size * size);
            }
            return(result);
        }
Example #4
0
        public static TextureCompiler.CColor[] GetTilePartPixels(Image <Rgba32> tex, int size, int px, int py)
        {
            var result = new TextureCompiler.CColor[size * size];

            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    var p = tex[px * size + x, py *size + size - 1 - y];
                    result[y * size + x] = new TextureCompiler.CColor(p);
                }
            }

            return(result);
        }
        public static CSprite Compile(TextureCompiler texture, Sprite res, string root, string path)
        {
            var    csprite = new CSprite();
            string link    = Compiler.ResolveLink(root, path, res.Texture);

            csprite.TextureIndex = texture.FindLoad(
                root, link,
                (Image <Rgba32> img) =>
            {
                int tw = img.Width;
                int th = img.Height;

                var pixels = new TextureCompiler.CColor[tw * th];
                if (res.VerticalFrames)
                {
                    //if (th % res.FrameCount != 0) LogQueue.Put("Warning: Bad texture proporions.");
                    th /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[x, f * th + th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }
                else
                {
                    //if (tw % res.FrameCount != 0) LogQueue.Put("Warning: Bad texture proporions.");
                    tw /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[f * tw + x, th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }
                return(pixels);
            },
                (Image <Rgba32> img) =>
            {
                int w = img.Width;
                int h = img.Height;
                if (res.VerticalFrames)
                {
                    h /= res.FrameCount;
                }
                else
                {
                    w /= res.FrameCount;
                }
                return(new TextureCompiler.CColor[] { new TextureCompiler.CColor((uint)w), new TextureCompiler.CColor((uint)h) });
            }
                );
            csprite.FrameCount = res.FrameCount;
            csprite.FrameDelay = res.FrameDelay;
            csprite.ImgboxW    = res.ImgboxW;
            csprite.ImgboxH    = res.ImgboxH;
            csprite.AxisX      = res.AxisX;
            csprite.AxisY      = res.AxisY;
            csprite.Angle      = res.Angle;

            return(csprite);
        }
Example #6
0
        private CImage Compile(string path, InterfaceImage res)
        {
            var cimage = new CImage();

            cimage.Texture = Texture.FindLoad(
                RootDirectory,
                ResolveLink(path, res.Texture),
                (Image <Rgba32> img) =>
            {
                int tw = img.Width;
                int th = img.Height;

                var pixels = new TextureCompiler.CColor[tw * th];
                if (res.VerticalFrames)
                {
                    th /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[x, f * th + th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }
                else
                {
                    tw /= res.FrameCount;

                    for (int f = 0; f < res.FrameCount; f++)
                    {
                        for (int y = 0; y < th; y++)
                        {
                            for (int x = 0; x < tw; x++)
                            {
                                var p = img[f * tw + x, th - 1 - y];
                                pixels[f * tw * th + y * tw + x] = new TextureCompiler.CColor(p);
                            }
                        }
                    }
                }

                return(pixels);
            },
                (Image <Rgba32> img) =>
            {
                int w = img.Width;
                int h = img.Height;
                if (res.VerticalFrames)
                {
                    h /= res.FrameCount;
                }
                else
                {
                    w /= res.FrameCount;
                }
                return(new TextureCompiler.CColor[] { new TextureCompiler.CColor((uint)w), new TextureCompiler.CColor((uint)h) });
            }
                );

            cimage.Color   = new TextureCompiler.CColor(res.Color);
            cimage.Stretch = CImage.StretchType.Solid;
            if (cimage.Texture >= 0)
            {
                switch (res.Stretch)
                {
                case InterfaceTextureStretchType.Repeat: cimage.Stretch = CImage.StretchType.Repeat; break;

                case InterfaceTextureStretchType.Scale: cimage.Stretch = CImage.StretchType.Scale; break;
                }
            }
            return(cimage);
        }