Example #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;
            }
        }
Example #2
0
        protected virtual void OnRenderList(UIList control, CanvasRenderer renderer)
        {
            var rect = control.GetScreenRectangle();

            renderer.AddQuad(rect, new ColorValue(0, 0, 0));
            //renderer.AddQuad( rect, new ColorValue( 0.2, 0.2, 0.2 ) );

            var rect2 = rect;

            rect2.Expand(-control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 2)));

            //border
            var color = new ColorValue(0.75, 0.75, 0.75);

            renderer.AddQuad(new Rectangle(rect.Left, rect.Top, rect2.Left, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect2.Left, rect.Top, rect2.Right, rect2.Top), color);
            renderer.AddQuad(new Rectangle(rect2.Right, rect.Top, rect.Right, rect.Bottom), color);
            renderer.AddQuad(new Rectangle(rect.Left, rect2.Bottom, rect2.Right, rect.Bottom), color);

            var font = control.Font.Value;

            if (font == null)
            {
                font = renderer.DefaultFont;
            }
            var fontSize         = control.GetFontSizeScreen();
            var itemSize         = GetListItemSizeScreen(control, renderer);
            var totalItemsHeight = itemSize * control.Items.Count;
            var scrollBar        = control.GetScrollBar();

            //!!!!тут?
            //update scroll bar properties
            if (scrollBar != null)
            {
                double screenSizeY       = rect2.Size.Y;
                double scrollScreenSizeY = totalItemsHeight - screenSizeY;

                scrollBar.Visible = control.AlwaysShowScrollBar || totalItemsHeight > screenSizeY;
                if (scrollBar.Visible)
                {
                    scrollBar.ValueRange = new Range(0, scrollScreenSizeY);
                }

                //ensure visible
                if (listEnsureVisible != -1)
                {
                    if ((float)listEnsureVisible * itemSize > screenSizeY / 2)
                    {
                        var factor = (float)listEnsureVisible / (float)(control.Items.Count - 1);
                        var v      = scrollScreenSizeY * factor;
                        scrollBar.Value = MathEx.Clamp(v, 0, scrollBar.ValueRange.Value.Maximum);
                    }
                    else
                    {
                        scrollBar.Value = 0;
                    }

                    listEnsureVisible = -1;
                }

                //if( scrollBar.Visible )
                //{
                //	if( scrollScreenSizeY > 0 )
                //	{
                //		double currentScrollScreenPosY = scrollBar.Value * scrollScreenSizeY;

                //		double itemScrollScreenPosY = itemSize * (double)control.SelectedIndex;
                //		Range itemScrollScreenRangeY = new Range( itemScrollScreenPosY, itemScrollScreenPosY + itemSize );

                //		if( itemScrollScreenRangeY.Minimum < currentScrollScreenPosY )
                //		{
                //			currentScrollScreenPosY = itemScrollScreenRangeY.Minimum;
                //		}
                //		else
                //		{
                //			if( itemScrollScreenRangeY.Maximum > currentScrollScreenPosY + screenSizeY )
                //				currentScrollScreenPosY = itemScrollScreenRangeY.Maximum + itemSize - screenSizeY;
                //		}

                //		scrollBar.Value = currentScrollScreenPosY / scrollScreenSizeY;
                //	}
                //	else
                //		scrollBar.Value = 0;
                //}
                //else
                //	scrollBar.Value = 0;
            }

            //items
            if (control.Items.Count != 0)
            {
                renderer.PushClipRectangle(rect2);

                var positionY = rect2.Top;
                if (scrollBar != null && scrollBar.VisibleInHierarchy && scrollBar.EnabledInHierarchy)
                {
                    positionY -= scrollBar.Value;
                }

                for (int n = 0; n < control.Items.Count; n++)
                {
                    var item          = control.Items[n];
                    var itemRectangle = new Rectangle(rect2.Left, positionY, rect2.Right, positionY + itemSize);
                    if (scrollBar != null && scrollBar.EnabledInHierarchy && scrollBar.VisibleInHierarchy)
                    {
                        itemRectangle.Right -= scrollBar.GetScreenSize().X;
                    }

                    if (itemRectangle.Intersects(rect2))
                    {
                        renderer.PushClipRectangle(itemRectangle);

                        if (n == control.SelectedIndex)
                        {
                            var color2 = control.ReadOnlyInHierarchy ? new ColorValue(0.5, 0.5, 0.5) : new ColorValue(0, 0, 0.8);
                            renderer.AddQuad(itemRectangle, color2);
                        }

                        var positionX = rect2.Left + control.GetScreenOffsetByValue(new UIMeasureValueVector2(UIMeasure.Units, 2, 0)).X;
                        renderer.AddText(font, fontSize, item, new Vector2(positionX, itemRectangle.GetCenter().Y), EHorizontalAlignment.Left, EVerticalAlignment.Center, new ColorValue(1, 1, 1));

                        renderer.PopClipRectangle();
                    }

                    positionY += itemSize;
                }

                renderer.PopClipRectangle();
            }
        }