Inheritance: Rectangular
        protected override void OnPaint(ConsoleBitmap context)
        {
            var fullSize = ScrollableContentSize;
            ConsoleBitmap fullyPaintedPanel = new ConsoleBitmap(0, 0, fullSize.Width, fullSize.Height);
            ScrollableContent.PaintTo(fullyPaintedPanel);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    int scrollX = x + HorizontalScrollUnits;
                    int scrollY = y + VerticalScrollUnits;

                    if (scrollX >= fullyPaintedPanel.Width || scrollY >= fullyPaintedPanel.Height)
                    {
                        continue;
                    }

                    var scrolledPixel = fullyPaintedPanel.GetPixel(scrollX, scrollY);

                    if (scrolledPixel.Value.HasValue)
                    {
                        context.Pen = scrolledPixel.Value.Value;
                    }
                    else
                    {
                        context.Pen = new ConsoleCharacter(' ', backgroundColor: Background);
                    }

                    context.DrawPoint(x, y);
                }
            }

            base.OnPaint(context);
        }
 public void Clear()
 {
     Buffer = new ConsoleBitmap(0, 0, this.BufferWidth, this.WindowHeight);
     this.BufferWidth = Buffer.Width;
     this.CursorLeft = 0;
     this.CursorTop = 0;
 }
Example #3
0
        internal override void OnPaint(ConsoleBitmap context)
        {
            base.OnPaint(context);

            int y = 0;
            foreach(var item in ViewModel.Items)
            {
                var displayString = this.HasFocus && y == ViewModel.SelectedIndex && ViewModel.IsSelectionEnabled ? new ConsoleString(item.DisplayText, this.FocusForeground.ForegroundColor) : item.RichDisplayText;
                context.DrawString(displayString, 0, y++);
            }
        }
Example #4
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     #if PROFILING
     using (new TimeProfiler("Grid.OnPaint"))
     {
     #endif
         PaintInternal(context);
     #if PROFILING
     }
     #endif
 }
Example #5
0
 internal override void OnPaint(ConsoleBitmap context)
 {
     foreach (var control in Controls)
     {
         Rectangle scope = context.GetScope();
         try
         {
             context.Rescope(control.X, control.Y, control.Width, control.Height);
             control.Paint(context);
         }
         finally
         {
             context.Scope(scope);
         }
     }
 }
Example #6
0
 /// <summary>
 /// Creates a new console app given a set of boundaries
 /// </summary>
 /// <param name="x">The left position on the target console to bound this app</param>
 /// <param name="y">The right position on the target console to bound this app</param>
 /// <param name="w">The width of the app</param>
 /// <param name="h">The height of the app</param>
 public ConsoleApp(int x, int y, int w, int h)
     : base(ConsoleProvider.Current)
 {
     SetFocusOnStart = true;
     Theme = new Theme();
     Bitmap = new ConsoleBitmap(x, y, w, h);
     LayoutRoot = new ConsolePanel { Width = w, Height = h };
     FocusManager = new FocusManager();
     LayoutRoot.Application = this;
     AutoFillOnConsoleResize = false;
     FocusManager.SubscribeForLifetime(nameof(FocusManager.FocusedControl), Paint, LifetimeManager);
     LayoutRoot.Controls.BeforeAdded.SubscribeForLifetime((c) => { c.Application = this; c.BeforeAddedToVisualTreeInternal(); }, LifetimeManager);
     LayoutRoot.Controls.BeforeRemoved.SubscribeForLifetime((c) => { c.BeforeRemovedFromVisualTreeInternal(); }, LifetimeManager);
     LayoutRoot.Controls.Added.SubscribeForLifetime(ControlAddedToVisualTree, LifetimeManager);
     LayoutRoot.Controls.Removed.SubscribeForLifetime(ControlRemovedFromVisualTree, LifetimeManager);
     WindowResized.SubscribeForLifetime(HandleDebouncedResize, LifetimeManager);
 }
Example #7
0
        public ConsoleApp(int x, int y, int w, int h)
        {
            Bitmap = new ConsoleBitmap(x,y, w, h);
            LayoutRoot = new ConsolePanel { Width = w, Height = h };
            LayoutRoot.Application = this;
            focusableControls = new List<ConsoleControl>();
            focusIndex = -1;
            ExitOnEscapeCharacter = true;
            LayoutRoot.Controls.Added += (c) =>
            {
                c.Application = this;
                if (c.CanFocus) focusableControls.Add(c);

                if (c is ConsolePanel)
                {
                    var children = TraverseControlTree(c as ConsolePanel);
                    focusableControls.AddRange(children.Where(child => child.CanFocus));
                    focusableControls = focusableControls.Distinct().ToList();
                    foreach (var child in children) child.Application = this;
                }
            };

            LayoutRoot.Controls.Removed += (c) =>
            {
                c.Application = null;
                if (c.CanFocus) focusableControls.Remove(c);

                if (c is ConsolePanel)
                {
                    var children = TraverseControlTree(c as ConsolePanel);
                    foreach (var child in children)
                    {
                        focusableControls.Remove(child);
                        child.Application = null;
                    }
                }
            };
        }
