Beispiel #1
0
 public override void Render(RenderInfo info)
 {
     if (info == null)
     {
         base.Render(info);
         return;
     }
     DebugRender(info);
 }
Beispiel #2
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle, float scale, Color color, float alpha)
 {
     alpha = MathHelper.Clamp(alpha, 0, 1);
     color.A = (byte)(alpha * 255);
     color.R = (byte)(color.R * alpha);
     color.G = (byte)(color.G * alpha);
     color.B = (byte)(color.B * alpha);
     this.RenderFrame(info, frame, position, angle, scale, color);
 }
Beispiel #3
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle, Vector2 scale, Color color, float alpha, bool flipHorizontal)
 {
     alpha = MathHelper.Clamp(alpha, 0, 1);
     color.A = (byte)(alpha * 255);
     color.R = (byte)(color.R * alpha);
     color.G = (byte)(color.G * alpha);
     color.B = (byte)(color.B * alpha);
     Rectangle source = GetRectByFrame(frame);
     info.Batch.Draw(this.Texture, position, source, color, angle, Origin, scale, flipHorizontal ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
 }
Beispiel #4
0
        public override void Render(Phantom.Graphics.RenderInfo info)
        {
            Vector2 pos = this.Position + new Vector2(0, -4);

            switch (this.Facing)
            {
            case North:
                if (this.Attacking)
                {
                    Sprites.Character.RenderFrame(info, 8, pos);
                }
                else
                {
                    Sprites.Character.RenderFrame(info, 0 + this.frame, pos);
                }
                break;

            case East:
                if (this.Attacking)
                {
                    Sprites.Character.RenderFrame(info, 13, pos);
                }
                else
                {
                    Sprites.Character.RenderFrame(info, 5 + this.frame, pos);
                }
                break;

            case South:
                if (this.Attacking)
                {
                    Sprites.Character.RenderFrame(info, 4, pos);
                }
                else
                {
                    Sprites.Character.RenderFrame(info, 10 + this.frame, pos);
                }
                break;

            case West:
                if (this.Attacking)
                {
                    Sprites.Character.RenderFrame(info, 19, pos);
                }
                else
                {
                    Sprites.Character.RenderFrame(info, 15 + this.frame, pos);
                }
                break;
            }
            base.Render(info);
        }
Beispiel #5
0
 public override void Render(RenderInfo info)
 {
     if (this.Entity != null)
     {
         float scale = this.scale;
         if (this.Entity.Shape != null)
         {
             scale = this.Entity.Shape.RoughWidth / Math.Min(this.sprite.Width, this.sprite.Height) * this.scale;
         }
         this.sprite.RenderFrame(info, this.currentFrame, this.Entity.Position, this.Entity.Orientation, scale);
     }
     base.Render(info);
 }
Beispiel #6
0
            public override void Render(Phantom.Graphics.RenderInfo info)
            {
                if (info != null)
                {
                    info.Canvas.FillColor   = UILayer.ColorFace;
                    info.Canvas.StrokeColor = UILayer.ColorShadow;
                    info.Canvas.LineWidth   = 2;
                    info.Canvas.FillRect(this.position, halfSize, 0);
                    info.Canvas.StrokeRect(this.position, halfSize, 0);

                    Vector2 captionHalfSize = new Vector2(halfSize.X, 10);
                    info.Canvas.FillColor = UILayer.ColorShadow;
                    info.Canvas.FillRect(position + new Vector2(0, -halfSize.Y + 10), captionHalfSize, 0);

                    Vector2 size = UILayer.Font.MeasureString(Text);
                    UILayer.Font.DrawString(info, Text, this.position + new Vector2(5 - halfSize.X, 10 - halfSize.Y - size.Y * 0.5f), UILayer.ColorHighLight);
                }
                base.Render(info);
            }
Beispiel #7
0
        public override void Render(Phantom.Graphics.RenderInfo info)
        {
            Vector2 diagonal    = new Vector2(info.Width, info.Height) * .5f * (1 / info.Camera.Zoom);
            Vector2 topleft     = info.Camera.Position - diagonal - Vector2.One * TileSize;
            Vector2 bottomright = info.Camera.Position + diagonal + Vector2.One * TileSize;

            Vector2 p;
            Vector2 offset = Vector2.One * TileSize * .5f;
            Random  r      = new Random(this.seed);

            for (int i = 0; i < this.cells.Length; i++)
            {
                var room = this.rooms[i];
                p = offset + new Vector2(i % this.size, i / this.size) * (TileSize);
                if (p.X < topleft.X || p.Y < topleft.Y || p.X > bottomright.X || p.Y > bottomright.Y)
                {
                    continue;
                }
                switch (this.cells[i])
                {
                case NONE:
                    var tile = this.groundFrames[this.rooms[i] % this.groundFrames.Length];
                    Sprites.Roguelike.RenderFrame(info, tile + (i * 1327 % 2 * 56), p, 0, 1f);
                    break;

                case WALL:
                    // 26
                    Sprites.Roguelike.RenderFrame(info, (2 + i * 1327 % 2) * 56 + 6, p, 0, 1f);
                    break;

                default:
                    tile = this.groundFrames[this.rooms[i] % this.groundFrames.Length];
                    Sprites.Roguelike.RenderFrame(info, tile + (i * 1327 % 2 * 56), p, 0, 1f);
                    Sprites.Roguelike.RenderFrame(info, this.cells[i], p, 0, .8f);
                    break;
                }
            }
            base.Render(info);
        }
Beispiel #8
0
 protected override void RenderPassEndLock(RenderInfo info)
 {
     this.batch.Begin(this.sortMode, this.blendState, null, null, null, this.fx, info.World);
     CreateBounds(info, out TopLeft, out BottomRight);
     foreach (Entity e in this.entityLayer.GetEntitiesInRect(TopLeft, BottomRight, true))
     {
         if (!e.Ghost)
         {
             e.Render(info);
         }
     }
     foreach (Component c in this.nonEntities)
     {
         if (!c.Ghost)
         {
             c.Render(info);
         }
     }
     lock (PhantomGame.Game.GlobalRenderLock)
     {
         this.batch.End();
     }
 }
Beispiel #9
0
 public void DrawString(RenderInfo info, string s, Vector2 position, Color color, float scale, float orientation)
 {
     DrawString(info, s, position, color, scale, orientation, new Vector2(0, 0));
 }
Beispiel #10
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position)
 {
     this.RenderFrame(info, frame, position, 0);
 }
