Beispiel #1
0
        /// <summary>
        /// Draws random shapes.
        /// </summary>
        private void DrawShapes(BitmapBuffer writeableBmp)
        {
            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
                // Init some size vars
                int w  = writeableBmp.PixelWidth - 2;
                int h  = writeableBmp.PixelHeight - 2;
                int w2 = w >> 1;
                int h2 = h >> 1;

                // Clear
                writeableBmp.Clear();

                // Fill Shapes
                for (int i = 0; i < shapeCount; i++)
                {
                    // Random polygon
                    int[] p = new int[rand.Next(5, 10) * 2];
                    for (int j = 0; j < p.Length; j += 2)
                    {
                        p[j]     = rand.Next(w);
                        p[j + 1] = rand.Next(h);
                    }
                    writeableBmp.FillPolygon(p, GetRandomColor());
                }

                // Invalidates on exit of Using block
            }
        }
Beispiel #2
0
        /// <summary>
        /// Draws the different types of shapes.
        /// </summary>
        private void DrawStaticShapes(BitmapBuffer writeableBmp)
        {
            // HideShapeCountText();

            // Wrap updates in a GetContext call, to prevent invalidation and nested locking/unlocking during this block
            using (writeableBmp.GetBitmapContext())
            {
                // Init some size vars
                int w   = writeableBmp.PixelWidth;
                int h   = writeableBmp.PixelHeight;
                int w3  = w / 3;
                int h3  = h / 3;
                int w6  = w3 >> 1;
                int h6  = h3 >> 1;
                int w12 = w6 >> 1;
                int h12 = h6 >> 1;

                // Clear
                writeableBmp.Clear();

                // Fill closed concave polygon
                var p = new int[]
                {
                    w12 >> 1, h12,
                    w6, h3 - (h12 >> 1),
                    w3 - (w12 >> 1), h12,
                    w6 + w12, h12,
                    w6, h6 + h12,
                    w12, h12,
                    w12 >> 1, h12,
                };
                writeableBmp.FillPolygonsEvenOdd(new[] { p }, GetRandomColor());

                // Fill closed convex polygon
                p = new int[]
                {
                    w3 + w6, h12 >> 1,
                    w3 + w6 + w12, h12,
                    w3 + w6 + w12, h6 + h12,
                    w3 + w6, h6 + h12 + (h12 >> 1),
                    w3 + w12, h6 + h12,
                    w3 + w12, h12,
                    w3 + w6, h12 >> 1,
                };
                writeableBmp.FillPolygon(p, GetRandomColor());

                // Fill Triangle + Quad
                writeableBmp.FillTriangle(2 * w3 + w6, h12 >> 1, 2 * w3 + w6 + w12, h6 + h12, 2 * w3 + w12, h6 + h12,
                                          GetRandomColor());
                writeableBmp.FillQuad(w6, h3 + (h12 >> 1), w6 + w12, h3 + h6, w6, h3 + h6 + h12 + (h12 >> 1), w12,
                                      h3 + h6, GetRandomColor());

                // Fill Ellipses
                writeableBmp.FillEllipse(rand.Next(w3, w3 + w6), rand.Next(h3, h3 + h6), rand.Next(w3 + w6, 2 * w3),
                                         rand.Next(h3 + h6, 2 * h3), GetRandomColor());
                writeableBmp.FillEllipseCentered(2 * w3 + w6, h3 + h6, w12, h12, GetRandomColor());

                // Fill closed Cardinal Spline curve
                p = new int[]
                {
                    w12 >> 1, 2 * h3 + h12,
                    w6, h - (h12 >> 1),
                    w3 - (w12 >> 1), 2 * h3 + h12,
                    w6 + w12, 2 * h3 + h12,
                    w6, 2 * h3 + (h12 >> 1),
                    w12, 2 * h3 + h12,
                };
                writeableBmp.FillCurveClosed(p, 0.5f, GetRandomColor());

                // Fill closed Beziér curve
                p = new int[]
                {
                    w3 + w12, 2 * h3 + h6 + h12,
                    w3 + w6 + (w12 >> 1), 2 * h3,
                    w3 + w6 + w12 + (w12 >> 1), 2 * h3,
                    w3 + w6 + w12, 2 * h3 + h6 + h12,
                };
                writeableBmp.FillBeziers(p, GetRandomColor());

                // Fill Rectangle
                writeableBmp.FillRectangle(rand.Next(2 * w3, 2 * w3 + w6), rand.Next(2 * h3, 2 * h3 + h6),
                                           rand.Next(2 * w3 + w6, w), rand.Next(2 * h3 + h6, h), GetRandomColor());
                // Fill another rectangle with alpha blending
                writeableBmp.FillRectangle(rand.Next(2 * w3, 2 * w3 + w6), rand.Next(2 * h3, 2 * h3 + h6),
                                           rand.Next(2 * w3 + w6, w), rand.Next(2 * h3 + h6, h), GetRandomColor(), true);

                BitmapBufferEx.ColorInt black = BitmapBufferEx.ColorInt.FromArgb(255, 0, 0, 0);
                // Draw Grid
                writeableBmp.DrawLine(0, h3, w, h3, Colors.Black);
                writeableBmp.DrawLine(0, 2 * h3, w, 2 * h3, Colors.Black);
                writeableBmp.DrawLine(w3, 0, w3, h, Colors.Black);
                writeableBmp.DrawLine(2 * w3, 0, 2 * w3, h, Colors.Black);

                // Invalidates on exit of Using block
            }
        }
        /// <summary>
        /// fill with BitmapBufferExtension lib
        /// </summary>
        void FillWithBxt(VertexStoreSnap snap)
        {
            //transate the vxs/snap to command
            double x          = 0;
            double y          = 0;
            double offsetOrgX = this.OriginX;
            double offsetOrgY = this.OriginY;

            VertexSnapIter snapIter = snap.GetVertexSnapIter();
            VertexCmd      cmd;

            int latestMoveToX = 0, latestMoveToY = 0;
            int latestX = 0, latestY = 0;


            bool closed = false;

            _reusablePolygonList.Clear();

            while ((cmd = snapIter.GetNextVertex(out x, out y)) != VertexCmd.NoMore)
            {
                x += offsetOrgX;
                y += offsetOrgY;

                switch (cmd)
                {
                case VertexCmd.MoveTo:
                {
                    if (_reusablePolygonList.Count > 0)
                    {
                        //no drawline
                        _reusablePolygonList.Clear();
                    }

                    closed = false;
                    _reusablePolygonList.Add(latestMoveToX = latestX = (int)Math.Round(x));
                    _reusablePolygonList.Add(latestMoveToY = latestY = (int)Math.Round(y));
                }
                break;

                case VertexCmd.LineTo:
                case VertexCmd.P2c:
                case VertexCmd.P3c:
                {
                    //collect to the polygon
                    _reusablePolygonList.Add(latestX = (int)Math.Round(x));
                    _reusablePolygonList.Add(latestY = (int)Math.Round(y));
                }
                break;

                case VertexCmd.Close:
                case VertexCmd.CloseAndEndFigure:
                {
                    if (_reusablePolygonList.Count > 0)
                    {
                        //flush by draw line
                        _reusablePolygonList.Add(latestX = latestMoveToX);
                        _reusablePolygonList.Add(latestY = latestMoveToY);

                        _bxt.FillPolygon(_reusablePolygonList.ToArray(),
                                         this.fillColor.ToARGB());
                    }

                    _reusablePolygonList.Clear();
                    closed = true;
                }
                break;

                default:
                    break;
                }
            }
            //---------------
            if (!closed && (_reusablePolygonList.Count > 0) &&
                (latestX == latestMoveToX) && (latestY == latestMoveToY))
            {
                //flush by draw line
                _reusablePolygonList.Add(latestMoveToX);
                _reusablePolygonList.Add(latestMoveToY);

                _bxt.FillPolygon(
                    _reusablePolygonList.ToArray(),
                    this.fillColor.ToARGB());
            }
        }