public IVertexSource GetGlyphForCharacter(char character)
        {
            // scale it to the correct size.
            IVertexSource sourceGlyph = TypeFace.GetGlyphForCharacter(character);

            if (sourceGlyph != null)
            {
                if (DoUnderline)
                {
                    sourceGlyph = new GlyphWithUnderline(sourceGlyph, TypeFace.GetAdvanceForCharacter(character), TypeFace.Underline_position, TypeFace.Underline_thickness);
                }
                Affine glyphTransform = Affine.NewIdentity();
                glyphTransform *= Affine.NewScaling(currentEmScaling);
                IVertexSource characterGlyph = new VertexSourceApplyTransform(sourceGlyph, glyphTransform);

                if (FlatenCurves)
                {
                    characterGlyph = new FlattenCurves(characterGlyph);
                }

                return(characterGlyph);
            }

            return(null);
        }
Exemple #2
0
        public blur()
        {
            m_rbuf2                 = new ImageBuffer();
            m_shape_bounds          = new RectangleDouble();
            m_method                = new RadioButtonGroup(new Vector2(10.0, 10.0), new Vector2(130.0, 60.0));
            m_radius                = new Slider(new Vector2(130 + 10.0, 10.0 + 4.0), new Vector2(290, 8.0));
            m_shadow_ctrl           = new PolygonEditWidget(4);
            m_channel_r             = new CheckBox(10.0, 80.0, "Red");
            m_channel_g             = new CheckBox(10.0, 95.0, "Green");
            m_channel_b             = new CheckBox(10.0, 110.0, "Blue");
            m_FlattenCurves         = new CheckBox(10, 315, "Convert And Flatten Curves");
            m_FlattenCurves.Checked = true;

            AddChild(m_method);
            m_method.AddRadioButton("Stack Blur");
            m_method.AddRadioButton("Recursive Blur");
            m_method.AddRadioButton("Channels");
            m_method.SelectedIndex = 1;

            AddChild(m_radius);
            m_radius.SetRange(0.0, 40.0);
            m_radius.Value = 15.0;
            m_radius.Text  = "Blur Radius={0:F2}";

            AddChild(m_shadow_ctrl);

            AddChild(m_channel_r);
            AddChild(m_channel_g);
            AddChild(m_channel_b);
            AddChild(m_FlattenCurves);
            m_channel_g.Checked = true;

            m_sl = new ScanlineCachePacked8();

            StyledTypeFace typeFaceForLargeA = new StyledTypeFace(LiberationSansFont.Instance, 300, flatenCurves: false);

            m_path = typeFaceForLargeA.GetGlyphForCharacter('a');

            Affine shape_mtx = Affine.NewIdentity();

            shape_mtx *= Affine.NewTranslation(150, 100);
            m_path     = new VertexSourceApplyTransform(m_path, shape_mtx);
            m_shape    = new FlattenCurves(m_path);

            bounding_rect.bounding_rect_single(m_shape, 0, ref m_shape_bounds);

            m_shadow_ctrl.SetXN(0, m_shape_bounds.Left);
            m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom);
            m_shadow_ctrl.SetXN(1, m_shape_bounds.Right);
            m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom);
            m_shadow_ctrl.SetXN(2, m_shape_bounds.Right);
            m_shadow_ctrl.SetYN(2, m_shape_bounds.Top);
            m_shadow_ctrl.SetXN(3, m_shape_bounds.Left);
            m_shadow_ctrl.SetYN(3, m_shape_bounds.Top);
            m_shadow_ctrl.line_color(new ColorF(0, 0.3, 0.5, 0.3));
        }
