Exemple #1
0
        /// <summary>
        /// Scales the current DrawableComponent to a new size
        /// whilst maintaing content which should not be clipped.
        /// </summary>
        /// <param name="newX">The new unsigned width.</param>
        /// <param name="newY">The new unsigned height.</param>
        public void Scale(int newX, int newY)
        {
            IDrawableUnit[,] temporaryContent = new IDrawableUnit[newX, newY];

            for (int x = 0; x < newX; x++)
            {
                for (int y = 0; y < newY; y++)
                {
                    //Check to see if still in bounds of old size
                    if (y < SizeY && x < SizeX)
                    {
                        temporaryContent[x, y] = this.Contents[x, y];
                    }
                    else
                    {
                        temporaryContent[x, y] = null; //If it is out of bounds of original content place a null pixel here
                    }
                }
            }

            //Set the sizes and content
            SizeX         = newX;
            SizeY         = newY;
            this.Contents = temporaryContent;
        }
Exemple #2
0
        /// <summary>
        /// Calculates an output buffer of IDrawableUnit
        /// based on the DrawableComponent's current rotation.
        ///
        /// This function uses the formula:
        ///  * x' = xcos(degrees) - ysin(degrees)
        ///  * y' = xsin(degrees) + ycos(degrees)
        /// to find specific output points on a rotated buffer.
        ///
        ///  1. Rotation occurs in the center,
        ///  2. Rotated points which are outside of the original
        ///     buffer's size are clipped.
        ///  3. The buffer does not scale.
        /// </summary>
        /// <returns>The function returns a rotated version of
        /// DrawableComponent.Contents.</returns>
        public IDrawableUnit[,] CalculateRotation()
        {
            double cosd = Math.Round(Math.Cos(this.Rotation)); //Cosine of the degrees to rotate
            double sind = Math.Round(Math.Sin(this.Rotation)); //Sine of the degrees to rotate

            int centerx = SizeX / 2;
            int centery = SizeY / 2;

            IDrawableUnit[,] rotatedContent = new IDrawableUnit[SizeX, SizeY];

            //Rotate
            for (int x = 0; x < SizeX; x++)
            {
                for (int y = 0; y < SizeY; y++)
                {
                    /*Math for rotation
                     * x' = xcos(degrees) - ysin(degrees)
                     * y' = xsin(degrees) + ycos(degrees)
                     */
                    int xprime = centerx + (int)((x - centerx) * cosd - (y - centery) * sind);
                    int yprime = centery + (int)((x - centerx) * sind + (y - centery) * cosd);

                    //Determine if is within boundries
                    if ((xprime >= 0 && xprime < SizeX && yprime >= 0 && yprime < SizeY))
                    {
                        rotatedContent[xprime, yprime] = this.Contents[x, y];
                    }
                }
            }


            return(rotatedContent);
        }
Exemple #3
0
 public static void ModifyAll(DrawableComponent Component, IDrawableUnit Modification)
 {
     for (int x = 0; x < Component.SizeX; x++)
     {
         for (int y = 0; y < Component.SizeY; y++)
         {
             Component.Contents[x, y] = Modification;
         }
     }
 }
        public ButtonComponent(string Name, DrawableComponent drawInfo,
                               IDrawableUnit SelectedColors, IDrawableUnit PressedColors,
                               IDrawableUnit UnselectedColors,
                               PressAction calledWhenPressed)
            : base(Name, drawInfo)
        {
            this.SelectedColors   = SelectedColors;
            this.UnselectedColors = UnselectedColors;
            this.PressedColors    = PressedColors;

            Pressed  = false;
            Selected = false;
            SetColors(UnselectedColors);
            this.calledWhenPressed = calledWhenPressed;
        }
        public ButtonComponent(string Name, DrawableComponent drawInfo,
            IDrawableUnit SelectedColors, IDrawableUnit PressedColors,
            IDrawableUnit UnselectedColors,
            PressAction calledWhenPressed)
            : base(Name,drawInfo)
        {
            this.SelectedColors = SelectedColors;
            this.UnselectedColors = UnselectedColors;
            this.PressedColors = PressedColors;

            Pressed = false;
            Selected = false;
            SetColors(UnselectedColors);
            this.calledWhenPressed = calledWhenPressed;
        }
Exemple #6
0
        public static void Initialize(string Titlez, IDrawableUnit Backgroundz)
        {
            //Set up component management
            Components = new Dictionary <string, Component>();
            InLoop     = false;

            //Set up buffers
            PreBuffer = new IDrawableUnit[80, 25];
            Buffer    = new CharInfo[80 * 25];

            //Set up screen properties
            Background   = Backgroundz;
            ConsoleTitle = Titlez;


            //Set up runtime
            Running = false;
        }
