Esempio n. 1
0
 protected override void DoDraw(IBatchRenderer sbatch, FRectangle bounds)
 {
     if (Alignment == HUDAlignment.CENTER || Alignment == HUDAlignment.CENTERLEFT || Alignment == HUDAlignment.CENTERRIGHT)
     {
         sbatch.DrawString(
             Font,
             _textCache,
             new FPoint(bounds.Left, bounds.Top + _fontVOffset),
             TextColor * Alpha,
             0,
             FPoint.Zero,
             _fontScale,
             SpriteEffects.None,
             0);
     }
     else
     {
         sbatch.DrawString(
             Font,
             _textCache,
             bounds.TopLeft,
             TextColor * Alpha,
             0,
             FPoint.Zero,
             _fontScale,
             SpriteEffects.None,
             0);
     }
 }
Esempio n. 2
0
		protected override void DoDraw(IBatchRenderer sbatch, FRectangle bounds)
		{
			if (Alignment == HUDAlignment.CENTER || Alignment == HUDAlignment.CENTERLEFT || Alignment == HUDAlignment.CENTERRIGHT)
			{
				sbatch.DrawString(
					Font, 
					_textCache, 
					new Vector2(bounds.Left, bounds.Top + _fontVOffset), 
					TextColor, 
					0, 
					Vector2.Zero, 
					_fontScale, 
					SpriteEffects.None, 
					0);
			}
			else
			{
				sbatch.DrawString(
					Font, 
					_textCache, 
					bounds.VectorTopLeft, 
					TextColor, 
					0,
					Vector2.Zero, 
					_fontScale, 
					SpriteEffects.None, 
					0);
			}
		}
Esempio n. 3
0
        public void Draw()
        {
            if (!IsEnabled)
            {
                return;
            }

            debugBatch.Begin(1f, blendState: BlendState.NonPremultiplied);             //scale=1f is ok because we use no textures

            foreach (var line in lines.SelectMany(p => p.GetLines()).Where(p => p.Active()))
            {
                var columns = line.DisplayText();

                var pos = new FPoint(TEXT_OFFSET * Scale, line.PositionY * Scale);

                if (columns.Count == 0 || columns.All(string.IsNullOrWhiteSpace))
                {
                    continue;
                }

                foreach (var _text in columns)
                {
                    var text = FontRenderHelper.MakeTextSafeWithWarn(font, _text, '_');

                    var size = font.MeasureString(text) * Scale;

                    var bg = line.Background;
                    if (bg.A == 255)
                    {
                        bg = ColorMath.Fade(line.Background, line.Decay * backgroundAlpha);
                    }

                    debugBatch.FillRectangle(
                        new FRectangle(pos.X - TEXT_OFFSET * Scale, pos.Y, size.X + 2 * TEXT_OFFSET * Scale, size.Y),
                        bg);

                    debugBatch.DrawString(
                        font,
                        text,
                        pos,
                        ColorMath.Fade(line.Color, line.Decay),
                        0,
                        FPoint.Zero,
                        Scale,
                        SpriteEffects.None,
                        0);

                    pos = new FPoint(pos.X + 3 * TEXT_OFFSET * Scale + size.X, pos.Y);
                }
            }

            debugBatch.End();
        }
Esempio n. 4
0
        public static void DrawTextCenteredWithScale(IBatchRenderer sbatch, SpriteFont font, float scale, string text, Color color, FPoint position, float rotation = 0f)
        {
            if (text == "")
            {
                return;
            }
            var bounds = MeasureStringCached(font, text);

            sbatch.DrawString(
                font,
                text,
                position,
                color,
                rotation,
                new FPoint(bounds.Width / 2f, bounds.Height / 2f - GetFontVCenterOffset(font)),
                scale,
                SpriteEffects.None,
                0);
        }
