Пример #1
0
        /// <summary>
        /// Draw the button
        /// </summary>
        /// <param name="focused">True if button has the focus, false otherwise</param>
        public override void Draw(bool focused)
        {
            int w = GetRight() - GetLeft() + 1;

            // Main button text
            Console.SetCursorPosition(GetLeft(), GetTop());
            Console.BackgroundColor = ConsoleTheme.Current.PopupButtonBg;
            if (focused)
            {
                Console.ForegroundColor = ConsoleTheme.Current.PopupButtonSelectedFg;
            }
            else
            {
                Console.ForegroundColor = ConsoleTheme.Current.PopupButtonFg;
            }
            Console.Write(ScreenObject.PadCenter(caption, w));

            // Right shadow
            Console.BackgroundColor = ConsoleTheme.Current.PopupBg;
            Console.ForegroundColor = ConsoleTheme.Current.PopupButtonShadow;
            Console.Write(Symbols.lowerHalfBlock);

            // Bottom shadow
            Console.SetCursorPosition(GetLeft() + 1, GetTop() + 1);
            Console.Write(shadowStrip);
        }
Пример #2
0
        /// <summary>
        /// Draw the text box
        /// </summary>
        /// <param name="theme">The visual theme to use to draw the dialog</param>
        /// <param name="focused">Framework parameter not relevant to this object</param>
        public override void Draw(ConsoleTheme theme, bool focused)
        {
            int l     = GetLeft();
            int h     = GetBottom() - GetTop() + 1;
            int index = lines.Count < h ? 0 : topLine;
            // Chop one col off the right if we need a scrollbar
            int w = GetRight() - l + 1 + (lines.Count > h ? -1 : 0);

            if (getBgColor != null)
            {
                Console.BackgroundColor = getBgColor(theme);
            }
            else
            {
                Console.BackgroundColor = theme.TextBoxBg;
            }
            if (getFgColor != null)
            {
                Console.ForegroundColor = getFgColor(theme);
            }
            else
            {
                Console.ForegroundColor = theme.TextBoxFg;
            }
            for (int y = GetTop(); y <= GetBottom(); ++y, ++index)
            {
                Console.SetCursorPosition(l, y);
                if (index < lines.Count)
                {
                    switch (align)
                    {
                    case TextAlign.Left:
                        Console.Write(lines[index].PadRight(w));
                        break;

                    case TextAlign.Center:
                        Console.Write(ScreenObject.PadCenter(lines[index], w));
                        break;

                    case TextAlign.Right:
                        Console.Write(lines[index].PadLeft(w));
                        break;
                    }
                }
                else
                {
                    Console.Write("".PadRight(w));
                }
            }

            // Scrollbar
            if (lines.Count > h)
            {
                DrawScrollbar(
                    theme,
                    GetRight(), GetTop(), GetBottom(),
                    GetTop() + 1 + (h - 3) * topLine / (lines.Count - h)
                    );
            }
        }
Пример #3
0
        /// <summary>
        /// Set the focus to a given ScreenObject
        /// </summary>
        /// <param name="so">ScreenObject to focus</param>
        protected void SetFocus(ScreenObject so)
        {
            int index = objects.IndexOf(so);

            if (index >= 0)
            {
                focusIndex = index;
            }
        }
Пример #4
0
        /// <summary>
        /// Draw the outline of the dialog and clear the footer
        /// </summary>
        protected override void DrawBackground()
        {
            int    w = GetRight() - GetLeft() + 1;
            string fullHorizLineDouble = new string(Symbols.horizLineDouble, w - 2);
            string midSpace            = new string(' ', w - 2);

            Console.BackgroundColor = ConsoleTheme.Current.PopupBg;
            Console.ForegroundColor = ConsoleTheme.Current.PopupOutlineFg;
            for (int y = GetTop(); y <= GetBottom(); ++y)
            {
                if (y < 0 || y >= Console.WindowHeight)
                {
                    continue;
                }
                Console.SetCursorPosition(GetLeft(), y);
                if (y == GetTop())
                {
                    // Top row
                    string curTitle = CenterHeader();
                    if (string.IsNullOrEmpty(curTitle))
                    {
                        Console.Write(Symbols.upperLeftCornerDouble + fullHorizLineDouble + Symbols.upperRightCornerDouble);
                    }
                    else
                    {
                        // Title centered
                        Console.Write(Symbols.upperLeftCornerDouble
                                      + ScreenObject.PadCenter($" {curTitle} ", w - 2, Symbols.horizLineDouble)
                                      + Symbols.upperRightCornerDouble);
                    }
                }
                else if (y == GetBottom())
                {
                    // Bottom row
                    Console.Write(Symbols.lowerLeftCornerDouble + fullHorizLineDouble + Symbols.lowerRightCornerDouble);
                }
                else
                {
                    // Blank lines, mostly padding
                    Console.Write(Symbols.vertLineDouble + midSpace + Symbols.vertLineDouble);
                }
            }
            DrawShadow(GetLeft(), GetTop(), GetRight(), GetBottom());
        }
Пример #5
0
 private void Blur(ScreenObject source, bool forward)
 {
     if (objects.Count > 0)
     {
         int loops = 0;
         do
         {
             if (++loops > objects.Count)
             {
                 focusIndex = 0;
                 break;
             }
             if (forward)
             {
                 focusIndex = (focusIndex + 1) % objects.Count;
             }
             else
             {
                 focusIndex = (focusIndex + objects.Count - 1) % objects.Count;
             }
         } while (!objects[focusIndex].Focusable());
     }
 }
Пример #6
0
 /// <summary>
 /// Add a ScreenObject for inclusion in this display
 /// </summary>
 /// <param name="so">ScreenObject to Add</param>
 protected void AddObject(ScreenObject so)
 {
     objects.Add(so);
     so.OnBlur += Blur;
 }