コード例 #1
0
ファイル: TypeFace.cs プロジェクト: ruicraveiro87/agg-sharp
            public ClosedLoopGlyphData(VertexStorage source)
            {
                storage = new VertexStorage();

                var vertexData = source.Vertices().Where(v => v.command != ShapePath.FlagsAndCommand.FlagNone).ToArray();

                VertexData previous = default(VertexData);

                for (var i = 0; i < vertexData.Length; i++)
                {
                    var current = vertexData[i];

                    // All MoveTo operations should be preceded by ClosePolygon
                    if (i > 0 &&
                        current.IsMoveTo &&
                        ShapePath.is_vertex(previous.command))
                    {
                        storage.ClosePolygon();
                    }

                    // Add original VertexData
                    storage.Add(current.position.X, current.position.Y, current.command);

                    // Hold prior item
                    previous = current;
                }

                // Ensure closed
                storage.ClosePolygon();
            }
コード例 #2
0
        public void ThreeItemPolygonCountTest()
        {
            var storage = new VertexStorage();

            // Square
            storage.MoveTo(0, 0);
            storage.LineTo(100, 0);
            storage.LineTo(100, 100);
            storage.LineTo(0, 100);
            storage.ClosePolygon();

            // Triangle
            storage.MoveTo(30, 30);
            storage.LineTo(40, 30);
            storage.LineTo(35, 40);
            storage.ClosePolygon();

            // Small Square
            storage.MoveTo(20, 20);
            storage.LineTo(25, 20);
            storage.LineTo(25, 25);
            storage.LineTo(20, 25);
            storage.ClosePolygon();

            var polygons = storage.CreatePolygons();

            //var image = new ImageBuffer(200, 200);
            //var graphics = image.NewGraphics2D();
            //graphics.Render(new Stroke(storage), Color.Blue);
            //ImageTgaIO.Save(image, @"c:\temp\some.tga");

            Assert.AreEqual(3, polygons.Count, "Three polygons should be create for a two squares and a triangle");
        }
コード例 #3
0
        static public int parse_lion(VertexStorage path, Color[] colors, int[] path_idx)
        {
            // Parse the lion and then detect its bounding
            // box and arrange polygons orientations (make all polygons
            // oriented clockwise or counterclockwise)

            int npaths = 0;

            string[] splitOnNL = g_lion.Split('\n');
            foreach (string LineString in splitOnNL)
            {
                int c;
                if (LineString.Length > 0 &&
                    LineString[0] != 'M' &&
                    Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c))
                {
                    // New color. Every new color creates new path in the path object.
                    path.ClosePolygon();
                    colors[npaths]   = Color.rgb8_packed((int)c);
                    path_idx[npaths] = path.start_new_path();
                    npaths++;
                }
                else
                {
                    bool     startedPoly  = false;
                    string[] splitOnSpace = LineString.Split(' ');
                    for (int i = 0; i < splitOnSpace.Length; i++)
                    {
                        string[] splitOnComma = splitOnSpace[i].Split(',');
                        if (splitOnComma.Length > 1)
                        {
                            double x = 0.0;
                            double y = 0.0;
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);

                            if (!startedPoly)
                            {
                                startedPoly = true;
                                path.ClosePolygon();
                                path.MoveTo(x, y);
                            }
                            else
                            {
                                path.LineTo(x, y);
                            }
                        }
                    }
                }
            }

            path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW);
            return(npaths);
        }
コード例 #4
0
        public static VertexStorage CreateVertexStorage(this Polygons polygons, double scaling = 1000)
        {
            var output = new VertexStorage();

            foreach (Polygon polygon in polygons)
            {
                bool first = true;

                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X / scaling, point.Y / scaling, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }

            return(output);
        }
コード例 #5
0
        public static VertexStorage PolygonToPathStorage(this Polygons polygons)
        {
            VertexStorage output = new VertexStorage();

            foreach (Polygon polygon in polygons)
            {
                bool first = true;
                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }
            output.Add(0, 0, ShapePath.FlagsAndCommand.Stop);

            return(output);
        }
