void HatchSolidDiamond(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor);
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchWidth / 2.0f;

            // We will paint two triangles from corners meeting in the middle
            // make sure to offset by half pixels so that the point is actually a point.
            context.MoveTo(-HALF_PIXEL_X, HALF_PIXEL_Y);
            context.AddLineToPoint(2 + HALF_PIXEL_X, halfMe - HALF_PIXEL_Y);
            context.AddLineToPoint(-HALF_PIXEL_X, hatchHeight - (1.0f + HALF_PIXEL_Y));
            context.ClosePath();
            context.FillPath();

            // now we do the right one
            context.MoveTo(hatchWidth, HALF_PIXEL_Y);
            context.AddLineToPoint(halfMe + HALF_PIXEL_X, halfMe - HALF_PIXEL_Y);
            context.AddLineToPoint(hatchWidth, hatchHeight - (1.0f + HALF_PIXEL_Y));
            context.ClosePath();
            context.FillPath();
        }
        void HatchOutlinedDiamond(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor);
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            // this is really just two diagonal lines from each corner too
            // their opposite corners.
            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchWidth, hatchHeight);
            context.StrokePath();
            context.MoveTo(1, hatchHeight);
            context.AddLineToPoint(hatchWidth, 1);
            context.StrokePath();
        }
Beispiel #3
0
        private void DrawBox(CGContext context, CGRect trect, float fRadius)
        {
            float fWidth  = (float)trect.Width;
            float fHeight = (float)trect.Height;

            if (fRadius > fWidth / 2.0f)
            {
                fRadius = fWidth / 2.0f;
            }
            if (fRadius > fHeight / 2.0f)
            {
                fRadius = fHeight / 2.0f;
            }

            float fMinX = (float)trect.GetMinX();
            float fMidX = (float)trect.GetMidX();
            float fMaxX = (float)trect.GetMaxX();
            float fMinY = (float)trect.GetMinY();
            float fMidY = (float)trect.GetMidY();
            float fMaxY = (float)trect.GetMaxY();

            context.MoveTo(fMinX, fMidY);
            context.AddArcToPoint(fMinX, fMinY, fMidX / 2, fMinY, fRadius);
            context.AddLineToPoint(fMidX - 5, fMinY);
            context.AddLineToPoint(fMidX, fMinY - 5);
            context.AddLineToPoint(fMidX + 5, fMinY);
            context.AddArcToPoint(fMaxX, fMinY, fMaxX, fMidY, fRadius);
            context.AddArcToPoint(fMaxX, fMaxY, fMidX, fMaxY, fRadius);
            context.AddArcToPoint(fMinX, fMaxY, fMinX, fMidY, fRadius);
        }
        void HatchDiagonalBrick(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            hatchHeight -= 1;
            hatchWidth  -= 1;

            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchWidth, hatchHeight);
            context.StrokePath();

            context.MoveTo(0, hatchHeight);
            context.AddLineToPoint(hatchWidth / 2.0f, hatchHeight / 2.0f);
            context.StrokePath();
        }
Beispiel #5
0
        // rect changes depending on if the whole view is being redrawn, or just a section
        public override void Draw(CGRect rect)
        {
            Console.WriteLine("Draw() Called");
            base.Draw(rect);

            using (CGContext context = UIGraphics.GetCurrentContext()) {
                // fill the background with white
                // set fill color
                UIColor.White.SetFill();
                //context.SetRGBFillColor (1, 1, 1, 1f);
                // paint
                context.FillRect(rect);

                // draw a rectangle using stroke rect
                UIColor.Blue.SetStroke();
                context.StrokeRect(new CGRect(10, 10, 200, 100));

                // draw a rectangle using a path
                context.BeginPath();
                context.MoveTo(220, 10);
                context.AddLineToPoint(420, 10);
                context.AddLineToPoint(420, 110);
                context.AddLineToPoint(220, 110);
                context.ClosePath();
                UIColor.DarkGray.SetFill();
                context.DrawPath(CGPathDrawingMode.FillStroke);

                // draw a rectangle using a path
                CGPath rectPath = new CGPath();
                rectPath.AddRect(new CGRect(new CGPoint(430, 10), new CGSize(200, 100)));
                context.AddPath(rectPath);
                context.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Beispiel #6
0
        public void DrawLine(float sx, float sy, float ex, float ey, float w)
        {
#if not
                        #if DEBUG
            if (float.IsNaN(sx) || float.IsNaN(sy) || float.IsNaN(ex) || float.IsNaN(ey) || float.IsNaN(w))
            {
                System.Diagnostics.Debug.WriteLine("NaN in CoreGraphicsGraphics.DrawLine");
            }
                        #endif
#endif
            if (_linesBegun)
            {
                _lineWidth = w;
                if (_numLinePoints < _linePointsCount)
                {
                    if (_numLinePoints == 0)
                    {
                        _linePoints[_numLinePoints].X = sx;
                        _linePoints[_numLinePoints].Y = sy;
                        _numLinePoints++;
                    }
                    _linePoints[_numLinePoints].X = ex;
                    _linePoints[_numLinePoints].Y = ey;
                    _numLinePoints++;
                }
            }
            else
            {
                _c.MoveTo(sx, sy);
                _c.AddLineToPoint(ex, ey);
                _c.SetLineWidth(w);
                _c.StrokePath();
            }
        }
        void HatchDiagonalCross(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, true);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            //float halfMe = hatchHeight / 2.0f;

            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchWidth, hatchHeight);
            context.StrokePath();

            context.MoveTo(hatchWidth, 0);
            context.AddLineToPoint(0, hatchHeight);
            context.StrokePath();
        }
        void HatchDashedHorizontal(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchHeight / 2.0f - 1;

            hatchWidth  -= 1;
            hatchHeight -= 1;

            context.MoveTo(halfMe + 1, halfMe);
            context.AddLineToPoint(hatchWidth, halfMe);
            context.StrokePath();

            context.MoveTo(0, hatchHeight);
            context.AddLineToPoint(halfMe, hatchHeight);
            context.StrokePath();
        }
        private void HatchGrid(CGContext context)
        {
            var hatchSize = getHatchWidth(hatchStyle);
            var lineWidth = getLineWidth(hatchStyle);

            initializeContext(context, hatchSize, false);

            /* draw background */
            drawBackground(context, backColor, hatchSize, hatchSize);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            hatchSize -= HALF_PIXEL_X;
            float yoffset = 0;

            if (hatchStyle == HatchStyle.DottedGrid)
            {
                yoffset = 1;
                nfloat[] dash = new nfloat[] { 1, 1 };
                context.SetLineDash(2, dash);
            }

            /* draw a horizontal line */
            context.MoveTo(0, yoffset);
            context.AddLineToPoint(0, hatchSize);
            context.StrokePath();
            /* draw a vertical line */
            context.MoveTo(0, hatchSize);
            context.AddLineToPoint(hatchSize, hatchSize);

            context.StrokePath();
        }