Example #8
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // free managed resources
         if (bitmap != null)
         {
             bitmap.Unlock();
             bitmap = null;
         }
     }
 }
Example #9
0
 public PaintOnceContext(ConsoleBitmap bitmap)
 {
     this.bitmap = bitmap;
     bitmap.Lock();
 }
Example #10
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     context.Pen = new ConsoleCharacter(' ', null, myFocusStackDepth == Application.FocusManager.StackDepth ? Theme.DefaultTheme.H1Color : Theme.DefaultTheme.DisabledColor);
     context.DrawLine(0, 0, Width, 0);
     context.DrawLine(0, Height-1, Width, Height-1);
     base.OnPaint(context);
 }
Example #11
0
        /// <summary>
        /// paints the text box
        /// </summary>
        /// <param name="context"></param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var toPaint = textState.CurrentValue;
            var bgTransformed = new List<ConsoleCharacter>();

            foreach(var c in toPaint)
            {
                if(c.BackgroundColor == ConsoleString.DefaultBackgroundColor && Background != ConsoleString.DefaultBackgroundColor)
                {
                    bgTransformed.Add(new ConsoleCharacter(c.Value, Foreground, Background));
                }
                else
                {
                    bgTransformed.Add(c);
                }
            }

            context.DrawString(new ConsoleString(bgTransformed), 0, 0);

            if (blinkState)
            {
                char blinkChar = textState.CursorPosition >= toPaint.Length ? ' ' : toPaint[textState.CursorPosition].Value;
                context.Pen = new ConsoleCharacter(blinkChar, Application.Theme.FocusContrastColor, Application.Theme.FocusColor);
                context.DrawPoint(textState.CursorPosition, 0);
            }
        }
Example #12
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     base.OnPaint(context);
     context.Pen = Value;
     context.DrawPoint(0,0);
 }
