Exemple #1
0
        private void GenPrimitives()
        {
            
            SizeF csize = this.ClientSize;
            // since backbuffer size is the same as this.Client size.
            
            Random r = new Random(7737);
            int w = (int)csize.Width;
            int h = (int)csize.Height;

           if (m_sampleDrawing == SampleDrawings.FillSolidRects
                
                || m_sampleDrawing == SampleDrawings.Draw_Rects)
            {


                int itemCount = 300;
                m_rects.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    int cx = r.Next(-40, w);
                    int cy = r.Next(-40, h);
                    int width = r.Next(20, 140);
                    int height = r.Next(20, 140);
                    Rectangle rect =
                        new Rectangle(cx, cy, width, height);
                    m_rects.Add(rect);
                }

                if (m_sampleDrawing == SampleDrawings.FillSolidRects)
                    m_drawInfo = string.Format("Fill {0} solid rectangles", itemCount);                
                else
                    m_drawInfo = string.Format("Draw {0} rectangles", itemCount);
            }

            else if (m_sampleDrawing == SampleDrawings.DrawRandomLines1
                || m_sampleDrawing == SampleDrawings.DrawRandomLines2)
            {
                int itemCount = 2000;
                m_lines.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    PointF pt1 = new PointF(r.Next(w), r.Next(h));
                    PointF pt2 = new PointF(r.Next(w), r.Next(h));
                    m_lines.Add(new Line(pt1, pt2));
                }

                if (m_sampleDrawing == SampleDrawings.DrawRandomLines1)
                    m_drawInfo = string.Format("Draw {0} lines width = 1", itemCount);
                else
                    m_drawInfo = string.Format("Draw {0} lines width = 2", itemCount);
            }
           
           
           
            else if (m_sampleDrawing == SampleDrawings.DrawBeziers)
            {
                r = new Random(7737);
                int itemCount = 200;
                Bezier bz = new Bezier();
                bz.P1 = new PointF(0, 0);
                bz.P2 = new PointF(20, 25);
                bz.P3 = new PointF(40, -25);
                bz.P4 = new PointF(60, 25);

                m_beziers.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    Bezier b = new Bezier();
                    SizeF sz = new SizeF();
                    sz.Width = r.Next(w);
                    sz.Height = r.Next(h);
                    b.P1 = bz.P1 + sz;
                    b.P2 = bz.P2 + sz;
                    b.P3 = bz.P3 + sz;
                    b.P4 = bz.P4 + sz;
                    m_beziers.Add(b);
                }
                m_drawInfo = string.Format("Draw {0} beziers", itemCount);
            }
            
            else if (m_sampleDrawing == SampleDrawings.DrawText)
            {

                r = new Random(7737);
                int itemCount = 200;
                m_texts.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    PointF pt = new PointF(r.Next(w), r.Next(h));
                    m_texts.Add(pt);
                }
                m_drawInfo = string.Format("Draw {0} text", itemCount);

            }
            else if (m_sampleDrawing == SampleDrawings.DrawBitmaps)
            {
                m_drawInfo = "Draw overlapping transparent bitmaps";
            }
           
            m_fps = 0.0f;
            UpdateInfo();
        }