Beispiel #10
0
        public void DrawLayer(CALayer layer, CGContext context)
        {
            CATransaction.DisableActions    = true;
            CATransaction.AnimationDuration = 0;
            //nfloat width = layer.Frame.Width;
            //nfloat spread = UserSettings.GetSettings().BounceWidthPad;
            //nfloat division = UserSettings.GetSettings().BounceDivision;

            nfloat pad   = (nfloat)BounceHelper.LanePadding;    //(layer.Frame.Width - layer.Frame.Height) / 2;
            nfloat horiz = (nfloat)BounceHelper.LaneAreaHeight; //layer.Frame.Height * division;

            context.SetLineWidth(2);
            context.SetStrokeColor(NSColor.White.CGColor);
            // draw the left lane edge
            context.MoveTo(0, 0);
            context.AddLineToPoint(pad, horiz);

            // draw each lane divider
            nfloat horizSpacing = (nfloat)BounceHelper.TopLaneSpacing;    //(width - 2 * pad) / Metronome.Instance.Layers.Count;
            nfloat baseSpacing  = (nfloat)BounceHelper.BottomLaneSpacing; //width / Metronome.Instance.Layers.Count;

            for (int i = 1; i <= Metronome.Instance.Layers.Count; i++)
            {
                context.MoveTo(baseSpacing * i, 0);
                context.AddLineToPoint(pad + horizSpacing * i, horiz);
            }

            context.StrokePath();
        }
    public override void DrawInContext(CGContext context)
    {
        context.SetRGBStrokeColor(1, 1, 1, 1f);

        // Draw lines with a stroke width from 1-10
        for (int i = 1; i <= 10; ++i)
        {
            context.SetLineWidth(i);
            context.MoveTo(10, (float)i * 20.5f);
            context.AddLineToPoint(310, (float)i * 20.5f);
            context.StrokePath();
        }

        // Demonstration that stroke is even on both sides of the line
        context.SetLineWidth(15);
        context.MoveTo(10, 245.5f);
        context.AddLineToPoint(310, 245.5f);
        context.StrokePath();

        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.SetLineWidth(3);
        context.MoveTo(10, 245.5f);
        context.AddLineToPoint(310, 245.5f);
        context.StrokePath();
    }
Beispiel #12
0
        public override void Draw(CoreGraphics.CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                if (points != null)
                {
                    CGPath currentPath = new CGPath();
                    currentPath.AddLines(points);
                    g.AddPath(currentPath);
                    g.SetLineWidth(2);
                    if (invertColors)
                    {
                        g.SetStrokeColor(UIColor.FromRGB(255, 255, 255).CGColor);
                    }
                    else
                    {
                        g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor);
                    }

                    g.AddLineToPoint(rect.Right, rect.Bottom);
                    g.AddLineToPoint(rect.Left, rect.Bottom);
                    g.ClosePath();

                    if (displayPoints)
                    {
                        g.SetAlpha(.7f);
                        g.SetFillColor(UIColor.FromRGB(100, 100, 100).CGColor);
                    }
                    else if (invertColors)
                    {
                        g.SetFillColor(UIColor.FromRGB(255, 255, 255).CGColor);
                    }
                    else
                    {
                        g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor);
                    }

                    g.DrawPath(CGPathDrawingMode.FillStroke);
                    g.SetAlpha(1f);

                    if (displayPoints)
                    {
                        nfloat smallRadius = Frame.Width * .01f;
                        nfloat bigRadius   = Frame.Width * .03f;
                        foreach (CGPoint point in points)
                        {
                            g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor);
                            g.SetAlpha(.3f);
                            g.AddArc(point.X, point.Y, bigRadius, 0.0f, (float)Math.PI * 2.0f, true);
                            g.FillPath();
                            g.SetAlpha(1f);
                            g.AddArc(point.X, point.Y, smallRadius, 0.0f, (float)Math.PI * 2.0f, true);
                            g.FillPath();
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public void DrawGraph(CGContext g, nfloat x0, nfloat x1, nfloat y0, nfloat y1)
        {
            nfloat frameWidth  = x1 - x0;
            nfloat frameHeight = y1 - y0;

            nfloat padding = frameWidth / 8;

            nfloat insideWidth = frameWidth - padding * 2;

            //nfloat insideHeight = insideWidth;

            g.SetLineWidth(_lineWidth);
            g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor);
            g.MoveTo(x0 + padding, y0 + padding);                  // + (frameHeight) / 2);
            g.AddLineToPoint(x0 + (frameWidth) / 2, y1 - padding); // y1 - padding);
            g.AddLineToPoint(x1 - padding, y0 + padding);          // + (frameHeight) / 2);
            g.StrokePath();


            /*
             * g.SetLineWidth(_lineWidth);
             *
             * g.SetStrokeColor(UIColor.FromRGB(155, 155, 155).CGColor);
             *
             * g.MoveTo(x0, y0);
             * g.AddLineToPoint(x0 + (x1 - x0), y0);
             * g.StrokePath();
             *
             * g.SetStrokeColor(_barColor.CGColor);
             * g.MoveTo(x0, y0);
             * g.AddLineToPoint(x0 + _progressPercent * (x1 - x0), y0);
             * g.StrokePath();
             */
        }
