예제 #1
0
        public override void Render (ConsoleBuffer buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            Rect renderRectWithoutShadow = new Rect(RenderSize).Deflate(Thickness.Max(Shadow, 0));

            //base.Render(buffer);
            if (Background != null)
                buffer.FillBackgroundRectangle(renderRectWithoutShadow, Background.Value);
            buffer.FillForegroundRectangle(new Rect(RenderSize), EffectiveColor);

            if (!Shadow.IsEmpty) {
                // 3 2 2 1:     -1 -1 2 3:
                // ▄▄▄▄▄▄▄▄▄    oooo▄▄
                // █████████    oooo██
                // ███oooo██     █████
                // ███oooo██     █████
                // ▀▀▀▀▀▀▀▀▀     ▀▀▀▀▀
                Thickness shadowLineDelta = new Thickness(0, 1);
                Thickness shadowOffset = Thickness.Max(-Shadow - shadowLineDelta, 0);
                Rect shadowRect = new Rect(RenderSize).Deflate(shadowOffset);

                if (Shadow.Top != 0)
                    buffer.FillForegroundLine(shadowRect.TopLine, ShadowColor, Chars.LowerHalfBlock);
                if (Shadow.Bottom != 0)
                    buffer.FillForegroundLine(shadowRect.BottomLine, ShadowColor, Chars.UpperHalfBlock);
                buffer.FillForegroundRectangle(shadowRect.Deflate(shadowLineDelta), ShadowColor, Chars.FullBlock);
                if (ShadowColor == null && ShadowColorMap != null)
                    buffer.ApplyColorMap(shadowRect, ShadowColorMap,
                        (ref ConsoleChar c) => c.ForegroundColor = ShadowColorMap[(int)c.BackgroundColor]);
            }
            buffer.FillForegroundRectangle(renderRectWithoutShadow, EffectiveColor);
            buffer.DrawRectangle(renderRectWithoutShadow, EffectiveColor, Stroke);
        }