Beispiel #11
0
 public void DrawString(RenderInfo info, string s, Vector2 position, Color color)
 {
     DrawString(info, s, position, color, 1, 0, new Vector2(0, 0));
 }
Beispiel #12
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, Vector2 drawSize, float angle)
 {
     this.RenderFrame(info, frame, position, drawSize, angle, Color.White);
 }
Beispiel #13
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle)
 {
     this.RenderFrame(info, frame, position, angle, 1);
 }
Beispiel #14
0
 private void DebugRender(RenderInfo info)
 {
     Canvas canvas = info.Canvas;
     foreach (EntityLayer el in this.Parent.GetAllComponentsByType<EntityLayer>())
     {
         foreach (Entity e in el.GetAllComponentsByType<Entity>())
         {
             if (e.Mover != null)
             {
                 canvas.Begin();
                 Vector2 r = Vector2.One.RotateBy(e.Orientation);
                 Vector2 l = r.LeftPerproduct();
                 canvas.MoveTo(e.Position - r * 2);
                 canvas.LineTo(e.Position + r * 2);
                 canvas.MoveTo(e.Position - l * 2);
                 canvas.LineTo(e.Position + l * 2);
                 canvas.LineWidth = this.defaultLineWidth;
                 canvas.StrokeColor = GetColor("entity");
                 canvas.Stroke();
                 canvas.LineWidth = this.defaultLineWidth * 3;
                 canvas.StrokeColor = DebugLayer.Shadow;
                 canvas.Stroke();
                 if (e.Mover.Force.LengthSquared() > 0)
                     DrawVector(canvas, e.Position + e.Mover.Velocity + e.Mover.Acceleration, e.Position + e.Mover.Velocity + e.Mover.Acceleration + e.Mover.Force, "force");
                 if (e.Mover.Acceleration.LengthSquared() > 0)
                     DrawVector(canvas, e.Position + e.Mover.Velocity, e.Position + e.Mover.Velocity + e.Mover.Acceleration, "acceleration");
                 if (e.Mover.Velocity.LengthSquared() > 0)
                     DrawVector(canvas, e.Position, e.Position + e.Mover.Velocity, "velocity");
             }
         }
     }
     foreach (KeyValuePair<Entity, Dictionary<string, Vector2>> e in this.entityVectors)
     {
         Vector2 pos = e.Key.Position;
         foreach (KeyValuePair<string, Vector2> v in e.Value)
         {
             DrawVector(canvas, pos, pos + v.Value, v.Key);
         }
     }
     foreach (KeyValuePair<Entity, Dictionary<string, EntityLabel>> e in this.entityLabels)
     {
         Vector2 pos = e.Key.Position;
         foreach (KeyValuePair<string, EntityLabel> v in e.Value)
         {
             info.Batch.DrawString(this.font, v.Value.Label, pos + v.Value.Offset, GetColor(v.Value.Name), 0, Vector2.Zero, 1/info.Camera.Zoom, SpriteEffects.None, 0);
         }
     }
 }
