Ejemplo n.º 1
0
        /// <summary>
        /// Raises the DrawContents event.
        /// </summary>
        /// <param name="screen">screen where the window is redrawn</param>
        /// <param name="hasFocus">true if the window is in application focus</param>
        ///
        protected override void OnDrawContents(Screen screen, bool hasFocus)
        {
            if (screen == null)
            {
                return;
            }

            // Setup item colors for header
            //
            if (hasFocus)
            {
                screen.BackColor = HeaderBackColor;
                screen.ForeColor = HeaderForeColor;
            }
            else
            {
                screen.BackColor = HeaderBackColorInact;
                screen.ForeColor = HeaderForeColorInact;
            }

            // Draw header
            //
            for (int row = 0; row < HeaderHeight; ++row)
            {
                string text = Header[row];

                if (text == WideDivider)   // 'wide'-divider drawn in border
                {
                    continue;
                }
                else if (text == ShortDivider)   // 'short'-divider
                {
                    text = string.Empty.PadRight(ClientWidth, '─');
                }

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                screen.CursorTop  = row;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            // Visible rows belongs to half-open range [ startRow, lastRow )
            //
            int startRow = Math.Max(0, ViewFrom);
            int lastRow  = Math.Min(ItemCount, ViewFrom + ViewHeight);

            for (int row = startRow; row < lastRow; ++row)
            {
                string text = row >= Items.Count ? string.Empty : Items[row].Text;

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                // Setup item colors
                //
                if (hasFocus)
                {
                    if (row == CurrentItem)
                    {
                        screen.BackColor = CurrentRowBackColor;
                        screen.ForeColor = CurrentRowForeColor;
                    }
                    else
                    {
                        screen.BackColor = BackColor;
                        screen.ForeColor = ForeColor;
                    }
                }
                else if (row == CurrentItem)
                {
                    screen.BackColor = CurrentRowBackColorInact;
                    screen.ForeColor = CurrentRowForeColorInact;
                }
                else
                {
                    screen.BackColor = BackColorInact;
                    screen.ForeColor = ForeColorInact;
                }

                screen.CursorTop  = HeaderHeight + row - ViewFrom;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            // Setup item colors for footer
            //
            if (hasFocus)
            {
                screen.BackColor = FooterBackColor;
                screen.ForeColor = FooterForeColor;
            }
            else
            {
                screen.BackColor = FooterBackColorInact;
                screen.ForeColor = FooterForeColorInact;
            }

            // Draw footer
            //
            for (int row = 0; row < FooterHeight; ++row)
            {
                string text = Footer[row];

                if (text == WideDivider)   // 'wide'-divider drawn in border
                {
                    continue;
                }
                else if (text == ShortDivider)   // 'short'-divider
                {
                    text = string.Empty.PadRight(ClientWidth, '─');
                }

                text = TaggedText.AlignedText(text, ClientWidth,
                                              TextAlign.Left, HorizontalPadding, HorizontalPadding);

                screen.CursorTop  = ClientHeight - FooterHeight + row;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            base.OnDrawContents(screen, hasFocus);
        }
Ejemplo n.º 2
0
        /////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Draws default border, caption and scroll bar for the window.
        /// </summary>
        /// <remarks>
        /// Border is drawn depending on Border, Caption and VerticalScrollBar flags:
        /// <pre>
        ///              No Border           With Border           With Border
        ///                                                        and Caption
        ///
        ///          Without Scrollbar:                           ┌──────────────┐
        ///                                                       │██████████████│
        ///                                 ┌──────────────┐      ├──────────────┤
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒▒▒     │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│      │▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
        ///                                 └──────────────┘      └──────────────┘
        ///
        ///          With Scrollbar:                              ┌──────────────┐
        ///                                                       │██████████████│
        ///                                 ┌────────────┬─┐      ├────────────┬─┤
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│▲     │▒▒▒▒▒▒▒▒▒▒▒▒│▲│      │▒▒▒▒▒▒▒▒▒▒▒▒│▲│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│█     │▒▒▒▒▒▒▒▒▒▒▒▒│█│      │▒▒▒▒▒▒▒▒▒▒▒▒│█│
        ///              ▒▒▒▒▒▒▒▒▒▒▒▒│▼     │▒▒▒▒▒▒▒▒▒▒▒▒│▼│      │▒▒▒▒▒▒▒▒▒▒▒▒│▼│
        ///                                 └────────────┴─┘      └────────────┴─┘
        /// </pre>
        ///
        /// 3D-shadow of the border might be drawn using:
        /// <code>
        ///
        /// screen.SetColors( Left + 1, Top + Height + 1, Width + 2, 1,
        ///     Color.Black, Color.Black );
        ///
        /// screen.SetColors( Left + Width + 1, Top + 1, 2, Height,
        ///     Color.Black, Color.Black );
        ///
        /// </code>
        ///
        /// </remarks>
        ///
        public void DefaultDrawBorder(Screen screen, bool hasFocus)
        {
            ColorContext savedColors = new ColorContext(screen);

            bool hasScrollbar = VerticalScrollBar && Height >= 2 && Width >= 3;

            if (Border && !CaptionVisible)
            {
                // Draw normal window border without caption but with optional
                // border margin
                //
                screen.DrawRectangle(-1, -1, Width + 2, Height + 2);
            }
            else if (Border)
            {
                // Draw expanded window border for caption
                //
                screen.DrawRectangle(-1, -3, Width + 2, Height + 4);

                // Draw separator between window contents and caption
                //
                screen.Put(-1, -1, Box._UDsR);
                screen.Put(Width, -1, Box._UDLs);
                screen.DrawRectangle(0, -1, Width, 1);
            }

            // Draw vertical scrollbar with optional frame
            //
            if (hasScrollbar)
            {
                int reducedWidth = Width - 2;

                // Draw separator between window contents and scroll bar
                //
                if (Border)
                {
                    screen.DrawRectangle(reducedWidth, 0, 1, Height);
                    screen.Put(reducedWidth, -1, Box._sDLR);
                    screen.Put(reducedWidth, Height, Box._UsLR);
                }
                else
                {
                    screen.DrawRectangle(reducedWidth, 0, 1, Height);
                    screen.DrawRectangle(reducedWidth + 2, 0, 1, Height);
                }

                // Draw vertical scroll bar

                if (hasFocus)
                {
                    screen.ForeColor = ScrollBarForeColor;
                }
                else
                {
                    screen.ForeColor = ScrollBarForeColorInact;
                }

                screen.DrawVerticalScrollBar(reducedWidth + 1, 0, Height,
                                             VerticalScrollBarFirstItem, VerticalScrollBarLastItem,
                                             VerticalScrollBarItemCount);
            }

            // Write caption
            //
            if (Border & CaptionVisible & Caption != null)
            {
                if (hasFocus)
                {
                    screen.BackColor = CaptionBackColor;
                    screen.ForeColor = CaptionForeColor;
                }
                else
                {
                    screen.BackColor = CaptionBackColorInact;
                    screen.ForeColor = CaptionForeColorInact;
                }

                string text = TaggedText.AlignedText(Caption, Width,
                                                     CaptionTextAlign, CaptionIndent, CaptionIndent);

                screen.CursorTop  = -2;
                screen.CursorLeft = 0;
                screen.Write(text);
            }

            savedColors.Restore();
        }