Exemple #3
0
        private static void PrintLineEnd(GCodeSketch turtle, bool drawGlpyphs, int i, Vector2 currentPos)
        {
            if (drawGlpyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource))
            {
                var flattened = new FlattenCurves(vertexSource);

                var verticies = flattened.Vertices();
                var firstItem = verticies.First();
                var position  = turtle.CurrentPosition;

                var scale = 0.32;

                if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo)
                {
                    turtle.MoveTo((firstItem.position * scale) + currentPos);
                }

                bool closed = false;

                foreach (var item in verticies)
                {
                    switch (item.command)
                    {
                    case ShapePath.FlagsAndCommand.MoveTo:
                        turtle.MoveTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.LineTo:
                        turtle.LineTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.FlagClose:
                        turtle.LineTo((firstItem.position * scale) + currentPos);
                        closed = true;
                        break;
                    }
                }

                if (!closed)
                {
                    turtle.LineTo((firstItem.position * scale) + currentPos);
                }
            }
        }
        private void DrawBigA(Graphics2D graphics2D)
        {
            ScanlineRasterizer m_ras = new ScanlineRasterizer();

            m_ras.SetVectorClipBox(0, 0, Width, Height);
            TypeFacePrinter            bigAPrinter       = new TypeFacePrinter("a", 150);
            FlattenCurves              flattenedBigA     = new FlattenCurves(bigAPrinter);
            VertexSourceApplyTransform scaleAndTranslate = new VertexSourceApplyTransform(flattenedBigA, Affine.NewTranslation(155, 55));
            ScanlineCachePacked8       m_sl             = new ScanlineCachePacked8();
            ScanlineRenderer           scanlineRenderer = new ScanlineRenderer();

#if false
            ImageProxySubpxelLcd24     clippingProxy = new ImageProxySubpxelLcd24(graphics2D.DestImage, new lcd_distribution_lut());
            VertexSourceApplyTransform scaledWide    = new VertexSourceApplyTransform(scaleAndTranslate, Affine.NewScaling(3, 1));
            m_ras.add_path(scaledWide);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#else
            m_ras.add_path(scaleAndTranslate);
            ImageClippingProxy clippingProxy = new ImageClippingProxy(graphics2D.DestImage);
            scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#endif
        }
        public void DrawCard(Graphics2D DestGraphics, int CardX, int CardY)
        {
            double StartX = CardX * CARD_WIDTH + m_BoardX;
            double StartY = CardY * CARD_HEIGHT + m_BoardY;

            RectangleDouble CardBounds           = new RectangleDouble(StartX + 1.5, StartY + 1.5, StartX + CARD_WIDTH - 1.5, StartY + CARD_HEIGHT - 1.5);
            RoundedRect     CardFiledRoundedRect = new RoundedRect(CardBounds.Left, CardBounds.Bottom, CardBounds.Right, CardBounds.Top, 5);
            Stroke          CardRectBounds       = new Stroke(CardFiledRoundedRect);

            CardRectBounds.width(1);

            CCard  Card        = MomsGame.GetCard(CardX, CardY);
            int    CardValue   = Card.GetValue();
            int    CardSuit    = Card.GetSuit();
            String ValueString = "Uninitialized ";

            if (CardValue > (int)CCard.CARD_VALUE.VALUE_ACE)
            {
                DestGraphics.SetTransform(Affine.NewIdentity());
                DestGraphics.Render(CardRectBounds, new RGBA_Bytes(0, 0, 0));
                if (CardValue > 10)
                {
                    switch (CardValue)
                    {
                    case 11:
                        ValueString = "J";
                        break;

                    case 12:
                        ValueString = "Q";
                        break;

                    case 13:
                        ValueString = "K";
                        break;

                    default:
                        throw new Exception();
                    }
                }
                else
                {
                    ValueString = CardValue.ToString();
                }

                TextWidget      stringToDraw = new TextWidget(ValueString, 10);
                RectangleDouble textBounds   = stringToDraw.Printer.LocalBounds;
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 2, CardBounds.Top - 8 - textBounds.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 4 - textBounds.Width, CardBounds.Bottom + 9 - textBounds.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));

                RGBA_Bytes    SuitColor = new RGBA_Bytes(0, 0, 0);
                IVertexSource suitPath  = new PathStorage();

                switch (CardSuit)
                {
                case (int)CCard.CARD_SUIT.SUIT_DIAMOND:
                {
                    SuitColor = new RGBA_Bytes(0xFF, 0x11, 0x11);
                    suitPath  = m_DiamondShape;
                }
                break;

                case (int)CCard.CARD_SUIT.SUIT_CLUB:
                {
                    SuitColor = new RGBA_Bytes(0x22, 0x22, 0x66);
                    suitPath  = new FlattenCurves(m_ClubShape);
                }
                break;

                case (int)CCard.CARD_SUIT.SUIT_HEART:
                {
                    SuitColor = new RGBA_Bytes(0xBB, 0x00, 0x00);
                    suitPath  = new FlattenCurves(m_HeartShape);
                }
                break;

                case (int)CCard.CARD_SUIT.SUIT_SPADE:
                {
                    SuitColor = new RGBA_Bytes(0x00, 0x00, 0x00);
                    suitPath  = new FlattenCurves(m_SpadeShape);
                }
                break;

                default:
                    break;
                }

                textBounds = stringToDraw.Printer.LocalBounds;

                if (CardValue < 11)
                {
                    for (int CurDot = 0; CurDot < CardValue; CurDot++)
                    {
                        double OffsetX = 0, OffsetY = 0;
                        GetSuitOffset(ref OffsetX, ref OffsetY, CurDot, (int)CardValue);
                        DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + OffsetX, CardBounds.Bottom + OffsetY));
                        DestGraphics.Render(suitPath, SuitColor);
                    }
                }
                else
                {
                    DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 9, CardBounds.Bottom + 17));
                    DestGraphics.Render(suitPath, SuitColor);
                    DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 9, CardBounds.Top - 17));
                    DestGraphics.Render(suitPath, SuitColor);

                    stringToDraw = new TextWidget(ValueString, 22);
                    textBounds   = stringToDraw.Printer.LocalBounds;
                    DestGraphics.SetTransform(Affine.NewTranslation(-1 + CardBounds.Left + CardBounds.Width / 2 - textBounds.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - textBounds.Height / 2));
                    DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));
                }
            }
            else
            {
                RGBA_Bytes HoleColor = new RGBA_Bytes(0, 0, 0);

                String OpenSpaceString;

                if (!MomsGame.SpaceIsClickable(CardX, CardY))
                {
                    HoleColor       = new RGBA_Bytes(0xf8, 0xe2, 0xe8);
                    OpenSpaceString = "X";
                }
                else
                {
                    HoleColor       = new RGBA_Bytes(0xe1, 0xe0, 0xf6);
                    OpenSpaceString = "O";
                }

                TextWidget      stringToDraw = new TextWidget(OpenSpaceString, 35);
                RectangleDouble Size         = stringToDraw.Printer.LocalBounds;
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + CardBounds.Width / 2 - Size.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - Size.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, HoleColor);
            }
        }
        private void render_gpc(Graphics2D graphics2D)
        {
            switch (m_polygons.SelectedIndex)
            {
            case 0:
            {
                //------------------------------------
                // Two simple paths
                //
                PathStorage ps1 = new PathStorage();
                PathStorage ps2 = new PathStorage();

                double x = m_x - Width / 2 + 100;
                double y = m_y - Height / 2 + 100;
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.ClosePolygon();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);

                ps1.MoveTo(x + 220, y + 222);
                ps1.LineTo(x + 363, y + 249);
                ps1.LineTo(x + 265, y + 331);

                ps1.MoveTo(x + 242, y + 243);
                ps1.LineTo(x + 268, y + 309);
                ps1.LineTo(x + 325, y + 261);

                ps1.MoveTo(x + 259, y + 259);
                ps1.LineTo(x + 273, y + 288);
                ps1.LineTo(x + 298, y + 266);

                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);

                graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
                graphics2D.Render(ps2, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

                CreateAndRenderCombined(graphics2D, ps1, ps2);
            }
            break;

            case 1:
            {
                //------------------------------------
                // Closed stroke
                //
                PathStorage ps1    = new PathStorage();
                PathStorage ps2    = new PathStorage();
                Stroke      stroke = new Stroke(ps2);
                stroke.width(10.0);

                double x = m_x - Width / 2 + 100;
                double y = m_y - Height / 2 + 100;
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.ClosePolygon();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);

                ps1.MoveTo(x + 220 - 50, y + 222);
                ps1.LineTo(x + 265 - 50, y + 331);
                ps1.LineTo(x + 363 - 50, y + 249);
                ps1.close_polygon(ShapePath.FlagsAndCommand.FlagCCW);

                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);
                ps2.ClosePolygon();

                graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
                graphics2D.Render(stroke, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

                CreateAndRenderCombined(graphics2D, ps1, stroke);
            }
            break;

            case 2:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                PathStorage gb_poly = new PathStorage();
                PathStorage arrows  = new PathStorage();
                GreatBritanPathStorage.Make(gb_poly);
                make_arrows(arrows);

                Affine mtx1 = Affine.NewIdentity();
                Affine mtx2 = Affine.NewIdentity();
                mtx1 *= Affine.NewTranslation(-1150, -1150);
                mtx1 *= Affine.NewScaling(2.0);

                mtx2  = mtx1;
                mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2);

                VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);
                VertexSourceApplyTransform trans_arrows  = new VertexSourceApplyTransform(arrows, mtx2);

                graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.Width = 0.1;
                graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

                graphics2D.Render(trans_arrows, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

                CreateAndRenderCombined(graphics2D, trans_gb_poly, trans_arrows);
            }
            break;

            case 3:
            {
                //------------------------------------
                // Great Britain and a Spiral
                //
                spiral sp     = new spiral(m_x, m_y, 10, 150, 30, 0.0);
                Stroke stroke = new Stroke(sp);
                stroke.width(15.0);

                PathStorage gb_poly = new PathStorage();
                GreatBritanPathStorage.Make(gb_poly);

                Affine mtx = Affine.NewIdentity();;
                mtx *= Affine.NewTranslation(-1150, -1150);
                mtx *= Affine.NewScaling(2.0);

                VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx);

                graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

                graphics2D.Render(stroke, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

                CreateAndRenderCombined(graphics2D, trans_gb_poly, stroke);
            }
            break;

            case 4:
            {
                //------------------------------------
                // Spiral and glyph
                //
                spiral sp     = new spiral(m_x, m_y, 10, 150, 30, 0.0);
                Stroke stroke = new Stroke(sp);
                stroke.width(15.0);

                PathStorage glyph = new PathStorage();
                glyph.MoveTo(28.47, 6.45);
                glyph.curve3(21.58, 1.12, 19.82, 0.29);
                glyph.curve3(17.19, -0.93, 14.21, -0.93);
                glyph.curve3(9.57, -0.93, 6.57, 2.25);
                glyph.curve3(3.56, 5.42, 3.56, 10.60);
                glyph.curve3(3.56, 13.87, 5.03, 16.26);
                glyph.curve3(7.03, 19.58, 11.99, 22.51);
                glyph.curve3(16.94, 25.44, 28.47, 29.64);
                glyph.LineTo(28.47, 31.40);
                glyph.curve3(28.47, 38.09, 26.34, 40.58);
                glyph.curve3(24.22, 43.07, 20.17, 43.07);
                glyph.curve3(17.09, 43.07, 15.28, 41.41);
                glyph.curve3(13.43, 39.75, 13.43, 37.60);
                glyph.LineTo(13.53, 34.77);
                glyph.curve3(13.53, 32.52, 12.38, 31.30);
                glyph.curve3(11.23, 30.08, 9.38, 30.08);
                glyph.curve3(7.57, 30.08, 6.42, 31.35);
                glyph.curve3(5.27, 32.62, 5.27, 34.81);
                glyph.curve3(5.27, 39.01, 9.57, 42.53);
                glyph.curve3(13.87, 46.04, 21.63, 46.04);
                glyph.curve3(27.59, 46.04, 31.40, 44.04);
                glyph.curve3(34.28, 42.53, 35.64, 39.31);
                glyph.curve3(36.52, 37.21, 36.52, 30.71);
                glyph.LineTo(36.52, 15.53);
                glyph.curve3(36.52, 9.13, 36.77, 7.69);
                glyph.curve3(37.01, 6.25, 37.57, 5.76);
                glyph.curve3(38.13, 5.27, 38.87, 5.27);
                glyph.curve3(39.65, 5.27, 40.23, 5.62);
                glyph.curve3(41.26, 6.25, 44.19, 9.18);
                glyph.LineTo(44.19, 6.45);
                glyph.curve3(38.72, -0.88, 33.74, -0.88);
                glyph.curve3(31.35, -0.88, 29.93, 0.78);
                glyph.curve3(28.52, 2.44, 28.47, 6.45);
                glyph.ClosePolygon();

                glyph.MoveTo(28.47, 9.62);
                glyph.LineTo(28.47, 26.66);
                glyph.curve3(21.09, 23.73, 18.95, 22.51);
                glyph.curve3(15.09, 20.36, 13.43, 18.02);
                glyph.curve3(11.77, 15.67, 11.77, 12.89);
                glyph.curve3(11.77, 9.38, 13.87, 7.06);
                glyph.curve3(15.97, 4.74, 18.70, 4.74);
                glyph.curve3(22.41, 4.74, 28.47, 9.62);
                glyph.ClosePolygon();

                Affine mtx = Affine.NewIdentity();
                mtx *= Affine.NewScaling(4.0);
                mtx *= Affine.NewTranslation(220, 200);
                VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
                FlattenCurves curve = new FlattenCurves(trans);

                CreateAndRenderCombined(graphics2D, stroke, curve);

                graphics2D.Render(stroke, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());

                graphics2D.Render(curve, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());
            }
            break;
            }
        }
