public override void Render(RenderingBuffer buffer)
        {
            Attr attrs;

            if (HasFocus)
            {
                attrs = Colors.Blend(Color.White, Color.DarkGreen);
            }
            else
            {
                attrs = Colors.Blend(Color.Black, Color.DarkCyan);
            }

            buffer.SetPixel(0, 0, ' ', attrs);
            int usedForCurrentItem = 0;

            if (Items.Count != 0 && ActualWidth > 4)
            {
                usedForCurrentItem = RenderString(Items[SelectedItemIndex ?? 0], buffer, 1, 0, ActualWidth - 4, attrs);
            }
            buffer.FillRectangle(1 + usedForCurrentItem, 0, ActualWidth - (usedForCurrentItem + 1), 1, ' ', attrs);
            if (ActualWidth > 2)
            {
                buffer.SetPixel(ActualWidth - 2, 0, opened ? '^' : 'v', attrs);
            }
        }
Exemple #2
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr captionAttrs;

            if (HasFocus)
            {
                captionAttrs = Colors.Blend(Color.White, Color.DarkGreen);
            }
            else
            {
                captionAttrs = Colors.Blend(Color.Black, Color.DarkGreen);
            }

            Attr buttonAttrs = captionAttrs;

//            if ( pressed )
//                buttonAttrs = Colors.Blend(Color.Black, Color.DarkGreen);

            buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3);

            buffer.SetPixel(0, 0, pressed ? '<' : '[', buttonAttrs);
            buffer.SetPixel(1, 0, Checked ? 'X' : ' ', buttonAttrs);
            buffer.SetPixel(2, 0, pressed ? '>' : ']', buttonAttrs);
            buffer.SetPixel(3, 0, ' ', buttonAttrs);
            if (null != caption)
            {
                RenderString(caption, buffer, 4, 0, ActualWidth - 4, captionAttrs);
            }
        }
Exemple #3
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr attr = Colors.Blend(Color.White, Color.DarkBlue);

            buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, ' ', attr);
            if (null != text)
            {
                for (int i = displayOffset; i < text.Length; i++)
                {
                    if (i - displayOffset < ActualWidth - 2 && i - displayOffset >= 0)
                    {
                        buffer.SetPixel(1 + i - displayOffset, 0, text[i]);
                    }
                }
            }
            Attr arrowsAttr = Colors.Blend(Color.Green, Color.DarkBlue);

            if (displayOffset > 0)
            {
                buffer.SetPixel(0, 0, '<', arrowsAttr);
            }
            if (!String.IsNullOrEmpty(text) && ActualWidth - 2 + displayOffset < text.Length)
            {
                buffer.SetPixel(ActualWidth - 1, 0, '>', arrowsAttr);
            }
        }
