Пример #1
0
        /// <summary>
        /// Enables a group of figures to be drawn using the same settings.
        /// </summary>
        /// <param name="device"></param>
        public DrawBatch (GraphicsDevice device)
        {
            if (device == null)
                throw new ArgumentNullException("device");

            _device = device;
            _device.DeviceReset += GraphicsDeviceReset;

            _infoBuffer = new DrawingInfo[2048];
            _indexBuffer = new short[32768];
            _vertexBuffer = new VertexPositionColorTexture[8192];
            _computeBuffer = new Vector2[64];
            _colorBuffer = new Color[64];
            _geometryBuffer = new Vector2[256];
            _pathBuilder = new PathBuilder();

            _standardEffect = new BasicEffect(device);
            _standardEffect.TextureEnabled = true;
            _standardEffect.VertexColorEnabled = true;

            _defaultTexture = new Texture2D(device, 1, 1);
            _defaultTexture.SetData<Color>(new Color[] { Color.White });

            _ws = new PenWorkspace();
        }
Пример #2
0
        private void InitializePaths()
        {
            var bounds = VisibleBoundsWorldspace;
            var center = bounds.Center;
            //var center = new CCVector2(200, 200);

            Pen lilypadPen = new Pen(CCColor4B.Green, 15)
            {
                Alignment = PenAlignment.Center
            };

            _lilypadPath = BuildLillyPad(center, 150, 0);
            _lilypadStroke = _lilypadPath.Stroke(lilypadPen, PathType.Closed);

            Pen outerFlowerPen = new Pen(CCColor4B.White * 0.75f, 15)
            {
                Alignment = PenAlignment.Outset
            };

            _outerFlowerStroke = BuildFlower(center, 8, 120, 100, (float)(Math.PI / 8)).Stroke(outerFlowerPen, PathType.Closed);

            Pen innerFlowerPen = new Pen(Microsoft.Xna.Framework.Color.MediumPurple * 0.5f, 10)
            {
                Alignment = PenAlignment.Outset
            };

            _innerFlowerStroke = BuildFlower(center, 16, 105, 60, 0).Stroke(innerFlowerPen, PathType.Closed);
        }
Пример #3
0
        public override void Setup (GraphicsDevice device)
        {
            _gradWidth = new GradientPen(Color.Lime, Color.Blue, 15);
            _gradLength = new PathGradientPen(Color.Lime, Color.Blue, 15);

            PathBuilder pathBuilder = new PathBuilder() { CalculateLengths = true };
            pathBuilder.AddPath(StarPoints(new Vector2(325, 75), 5, 50, 25, 0, false));

            _widthStar = pathBuilder.Stroke(_gradWidth, PathType.Open);
            _lengthStar = pathBuilder.Stroke(_gradLength, Matrix.CreateTranslation(0, 125, 0), PathType.Open);
        }
Пример #4
0
        private GraphicsPath CreateFlowerGP (Pen pen, Vector2 center, int petalCount, float petalLength, float petalWidth, float rotation)
        {
            List<Vector2> points = StarPoints(center, petalCount / 2, petalLength, petalLength, rotation, false);

            PathBuilder builder = new PathBuilder();
            builder.AddPoint(center);

            foreach (Vector2 point in points) {
                builder.AddArcByPoint(point, petalWidth / 2);
                builder.AddArcByPoint(center, petalWidth / 2);
            }

            return builder.Stroke(pen, PathType.Closed);
        }