Exemple #7
0
        public override Task Rebuild()
        {
            var allPaths = SvgParser.GetPaths(this.SvgPath);

            var selectedItems = new HashSet <SvgParser.SvgNodeInfo>(allPaths);

            try
            {
                this.Children.Modify(children =>
                {
                    children.Clear();

                    var svgContent = new List <IObject3D>();

                    int i = 0;
                    foreach (var item in selectedItems)
                    {
                        IVertexSource vertexSource = null;

                        if (item is SvgParser.SvgPolygonInfo polygon)
                        {
                            var storage = new VertexStorage();

                            storage.MoveTo(polygon.Points[0]);

                            for (var j = 1; j < polygon.Points.Count; j++)
                            {
                                storage.LineTo(polygon.Points[j]);
                            }

                            // close
                            storage.LineTo(polygon.Points[0]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPolyLineInfo polyline)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(polyline.Points[0]);

                            for (var j = 1; j < polyline.Points.Count; j++)
                            {
                                storage.LineTo(polyline.Points[j]);
                            }

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgLineInfo line)
                        {
                            var storage = new VertexStorage();
                            storage.MoveTo(line.Points[0]);
                            storage.LineTo(line.Points[1]);

                            vertexSource = storage;
                        }
                        else if (item is SvgParser.SvgPathInfo path)
                        {
                            vertexSource = new VertexStorage(path.DString);
                        }
                        else
                        {
                            // Skip unknown type
                            continue;
                        }

                        var flattened = new FlattenCurves(vertexSource)
                        {
                            ResolutionScale = 6
                        };

                        var itemZ = 3 + item.Z + (0.1 * i++);

                        if (item.Fill is SvgColourServer fill)
                        {
                            var fillColor = fill.Colour.GetAggColor();

                            var object3D = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(flattened, itemZ),
                                Color = fillColor,
                                // Flip
                                //Matrix = Matrix4X4.Identity * Matrix4X4.CreateScale(1, -1, 1)
                            };

                            svgContent.Add(object3D);
                        }

                        if (item.Stroke is SvgColourServer stroke)
                        {
                            var aggStroke = new Stroke(flattened, item.StrokeWidth)
                            {
                                LineCap  = LineCap.Round,
                                LineJoin = LineJoin.Round
                            };

                            //							aggStroke.l

                            var strokeObject = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(aggStroke, itemZ),
                                Color = stroke.Colour.GetAggColor()
                            };

                            svgContent.Add(strokeObject);
                        }
                    }

                    var mirror = new MirrorObject3D()
                    {
                        MirrorOn = MirrorObject3D.MirrorAxis.Y_Axis
                    };

                    mirror.Children.Modify(list =>
                    {
                        list.AddRange(svgContent);
                    });

                    mirror.Rebuild();

                    mirror.Matrix = Matrix4X4.CreateScale(0.15);

                    children.Add(mirror);
                });
            }
            catch { }

            return(base.Rebuild());
        }
