コード例 #1
0
        /// <summary>
        /// Creates polygon from the texture.
        /// </summary>
        /// <returns>Returns created polygon as <see cref="ShapeState"/> or null when unsuccessful.</returns>
        public ShapeState CreatePolygonFromTexture()
        {
            // texture data
            uint[] data = new uint[textureScreen.Texture.TextureXna.Width * textureScreen.Texture.TextureXna.Height];
            textureScreen.Texture.TextureXna.GetData(data);

            // compute vertices from texture
            Vertices textureVertices;

            try
            {
                textureVertices = PolygonTools.CreatePolygon(data, textureScreen.Texture.TextureXna.Width, true);
            }
            catch
            {
                Messages.ShowError("Unable to convert texture to polygon.");
                return(null);
            }

            // no polygon
            if (textureVertices.Count < 3)
            {
                Messages.ShowError("Result polygon would have less then 3 vertices.");
                return(null);
            }
            // polygon is not simple
            else if (!textureVertices.IsSimple())
            {
                Messages.ShowError("Result polygon would have crossing edges. Probably texture cointains separate regions.");
                return(null);
            }
            // polygon is correct => move polygon to correct position
            else
            {
                for (int i = 0; i < textureVertices.Count; ++i)
                {
                    textureVertices[i] -= textureScreen.Texture.Origin;
                }
            }

            return(textureScreen.AddShape(new Polygon(textureVertices)));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextureForm"/> class.
        /// </summary>
        /// <param name="texture">The texture to edit.</param>
        public TextureForm(Texture texture)
        {
            InitializeComponent();

            Icon = Properties.Resources._2DPGC_Logo;

            // messages manager
            messagesManager          = new DefaultMessagesManager(statusLabel);
            Messages.MessagesManager = messagesManager;

            // texture
            this.texture = texture;

            // init controls settings
            nameTextBox.Text = texture.Name;

            // texture screen
            textureScreen         = new TextureScreen();
            textureScreen.Texture = texture;
            textureScreen.Dock    = DockStyle.Fill;
            tableLayoutPanel.Controls.Add(textureScreen, 0, 0);
            textureScreen.Zoom     = 100;
            textureScreen.Position = new PointF(-textureScreen.Width / 2f, -textureScreen.Height / 2f);

            // shapes controller
            shapesController          = new TextureControllerForShapesEditing(textureScreen);
            shapesController.Location = new Point(3, 81);
            textureSettingsPanel.Controls.Add(shapesController);

            // title (window text)
            UpdateTitle();

            // init shapes from texture
            foreach (Shape shape in texture.Shapes)
            {
                ShapeState newItem = textureScreen.AddShape(shape);
                shapesController.ShapesList.Items.Add(newItem);
            }
            shapesController.ShapesList.SelectedIndex = shapesController.ShapesList.Items.Count - 1;
        }