Esempio n. 5
0
        public static void DrawTextTopRight(IBatchRenderer sbatch, SpriteFont font, float size, string text, Color color, FPoint position)
        {
            if (text == "")
            {
                return;
            }

            var bounds = MeasureStringCached(font, text);

            sbatch.DrawString(
                font,
                text,
                position,
                color,
                0,
                new FPoint(bounds.Width, 0),
                GetFontScale(font, size),
                SpriteEffects.None,
                0);
        }
Esempio n. 6
0
        public static void DrawTextVerticallyCentered(IBatchRenderer sbatch, SpriteFont font, float size, string text, Color color, FPoint position)
        {
            if (text == "")
            {
                return;
            }

            var bounds = MeasureStringCached(font, text);

            sbatch.DrawString(
                font,
                text,
                position,
                color,
                0,
                new FPoint(0, bounds.Height / 2f - GetFontVCenterOffset(font)),
                GetFontScale(font, size),
                SpriteEffects.None,
                0);
        }
		public static void DrawTextCentered(IBatchRenderer sbatch, SpriteFont font, float size, string text, Color color, Vector2 position)
		{
			//TODO How expensive is this calculation each draw call ?
			//     perhaps move everything in some kind of fontrendererCache
			//     which remembers all calculated values until text/size/... changes (like with the HUD)

			var scale = GetFontScale(font, size);

			var bounds = font.MeasureString(text);

			sbatch.DrawString(
				font,
				text,
				position,
				color,
				0,
				new Vector2(bounds.X / 2f, bounds.Y / 2f - GetFontVCenterOffset(font)),
				scale,
				SpriteEffects.None,
				0);
		}
Esempio n. 8
0
        public static void DrawTextCenteredWithBackground(IBatchRenderer sbatch, SpriteFont font, float size, string text, Color color, FPoint position, Color background)
        {
            if (text == "")
            {
                return;
            }
            var bounds = MeasureStringCached(font, text);
            var scale  = GetFontScale(font, size);

            sbatch.FillRectangle(FRectangle.CreateByCenter(position, scale * bounds.Width + size / 3f, scale * bounds.Height), background);

            sbatch.DrawString(
                font,
                text,
                position,
                color,
                0,
                new FPoint(bounds.Width / 2f, bounds.Height / 2f - GetFontVCenterOffset(font)),
                scale,
                SpriteEffects.None,
                0);
        }
Esempio n. 9
0
        protected override void DoDraw(IBatchRenderer sbatch, FRectangle bounds)
        {
            var scale = Size.Width * 1f / width;

            FlatRenderHelper.DrawRoundedBlurPanelBackgroundPart(sbatch, bounds, ROUNDNESS);

            if (btnIndex == 0)
            {
                sbatch.DrawScaled(
                    Textures.TexHUDButtonPauseMenuMarkerBackground,
                    Center + new Vector2(width / 2f - HUDPauseButton.DIAMETER / 2f, -(HEIGHT / 2f + MARKER_HEIGHT / 2f)) * scale,
                    scale,
                    Color.White,
                    0f);

                sbatch.DrawScaled(
                    Textures.TexHUDButtonPauseMenuMarker,
                    Center + new Vector2(width / 2f - HUDPauseButton.DIAMETER / 2f, -(HEIGHT / 2f + MARKER_HEIGHT / 2f)) * scale,
                    scale,
                    IsPressed ? FlatColors.Concrete : FlatColors.Silver,
                    0f);
            }

            SimpleRenderHelper.DrawRoundedRect(sbatch, bounds, IsPressed ? FlatColors.Concrete : FlatColors.Silver, ROUNDNESS);

            var fontBounds = Textures.HUDFontBold.MeasureString(btnText).ToFSize();

            sbatch.DrawString(
                Textures.HUDFontBold,
                btnText,
                Center + new Vector2(-width / 2f + 12 + fontScaleFactor * fontBounds.Width / 2f, 0f) * scale,
                FlatColors.Foreground,
                0f,
                fontBounds.Center,
                scale * fontScaleFactor,
                SpriteEffects.None, 0f);
        }