Beispiel #14
0
        //绘图
        private void DrawWave(CGRect rect)
        {
            //获取图片控件大小
            int width = (int)rect.Width;
            int height = (int)rect.Height;

            System.Diagnostics.Debug.Print($"{DateTime.Now}, DrawWave: width={width}, height={height}");

            MaxHeight = height;

            CGContext context = UIGraphics.GetCurrentContext();

            if (BioBuf.Length > 0)
            {
                //创建画笔
                context.SetLineWidth(1);//画笔线宽
                context.SetStrokeColor(UIColor.Blue.CGColor);//画笔颜色

                //画曲线
                int x = 0;
                int y1 = 0;
                int y2 = 0;
                context.MoveTo(x, y1);//起点

                for (int i = 0; i < BioBuf.Length; i++)
                {
                    x = i;
                    y1 = y2;
                    y2 = WaveHeight(BioBuf[i]);

                    context.AddLineToPoint(x + 1, y2);//终点
                }

                context.StrokePath();//画线

                //画基线
                if (BioBaselien > 0)
                {
                    //创建画笔
                    context.SetStrokeColor(UIColor.Red.CGColor);//画笔颜色

                    y2 = WaveHeight(BioBaselien);
                    context.MoveTo(0, y2);//起点
                    context.AddLineToPoint(BioBuf.Length, y2);//终点

                    context.StrokePath();//画线}
                }
            }

            //创建画笔
            context.SetStrokeColor(UIColor.Gray.CGColor);//画笔颜色

            //画边界
            context.AddRect(new CGRect(0, 0, width, height));
            context.StrokePath();//画线

            System.Diagnostics.Debug.Print($"{DateTime.Now}, DrawWave");
        }
 static void icon_arrow_down(CGContext c)
 {
     c.MoveTo(0f, 374f);
     c.AddQuadCurveToPoint(0f, 393f, 14f, 407f);
     c.AddLineToPoint(63f, 456f);
     c.AddQuadCurveToPoint(77f, 470f, 96f, 470f);
     c.AddQuadCurveToPoint(115f, 470f, 129f, 456f);
     c.AddLineToPoint(294f, 291f);
     c.AddLineToPoint(294f, 703f);
     c.AddQuadCurveToPoint(294f, 722f, 307.5f, 735.5f);
     c.AddQuadCurveToPoint(321f, 749f, 340f, 749f);
     c.AddLineToPoint(410f, 749f);
     c.AddQuadCurveToPoint(430f, 749f, 443f, 735.5f);
     c.AddQuadCurveToPoint(456f, 722f, 456f, 703f);
     c.AddLineToPoint(456f, 291f);
     c.AddLineToPoint(622f, 456f);
     c.AddQuadCurveToPoint(636f, 470f, 654.5f, 470f);
     c.AddQuadCurveToPoint(673f, 470f, 687f, 456f);
     c.AddLineToPoint(737f, 407f);
     c.AddQuadCurveToPoint(751f, 393f, 751f, 374f);
     c.AddQuadCurveToPoint(751f, 355f, 737f, 341f);
     c.AddLineToPoint(408f, 13f);
     c.AddQuadCurveToPoint(394f, -1f, 375f, -1f);
     c.AddQuadCurveToPoint(356f, -1f, 342f, 13f);
     c.AddLineToPoint(14f, 341f);
     c.AddQuadCurveToPoint(0f, 355f, 0f, 374f);
     c.ClosePath();
     c.MoveTo(0f, 374f);
     c.FillPath();
     c.StrokePath();
 }
 static void icon_arrow_up(CGContext c)
 {
     c.MoveTo(-0.5f, 375f);
     c.AddQuadCurveToPoint(-1f, 394f, 13f, 408f);
     c.AddLineToPoint(342f, 736f);
     c.AddQuadCurveToPoint(356f, 750f, 375f, 750f);
     c.AddQuadCurveToPoint(394f, 750f, 408f, 736f);
     c.AddLineToPoint(736f, 408f);
     c.AddQuadCurveToPoint(750f, 394f, 750f, 375f);
     c.AddQuadCurveToPoint(750f, 356f, 736f, 342f);
     c.AddLineToPoint(687f, 293f);
     c.AddQuadCurveToPoint(673f, 279f, 654.5f, 279f);
     c.AddQuadCurveToPoint(636f, 279f, 622f, 293f);
     c.AddLineToPoint(456f, 458f);
     c.AddLineToPoint(456f, 46f);
     c.AddQuadCurveToPoint(456f, 27f, 442.5f, 13.5f);
     c.AddQuadCurveToPoint(429f, 0f, 410f, 0f);
     c.AddLineToPoint(340f, 0f);
     c.AddQuadCurveToPoint(320f, 0f, 307f, 13.5f);
     c.AddQuadCurveToPoint(294f, 27f, 294f, 46f);
     c.AddLineToPoint(294f, 458f);
     c.AddLineToPoint(129f, 293f);
     c.AddQuadCurveToPoint(115f, 279f, 96f, 279f);
     c.AddQuadCurveToPoint(77f, 279f, 63f, 293f);
     c.AddLineToPoint(14f, 342f);
     c.AddQuadCurveToPoint(0f, 356f, -0.5f, 375f);
     c.ClosePath();
     c.MoveTo(-0.5f, 375f);
     c.FillPath();
     c.StrokePath();
 }
Beispiel #17
0
        /// <summary> 连线绘制图案(以设定颜色绘制)  将选中的圆形以color颜色链接起来
        /// </summary>
        /// <param name="rect">图形上下文</param>
        /// <param name="color">连线颜色</param>
        public void ConnectCirclesInRect(CGRect rect, UIColor color)
        {
            //获取上下文
            CGContext ctx = UIGraphics.GetCurrentContext();

            // 添加路径
            ctx.AddRect(rect);
            //是否剪裁
            ClipSubviewsWhenConnectInContext(ctx, Clip);
            //剪裁上下文
            ctx.EOClip();
            // 遍历数组中的circle
            for (int index = 0; index < CircleSet.Count; index++)
            {
                // 取出选中按钮
                PCCircle circle = CircleSet[index];
                // 起点按钮
                if (index == 0)
                {
                    ctx.MoveTo(circle.Center.X, circle.Center.Y);
                }
                else
                {
                    // 全部是连线
                    ctx.AddLineToPoint(circle.Center.X, circle.Center.Y);
                }
            }

            // 连接最后一个按钮到手指当前触摸得点
            if (!CurrentPoint.Equals(new CGPoint(0, 0)))
            {
                foreach (var item in Subviews)
                {
                    if (GetCircleState() == CircleState.CircleStateError || GetCircleState() == CircleState.CircleStateLastOneError)
                    {
                        // 如果是错误的状态下不连接到当前点
                    }
                    else
                    {
                        ctx.AddLineToPoint(CurrentPoint.X, CurrentPoint.Y);
                    }
                }
            }

            //线条转角样式
            ctx.SetLineCap(CGLineCap.Round);
            ctx.SetLineJoin(CGLineJoin.Round);
            // 设置绘图的属性
            ctx.SetLineWidth(PCCircleViewConst.CircleConnectLineWidth);
            // 线条颜色
            color.SetColor();
            //渲染路径
            ctx.StrokePath();
        }
Beispiel #18
0
        public void FillPolygon(Polygon poly)
        {
            var count = poly.Points.Count;

            _c.MoveTo((float)poly.Points[0].X, (float)poly.Points[0].Y);
            for (var i = 1; i < count; i++)
            {
                var p = poly.Points[i];
                _c.AddLineToPoint((float)p.X, (float)p.Y);
            }
            _c.FillPath();
        }
        private void HatchUpwardDiagonal(CGContext context)
        {
            var hatchSize = getHatchWidth(hatchStyle);
            var lineWidth = getLineWidth(hatchStyle);


            if (hatchStyle != HatchStyle.ForwardDiagonal &&
                hatchStyle != HatchStyle.BackwardDiagonal)
            {
                initializeContext(context, hatchSize, false);
            }
            else
            {
                initializeContext(context, hatchSize, true);
            }


            /* draw background */
            drawBackground(context, backColor, hatchSize, hatchSize);


            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetFillColor(foreColor);

            context.SetLineWidth(1);
            context.SetLineCap(CGLineCap.Square);

            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchSize, hatchSize);
            /* draw a diagonal line for as many times as linewidth*/
            for (int l = 0; l < lineWidth; l++)
            {
                /* draw a diagonal line */
                context.MoveTo(l, 0);
                context.AddLineToPoint(hatchSize, hatchSize - l);

                context.StrokePath();
            }

            /**
             * because we are within a rectangular pattern we have to complete the tip of the preceeding line
             * pattern
             */
            for (int k = 1; k < lineWidth; k++)
            {
                /* draw a diagonal line */
                context.MoveTo(0, hatchSize - k);
                context.AddLineToPoint(k - 1, hatchSize - 1);

                context.StrokePath();
            }
        }
        private void DrawCurrentTouch(CGContext ctx)
        {
            if (mCurrTouch == PointF.Empty)
            {
                return;
            }

            var parentDIV       = (DrawingImageView)Superview;
            var grandParentDISV = (DrawingImageScrollView)parentDIV.Superview;
            var zoomScale       = grandParentDISV.ZoomScale;

            // circle
            try
            {
                ctx.SaveState();
                ctx.BeginPath();

                ctx.SetStrokeColorWithColor(LineColor);
                ctx.SetLineWidth(9f / zoomScale);

                var rad = CurrentTouchRadius / zoomScale;

                ctx.AddArc(mCurrTouch.X, mCurrTouch.Y, rad, 0.0f, 2.0f * (float)Math.PI, true);
            }
            finally
            {
                ctx.StrokePath();
                ctx.RestoreState();
            }

            // crosshairs
            try
            {
                ctx.SaveState();
                ctx.BeginPath();

                ctx.SetStrokeColorWithColor(LineColor);
                ctx.SetLineWidth(1f / zoomScale);

                // horizontal line
                ctx.MoveTo(0f, mCurrTouch.Y);
                ctx.AddLineToPoint(Frame.Right, mCurrTouch.Y);

                // vertical line
                ctx.MoveTo(mCurrTouch.X, 0f);
                ctx.AddLineToPoint(mCurrTouch.X, Frame.Bottom);
            }
            finally
            {
                ctx.StrokePath();
                ctx.RestoreState();
            }
        }
