コード例 #1
0
 /// <summary>
 /// Converts D2dEllipse to SharpDX.Ellipse</summary>
 internal static Ellipse ToSharpDX(this D2dEllipse ellipse)
 {
     return(new Ellipse
     {
         Point = ellipse.Center.ToSharpDX(),
         RadiusX = ellipse.RadiusX,
         RadiusY = ellipse.RadiusY
     });
 }
コード例 #2
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Paints the interior of the specified ellipse</summary>
 /// <param name="ellipse">The position and radius, in pixels, of the ellipse to paint</param>
 /// <param name="color">The color used to paint the interior of the ellipse</param>
 public void FillEllipse(D2dEllipse ellipse, Color color)
 {
     m_solidColorBrush.Color = color;
     FillEllipse(ellipse, m_solidColorBrush);
 }
コード例 #3
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Paints the interior of the specified ellipse</summary>
 /// <param name="ellipse">The position and radius, in pixels, of the ellipse to paint</param>
 /// <param name="brush">The brush used to paint the interior of the ellipse</param>
 public void FillEllipse(D2dEllipse ellipse, D2dBrush brush)
 {
     m_renderTarget.FillEllipse(ellipse.ToSharpDX(), brush.NativeBrush);
 }
コード例 #4
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Draws the outline of the specified ellipse</summary>
 /// <param name="ellipse">Position and radius of the ellipse to draw in pixels</param>
 /// <param name="color">The color used to paint the ellipse's outline</param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param>
 public void DrawEllipse(D2dEllipse ellipse, Color color, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     m_solidColorBrush.Color = color;
     DrawEllipse(ellipse, m_solidColorBrush, strokeWidth, strokeStyle);
 }
