Esempio n. 1
0
        public void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r, DirectGraphicsContext <TSurface, TSource> layer, Point destination, int fontScale = 1)
        {
            var font = r.SpriteManager["font"];

            byte[] asciiBytes = Encoding.ASCII.GetBytes(Text);

            int destX = destination.X;

            if (Icon != null)
            {
                Rectangle iconDestination = new Rectangle(Icon.Destination);
                iconDestination.X += destination.X;
                iconDestination.Y += destination.Y;
                layer.Draw(r.SpriteManager[Icon.Texture], iconDestination.ToDrawing(), Icon.Source != Rectangle.Empty ? Icon.Source.ToDrawing() : (System.Drawing.Rectangle?)null);

                destX += (int)iconDestination.Width + 4;
            }

            foreach (byte c in asciiBytes)
            {
                int srcX = (c % 16) * 8;
                int srcY = (c / 16) * 8;

                layer.Draw(font, new System.Drawing.Rectangle(destX, destination.Y, 8 * fontScale, 8 * fontScale), new System.Drawing.Rectangle(srcX, srcY, 8, 8), new DrawInfo()
                {
                    Color = Color
                });
                destX += char_sizes[c] * fontScale;
            }
        }
Esempio n. 2
0
        public static void Render <TSurface, TSource>(DirectGraphicsContext <TSurface, TSource> layer, CameraView view, ScreenRenderer <TSurface, TSource> r, List <Sprite> sprites, Transform transform = null)
        {
            IGameController controller = Woofer.Controller;

            foreach (Sprite sprite in sprites)
            {
                if (sprite.Source.X < 0 || sprite.Source.Y < 0)
                {
                    continue;
                }
                float x = (float)sprite.Destination.X;
                float y = (float)sprite.Destination.Y;
                if (transform != null)
                {
                    x += ((float)(transform.Position.X));
                    y += ((float)(transform.Position.Y));
                }
                float width  = (float)sprite.Destination.Width;
                float height = (float)sprite.Destination.Height;

                if (!new System.Drawing.RectangleF(x, y, width, height)
                    .IntersectsWith(
                        new System.Drawing.RectangleF((float)(view.X - layer.GetSize().Width / 2), (float)(view.Y - layer.GetSize().Height / 2), layer.GetSize().Width, layer.GetSize().Height)))
                {
                    continue;
                }

                x -= (int)Math.Floor(view.X);
                y -= (int)Math.Floor(view.Y);

                y *= -1;
                y -= height;

                x += layer.GetSize().Width / 2;
                y += layer.GetSize().Height / 2;


                System.Drawing.Rectangle drawingRect = new System.Drawing.Rectangle((int)Math.Floor(x), (int)Math.Floor(y), (int)width, (int)height);

                layer.Draw(r.SpriteManager[sprite.Texture], drawingRect, sprite.Source != Rectangle.Empty ? sprite.Source.ToDrawing() : (System.Drawing.Rectangle?)null, new DrawInfo()
                {
                    Mode = sprite.DrawMode, Color = System.Drawing.Color.FromArgb((int)(sprite.Opacity * 255), 255, 255, 255)
                });
            }
        }
Esempio n. 3
0
        public void Render <TSurface, TSource>(DirectGraphicsContext <TSurface, TSource> layer, CameraView view, ScreenRenderer <TSurface, TSource> r)
        {
            IGameController controller = Woofer.Controller;

            Spatial spatial = Owner.Components.Get <Spatial>();

            foreach (Sprite sprite in Sprites)
            {
                float x = (float)sprite.Destination.X;
                float y = (float)sprite.Destination.Y;
                if (spatial != null)
                {
                    x += ((float)(spatial.X));
                    y += ((float)(spatial.Y));
                }
                float width  = (float)sprite.Destination.Width;
                float height = (float)sprite.Destination.Height;

                x -= (int)Math.Floor(controller.ActiveScene.CurrentViewport.X);
                y -= (int)Math.Floor(controller.ActiveScene.CurrentViewport.Y);

                y *= -1;
                y -= height;

                x += layer.GetSize().Width / 2;
                y += layer.GetSize().Height / 2;


                System.Drawing.Rectangle drawingRect = new System.Drawing.Rectangle((int)Math.Floor(x), (int)Math.Floor(y), (int)width, (int)height);

                if (sprite.Source is Rectangle source)
                {
                    layer.Draw(r.SpriteManager[sprite.Texture], drawingRect, sprite.Source.ToDrawing());
                }
                else
                {
                    layer.Draw(r.SpriteManager[sprite.Texture], drawingRect);
                }
            }
        }
Esempio n. 4
0
        public virtual void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r, DirectGraphicsContext <TSurface, TSource> layer, Vector2D offset)
        {
            if (!Enabled)
            {
                return;
            }
            layer.FillRect((Bounds + (Position + offset)).ToDrawing(), Highlighted ? Focused ? Color.CornflowerBlue : Color.FromArgb(63, 63, 70) : Color.FromArgb(37, 37, 38));
            TextUnit  label         = new TextUnit(Display);
            Rectangle displayBounds = (Bounds + (Position + offset));

            System.Drawing.Size labelSize = label.GetSize(TextSize);
            label.Render(r, layer, new Point((int)(displayBounds.X + displayBounds.Width / 2 - labelSize.Width / 2), (int)(displayBounds.Y + displayBounds.Height / 2 - labelSize.Height / 2)), TextSize);
        }
Esempio n. 5
0
 public override void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r, DirectGraphicsContext <TSurface, TSource> layer, Vector2D offset)
 {
     Display = Owner.Shift ? ShiftDisplay : NormalDisplay;
     base.Render(r, layer, offset);
 }