Beispiel #15
0
 private void RenderPassFullLock(RenderInfo info)
 {
     lock (PhantomGame.Game.GlobalRenderLock)
     {
         this.batch.Begin(this.sortMode, this.blendState, null, null, null, this.fx, info.World);
         IList<Component> components = this.Parent.Components;
         int count = components.Count;
         for (int i = 0; i < count; i++)
         {
             if (!components[i].Ghost)
             {
                 if (this == components[i])
                     this.Parent.Render(info); // TODO: Document and test this!
                 components[i].Render(info);
             }
         }
         this.batch.End();
     }
 }
Beispiel #16
0
 internal void SetRenderInfo(RenderInfo info)
 {
     this.info = info;
 }
Beispiel #17
0
 internal void SetRenderInfo(RenderInfo info)
 {
     this.info = info;
 }
Beispiel #18
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle, float scale)
 {
     this.RenderFrame(info, frame, position, angle, scale, Color.White);
 }
Beispiel #19
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position)
 {
     this.RenderFrame(info, frame, position, 0);
 }
Beispiel #20
0
 public override void Render( RenderInfo info )
 {
     if( info == null )
         this.renderer.Render( info );
      	        //!base.Render();
 }
Beispiel #21
0
        public override void Render(RenderInfo info)
        {
            if (info == null)
                return;
            info.Camera = Editing.Camera;
            if (layers[currentLayer].Layer is EntityLayer)
                DrawEntities(info, layers[currentLayer].Layer as EntityLayer);

            info.Batch.DrawString(font, layers[currentLayer].Name, new Vector2(11, PhantomGame.Game.Resolution.Height - 29), Color.Black);
            info.Batch.DrawString(font, layers[currentLayer].Name, new Vector2(10, PhantomGame.Game.Resolution.Height - 30), Color.White);
            base.Render(info);
        }
Beispiel #22
0
 private static Vector2 DrawEntity(RenderInfo info, Vector2 topLeft, Entity entity)
 {
     Circle circle = entity.Shape as Circle;
     OABB oabb = entity.Shape as OABB;
     Polygon polygon = entity.Shape as Polygon;
     if (circle != null)
     {
         info.Canvas.StrokeCircle(entity.Position - topLeft, circle.Radius);
         info.Canvas.StrokeLine(entity.Position - topLeft, entity.Position + entity.Direction * circle.Radius - topLeft);
     }
     else if (oabb != null)
     {
         info.Canvas.StrokeRect(entity.Position - topLeft, oabb.HalfSize, entity.Orientation);
     }
     else if (polygon != null)
     {
         Vector2 pos = entity.Position - topLeft;
         Vector2[] verts = polygon.RotatedVertices(entity.Orientation);
         info.Canvas.Begin();
         info.Canvas.MoveTo(pos + verts[verts.Length - 1]);
         for (int i = 0; i < verts.Length; i++)
             info.Canvas.LineTo(pos + verts[i]);
         info.Canvas.Stroke();
     }
     return topLeft;
 }