コード例 #5
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Draws the outline of the specified ellipse using the specified stroke style</summary>
 /// <param name="ellipse">Position and radius of the ellipse to draw in pixels</param>
 /// <param name="brush">The brush used to paint the ellipse's outline</param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param>
 public void DrawEllipse(D2dEllipse ellipse, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     m_renderTarget.DrawEllipse(ellipse.ToSharpDX(), brush.NativeBrush, strokeWidth,
         strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
 }
コード例 #6
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
 /// <summary>
 /// Draws an arc representing a portion of an ellipse specified by a D2dEllipse</summary>
 /// <param name="ellipse">Ellipse to draw</param>
 /// <param name="color">The color used to paint the arc's outline</param>
 /// <param name="startAngle">Starting angle in degrees measured clockwise from the x-axis 
 /// to the starting point of the arc</param>
 /// <param name="sweepAngle">Sweep angle in degrees measured clockwise from the startAngle 
 /// parameter to ending point of the arc</param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered 
 /// on the ellipse's outline.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the arc's outline or null to draw a solid line</param>
 public void DrawArc(D2dEllipse ellipse, Color color, float startAngle, float sweepAngle, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     m_solidColorBrush.Color = color;
     DrawArc(ellipse, m_solidColorBrush, startAngle, sweepAngle, strokeWidth, strokeStyle);
 }
コード例 #7
0
ファイル: D2dGraphics.cs プロジェクト: sbambach/ATF
        /// <summary>
        /// Draws an arc representing a portion of an ellipse specified by a D2dEllipse</summary>
        /// <param name="ellipse">Ellipse to draw</param>
        /// <param name="brush">The brush used to paint the arc's outline</param>
        /// <param name="startAngle">Starting angle in degrees measured clockwise from the x-axis 
        /// to the starting point of the arc</param>
        /// <param name="sweepAngle">Sweep angle in degrees measured clockwise from the startAngle 
        /// parameter to ending point of the arc</param>
        /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered 
        /// on the ellipse's outline.</param>
        /// <param name="strokeStyle">The style of stroke to apply to the arc's outline or null to draw a solid line</param>
        public void DrawArc(D2dEllipse ellipse, D2dBrush brush, float startAngle, float sweepAngle, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            // compute steps
            float step = Tessellation / m_scale.X;
            float angle1 = startAngle * ToRadian;
            float angle2 = (startAngle + sweepAngle) * ToRadian;
            if (angle1 > angle2)
            {
                float temp = angle1;
                angle1 = angle2;
                angle2 = temp;
            }

            float cx = ellipse.Center.X;
            float cy = ellipse.Center.Y;

            var v1 = new Vec2F();
            v1.X = ellipse.RadiusX * (float)Math.Cos(angle1);
            v1.Y = ellipse.RadiusY * (float)Math.Sin(angle1);

            var v2 = new Vec2F();
            v2.X = ellipse.RadiusX * (float)Math.Cos(angle2);
            v2.Y = ellipse.RadiusY * (float)Math.Sin(angle2);

            float arcLen = (v2 - v1).Length; // approx arc len.
            float numSegs = arcLen / step;
            float dtheta = (angle2 - angle1) / numSegs;

            m_tempPoints.Clear();
            for (float theta = angle1; theta < angle2; theta += dtheta)
            {
                var pt = new PointF();
                pt.X = cx + ellipse.RadiusX * (float)Math.Cos(theta);
                pt.Y = cy + ellipse.RadiusY * (float)Math.Sin(theta);
                m_tempPoints.Add(pt);
            }
            DrawLines(m_tempPoints, brush, strokeWidth, strokeStyle);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: Joxx0r/ATF
        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();
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: Joxx0r/ATF
        private void Render()
        {            
            SizeF csize = m_d2dGraphics.Size;
            int w = (int)csize.Width;
            int h = (int)csize.Height;
            Size clsize = this.ClientSize;
            
            PointF pt = this.PointToClient(Control.MousePosition);


            frmclk.Start(); // start frame timer.

            m_d2dGraphics.BeginDraw();
            m_d2dGraphics.Transform = Matrix3x2F.Identity;
            m_d2dGraphics.Clear(m_bkgColor);
                       

            switch (m_sampleDrawing)
            {
                case SampleDrawings.DrawFewStates:
                    {
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        m_d2dGraphics.TextAntialiasMode = D2dTextAntialiasMode.Default;

                        float scale = 2.0f;
                        Matrix3x2F xform = Matrix3x2F.CreateScale(scale, scale);
                        m_d2dGraphics.Transform = xform;
                        m_brush1.Color = Color.Black;
                        m_brush2.Color = Color.White;
                        foreach (State state in m_states)
                        {
                            DrawState(state, scale);
                        }
                        m_d2dGraphics.Transform = Matrix3x2F.Identity;
                    }
                    break;
                case SampleDrawings.FillSolidRects:
                    {
                        
                        // turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        for (int i = 0; i < m_rects.Count; i++)
                            m_d2dGraphics.FillRectangle(m_rects[i], m_colors[i]);
                    }
                    break;

                case SampleDrawings.FillBmpRects:
                    {
                         //turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        for (int i = 1; i < 5; i++)
                        {
                            RectangleF rect = new RectangleF(20 + i * 50, 10, 50, 50);
                            m_bmpBrush.Location = rect.Location;
                            m_d2dGraphics.FillRectangle(rect, m_bmpBrush);
                        }

                    }
                    break;
                case SampleDrawings.FillGradientRects1:
                    {                        
                        // below is a way to use one linear gradient brush 
                        // to fill rectangle with the given color.
                        // this method works best for  non-overlapping rectangles.
                        //
                        // The first loop renders all the rectangles using FillRectangle(RectangleF rect, Color color)
                        // The second loop fill rectangles using linear gradient brush.
                        // The reason for using two loops is to minimize render state changes.
                        // (changing render state is expensive for hardware d2d graphics).
                        
                       
                        // turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;

                        // two loops methods does not work for this example.
                        // because rectangles are overlapping.
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            RectangleF rect = m_rects[i];                            

                            m_d2dGraphics.FillRectangle(rect, m_colors[i]);

                            m_darkenBrush.StartPoint = rect.Location;
                            m_darkenBrush.EndPoint = new PointF(rect.X, rect.Bottom);
                            m_d2dGraphics.FillRectangle(rect, m_darkenBrush);
                        }
                    }
                    break;
                case SampleDrawings.FillGradientRects2:
                    {
                        // turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            RectangleF rect = m_rects[i];
                            Color start = m_colors[i];
                            Color end = Color.FromArgb((int)(start.R / 1.90f), (int)(start.G / 1.90f), (int)(start.B / 1.90f));
                            PointF pt1 = rect.Location;
                            PointF pt2 = new PointF(rect.X, rect.Bottom);

                            // note for each unique color a new linear gradient brush 
                            // will be created and cached for reuse.
                            m_d2dGraphics.FillRectangle(rect, pt1, pt2, start, end);
                        }                        
                    }
                    break;

                case SampleDrawings.FillGradientRects3:
                    {
                        // turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            RectangleF rect = m_rects[i];
                            m_titlebrush.StartPoint = rect.Location;
                            m_titlebrush.EndPoint = new PointF(rect.Right, rect.Bottom);
                            m_d2dGraphics.FillRectangle(rect, m_titlebrush);
                        }
                    }
                    break;

                case SampleDrawings.DrawTriangle:
                    {                     
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        PointF[] polys
                            = {
                                  new PointF(200,200),
                                  new PointF(250,300),
                                  new PointF(150,300),
                              };
                        m_d2dGraphics.FillPolygon(polys, Color.DarkBlue);
                        m_d2dGraphics.DrawPolygon(polys, Color.Yellow, 3.0f);                          
                    }
                    break;
                case SampleDrawings.DrawRects:
                    {
                        // turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.DrawRectangle(m_rects[i], m_brush1, 2.0f);
                        }
                    }
                    break;
                case SampleDrawings.DrawRectsWithBitmapMasks:
                    {
                       //  turn off AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.FillOpacityMask(m_bmp, m_brush1, m_rects[i]);
                        }
                    }
                    break;
                case SampleDrawings.FillSolidRoundedRects:
                    {
                        // turn On AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        // fill rounded rectangles                        
                        for (int i = 0; i < m_roundedRects.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.FillRoundedRectangle(m_roundedRects[i], m_brush1);
                        }
                    }
                    break;
                case SampleDrawings.DrawRoundedRects:
                    {
                        // turn On AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        // fill rounded rectangles
                        for (int i = 0; i < m_roundedRects.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.DrawRoundedRectangle(m_roundedRects[i], m_brush1, 1.0f);
                        }
                    }
                    break;
                case SampleDrawings.FillSolidEllipse:
                    {
                        // turn On AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        for (int i = 0; i < m_ellipses.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.FillEllipse(m_ellipses[i], m_brush1);
                        }
                    }
                    break;
                case SampleDrawings.DrawEllipse:
                    {
                        // turn On AA
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        for (int i = 0; i < m_ellipses.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.DrawEllipse(m_ellipses[i], m_brush1, 2.0f);
                        }
                    }
                    break;
                case SampleDrawings.DrawOrbs:
                    {                                                
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        for (int i = 0; i < m_ellipses.Count; i++)
                        {
                            D2dRadialGradientBrush
                            radialBrush = m_radialBrushes[i];
                            D2dEllipse ellipse = m_ellipses[i];
                            PointF center = ellipse.Center;
                            
                            radialBrush.Center = center;                            
                            radialBrush.RadiusX = ellipse.RadiusX;
                            radialBrush.RadiusY = ellipse.RadiusY;

                            D2dLinearGradientBrush linearBrush = m_linearBrushes[i];
                            linearBrush.StartPoint = new PointF(0, center.Y - ellipse.RadiusY);
                            linearBrush.EndPoint = new PointF(0, center.Y + ellipse.RadiusY);
                                                                               
                            m_d2dGraphics.FillEllipse(m_ellipses[i], radialBrush);
                            m_d2dGraphics.FillEllipse(ellipse, linearBrush);
                           
                            D2dEllipse glassy = new D2dEllipse();
                            glassy.Center =
                                new PointF(center.X, center.Y - ellipse.RadiusY * 0.5f);
                            glassy.RadiusX = ellipse.RadiusX * 0.75f;
                            glassy.RadiusY = ellipse.RadiusY * 0.5f;


                            D2dLinearGradientBrush linearBrush2 = m_linearBrushes2[i];
                            linearBrush2.StartPoint
                                = new PointF(0, glassy.Center.Y - glassy.RadiusY);
                            linearBrush2.EndPoint
                                = new PointF(0, glassy.Center.Y + glassy.RadiusY);

                            m_d2dGraphics.FillEllipse(glassy, linearBrush2);
                        }

                    }
                    break;
                case SampleDrawings.DrawRandomLines1:
                    {
                        // turn AA off for thin lines.
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        //m_d2dGraphics.AntialiasMode = D2dAntialiasMode.Aliased;
                        float width = scr;
                        for (int i = 0; i < m_lines.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            Line line = m_lines[i];
                            m_d2dGraphics.DrawLine(line.P1, line.P2, m_brush1, width);
                        }                        
                    }
                    break;
                case SampleDrawings.DrawRandomLines2:
                    {
                        // OK turn AA ON for thick lines.
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        for (int i = 0; i < m_lines.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            Line line = m_lines[i];
                            m_d2dGraphics.DrawLine(line.P1, line.P2, m_brush1, 2.0f);
                        }

                    }
                    break;
                case SampleDrawings.UseClipRectangle:
                    {

                        m_brush1.Color = Color.Yellow;

                        m_d2dGraphics.DrawText
                            ("Use Clip Rectangle", m_generalTextFormat,
                            new RectangleF(10, 10, 200, 50), m_brush1);
                        // OK turn AA ON for thick lines.
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        RectangleF clipRect
                            = new RectangleF(120, 120, 400,400);

                        m_d2dGraphics.PushAxisAlignedClip(clipRect);

                        for (int i = 0; i < m_lines.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            Line line = m_lines[i];
                            m_d2dGraphics.DrawLine(line.P1, line.P2, m_brush1, 2.0f);
                        }

                        m_d2dGraphics.PopAxisAlignedClip();

                    }
                    break;
                case SampleDrawings.DrawConnectedLines:
                    {
                        // OK turn AA ON for thick lines.
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        m_brush1.Color = Color.White;
                        m_d2dGraphics.DrawLines(m_connectedLines, m_brush1, 2.0f);
                    }
                    break;
                case SampleDrawings.DrawBeziers:
                    {
                        // turn AA on.
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        float width = 2.0f;                        
                        int c = 0;
                        foreach (Bezier bz in m_beziers)
                        {
                            m_brush1.Color = m_colors[c++];
                            m_d2dGraphics.DrawBezier(
                                bz.P1, bz.P2, bz.P3, bz.P4, m_brush1, width);
                        }
                    }
                    break;
                case SampleDrawings.DrawCachedBitmap:
                    {

                        // render to offscreen buffer.
                        m_bitmapgraphics.BeginDraw();
                        m_bitmapgraphics.Clear(Color.Green);
                        m_bitmapgraphics.FillRectangle(new RectangleF(10, 10, 80, 80), Color.Yellow);
                        m_bitmapgraphics.EndDraw();

                        using (D2dBitmap bmp = m_bitmapgraphics.GetBitmap())
                        {
                            m_d2dGraphics.DrawBitmap(bmp, new PointF(10, 10), 1.0f);
                        }
                    }
                    break;
                case SampleDrawings.DrawText:
                    {
                        m_d2dGraphics.TextAntialiasMode = D2dTextAntialiasMode.Default;
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;

                        for (int i = 0; i < m_texts.Count; i++)
                        {                           
                            m_brush1.Color = m_colors[i];                            
                             m_d2dGraphics.DrawText(
                                  m_drawInfo,
                                  m_generalTextFormat,
                                  m_texts[i],
                                  m_brush1);
                        }
                    }

                    break;
                case SampleDrawings.DrawTextLayout:
                    {
                        m_d2dGraphics.TextAntialiasMode = D2dTextAntialiasMode.Default;
                        m_d2dGraphics.AntialiasMode = D2dAntialiasMode.PerPrimitive;
                        for (int i = 0; i < m_texts.Count; i++)
                        {                            
                            m_brush1.Color = m_colors[i];
                            m_d2dGraphics.DrawTextLayout(m_texts[i], m_textLayouts[i], m_brush1);                            
                        }
                    }
                    break;
                case SampleDrawings.DrawBitmaps:
                    {
                        Random rnd = new Random(7533);

                        for (int i = 0; i < 20; i++)
                        {
                            PointF bmpPt
                                = new PointF(rnd.Next(w), rnd.Next(h));
                            m_d2dGraphics.DrawBitmap(m_bmp, bmpPt, 1.0f - i / 20.0f);
                        }
                        m_d2dGraphics.DrawBitmap(m_emptyBmp, new PointF(5, 5), 1.0f);
                    }
                    break;
                case SampleDrawings.GdiInterOp:
                    {
                        m_d2dGraphics.BeginGdiSection();
                        m_d2dGraphics.Graphics.SmoothingMode
                            = System.Drawing.Drawing2D.SmoothingMode.None;
                        
                        Pen p = new Pen(Color.Gold);
                        for (int i = 10; i < 200; i++)
                        {
                            Rectangle rect
                                = new Rectangle(i, i, i, i);
                            p.Color = m_colors[i];
                            m_d2dGraphics.Graphics.DrawRectangle(p, rect);
                        }
                        p.Dispose();                                              
                        m_d2dGraphics.EndGdiSection();                        
                    }
                    break;
                case SampleDrawings.LastValue:
                    break;
                default:
                    break;
            }

         
            m_brush1.Color = Color.Blue;
            RectangleF msRect
                = new RectangleF(pt, new SizeF(4, 4));
            msRect.Offset(-2, -2);

            m_d2dGraphics.FillRectangle(msRect, m_brush1);

            m_d2dGraphics.EndDraw();
                        
            m_frameCount++;
            m_cumulativeTime += (float)frmclk.Elapsed;

            // compute frames-per-second and time-per-frame regularly
            if (m_frameCount > 30)
            {
                m_fps = m_frameCount / m_cumulativeTime;
                m_cumulativeTime = 0;
                m_frameCount = 0;

                UpdateInfo();
            }
        }
