Ejemplo n.º 1
0
        /// <summary>
        /// Painting a single column (using a range).
        /// </summary>
        /// <param name="x">Global position X</param>
        /// <param name="y">Global position Y</param>
        /// <param name="r">Range from a shape</param>
        /// <param name="c">Color to be painted</param>
        private void PaintColumn(int x, int y, Range r, PaintingParameters pp)
        {
            int height = r.Length;
            //We don't use a method for getting chunk id because we need some variables
            int xchunk      = x / chunkSizeX;
            int ychunk      = y / chunkSizeY;
            int posInChunkX = x - xchunk * chunkSizeX;
            int posInChunkY = y - ychunk * chunkSizeY;
            int cid         = xchunk * ChunkCountY + ychunk;

            int k = 0;

            //Iterate over possible chunks vertically that can be contained in painting for this range
            while (true)
            {
                if (cid >= 0 && cid < Chunks.Count && k + ychunk < ChunkCountY && (k - 1) * chunkSizeY <= height)
                {
                    Chunks[cid].Paint(new RectInt(posInChunkX, posInChunkY - k * chunkSizeY, 1, r.Length + 1), pp);
                    cid++;
                    k++;
                }
                else
                {
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public void Paint(PaintingParameters paintingParameters)
        {
            int k = 0;

            foreach (Range r in paintingParameters.Shape.Ranges)
            {
                PaintColumn(paintingParameters.Position.x + k, paintingParameters.Position.y + r.Min, r, paintingParameters);
                k++;
            }
        }
Ejemplo n.º 3
0
        public override bool Paint(RectInt r, PaintingParameters pp)
        {
            bool b = base.Paint(r, pp);

            if (pp.DestructionMode == DestructionMode.DESTROY)
            {
                DeleteFromColumns(r);
            }
            if (pp.DestructionMode == DestructionMode.BUILD)
            {
                AddToColumns(r);
            }

            return(b);
        }
Ejemplo n.º 4
0
        public virtual bool Paint(RectInt r, PaintingParameters pp)
        {
            if (pp.PaintingMode == PaintingMode.NONE)
            {
                return(false);
            }

            //Find common rect that will be applied on this texture rect
            RectInt common;

            r.Intersects(new RectInt(0, 0, TextureSource.Texture.width, TextureSource.Texture.height), out common);

            //Generate color array...
            int len = common.width * common.height;

            if (len == 0)
            {
                return(false);
            }

            Color[] cs = new Color[len];

            //...using paiting method
            if (pp.PaintingMode == PaintingMode.REPLACE_COLOR)
            {
                for (int i = 0; i < len; i++)
                {
                    cs[i] = pp.Color;
                }
            }
            else if (pp.PaintingMode == PaintingMode.ADD_COLOR)
            {
                for (int i = 0; i < common.width; i++)
                {
                    for (int j = 0; j < common.height; j++)
                    {
                        cs[i * common.height + j] = TextureSource.Texture.GetPixel(common.x + i, common.y + j) + pp.Color;
                    }
                }
            }

            //Apply color
            TextureSource.Texture.SetPixels(common.x, common.y, common.width, common.height, cs);

            //Set up this chunk as ready to be updated on next Update()
            painted = true;
            return(true);
        }