Beispiel #21
0
        public void FillPolygon(Polygon poly)
        {
            var count = poly.Points.Count;

            _c.MoveTo(poly.Points[0].X, poly.Points[0].Y);
            for (var i = 1; i < count; i++)
            {
                var p = poly.Points[i];
                _c.AddLineToPoint(p.X, p.Y);
            }
            _c.ClosePath();
            FillPath();
        }
        public void FillPolygon(Polygon poly)
        {
            var count = poly.Points.Count;

            _c.SetLineJoin(CGLineJoin.Round);
            _c.MoveTo(poly.Points[0].X, poly.Points[0].Y);
            for (var i = 1; i < count; i++)
            {
                var p = poly.Points[i];
                _c.AddLineToPoint(p.X, p.Y);
            }
            _c.FillPath();
        }
Beispiel #23
0
        public override void Draw(CGRect rect)
        {
            CGContext con = UIGraphics.GetCurrentContext();

            nfloat length = rect.Width * 0.1f;

            con.SetLineWidth(3);
            con.SetStrokeColor(UIColor.Green.CGColor);

            con.MoveTo(0, length);
            con.AddLineToPoint(0, 0);
            con.AddLineToPoint(length, 0);
            con.StrokePath();

            con.MoveTo(rect.Width - length, 0);
            con.AddLineToPoint(rect.Width, 0);
            con.AddLineToPoint(rect.Width, length);
            con.StrokePath();

            con.MoveTo(rect.Width, rect.Height - length);
            con.AddLineToPoint(rect.Width, rect.Height);
            con.AddLineToPoint(rect.Width - length, rect.Height);
            con.StrokePath();

            con.MoveTo(length, rect.Height);
            con.AddLineToPoint(0, rect.Height);
            con.AddLineToPoint(0, rect.Height - length);
            con.StrokePath();
        }
