public override void VOnRender(float time, float elapsedTime, Cv_Renderer renderer)
        {
            m_iFrameCounter++;

            string fps          = string.Format(m_Format, "{0} fps", m_iFrameRate);
            var    fontResource = Cv_ResourceManager.Instance.GetResource <Cv_SpriteFontResource>("FramerateCounterFont", "Default");

            if (fontResource != null)
            {
                renderer.BeginDraw();
                renderer.DrawText(fontResource.GetFontData().Font, fps, m_Position + Vector2.One, Color.Black);
                renderer.DrawText(fontResource.GetFontData().Font, fps, m_Position, Color.White);
                renderer.EndDraw();
            }
        }
Example #2
0
        //TODO(JM): Maybe change rendering to draw text into a texture and then reuse texture
        internal override void VRender(Cv_Renderer renderer)
        {
            var textComponent = (Cv_TextComponent)Component;
            var scene         = CaravelApp.Instance.Scene;

            var pos   = scene.Transform.Position;
            var rot   = scene.Transform.Rotation;
            var scale = scene.Transform.Scale;

            var camTransf = scene.Camera.GetViewTransform(renderer.VirtualWidth, renderer.VirtualHeight, Cv_Transform.Identity);

            if (textComponent.Parallax != 1 && textComponent.Parallax != 0)
            {
                var zoomFactor = ((1 + ((scene.Camera.Zoom - 1) * textComponent.Parallax)) / scene.Camera.Zoom);
                scale = scale * zoomFactor; //Magic formula
                pos  += ((textComponent.Parallax - 1) * new Vector3(camTransf.Position.X, camTransf.Position.Y, 0));
                pos  += ((new Vector3(scene.Transform.Position.X, scene.Transform.Position.Y, 0)) * (1 - zoomFactor) * (textComponent.Parallax - 1));
            }

            var noCamera = textComponent.Parallax == 0;

            textComponent.DrawSelectionHighlight(renderer);

            if (!textComponent.Visible || textComponent.Text == null || textComponent.Text == "" || textComponent.FontResource == null || textComponent.FontResource == "")
            {
                return;
            }

            Cv_SpriteFontResource resource = Cv_ResourceManager.Instance.GetResource <Cv_SpriteFontResource>(textComponent.FontResource, textComponent.Owner.ResourceBundle);

            var font = resource.GetFontData().Font;

            var textToDisplay = "";

            if (textComponent.LiteralText)
            {
                textToDisplay = textComponent.Text;
            }
            else
            {
                textToDisplay = CaravelApp.Instance.GetString(textComponent.Text);
            }

            var text = WrapText(textToDisplay, font, textComponent.Width, textComponent.Height);

            var layerDepth = (int)Parent.Position.Z;

            layerDepth = layerDepth % Cv_Renderer.MaxLayers;

            var bounds = new Rectangle((int)(pos.X - (textComponent.Width * scene.Transform.Origin.X)),
                                       (int)(pos.Y - (textComponent.Width * scene.Transform.Origin.Y)),
                                       (int)textComponent.Width,
                                       (int)textComponent.Width);

            renderer.DrawText(font, text, bounds, textComponent.HorizontalAlignment, textComponent.VerticalAlignment, textComponent.Color,
                              rot,
                              Math.Min(scale.X, scale.Y),
                              SpriteEffects.None,
                              layerDepth / (float)Cv_Renderer.MaxLayers, noCamera);
        }