Пример #5
0
        public GradientPens()
        {

            _gradWidth = new GradientPen(Microsoft.Xna.Framework.Color.Lime, Microsoft.Xna.Framework.Color.Blue, 15);
            _gradLength = new PathGradientPen(Microsoft.Xna.Framework.Color.Lime, Microsoft.Xna.Framework.Color.Blue, 15);

            PathBuilder pathBuilder = new PathBuilder() { CalculateLengths = true };
            pathBuilder.AddPath(StarPoints(new CCVector2(325, 75), 5, 50, 25, 0, false));

            _widthStar = pathBuilder.Stroke(_gradWidth, PathType.Open);
            _lengthStar = pathBuilder.Stroke(_gradLength, 
                CCAffineTransform.Translate(CCAffineTransform.Identity, 0, 125, 0), 
                PathType.Open);
        }
        public override void Setup (GraphicsDevice device)
        {
            _gradWidthInner = new GradientPen(Color.Lime, Color.Cyan, 15) { Alignment = PenAlignment.Inset, StartCap = LineCap.Square, EndCap = LineCap.Square };
            _gradWidthCenter = new GradientPen(Color.Lime, Color.Cyan, 15) { StartCap = LineCap.Square, EndCap = LineCap.Square };
            _gradWidthOuter = new GradientPen(Color.Lime, Color.Cyan, 15) { Alignment = PenAlignment.Outset, StartCap = LineCap.Square, EndCap = LineCap.Square };

            Pen[] pens = new Pen[] { _gradWidthInner, _gradWidthCenter, _gradWidthOuter };
            for (int i = 0; i < _gPaths.Length; i++) {
                PathBuilder builder = new PathBuilder();
                foreach (Vector2 v in _baseCoords)
                    builder.AddPoint(v + Offset(i));
                _gPaths[i] = builder.Stroke(pens[i]);
            }
        }
        public GradientPensAlignment()
        {
            _gradWidthInner = new GradientPen(Microsoft.Xna.Framework.Color.Lime, Microsoft.Xna.Framework.Color.Cyan, 15) { Alignment = PenAlignment.Inset, StartCap = LineCap.Square, EndCap = LineCap.Square };
            _gradWidthCenter = new GradientPen(Microsoft.Xna.Framework.Color.Lime, Microsoft.Xna.Framework.Color.Cyan, 15) { StartCap = LineCap.Square, EndCap = LineCap.Square };
            _gradWidthOuter = new GradientPen(Microsoft.Xna.Framework.Color.Lime, Microsoft.Xna.Framework.Color.Cyan, 15) { Alignment = PenAlignment.Outset, StartCap = LineCap.Square, EndCap = LineCap.Square };

            Pen[] pens = new Pen[] { _gradWidthInner, _gradWidthCenter, _gradWidthOuter };
            for (int i = 0; i < _gPaths.Length; i++)
            {
                PathBuilder builder = new PathBuilder();
                foreach (CCVector2 v in _baseCoords)
                    builder.AddPoint(v + Offset(i));
                _gPaths[i] = builder.Stroke(pens[i]);
            }
        }
Пример #8
0
        /// <summary>
        /// Appends all of the points within another <see cref="PathBuilder"/> object to the end of the path.
        /// </summary>
        /// <param name="path">An existing path.</param>
        public void AddPath(PathBuilder path)
        {
            if (path._geometryIndex == 0)
            {
                return;
            }

            if (path._geometryIndex == 1)
            {
                AddPoint(path._geometryBuffer[0]);
                return;
            }

            CheckBufferFreeSpace(path._geometryIndex);

            int startIndex = LastPointEqual(path._geometryBuffer[0]) ? 1 : 0;
            int baseIndex  = _geometryIndex;

            for (int i = startIndex; i < path._geometryIndex; i++)
            {
                _geometryBuffer[_geometryIndex++] = path._geometryBuffer[i];
            }

            if (_calculateLengths)
            {
                if (path._lengthBuffer != null)
                {
                    for (int i = startIndex; i < path._geometryIndex; i++)
                    {
                        _lengthBuffer[baseIndex++] = path._lengthBuffer[i];
                    }
                }
                else
                {
                    CalculateLengthsInRange(baseIndex, path._geometryIndex - baseIndex);
                }
            }
        }