Exemple #7
0
        private static void Draw()
        {
            for (int y = 0; y < 25; y++)
            {
                for (int x = 0; x < 80; x++)
                {
                    if (PreBuffer[x, y] == null)
                    {
                        Buffer[y * 80 + x] = Background.Value;
                    }
                    else
                    {
                        Buffer[y * 80 + x] = PreBuffer[x, y].Value;
                    }
                }
            }

            SmallRect rect = new SmallRect()
            {
                Left = 0, Top = 0, Right = 80, Bottom = 25
            };                                                                               //Create a rectangle for ConsoleWIndow


            bool b = WriteConsoleOutputW(h, Buffer,
                                         new Coord()
            {
                X = 80, Y = 25
            },
                                         new Coord()
            {
                X = 0, Y = 0
            },
                                         ref rect);



            //Reset prebuffer
            PreBuffer = new IDrawableUnit[80, 25];
        }
 private void SetColors(IDrawableUnit colors)
 {
     this.Foreground = colors.ForeColor;
     this.Background = colors.BackColor;
 }
Exemple #9
0
        public static void Initialize(string Titlez, IDrawableUnit Backgroundz)
        {
            //Set up component management
            Components = new Dictionary<string, Component>();
            InLoop = false;

            //Set up buffers
            PreBuffer = new IDrawableUnit[80, 25];
            Buffer = new CharInfo[80 * 25];

            //Set up screen properties
            Background = Backgroundz;
            ConsoleTitle = Titlez;

            //Set up runtime
            Running = false;
        }
        /// <summary>
        /// Scales the current DrawableComponent to a new size
        /// whilst maintaing content which should not be clipped.
        /// </summary>
        /// <param name="newX">The new unsigned width.</param>
        /// <param name="newY">The new unsigned height.</param>
        public void Scale(int newX, int newY)
        {
            IDrawableUnit[,] temporaryContent = new IDrawableUnit[newX, newY];

            for (int x = 0; x < newX; x++)
            {
                for (int y = 0; y < newY; y++)
                {
                    //Check to see if still in bounds of old size
                    if (y < SizeY && x < SizeX)
                        temporaryContent[x, y] = this.Contents[x, y];
                    else
                        temporaryContent[x, y] = null; //If it is out of bounds of original content place a null pixel here
                }
            }

            //Set the sizes and content
            SizeX = newX;
            SizeY = newY;
            this.Contents = temporaryContent;
        }
        /// <summary>
        /// Draws the specified component to a IDrawableUnit[,] buffer.
        /// </summary>
        /// <param name="Buffer">The buffer to which the method will draw.</param>
        /// <param name="Height">The height of the buffer to be drawn to.</param>
        /// <param name="Width">The width of the buffer to be drawn to.</param>
        public void Draw(IDrawableUnit[,] Buffer, int Height, int Width)
        {
            lock(this)
            if (X < Width && Y < Height) //If the Component is within the bounds of the Buffer
            {

                for (int y = Y; y < Height && y - Y < SizeY; y++)
                {
                    for (int x = X; x < Width && x - X < SizeX; x++)
                    {   //If the content is not null (only if transparent)
                        if (Contents[x - X, y - Y] != null)
                            Buffer[x, y] = Contents[x - X, y - Y]; //set the Buffer
                        else if (!Transparent)
                            Buffer[x, y] = new Pixel(Background);
                        else if (Transparent)
                            Buffer[x, y] = null;
                    }
                }
            }
        }
        /// <summary>
        /// Calculates an output buffer of IDrawableUnit
        /// based on the DrawableComponent's current rotation.
        /// 
        /// This function uses the formula:
        ///  * x' = xcos(degrees) - ysin(degrees)
        ///  * y' = xsin(degrees) + ycos(degrees)
        /// to find specific output points on a rotated buffer.
        /// 
        ///  1. Rotation occurs in the center,
        ///  2. Rotated points which are outside of the original
        ///     buffer's size are clipped.
        ///  3. The buffer does not scale.
        /// </summary>
        /// <returns>The function returns a rotated version of
        /// DrawableComponent.Contents.</returns>
        public IDrawableUnit[,] CalculateRotation()
        {
            double cosd = Math.Round(Math.Cos(this.Rotation)); //Cosine of the degrees to rotate
            double sind = Math.Round(Math.Sin(this.Rotation)); //Sine of the degrees to rotate

            int centerx = SizeX / 2;
            int centery = SizeY / 2;

            IDrawableUnit[,] rotatedContent = new IDrawableUnit[SizeX, SizeY];

            //Rotate
            for (int x = 0; x < SizeX; x++)
                for (int y = 0; y < SizeY; y++)
                {
                    /*Math for rotation
                     * x' = xcos(degrees) - ysin(degrees)
                     * y' = xsin(degrees) + ycos(degrees)
                     */
                    int xprime = centerx + (int)((x - centerx) * cosd - (y - centery) * sind);
                    int yprime = centery + (int)((x - centerx) * sind + (y - centery) * cosd);

                    //Determine if is within boundries
                    if ((xprime >= 0 && xprime < SizeX && yprime >= 0 && yprime < SizeY))
                    {

                        rotatedContent[xprime, yprime] = this.Contents[x, y];
                    }
                }

            return rotatedContent;
        }
Exemple #13
0
 private void SetColors(IDrawableUnit colors)
 {
     this.Foreground = colors.ForeColor;
     this.Background = colors.BackColor;
 }
Exemple #14
0
 public static void ModifyAll(DrawableComponent Component, IDrawableUnit Modification)
 {
     for (int x = 0; x < Component.SizeX; x++)
         for (int y = 0; y < Component.SizeY; y++)
             Component.Contents[x, y] = Modification;
 }