예제 #1
0
        public ConsoleBitmap(Rectangle bounds, ConsoleCharacter? bg = null)
        {
            _syncLock = new object();
            this.Top = bounds.Y;
            this.Left = bounds.X;

            bounds = new Rectangle(0, 0, bounds.Width, bounds.Height);

            this.Bounds = bounds;
            this.scope = bounds;
            this.Console = ConsoleProvider.Current;
            this.Background = bg.HasValue ? bg.Value : new ConsoleCharacter(' ');
            this.Pen = new ConsoleCharacter('*');
            pixels = new ConsolePixel[this.Width][];
            for (int x = 0; x < this.Width; x++)
            {
                pixels[x] = new ConsolePixel[this.Height];
                for (int y = 0; y < pixels[x].Length; y++)
                {
                    pixels[x][y] = new ConsolePixel() { Value = bg };
                }
            }
        }
예제 #2
0
 public void Scope(Rectangle bounds)
 {
     this.scope = bounds;
 }
예제 #3
0
        public void Rescope(int xIncrement, int yIncrement, int w, int h)
        {
            w = Math.Min(w, scope.Width - xIncrement);
            h = Math.Min(h, scope.Height - yIncrement);

            scope = new Rectangle(scope.X + xIncrement, scope.Y + yIncrement, w, h);
        }
예제 #4
0
 public bool IsRightOf(Rectangle other)
 {
     return Right > other.Right;
 }
예제 #5
0
 public bool IsLeftOf(Rectangle other)
 {
     return Left < other.Left;
 }
예제 #6
0
 public bool IsBelow(Rectangle other)
 {
     return Bottom > other.Bottom;
 }
예제 #7
0
 public bool IsAbove(Rectangle other)
 {
     return Top < other.Top;
 }
예제 #8
0
        public bool Contains(Rectangle other)
        {
            var insideLeftEdge = other.Left >= Left;
            var insideRightEdge = other.Right <= Right;

            var insideTopEdge = other.Top >= Top;
            var insideBottomEdge = other.Bottom <= Bottom;

            return insideLeftEdge && insideRightEdge && insideTopEdge && insideBottomEdge;
        }
예제 #9
0
        private void FocusChanged()
        {
            bool focusedControlIsWithinMe = VisitControlTree((control) =>
            {
                return control == Application.FocusManager.FocusedControl;
            });

            if (focusedControlIsWithinMe)
            {
                var offset = Application.FocusManager.FocusedControl.CalculateRelativePosition(this);

                var visibleWindowBounds = new Rectangle(HorizontalScrollUnits, VerticalScrollUnits, Width, Height);
                var focusedControlBounds = new Rectangle(offset, Application.FocusManager.FocusedControl.Size);

                if (focusedControlBounds.IsAbove(visibleWindowBounds))
                {
                    int amount = visibleWindowBounds.Top - focusedControlBounds.Top;
                    VerticalScrollUnits -= amount;
                }

                if (focusedControlBounds.IsBelow(visibleWindowBounds))
                {
                    int amount = focusedControlBounds.Bottom - visibleWindowBounds.Bottom;
                    VerticalScrollUnits += amount;
                }

                if (focusedControlBounds.IsLeftOf(visibleWindowBounds))
                {
                    int amount = visibleWindowBounds.Left - focusedControlBounds.Left;
                    HorizontalScrollUnits -= amount;
                }

                if (focusedControlBounds.IsRightOf(visibleWindowBounds))
                {
                    int amount = focusedControlBounds.Right - visibleWindowBounds.Right;
                    HorizontalScrollUnits += amount;
                }
            }
        }