AddLineToPoint() 공개 메소드

public AddLineToPoint ( float x, float y ) : void
x float
y float
리턴 void
        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();
        }
예제 #2
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 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();
        }
        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();
        }
        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();
            }
        }
        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();
        }
        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;

            RectangleF rect = new RectangleF(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();
        }
        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;
                float[] dash = new float[] { 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 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();
        }
        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
            RectangleF rect = new RectangleF(1,hatchHeight-1,1,1);
            setPixels(context, rect);

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

            rect.X += 1;
            rect.Y -= 1;
            setPixels(context, rect);
        }
        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();
        }
        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);

            RectangleF rect = new RectangleF(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();
        }
        /*
         * Based on the algorithm described in
         *      http://www.stillhq.com/ctpfaq/2002/03/c1088.html#AEN1212
         */
        static void make_arc(CGContext graphics, bool start, float x, float y, float width,
			         float height, float startAngle, float endAngle, bool antialiasing, bool isPieSlice)
        {
            float delta, bcp;
            double sin_alpha, sin_beta, cos_alpha, cos_beta;
            float PI = (float)Math.PI;

            float rx = width / 2;
            float ry = height / 2;

            /* center */
            float cx = x + rx;
            float cy = y + ry;

            /* angles in radians */
            float alpha = startAngle * PI / 180;
            float beta = endAngle * PI / 180;

            /* adjust angles for ellipses */
            alpha = (float)Math.Atan2(rx * Math.Sin(alpha), ry * Math.Cos(alpha));
            beta = (float)Math.Atan2(rx * Math.Sin(beta), ry * Math.Cos(beta));

            if (Math.Abs(beta - alpha) > PI)
            {
                if (beta > alpha)
                    beta -= 2 * PI;
                else
                    alpha -= 2 * PI;
            }

            delta = beta - alpha;
            bcp = (float)(4.0 / 3.0 * (1 - Math.Cos(delta / 2)) / Math.Sin(delta / 2));

            sin_alpha = Math.Sin(alpha);
            sin_beta = Math.Sin(beta);
            cos_alpha = Math.Cos(alpha);
            cos_beta = Math.Cos(beta);

            /* don't move to starting point if we're continuing an existing curve */
            if (start)
            {
                /* starting point */
                double sx = cx + rx * cos_alpha;
                double sy = cy + ry * sin_alpha;
                if (isPieSlice)
                    graphics.AddLineToPoint((float)sx,(float)sy);
                else
                    graphics.MoveTo((float)sx,(float)sy);
            }

            graphics.AddCurveToPoint(cx + rx * (float)(cos_alpha - bcp * sin_alpha),
                                    cy + ry * (float)(sin_alpha + bcp * cos_alpha),
                                    cx + rx * (float)(cos_beta + bcp * sin_beta),
                                    cy + ry * (float)(sin_beta - bcp * cos_beta),
                                    cx + rx * (float)cos_beta, cy + ry * (float)sin_beta);
        }