Beispiel #23
0
        public void DrawString(RenderInfo info, string s, Vector2 position, Color color, float scale, float orientation, Vector2 origin, Phont outline, Color outlineColor)
        {
            Sprite spr         = this.sprite;
            float  spriteScale = scale;

            float scaleUp = (info.Renderer == null || info.Renderer.Policy == Renderer.ViewportPolicy.None || info.Renderer.Policy == Renderer.ViewportPolicy.Centered) ? 1 : (PhantomGame.Game.Width / PhantomGame.Game.Resolution.Width);

            //scale up?
            if (scale > scaleUp && larger != null)
            {
                Phont l = this;
                do
                {
                    spriteScale /= l.largerScaleFactor;
                    l            = l.larger;
                } while (spriteScale > scaleUp && l.larger != null);
                spr = l.sprite;
            }

            //scale down?
            if (smaller != null && scale <= this.smallerScaleFactor * scaleUp)
            {
                Phont l = this;
                do
                {
                    spriteScale /= l.smallerScaleFactor;
                    l            = l.smaller;
                } while (l.smaller != null && spriteScale <= l.smallerScaleFactor * scaleUp);
                spr = l.sprite;
            }

            Vector2 u = PhantomUtils.FromAngle(orientation);
            Vector2 p = position;

            p   -= origin.RotateBy(orientation) * scale;
            p.Y += u.X * LineSpacing * 0.5f * scale;
            p.X -= u.Y * LineSpacing * 0.5f * scale;
            float kerningTop    = -1;
            float kerningCenter = -1;
            float kerningBottom = -1;
            float r             = 0;

            for (int i = 0; i < s.Length; i++)
            {
                int index = (int)s[i] - 32;
                if (index == '\r' - 32)
                {
                    continue;
                }
                else if (index == '\n' - 32)
                {
                    kerningTop = -1;
                    p         -= u * r;
                    p.Y       += u.X * LineSpacing * scale;
                    p.X       -= u.Y * LineSpacing * scale;
                    r          = 0;
                }
                else if (index >= 0 && index < 8 * 16)
                {
                    float w;
                    if (index > 0)
                    {
                        if (kerningTop >= 0)
                        {
                            w = Math.Max(Math.Max(kerningTopLeft[index] + kerningTop, kerningCenterLeft[index] + kerningCenter), kerningBottomLeft[index] + kerningBottom);
                        }
                        else
                        {
                            w = Math.Max(Math.Max(kerningTopLeft[index], kerningCenterLeft[index]), kerningBottomLeft[index]);
                        }
                        //draws measure to determin kerning heights
                        //BaseSprites.Rect.RenderFrame(info, 0, p + new Vector2(0, -sprite.Height * 0.5f + kTop), new Vector2(1, 1), 0, Color.White);
                        //BaseSprites.Rect.RenderFrame(info, 0, p + new Vector2(0, -sprite.Height * 0.5f + kBottom), new Vector2(1, 1), 0, Color.White);
                        p += u * w * scale;
                        r += w * scale;
                        outline.sprite.RenderFrame(info, index, p, orientation, scale, outlineColor);
                        spr.RenderFrame(info, index, p, orientation, spriteScale, color);
                        kerningTop    = kerningTopRight[index];
                        kerningCenter = kerningCenterRight[index];
                        kerningBottom = kerningBottomRight[index];
                    }
                    else
                    {
                        p            += u * SpaceWidth * scale;
                        r            += SpaceWidth * scale;
                        kerningBottom = Math.Max(kerningBottom, Math.Max(kerningCenter, kerningTop));
                        kerningCenter = kerningBottom;
                        kerningTop    = kerningBottom;
                    }
                    p += u * CharacterSpacing * scale;
                    r += CharacterSpacing * scale;
                }
            }
        }
