Esempio n. 1
0
        public static void PerformRenderUI()
        {
            CanvasRenderer renderer = MainViewport.CanvasRenderer;

            if (transparency == 0.0f)
            {
                return;
            }

            //load backgrouund texture and font
            if (texture != null && texture.Disposed)
            {
                needLoadTextureAndFont = true;
            }
            if (needLoadTextureAndFont)
            {
                texture = ResourceManager.LoadResource <Component_Image>("Base\\UI\\Images\\Console.png");
                //texture = ResourceManager.LoadResource<Component_Image>( "Base\\UI\\Images\\Console.jpg" );

                font = renderer.DefaultFont;
                //font = EngineFontManager.Instance.LoadFont( "Default", .025f );
                needLoadTextureAndFont = false;
            }

            if (font == null)
            {
                return;
            }

            Vector2F viewportSize = renderer.ViewportForScreenCanvasRenderer.SizeInPixels.ToVector2F();
            Vector2F shadowOffset = new Vector2F(1, 1) / viewportSize;

            //draw background
            var textureRect = new Rectangle(0, 0, 10 * renderer.AspectRatio, 10 / 2);

            textureRect -= textureOffset;
            renderer.AddQuad(new Rectangle(0, 0, 1, .5f), textureRect, texture, new ColorValue(1, 1, 1, transparency), false);

            //var textureRect = new Rectangle( 0, 1.0 - renderer.AspectRatioInv, 1, 1 );
            //renderer.AddQuad( new Rectangle( 0, 0, 1, .5f ), textureRect, texture, new ColorValue( 0.7, 0.7, 0.7, transparency ), false );

            //draw border line
            renderer.AddQuad(new Rectangle(0, .5f, 1, .508f), new ColorValue(0.29f, 0.6f, 0.86f, 0.9f * transparency));

            //draw background info
            string staticText = "Press \"~\" or \"F12\" to hide console\r\nPress \"Ctrl + ~\" to hide and disable auto opening";

            renderer.AddTextWordWrap(staticText, new RectangleF(0, 0, .995f, .495f), EHorizontalAlignment.Right, false, EVerticalAlignment.Bottom, 0,
                                     new ColorValue(0.8, 0.8, 0.8, transparency));

            float fontheight = (float)fontSize;            // font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

            if (stringDownPosition != strings.Count - 1)
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
            {
                str = currentString + "_";
            }

            renderer.PushClipRectangle(new RectangleF(0, 0, .975f, 1));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y) + shadowOffset, EHorizontalAlignment.Left,
                             EVerticalAlignment.Center, new ColorValue(0, 0, 0, transparency / 2));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y), EHorizontalAlignment.Left,
                             EVerticalAlignment.Center, new ColorValue(1, 1, 1, transparency));
            renderer.PopClipRectangle();

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;

            if (startpos > strings.Count - 1)
            {
                startpos = strings.Count - 1;
            }
            for (int n = startpos; n >= 0 && y - fontheight > 0; n--)
            {
                var text      = strings[n].text;
                int lineCount = text.Count(f => f == '\n') + 1;

                float y2 = y - fontheight * (lineCount - 1) / 2;

                renderer.AddText(font, fontSize, text, new Vector2F(x, y2) + shadowOffset, EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(0, 0, 0, transparency / 2));
                renderer.AddText(font, fontSize, text, new Vector2F(x, y2), EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight * lineCount;
            }
        }