Beispiel #24
0
		static void addPath(CGContext context, CGRect rect, float radius, RoundedCorner cornerMask)
		{
			context.MoveTo(rect.X, rect.Y + radius);
			context.AddLineToPoint(rect.X, rect.Y + rect.Height - radius);
			if (((int)cornerMask & (int)RoundedCorner.BottomLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + rect.Height - radius, 
					radius, (nfloat)Math.PI, (nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + radius, rect.Y + rect.Height);
			}

			context.AddLineToPoint(rect.X + rect.Width - radius, 
				rect.Y + rect.Height);

			if (((int)cornerMask & (int)RoundedCorner.BottomRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, 
					rect.Y + rect.Height - radius, radius, (nfloat)Math.PI / 2, 0.0f, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height - radius);
			}

			context.AddLineToPoint(rect.X + rect.Width, rect.Y + radius);

			if (((int)cornerMask & (int)RoundedCorner.TopRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, rect.Y + radius, 
					radius, 0, -(nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y);
				context.AddLineToPoint(rect.X + rect.Width - radius, rect.Y);
			}

			context.AddLineToPoint(rect.X + radius, rect.Y);

			if (((int)cornerMask & (int)RoundedCorner.TopLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + radius, radius, 
					-(nfloat)Math.PI / 2, (nfloat)Math.PI, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y);
				context.AddLineToPoint(rect.X, rect.Y + radius);
			}

			context.ClosePath();
		}
        public void UpdateGraph(nfloat progressPercent)
        {
            _progressPercent = progressPercent;

            _g.SetStrokeColor(UIColor.FromRGB(155, 155, 155).CGColor);
            _g.MoveTo(_x0, _y0);
            _g.AddLineToPoint(_x0 + (_x1 - _x0), _y0);
            _g.StrokePath();

            _g.SetStrokeColor(_barColor.CGColor);
            _g.MoveTo(_x0, _y0);
            _g.AddLineToPoint(_x0 + _progressPercent * (_x1 - _x0), _y0);
            _g.StrokePath();
            SetNeedsDisplay();
        }
Beispiel #26
0
        public static void AddBottomRoundedRect(this CGContext c, RectangleF b, float r)
        {
            c.MoveTo(b.Left, b.Top + r);
            c.AddLineToPoint(b.Left, b.Bottom - r);

            c.AddArc(b.Left + r, b.Bottom - r, r, (float)(Math.PI), (float)(Math.PI / 2), true);

            c.AddLineToPoint(b.Right - r, b.Bottom);

            c.AddArc(b.Right - r, b.Bottom - r, r, (float)(-3 * Math.PI / 2), (float)(0), true);

            c.AddLineToPoint(b.Right, b.Top);

            c.AddLineToPoint(b.Left, b.Top);
        }
Beispiel #27
0
        /// <summary>
        /// Draw the triangle
        /// </summary>
        /// <param name="rect">Rect.</param>
        public override void Draw(CGRect rect)
        {
            UIColor.Clear.SetColor();
            UIGraphics.RectFill(rect);
            CGContext context = UIGraphics.GetCurrentContext();

            context.BeginPath();
            context.MoveTo(0.0f, 0.0f);
            context.AddLineToPoint(ENDGE_LENGTH, ENDGE_LENGTH);
            context.AddLineToPoint(ENDGE_LENGTH, 0.0f);
            context.ClosePath();
            TriangleBackgroundColor.SetFill();
            context.DrawPath(CGPathDrawingMode.Fill);
            AddSubview(ActionView);
        }
Beispiel #28
0
        public override void Draw(CGRect bounds, CGContext context, UIView view)
        {
            var width = 0.5f / UIScreen.MainScreen.Scale;
            context.BeginPath();
            context.SetLineWidth(width);
            context.SetStrokeColor(UIColor.FromRGB(150, 150, 154).CGColor);
            var x = bounds.Width / 2f - width;
			context.MoveTo(x, 0f);
			context.AddLineToPoint(x, bounds.Height);
            context.StrokePath();

            var row = Value;
            var half = bounds.Height / 2;
            var halfText = _font.LineHeight / 2 + 1;

            row.Image1.Draw(new CGRect(15, half - 8f, 16f, 16f));

            if (!string.IsNullOrEmpty(row.Text1))
            {
                UIColor.Gray.SetColor();
                new NSString(row.Text1).DrawString(new CGRect(36,  half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation);
            }

            row.Image2.Draw(new CGRect(bounds.Width / 2 + 15, half - 8f, 16f, 16f));

            if (!string.IsNullOrEmpty(row.Text2))
            {
                UIColor.Gray.SetColor();
                new NSString(row.Text2).DrawString(new CGRect(bounds.Width / 2 + 36,  half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation);
            }
        }
Beispiel #29
0
        private void DrawStroke(CGContext context, UITouch touch)
        {
            var    previousLocation = touch.PreviousLocationInView(this);
            var    location         = touch.LocationInView(this);
            nfloat lineWidth;

            if (touch.Type == UITouchType.Stylus)
            {
                lineWidth = touch.AltitudeAngle < TiltThreshold?LineWidthForShading(context, touch) : LineWidthForDrawing(touch);

                DrawColor.SetStroke();
            }
            else
            {
                lineWidth = (nfloat)HandLineWidth;
                DrawColor.SetStroke();
            }

            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Round);

            context.MoveTo(previousLocation.X, previousLocation.Y);
            context.AddLineToPoint(location.X, location.Y);
            context.StrokePath();
        }
        void HatchHorizontalBrick(CGContext context)
        {
            var hatchWidth  = getHatchWidth(hatchStyle);
            var hatchHeight = getHatchHeight(hatchStyle);
            var lineWidth   = getLineWidth(hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground(context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor);
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            CGRect rect = new CGRect(0, 0, 1, 1);

            rect.Y      = 3;
            rect.Width  = hatchWidth;
            rect.Height = hatchHeight - 4;
            context.StrokeRect(rect);

            context.MoveTo(hatchWidth / 2.0f, 0);
            context.AddLineToPoint(hatchWidth / 2.0f, 3);
            context.StrokePath();
        }
Beispiel #31
0
        public override void RelLineTo(object backend, double dx, double dy)
        {
            CGContext ctx = ((CGContextBackend)backend).Context;
            PointF    p   = ctx.GetPathCurrentPoint();

            ctx.AddLineToPoint((float)(p.X + dx), (float)(p.Y + dy));
        }
Beispiel #32
0
        public void DrawLine(CGPoint fromPoint, CGPoint toPoint)
        {
            UIGraphics.BeginImageContext(this.View.Frame.Size);
            CGContext context = UIGraphics.GetCurrentContext() as CGContext;

            if (context != null)
            {
                //tempImageView.Image.Draw(this.View.Bounds);
                tempImageView.Draw(this.View.Bounds);


                context.MoveTo(fromPoint.X, fromPoint.Y);
                context.AddLineToPoint(toPoint.X, fromPoint.Y);

                context.SetLineCap(CGLineCap.Round);
                context.SetBlendMode(CGBlendMode.Normal);
                context.SetLineWidth(brushWidth);
                context.SetStrokeColor(color.CGColor);

                context.StrokePath();

                tempImageView.Image = UIGraphics.GetImageFromCurrentImageContext();
                tempImageView.Alpha = opacity;
                UIGraphics.EndImageContext();
            }
        }
 protected override void DrawGridlines(RectangleF rect, CGContext context)
 {
     float maxY = rect.Size.Height;
     for (float y = CellSize.Height; y < maxY; y += (CellSize.Height + Gridlines.Thickness))
     {
         context.MoveTo(rect.Left, y + 0.5f);
         context.AddLineToPoint(rect.Right, y + 0.5f);
     }
     context.StrokePath();
 }
 protected override void DrawGridlines(RectangleF rect, CGContext context)
 {
     float maxX = rect.Size.Width;
     float cellWidth = CellSize.Width;
     for (float x = cellWidth; x < maxX; x += (cellWidth + Gridlines.Thickness))
     {
         context.MoveTo(x + 0.5f, rect.Location.Y);
         context.AddLineToPoint(x + 0.5f, rect.Size.Height);
     }
     context.StrokePath();
 }
Beispiel #35
0
		public override void DrawInContext (CGContext ctx)
		{
			base.DrawInContext (ctx);
			
			var bounds = Bounds;
			var c = new PointF (bounds.GetMidX (), bounds.GetMidY ());
			
			ctx.BeginPath ();
			ctx.MoveTo (c.X, c.Y);
			ctx.AddLineToPoint (bounds.Right, c.Y);
			ctx.AddArc (c.X, c.Y, bounds.Width/2, (float)0, (float)Angle, false);
			ctx.AddLineToPoint (c.X, c.Y);
			ctx.SetFillColor (otherColor);
			ctx.FillPath ();
			
			ctx.BeginPath ();
			ctx.MoveTo (c.X, c.Y);
			ctx.AddLineToPoint (bounds.Right, c.Y);
			ctx.AddArc (c.X, c.Y, bounds.Width/2, (float)0, (float)(1e-7 + Angle), true);
			ctx.AddLineToPoint (c.X, c.Y);
			ctx.SetFillColor (color);
			ctx.FillPath ();
			
		}
Beispiel #36
0
	public override void DrawInContext (CGContext context)
	{
		context.SetRGBStrokeColor (1, 1, 1, 1f);
		
		// Draw lines with a stroke width from 1-10
		for (int i = 1; i <= 10; ++i) {
			context.SetLineWidth (i);
			context.MoveTo (10, (float) i * 20.5f);
			context.AddLineToPoint (310, (float)i * 20.5f);
			context.StrokePath ();
		}
		
		// Demonstration that stroke is even on both sides of the line
		context.SetLineWidth(15);
		context.MoveTo (10, 245.5f);
		context.AddLineToPoint (310, 245.5f);
		context.StrokePath ();
	
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.SetLineWidth (3);
		context.MoveTo (10, 245.5f);
		context.AddLineToPoint (310, 245.5f);
		context.StrokePath ();
	}	
		/// <summary>
		/// Draws a star at the bottom left of the context of the specified diameter
		/// </summary>
		protected void DrawStar (CGContext context, float starDiameter)
		{
			// declare vars
			// 144º
			float theta = 2 * (float)Math.PI * (2f / 5f);
			float radius = starDiameter / 2;

			// move up and over
			context.TranslateCTM (starDiameter / 2, starDiameter / 2);

			context.MoveTo (0, radius);
			for (int i = 1; i < 5; i++) {
				context.AddLineToPoint (radius * (float)Math.Sin (i * theta), radius * (float)Math.Cos (i * theta));
			}
			//context.SetRGBFillColor (1, 1, 1, 1);
			context.ClosePath ();
			context.FillPath ();
		}
Beispiel #38
0
		/// <summary>
		/// This is a slightly more complicated draw pattern, but using it is just 
		/// as easy as the previous one. To use this one, simply change "DrawPolkaDotPattern"
		/// in line 54 above to "DrawStarPattern"
		/// </summary>
		protected void DrawStarPattern (CGContext context)
		{
			// declare vars
			float starDiameter = 16;
			// 144º
			float theta = 2 * (float)Math.PI * (2f / 5f);
			float radius = starDiameter / 2;
			
			// move up and over
			context.TranslateCTM (starDiameter / 2, starDiameter / 2);
			
			context.MoveTo (0, radius);
			for (int i = 1; i < 5; i++) {
				context.AddLineToPoint (radius * (float)Math.Sin (i * theta), radius * (float)Math.Cos (i * theta));
			}
			// fill our star as dark gray
			context.ClosePath ();
			context.FillPath ();
		}
        public override void Draw(RectangleF bounds, CGContext context, UIView view)
        {
            context.BeginPath();
			context.SetLineWidth(1.0f);
			context.SetStrokeColor(UIColor.FromRGB(199, 199, 205).CGColor);
			var x = (int)System.Math.Ceiling(bounds.Width / 2 - 0.5f);
			context.MoveTo(x, 0f);
			context.AddLineToPoint(x, bounds.Height);
            context.StrokePath();

            /*
            context.BeginPath();
            context.SetStrokeColor(UIColor.FromRGBA(250, 250, 250, 128).CGColor);
            context.MoveTo(bounds.Width / 2 + 0.5f, 0);
            context.AddLineToPoint(bounds.Width / 2 + 0.5f, bounds.Height);
            context.StrokePath();
            */

            var row = Value;
            var half = bounds.Height / 2;
            var halfText = _font.LineHeight / 2 + 1;

            row.Image1.Draw(new RectangleF(15, half - 8f, 16f, 16f));

            if (!string.IsNullOrEmpty(row.Text1))
            {
                UIColor.Gray.SetColor();
                view.DrawString(row.Text1, new RectangleF(36,  half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation);
            }

            row.Image2.Draw(new RectangleF(bounds.Width / 2 + 15, half - 8f, 16f, 16f));

            if (!string.IsNullOrEmpty(row.Text2))
            {
                UIColor.Gray.SetColor();
                view.DrawString(row.Text2, new RectangleF(bounds.Width / 2 + 36,  half - halfText, bounds.Width / 2 - 40, _font.LineHeight), _font, UILineBreakMode.TailTruncation);
            }
        }
Beispiel #40
0
	public override void DrawInContext (CGContext context)
	{
		// Draw lines with a white stroke color
		context.SetRGBStrokeColor (1f, 1f, 1f, 1f);

		// Draw them with a 2.0 stroke width so they are more visible
		context.SetLineWidth (2);

		context.MoveTo (10, 30);
		context.AddLineToPoint (310, 30);
		context.StrokePath ();

		// Draw connected sequence of lines
		var points = new PointF [] {
			new PointF (10, 90),
			new PointF (70, 60),
			new PointF (130, 90),
			new PointF (190, 60),
			new PointF (250, 90),
			new PointF (310, 60)
		};
		
		context.AddLines (points);
		context.StrokePath ();

		var segments = new PointF [] {
			new PointF (10, 150),
			new PointF (70, 120),
			new PointF (130, 150),
			new PointF (190, 120),
			new PointF (250, 150),
			new PointF (310, 120),
		};

		// Bulk call to stroke a sequence of line segments

		context.StrokeLineSegments (segments);
	}
        protected void HatchUpwardDiagonal(CGContext context)
        {
            var hatchSize = getHatchWidth (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            if (hatchStyle != HatchStyle.ForwardDiagonal &&
                hatchStyle != HatchStyle.BackwardDiagonal)
            {
                initializeContext(context, hatchSize, false);
            }
            else {
                initializeContext(context, hatchSize, true);
            }

            /* draw background */
            drawBackground (context, backColor, hatchSize, hatchSize);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetFillColor(foreColor.ToCGColor());

            context.SetLineWidth(1);
            context.SetLineCap(CGLineCap.Square);

            context.MoveTo(0,0);
            context.AddLineToPoint(hatchSize,hatchSize);
            /* draw a diagonal line for as many times as linewidth*/
            for (int l = 0; l < lineWidth; l++)
            {
                /* draw a diagonal line */
                context.MoveTo(l,0);
                context.AddLineToPoint(hatchSize, hatchSize-l);

                context.StrokePath();
            }

            /**
             * because we are within a rectangular pattern we have to complete the tip of the preceeding line
             * pattern
             */
            for (int k = 1; k < lineWidth; k++)
            {
                /* draw a diagonal line */
                context.MoveTo(0,hatchSize-k);
                context.AddLineToPoint(k-1, hatchSize-1);

                context.StrokePath();
            }
        }
Beispiel #42
0
		public void DrawInContext (CGContext context, bool isDebuggingEnabled, bool usePreciseLocation)
		{
			LinePoint maybePriorPoint = null;

			foreach (var point in points) {
				if (maybePriorPoint == null) {
					maybePriorPoint = point;
					continue;
				}

				var priorPoint = maybePriorPoint;

				var color = UIColor.Black;

				if (isDebuggingEnabled) {
					if (point.Properties.Contains (PointType.Cancelled))
						color = UIColor.Red;
					else if (point.Properties.Contains (PointType.NeedsUpdate))
						color = UIColor.Orange;
					else if (point.Properties.Contains (PointType.Finger))
						color = UIColor.Purple;
					else if (point.Properties.Contains (PointType.Coalesced))
						color = UIColor.Green;
					else if (point.Properties.Contains (PointType.Predicted))
						color = UIColor.Blue;
				} else {
					if (point.Properties.Contains (PointType.Cancelled))
						color = UIColor.Clear;
					else if (point.Properties.Contains (PointType.Finger))
						color = UIColor.Purple;
					if (point.Properties.Contains (PointType.Predicted) && !point.Properties.Contains (PointType.Cancelled))
						color = color.ColorWithAlpha (0.5f);
				}

				var location = usePreciseLocation ? point.PreciseLocation : point.Location;
				var priorLocation = usePreciseLocation ? priorPoint.PreciseLocation : priorPoint.Location;

				context.SetStrokeColor (color.CGColor);
				context.BeginPath ();
				context.MoveTo (priorLocation.X, priorLocation.Y);
				context.AddLineToPoint (location.X, location.Y);
				context.SetLineWidth (point.Magnitude);
				context.StrokePath ();

				maybePriorPoint = point;
			}
		}
Beispiel #43
0
        public void draw(CGContext context)
        {
            context.SetLineWidth(lineWidth);
            context.MoveTo(this.begin.X, this.begin.Y);
            context.AddLineToPoint(this.end.X, this.end.Y);

            UIColor clr = new UIColor(red, green, blue, alpha);
            clr.SetStroke();

            context.StrokePath();
        }
Beispiel #44
0
        public void drawWithColor(CGContext context, UIColor clr)
        {
            context.SetLineWidth(lineWidth);
            context.MoveTo(this.begin.X, this.begin.Y);
            context.AddLineToPoint(this.end.X, this.end.Y);

            clr.SetStroke();

            context.StrokePath();
        }
        protected void HatchVertical(CGContext context)
        {
            var hatchSize = getHatchWidth (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchSize, false);

            /* draw background */
            drawBackground (context, backColor, hatchSize, hatchSize);

            /* draw horizontal line in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchSize / 2.0f;

            // draw a horizontal line
            context.MoveTo(0, 0);
            context.AddLineToPoint(0, hatchSize);

            context.StrokePath();
        }
Beispiel #46
0
	public override void DrawInContext (CGContext context)
	{
		// Drawing lines with a white stroke color
		context.SetRGBStrokeColor(1, 1, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth(2);
		
		// Each dash entry is a run-length in the current coordinate system.
		// For dash1 we demonstrate the effect of the number of entries in the dash array
		// when count==2, we get length 10 drawn, length 10 skipped, etc
		// when count==3, we get 10 drawn, 10 skipped, 20 draw, 10 skipped, 10 drawn, 20 skipped, etc
		// and so on
		float [] dash1 = new float [] {10, 10, 20, 30, 50};
		
		// Different dash lengths
		for(int i = 2; i <= 5; ++i)
		{
			context.SetLineDash(0, dash1, i);
			context.MoveTo(10, (i - 1) * 20);
			context.AddLineToPoint(310, (i - 1) * 20);
			context.StrokePath();
		}
		
		// For dash2 we always use count 4, but use it to demonstrate the phase
		// phase=0 starts us 0 points into the dash, so we draw 10, skip 10, draw 20, skip 20, etc.
		// phase=6 starts 6 points in, so we draw 4, skip 10, draw 20, skip 20, draw 10, skip 10, etc.
		// phase=12 stats us 12 points in, so we skip 8, draw 20, skip 20, draw 10, skip 10, etc.
		// and so on.
		float [] dash2 = {10, 10, 20, 20};
	
		// Different dash phases
		for(int i = 0; i < 10; ++i)
		{
			context.SetLineDash((float) i * 6, dash2, 4);
			context.MoveTo(10, (float) (i + 6) * 20);
			context.AddLineToPoint(310, (float)(i + 6) * 20);
			context.StrokePath();
		}
	}	
        void HatchShingle(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor.ToCGColor());
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchWidth / 2.0f;

            // We are basically going to draw a lamda sign

            // Draw base
            context.MoveTo(0,0);
            context.AddLineToPoint(halfMe,halfMe-HALF_PIXEL_Y);
            context.AddLineToPoint(hatchWidth, HALF_PIXEL_Y);
            context.StrokePath();

            // draw the first part of tail
            context.MoveTo(halfMe + HALF_PIXEL_X, halfMe);
            context.AddLineToPoint(halfMe + HALF_PIXEL_X, halfMe + 1);
            context.StrokePath();

            // now the last curl on the tail
            CGRect rect = new CGRect (1,hatchHeight-1,1,1);
            setPixels(context, rect);

            rect.X += 1;
            setPixels(context, rect);

            rect.X += 1;
            rect.Y -= 1;
            setPixels(context, rect);
        }
Beispiel #48
0
		public static void DrawGridLines (CGContext context, float x, float width)
		{
			for (float y = -48.5f; y <= 48.5f; y += 16.0f) {
				context.MoveTo (x, y);
				context.AddLineToPoint (x + width, y);
			}
			context.SetStrokeColor (GraphLineColor ());
			context.StrokePath ();
		}
        void drawLinesToChildren(CGContext context, NodeView node)
        {
            if (node.LeftChild != null) {
                context.MoveTo (node.Frame.X + NodeWidth / 2, node.Frame.Y + NodeHeight);
                context.AddLineToPoint (node.LeftChild.Frame.X + NodeWidth / 2, node.LeftChild.Frame.Y);
                context.StrokePath ();
                drawLinesToChildren (context, node.LeftChild);
            }

            if (node.RightChild != null) {
                context.MoveTo (node.Frame.X + NodeWidth / 2, node.Frame.Y + NodeHeight);
                context.AddLineToPoint (node.RightChild.Frame.X + NodeWidth / 2, node.RightChild.Frame.Y);
                context.StrokePath ();
                drawLinesToChildren (context, node.RightChild);
            }
        }
        void HatchHorizontalBrick(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor.ToCGColor());

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            CGRect rect = new CGRect (0,0,1,1);

            rect.Y = 3;
            rect.Width = hatchWidth;
            rect.Height = hatchHeight - 4;
            context.StrokeRect(rect);

            context.MoveTo(hatchWidth / 2.0f, 0);
            context.AddLineToPoint(hatchWidth / 2.0f,3);
            context.StrokePath();
        }
        void HatchWeave(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor.ToCGColor());

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfWidth = hatchWidth / 2.0f;
            float halfHeight = hatchHeight / 2.0f;

            CGRect rect = new CGRect (0,0,1,1);

            // Add upward diagonals
            context.MoveTo(0,0);
            context.AddLineToPoint(halfWidth, halfHeight);
            context.StrokePath();

            context.MoveTo(0, halfHeight);
            context.AddLineToPoint(halfWidth -1, hatchHeight - 1);
            context.StrokePath();

            context.MoveTo(halfWidth, 0);
            context.AddLineToPoint(6, 2);
            context.StrokePath();

            //			context.MoveTo(0, 4);
            //			context.AddLineToPoint(2, 2);
            //			context.StrokePath();

            context.MoveTo(2,6);
            context.AddLineToPoint(7, 1);
            context.StrokePath();
        }
        void HatchDiagonalCross(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, true);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchHeight / 2.0f;

            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchWidth, hatchHeight);
            context.StrokePath();

            context.MoveTo(hatchWidth, 0);
            context.AddLineToPoint(0, hatchHeight);
            context.StrokePath();
        }
Beispiel #53
0
        public static void DrawLine(CGContext context, List<PointF> points, CGColor color, float lineWidth, bool closePath, bool dashed)
        {
            if (points == null)
                throw new NullReferenceException();

            if (points.Count == 0)
                throw new ArgumentException("The line must have at least one point.");

            context.SaveState();
            context.SetStrokeColor(color);
            context.SetLineWidth(lineWidth);
            context.MoveTo(points[0].X, points[0].Y);
            for(int a = 1; a < points.Count; a++)
                context.AddLineToPoint(points[a].X, points[a].Y);
            if (dashed)
                context.SetLineDash(0, new float[2] { 1, 2 }, 2);
            if (closePath)
                context.ClosePath();
            context.StrokePath();
            context.RestoreState();
        }
        void HatchOutlinedDiamond(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor.ToCGColor());
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            // this is really just two diagonal lines from each corner too
            // their opposite corners.
            context.MoveTo(0,0);
            context.AddLineToPoint(hatchWidth, hatchHeight);
            context.StrokePath();
            context.MoveTo(1,hatchHeight);
            context.AddLineToPoint(hatchWidth, 1);
            context.StrokePath();
        }
        protected void HatchGrid(CGContext context)
        {
            var hatchSize = getHatchWidth (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchSize, false);

            /* draw background */
            drawBackground (context, backColor, hatchSize, hatchSize);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            hatchSize -=HALF_PIXEL_X;
            float yoffset = 0;

            if (hatchStyle == HatchStyle.DottedGrid)
            {
                yoffset = 1;
                nfloat[] dash = new nfloat[] { 1, 1};
                context.SetLineDash(2,dash);

            }

            /* draw a horizontal line */
            context.MoveTo(0,yoffset);
            context.AddLineToPoint(0,hatchSize);
            context.StrokePath();
            /* draw a vertical line */
            context.MoveTo(0,hatchSize);
            context.AddLineToPoint(hatchSize, hatchSize);

            context.StrokePath();
        }
        void HatchDashedHorizontal(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchHeight / 2.0f - 1;
            hatchWidth -=1;
            hatchHeight -= 1;

            context.MoveTo(halfMe+1, halfMe);
            context.AddLineToPoint(hatchWidth, halfMe);
            context.StrokePath();

            context.MoveTo(0,hatchHeight);
            context.AddLineToPoint(halfMe, hatchHeight);
            context.StrokePath();
        }
Beispiel #57
0
        public void DrawInContext(CGContext context, bool isDebuggingEnabled, bool usePreciseLocation)
        {
            LinePoint maybePriorPoint = null;

            foreach (var point in Points) {
                if (maybePriorPoint == null) {
                    maybePriorPoint = point;
                    continue;
                }

                var priorPoint = maybePriorPoint;

                var color = UIColor.Black;
                var pointType = point.PointType;

                if (isDebuggingEnabled) {
                    if (pointType.Has (PointType.Cancelled))
                        color = UIColor.Red;
                    else if (pointType.Has (PointType.NeedsUpdate))
                        color = UIColor.Orange;
                    else if (pointType.Has (PointType.Finger))
                        color = UIColor.Purple;
                    else if (pointType.Has (PointType.Coalesced))
                        color = UIColor.Green;
                    else if (pointType.Has (PointType.Predicted))
                        color = UIColor.Blue;
                } else {
                    if (pointType.Has (PointType.Cancelled))
                        color = UIColor.Red;
                    else if (pointType.Has (PointType.Finger))
                        color = UIColor.Purple;

                    if (pointType.Has (PointType.Predicted) && !pointType.Has (PointType.Cancelled))
                        color = color.ColorWithAlpha (.5f);
                }

                var location = usePreciseLocation ? point.PreciseLocation : point.Location;
                var priorLocation = usePreciseLocation ? priorPoint.PreciseLocation : priorPoint.Location;

                context.SetStrokeColor (color.CGColor);
                context.BeginPath ();
                context.MoveTo (priorLocation.X, priorLocation.Y);
                context.AddLineToPoint (location.X, location.Y);
                context.SetLineWidth (point.Magnitude);
                context.StrokePath ();

                // Draw azimuith and elevation on all non-coalesced points when debugging.
                if (isDebuggingEnabled &&
                    !point.PointType.Has (PointType.Coalesced) &&
                    !point.PointType.Has (PointType.Predicted) &&
                    !point.PointType.Has (PointType.Finger)) {
                    context.BeginPath ();
                    context.SetStrokeColor (UIColor.Red.CGColor);
                    context.SetLineWidth (.5f);
                    context.MoveTo (location.X, location.Y);
                    var targetPoint = new CGPoint (.5f + 10f * NMath.Cos (point.AltitudeAngle), 0f);
                    targetPoint = CGAffineTransform.MakeRotation (point.AzimuthAngle).TransformPoint (targetPoint);
                    targetPoint.X += location.X;
                    targetPoint.Y += location.Y;
                    context.AddLineToPoint (targetPoint.X, targetPoint.Y);
                    context.StrokePath ();
                }

                maybePriorPoint = point;
            }
        }
        void HatchDiagonalBrick(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            hatchHeight -= 1;
            hatchWidth -= 1;

            context.MoveTo(0, 0);
            context.AddLineToPoint(hatchWidth,hatchHeight);
            context.StrokePath();

            context.MoveTo(0, hatchHeight);
            context.AddLineToPoint(hatchWidth / 2.0f,hatchHeight / 2.0f);
            context.StrokePath();
        }
Beispiel #59
0
	public override void DrawInContext (CGContext context)
	{
		// Drawing lines with a white stroke color
		context.SetRGBStrokeColor(1, 1, 1, 1);
		
		// Preserve the current drawing state
		context.SaveState();
		
		// Set the line width so that the cap is visible
		context.SetLineWidth(20);
		
		// Line caps demonstration
		
		// Line cap butt, default.
		context.SetLineCap(CGLineCap.Butt);
		context.MoveTo(40, 30);
		context.AddLineToPoint(280, 30);
		context.StrokePath();
		
		// Line cap round
		context.SetLineCap(CGLineCap.Round);
		context.MoveTo(40, 65);
		context.AddLineToPoint(280, 65);
		context.StrokePath();
		
		// Line cap square
		context.SetLineCap(CGLineCap.Square);
		context.MoveTo(40, 100);
		context.AddLineToPoint(280, 100);
		context.StrokePath();
		
		// Restore the previous drawing state, and save it again.
		context.RestoreState();
		context.SaveState();
		
		// Set the line width so that the join is visible
		context.SetLineWidth(20);
		
		// Line join miter, default
		context.SetLineJoin(CGLineJoin.Miter);
		context.MoveTo(40, 260);
		context.AddLineToPoint(160, 140);
		context.AddLineToPoint(280, 260);
		context.StrokePath();
		
		// Line join round
		context.SetLineJoin(CGLineJoin.Round);
		context.MoveTo(40, 320);
		context.AddLineToPoint(160, 200);
		context.AddLineToPoint(280, 320);
		context.StrokePath();
		
		// Line join bevel
		context.SetLineJoin(CGLineJoin.Bevel);
		context.MoveTo(40, 380);
		context.AddLineToPoint(160, 260);
		context.AddLineToPoint(280, 380);
		context.StrokePath();
	
		// Restore the previous drawing state.
		context.RestoreState();
	
		// Demonstrate where the path that generated each line is
		context.SetRGBStrokeColor(1, 0, 0, 1);
		context.SetLineWidth(3);
		context.MoveTo(40, 30);
		context.AddLineToPoint(280, 30);
		context.MoveTo(40, 65);
		context.AddLineToPoint(280, 65);
		context.MoveTo(40, 100);
		context.AddLineToPoint(280, 100);
		context.MoveTo(40, 260);
		context.AddLineToPoint(160, 140);
		context.AddLineToPoint(280, 260);
		context.MoveTo(40, 320);
		context.AddLineToPoint(160, 200);
		context.AddLineToPoint(280, 320);
		context.MoveTo(40, 380);
		context.AddLineToPoint(160, 260);
		context.AddLineToPoint(280, 380);
		context.StrokePath();
	}	
        void HatchSolidDiamond(CGContext context)
        {
            var hatchWidth = getHatchWidth (hatchStyle);
            var hatchHeight = getHatchHeight (hatchStyle);
            var lineWidth = getLineWidth (hatchStyle);

            initializeContext(context, hatchHeight, false);

            /* draw background */
            drawBackground (context, backColor, hatchWidth, hatchHeight);

            /* draw lines in the foreground color */
            context.SetFillColor(foreColor.ToCGColor());
            context.SetStrokeColor(foreColor.ToCGColor());
            context.SetLineWidth(lineWidth);
            context.SetLineCap(CGLineCap.Square);

            float halfMe = hatchWidth / 2.0f;

            // We will paint two triangles from corners meeting in the middle
            // make sure to offset by half pixels so that the point is actually a point.
            context.MoveTo(-HALF_PIXEL_X,HALF_PIXEL_Y);
            context.AddLineToPoint(2+HALF_PIXEL_X, halfMe - HALF_PIXEL_Y);
            context.AddLineToPoint(-HALF_PIXEL_X, hatchHeight- (1.0f + HALF_PIXEL_Y));
            context.ClosePath();
            context.FillPath();

            // now we do the right one
            context.MoveTo(hatchWidth,HALF_PIXEL_Y);
            context.AddLineToPoint(halfMe+HALF_PIXEL_X, halfMe - HALF_PIXEL_Y);
            context.AddLineToPoint(hatchWidth, hatchHeight - (1.0f + HALF_PIXEL_Y));
            context.ClosePath();
            context.FillPath();
        }