Beispiel #24
0
        private RenderInfo BuildRenderInfo()
        {
            RenderInfo info = new RenderInfo();
            info.Renderer = this;
            info.Pass = 0;
            info.Batch = this.batch;
            info.GraphicsDevice = PhantomGame.Game.GraphicsDevice;

            Viewport resolution = PhantomGame.Game.Resolution;
            Vector2 designSize = PhantomGame.Game.Size;
            float designRatio = designSize.X / designSize.Y;

            float width = resolution.Height * designRatio;
            float height = resolution.Width * (designSize.Y / designSize.X);
            float paddingX = (resolution.Width - width) * .5f;
            float paddingY = (resolution.Height - height) * .5f;

            Viewport fit, fill;
            if (resolution.AspectRatio > designRatio)
            {
                fit = new Viewport((int)paddingX, 0, (int)width, resolution.Height);
                fill = new Viewport(0, (int)paddingY, resolution.Width, (int)height);
            }
            else
            {
                fit = new Viewport(0, (int)paddingY, resolution.Width, (int)height);
                fill = new Viewport((int)paddingX, 0, (int)width, resolution.Height);
            }

            switch (this.Policy)
            {
                case ViewportPolicy.None:
                    info.Width = resolution.Width;
                    info.Height = resolution.Height;
                    break;
                case ViewportPolicy.Aligned:
                    info.Width = fit.Width;
                    info.Height = fit.Height;
                    break;
                case ViewportPolicy.Fit:
                case ViewportPolicy.Fill:
                case ViewportPolicy.Stretch:
                case ViewportPolicy.Centered:
                    info.Width = designSize.X;
                    info.Height = designSize.Y;
                    break;
            }

            info.Projection = Matrix.CreateOrthographicOffCenter(
                0, resolution.Width, resolution.Height, 0,
                0, 1);

            info.World = Matrix.Identity;
            if (this.layer != null && this.layer.Camera != null && (this.Options & RenderOptions.IgnoreCamera) == 0)
            {
                Camera c = this.layer.Camera;
                if (c.Zoom != 1)
                {
                    info.World *= Matrix.CreateTranslation(-new Vector3(c.Position + c.Focus, 0));
                    info.World *= Matrix.CreateScale(c.Zoom, c.Zoom, 1);
                    info.World *= Matrix.CreateRotationZ(c.Orientation);
                    info.World *= Matrix.CreateTranslation(new Vector3(c.Position + c.Focus, 0));

                }
                info.World *= Matrix.CreateTranslation(info.Width * .5f - c.Position.X, info.Height * .5f - c.Position.Y, 0);
                info.Camera = c;
            }

            switch (this.Policy)
            {
                case ViewportPolicy.None:
                    break;
                case ViewportPolicy.Aligned:
                    info.World *= Matrix.CreateTranslation(fit.X, fit.Y, 0);
                    break;
                case ViewportPolicy.Centered:
                    info.World = Matrix.CreateTranslation((resolution.Width - designSize.X) * .5f, (resolution.Height - designSize.Y) * .5f, 0);
                    break;
                case ViewportPolicy.Stretch:
                    info.World = Matrix.CreateScale(
                            resolution.Width / designSize.X,
                            resolution.Height / designSize.Y,
                            1);
                    break;
                case ViewportPolicy.Fill:
                    if (resolution.Width != designSize.X || resolution.Height != designSize.Y)
                    {
                        Matrix scale = Matrix.CreateScale(
                            fill.Width / designSize.X,
                            fill.Height / designSize.Y,
                            1);
                        Matrix translate = Matrix.CreateTranslation(fill.X, fill.Y, 0);
                        info.World *= scale * translate;
                    }
                    break;
                case ViewportPolicy.Fit:
                    if (resolution.Width != designSize.X || resolution.Height != designSize.Y)
                    {
                        Matrix scale = Matrix.CreateScale(
                            fit.Width / designSize.X,
                            fit.Height / designSize.Y,
                            1);
                        Matrix translate = Matrix.CreateTranslation(fit.X, fit.Y, 0);
                        info.World *= scale * translate;
                    }
                    break;
            }

            if (this.canvas != null)
            {
                this.canvas.SetRenderInfo(info);
                info.Canvas = this.canvas;
            }

            return info;
        }
