Exemple #1
0
        public void DrawFloatingMessage(Camera camera, string message, float factor)
        {
            BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles");

            if (!camera.Eye.HasValue)
            {
                Vector2 position = camera.ViewportSize / 2f;
                position.X += 0.07f * camera.ViewportSize.X * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position.Y += 0.07f * camera.ViewportSize.Y * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 1, DepthStencilState.None, null, BlendState.AlphaBlend);
                int         count       = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(message, position, 0f, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.One * camera.GameWidget.GlobalScale, Vector2.Zero);
                fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
                fontBatch2D.Flush();
            }
            else
            {
                Vector3 position2 = -4f * Vector3.UnitZ;
                position2.X += 0.28f * (float)MathUtils.Sin(1.7300000190734863 * Time.FrameStartTime);
                position2.Y += 0.28f * (float)MathUtils.Cos(1.1200000047683716 * Time.FrameStartTime);
                FontBatch3D fontBatch3D = m_primitivesRenderer3D.FontBatch(font, 1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend);
                fontBatch3D.QueueText(message, position2, 0.008f * Vector3.UnitX, -0.008f * Vector3.UnitY, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.Zero);
                fontBatch3D.Flush(camera.ProjectionMatrix);
            }
        }
Exemple #2
0
        public void DrawMessage(Camera camera, string message, float factor)
        {
            BitmapFont font = ContentManager.Get <BitmapFont>("Fonts/Pericles");

            if (!camera.Eye.HasValue)
            {
                Vector2     position    = new Vector2(camera.ViewportSize.X / 2f, camera.ViewportSize.Y - 25f);
                FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 0, DepthStencilState.None, null, BlendState.AlphaBlend);
                int         count       = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(message, position, 0f, Color.Gray * factor, TextAnchor.HorizontalCenter | TextAnchor.Bottom, Vector2.One * camera.GameWidget.GlobalScale, Vector2.Zero);
                fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
                fontBatch2D.Flush();
            }
            else
            {
                Vector3     position2   = -4f * Vector3.UnitZ + -0.24f / camera.ProjectionMatrix.M22 * 2f * Vector3.UnitY;
                FontBatch3D fontBatch3D = m_primitivesRenderer3D.FontBatch(font, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend);
                fontBatch3D.QueueText(message, position2, 0.0104f * Vector3.UnitX, -0.0104f * Vector3.UnitY, Color.White * factor, TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter, Vector2.Zero);
                fontBatch3D.Flush(camera.ProjectionMatrix);
            }
        }
Exemple #3
0
        public override void Draw(DrawContext dc)
        {
            Color color = Color * base.GlobalColorTransform;

            if (!string.IsNullOrEmpty(m_text))
            {
                Vector2      position     = new Vector2(0f - m_scroll, base.ActualSize.Y / 2f);
                SamplerState samplerState = TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp;
                FontBatch2D  fontBatch2D  = dc.PrimitivesRenderer2D.FontBatch(Font, 1, DepthStencilState.None, null, null, samplerState);
                int          count        = fontBatch2D.TriangleVertices.Count;
                fontBatch2D.QueueText(Text, position, 0f, color, TextAnchor.VerticalCenter, new Vector2(FontScale), FontSpacing);
                fontBatch2D.TransformTriangles(base.GlobalTransform, count);
            }
            if (!m_hasFocus || !(MathUtils.Remainder(Time.RealTime - m_focusStartTime, 0.5) < 0.25))
            {
                return;
            }
            float   num = Font.CalculateCharacterPosition(Text, CaretPosition, new Vector2(FontScale), FontSpacing);
            Vector2 v   = new Vector2(0f, base.ActualSize.Y / 2f) + new Vector2(num - m_scroll, 0f);

            if (m_hasFocus)
            {
                if (v.X < 0f)
                {
                    m_scroll = MathUtils.Max(m_scroll + v.X, 0f);
                }
                if (v.X > base.ActualSize.X)
                {
                    m_scroll += v.X - base.ActualSize.X + 1f;
                }
            }
            FlatBatch2D flatBatch2D = dc.PrimitivesRenderer2D.FlatBatch(1, DepthStencilState.None);
            int         count2      = flatBatch2D.TriangleVertices.Count;

            flatBatch2D.QueueQuad(v - new Vector2(0f, Font.GlyphHeight / 2f * FontScale * Font.Scale), v + new Vector2(1f, Font.GlyphHeight / 2f * FontScale * Font.Scale), 0f, color);
            flatBatch2D.TransformTriangles(base.GlobalTransform, count2);
        }
Exemple #4
0
 public override void Draw(DrawContext dc)
 {
     if (!string.IsNullOrEmpty(Text) && Color.A != 0)
     {
         SamplerState samplerState = TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp;
         FontBatch2D  fontBatch2D  = dc.PrimitivesRenderer2D.FontBatch(Font, 1, DepthStencilState.None, null, null, samplerState);
         int          count        = fontBatch2D.TriangleVertices.Count;
         float        num          = 0f;
         if ((TextAnchor & TextAnchor.VerticalCenter) != 0)
         {
             float num2 = Font.GlyphHeight * FontScale * Font.Scale + (float)(m_lines.Count - 1) * ((Font.GlyphHeight + Font.Spacing.Y) * FontScale * Font.Scale + FontSpacing.Y);
             num = (base.ActualSize.Y - num2) / 2f;
         }
         else if ((TextAnchor & TextAnchor.Bottom) != 0)
         {
             float num3 = Font.GlyphHeight * FontScale * Font.Scale + (float)(m_lines.Count - 1) * ((Font.GlyphHeight + Font.Spacing.Y) * FontScale * Font.Scale + FontSpacing.Y);
             num = base.ActualSize.Y - num3;
         }
         TextAnchor anchor = TextAnchor & ~(TextAnchor.VerticalCenter | TextAnchor.Bottom);
         Color      color  = Color * base.GlobalColorTransform;
         float      num4   = CalculateLineHeight();
         foreach (string line in m_lines)
         {
             float x = 0f;
             if ((TextAnchor & TextAnchor.HorizontalCenter) != 0)
             {
                 x = base.ActualSize.X / 2f;
             }
             else if ((TextAnchor & TextAnchor.Right) != 0)
             {
                 x = base.ActualSize.X;
             }
             bool    flag   = true;
             Vector2 vector = Vector2.Zero;
             float   angle  = 0f;
             if (TextOrientation == TextOrientation.Horizontal)
             {
                 vector = new Vector2(x, num);
                 angle  = 0f;
                 _      = Display.ScissorRectangle;
                 flag   = true;
             }
             else if (TextOrientation == TextOrientation.VerticalLeft)
             {
                 vector = new Vector2(x, base.ActualSize.Y + num);
                 angle  = MathUtils.DegToRad(-90f);
                 flag   = true;
             }
             if (flag)
             {
                 if (DropShadow)
                 {
                     fontBatch2D.QueueText(line, vector + 1f * new Vector2(FontScale), 0f, new Color((byte)0, (byte)0, (byte)0, color.A), anchor, new Vector2(FontScale), FontSpacing, angle);
                 }
                 fontBatch2D.QueueText(line, vector, 0f, color, anchor, new Vector2(FontScale), FontSpacing, angle);
             }
             num += num4;
         }
         fontBatch2D.TransformTriangles(base.GlobalTransform, count);
     }
 }