Esempio n. 1
0
        /// <summary>
        /// Searches for a particular texture info
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public AtlasNode FindNode(object userData)
        {
            if (mUserData == userData)
            {
                return(this);
            }

            AtlasNode node = null;

            if (mLeft != null)
            {
                node = mLeft.FindNode(userData);
                if (node != null)
                {
                    return(node);
                }
            }

            if (mRight != null)
            {
                node = mRight.FindNode(userData);
                if (node != null)
                {
                    return(node);
                }
            }

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="image"></param>
        /// <param name="rectangle"></param>
        public AtlasNode(object userData, Image image, Rectangle rectangle)
        {
            mUserData = userData;
            mImage = image;
            mRectangle = rectangle;

            mLeft = null;
            mRight = null;
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="info"></param>
        /// <param name="image"></param>
        /// <param name="rectangle"></param>
        public AtlasNode(object userData, Image image, Rectangle rectangle)
        {
            mUserData  = userData;
            mImage     = image;
            mRectangle = rectangle;

            mLeft  = null;
            mRight = null;
        }
Esempio n. 4
0
        private void DisposeAtlasNode(AtlasNode node)
        {
            if (node == null)
                return;

            DisposeAtlasNode(node.mLeft);
            DisposeAtlasNode(node.mRight);

            FontBuilder.Glyph glyph = node.mUserData as FontBuilder.Glyph;
            if (glyph != null && glyph.mBitmap != null)
            {
                glyph.mBitmap.Dispose();

                if (node.mImage != glyph.mBitmap)
                {
                    node.mImage.Dispose();
                }

                node.mImage = null;
                glyph.mBitmap = null;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a new texture and image to a particular node
        /// </summary>
        /// <param name="info"></param>
        /// <param name="image"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool AddTexture(Image image, object userData, AtlasNode node)
        {
            if (node == null)
                return false;

            if (node.mUserData != null)
                return false;

            if (node.mLeft != null && node.mRight != null)
            {
                if (AddTexture(image, userData, node.mLeft))
                    return true;

                if (AddTexture(image, userData, node.mRight))
                    return true;

                return false;
            }

            if (node.mRectangle.Width < image.Width ||
                node.mRectangle.Height < image.Height)
            {
                return false;
            }

            if (node.mRectangle.Width == image.Width &&
                node.mRectangle.Height == image.Height)
            {
                node.mUserData = userData;
                node.mImage = image;
                return true;
            }

            int dw = node.mRectangle.Width - image.Width;
            int dh = node.mRectangle.Height - image.Height;

            if (dw > dh)
            {
                node.mLeft = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                     node.mRectangle.Top,
                                                                     image.Width,
                                                                     node.mRectangle.Height));

                node.mRight = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left + image.Width,
                                                                      node.mRectangle.Top,
                                                                      node.mRectangle.Width - image.Width,
                                                                      node.mRectangle.Height));
            }
            else
            {
                node.mLeft = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                     node.mRectangle.Top,
                                                                     node.mRectangle.Width,
                                                                     image.Height));

                node.mRight = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                      node.mRectangle.Top + image.Height,
                                                                      node.mRectangle.Width,
                                                                      node.mRectangle.Height - image.Height));
            }

            return AddTexture(image, userData, node.mLeft);
        }
Esempio n. 6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="filename"></param>
 public TextureAtlas(uint id, int width, int height, string filename)
 {
     mID = id;
     mRoot = new AtlasNode(null, null, new Rectangle(0, 0, width, height));
     mFilename = filename;
 }
Esempio n. 7
0
        /// <summary>
        /// Adds a new texture and image to a particular node
        /// </summary>
        /// <param name="info"></param>
        /// <param name="image"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool AddTexture(Image image, object userData, AtlasNode node)
        {
            if (node == null)
            {
                return(false);
            }

            if (node.mUserData != null)
            {
                return(false);
            }

            if (node.mLeft != null && node.mRight != null)
            {
                if (AddTexture(image, userData, node.mLeft))
                {
                    return(true);
                }

                if (AddTexture(image, userData, node.mRight))
                {
                    return(true);
                }

                return(false);
            }

            if (node.mRectangle.Width < image.Width ||
                node.mRectangle.Height < image.Height)
            {
                return(false);
            }

            if (node.mRectangle.Width == image.Width &&
                node.mRectangle.Height == image.Height)
            {
                node.mUserData = userData;
                node.mImage    = image;
                return(true);
            }

            int dw = node.mRectangle.Width - image.Width;
            int dh = node.mRectangle.Height - image.Height;

            if (dw > dh)
            {
                node.mLeft = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                     node.mRectangle.Top,
                                                                     image.Width,
                                                                     node.mRectangle.Height));

                node.mRight = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left + image.Width,
                                                                      node.mRectangle.Top,
                                                                      node.mRectangle.Width - image.Width,
                                                                      node.mRectangle.Height));
            }
            else
            {
                node.mLeft = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                     node.mRectangle.Top,
                                                                     node.mRectangle.Width,
                                                                     image.Height));

                node.mRight = new AtlasNode(null, null, new Rectangle(node.mRectangle.Left,
                                                                      node.mRectangle.Top + image.Height,
                                                                      node.mRectangle.Width,
                                                                      node.mRectangle.Height - image.Height));
            }

            return(AddTexture(image, userData, node.mLeft));
        }
Esempio n. 8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="id"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="filename"></param>
 public TextureAtlas(uint id, int width, int height, string filename)
 {
     mID       = id;
     mRoot     = new AtlasNode(null, null, new Rectangle(0, 0, width, height));
     mFilename = filename;
 }