Exemple #4
0
 protected void RenderBorders(RenderingBuffer buffer, Point a, Point b, bool singleOrDouble, Attr attrs)
 {
     if (singleOrDouble)
     {
         // Corners
         buffer.SetPixel(a.X, a.Y, UnicodeTable.SingleFrameTopLeftCorner, attrs);
         buffer.SetPixel(b.X, b.Y, UnicodeTable.SingleFrameBottomRightCorner, attrs);
         buffer.SetPixel(a.X, b.Y, UnicodeTable.SingleFrameBottomLeftCorner, attrs);
         buffer.SetPixel(b.X, a.Y, UnicodeTable.SingleFrameTopRightCorner, attrs);
         // Horizontal & vertical frames
         buffer.FillRectangle(a.X + 1, a.Y, b.X - a.X - 1, 1, UnicodeTable.SingleFrameHorizontal, attrs);
         buffer.FillRectangle(a.X + 1, b.Y, b.X - a.X - 1, 1, UnicodeTable.SingleFrameHorizontal, attrs);
         buffer.FillRectangle(a.X, a.Y + 1, 1, b.Y - a.Y - 1, UnicodeTable.SingleFrameVertical, attrs);
         buffer.FillRectangle(b.X, a.Y + 1, 1, b.Y - a.Y - 1, UnicodeTable.SingleFrameVertical, attrs);
     }
     else
     {
         // Corners
         buffer.SetPixel(a.X, a.Y, UnicodeTable.DoubleFrameTopLeftCorner, attrs);
         buffer.SetPixel(b.X, b.Y, UnicodeTable.DoubleFrameBottomRightCorner, attrs);
         buffer.SetPixel(a.X, b.Y, UnicodeTable.DoubleFrameBottomLeftCorner, attrs);
         buffer.SetPixel(b.X, a.Y, UnicodeTable.DoubleFrameTopRightCorner, attrs);
         // Horizontal & vertical frames
         buffer.FillRectangle(a.X + 1, a.Y, b.X - a.X - 1, 1, UnicodeTable.DoubleFrameHorizontal, attrs);
         buffer.FillRectangle(a.X + 1, b.Y, b.X - a.X - 1, 1, UnicodeTable.DoubleFrameHorizontal, attrs);
         buffer.FillRectangle(a.X, a.Y + 1, 1, b.Y - a.Y - 1, UnicodeTable.DoubleFrameVertical, attrs);
         buffer.FillRectangle(b.X, a.Y + 1, 1, b.Y - a.Y - 1, UnicodeTable.DoubleFrameVertical, attrs);
     }
 }
        public override void Render(RenderingBuffer buffer)
        {
            Attr captionAttrs;

            if (Disabled)
            {
                captionAttrs = Colors.Blend(Color.Gray, Color.DarkGray);
            }
            else
            {
                if (HasFocus)
                {
                    captionAttrs = Colors.Blend(Color.White, Color.DarkGreen);
                }
                else
                {
                    captionAttrs = Colors.Blend(Color.Black, Color.DarkGreen);
                }
            }

            if (pressed)
            {
                buffer.FillRectangle(1, 0, ActualWidth - 1, ActualHeight - 1, ' ', captionAttrs);
                buffer.SetOpacityRect(0, 0, 1, ActualHeight, 3);
                buffer.FillRectangle(0, 0, 1, ActualHeight, ' ', captionAttrs);
                if (!string.IsNullOrEmpty(Caption))
                {
                    RenderString(Caption, buffer, 2 + 1 + (ActualWidth - 2 * 2 - Caption.Length) / 2,
                                 (ActualHeight - 1) / 2, ActualWidth - 2 * 2, captionAttrs);
                }
                buffer.SetOpacityRect(0, ActualHeight - 1, ActualWidth, 1, 3);
                buffer.FillRectangle(0, ActualHeight - 1, ActualWidth, 1, ' ', Attr.NO_ATTRIBUTES);
            }
            else
            {
                buffer.FillRectangle(0, 0, ActualWidth - 1, ActualHeight, ' ', captionAttrs);
                if (!string.IsNullOrEmpty(Caption))
                {
                    RenderString(Caption, buffer, 2 + (ActualWidth - 2 * 2 - Caption.Length) / 2,
                                 (ActualHeight - 1) / 2, ActualWidth - 2 * 2, captionAttrs);
                }
                buffer.SetPixel(0, ActualHeight - 1, ' ');
                buffer.SetOpacityRect(0, ActualHeight - 1, ActualWidth, 1, 3);
                buffer.FillRectangle(1, ActualHeight - 1, ActualWidth - 1, 1, UnicodeTable.UpperHalfBlock, Attr.NO_ATTRIBUTES);
                buffer.SetOpacityRect(ActualWidth - 1, 0, 1, ActualHeight, 3);
                buffer.FillRectangle(ActualWidth - 1, 1, 1, ActualHeight - 2, UnicodeTable.FullBlock, Attr.NO_ATTRIBUTES);
                buffer.SetPixel(ActualWidth - 1, 0, UnicodeTable.LowerHalfBlock);
            }
        }