コード例 #6
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL();

            double snappingRadians = MathHelper.Tau / numSnapPoints;
            var    clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World);

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                VertexStorage snapShape = new VertexStorage();
                snapShape.MoveTo(-10, 0);
                snapShape.LineTo(5, 7);
                snapShape.LineTo(5, -7);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = Color.Black;
                if (i == markToSnapTo)
                {
                    color = Color.Red;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
コード例 #7
0
        public static VertexStorage CreatePathStorage(List <List <IntPoint> > polygons)
        {
            VertexStorage output = new VertexStorage();

            foreach (List <IntPoint> polygon in polygons)
            {
                bool first = true;
                foreach (IntPoint point in polygon)
                {
                    if (first)
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.MoveTo);
                        first = false;
                    }
                    else
                    {
                        output.Add(point.X, point.Y, ShapePath.FlagsAndCommand.LineTo);
                    }
                }

                output.ClosePolygon();
            }

            return(output);
        }
コード例 #8
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);

            double snappingRadians = MathHelper.Tau / numSnapPoints;

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                var snapShape = new VertexStorage();
                var scale     = GuiWidget.DeviceScale;
                snapShape.MoveTo(-10 * scale, 0);
                snapShape.LineTo(5 * scale, 7 * scale);
                snapShape.LineTo(5 * scale, -7 * scale);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = theme.TextColor;
                if (i == markToSnapTo)
                {
                    color = theme.PrimaryAccentColor;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
コード例 #9
0
ファイル: SimpleTests.cs プロジェクト: larsbrubaker/agg-sharp
        public void JsonSerializeVertexStorage()
        {
            var test1Control = new VertexStorage();

            test1Control.MoveTo(10, 11);
            test1Control.LineTo(100, 11);
            test1Control.LineTo(100, 110);
            test1Control.ClosePolygon();
            string jsonData    = JsonConvert.SerializeObject(test1Control);
            var    test1Result = JsonConvert.DeserializeObject <VertexStorage>(jsonData);

            Assert.AreEqual(test1Control.Count, test1Result.Count);

            var control = test1Control.Vertices().GetEnumerator();
            var result  = test1Result.Vertices().GetEnumerator();

            for (int i = 0; i < test1Control.Count; i++)
            {
                control.MoveNext();
                result.MoveNext();
                var controlVertex = control.Current;
                var resultVertex  = result.Current;
                Assert.AreEqual(controlVertex.command, resultVertex.command);
                Assert.AreEqual(controlVertex.position, resultVertex.position);
            }
        }
コード例 #10
0
        private void make_arrows(VertexStorage ps)
        {
            ps.remove_all();

            ps.MoveTo(1330.599999999999909, 1282.399999999999864);
            ps.LineTo(1377.400000000000091, 1282.399999999999864);
            ps.LineTo(1361.799999999999955, 1298.000000000000000);
            ps.LineTo(1393.000000000000000, 1313.599999999999909);
            ps.LineTo(1361.799999999999955, 1344.799999999999955);
            ps.LineTo(1346.200000000000045, 1313.599999999999909);
            ps.LineTo(1330.599999999999909, 1329.200000000000045);
            ps.ClosePolygon();

            ps.MoveTo(1330.599999999999909, 1266.799999999999955);
            ps.LineTo(1377.400000000000091, 1266.799999999999955);
            ps.LineTo(1361.799999999999955, 1251.200000000000045);
            ps.LineTo(1393.000000000000000, 1235.599999999999909);
            ps.LineTo(1361.799999999999955, 1204.399999999999864);
            ps.LineTo(1346.200000000000045, 1235.599999999999909);
            ps.LineTo(1330.599999999999909, 1220.000000000000000);
            ps.ClosePolygon();

            ps.MoveTo(1315.000000000000000, 1282.399999999999864);
            ps.LineTo(1315.000000000000000, 1329.200000000000045);
            ps.LineTo(1299.400000000000091, 1313.599999999999909);
            ps.LineTo(1283.799999999999955, 1344.799999999999955);
            ps.LineTo(1252.599999999999909, 1313.599999999999909);
            ps.LineTo(1283.799999999999955, 1298.000000000000000);
            ps.LineTo(1268.200000000000045, 1282.399999999999864);
            ps.ClosePolygon();

            ps.MoveTo(1268.200000000000045, 1266.799999999999955);
            ps.LineTo(1315.000000000000000, 1266.799999999999955);
            ps.LineTo(1315.000000000000000, 1220.000000000000000);
            ps.LineTo(1299.400000000000091, 1235.599999999999909);
            ps.LineTo(1283.799999999999955, 1204.399999999999864);
            ps.LineTo(1252.599999999999909, 1235.599999999999909);
            ps.LineTo(1283.799999999999955, 1251.200000000000045);
            ps.ClosePolygon();
        }
コード例 #11
0
        public void CubePolygonCountTest()
        {
            var square = new VertexStorage();

            square.MoveTo(0, 0);
            square.LineTo(100, 0);
            square.LineTo(100, 100);
            square.LineTo(0, 100);
            square.ClosePolygon();

            var polygons = square.CreatePolygons();

            Assert.AreEqual(1, polygons.Count, "One polygon should be created for a simple 4 point cube path");
        }
コード例 #12
0
        public void MoveToCreatesAdditionalPolygonTest()
        {
            // Any MoveTo should always create a new Polygon
            var storage = new VertexStorage();

            storage.MoveTo(0, 0);
            storage.LineTo(100, 0);
            storage.LineTo(100, 100);
            storage.MoveTo(30, 30);
            storage.LineTo(0, 100);
            storage.ClosePolygon();

            var polygons = storage.CreatePolygons();

            Assert.AreEqual(2, polygons.Count, "Two polygons should be created for a path with a floating MoveTo command");
        }
コード例 #13
0
        public void TwoItemPolygonCountTest()
        {
            var square = new VertexStorage();

            square.MoveTo(0, 0);
            square.LineTo(100, 0);
            square.LineTo(100, 100);
            square.LineTo(0, 100);
            square.ClosePolygon();

            var result = square.CombineWith(new Ellipse(Vector2.Zero, 10));

            var polygons = result.CreatePolygons();

            Assert.AreEqual(2, polygons.Count, "Two polygons should be create for a combined square and ellipse");
        }
コード例 #14
0
        private void DrawImageGetDestBounds(IImageByte sourceImage,
                                            double destX,
                                            double destY,
                                            double hotspotOffsetX,
                                            double hotspotOffsetY,
                                            double scaleX,
                                            double scaleY,
                                            double angleRad,
                                            out Affine destRectTransform)
        {
            destRectTransform = Affine.NewIdentity();

            if (hotspotOffsetX != 0.0f || hotspotOffsetY != 0.0f)
            {
                destRectTransform *= Affine.NewTranslation(-hotspotOffsetX, -hotspotOffsetY);
            }

            if (scaleX != 1 || scaleY != 1)
            {
                destRectTransform *= Affine.NewScaling(scaleX, scaleY);
            }

            if (angleRad != 0)
            {
                destRectTransform *= Affine.NewRotation(angleRad);
            }

            if (destX != 0 || destY != 0)
            {
                destRectTransform *= Affine.NewTranslation(destX, destY);
            }

            int sourceBufferWidth  = (int)sourceImage.Width;
            int sourceBufferHeight = (int)sourceImage.Height;

            drawImageRectPath.remove_all();

            drawImageRectPath.MoveTo(0, 0);
            drawImageRectPath.LineTo(sourceBufferWidth, 0);
            drawImageRectPath.LineTo(sourceBufferWidth, sourceBufferHeight);
            drawImageRectPath.LineTo(0, sourceBufferHeight);
            drawImageRectPath.ClosePolygon();
        }
コード例 #15
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                double pointsToMm = 0.352778;

                var printer = new TypeFacePrinter(Text.Value(this), new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize.Value(this)))
                {
                    ResolutionScale = 10
                };

                var scaledLetterPrinter = new VertexSourceApplyTransform(printer, Affine.NewScaling(pointsToMm));
                var vertexSource        = new VertexStorage();

                foreach (var vertex in scaledLetterPrinter.Vertices())
                {
                    if (vertex.IsMoveTo)
                    {
                        vertexSource.MoveTo(vertex.position);
                    }
                    else if (vertex.IsLineTo)
                    {
                        vertexSource.LineTo(vertex.position);
                    }
                    else if (vertex.IsClose)
                    {
                        vertexSource.ClosePolygon();
                    }
                }

                vertexSource = (VertexStorage)vertexSource.Union(vertexSource);

                this.VertexSource = vertexSource;

                // set the mesh to show the path
                this.Mesh = this.VertexSource.Extrude(Constants.PathPolygonsHeight);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Path));
            return(Task.CompletedTask);
        }