Example #13
0
        /// <summary>
        /// paints the button
        /// </summary>
        /// <param name="context">drawing context</param>
        protected override void OnPaint(ConsoleBitmap context)
        {
            var drawState = new ConsoleString();

            drawState = "[".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background = Background);
            if (Text != null)
            {
                ConsoleColor fg, bg;

                if(HasFocus)
                {
                    fg = Application.Theme.FocusContrastColor;
                    bg = Application.Theme.FocusColor;
                }
                else if(CanFocus)
                {
                    fg = Foreground;
                    bg = Background;
                }
                else
                {
                    fg = Application.Theme.DisabledColor;
                    bg = Background;
                }

                drawState += new ConsoleString(Text, fg, bg);

                if(Shortcut != null)
                {
                    if(Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Alt)
                    {
                        drawState += new ConsoleString($" (ALT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Shift)
                    {
                        drawState += new ConsoleString($" (SHIFT+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else if (Shortcut.Modifier.HasValue && Shortcut.Modifier == ConsoleModifiers.Control)
                    {
                        drawState += new ConsoleString($" (CTL+{Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                    else
                    {
                        drawState += new ConsoleString($" ({Shortcut.Key})", CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor);
                    }
                }
            }

            drawState += "]".ToConsoleString(CanFocus ? Application.Theme.H1Color : Application.Theme.DisabledColor, Background);
            Width = drawState.Length;
            context.DrawString(drawState, 0, 0);
        }
 internal void PaintTo(ConsoleBitmap context)
 {
     OnPaint(context);
 }
 protected override void OnPaint(ConsoleBitmap context)
 {
     base.OnPaint(context);
     if (HasFocus)
     {
         context.Pen = new ConsoleCharacter(' ', backgroundColor: Application.Theme.FocusColor);
         context.FillRect(0, 0, Width, Height);
     }
 }
Example #16
0
 protected override void OnPaint(ConsoleBitmap context)
 {
     base.OnPaint(context);
 }
Example #17
0
        private void PaintInternal(ConsoleBitmap context)
        {
            if (this.Height < 5)
            {
                context.DrawString("Grid can't render in a space this small", 0, 0);
                return;
            }

            if (VisibleColumns.Count == 0)
            {
                context.DrawString(NoVisibleColumnsMessage.ToConsoleString(Application.Theme.H1Color), 0, 0);
                return;
            }

            List<ConsoleString> headers = new List<ConsoleString>();
            List<List<ConsoleString>> rows = new List<List<ConsoleString>>();
            List<ColumnOverflowBehavior> overflowBehaviors = new List<ColumnOverflowBehavior>();

            if (VisibleColumns.Where(c => c.WidthPercentage != 0).Count() == 0)
            {
                foreach (var col in VisibleColumns)
                {
                    col.WidthPercentage = 1.0 / VisibleColumns.Count;
                }
            }

            foreach (var header in VisibleColumns)
            {
                headers.Add(header.ColumnDisplayName);
                var colWidth = (int)(header.WidthPercentage * this.Width);

                if (header.OverflowBehavior is SmartWrapOverflowBehavior)
                {
                    (header.OverflowBehavior as SmartWrapOverflowBehavior).MaxWidthBeforeWrapping = colWidth;
                }
                else if (header.OverflowBehavior is TruncateOverflowBehavior)
                {
                    (header.OverflowBehavior as TruncateOverflowBehavior).ColumnWidth = colWidth;
                }

                overflowBehaviors.Add(header.OverflowBehavior);
            }

            int viewIndex = visibleRowOffset;
            foreach (var item in DataView.Items)
            {
                List<ConsoleString> row = new List<ConsoleString>();
                int columnIndex = 0;
                foreach (var col in VisibleColumns)
                {
                    var value = PropertyResolver(item, col.ColumnName.ToString());
                    var displayValue = value == null ? "<null>".ToConsoleString() : (value is ConsoleString ? (ConsoleString)value : value.ToString().ToConsoleString());

                    if (viewIndex == SelectedIndex)
                    {
                        if (this.SelectionMode == GridSelectionMode.Row || (this.SelectionMode == GridSelectionMode.Cell && columnIndex == selectedColumnIndex))
                        {
                            displayValue = new ConsoleString(displayValue.ToString(), this.Background, HasFocus ? Application.Theme.FocusColor : Application.Theme.SelectedUnfocusedColor);
                        }
                    }

                    row.Add(displayValue);
                    columnIndex++;
                }
                viewIndex++;
                rows.Add(row);
            }

            ConsoleTableBuilder builder = new ConsoleTableBuilder();
            ConsoleString table;
            #if PROFILING
            using (new TimeProfiler("Grid.FormatAsTable"))
            {
            #endif
                table = builder.FormatAsTable(headers, rows, RowPrefix.ToString(), overflowBehaviors, Gutter);
            #if PROFILING
            }
            #endif

            if (FilterText != null)
            {
                table = table.Highlight(FilterText, Application.Theme.HighlightContrastColor, Application.Theme.HighlightColor, StringComparison.InvariantCultureIgnoreCase);
            }

            if (DataView.IsViewComplete == false)
            {
                table += "Loading more rows...".ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData && DataView.Items.Count == 0)
            {
                table += NoDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else if (DataView.IsViewEndOfData)
            {
                table += EndOfDataMessage.ToConsoleString(Application.Theme.H1Color);
            }
            else
            {
                table += "more data below".ToConsoleString(Application.Theme.H1Color);
            }
            context.DrawString(table, 0, 0);

            if (FilteringEnabled)
            {

            }
        }
Example #18
0
        protected override void OnPaint(ConsoleBitmap context)
        {
            for(int y = 0; y < lines.Count; y++)
            {
                if(y >= Height)
                {
                    break;
                }

                var line = lines[y];

                for(int x = 0; x < line.Count && x < Width; x++)
                {
                    context.Pen = HasFocus ? new ConsoleCharacter(line[x].Value, Application.Theme.FocusContrastColor, Application.Theme.FocusColor) : line[x];
                    context.DrawPoint(x, y);
                }
            }
        }
        internal void Paint(ConsoleBitmap context)
        {
            if (IsVisible == false)
            {
                return;
            }

            if (TransparentBackground == false)
            {
                context.Pen = new ConsoleCharacter(' ', null, Background);
                context.FillRect(0, 0, Width, Height);
            }

            OnPaint(context);
        }
Example #20
0
 internal virtual void OnPaint(ConsoleBitmap context)
 {
 }
 /// <summary>
 /// You should override this method if you are building a custom control, from scratch, and need to control
 /// every detail of the painting process.  If possible, prefer to create your custom control by deriving from
 /// ConsolePanel, which will let you assemble a new control from others.
 /// </summary>
 /// <param name="context">The scoped bitmap that you can paint on</param>
 protected virtual void OnPaint(ConsoleBitmap context)
 {
 }
Example #22
0
        internal void Paint(ConsoleBitmap context)
        {
            Rectangle scope = context.GetScope();

            if (Background != ConsoleControl.TransparantColor)
            {
                context.Pen = Background;
                context.FillRect(0, 0, Width, Height);
            }

            try
            {
                context.Rescope(this.X, this.Y, this.Width, this.Height);
                context.Pen = this.Foreground;
                OnPaint(context);
            }
            finally
            {
                context.Scope(scope);
            }
        }