public static TextureRegion CreateFromSource(Texture pTexture, ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
        {
            TextureRegion textureRegion = new TextureRegion(pTexture, pTexturePositionX, pTexturePositionY, pTextureSource.GetWidth(), pTextureSource.GetHeight());

            pTexture.AddTextureSource(pTextureSource, textureRegion.GetTexturePositionX(), textureRegion.GetTexturePositionY());
            return(textureRegion);
        }
Beispiel #2
0
        public static Texture CreateForTextureSourceSize(ITextureSource pTextureSource, TextureOptions pTextureOptions)
        {
            int loadingScreenWidth  = pTextureSource.GetWidth();
            int loadingScreenHeight = pTextureSource.GetHeight();

            return(new Texture(MathUtils.NextPowerOfTwo(loadingScreenWidth), MathUtils.NextPowerOfTwo(loadingScreenHeight), pTextureOptions));
        }
        public static TiledTextureRegion CreateTiledFromSource(Texture pTexture, ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY, int pTileColumns, int pTileRows)
        {
            TiledTextureRegion tiledTextureRegion = new TiledTextureRegion(pTexture, pTexturePositionX, pTexturePositionY, pTextureSource.GetWidth(), pTextureSource.GetHeight(), pTileColumns, pTileRows);

            pTexture.AddTextureSource(pTextureSource, tiledTextureRegion.GetTexturePositionX(), tiledTextureRegion.GetTexturePositionY());
            return(tiledTextureRegion);
        }
Beispiel #4
0
        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        // ===========================================================
        // Methods
        // ===========================================================

        public TextureSourceWithLocation AddTextureSource(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY) /* throws IllegalArgumentException */
        {
            this.CheckTextureSourcePosition(pTextureSource, pTexturePositionX, pTexturePositionY);

            TextureSourceWithLocation textureSourceWithLocation = new TextureSourceWithLocation(pTextureSource, pTexturePositionX, pTexturePositionY);

            this.mTextureSources.Add(textureSourceWithLocation);
            this.mUpdateOnHardwareNeeded = true;
            return(textureSourceWithLocation);
        }
Beispiel #5
0
 private void CheckTextureSourcePosition(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY) /* throws IllegalArgumentException */
 {
     if (pTexturePositionX < 0)
     {
         throw new IllegalArgumentException("Illegal negative pTexturePositionX supplied: '" + pTexturePositionX + "'");
     }
     else if (pTexturePositionY < 0)
     {
         throw new IllegalArgumentException("Illegal negative pTexturePositionY supplied: '" + pTexturePositionY + "'");
     }
     else if (pTexturePositionX + pTextureSource.GetWidth() > this.mWidth || pTexturePositionY + pTextureSource.GetHeight() > this.mHeight)
     {
         throw new IllegalArgumentException("Supplied TextureSource must not exceed bounds of Texture.");
     }
 }
        /**
         * Removes a {@link ITextureSource} before {@link BuildableTexture#build(ITextureBuilder)} is called.
         * @param pTextureSource to be removed.
         */
        public void RemoveTextureSource(ITextureSource pTextureSource)
        {
            //final ArrayList<TextureSourceWithWithLocationCallback> textureSources = this.mTextureSourcesToPlace;
            List <TextureSourceWithWithLocationCallback> textureSources = this.mTextureSourcesToPlace;

            for (int i = textureSources.Count - 1; i >= 0; i--)
            {
                TextureSourceWithWithLocationCallback textureSource = textureSources[i];
                if (textureSource.mTextureSource == pTextureSource)
                {
                    textureSources.RemoveAt(i);
                    this.mUpdateOnHardwareNeeded = true;
                    return;
                }
            }
        }
Beispiel #7
0
        public void RemoveTextureSource(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
        {
            //final ArrayList<TextureSourceWithLocation> textureSources = this.mTextureSources;
            List <TextureSourceWithLocation> textureSources = this.mTextureSources;

            for (int i = textureSources.Count - 1; i >= 0; i--)
            {
                TextureSourceWithLocation textureSourceWithLocation = textureSources[i];
                if (textureSourceWithLocation.mTextureSource == pTextureSource && textureSourceWithLocation.mTexturePositionX == pTexturePositionX && textureSourceWithLocation.mTexturePositionY == pTexturePositionY)
                {
                    textureSources.RemoveAt(i);
                    this.mUpdateOnHardwareNeeded = true;
                    return;
                }
            }
        }
            //private Node createChildren(final ITextureSource pTextureSource, final int pTextureWidth, final int pTextureHeight, final int pTextureSpacing, final int pDeltaWidth, final int pDeltaHeight) {
            private NodeClass CreateChildren(ITextureSource pTextureSource, int pTextureWidth, int pTextureHeight, int pTextureSpacing, int pDeltaWidth, int pDeltaHeight)
            {
                RectClass rect = this.mRect;

                if (pDeltaWidth >= pDeltaHeight)
                {
                    /* Split using a vertical axis. */
                    this.mChildA = new NodeClass(
                        rect.GetLeft(),
                        rect.GetTop(),
                        pTextureSource.GetWidth() + pTextureSpacing,
                        rect.GetHeight()
                        );

                    this.mChildB = new NodeClass(
                        rect.GetLeft() + (pTextureSource.GetWidth() + pTextureSpacing),
                        rect.GetTop(),
                        rect.GetWidth() - (pTextureSource.GetWidth() + pTextureSpacing),
                        rect.GetHeight()
                        );
                }
                else
                {
                    /* Split using a horizontal axis. */
                    this.mChildA = new NodeClass(
                        rect.GetLeft(),
                        rect.GetTop(),
                        rect.GetWidth(),
                        pTextureSource.GetHeight() + pTextureSpacing
                        );

                    this.mChildB = new NodeClass(
                        rect.GetLeft(),
                        rect.GetTop() + (pTextureSource.GetHeight() + pTextureSpacing),
                        rect.GetWidth(),
                        rect.GetHeight() - (pTextureSource.GetHeight() + pTextureSpacing)
                        );
                }

                return(this.mChildA.Insert(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing));
            }
        // ===========================================================
        // Getter & Setter
        // ===========================================================

        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        //@SuppressWarnings("deprecation")
        //@Override
        //public override void pack(final BuildableTexture pBuildableTexture, final ArrayList<TextureSourceWithWithLocationCallback> pTextureSourcesWithLocationCallback) throws IllegalArgumentException {
        public /* override */ void Pack(BuildableTexture pBuildableTexture, List <TextureSourceWithLocationCallback> pTextureSourcesWithLocationCallback)
        {
            //Collections.sort(pTextureSourcesWithLocationCallback, TEXTURESOURCE_COMPARATOR);
            pTextureSourcesWithLocationCallback.Sort((IComparer <TextureSourceWithLocationCallback>)TEXTURESOURCE_COMPARER);

            NodeClass root = new NodeClass(new RectClass(0, 0, pBuildableTexture.GetWidth(), pBuildableTexture.GetHeight()));

            int textureSourceCount = pTextureSourcesWithLocationCallback.Count;

            for (int i = 0; i < textureSourceCount; i++)
            {
                TextureSourceWithLocationCallback textureSourceWithLocationCallback = pTextureSourcesWithLocationCallback[i];
                ITextureSource textureSource = textureSourceWithLocationCallback.GetTextureSource();

                NodeClass inserted = root.Insert(textureSource, pBuildableTexture.GetWidth(), pBuildableTexture.GetHeight(), this.mTextureSourceSpacing);

                if (inserted == null)
                {
                    throw new IllegalArgumentException("Could not pack: " + textureSource.ToString());
                }
                TextureSourceWithLocation textureSourceWithLocation = pBuildableTexture.AddTextureSource(textureSource, inserted.mRect.mLeft, inserted.mRect.mTop);
                textureSourceWithLocationCallback.GetCallback().OnCallback(textureSourceWithLocation);
            }
        }
Beispiel #10
0
            // ===========================================================
            // Constructors
            // ===========================================================

            public TextureSourceWithLocation(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
            {
                this.mTextureSource    = pTextureSource;
                this.mTexturePositionX = pTexturePositionX;
                this.mTexturePositionY = pTexturePositionY;
            }
Beispiel #11
0
 public /* override */ virtual void OnTextureSourceLoadExeption(Texture pTexture, ITextureSource pTextureSource, Throwable pThrowable)
 {
     Debug.E("Exception loading TextureSource. Texture: " + pTexture.ToString() + " TextureSource: " + pTextureSource, pThrowable);
 }
Beispiel #12
0
 public /* override */ virtual void OnTextureSourceLoadExeption(Texture pTexture, ITextureSource pTextureSource, Throwable pThrowable)
 {
 }
Beispiel #13
0
 public void RemoveTextureSource(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
 {
     //final ArrayList<TextureSourceWithLocation> textureSources = this.mTextureSources;
     List<TextureSourceWithLocation> textureSources = this.mTextureSources;
     for (int i = textureSources.Count - 1; i >= 0; i--)
     {
         TextureSourceWithLocation textureSourceWithLocation = textureSources[i];
         if (textureSourceWithLocation.mTextureSource == pTextureSource && textureSourceWithLocation.mTexturePositionX == pTexturePositionX && textureSourceWithLocation.mTexturePositionY == pTexturePositionY)
         {
             textureSources.RemoveAt(i);
             this.mUpdateOnHardwareNeeded = true;
             return;
         }
     }
 }
        // ===========================================================
        // Methods
        // ===========================================================

        /**
         * When all {@link ITextureSource}s are added you have to call {@link BuildableTexture#build(ITextureBuilder)}.
         * @param pTextureSource to be added.
         * @param pTextureRegion
         */
        public void AddTextureSource(ITextureSource pTextureSource, andengine.util.Callback <TextureSourceWithLocation> pCallback)
        {
            this.mTextureSourcesToPlace.Add(new TextureSourceWithWithLocationCallback(pTextureSource, pCallback));
        }
Beispiel #15
0
 private void CheckTextureSourcePosition(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY) /* throws IllegalArgumentException */ {
     if (pTexturePositionX < 0)
     {
         throw new IllegalArgumentException("Illegal negative pTexturePositionX supplied: '" + pTexturePositionX + "'");
     }
     else if (pTexturePositionY < 0)
     {
         throw new IllegalArgumentException("Illegal negative pTexturePositionY supplied: '" + pTexturePositionY + "'");
     }
     else if (pTexturePositionX + pTextureSource.GetWidth() > this.mWidth || pTexturePositionY + pTextureSource.GetHeight() > this.mHeight)
     {
         throw new IllegalArgumentException("Supplied TextureSource must not exceed bounds of Texture.");
     }
 }
            // ===========================================================
            // Constructors
            // ===========================================================

            public TextureSourceWithWithLocationCallback(ITextureSource pTextureSource, andengine.util.Callback <TextureSourceWithLocation> pCallback)
            {
                this.mTextureSource = pTextureSource;
                mCallback           = pCallback;
            }
Beispiel #17
0
 public /* override */ virtual void OnTextureSourceLoadExeption(Texture pTexture, ITextureSource pTextureSource, Throwable pThrowable)
 {
     Debug.E("Exception loading TextureSource. Texture: " + pTexture.ToString() + " TextureSource: " + pTextureSource, pThrowable);
 }
Beispiel #18
0
            // ===========================================================
            // Constructors
            // ===========================================================

            public TextureSourceWithLocation(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
            {
                this.mTextureSource = pTextureSource;
                this.mTexturePositionX = pTexturePositionX;
                this.mTexturePositionY = pTexturePositionY;
            }
Beispiel #19
0
 public static Texture CreateForTextureSourceSize(ITextureSource pTextureSource)
 {
     return(CreateForTextureSourceSize(pTextureSource, TextureOptions.DEFAULT));
 }
Beispiel #20
0
 public EngineOptions SetLoadingScreenTextureSource(/* final */ ITextureSource pLoadingScreenTextureSource)
 {
     this.mLoadingScreenTextureSource = pLoadingScreenTextureSource;
     return(this);
 }
        /*
         * public static TiledTextureRegion createTiledFromSource(final BuildableTexture pBuildableTexture, final ITextureSource pTextureSource, final int pTileColumns, final int pTileRows) {
         *  final TiledTextureRegion tiledTextureRegion = new TiledTextureRegion(pBuildableTexture, 0, 0, pTextureSource.getWidth(), pTextureSource.getHeight(), pTileColumns, pTileRows);
         *  pBuildableTexture.addTextureSource(pTextureSource, new Callback<TextureSourceWithLocation>() {
         *      @Override
         *      public void onCallback(final TextureSourceWithLocation pCallbackValue) {
         *          tiledTextureRegion.setTexturePosition(pCallbackValue.getTexturePositionX(), pCallbackValue.getTexturePositionY());
         *      }
         *  });
         *  return tiledTextureRegion;
         * }
         */
        public static TiledTextureRegion CreateTiledFromSource(BuildableTexture pBuildableTexture, ITextureSource pTextureSource, int pTileColumns, int pTileRows)
        {
            //TiledTextureRegion tiledTextureRegion = new TiledTextureRegion(pBuildableTexture, 0, 0, pTextureSource.getWidth(), pTextureSource.getHeight(), pTileColumns, pTileRows);
            TiledTextureRegion tiledTextureRegion = new TiledTextureRegion(pBuildableTexture, 0, 0, pTextureSource.GetWidth(), pTextureSource.GetHeight(), pTileColumns, pTileRows);

            pBuildableTexture.AddTextureSource(pTextureSource, new TextureSourceWithLocationCallback(tiledTextureRegion));
            return(tiledTextureRegion);
        }
 public EngineOptions SetLoadingScreenTextureSource(/* final */ ITextureSource pLoadingScreenTextureSource)
 {
     this.mLoadingScreenTextureSource = pLoadingScreenTextureSource;
     return this;
 }
Beispiel #23
0
 public /* override */ virtual void OnTextureSourceLoadExeption(Texture pTexture, ITextureSource pTextureSource, Throwable pThrowable) { }
        public static TextureRegion CreateFromSource(BuildableTexture pBuildableTexture, ITextureSource pTextureSource)
        {
            TextureRegion textureRegion = new TextureRegion(pBuildableTexture, 0, 0, pTextureSource.GetWidth(), pTextureSource.GetHeight());
            TextureSourceWithLocationCallback callback = new TextureSourceWithLocationCallback(textureRegion);

            pBuildableTexture.AddTextureSource(pTextureSource, callback);
            return(textureRegion);
        }
            // ===========================================================
            // Methods for/from SuperClass/Interfaces
            // ===========================================================

            // ===========================================================
            // Methods
            // ===========================================================

            //	public Node insert(final ITextureSource pTextureSource, final int pTextureWidth, final int pTextureHeight, final int pTextureSpacing) throws IllegalArgumentException {
            public NodeClass Insert(ITextureSource pTextureSource, int pTextureWidth, int pTextureHeight, int pTextureSpacing) /* throws IllegalArgumentException */
            {
                if (this.mChildA != null && this.mChildB != null)
                {
                    NodeClass newNode = this.mChildA.Insert(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing);
                    if (newNode != null)
                    {
                        return(newNode);
                    }
                    else
                    {
                        return(this.mChildB.Insert(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing));
                    }
                }
                else
                {
                    if (this.mTextureSource != null)
                    {
                        return(null);
                    }

                    int textureSourceWidth  = pTextureSource.GetWidth();
                    int textureSourceHeight = pTextureSource.GetHeight();

                    int rectWidth  = this.mRect.GetWidth();
                    int rectHeight = this.mRect.GetHeight();

                    if (textureSourceWidth > rectWidth || textureSourceHeight > rectHeight)
                    {
                        return(null);
                    }

                    int textureSourceWidthWithSpacing  = textureSourceWidth + pTextureSpacing;
                    int textureSourceHeightWithSpacing = textureSourceHeight + pTextureSpacing;

                    int rectLeft = this.mRect.GetLeft();
                    int rectTop  = this.mRect.GetTop();

                    bool fitToBottomWithoutSpacing = textureSourceHeight == rectHeight && rectTop + textureSourceHeight == pTextureHeight;
                    bool fitToRightWithoutSpacing  = textureSourceWidth == rectWidth && rectLeft + textureSourceWidth == pTextureWidth;

                    if (textureSourceWidthWithSpacing == rectWidth)
                    {
                        if (textureSourceHeightWithSpacing == rectHeight)
                        { /* Normal case with padding. */
                            this.mTextureSource = pTextureSource;
                            return(this);
                        }
                        else if (fitToBottomWithoutSpacing)
                        { /* Bottom edge of the Texture. */
                            this.mTextureSource = pTextureSource;
                            return(this);
                        }
                    }

                    if (fitToRightWithoutSpacing)
                    { /* Right edge of the Texture. */
                        if (textureSourceHeightWithSpacing == rectHeight)
                        {
                            this.mTextureSource = pTextureSource;
                            return(this);
                        }
                        else if (fitToBottomWithoutSpacing)
                        { /* Bottom edge of the Texture. */
                            this.mTextureSource = pTextureSource;
                            return(this);
                        }
                        else if (textureSourceHeightWithSpacing > rectHeight)
                        {
                            return(null);
                        }
                        else
                        {
                            return(CreateChildren(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing, rectWidth - textureSourceWidth, rectHeight - textureSourceHeightWithSpacing));
                        }
                    }

                    if (fitToBottomWithoutSpacing)
                    {
                        if (textureSourceWidthWithSpacing == rectWidth)
                        {
                            this.mTextureSource = pTextureSource;
                            return(this);
                        }
                        else if (textureSourceWidthWithSpacing > rectWidth)
                        {
                            return(null);
                        }
                        else
                        {
                            return(CreateChildren(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing, rectWidth - textureSourceWidthWithSpacing, rectHeight - textureSourceHeight));
                        }
                    }
                    else if (textureSourceWidthWithSpacing > rectWidth || textureSourceHeightWithSpacing > rectHeight)
                    {
                        return(null);
                    }
                    else
                    {
                        return(CreateChildren(pTextureSource, pTextureWidth, pTextureHeight, pTextureSpacing, rectWidth - textureSourceWidthWithSpacing, rectHeight - textureSourceHeightWithSpacing));
                    }
                }
            }
        // ===========================================================
        // Getter & Setter
        // ===========================================================

        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        /**
         * Most likely this is not the method you'd want to be using, as the {@link ITextureSource} won't get packed through this.
         * Use {@link BuildableTexture#addTextureSource(ITextureSource)} instead.
         */
        /// @Deprecated
        public new TextureSourceWithLocation AddTextureSource(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY)
        {
            return(base.AddTextureSource(pTextureSource, pTexturePositionX, pTexturePositionY));
        }
Beispiel #27
0
        // ===========================================================
        // Methods for/from SuperClass/Interfaces
        // ===========================================================

        // ===========================================================
        // Methods
        // ===========================================================

        public TextureSourceWithLocation AddTextureSource(ITextureSource pTextureSource, int pTexturePositionX, int pTexturePositionY) /* throws IllegalArgumentException */ {
            this.CheckTextureSourcePosition(pTextureSource, pTexturePositionX, pTexturePositionY);

            TextureSourceWithLocation textureSourceWithLocation = new TextureSourceWithLocation(pTextureSource, pTexturePositionX, pTexturePositionY);
            this.mTextureSources.Add(textureSourceWithLocation);
            this.mUpdateOnHardwareNeeded = true;
            return textureSourceWithLocation;
        }