Exemple #6
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr selectedAttr = Colors.Blend(Color.White, Color.DarkGreen);
            Attr attr         = Colors.Blend(Color.Black, Color.DarkCyan);
            Attr disabledAttr = Colors.Blend(Color.Gray, Color.DarkCyan);

            for (int y = 0; y < ActualHeight; y++)
            {
                string item = y < items.Count ? items[y] : null;

                if (item != null)
                {
                    Attr currentAttr = disabledItemsIndexes.Contains(y) ? disabledAttr :
                                       (SelectedItemIndex == y ? selectedAttr : attr);

                    buffer.SetPixel(0, y, ' ', currentAttr);
                    if (ActualWidth > 1)
                    {
                        // минус 2 потому что у нас есть по пустому пикселю слева и справа
                        int rendered = RenderString(item, buffer, 1, y, ActualWidth - 2, currentAttr);
                        buffer.FillRectangle(1 + rendered, y, ActualWidth - (1 + rendered), 1, ' ',
                                             currentAttr);
                    }
                }
                else
                {
                    buffer.FillRectangle(0, y, ActualWidth, 1, ' ', attr);
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Рисует исключительно себя - просто фон.
 /// </summary>
 /// <param name="buffer"></param>
 public override void Render(RenderingBuffer buffer)
 {
     for (int x = 0; x < ActualWidth; ++x)
     {
         for (int y = 0; y < ActualHeight; ++y)
         {
             buffer.SetPixel(x, y, ' ', Attr.BACKGROUND_BLUE |
                             Attr.BACKGROUND_GREEN | Attr.BACKGROUND_RED | Attr.FOREGROUND_BLUE |
                             Attr.FOREGROUND_GREEN | Attr.FOREGROUND_RED | Attr.FOREGROUND_INTENSITY);
         }
     }
 }
 private void renderBorderSafe(RenderingBuffer buffer, int x, int y, int x2, int y2)
 {
     if (ActualWidth > x && ActualHeight > y)
     {
         buffer.SetPixel(x, y, UnicodeTable.SingleFrameTopLeftCorner);
     }
     if (ActualWidth > x && ActualHeight > y2 && y2 > y)
     {
         buffer.SetPixel(x, y2, UnicodeTable.SingleFrameBottomLeftCorner);
     }
     if (ActualHeight > y)
     {
         for (int i = x + 1; i <= Math.Min(x2 - 1, ActualWidth - 1); i++)
         {
             buffer.SetPixel(i, y, UnicodeTable.SingleFrameHorizontal);
         }
     }
     if (ActualHeight > y2)
     {
         for (int i = x + 1; i <= Math.Min(x2 - 1, ActualWidth - 1); i++)
         {
             buffer.SetPixel(i, y2, UnicodeTable.SingleFrameHorizontal);
         }
     }
     if (ActualWidth > x)
     {
         for (int j = y + 1; j <= Math.Min(y2 - 1, ActualHeight - 1); j++)
         {
             buffer.SetPixel(x, j, UnicodeTable.SingleFrameVertical);
         }
     }
     if (ActualWidth > x2)
     {
         for (int j = y + 1; j <= Math.Min(y2 - 1, ActualHeight - 1); j++)
         {
             buffer.SetPixel(x2, j, UnicodeTable.SingleFrameVertical);
         }
     }
     if (ActualWidth > x2 && ActualHeight > y && x2 > x)
     {
         buffer.SetPixel(x2, y, UnicodeTable.SingleFrameTopRightCorner);
     }
     if (ActualWidth > x2 && ActualHeight > y2 && y2 > y && x2 > x)
     {
         buffer.SetPixel(x2, y2, UnicodeTable.SingleFrameBottomRightCorner);
     }
 }
Exemple #9
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr attr = Colors.Blend(Color.Black, Color.DarkYellow);

            buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, ' ', attr);
            for (int x = 0; x < ActualWidth; ++x)
            {
                for (int y = 0; y < ActualHeight; ++y)
                {
                    if (y == 0 && x < text.Length)
                    {
                        buffer.SetPixel(x, y, text[x], attr);
                    }
                }
            }
            buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3);
        }
        /// <summary>
        /// Renders string using attr, but if character is prefixed with underscore,
        /// symbol will use specialAttrs instead. To render underscore pass two underscores.
        /// Example: "_File" renders File when 'F' is rendered using specialAttrs.
        /// </summary>
        private static int renderString(string s, RenderingBuffer buffer,
                                        int x, int y, int maxWidth, Attr attr,
                                        Attr specialAttr)
        {
            bool underscore = false;
            int  j          = 0;

            for (int i = 0; i < s.Length && j < maxWidth; i++)
            {
                char c;
                if (underscore)
                {
                    c = s[i];
                }
                else
                {
                    if (s[i] == '_')
                    {
                        underscore = true;
                        continue;
                    }
                    else
                    {
                        c = s[i];
                    }
                }

                Attr a;
                if (j + 2 >= maxWidth && j >= 2 && s.Length > maxWidth)
                {
                    c = '.';
                    a = attr;
                }
                else
                {
                    a = underscore ? specialAttr : attr;
                }
                buffer.SetPixel(x + j, y, c, a);

                j++;
                underscore = false;
            }
            return(j);
        }