コード例 #16
0
        private void DrawImageGetDestBounds(IImageByte sourceImage,
                                            double DestX, double DestY,
                                            double HotspotOffsetX, double HotspotOffsetY,
                                            double ScaleX, double ScaleY,
                                            double AngleRad, out Affine destRectTransform)
        {
            destRectTransform = Affine.NewIdentity();

            if (HotspotOffsetX != 0.0f || HotspotOffsetY != 0.0f)
            {
                destRectTransform *= Affine.NewTranslation(-HotspotOffsetX, -HotspotOffsetY);
            }

            if (ScaleX != 1 || ScaleY != 1)
            {
                destRectTransform *= Affine.NewScaling(ScaleX, ScaleY);
            }

            if (AngleRad != 0)
            {
                destRectTransform *= Affine.NewRotation(AngleRad);
            }

            if (DestX != 0 || DestY != 0)
            {
                destRectTransform *= Affine.NewTranslation(DestX, DestY);
            }

            int SourceBufferWidth  = (int)sourceImage.Width;
            int SourceBufferHeight = (int)sourceImage.Height;

            drawImageRectPath.remove_all();

            drawImageRectPath.MoveTo(0, 0);
            drawImageRectPath.LineTo(SourceBufferWidth, 0);
            drawImageRectPath.LineTo(SourceBufferWidth, SourceBufferHeight);
            drawImageRectPath.LineTo(0, SourceBufferHeight);
            drawImageRectPath.ClosePolygon();
        }