Exemple #8
0
        private void RenderPolygonToPathAgainst(Graphics2D graphics2D)
        {
            IVertexSource pathToUse = null;

            switch (shapeTypeRadioGroup.SelectedIndex)
            {
            case 0:    // simple polygon map
            {
                PathStorage ps1 = new PathStorage();

                ps1.MoveTo(85, 417);
                ps1.LineTo(338, 428);
                ps1.LineTo(344, 325);
                ps1.LineTo(399, 324);
                ps1.LineTo(400, 421);
                ps1.LineTo(644, 415);
                ps1.LineTo(664, 75);
                ps1.LineTo(98, 81);
                ps1.ClosePolygon();

                ps1.MoveTo(343, 290);
                ps1.LineTo(159, 235);
                ps1.LineTo(154, 162);
                ps1.LineTo(340, 114);
                ps1.ClosePolygon();

                ps1.MoveTo(406, 121);
                ps1.LineTo(587, 158);
                ps1.LineTo(591, 236);
                ps1.LineTo(404, 291);
                ps1.ClosePolygon();

                pathToUse = ps1;
            }
            break;

            case 1:     // multiple pegs
            {
                PathStorage ps2 = new PathStorage();

                double x = 0;
                double y = 0;

                ps2.MoveTo(100 + 32, 100 + 77);
                ps2.LineTo(100 + 473, 100 + 263);
                ps2.LineTo(100 + 351, 100 + 290);
                ps2.LineTo(100 + 354, 100 + 374);

                pathToUse = ps2;
            }
            break;

            case 2:
            {
                // circle holes
                PathStorage ps1 = new PathStorage();

                double x = 0;
                double y = 0;
                ps1.MoveTo(x + 140, y + 145);
                ps1.LineTo(x + 225, y + 44);
                ps1.LineTo(x + 296, y + 219);
                ps1.ClosePolygon();

                ps1.LineTo(x + 226, y + 289);
                ps1.LineTo(x + 82, y + 292);
                ps1.ClosePolygon();

                ps1.MoveTo(x + 220 - 50, y + 222);
                ps1.LineTo(x + 265 - 50, y + 331);
                ps1.LineTo(x + 363 - 50, y + 249);
                ps1.ClosePolygon();

                pathToUse = ps1;
            }
            break;

            case 3:     // Great Britain
            {
                PathStorage gb_poly = new PathStorage();
                GreatBritanPathStorage.Make(gb_poly);

                Affine mtx1 = Affine.NewIdentity();
                Affine mtx2 = Affine.NewIdentity();
                mtx1 *= Affine.NewTranslation(-1150, -1150);
                mtx1 *= Affine.NewScaling(2.0);

                mtx2  = mtx1;
                mtx2 *= Affine.NewTranslation(Width / 2, Height / 2);

                VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);

                pathToUse = trans_gb_poly;
            }
            break;

            case 4:     // Arrows
            {
                PathStorage arrows = new PathStorage();
                make_arrows(arrows);

                Affine mtx1 = Affine.NewIdentity();
                mtx1 *= Affine.NewTranslation(-1150, -1150);
                mtx1 *= Affine.NewScaling(2.0);

                VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx1);

                pathToUse = trans_arrows;
            }
            break;

            case 5:     // Spiral
            {
                spiral sp     = new spiral(Width / 2, Height / 2, 10, 150, 30, 0.0);
                Stroke stroke = new Stroke(sp);
                stroke.width(15.0);

                Affine mtx = Affine.NewIdentity();;
                mtx *= Affine.NewTranslation(-1150, -1150);
                mtx *= Affine.NewScaling(2.0);

                pathToUse = stroke;
            }
            break;

            case 6:     // Glyph
            {
                //------------------------------------
                // Spiral and glyph
                //
                PathStorage glyph = new PathStorage();
                glyph.MoveTo(28.47, 6.45);
                glyph.curve3(21.58, 1.12, 19.82, 0.29);
                glyph.curve3(17.19, -0.93, 14.21, -0.93);
                glyph.curve3(9.57, -0.93, 6.57, 2.25);
                glyph.curve3(3.56, 5.42, 3.56, 10.60);
                glyph.curve3(3.56, 13.87, 5.03, 16.26);
                glyph.curve3(7.03, 19.58, 11.99, 22.51);
                glyph.curve3(16.94, 25.44, 28.47, 29.64);
                glyph.LineTo(28.47, 31.40);
                glyph.curve3(28.47, 38.09, 26.34, 40.58);
                glyph.curve3(24.22, 43.07, 20.17, 43.07);
                glyph.curve3(17.09, 43.07, 15.28, 41.41);
                glyph.curve3(13.43, 39.75, 13.43, 37.60);
                glyph.LineTo(13.53, 34.77);
                glyph.curve3(13.53, 32.52, 12.38, 31.30);
                glyph.curve3(11.23, 30.08, 9.38, 30.08);
                glyph.curve3(7.57, 30.08, 6.42, 31.35);
                glyph.curve3(5.27, 32.62, 5.27, 34.81);
                glyph.curve3(5.27, 39.01, 9.57, 42.53);
                glyph.curve3(13.87, 46.04, 21.63, 46.04);
                glyph.curve3(27.59, 46.04, 31.40, 44.04);
                glyph.curve3(34.28, 42.53, 35.64, 39.31);
                glyph.curve3(36.52, 37.21, 36.52, 30.71);
                glyph.LineTo(36.52, 15.53);
                glyph.curve3(36.52, 9.13, 36.77, 7.69);
                glyph.curve3(37.01, 6.25, 37.57, 5.76);
                glyph.curve3(38.13, 5.27, 38.87, 5.27);
                glyph.curve3(39.65, 5.27, 40.23, 5.62);
                glyph.curve3(41.26, 6.25, 44.19, 9.18);
                glyph.LineTo(44.19, 6.45);
                glyph.curve3(38.72, -0.88, 33.74, -0.88);
                glyph.curve3(31.35, -0.88, 29.93, 0.78);
                glyph.curve3(28.52, 2.44, 28.47, 6.45);
                glyph.ClosePolygon();

                glyph.MoveTo(28.47, 9.62);
                glyph.LineTo(28.47, 26.66);
                glyph.curve3(21.09, 23.73, 18.95, 22.51);
                glyph.curve3(15.09, 20.36, 13.43, 18.02);
                glyph.curve3(11.77, 15.67, 11.77, 12.89);
                glyph.curve3(11.77, 9.38, 13.87, 7.06);
                glyph.curve3(15.97, 4.74, 18.70, 4.74);
                glyph.curve3(22.41, 4.74, 28.47, 9.62);
                glyph.ClosePolygon();

                Affine mtx = Affine.NewIdentity();
                mtx *= Affine.NewScaling(4.0);
                mtx *= Affine.NewTranslation(220, 200);
                VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
                FlattenCurves curve = new FlattenCurves(trans);

                pathToUse = curve;
            }
            break;
            }

            graphics2D.Render(pathToUse, fillColor);

            PathStorage travelLine = new PathStorage();

            travelLine.MoveTo(lineStart);
            travelLine.LineTo(mousePosition);

            Polygons polygonsToPathAround = VertexSourceToClipperPolygons.CreatePolygons(pathToUse, 1);

            polygonsToPathAround = FixWinding(polygonsToPathAround);

            Polygons travelPolysLine = VertexSourceToClipperPolygons.CreatePolygons(travelLine, 1);

            CreateAndRenderPathing(graphics2D, polygonsToPathAround, travelPolysLine);
        }
        private static void PrintLineEnd(GCodeSketch turtle, bool drawGlyphs, int i, Vector2 currentPos, bool lift = false)
        {
            var originalSpeed = turtle.Speed;

            turtle.Speed = Math.Min(700, turtle.Speed);

            if (drawGlyphs && CalibrationLine.Glyphs.TryGetValue(i, out IVertexSource vertexSource))
            {
                turtle.WriteRaw("; LineEnd Marker");
                var flattened = new FlattenCurves(vertexSource);

                var verticies = flattened.Vertices();
                var firstItem = verticies.First();
                var position  = turtle.CurrentPosition;

                var scale = 0.3;

                if (firstItem.command != ShapePath.FlagsAndCommand.MoveTo)
                {
                    if (lift)
                    {
                        turtle.PenUp();
                    }

                    turtle.MoveTo((firstItem.position * scale) + currentPos);
                }

                bool closed = false;

                foreach (var item in verticies)
                {
                    switch (item.command)
                    {
                    case ShapePath.FlagsAndCommand.MoveTo:
                        if (lift)
                        {
                            turtle.PenUp();
                        }

                        turtle.MoveTo((item.position * scale) + currentPos);

                        if (lift)
                        {
                            turtle.PenDown();
                        }
                        break;

                    case ShapePath.FlagsAndCommand.LineTo:
                        turtle.LineTo((item.position * scale) + currentPos);
                        break;

                    case ShapePath.FlagsAndCommand.FlagClose:
                        turtle.LineTo((firstItem.position * scale) + currentPos);
                        closed = true;
                        break;
                    }
                }

                bool atStartingPosition = position.Equals(turtle.CurrentPosition, .1);

                if (!closed &&
                    !atStartingPosition)
                {
                    turtle.LineTo((firstItem.position * scale) + currentPos);
                    atStartingPosition = position.Equals(turtle.CurrentPosition, .1);
                }

                // Restore original speed
                turtle.Speed = originalSpeed;

                if (!atStartingPosition)
                {
                    // Return to original position
                    turtle.PenUp();
                    turtle.MoveTo(currentPos);
                    turtle.PenDown();
                }
            }
        }