Beispiel #25
0
        public override void Render(RenderInfo info)
        {
            this.lastRenderInfo = info;

            float padding = 10f;
            float width = info.Width;
            float height = info.Height;
            Vector2 center = new Vector2(width, height) * .5f;
            Canvas c = info.Canvas;
            SpriteBatch batch = info.Batch;

            if (info.Pass == 0)
            {
                // Semi dark background:
                c.FillColor = Color.Black;
                c.FillColor.A = 0x32;
                c.FillRect(center, center, 0);
                c.FillColor.A = 0x10;
                c.FillCircle(center, Math.Min(center.X, center.Y));

                // The circle:
                float sin75 = (float)Math.Sin(this.timer * .75f);
                float radius = 50 + sin75 * sin75 * sin75 * 25;
                c.StrokeColor = Color.Lerp(this.one, Color.White, .5f);
                c.LineWidth = 5;
                c.StrokeCircle(center, radius);
                c.FillColor = this.one;
                c.FillCircle(center, radius);
                c.StrokeColor = Color.Lerp(this.one, Color.Black, .8f);
                c.LineWidth = 3;
                c.StrokeCircle(center, radius);

                // John of the Cross:
                float s = 42;
                Vector2 offset = center * 2 - Vector2.UnitX * s * 2 - Vector2.UnitY * 10;
                c.Begin();
                c.MoveTo(offset);
                c.LineTo(offset.X + s, offset.Y);
                c.LineTo(offset.X + s, offset.Y-s);
                c.LineTo(offset.X, offset.Y-s);
                c.LineTo(offset);
                c.LineTo(offset.X + s, offset.Y - s);
                c.LineTo(offset.X + s*.5f, offset.Y - s*1.5f);
                c.LineTo(offset.X, offset.Y - s);
                c.LineTo(offset.X + s, offset.Y);
                c.LineWidth = 5f;
                c.StrokeColor = Color.Lerp(this.two, Color.White, .2f);
                c.Stroke();
                c.LineWidth = 2.5f;
                c.StrokeColor = this.two;
                c.Stroke();

                // Health HUD:
                c.StrokeColor = Color.Black;
                c.LineWidth = 1;
                Vector2 boxSize = new Vector2(10, 15);
                Vector2 healthPos = new Vector2( width-10, 10 );
                int boxCount = 16;
                float health = MathHelper.Clamp(1 - Mouse.GetState().ScrollWheelValue / 1200f, 0, 1);
                for (int i = 0; i < boxCount; i++)
                {
                    if (i < health * boxCount)
                        c.FillColor = Color.Lerp(Color.DarkRed, Color.Red, i / (float)boxCount);
                    else
                        c.FillColor = Color.Transparent;
                    Vector2 p = healthPos;
                    p.X -= boxSize.X * (boxCount - i) - boxSize.X * .5f;
                    p.Y += boxSize.Y * .5f;
                    c.FillRect(p, boxSize * .5f, 0);
                    c.StrokeRect(p, boxSize * .5f, 0);
                }

                // Shapes:
                c.Begin();
                c.MoveTo(50, height - 50);
                c.LineTo(50, height - 100);
                c.LineTo(100, height - 100);
                c.LineTo(70, height - 70);
                c.LineTo(100, height - 70);
                c.MoveTo(110, height - 100);
                c.LineTo(200, height - 100);
                c.LineTo(110, height - 70);
                c.MoveTo(50, height - 110);
                c.LineTo(75, height - 150);
                c.LineTo(75, height - 120);
                c.LineTo(100, height - 120);
                c.LineTo(100, height - 110);
                c.LineTo(75, height - 110);

                c.MoveTo(85, height - 150);
                c.LineTo(100, height - 150);
                c.LineTo(130, height - 120);
                c.LineTo(200, height - 110);
                c.LineTo(110, height - 110);
                c.LineTo(110, height - 130);
                c.LineTo(85, height - 130);
                c.StrokeColor = Color.Lerp(this.six, Color.Black, .75f);
                c.LineWidth = 6;
                c.Stroke();
                c.FillColor = this.six;
                c.Fill();
                c.StrokeColor = Color.Lerp(this.six, Color.White, .75f);
                c.LineWidth = 1;
                c.Stroke();

                // Info text and rect:
                this.UpdateInfoText();
                float infoTextAngle = .05f * (float)Math.Sin(this.timer * .5f);
                c.FillColor = Color.Black;
                c.FillColor.A = 0x80;
                c.FillRect(this.infoHalfSize + Vector2.One * padding * 2, this.infoHalfSize + Vector2.One * padding, infoTextAngle);
                c.LineWidth = 1;
                c.StrokeColor = Color.White;
                c.StrokeColor.A = 0x80;
                c.StrokeRect(this.infoHalfSize + Vector2.One * padding * 2, this.infoHalfSize + Vector2.One * padding, infoTextAngle);
                batch.DrawString(this.font, this.info, Vector2.One * padding * 2, Color.White);
            }

            // Passes:
            float passScale = info.Pass / (float)info.Renderer.Passes;
            c.FillColor = Color.Lerp(this.one, this.two, passScale);
            c.FillRect(new Vector2(width * .5f, height - 5), new Vector2(width * .5f * (1-passScale), 5), 0);

            base.Render(info);
        }