Exemple #11
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr attr = Colors.Blend(Color.DarkCyan, Color.DarkBlue);

            buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 2);

            if (horizontalScrollVisible)
            {
                buffer.SetOpacityRect(0, ActualHeight - 1, ActualWidth, 1, 0);
                buffer.SetPixel(0, ActualHeight - 1, UnicodeTable.ArrowLeft, attr); // ◄
                // оставляем дополнительный пиксель справа, если одновременно видны оба скроллбара
                int rightOffset = verticalScrollVisible ? 1 : 0;
                if (ActualWidth > 2 + rightOffset)
                {
                    buffer.FillRectangle(1, ActualHeight - 1, ActualWidth - (2 + rightOffset), 1,
                                         UnicodeTable.MediumShade, attr); // ▒
                }
                if (ActualWidth > 1 + rightOffset)
                {
                    buffer.SetPixel(ActualWidth - (1 + rightOffset), ActualHeight - 1,
                                    UnicodeTable.ArrowRight, attr); // ►
                }

                // определим, в каком месте находится ползунок
                if (ActualWidth > 3 + (verticalScrollVisible ? 1 : 0))
                {
                    int remainingWidth = ActualWidth - (verticalScrollVisible ? 1 : 0);
                    int extraWidth     = Content.RenderSize.Width - remainingWidth;
                    int pages          = extraWidth / (remainingWidth - 2 - 1);

                    //Debugger.Log( 1, "", "pages: " + pages + "\n" );

                    int scrollerPos;
                    if (pages == 0)
                    {
                        double posInDelta = (remainingWidth * 1.0 - 2 - 1) / extraWidth;
                        //Debugger.Log( 1, "", "posInDelta: " + posInDelta + "\n" );
                        scrollerPos = ( int )Math.Round(posInDelta * deltaX);
                    }
                    else
                    {
                        double deltaInPos = (extraWidth * 1.0) / (remainingWidth - 2 - 1);
                        //Debugger.Log( 1, "", "deltaX/( deltaInPos ): " + deltaX/( deltaInPos ) + "\n" );
                        scrollerPos = ( int )Math.Round(deltaX / (deltaInPos));
                    }

                    buffer.SetPixel(1 + scrollerPos, ActualHeight - 1, UnicodeTable.BlackSquare, attr); // ■
                }
                else if (ActualWidth == 3 + (verticalScrollVisible ? 1 : 0))
                {
                    buffer.SetPixel(1, ActualHeight - 1, UnicodeTable.BlackSquare, attr); // ■
                }
            }
            if (verticalScrollVisible)
            {
                buffer.SetOpacityRect(ActualWidth - 1, 0, 1, ActualHeight, 0);

                buffer.SetPixel(ActualWidth - 1, 0, UnicodeTable.ArrowUp, attr); // ▲
                // оставляем дополнительный пиксель снизу, если одновременно видны оба скроллбара
                int downOffset = horizontalScrollVisible ? 1 : 0;
                if (ActualHeight > 2 + downOffset)
                {
                    buffer.FillRectangle(ActualWidth - 1, 1, 1, ActualHeight - (2 + downOffset), UnicodeTable.MediumShade, attr); // ▒
                }
                if (ActualHeight > 1 + downOffset)
                {
                    buffer.SetPixel(ActualWidth - 1, ActualHeight - (1 + downOffset), UnicodeTable.ArrowDown, attr); // ▼
                }

                // определим, в каком месте находится ползунок
                if (ActualHeight > 3 + (horizontalScrollVisible ? 1 : 0))
                {
                    int remainingHeight = ActualHeight - (horizontalScrollVisible ? 1 : 0);
                    int extraHeight     = Content.RenderSize.Height - remainingHeight;
                    int pages           = extraHeight / (remainingHeight - 2 - 1);

                    //Debugger.Log( 1, "", "pages: " + pages + "\n" );

                    int scrollerPos;
                    if (pages == 0)
                    {
                        double posInDelta = (remainingHeight * 1.0 - 2 - 1) / extraHeight;
                        //Debugger.Log( 1, "", "posInDelta: " + posInDelta + "\n" );
                        scrollerPos = ( int )Math.Round(posInDelta * deltaY);
                    }
                    else
                    {
                        double deltaInPos = (extraHeight * 1.0) / (remainingHeight - 2 - 1);
                        //Debugger.Log( 1, "", "deltaY/( deltaInPos ): " + deltaY/( deltaInPos ) + "\n" );
                        scrollerPos = ( int )Math.Round(deltaY / (deltaInPos));
                    }

                    buffer.SetPixel(ActualWidth - 1, 1 + scrollerPos, UnicodeTable.BlackSquare, attr); // ■
                }
                else if (ActualHeight == 3 + (horizontalScrollVisible ? 1 : 0))
                {
                    buffer.SetPixel(ActualWidth - 1, 1, UnicodeTable.BlackSquare, attr); // ■
                }
            }
            if (horizontalScrollVisible && verticalScrollVisible)
            {
                buffer.SetPixel(ActualWidth - 1, ActualHeight - 1, UnicodeTable.SingleFrameBottomRightCorner, attr); // ┘
            }
        }
