Пример #1
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        protected override void Draw()
        {
            // Clear to the default control background color.
            Color backColor = new Color(BackColor.R, BackColor.G, BackColor.B);

            GraphicsDevice.Clear(backColor);

            if (OldWidth != ClientSize.Width || OldHeight != ClientSize.Height)
            {
                Matrix Projection      = Matrix.CreateOrthographicOffCenter(0, ClientSize.Width, ClientSize.Height, 0, 0, 1);
                Matrix HalfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

                PolygonEffect.Projection = HalfPixelOffset * Projection;

                OldWidth  = ClientSize.Width;
                OldHeight = ClientSize.Height;
            }

            g.Begin();

            if (EditOrigin && sprSource != null)
            {
                g.Draw(sprSource, new Vector2(0, 0), Color.White);
            }
            else
            {
                PolygonEffect.Texture = sprSource;
                PolygonEffect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.RasterizerState = RasterizerState.CullNone;

                foreach (Polygon ActivePolygon in ListPolygon)
                {
                    ActivePolygon.Draw(GraphicsDevice);
                }
            }

            //Draw selected polygons.
            PolygonEffect.Texture = sprRedTexture;
            PolygonEffect.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            foreach (Polygon ActivePolygon in ListSelectedPolygon)
            {
                ActivePolygon.Draw(GraphicsDevice);
            }

            DrawPolygons(g);

            if (SplittingPoint1 != SplittingPoint2)
            {
                DrawLine(g, SplittingPoint1, SplittingPoint2, Color.Black);
            }

            g.End();
        }
Пример #2
0
        public override void Draw(CustomSpriteBatch g, bool IsInEditMode)
        {
            foreach (Polygon ActivePolygon in ListPolygon)
            {
                ActivePolygon.Draw(g.GraphicsDevice);
            }

            if (IsInEditMode)
            {
                foreach (Polygon ActivePolygon in ListPolygon)
                {
                    for (int I = 0; I < ActivePolygon.ArrayIndex.Length; I += 3)
                    {
                        Vector2 Vertex1 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I]];
                        Vector2 Vertex2 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I + 1]];
                        Vector2 Vertex3 = ActivePolygon.ArrayVertex[ActivePolygon.ArrayIndex[I + 2]];

                        g.DrawLine(GameScreen.sprPixel, Vertex1, Vertex2, Color.Black, 1);
                        g.DrawLine(GameScreen.sprPixel, Vertex2, Vertex3, Color.Black, 1);
                        g.DrawLine(GameScreen.sprPixel, Vertex3, Vertex1, Color.Black, 1);
                    }
                }
            }
        }