示例#1
0
        protected override void loadCompact(aBinaryReader reader)
        {
            base.loadCompact(reader);

            var finder = bloResourceFinder.getFinder();

            mTextureCount = 1;
            mTextures[0]  = finder.find <bloTexture>(reader, "timg");
            mPalette      = finder.find <bloPalette>(reader, "tlut");

            mBinding = (bloBinding)reader.Read8();

            int bits = reader.Read8();

            mMirror   = (bloMirror)((bits >> 0) & 3);
            mRotate90 = ((bits & 4) != 0);
            mWrapS    = (bloWrapMode)((bits >> 3) & 3);
            mWrapT    = mWrapS;

            reader.Skip(4);

            for (int i = 0; i < 4; ++i)
            {
                mColors[i] = new bloColor(bloColor.cWhite);
            }

            setBlendKonstColor();
            setBlendKonstAlpha();
        }
示例#2
0
        protected override void loadXml(xElement element)
        {
            base.loadXml(element);

            var finder = bloResourceFinder.getFinder();

            mTextureCount = 1;
            mTextures[0]  = finder.find <bloTexture>(element.Element("texture"), "timg");
            mPalette      = finder.find <bloPalette>(element.Element("palette"), "tlut");

            if (!Enum.TryParse <bloBinding>(element.Element("binding"), true, out mBinding))
            {
                mBinding = (bloBinding.Left | bloBinding.Top | bloBinding.Right | bloBinding.Bottom);
            }

            if (!Enum.TryParse <bloMirror>(element.Element("mirror"), true, out mMirror))
            {
                mMirror = 0;
            }

            mRotate90 = (element.Element("rotate-90") | false);

            if (!Enum.TryParse <bloWrapMode>(element.Element("wrap-s"), true, out mWrapS))
            {
                mWrapS = bloWrapMode.None;
            }

            if (!Enum.TryParse <bloWrapMode>(element.Element("wrap-t"), true, out mWrapT))
            {
                mWrapT = bloWrapMode.None;
            }

            bloXml.loadGradient(element.Element("gradient"), out mFromColor, out mToColor);

            var white  = new bloColor(bloColor.cWhite);
            var colors = element.Element("colors");

            mColors[(int)bloTextureBase.TopLeft]     = bloXml.loadColor(colors.Element("top-left"), white);
            mColors[(int)bloTextureBase.TopRight]    = bloXml.loadColor(colors.Element("top-right"), white);
            mColors[(int)bloTextureBase.BottomLeft]  = bloXml.loadColor(colors.Element("bottom-left"), white);
            mColors[(int)bloTextureBase.BottomRight] = bloXml.loadColor(colors.Element("bottom-right"), white);

            setBlendKonstColor();
            setBlendKonstAlpha();
        }
示例#3
0
 static void loadCornerXml(TextureSlot slot, bloResourceFinder finder, xElement element, bloMirror defMirror)
 {
     slot.texture = finder.find <bloTexture>(element.Element("texture"), "timg");
     slot.color   = bloXml.loadColor(element.Element("color"), new bloColor(bloColor.cWhite));
     if (!Enum.TryParse <bloMirror>(element.Element("mirror"), out slot.mirror))
     {
         slot.mirror = 0;
     }
 }
示例#4
0
        protected override void loadBlo1(aBinaryReader reader)
        {
            base.loadBlo1(reader);

            var finder = bloResourceFinder.getFinder();

            int numparams = reader.Read8();

            mTextureCount = 1;
            mTextures[0]  = finder.find <bloTexture>(reader, "timg");
            mPalette      = finder.find <bloPalette>(reader, "tlut");
            mBinding      = (bloBinding)reader.Read8();

            numparams -= 3;

            if (numparams > 0)
            {
                int bits = reader.Read8();
                mMirror   = (bloMirror)(bits & 3);
                mRotate90 = ((bits & 4) != 0);
                --numparams;
            }
            else
            {
                mMirror   = 0;
                mRotate90 = false;
            }

            if (numparams > 0)
            {
                int bits = reader.Read8();
                mWrapS = (bloWrapMode)((bits >> 2) & 3);
                mWrapT = (bloWrapMode)((bits >> 0) & 3);
                --numparams;
            }
            else
            {
                mWrapS = bloWrapMode.None;
                mWrapT = bloWrapMode.None;
            }

            if (numparams > 0)
            {
                mFromColor = new bloColor(reader.Read32());
                --numparams;
            }
            else
            {
                mFromColor = new bloColor(bloColor.cZero);
            }

            if (numparams > 0)
            {
                mToColor = new bloColor(reader.Read32());
                --numparams;
            }
            else
            {
                mToColor = new bloColor(bloColor.cOne);
            }

            for (int i = 0; i < 4; ++i)
            {
                if (numparams > 0)
                {
                    mColors[i] = new bloColor(reader.Read32());
                    --numparams;
                }
                else
                {
                    mColors[i] = new bloColor(bloColor.cWhite);
                }
            }

            reader.Skip(4);

            setBlendKonstColor();
            setBlendKonstAlpha();
        }