Exemple #12
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr attr = Colors.Blend(Color.Black, Color.DarkGreen);

            // прозрачный фон для рамки
            buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3);
            // полностью прозрачный внутри
            if (ActualWidth > 2 && ActualHeight > 2)
            {
                buffer.SetOpacityRect(1, 1, ActualWidth - 2, ActualHeight - 2, 2);
            }
            // title
            int titleRenderedWidth = 0;

            if (!string.IsNullOrEmpty(title))
            {
                titleRenderedWidth = RenderString(title, buffer, 2, 0, ActualWidth - 4, attr);
            }
            // upper border
            for (int x = 0; x < ActualWidth; x++)
            {
                char?c = null;
                if (x == 0)
                {
                    c = UnicodeTable.SingleFrameTopLeftCorner;
                }
                else if (x == ActualWidth - 1)
                {
                    c = UnicodeTable.SingleFrameTopRightCorner;
                }
                else if (x == 1 || x == 2 + titleRenderedWidth)
                {
                    c = ' ';
                }
                else if (x > 2 + titleRenderedWidth && x < ActualWidth - 1)
                {
                    c = UnicodeTable.SingleFrameHorizontal;
                }
                if (c != null)
                {
                    buffer.SetPixel(x, 0, c.Value, attr);
                }
            }
            // left border
            if (ActualHeight > 2)
            {
                buffer.FillRectangle(0, 1, 1, ActualHeight - 2, UnicodeTable.SingleFrameVertical, attr);
            }
            if (ActualHeight > 1)
            {
                buffer.SetPixel(0, ActualHeight - 1, UnicodeTable.SingleFrameBottomLeftCorner, attr);
            }
            // right border
            if (ActualWidth > 1)
            {
                if (ActualHeight > 2)
                {
                    buffer.FillRectangle(ActualWidth - 1, 1, 1, ActualHeight - 2, UnicodeTable.SingleFrameVertical, attr);
                }
                if (ActualHeight > 1)
                {
                    buffer.SetPixel(ActualWidth - 1, ActualHeight - 1, UnicodeTable.SingleFrameBottomRightCorner, attr);
                }
            }
            // bottom border
            if (ActualHeight > 1 && ActualWidth > 2)
            {
                buffer.FillRectangle(1, ActualHeight - 1, ActualWidth - 2, 1, UnicodeTable.SingleFrameHorizontal, attr);
            }
        }