Esempio n. 10
0
        public override void Draw(IBatchRenderer sbatch)
        {
            int ioffX = -(int)(Owner.MapOffsetX / TILE_WIDTH);
            int ioffY = -(int)(Owner.MapOffsetY / TILE_WIDTH);

            int extensionX = MathHelper.Min(MAX_EXTENSION_X, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH));
            int extensionY = MathHelper.Min(MAX_EXTENSION_Y, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH));

            int countX = FloatMath.Ceiling(VAdapter.VirtualTotalWidth / TILE_WIDTH) + 1;
            int countY = FloatMath.Ceiling(VAdapter.VirtualTotalHeight / TILE_WIDTH) + 1;

            for (int ox = ioffX - extensionX; ox < ioffX + countX + extensionX; ox++)
            {
                for (int oy = ioffY - extensionY; oy < ioffY + countY + extensionY; oy++)
                {
                    var x = ox + MAX_EXTENSION_X;                     // real coords -> array coords
                    var y = oy + MAX_EXTENSION_Y;

                    if (x < 0)
                    {
                        continue;
                    }
                    if (y < 0)
                    {
                        continue;
                    }
                    if (x >= tileCountX)
                    {
                        continue;
                    }
                    if (y >= tileCountY)
                    {
                        continue;
                    }

                    var color = GetGridColor(x, y);

                    var rect = new FRectangle(ox * TILE_WIDTH, oy * TILE_WIDTH, TILE_WIDTH, TILE_WIDTH);

                    sbatch.DrawStretched(Textures.TexPixel, rect, color);
                    sbatch.DrawStretched(Textures.TexTileBorder, rect, Color.White);

#if DEBUG
                    if (DebugSettings.Get("DebugBackground"))
                    {
                        var tx = rect.X + 8;
                        var ty = rect.Y + 8;

                        sbatch.DrawString(
                            Textures.DebugFontSmall,
                            string.Format("({4}|{5})\n{0,2}: {1:000}\n[{2}]{3}", _grid[x, y].Fraction?.ToString() ?? "##", _grid[x, y].PowerCurr * 100, _grid[x, y].SourceDistance, _grid[x, y].IsNeutralDraining ? "D" : "", ox, oy),
                            new FPoint(tx, ty),
                            _grid[x, y].Fraction?.Color ?? Color.Black);

                        if (_grid[x, y].SpawnSource != null)
                        {
                            SimpleRenderHelper.DrawCross(sbatch, rect, _grid[x, y].SpawnSource.Fraction.Color * 0.5f, 2);
                        }

                        var v4tl = new Vector2(+5, +5);
                        var v4tr = new Vector2(-5, +5);
                        var v4br = new Vector2(-5, -5);
                        var v4bl = new Vector2(+5, -5);

                        if (_grid[x, y].BlockNorth)
                        {
                            sbatch.DrawLine(rect.TopLeft + v4tl, rect.TopRight + v4tr, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockEast)
                        {
                            sbatch.DrawLine(rect.TopRight + v4tr, rect.BottomRight + v4br, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockSouth)
                        {
                            sbatch.DrawLine(rect.BottomRight + v4br, rect.BottomLeft + v4bl, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockWest)
                        {
                            sbatch.DrawLine(rect.BottomLeft + v4bl, rect.TopLeft + v4tl, Color.Yellow * 0.6f, 4);
                        }
                    }
#endif
                }
            }
        }
Esempio n. 11
0
		public override void Draw(IBatchRenderer sbatch)
		{
			int extensionX = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / GDConstants.TILE_WIDTH);
			int extensionY = FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / GDConstants.TILE_WIDTH);

			for (int x = -extensionX; x < TILE_COUNT_X + extensionX; x++)
			{
				for (int y = -extensionY; y < TILE_COUNT_Y + extensionY; y++)
				{
					var color = GetGridColor(x, y);

					sbatch.Draw(Textures.TexPixel, new Rectangle(x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), color);
					sbatch.Draw(Textures.TexTileBorder, new Rectangle(x * GDConstants.TILE_WIDTH, y * GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH, GDConstants.TILE_WIDTH), Color.White);

#if DEBUG
					if (DebugSettings.Get("DebugBackground"))
					{
						if (x < -1) continue;
						if (y < -1) continue;
						if (x > TILE_COUNT_X) continue;
						if (y > TILE_COUNT_Y) continue;

						var tx = x * GDConstants.TILE_WIDTH + 8;
						var ty = y * GDConstants.TILE_WIDTH + 8;

						sbatch.DrawString(
							Textures.DebugFontSmall,
							string.Format("{0,2}: {1:000}", gridColor[x + 1, y + 1].Fraction?.ToString() ?? "##", gridColor[x + 1, y + 1].Strength * 100),
							new Vector2(tx, ty),
							gridColor[x + 1, y + 1].Fraction?.Color ?? Color.Black);
					}
#endif
				}
			}

#if DEBUG
			if (DebugSettings.Get("DebugBackground"))
			{
				foreach (var particle in Particles)
				{
					sbatch.Draw(
						Textures.TexPixel.Texture,
						new Vector2(particle.X, particle.Y),
						Textures.TexPixel.Bounds,
						particle.Fraction.Color * 0.6f * particle.PowerPercentage,
						0,
						new Vector2(0.5f, 0.5f),
						8,
						SpriteEffects.None, 1);
				}

				sbatch.DrawRectangle(new FRectangle(0, 0, TILE_COUNT_X * GDConstants.TILE_WIDTH, TILE_COUNT_Y * GDConstants.TILE_WIDTH), Color.Magenta);
			}
#endif
		}
		protected override void DoDraw(IBatchRenderer sbatch, FRectangle bounds)
		{
			var scale = Size.Width * 1f / WIDTH;

			FlatRenderHelper.DrawRoundedBlurPanelBackgroundPart(sbatch, bounds, ROUNDNESS_FACTOR);

			if (btnIndex == 0)
			{
				sbatch.Draw(
					Textures.TexHUDButtonPauseMenuMarkerBackground.Texture,
					Center + new Vector2(WIDTH/2f - HUDPauseButton.DIAMETER/2f, -(HEIGHT/2f + MARKER_HEIGHT/2f)) * scale,
					Textures.TexHUDButtonPauseMenuMarkerBackground.Bounds,
					Color.White,
					0f,
					Textures.TexHUDButtonPauseMenuMarkerBackground.Center(),
					scale * Textures.DEFAULT_TEXTURE_SCALE,
					SpriteEffects.None,
					0);

				sbatch.Draw(
					Textures.TexHUDButtonPauseMenuMarker.Texture,
					Center + new Vector2(WIDTH / 2f - HUDPauseButton.DIAMETER / 2f, -(HEIGHT / 2f + MARKER_HEIGHT / 2f)) * scale,
					Textures.TexHUDButtonPauseMenuMarker.Bounds,
					IsPressed ? FlatColors.Concrete : FlatColors.Silver,
					0f,
					Textures.TexHUDButtonPauseMenuMarker.Center(),
					scale * Textures.DEFAULT_TEXTURE_SCALE,
					SpriteEffects.None,
					0);
			}

			FlatRenderHelper.DrawRoundedBlurPanelSolidPart(sbatch, bounds, IsPressed ? FlatColors.Concrete : FlatColors.Silver, ROUNDNESS_FACTOR);

			var fontBounds = Textures.HUDFontBold.MeasureString(btnText);

			sbatch.DrawString(
				Textures.HUDFontBold, 
				btnText, 
				Center + new Vector2(-WIDTH/2f + 12 + fontScaleFactor * fontBounds.X/2f, 0f)*scale, 
				FlatColors.Foreground, 
				0f,
				fontBounds/2f,
				scale * fontScaleFactor, 
				SpriteEffects.None, 0f);
		}