コード例 #17
0
        override public Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                double pointsToMm = 0.352778;

                var printer = new TypeFacePrinter(Text, new StyledTypeFace(ApplicationController.GetTypeFace(Font), PointSize))
                {
                    ResolutionScale = 10
                };

                var scaledLetterPrinter = new VertexSourceApplyTransform(printer, Affine.NewScaling(pointsToMm));
                var vertexSource        = new VertexStorage();

                foreach (var vertex in scaledLetterPrinter.Vertices())
                {
                    if (vertex.IsMoveTo)
                    {
                        vertexSource.MoveTo(vertex.position);
                    }
                    else if (vertex.IsLineTo)
                    {
                        vertexSource.LineTo(vertex.position);
                    }
                    else if (vertex.IsClose)
                    {
                        vertexSource.ClosePolygon();
                    }
                }

                this.VertexSource = vertexSource;
                base.Mesh         = null;
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Path));
            return(Task.CompletedTask);
        }
コード例 #18
0
        private void ProcTree(XElement g)
        {
            foreach (var elem in g.Elements())
            {
                switch (elem.Name.LocalName)
                {
                case "path":
                case "polygon":

                    string htmlColor = ((string)elem.Attribute("style"))?.Replace("fill:", "").Replace(";", "") ?? "#999";

                    if (elem.Name.LocalName == "polygon")
                    {
                        var path = new VertexStorage();

                        string pointsLine = ((string)elem.Attribute("points"))?.Trim();

                        var segments = pointsLine.Split(' ');

                        bool firstMove = true;
                        foreach (var segment in segments)
                        {
                            var point = segment.Split(',');

                            if (firstMove)
                            {
                                path.MoveTo(new Vector2(double.Parse(point[0]), double.Parse(point[1])));
                                firstMove = false;
                            }
                            else
                            {
                                path.LineTo(new Vector2(double.Parse(point[0]), double.Parse(point[1])));
                            }
                        }

                        path.ClosePolygon();

                        items.Add(new ColoredVertexSource()
                        {
                            VertexSource = path,
                            Color        = new Color(htmlColor)
                        });
                    }
                    else
                    {
                        string dString = (string)elem.Attribute("d");
                        items.Add(new ColoredVertexSource()
                        {
                            VertexSource = new VertexStorage(dString),
                            Color        = new Color(htmlColor)
                        });
                    }

                    break;

                case "g":
                    ProcTree(elem);
                    break;
                }
            }
        }
