Beispiel #1
0
        /// <summary>
        /// Resizes this image, preserving the data in the pixels that remain in the new area
        /// </summary>
        /// <param name="w">the new width</param>
        /// <param name="h">the new height</param>
        public void Resize(int w, int h)
        {
            var newPixels = new ConsolePixel[w][];

            for (int x = 0; x < w; x++)
            {
                newPixels[x] = new ConsolePixel[h];
                for (int y = 0; y < newPixels[x].Length; y++)
                {
                    if (IsInBounds(x, y))
                    {
                        newPixels[x][y] = pixels[x][y];
                    }
                    else
                    {
                        newPixels[x][y] = new ConsolePixel()
                        {
                            Value = new ConsoleCharacter(' ')
                        };
                    }
                }
            }

            pixels      = newPixels;
            this.Width  = w;
            this.Height = h;
            this.Invalidate();
        }
Beispiel #2
0
        private void DrawPixel(int x, int y, ConsolePixel pixel, ConsoleCharacter value)
        {
            x = Left + x;
            y = Top + y;

            if (Console.CursorLeft != x)
            {
                Console.CursorLeft = x;
            }

            if (Console.CursorTop != y)
            {
                Console.CursorTop = y;
            }

            if (Console.ForegroundColor != value.ForegroundColor)
            {
                Console.ForegroundColor = value.ForegroundColor;
            }

            if (Console.BackgroundColor != value.BackgroundColor)
            {
                Console.BackgroundColor = value.BackgroundColor;
            }

            Console.Write(value.Value);

            if (pixel != null)
            {
                pixel.Sync();
            }
        }
Beispiel #3
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
                    };
                }
            }
        }
Beispiel #4
0
        // todo - is rectangular, but if you try to set width and height there will be inconsistent state
        public void Resize(int w, int h)
        {
            var newPixels = new ConsolePixel[w][];

            for (int x = 0; x < w; x++)
            {
                newPixels[x] = new ConsolePixel[h];
                for (int y = 0; y < newPixels[x].Length; y++)
                {
                    if (IsInBounds(x, y))
                    {
                        newPixels[x][y] = pixels[x][y];
                    }
                    else
                    {
                        newPixels[x][y] = new ConsolePixel()
                        {
                            Value = Background
                        };
                    }
                }
            }

            pixels    = newPixels;
            this.Size = new Size(w, h);
            this.Scope(Bounds);
            this.Invalidate();
        }
Beispiel #5
0
        /// <summary>
        /// Creates a new ConsoleBitmap
        /// </summary>
        /// <param name="bounds">the area of the image</param>
        public ConsoleBitmap(Rectangle bounds)
        {
            bounds = new Rectangle(0, 0, bounds.Width, bounds.Height);

            this.X               = bounds.X;
            this.Y               = bounds.Y;
            this.Width           = bounds.Width;
            this.Height          = bounds.Height;
            this.Scope           = bounds;
            this.Console         = ConsoleProvider.Current;
            this.lastBufferWidth = this.Console.BufferWidth;
            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 = new ConsoleCharacter(' ')
                    };
                }
            }
        }
Beispiel #6
0
        private bool IsVisibleOnMyPanel(ConsolePixel pixel)
        {
            if (pixel.Value.HasValue == false)
            {
                return(false);
            }

            var c = pixel.Value.Value;

            if (c.Value == ' ')
            {
                return(c.BackgroundColor != Background);
            }
            else
            {
                return(c.ForegroundColor != Background || c.BackgroundColor != Background);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Creates a new ConsoleBitmap
 /// </summary>
 /// <param name="bounds">the area of the image</param>
 public ConsoleBitmap(Size bounds)
 {
     this.Width           = bounds.Width;
     this.Height          = bounds.Height;
     this.Console         = ConsoleProvider.Current;
     this.lastBufferWidth = this.Console.BufferWidth;
     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 = new ConsoleCharacter(' ')
             };
         }
     }
 }
Beispiel #8
0
        private void DrawPixel(int x, int y, ConsolePixel pixel, ConsoleCharacter value)
        {
            x = Left + x;
            y = Top + y;

            if (x >= lastBufferWidth)
            {
                return;
            }
            try
            {
                if (Console.CursorLeft != x)
                {
                    Console.CursorLeft = x;
                }

                if (Console.CursorTop != y)
                {
                    Console.CursorTop = y;
                }

                if (Console.ForegroundColor != value.ForegroundColor)
                {
                    Console.ForegroundColor = value.ForegroundColor;
                }

                if (Console.BackgroundColor != value.BackgroundColor)
                {
                    Console.BackgroundColor = value.BackgroundColor;
                }

                Console.Write(value.Value);
            }catch (ArgumentOutOfRangeException)
            {
            }

            if (pixel != null)
            {
                pixel.Sync();
            }
        }
        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 };
                }
            }
        }
Beispiel #10
0
        private void DrawPixel(int x, int y, ConsolePixel pixel, ConsoleCharacter value)
        {
            x = Left + x;
            y = Top + y;

            if (Console.CursorLeft != x)
            {
                Console.CursorLeft = x;
            }

            if (Console.CursorTop != y)
            {
                Console.CursorTop = y;
            }

            if (Console.ForegroundColor != value.ForegroundColor)
            {
                Console.ForegroundColor = value.ForegroundColor;
            }

            if (Console.BackgroundColor != value.BackgroundColor)
            {
                Console.BackgroundColor = value.BackgroundColor;
            }

            Console.Write(value.Value);

            if(pixel != null)
            {
                pixel.Sync();
            }
        }
        private void DrawPixel(int x, int y, ConsolePixel pixel, ConsoleCharacter value)
        {
            x = Left + x;
            y = Top + y;

            if(x >= lastBufferWidth)
            {
                return;
            }
            try
            {
                if (Console.CursorLeft != x)
                {
                    Console.CursorLeft = x;
                }

                if (Console.CursorTop != y)
                {
                    Console.CursorTop = y;
                }

                if (Console.ForegroundColor != value.ForegroundColor)
                {
                    Console.ForegroundColor = value.ForegroundColor;
                }

                if (Console.BackgroundColor != value.BackgroundColor)
                {
                    Console.BackgroundColor = value.BackgroundColor;
                }

                Console.Write(value.Value);
            }catch(ArgumentOutOfRangeException)
            {

            }

            if(pixel != null)
            {
                pixel.Sync();
            }
        }
        // todo - is rectangular, but if you try to set width and height there will be inconsistent state
        public void Resize(int w, int h)
        {
            var newPixels = new ConsolePixel[w][];
            for (int x = 0; x < w; x++)
            {
                newPixels[x] = new ConsolePixel[h];
                for (int y = 0; y < newPixels[x].Length; y++)
                {
                    if (IsInBounds(x, y))
                    {
                        newPixels[x][y] = pixels[x][y];
                    }
                    else
                    {
                        newPixels[x][y] = new ConsolePixel() { Value = Background };
                    }
                }
            }

            pixels = newPixels;
            this.Size = new Size(w, h);
            this.Scope(Bounds);
            this.Invalidate();
        }