示例#5
0
        void drawSelf(int x, int y, int width, int height, bloBinding binding, bloMirror mirror, bool rotate90, bloWrapMode wrapS, bloWrapMode wrapT)
        {
            var texture = mTextures[0];

            // wrapping
            int left = x;
            int top  = y;

            if (wrapS == bloWrapMode.None)
            {
                double cap = (rotate90 ? texture.getHeight() : texture.getWidth());
                if (!binding.hasFlag(bloBinding.Left))
                {
                    if (width > cap)
                    {
                        left = (int)(
                            binding.hasFlag(bloBinding.Right) ?
                            (x + width - cap) : (x + ((width - cap)) / 2)
                            );
                        width = (int)cap;
                    }
                }
                else if (!binding.hasFlag(bloBinding.Right))
                {
                    if (width > cap)
                    {
                        width = (int)cap;
                    }
                }
            }

            if (mWrapT == bloWrapMode.None)
            {
                double cap = (rotate90 ? texture.getWidth() : texture.getHeight());
                if (!binding.hasFlag(bloBinding.Top))
                {
                    if (height > cap)
                    {
                        top = (int)(
                            binding.hasFlag(bloBinding.Bottom) ?
                            (y + height - cap) : (y + ((height - cap)) / 2)
                            );
                        height = (int)cap;
                    }
                }
                else if (!binding.hasFlag(bloBinding.Bottom))
                {
                    if (height > cap)
                    {
                        height = (int)cap;
                    }
                }
            }

            // binding
            bool bindLeft, bindRight, bindTop, bindBottom;

            if (rotate90)
            {
                bindLeft   = (mirror.hasFlag(bloMirror.X) ? binding.hasFlag(bloBinding.Bottom) : binding.hasFlag(bloBinding.Top));
                bindRight  = (mirror.hasFlag(bloMirror.X) ? binding.hasFlag(bloBinding.Top) : binding.hasFlag(bloBinding.Bottom));
                bindTop    = (mirror.hasFlag(bloMirror.Y) ? binding.hasFlag(bloBinding.Left) : binding.hasFlag(bloBinding.Right));
                bindBottom = (mirror.hasFlag(bloMirror.Y) ? binding.hasFlag(bloBinding.Right) : binding.hasFlag(bloBinding.Left));
            }
            else
            {
                bindLeft   = (mirror.hasFlag(bloMirror.X) ? binding.hasFlag(bloBinding.Right) : binding.hasFlag(bloBinding.Left));
                bindRight  = (mirror.hasFlag(bloMirror.X) ? binding.hasFlag(bloBinding.Left) : binding.hasFlag(bloBinding.Right));
                bindTop    = (mirror.hasFlag(bloMirror.Y) ? binding.hasFlag(bloBinding.Bottom) : binding.hasFlag(bloBinding.Top));
                bindBottom = (mirror.hasFlag(bloMirror.Y) ? binding.hasFlag(bloBinding.Top) : binding.hasFlag(bloBinding.Bottom));
            }

            // U mapping
            int    rectWidth = (rotate90 ? height : width);
            double texWidth = texture.getWidth();
            double widthFactor = (rectWidth / texWidth);
            double fLeft, fRight;

            if (bindLeft)
            {
                fLeft  = 0.0d;
                fRight = (bindRight ? 1.0d : widthFactor);
            }
            else if (bindRight)
            {
                fLeft  = (1.0d - widthFactor);
                fRight = 1.0d;
            }
            else
            {
                fLeft  = (0.5d - (widthFactor * 0.5d));
                fRight = (0.5d + (widthFactor * 0.5d));
            }

            // V mapping
            int    rectHeight = (rotate90 ? width : height);
            double texHeight = texture.getHeight();
            double heightFactor = (rectHeight / texHeight);
            double fTop, fBottom;

            if (bindTop)
            {
                fTop    = 0.0d;
                fBottom = (bindBottom ? 1.0d : heightFactor);
            }
            else if (bindBottom)
            {
                fTop    = (1.0d - heightFactor);
                fBottom = 1.0d;
            }
            else
            {
                fTop    = (0.5d - (heightFactor * 0.5d));
                fBottom = (0.5d + (heightFactor * 0.5d));
            }

            // mirror
            if (mirror.hasFlag(bloMirror.X))
            {
                bloMath.swap(ref fLeft, ref fRight);
            }

            if (mirror.hasFlag(bloMirror.Y))
            {
                bloMath.swap(ref fTop, ref fBottom);
            }

            // render
            if (rotate90)
            {
                drawSelf(
                    (left - x), (top - y), width, height,
                    new Vector2d(fLeft, fBottom),
                    new Vector2d(fLeft, fTop),
                    new Vector2d(fRight, fBottom),
                    new Vector2d(fRight, fTop)
                    );
            }
            else
            {
                drawSelf(
                    (left - x), (top - y), width, height,
                    new Vector2d(fLeft, fTop),
                    new Vector2d(fRight, fTop),
                    new Vector2d(fLeft, fBottom),
                    new Vector2d(fRight, fBottom)
                    );
            }
        }
示例#6
0
 public void draw(bloRectangle rectangle, bloMirror mirror, bool rotate90)
 {
     draw(rectangle.left, rectangle.top, rectangle.width, rectangle.height, mirror.hasFlag(bloMirror.X), mirror.hasFlag(bloMirror.Y), rotate90);
 }
示例#7
0
 public static bool hasFlag(this bloMirror value, bloMirror flag)
 {
     return((value & flag) == flag);
 }