コード例 #10
0
ファイル: D2dGraphics.cs プロジェクト: vincenthamm/ATF
 /// <summary>
 /// Paints the interior of the specified ellipse</summary>
 /// <param name="ellipse">The position and radius, in pixels, of the ellipse to paint</param>
 /// <param name="brush">The brush used to paint the interior of the ellipse</param>
 public void FillEllipse(D2dEllipse ellipse, D2dBrush brush)
 {
     var tmpEllipse = new Ellipse();
     tmpEllipse.Point = new DrawingPointF(ellipse.Center.X, ellipse.Center.Y);
     tmpEllipse.RadiusX = ellipse.RadiusX;
     tmpEllipse.RadiusY = ellipse.RadiusY;
     m_renderTarget.FillEllipse(tmpEllipse, brush.NativeBrush);
 }
コード例 #11
0
ファイル: D2dGraphics.cs プロジェクト: vincenthamm/ATF
 /// <summary>
 /// Draws the outline of the specified ellipse using the specified stroke style</summary>
 /// <param name="ellipse">Position and radius of the ellipse to draw in pixels</param>
 /// <param name="brush">The brush used to paint the ellipse's outline</param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param>
 public void DrawEllipse(D2dEllipse ellipse, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     var tmpEllipse = new Ellipse();
     tmpEllipse.Point = new DrawingPointF(ellipse.Center.X, ellipse.Center.Y);
     tmpEllipse.RadiusX = ellipse.RadiusX;
     tmpEllipse.RadiusY = ellipse.RadiusY;
     m_renderTarget.DrawEllipse(tmpEllipse, brush.NativeBrush, strokeWidth,
         strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
 }