Exemple #2
0
        private void GenPrimitives()
        {
            
            SizeF csize = m_d2dGraphics.Size;            

            Random r = new Random(7737);
            int w = (int)csize.Width;
            int h = (int)csize.Height;

            if (m_sampleDrawing == SampleDrawings.DrawFewStates)
            {
                m_drawInfo = "draw few states";
            }
            else if (m_sampleDrawing == SampleDrawings.FillSolidRects
                || m_sampleDrawing == SampleDrawings.FillGradientRects1
                || m_sampleDrawing == SampleDrawings.FillGradientRects2
                || m_sampleDrawing == SampleDrawings.FillGradientRects3
                || m_sampleDrawing == SampleDrawings.DrawRects
                || m_sampleDrawing == SampleDrawings.DrawRectsWithBitmapMasks
                || m_sampleDrawing == SampleDrawings.FillBmpRects)

            {
                int itemCount = 500;
                m_rects.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    float cx = r.Next(-40, w);
                    float cy = r.Next(-40, h);
                    float width = r.Next(20, 140);
                    float height = r.Next(20, 140);
                    RectangleF rect =
                        new RectangleF(cx, cy, width, height);
                    m_rects.Add(rect);
                }

                if (m_sampleDrawing == SampleDrawings.FillSolidRects)
                    m_drawInfo = string.Format("Fill {0} solid rectangles", itemCount);
                else if (m_sampleDrawing == SampleDrawings.FillGradientRects1
                    || m_sampleDrawing == SampleDrawings.FillGradientRects2
                    || m_sampleDrawing == SampleDrawings.FillGradientRects3)
                    m_drawInfo = string.Format("Fill {0} gradient rectangles", itemCount);
                else if (m_sampleDrawing == SampleDrawings.FillBmpRects)
                    m_drawInfo = string.Format("Fill {0} rectangles using bitmap brush", itemCount);
                else if (m_sampleDrawing == SampleDrawings.DrawRectsWithBitmapMasks)
                    m_drawInfo = string.Format("Fill {0} rectangles using bitmap's alpha blending", itemCount);
                else
                    m_drawInfo = string.Format("Draw {0} rectangles", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.FillSolidRoundedRects
                || m_sampleDrawing == SampleDrawings.DrawRoundedRects)
            {
                int itemCount = 300;
                m_roundedRects.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    float cx = r.Next(-40, w);
                    float cy = r.Next(-40, h);
                    float width = r.Next(20, 140);
                    float height = r.Next(20, 140);
                    D2dRoundedRect roundRect = new D2dRoundedRect();
                    roundRect.Rect = new RectangleF(cx, cy, width, height);
                    roundRect.RadiusX = 12;
                    roundRect.RadiusY = 12;
                    m_roundedRects.Add(roundRect);
                }

                if (m_sampleDrawing == SampleDrawings.FillSolidRoundedRects)
                    m_drawInfo = string.Format("Fill {0} solid rounded rectangles", itemCount);
                else
                    m_drawInfo = string.Format("Draw {0} rounded rectangles", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawRandomLines1
                || m_sampleDrawing == SampleDrawings.DrawRandomLines2)
            {
                int itemCount = 2000;
                m_lines.Clear();
                for (int i = 0; i < itemCount; i++)
                {

                    PointF pt1 = new PointF(r.Next(w), r.Next(h));
                    //PointF pt2 = new PointF(pt1.X + r.Next(-20, 20), pt1.Y+r.Next(-20, 20));
                    PointF pt2 = new PointF(r.Next(w), r.Next(h));
                    m_lines.Add(new Line(pt1, pt2));
                }

                if (m_sampleDrawing == SampleDrawings.DrawRandomLines1)
                    m_drawInfo = string.Format("Draw {0} lines width = 1", itemCount);
                else
                    m_drawInfo = string.Format("Draw {0} lines width = 2", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawConnectedLines)
            {
                int itemCount = 200;
                m_connectedLines.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    PointF pt = new PointF(r.Next(w), r.Next(h));
                    m_connectedLines.Add(pt);
                }
                m_drawInfo = string.Format("Draw {0} connected lines width = 2", itemCount - 1);
            }
            else if (m_sampleDrawing == SampleDrawings.FillSolidEllipse)
            {
                int itemCount = 300;
                m_ellipses.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    D2dEllipse elp = new D2dEllipse();
                    elp.Center = new PointF(r.Next(w), r.Next(h));
                    elp.RadiusX = r.Next(20, 120);
                    elp.RadiusY = r.Next(20, 120);
                    m_ellipses.Add(elp);
                }

                m_drawInfo = string.Format("Fill {0} solid ellipses", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawOrbs)
            {
                int itemCount = 60;
                m_ellipses.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    D2dEllipse elp = new D2dEllipse();
                    elp.Center = new PointF(r.Next(w), r.Next(h));
                    float rad = r.Next(60,120);
                    elp.RadiusX = rad;
                    elp.RadiusY = rad;
                    m_ellipses.Add(elp);
                }
                m_drawInfo = string.Format("Render {0} Glass balls", itemCount);

            }
            else if (m_sampleDrawing == SampleDrawings.DrawEllipse)
            {
                int itemCount = 200;
                m_ellipses.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    int k = i + 10;
                    D2dEllipse elp = new D2dEllipse();
                    elp.Center = new PointF(k + k / 2, k + k / 2);
                    elp.RadiusX = k / 2;
                    elp.RadiusY = k / 2;
                    m_ellipses.Add(elp);
                }
                m_drawInfo = string.Format("Draw {0} ellipses", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawBeziers)
            {
                r = new Random(7737);
                int itemCount = 200;
                Bezier bz = new Bezier();
                
                bz.P1 = new PointF(0, 0);
                bz.P2 = new PointF(20f, 25f);
                bz.P3 = new PointF(40f, -25f);
                bz.P4 = new PointF(60f, 25f);

                m_beziers.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    Bezier b = new Bezier();
                    SizeF sz = new SizeF();
                    sz.Width = r.Next(w);
                    sz.Height = r.Next(h);
                    b.P1 = bz.P1 + sz;
                    b.P2 = bz.P2 + sz;
                    b.P3 = bz.P3 + sz;
                    b.P4 = bz.P4 + sz;
                    m_beziers.Add(b);
                }
                m_drawInfo = string.Format("Draw {0} beziers", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawCachedBitmap)
            {
                m_drawInfo = "Draw of screen buffer (bitmap)";
            }
            else if (m_sampleDrawing == SampleDrawings.DrawText)
            {
                r = new Random(7737);
                int itemCount = 200;
                m_texts.Clear();                
                for (int i = 0; i < itemCount; i++)
                {
                    PointF pt = new PointF(r.Next(w), r.Next(h));
                    m_texts.Add(pt);                    
                }
                m_drawInfo = string.Format("Draw {0} text", itemCount);
            }
            else if (m_sampleDrawing == SampleDrawings.DrawTextLayout)
            {
                foreach (D2dTextLayout txtlayout in m_textLayouts)
                    txtlayout.Dispose();

                r = new Random(7737);
                int itemCount = 200;
                m_texts.Clear();                
                m_textLayouts.Clear();
                for (int i = 0; i < itemCount; i++)
                {
                    PointF pt = new PointF(r.Next(w), r.Next(h));
                    m_texts.Add(pt);
                    D2dTextLayout txtLayout =
                        D2dFactory.CreateTextLayout("Draw Text " + i, m_generalTextFormat);
                    m_textLayouts.Add(txtLayout);                    
                }
                m_drawInfo = string.Format("Draw {0} text layout", itemCount);

            }
            else if (m_sampleDrawing == SampleDrawings.DrawBitmaps)
            {
                m_drawInfo = "Draw overlapping transparent bitmaps";
            }
            else if (m_sampleDrawing == SampleDrawings.GdiInterOp)
            {
                m_drawInfo = "Gdi interop";
            }
            else if (m_sampleDrawing == SampleDrawings.DrawTriangle)
            {
                m_drawInfo = "Fill and draw a triangle";
            }

            m_fps = 0.0f;
            UpdateInfo();
        }