Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void UpdateAndDraw(ControlBase control, TimeSpan time)
        {
            if (!control.IsDirty)
            {
                return;
            }
            if (!(control is ProgressBar progressbar))
            {
                return;
            }

            RefreshTheme(control.FindThemeColors(), control);

            ColoredGlyph foregroundAppearance  = Foreground.GetStateAppearance(control.State);
            ColoredGlyph backgroundAppearance  = Background.GetStateAppearance(control.State);
            ColoredGlyph displayTextAppearance = DisplayText.GetStateAppearance(control.State);

            progressbar.Surface.Fill(backgroundAppearance.Foreground, backgroundAppearance.Background, backgroundAppearance.Glyph);

            if (progressbar.IsHorizontal)
            {
                Rectangle fillRect;

                if (progressbar.HorizontalAlignment == HorizontalAlignment.Left)
                {
                    fillRect = new Rectangle(0, 0, progressbar.fillSize, progressbar.Height);
                }
                else
                {
                    fillRect = new Rectangle(progressbar.Width - progressbar.fillSize, 0, progressbar.fillSize, progressbar.Height);
                }

                progressbar.Surface.Fill(fillRect, foregroundAppearance.Foreground, foregroundAppearance.Background, foregroundAppearance.Glyph);

                if (progressbar.DisplayTextColor.A != 0 && !string.IsNullOrEmpty(progressbar.DisplayText))
                {
                    string alignedString;
                    if (progressbar.DisplayText == "%")
                    {
                        alignedString = $"{(int)(progressbar.Progress * 100)}%".Align(progressbar.DisplayTextAlignment, progressbar.Width);
                    }
                    else
                    {
                        alignedString = progressbar.DisplayText.Align(progressbar.DisplayTextAlignment, progressbar.Width);
                    }

                    int centerRow = progressbar.Surface.Height / 2;

                    for (int i = 0; i < alignedString.Length; i++)
                    {
                        if (alignedString[i] != ' ')
                        {
                            if (PrintDisplayAsDecorator)
                            {
                                progressbar.Surface.AddDecorator(i, centerRow, 1, new CellDecorator(displayTextAppearance.Foreground, alignedString[i], Mirror.None));
                            }
                            else
                            {
                                progressbar.Surface.SetGlyph(i, centerRow, alignedString[i], displayTextAppearance.Foreground);
                            }
                        }
                    }
                }
            }

            else
            {
                Rectangle fillRect;

                if (progressbar.VerticalAlignment == VerticalAlignment.Top)
                {
                    fillRect = new Rectangle(0, 0, progressbar.Width, progressbar.fillSize);
                }
                else
                {
                    fillRect = new Rectangle(0, progressbar.Height - progressbar.fillSize, progressbar.Width, progressbar.fillSize);
                }

                progressbar.Surface.Fill(fillRect, foregroundAppearance.Foreground, foregroundAppearance.Background, foregroundAppearance.Glyph);
            }



            progressbar.IsDirty = false;
        }