コード例 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SelectTemplateDialog" /> class.
        /// </summary>
        // ReSharper disable once NotNullMemberIsNotInitialized
        public SelectTemplateDialog()
        {
            InitializeComponent();

            int index = 0;

            foreach (Tuple <Template, IImage> tuple in TemplateManager.Templates)
            {
                Image image;
                using (Stream stream = tuple.Item2.GetStream())
                {
                    image = Image.FromStream(stream);
                    if (image.Size != _thumbnailList.ImageSize)
                    {
                        Vector2 scale    = _thumbnailList.ImageSize.ToVector2() / image.Size.ToVector2();
                        float   minScale = Math.Min(scale.X, scale.Y);
                        Vector2 size     = minScale * image.Size.ToVector2();
                        Vector2 pos      = (_thumbnailList.ImageSize.ToVector2() - size) / 2;

                        Bitmap bit = new Bitmap(
                            _thumbnailList.ImageSize.Width,
                            _thumbnailList.ImageSize.Height,
                            PixelFormat.Format32bppArgb);

                        using (GdiPGraphics g = GdiPGraphics.FromImage(bit))
                        {
                            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            g.SmoothingMode     = SmoothingMode.AntiAlias;
                            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                            g.DrawImage(image, pos.X, pos.Y, size.X, size.Y);
                        }
                        image.Dispose();
                        image = bit;
                    }
                }

                _thumbnailList.Images.Add(image);

                // TODO Just temporary. need to add a name to Template
                ShapeTemplate shapeTemplate = tuple.Item1.ShapeTemplates.First().Value;
                string        name          = shapeTemplate.Name;
                int           sideCount     = shapeTemplate.VertexNames.Count;

                ListViewItem item = new ListViewItem(name, index++, GetGroup(sideCount))
                {
                    Tag = tuple.Item1
                };

                _templateList.Items.Add(item);
            }
        }
コード例 #2
0
ファイル: Shape.cs プロジェクト: billings7/EscherTilier
        /// <summary>
        ///     Initializes a new instance of the <see cref="Shape" /> class.
        /// </summary>
        /// <param name="template">The template to create the shape from.</param>
        /// <param name="vertexPositions">The positions of each vertex.</param>
        /// <exception cref="System.ArgumentNullException">
        ///     <paramref name="template" /> or <paramref name="vertexPositions" /> was <see langword="null" />
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">Wrong number of vertex positions given.</exception>
        public Shape([NotNull] ShapeTemplate template, [NotNull] IReadOnlyList <Vector2> vertexPositions)
        {
            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }
            if (vertexPositions == null)
            {
                throw new ArgumentNullException(nameof(vertexPositions));
            }
            if (vertexPositions.Count != template.VertexNames.Count)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(vertexPositions),
                          "Wrong number of vertex positions given.");
            }

            Template = template;

            Dictionary <string, Edge>   edgesByName    = new Dictionary <string, Edge>(StringComparer.InvariantCulture);
            Dictionary <string, Vertex> verticesByName = new Dictionary <string, Vertex>(StringComparer.InvariantCulture);

            Edge[]   edges    = new Edge[template.EdgeNames.Count];
            Vertex[] vertices = new Vertex[template.VertexNames.Count];

            Edge   firstEdge  = null;
            Vertex lastVertex = null;

            for (int i = 0; i < template.EdgeNames.Count; i++)
            {
                string  edgeName = template.EdgeNames[i];
                string  vertName = template.VertexNames[i];
                Vector2 vertLoc  = vertexPositions[i];

                Debug.Assert(edgeName != null, "edgeName != null");
                Debug.Assert(vertName != null, "vertName != null");

                Edge   edge = new Edge(edgeName, this);
                Vertex vert = new Vertex(vertName, this, vertLoc);

                edge.End = vert;
                vert.In  = edge;

                if (lastVertex == null)
                {
                    firstEdge = edge;
                }
                else
                {
                    edge.Start     = lastVertex;
                    lastVertex.Out = edge;
                }

                lastVertex = vert;

                edgesByName.Add(edgeName, edge);
                verticesByName.Add(vertName, vert);

                edges[i]    = edge;
                vertices[i] = vert;
            }
            Debug.Assert(firstEdge != null, "firstEdge != null");

            firstEdge.Start = lastVertex;
            lastVertex.Out  = firstEdge;

            _edgesByName    = edgesByName;
            _verticesByName = verticesByName;

            Vertices = vertices;
            Edges    = edges;

            IsClockwise =
                Edges.Sum(e => (e.End.Location.X - e.Start.Location.X) * (e.End.Location.Y + e.Start.Location.Y)) > 0;
        }
コード例 #3
0
ファイル: Shape.cs プロジェクト: billings7/EscherTilier
 /// <summary>
 ///     Initializes a new instance of the <see cref="Shape" /> class.
 /// </summary>
 /// <param name="template">The template to create the shape from.</param>
 /// <exception cref="System.ArgumentNullException"><paramref name="template" /> was <see langword="null" /></exception>
 public Shape([NotNull] ShapeTemplate template)
     : this(template, template.InitialVertices)
 {
 }