コード例 #19
0
        private void render_gpc(Graphics2D graphics2D)
        {
            switch (m_polygons.SelectedIndex)
            {
            case 0:
            {
                //------------------------------------
                // Two simple paths
                //
                VertexStorage ps1 = new VertexStorage();
                VertexStorage ps2 = new VertexStorage();

                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 ColorF(0, 0, 0, 0.1).ToColor());
                graphics2D.Render(ps2, new ColorF(0, 0.6, 0, 0.1).ToColor());

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

            case 1:
            {
                //------------------------------------
                // Closed stroke
                //
                VertexStorage ps1    = new VertexStorage();
                VertexStorage ps2    = new VertexStorage();
                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 ColorF(0, 0, 0, 0.1).ToColor());
                graphics2D.Render(stroke, new ColorF(0, 0.6, 0, 0.1).ToColor());

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

            case 2:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                VertexStorage gb_poly = new VertexStorage();
                VertexStorage arrows  = new VertexStorage();
                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 ColorF(0.5, 0.5, 0, 0.1).ToColor());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.Width = 0.1;
                graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor());

                graphics2D.Render(trans_arrows, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor());

                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);

                VertexStorage gb_poly = new VertexStorage();
                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 ColorF(0.5, 0.5, 0, 0.1).ToColor());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor());

                graphics2D.Render(stroke, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor());

                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);

                VertexStorage glyph = new VertexStorage();
                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 ColorF(0, 0, 0, 0.1).ToColor());

                graphics2D.Render(curve, new ColorF(0, 0.6, 0, 0.1).ToColor());
            }
            break;
            }
        }
コード例 #20
0
        public CalibrationTabWidget(XyCalibrationWizard calibrationWizard, TextButton nextButton, ThemeConfig theme)
        {
            this.calibrationWizard = calibrationWizard;
            this.theme             = theme;
            this.NextButton        = nextButton;
            tabBaseColor           = new Color(theme.SlightShade.ToColorF(), theme.SlightShade.Alpha0To1 * 1.2);

            double barWidth  = 30;
            double barHeight = 300;

            double left   = LocalBounds.Left + 15;
            double bottom = LocalBounds.Bottom + 15;
            double right  = left + barHeight;

            var a = new Vector2(left, bottom);
            var b = new Vector2(left, bottom + barHeight);
            var c = new Vector2(left + barWidth, bottom + barHeight);
            var d = new Vector2(left + barWidth, bottom + barWidth);
            var e = new Vector2(right, bottom + barWidth);
            var f = new Vector2(right + (barWidth * .7), bottom + (barWidth / 2));
            var g = new Vector2(right, bottom);

            var m = new Vector2(b.X + (barWidth / 2), b.Y + (barWidth * .6));
            var n = new Vector2(m.X, b.Y);
            var r = new Vector2(b.X, m.Y);

            var tabShape2 = new VertexStorage();

            tabShape2.Add(a.X, a.Y, FlagsAndCommand.MoveTo); // A
            tabShape2.LineTo(b);                             // A - B

            tabShape2.curve3(r.X, r.Y, m.X, m.Y);            // B -> C
            tabShape2.curve3(c.X, c.Y);

            tabShape2.LineTo(d);             // C -> D
            tabShape2.LineTo(e);             // D -> E
            tabShape2.LineTo(f);             // E -> F
            tabShape2.LineTo(g);             // F -> G
            tabShape2.ClosePolygon();

            int highlightStroke = 2;
            int highlightOffset = 8;
            int highlightWidth  = 16;

            double x1 = d.X + highlightOffset;
            double x2 = x1 + highlightWidth;
            double y1 = d.Y + highlightOffset;
            double y2 = c.Y - highlightOffset;

            double midY = y1 + (y2 - y1) / 2;

            var highlighter = new VertexStorage();

            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x2, y1);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2 + highlightOffset, midY);
            highlighter.LineTo(x2, midY);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x1, y2);

            xHighlighter = new Stroke(highlighter, highlightStroke);

            xLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute
            };

            xLabel.Position = new Vector2(x2 + highlightOffset * 2, midY - xLabel.Height / 2);

            this.AddChild(xLabel);

            x1 = d.X + highlightOffset;
            y1 = d.Y + 50;

            x1 = d.X + highlightOffset;
            x2 = e.X - highlightOffset;
            y1 = d.Y + highlightOffset;
            y2 = y1 + highlightWidth;

            double midX = x1 + (x2 - x1) / 2;

            highlighter = new VertexStorage();
            highlighter.MoveTo(x1, y1);
            highlighter.LineTo(x1, y2);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(midX, y2 + highlightOffset);
            highlighter.LineTo(midX, y2);
            highlighter.LineTo(x2, y2);
            highlighter.LineTo(x2, y1);

            yHighlighter = new Stroke(highlighter, highlightStroke);

            yLabel = new TextWidget("Select the most centered pad", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                HAnchor = HAnchor.Absolute,
                VAnchor = VAnchor.Absolute,
                Visible = false,
            };
            this.AddChild(yLabel);

            yLabel.Position = new Vector2(midX - yLabel.Width / 2, y2 + (highlightOffset * 2));

            yHighlighter = new Stroke(highlighter, highlightStroke);

            int padCount = 7;

            double cellSize = (barHeight - barWidth) / padCount;
            int    padding  = (int)(cellSize * .3);

            double padSize = cellSize - padding;

            var titles = new[] { "-3", "-2", "-1", "0", "+1", "+2", "+3" };

            for (var i = 0; i < padCount; i++)
            {
                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left, bottom + 3 + barWidth + (cellSize * i)),
                    Height   = padSize,
                    Width    = barWidth,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.X
                });

                this.AddChild(new CalibrationPad(titles[i], theme, pointSize: theme.DefaultFontSize - 1)
                {
                    Position = new Vector2(left + 3 + barWidth + (cellSize * i), bottom),
                    Height   = barWidth,
                    Width    = padSize,
                    Index    = i,
                    IsActive = i == 3,
                    Axis     = PrinterConnection.Axis.Y
                });
            }

            foreach (var calibrationPad in this.Children.OfType <CalibrationPad>())
            {
                calibrationPad.Click   += this.CalibrationPad_Click;
                calibrationPad.Hovered += this.CalibrationPad_Hovered;
            }

            tabShape  = new FlattenCurves(tabShape2);
            tabStroke = new Stroke(tabShape);
        }
