コード例 #1
0
ファイル: PenDemo.cs プロジェクト: misiek/foo
        private void Draw(Graphics graphics, GraphicsPlus g)
        {
            StringFormat sf = new StringFormat();
            sf.LineAlignment = sf.Alignment = System.Drawing.StringAlignment.Center;
            int deltaH = ClientRectangle.Height / 8;
            GpRectF rc = new GpRectF(0, 0, ClientRectangle.Width, deltaH);
            RectangleF rcf = new RectangleF(0, 0, ClientRectangle.Width, deltaH);

            using (SolidBrush brText = new SolidBrush(Color.Black))
            using (Font fnt = new Font("Tahoma", 9, System.Drawing.FontStyle.Bold))
            {
                penSolid.SetWidth(15);
                g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                graphics.DrawString("Solid with caps", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

                SmoothingMode mode = g.GetSmoothingMode();
                g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

                penSolid.SetColor(Color.Blue);
                g.DrawLine(penSolid, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                graphics.DrawString("Solid with caps and anitalising", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

                g.DrawLine(penHatch, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                graphics.DrawString("Hatched", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

                penSolidTrans.SetWidth(20);
                penSolidTrans.SetLineCap(LineCap.LineCapRound, LineCap.LineCapDiamondAnchor, DashCap.DashCapRound);
                graphics.DrawString("Solid with transparency", fnt, brText, rcf, sf);
                g.DrawLine(penSolidTrans, 15, rcf.Top + 10, rc.Width - 30, rcf.Top + 10);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

                g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
                brText.Color = Color.White;
                g.DrawLine(penSolidCustomCap, 15, rcf.Top + 15, rc.Width - 50, rcf.Top + 15);
                graphics.DrawString("Custom cap", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);
                g.SetSmoothingMode(mode);

                brText.Color = Color.Gray;
                g.DrawLine(penDash, 5, rcf.Top + 10, rc.Width - 10, rcf.Top + 10);
                graphics.DrawString("Dash (round)", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

                brText.Color = Color.White;
                g.DrawLine(penGradient, 15, rcf.Top + 20, rc.Width - 30, rcf.Top + 20);
                graphics.DrawString("Gradient brush-based", fnt, brText, rcf, sf);
                rcf.Y += deltaH; rc.Offset(0, deltaH);

            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: misiek/foo
 private void AddStroke(int x, int y)
 {
     allPoints.Add(new GpPointF(x, y));
     if ( allPoints.Count == 1 )
         return;
     path.AddLine(allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]);
     using (Graphics graphics = CreateGraphics())
     {
         IntPtr hdc = graphics.GetHdc();
         using (GraphicsPlus g = new GraphicsPlus(hdc))
         {
             SmoothingMode mode = g.GetSmoothingMode();
             g.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
             g.DrawLine(penWrite, allPoints[allPoints.Count - 2], allPoints[allPoints.Count - 1]);
             g.SetSmoothingMode(mode);
         }
         graphics.ReleaseHdc(hdc);
     }
 }
コード例 #3
0
ファイル: MapPanel.cs プロジェクト: misiek/foo
        private void drawRotatedArrow(GraphicsPlus graphics)
        {
            Debug.WriteLine("drawRotatedArrow: " + this.rotationAngle, this.ToString());

            Point center = new Point(this.Width / 2, this.Height / 2);

            int arWidthHalf = ARROW_WIDTH / 2;
            //int arHeightHalf = ARROW_HEIGHT / 2;

            Point[] arrowPoints = {
                new Point(center.X, center.Y - arWidthHalf),
                new Point(center.X - 2*arWidthHalf/3, center.Y + arWidthHalf),
                new Point(center.X + 2*arWidthHalf/3, center.Y + arWidthHalf),
                new Point(center.X, center.Y + arWidthHalf/2)
            };
            Debug.WriteLine("drawRotatedArrow: points "
                + PointUtil.pointsStr(arrowPoints), this.ToString());

            PointMath.RotatePoints(arrowPoints, center, this.rotationAngle);
            Debug.WriteLine("drawRotatedArrow: points "
                + PointUtil.pointsStr(arrowPoints), this.ToString());

            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            PenPlus pen = new PenPlus(ARROW_COLOR, 3);
            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);

            graphics.DrawLine(pen, new GpPoint(arrowPoints[0].X, arrowPoints[0].Y),
                                   new GpPoint(arrowPoints[1].X, arrowPoints[1].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[1].X, arrowPoints[1].Y),
                                   new GpPoint(arrowPoints[3].X, arrowPoints[3].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[3].X, arrowPoints[3].Y),
                                   new GpPoint(arrowPoints[2].X, arrowPoints[2].Y));
            graphics.DrawLine(pen, new GpPoint(arrowPoints[2].X, arrowPoints[2].Y),
                                   new GpPoint(arrowPoints[0].X, arrowPoints[0].Y));
            pen.Dispose();
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: misiek/foo
        private void TestGdiPlus(GraphicsPlus graphics)
        {
            graphics.DrawImage(bmp, 0, 0, ClientRectangle.Width, ClientRectangle.Height);

            PenPlus pen;

            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            pen= new PenPlus(Color.Black, 15);
            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);

            pen.SetWidth(3);

            pen.SetColor(Color.FromArgb(0x7f7f7f7f));
            pen.SetWidth(40);
            graphics.DrawLine(pen, 20, 20, ClientRectangle.Right - 20, ClientRectangle.Bottom - 20);
            graphics.DrawLine(pen, ClientRectangle.Right - 20, 20, 20, ClientRectangle.Bottom - 20);

            SmoothingMode mode = graphics.GetSmoothingMode();
            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);
            foreach(GraphicsPath p in allPaths)
                graphics.DrawPath(penWrite, p);
            graphics.SetSmoothingMode(mode);
            pen.Dispose();
        }
コード例 #5
0
ファイル: MapPanel.cs プロジェクト: misiek/foo
        private void drawDirectionLinePlus(GraphicsPlus graphics)
        {
            graphics.SetSmoothingMode(SmoothingMode.SmoothingModeAntiAlias);

            PenPlus pen = new PenPlus(TARGET_LINE_COLOR, 3);
            pen.SetEndCap(LineCap.LineCapRound);
            pen.SetStartCap(LineCap.LineCapRound);

            graphics.DrawLine(pen, this.Width / 2, this.Height / 2, targetPoint.X, targetPoint.Y);
            pen.Dispose();
        }