Beispiel #1
0
        public override void Draw(GameTime gameTime)
        {
            if (Texture != null)
            {
                //Lazy initializing
                if (SpriteBatch == null)
                {
                    SpriteBatch = new SpriteBatch(this.GraphicsDevice);
                }

                Matrix DrawMatrix = Matrix.CreateScale(Scale);

                SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, DrawMatrix);
                SpriteBatch.Draw(Texture, new Rectangle(-HorizontalSB.Value, -VerticalSB.Value, Texture.Width, Texture.Height), Color.White);

                for (int i = 0; i < BUFFER_SIZE; i++)
                {
                    if (Buffer[i].Region != Rectangle.Empty && i != CurrentBufferIndex)
                    {
                        Selection _sel = Buffer[i];
                        SelectionUtil.DrawRectangle(SpriteBatch, Color.Black * .4f, new Rectangle(_sel.Region.X - HorizontalSB.Value, _sel.Region.Y - VerticalSB.Value, _sel.Region.Width, _sel.Region.Height));
                        SelectionUtil.FillRectangle(SpriteBatch, Color.White * .2f, new Rectangle(_sel.Region.X + 1 - HorizontalSB.Value, _sel.Region.Y + 1 - VerticalSB.Value, _sel.Region.Width - 1, _sel.Region.Height - 1));
                    }
                }

                Selection sel = Buffer[CurrentBufferIndex];
                SelectionUtil.DrawRectangle(SpriteBatch, Color.Black * .7f, new Rectangle(sel.Region.X - HorizontalSB.Value, sel.Region.Y - VerticalSB.Value, sel.Region.Width, sel.Region.Height));
                SelectionUtil.FillRectangle(SpriteBatch, Color.White * .4f, new Rectangle(sel.Region.X + 1 - HorizontalSB.Value, sel.Region.Y + 1 - VerticalSB.Value, sel.Region.Width - 1, sel.Region.Height - 1));

                SpriteBatch.End();
            }
        }