コード例 #21
0
        private void GenerateToolLimitsTexture(PrinterConfig printer, int toolIndex, ImageBuffer bedplateImage)
        {
            var xScale = bedplateImage.Width / printer.Settings.BedBounds.Width;
            var yScale = bedplateImage.Height / printer.Settings.BedBounds.Height;

            int alpha = 80;

            var graphics = bedplateImage.NewGraphics2D();

            RectangleDouble toolBounds;

            if (toolIndex == 2)
            {
                var tool0Bounds = printer.Settings.ToolBounds[0];
                var tool1Bounds = printer.Settings.ToolBounds[1];

                tool0Bounds.IntersectWithRectangle(tool1Bounds);

                toolBounds = tool0Bounds;
            }
            else
            {
                toolBounds = printer.Settings.ToolBounds[toolIndex];
            }

            // move relative to the texture origin, move to the bed lower left position
            var bedBounds = printer.Settings.BedBounds;

            toolBounds.Offset(-bedBounds.Left, -bedBounds.Bottom);

            // Scale toolBounds into textures units
            toolBounds = new RectangleDouble(
                toolBounds.Left * xScale,
                toolBounds.Bottom * yScale,
                toolBounds.Right * xScale,
                toolBounds.Top * yScale);

            var imageBounds = bedplateImage.GetBounds();

            var dimRegion = new VertexStorage();

            dimRegion.MoveTo(imageBounds.Left, imageBounds.Bottom);
            dimRegion.LineTo(imageBounds.Right, imageBounds.Bottom);
            dimRegion.LineTo(imageBounds.Right, imageBounds.Top);
            dimRegion.LineTo(imageBounds.Left, imageBounds.Top);

            var targetRect = new VertexStorage();

            targetRect.MoveTo(toolBounds.Right, toolBounds.Bottom);
            targetRect.LineTo(toolBounds.Left, toolBounds.Bottom);
            targetRect.LineTo(toolBounds.Left, toolBounds.Top);
            targetRect.LineTo(toolBounds.Right, toolBounds.Top);
            targetRect.ClosePolygon();

            var overlayMinusTargetRect = new CombinePaths(dimRegion, targetRect);

            graphics.Render(overlayMinusTargetRect, new Color(Color.Black, alpha));

            string toolTitle = string.Format("{0} {1}", "Tool ".Localize(), toolIndex + 1);

            if (toolIndex == 2)
            {
                toolTitle = "Tools ".Localize() + "1 & 2";
            }

            var stringPrinter = new TypeFacePrinter(toolTitle, theme.DefaultFontSize, bold: true);
            var printerBounds = stringPrinter.GetBounds();

            int textPadding = 8;

            var textBounds = printerBounds;

            textBounds.Inflate(textPadding);

            var cornerRect = new RectangleDouble(toolBounds.Right - textBounds.Width, toolBounds.Top - textBounds.Height, toolBounds.Right, toolBounds.Top);

            graphics.Render(
                new RoundedRectShape(cornerRect, bottomLeftRadius: 6),
                theme.PrimaryAccentColor);

            graphics.DrawString(
                toolTitle,
                toolBounds.Right - textPadding,
                cornerRect.Bottom + (cornerRect.Height / 2 - printerBounds.Height / 2) + 1,
                theme.DefaultFontSize,
                justification: Justification.Right,
                baseline: Baseline.Text,
                color: Color.White,
                bold: true);

            graphics.Render(new Stroke(targetRect, 1), theme.PrimaryAccentColor);
        }