Exemple #13
0
        public override void Render(RenderingBuffer buffer)
        {
            Attr borderAttrs = moving ? Colors.Blend(Color.Green, Color.Gray) : Colors.Blend(Color.White, Color.Gray);

            // background
            buffer.FillRectangle(0, 0, this.ActualWidth, this.ActualHeight, ' ', borderAttrs);
            // Borders
            RenderBorders(buffer, new Point(0, 0), new Point(ActualWidth - 3, ActualHeight - 2),
                          this.moving || this.resizing, borderAttrs);
            // close button
            if (ActualWidth > 4)
            {
                buffer.SetPixel(2, 0, '[');
                buffer.SetPixel(3, 0, showClosingGlyph ? UnicodeTable.WindowClosePressedSymbol : UnicodeTable.WindowCloseSymbol,
                                Colors.Blend(Color.Green, Color.Gray));
                buffer.SetPixel(4, 0, ']');
            }
            // shadows
            buffer.SetOpacity(0, ActualHeight - 1, 2 + 4);
            buffer.SetOpacity(1, ActualHeight - 1, 2 + 4);
            buffer.SetOpacity(ActualWidth - 1, 0, 2 + 4);
            buffer.SetOpacity(ActualWidth - 2, 0, 2 + 4);
            buffer.SetOpacityRect(2, ActualHeight - 1, ActualWidth - 2, 1, 1 + 4);
            buffer.SetOpacityRect(ActualWidth - 2, 1, 2, ActualHeight - 1, 1 + 4);
            // title
            if (!string.IsNullOrEmpty(Title))
            {
                int    titleStartX          = 7;
                bool   renderTitle          = false;
                string renderTitleString    = null;
                int    availablePixelsCount = ActualWidth - titleStartX * 2;
                if (availablePixelsCount > 0)
                {
                    renderTitle = true;
                    if (Title.Length <= availablePixelsCount)
                    {
                        // dont truncate title
                        titleStartX      += (availablePixelsCount - Title.Length) / 2;
                        renderTitleString = Title;
                    }
                    else
                    {
                        renderTitleString = Title.Substring(0, availablePixelsCount);
                        if (renderTitleString.Length > 2)
                        {
                            renderTitleString = renderTitleString.Substring(0, renderTitleString.Length - 2) + "..";
                        }
                        else
                        {
                            renderTitle = false;
                        }
                    }
                }
                if (renderTitle)
                {
                    // assert !string.IsNullOrEmpty(renderingTitleString);
                    buffer.SetPixel(titleStartX - 1, 0, ' ', borderAttrs);
                    for (int i = 0; i < renderTitleString.Length; i++)
                    {
                        buffer.SetPixel(titleStartX + i, 0, renderTitleString[i], borderAttrs);
                    }
                    buffer.SetPixel(titleStartX + renderTitleString.Length, 0, ' ', borderAttrs);
                }
            }
        }