Beispiel #2
0
        public override void Draw(GameTime gameTime)
        {
            if (SpriteBatch == null)
            {
                SpriteBatch = new SpriteBatch(GraphicsDevice);
            }

            if (Template != null && Template.Texture != null)
            {
                Rectangle dest = Template.Texture.GetSource(0);
                SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
                if (Mode == 0)                   /*Viewer*/
                {
                    SpriteBatch.Draw(Template.Texture.Texture, dest, Template.Texture.GetSource(0), Color.White);
                }
                else if (Mode == 1)                     /*Collisions*/
                {
                    SpriteBatch.Draw(Template.Texture.Texture, dest, Color.White);

                    Color col  = new Color(255, 75, 0, 255);
                    Color col2 = new Color(250, 35, 0, 255);
                    foreach (Rectangle rect in Template.CollisionMap)
                    {
                        Rectangle w1 = new Rectangle(rect.X * 16, rect.Y * 16, rect.Width * 16, rect.Height * 16);
                        Rectangle w2 = new Rectangle(rect.X * 16 + 1, rect.Y * 16 + 1, rect.Width * 16 - 1, rect.Height * 16 - 1);

                        SelectionUtil.DrawRectangle(SpriteBatch, col * .7f, w1);
                        SelectionUtil.FillRectangle(SpriteBatch, col2 * .3f, w2);
                    }

                    Rectangle ww = new Rectangle(selection.Region.X * 16, selection.Region.Y * 16, selection.Region.Width * 16, selection.Region.Height * 16);
                    SelectionUtil.DrawRectangle(SpriteBatch, Color.White, ww);
                }
                else if (Mode == 2)
                {
                    Vector2   pos    = new Vector2(0, Template.ShadowOffset);
                    Rectangle src    = Template.Texture.GetSource(0);
                    Rectangle target = new Rectangle((int)pos.X, (int)pos.Y, Template.Texture.FrameWidth, (int)(Template.Texture.FrameHeight * 0.6f));
                    if (Template.ShadowType == ShadowType.Perspective)
                    {
                        SpriteBatch.Draw(Template.Texture.Texture, target, src, new Color(0f, 0f, 0f, 0.3f), 0.0f, Vector2.Zero, SpriteEffects.FlipVertically, 0f);
                    }
                    SpriteBatch.Draw(Template.Texture.Texture, dest, Color.White);

                    SelectionUtil.DrawStraightLine(SpriteBatch, Color.White, 0, Template.ShadowOffset, 1, Width);
                }
                SpriteBatch.End();
            }
        }
        public void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            Vector2     position = new Vector2(this.selection.Region.X, this.selection.Region.Y) * new Vector2(16, 16);
            SpriteBatch batch    = EditorEngine.Instance.World.ViewData.SpriteBatch;

            if (batch != null && capturedmouse)
            {
                Vector2 scroll = EditorEngine.Instance.World.Camera.Location;
                float   scale  = EditorEngine.Instance.World.Camera.Scale;

                Rectangle target = new Rectangle((int)(position.X * scale), (int)(position.Y * scale), (int)(selection.Region.Width * 16 * scale), (int)(selection.Region.Height * 16 * scale)).Add(scroll);

                SelectionUtil.FillRectangle(batch, Color.Blue * .35f, target);
                SelectionUtil.DrawRectangle(batch, Color.Black, target.Add(new Vector2(1, 1)));
                SelectionUtil.DrawRectangle(batch, Color.White, target);
            }
        }
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            int ypos = vscrollbar.Value;
            int xpos = hscrollbar.Value;

            if (Tileset != null)
            {
                if (Tileset.Texture != null && Tileset.Texture.Texture != null)
                {
                    batch.Begin();
                    batch.Draw(Tileset.Texture.Texture, -new Vector2(xpos, ypos), Color.White);

                    int x = Tileset.Texture.Texture.Width - xpos;
                    int y = Tileset.Texture.Texture.Height - ypos;

                    SelectionUtil.DrawStraightLine(batch, new Color(.9f, .4f, .4f, 1f), 1f, x, -ypos, 2, Tileset.Texture.Texture.Height);                    //vertical
                    SelectionUtil.DrawStraightLine(batch, new Color(.9f, .4f, .4f, 1f), 1f, -xpos, y, 1, Tileset.Texture.Texture.Width);                     //horizontal

                    SelectionUtil.DrawRectangle(batch, new Color(.7f, .1f, 0f, .6f), new Rectangle((xt << 4) - xpos, (yt << 4) - ypos, 16, 16));
                    SelectionUtil.FillRectangle(batch, new Color(.4f, .1f, 0f, .6f), new Rectangle((xt << 4) + 1 - xpos, (yt << 4) + 1 - ypos, 16, 16));

                    int ry = 0;
                    int rx = 0;
                    foreach (Tile t in Tileset.Tiles)
                    {
                        if (rx + 1 > Tileset.Texture.Texture.Width / 16)
                        {
                            rx = 0;
                            ry++;
                        }
                        batch.Draw(ox.Texture, new Rectangle((rx << 4) - xpos, (ry << 4) - ypos, 16, 16), ox.GetSource(t.DefaultBehavior.BehaviorId == this.Behavior ? 0 : 1), Color.White * 0.8f);
                        rx++;
                    }
                    batch.End();
                }
            }

            base.Draw(gameTime);
        }