Beispiel #26
0
        private void DrawEntities(RenderInfo info, EntityLayer entities)
        {
            int tiles = layers[currentLayer].Type == LayerType.Entities ? 0: 1;
            Vector2 topLeft = new Vector2(info.Camera.Left, info.Camera.Top);
            for (int i = 0; i < entities.Components.Count; i++)
            {
                Entity entity = entities.Components[i] as Entity;
                if (entity != null && entity.Shape != null && entity.Properties.GetInt("isTile",0)==tiles)
                {
                    info.Canvas.StrokeColor = Color.White;
                    info.Canvas.LineWidth = 4;
                    topLeft = DrawEntity(info, topLeft, entity);

                    info.Canvas.StrokeColor = Color.Black;
                    if (entity == selectedEntity)
                        info.Canvas.StrokeColor = Color.Yellow;
                    else if (entity == hoveringEntity)
                        info.Canvas.StrokeColor = Color.Cyan;
                    info.Canvas.LineWidth = 2;
                    topLeft = DrawEntity(info, topLeft, entity);

                    if (windows.Ghost)
                    {
                        if (entity == selectedEntity)
                        {
                            string name = MapLoader.ShortTypeName(selectedEntity.GetType());
                            Vector2 size = font.MeasureString(name);
                            info.Batch.DrawString(font, name, entity.Position - topLeft - size * 0.5f, Color.Yellow);
                        }
                        else if (entity == hoveringEntity)
                        {
                            string name = MapLoader.ShortTypeName(hoveringEntity.GetType());
                            Vector2 size = font.MeasureString(name);
                            info.Batch.DrawString(font, name, entity.Position - topLeft - size * 0.5f, Color.Cyan);
                        }
                    }
                }
            }

            if (windows.Ghost)
            {
                info.Canvas.StrokeColor = Color.Red;
                info.Canvas.LineWidth = 2;
                if (drawingEntity != null && hoveringEntity == null)
                {
                    DrawEntity(info, topLeft, drawingEntity);
                    string name = MapLoader.ShortTypeName(drawingEntity.GetType());
                    Vector2 size = font.MeasureString(name);
                    info.Batch.DrawString(font, name, drawingEntity.Position - topLeft - size * 0.5f, Color.Red);
                }
                else if (layers[currentLayer].Type == LayerType.Tiles)
                {
                    Vector2 pos = SnapPosition(mousePosition) - topLeft;
                    info.Canvas.Begin();
                    info.Canvas.MoveTo(pos - Vector2.One * MapLoader.TileSize * 0.5f);
                    info.Canvas.LineTo(pos + Vector2.One * MapLoader.TileSize * 0.5f);
                    info.Canvas.MoveTo(pos + new Vector2(MapLoader.TileSize * 0.5f, -MapLoader.TileSize * 0.5f));
                    info.Canvas.LineTo(pos + new Vector2(-MapLoader.TileSize * 0.5f, MapLoader.TileSize * 0.5f));
                    info.Canvas.Stroke();
                }
            }
        }
Beispiel #27
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle)
 {
     this.RenderFrame(info, frame, position, angle, 1);
 }