Пример #9
0
        private void InitializePaths ()
        {
            Vector2 center = new Vector2(200, 200);

            Pen lilypadPen = new Pen(Color.Green, 15) {
                Alignment = PenAlignment.Center
            };

            _lilypadPath = BuildLillyPad(center, 150, 0);
            _lilypadStroke = _lilypadPath.Stroke(lilypadPen, PathType.Closed);

            Pen outerFlowerPen = new Pen(Color.White * 0.75f, 15) {
                Alignment = PenAlignment.Outset
            };

            _outerFlowerStroke = BuildFlower(center, 8, 120, 100, (float)(Math.PI / 8)).Stroke(outerFlowerPen, PathType.Closed);

            Pen innerFlowerPen = new Pen(Color.MediumPurple * 0.5f, 10) {
                Alignment = PenAlignment.Outset
            };

            _innerFlowerStroke = BuildFlower(center, 16, 105, 60, 0).Stroke(innerFlowerPen, PathType.Closed);
        }
Пример #10
0
        /// <summary>
        /// Appends all of the points within another <see cref="PathBuilder"/> object to the end of the path.
        /// </summary>
        /// <param name="path">An existing path.</param>
        public void AddPath (PathBuilder path)
        {
            if (path._geometryIndex == 0)
                return;

            if (path._geometryIndex == 1) {
                AddPoint(path._geometryBuffer[0]);
                return;
            }

            CheckBufferFreeSpace(path._geometryIndex);

            int startIndex = LastPointEqual(path._geometryBuffer[0]) ? 1 : 0;
            int baseIndex = _geometryIndex;

            for (int i = startIndex; i < path._geometryIndex; i++)
                _geometryBuffer[_geometryIndex++] = path._geometryBuffer[i];

            if (_calculateLengths) {
                if (path._lengthBuffer != null) {
                    for (int i = startIndex; i < path._geometryIndex; i++)
                        _lengthBuffer[baseIndex++] = path._lengthBuffer[i];
                }
                else
                    CalculateLengthsInRange(baseIndex, path._geometryIndex - baseIndex);
            }
        }
Пример #11
0
        private static PathBuilder BuildLillyPad (Vector2 center, int radius, float rotation)
        {
            float segment = (float)(Math.PI * 2 / 32);

            PathBuilder builder = new PathBuilder();

            builder.AddPoint(center);
            builder.AddLine(radius, segment * 25 + rotation);
            builder.AddArcByAngle(center, segment * 30, radius / 2);

            return builder;
        }
Пример #12
0
        private static PathBuilder BuildFlower (Vector2 center, int petalCount, float petalLength, float petalWidth, float rotation)
        {
            List<Vector2> points = StarPoints(center, petalCount / 2, petalLength, petalLength, rotation, false);

            PathBuilder builder = new PathBuilder();
            builder.AddPoint(center);

            foreach (Vector2 point in points) {
                builder.AddArcByPoint(point, petalWidth / 2);
                builder.AddArcByPoint(center, petalWidth / 2);
            }

            return builder;
        }
Пример #13
0
        /// <summary>
        /// Enables a group of figures to be drawn using the same settings.
        /// </summary>
        /// <param name="device"></param>
        //public DrawBatch (GraphicsDevice device)
        //{
        public DrawBatch () : base()
        {
            //if (device == null)
            //    throw new ArgumentNullException("device");

            //_device = device;
            //_device.DeviceReset += GraphicsDeviceReset;

            _infoBuffer = new DrawingInfo[2048];
            //var info = base.CreateGeometryInstance(8192, 32768);
            
            _indexBuffer = new short[32768];
            _vertexBuffer = new VertexPositionColorTexture[8192];
            _computeBuffer = new CCVector2[64];
            _colorBuffer = new Color[64];
            _geometryBuffer = new CCVector2[256];
            _pathBuilder = new PathBuilder();

            //_standardEffect = new BasicEffect(device);
            //_standardEffect.TextureEnabled = true;
            //_standardEffect.VertexColorEnabled = true;

            //_defaultTexture = new Texture2D(device, 1, 1);
            //_defaultTexture.SetData<Color>(new Color[] { Microsoft.Xna.Framework.Color.White });
            _sortMode = DrawSortMode.Immediate;

            _ws = new PenWorkspace();
        }