Beispiel #5
0
        public void Draw(Microsoft.Xna.Framework.GameTime time)
        {
            if (!Initialized || World == null)
            {
                return;
            }
            if (CurrentMap == null)
            {
                return;
            }
            int w = CurrentMap.Width << 4;
            int h = CurrentMap.Height << 4;

            GraphicsDevice.Clear(new Color(0x2f, 0x2f, 0x2f));
            SpriteBatch batch = World.ViewData.SpriteBatch;

            batch.Begin(Matrix.CreateScale(1));

            SelectionUtil.FillRectangle(World.ViewData.SpriteBatch, Color.White * 0.5f, new Rectangle((int)World.Camera.Location.X, (int)World.Camera.Location.Y, (int)(w * World.Camera.Scale), (int)(h * World.Camera.Scale)));

            CurrentMap.Draw(time);

            if (this.World.Camera.Scale <= 0)
            {
                this.World.Camera.Scale = 1f;
            }

            StateMachine.Draw(time);

            if (Options.Instance.Grid)
            {
                if (CurrentMap != null)
                {
                    //We could draw a rectangle for every Tiles...
                    //Or we could be smart and draw lines for columns and rows!

                    Color c1 = Color.DeepSkyBlue;
                    Color c2 = Color.Black;

                    float trans_white = Options.Instance.GridOpacity;
                    float trans_black = Options.Instance.GridOpacity;

                    //rows
                    for (int y = 0; y < CurrentMap.Height; y++)
                    {
                        SelectionUtil.DrawStraightLine(World.ViewData.SpriteBatch, c1, trans_white, 0, (y << 4), CurrentMap.Width * 16, 1);
                        SelectionUtil.DrawStraightLine(World.ViewData.SpriteBatch, c2, trans_black, 0, (y << 4) + 1, CurrentMap.Width * 16, 1);
                    }

                    //columns
                    for (int x = 0; x < CurrentMap.Width; x++)
                    {
                        SelectionUtil.DrawStraightLine(World.ViewData.SpriteBatch, c1, trans_white, x << 4, 0, 1, CurrentMap.Height << 4);
                        SelectionUtil.DrawStraightLine(World.ViewData.SpriteBatch, c2, trans_black, (x << 4) + 1, 0, 1, CurrentMap.Height << 4);
                    }
                }
            }

            ScreenInterface.Draw(time);
            //batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise);
            //batch.Draw(renderTarget, new Rectangle(xCam, yCam, (int) (renderTarget.Width * Zoom), (int) (renderTarget.Height * Zoom)), Color.White);
            batch.End();
        }
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            int xpos = hscrollbar.Value;
            int ypos = vscrollbar.Value;

            if (spriteBatch == null)
            {
                spriteBatch = new SpriteBatch(GraphicsDevice);
            }

            if (Tileset != null)
            {
                if (checkerboard)
                {
                    int i = 0;
                    for (int cy = 0; cy < Tileset.Texture.Rows; cy++)
                    {
                        for (int cx = 0; cx < Tileset.Texture.Columns; cx++)
                        {
                            bool odd = i % 2 != 0;
                            //0xD8DEFF
                            //0xBFC8FF
                            Color col_dark  = new Color(0xd8, 0xde, 0xff);
                            Color col_light = new Color(0xbf, 0xc8, 0xff);
                            SelectionUtil.FillRectangle(spriteBatch, odd ? col_light : col_dark, new Rectangle(cx * 16 - xpos, cy * 16 - ypos, 16, 16));
                            i++;
                        }
                        i++;
                    }
                }
                spriteBatch.Begin();
                spriteBatch.Draw(Tileset.Texture.Texture, -new Vector2(xpos, ypos), Color.White);
                spriteBatch.End();

                int x = Tileset.Texture.Texture.Width - xpos;
                int y = Tileset.Texture.Texture.Height - ypos;

                SelectionUtil.DrawStraightLine(spriteBatch, new Color(.9f, .4f, .4f, 1f), 1f, x, -ypos, 2, Tileset.Texture.Texture.Height);                //vertical
                SelectionUtil.DrawStraightLine(spriteBatch, new Color(.9f, .4f, .4f, 1f), 1f, -xpos, y, 1, Tileset.Texture.Texture.Width);                 //horizontal


                List <Vector2> _points = points[currentEntity];
                foreach (Vector2 vec2 in _points)
                {
                    Tuple <int, int, int> bcol = colors[currentEntity];
                    Color col = new Color(bcol.Item1, bcol.Item2, bcol.Item3);
                    SelectionUtil.FillRectangle(spriteBatch, colorbuffer ? (col * 0.6f) : (Color.Red * 0.6f), new Rectangle((int)vec2.X * 16 - xpos, (int)vec2.Y * 16 - ypos, 16, 16));
                }

                for (int i = 0; i < points.Length; i++)
                {
                    if (i != currentEntity)
                    {
                        foreach (Vector2 vec2 in points[i])
                        {
                            SelectionUtil.FillRectangle(spriteBatch, Color.Black * 0.4f, new Rectangle((int)vec2.X * 16 - xpos, (int)vec2.Y * 16 - ypos, 16, 16));
                        }
                    }
                }
            }

            base.Draw(gameTime);
        }