Esempio n. 1
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr attr         = Colors.Blend(Color.Black, Color.DarkGreen);
            Attr inactiveAttr = Colors.Blend(Color.DarkGray, Color.DarkGreen);

            // Transparent background for borders
            buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3);

            buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, ' ', attr);

            // Transparent child content part
            if (ActualWidth > 2 && ActualHeight > 3)
            {
                buffer.SetOpacityRect(1, 3, ActualWidth - 2, ActualHeight - 4, 2);
            }

            renderBorderSafe(buffer, 0, 2, Math.Max(getTabHeaderWidth( ) - 1, ActualWidth - 1), ActualHeight - 1);

            // Start to render header
            buffer.FillRectangle(0, 0, ActualWidth, Math.Min(2, ActualHeight), ' ', attr);

            int x = 0;

            // Render tabs before active tab
            for (int tab = 0; tab < tabDefinitions.Count; x += TabDefinitions[tab++].Title.Length + 3)
            {
                var tabDefinition = TabDefinitions[tab];
                if (tab <= activeTabIndex)
                {
                    buffer.SetPixelSafe(x, 0, UnicodeTable.SingleFrameTopLeftCorner);
                    buffer.SetPixelSafe(x, 1, UnicodeTable.SingleFrameVertical);
                }
                if (tab == activeTabIndex)
                {
                    buffer.SetPixelSafe(x, 2,
                                        activeTabIndex == 0 ? UnicodeTable.SingleFrameVertical : UnicodeTable.SingleFrameBottomRightCorner);
                }
                for (int i = 0; i < tabDefinition.Title.Length + 2; i++)
                {
                    buffer.SetPixelSafe(x + 1 + i, 0, UnicodeTable.SingleFrameHorizontal);
                    if (tab == activeTabIndex)
                    {
                        buffer.SetPixelSafe(x + 1 + i, 2, ' ');
                    }
                }
                buffer.RenderStringSafe(" " + tabDefinition.Title + " ", x + 1, 1,
                                        activeTabIndex == tab ? attr : inactiveAttr);
                if (tab >= activeTabIndex)
                {
                    buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 0, UnicodeTable.SingleFrameTopRightCorner);
                    buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 1, UnicodeTable.SingleFrameVertical);
                }
                if (tab == activeTabIndex)
                {
                    buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 2,
                                        activeTabIndex == tabDefinitions.Count - 1 && ActualWidth - 1 == x + tabDefinition.Title.Length + 3
                            ? UnicodeTable.SingleFrameVertical
                            : UnicodeTable.SingleFrameBottomLeftCorner);
                }
            }
        }