コード例 #22
0
        public LibraryCollectionContainer()
        {
            this.ChildContainers = new List <ILibraryContainerLink>();
            this.Items           = new List <ILibraryItem>();
            this.Name            = "Library".Localize();

            var rootLibraryCollection = Datastore.Instance.dbSQLite.Table <PrintItemCollection>().Where(v => v.Name == "_library").Take(1).FirstOrDefault();

            if (rootLibraryCollection != null)
            {
                this.ChildContainers.Add(
                    new DynamicContainerLink(
                        () => "Local Library".Localize(),
                        StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                        StaticData.Instance.LoadIcon(Path.Combine("Library", "local_library_icon.png")),
                        () => new SqliteLibraryContainer(rootLibraryCollection.Id)));
            }

            this.ChildContainers.Add(
                new DynamicContainerLink(
                    () => "Calibration Parts".Localize(),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "calibration_library_icon.png")),
                    () => new CalibrationPartsContainer())
            {
                IsReadOnly = true
            });

            this.ChildContainers.Add(
                new DynamicContainerLink(
                    () => "Primitives".Localize(),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "primitives_library_icon.png")),
                    () => new PrimitivesContainer())
            {
                IsReadOnly = true
            });

            var forceAddQueue = false;

#if DEBUG
            forceAddQueue = true;
#endif
            // only add the queue if there are items in it
            var queueItems = QueueData.Instance.PrintItems.ToList();
            if (forceAddQueue || queueItems.Any())
            {
                this.ChildContainers.Add(
                    new DynamicContainerLink(
                        () => "Print Queue".Localize(),
                        StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                        StaticData.Instance.LoadIcon(Path.Combine("Library", "queue_icon.png")),
                        () => new PrintQueueContainer()));
            }

#if DEBUG
            this.ChildContainers.Add(
                new DynamicContainerLink(
                    () => "Pipe Works".Localize(),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                    null,
                    () => new PipeWorksContainer())
            {
                IsReadOnly = true
            });

            int index = 0;

            this.ChildContainers.Add(
                new DynamicContainerLink(
                    () => "Experimental".Localize(),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                    null,
                    () => new DynamicContainer()
            {
                Items = new List <ILibraryItem>()
                {
                    new GeneratorItem(
                        () => "Calibration Tab".Localize(),
                        async() => await XyCalibrationTabObject3D.Create())
                    {
                        DateCreated = new System.DateTime(index++)
                    },
                    new GeneratorItem(
                        () => "Calibration Face".Localize(),
                        async() => await XyCalibrationFaceObject3D.Create())
                    {
                        DateCreated = new System.DateTime(index++)
                    },
                    new GeneratorItem(
                        () => "Text2".Localize(),
                        async() => await TextPathObject3D.Create())
                    {
                        DateCreated = new System.DateTime(index++)
                    },
                    new GeneratorItem(
                        () => "Path".Localize(),
                        () =>
                    {
                        var storage = new VertexStorage();
                        storage.MoveTo(5, 5);
                        storage.LineTo(10, 5);
                        storage.LineTo(7.5, 10);
                        storage.ClosePolygon();

                        var path = new PathObject3D()
                        {
                            VertexSource = storage
                        };

                        return(Task.FromResult <IObject3D>(path));
                    })
                    {
                        DateCreated = new System.DateTime(index++)
                    },
                }
            })
            {
                IsReadOnly = true
            });
#endif
        }