Beispiel #28
0
        public RenderInfo BuildRenderInfo()
        {
            RenderInfo info = new RenderInfo();

            info.Renderer       = this;
            info.Pass           = 0;
            info.Batch          = this.batch;
            info.GraphicsDevice = PhantomGame.Game.GraphicsDevice;

            info.IsTopState = this.state == PhantomGame.Game.CurrentState;

            Viewport resolution  = PhantomGame.Game.Resolution;
            Vector2  designSize  = PhantomGame.Game.Size;
            float    designRatio = designSize.X / designSize.Y;

            float width    = resolution.Height * designRatio;
            float height   = resolution.Width * (designSize.Y / designSize.X);
            float paddingX = (resolution.Width - width) * .5f;
            float paddingY = (resolution.Height - height) * .5f;

            Viewport fit, fill;

            if (resolution.AspectRatio > designRatio)
            {
                fit          = new Viewport((int)paddingX, 0, (int)width, resolution.Height);
                fill         = new Viewport(0, (int)paddingY, resolution.Width, (int)height);
                info.Padding = new Vector2(paddingX * designSize.Y / resolution.Height, 0);
            }
            else
            {
                fit          = new Viewport(0, (int)paddingY, resolution.Width, (int)height);
                fill         = new Viewport((int)paddingX, 0, (int)width, resolution.Height);
                info.Padding = new Vector2(0, paddingY * designSize.X / resolution.Width);
            }

            switch (this.Policy)
            {
            case ViewportPolicy.None:
                info.Width  = resolution.Width;
                info.Height = resolution.Height;
                break;

            case ViewportPolicy.Aligned:
                info.Width  = fit.Width;
                info.Height = fit.Height;
                break;

            case ViewportPolicy.Fit:
            case ViewportPolicy.Fill:
            case ViewportPolicy.Stretch:
            case ViewportPolicy.Centered:
                info.Width  = designSize.X;
                info.Height = designSize.Y;
                break;
            }


            info.Projection = Matrix.CreateOrthographicOffCenter(
                0, resolution.Width, resolution.Height, 0,
                0, 1);

            info.World = Matrix.Identity;
            if (this.layer != null && this.layer.Camera != null && (this.Options & RenderOptions.IgnoreCamera) == 0)
            {
                info.Camera = this.layer.Camera;
                info.World *= info.Camera.CreateMatrix(info.Width, info.Height);
            }


            switch (this.Policy)
            {
            case ViewportPolicy.None:
                break;

            case ViewportPolicy.Aligned:
                info.World *= Matrix.CreateTranslation(fit.X, fit.Y, 0);
                break;

            case ViewportPolicy.Centered:
                info.World = Matrix.CreateTranslation((resolution.Width - designSize.X) * .5f, (resolution.Height - designSize.Y) * .5f, 0);
                break;

            case ViewportPolicy.Stretch:
                info.World = Matrix.CreateScale(
                    resolution.Width / designSize.X,
                    resolution.Height / designSize.Y,
                    1);
                break;

            case ViewportPolicy.Fill:
                if (resolution.Width != designSize.X || resolution.Height != designSize.Y)
                {
                    Matrix scale = Matrix.CreateScale(
                        fill.Width / designSize.X,
                        fill.Height / designSize.Y,
                        1);
                    Matrix translate = Matrix.CreateTranslation(fill.X, fill.Y, 0);
                    info.World *= scale * translate;
                }
                break;

            case ViewportPolicy.Fit:
                if (resolution.Width != designSize.X || resolution.Height != designSize.Y)
                {
                    Matrix scale = Matrix.CreateScale(
                        fit.Width / designSize.X,
                        fit.Height / designSize.Y,
                        1);
                    Matrix translate = Matrix.CreateTranslation(fit.X, fit.Y, 0);
                    info.World *= scale * translate;
                }
                break;
            }

            if (this.canvas != null)
            {
                this.canvas.SetRenderInfo(info);
                info.Canvas = this.canvas;
            }

            info.RenderTarget = null;


            this.lastWorld = info.World;
            return(info);
        }
Beispiel #29
0
        public Vector2 GetPadding()
        {
            RenderInfo info = BuildRenderInfo();

            return(info.Padding);
        }
Beispiel #30
0
        public override void Render( RenderInfo info )
        {
            if (this.Parent == null || info != null)
                return;

            info = this.BuildRenderInfo();

            info.GraphicsDevice.RasterizerState = RasterizerState.CullNone;

            for (int pass = 0; pass < this.Passes; pass++)
            {
                info.Pass = pass;
                this.activeRenderPass(info);
            }

            base.Render(info);
        }
Beispiel #31
0
 public void RenderFrame(RenderInfo info, int frame, Vector2 position, float angle, float scale, Color color, bool flipHorizontal)
 {
     if (frame < 0 || frame >= this.FrameCount)
         return;
     Rectangle source = GetRectByFrame(frame);
     info.Batch.Draw(this.Texture, position, source, color, angle, Origin, scale, flipHorizontal ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
 }
        public override void Render(RenderInfo info)
        {
            Matrix[] transforms = new Matrix[this.model.Bones.Count];
            this.model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in this.model.Meshes)
            {

                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * world;
                    effect.View = this.layer.Camera.View;
                    effect.Projection = this.layer.Camera.Projection;
                }

                mesh.Draw();
            }
            base.Render(info);
        }