Esempio n. 1
0
 public void TestDecrement()
 {
     Background b = new Background(BackgroundFlag.Burn);
     b--;
     Assert.IsTrue(b.BackgroundFlag == BackgroundFlag.AddA);
     b--;
     Assert.IsTrue(b.BackgroundFlag == BackgroundFlag.Add);
 }
Esempio n. 2
0
 public void TestIncrement()
 {
     Background b = new Background(BackgroundFlag.Multiply);
     b++;
     Assert.IsTrue(b.BackgroundFlag == BackgroundFlag.Lighten);
     b++;
     Assert.IsTrue(b.BackgroundFlag == BackgroundFlag.Darken);
 }
Esempio n. 3
0
 public void TestDecrementOffEdge()
 {
     Background b = new Background(BackgroundFlag.Lighten);
     b--;
     b--;
     b--;
     b--;
 }
Esempio n. 4
0
 public void TestConsoleBackground()
 {
     Background alpha = new Background(BackgroundFlag.ColorDodge);
     Background beta = new Background(BackgroundFlag.AddA, .75f);
     Assert.IsTrue(alpha.BackgroundFlag == BackgroundFlag.ColorDodge);
     Assert.AreEqual(alpha.AlphaValue, 0);
     Assert.IsTrue(beta.BackgroundFlag == BackgroundFlag.AddA);
     Assert.AreEqual(beta.AlphaValue, 191);
 }
Esempio n. 5
0
 public void TestBackgroundCopyConstructor()
 {
     Background b = new Background(BackgroundFlag.Burn);
     Background newB = new Background(b);
     Assert.IsTrue(b.AlphaValue == newB.AlphaValue);
     Assert.IsTrue(b.BackgroundFlag == newB.BackgroundFlag);
     b++;
     Assert.IsFalse(b.BackgroundFlag == newB.BackgroundFlag);
 }
Esempio n. 6
0
 /// <summary>
 /// Create a copy of a background flag 
 /// </summary>
 /// <param name="b">Background to copy</param>
 public Background(Background b)
 {
     m_value = b.m_value;
 }
Esempio n. 7
0
 /// <summary>
 /// Set background color of single cell
 /// </summary>
 /// <param name="x">x (Width) position</param>
 /// <param name="y">y (Height) position</param>
 /// <param name="col">Background color</param>
 /// <param name="flag">Background flag</param>
 public void SetCharBackground(int x, int y, Color col, Background flag)
 {
     TCOD_console_set_back(m_consolePtr, x, y, col, flag.m_value);
 }
Esempio n. 8
0
 /// <summary>
 /// Blit part of a image to the console
 /// </summary>
 /// <param name="console">Console target</param>
 /// <param name="x">x coord of upper left of image on console</param>
 /// <param name="y">y coord of upper right of image on console</param>
 /// <param name="w">Width of part of image to blit</param>
 /// <param name="h">Height of part of image to blit</param>
 /// <param name="background">How image affects background color</param>
 public void BlitRect(Console console, int x, int y, int w, int h, Background background)
 {
     TCOD_image_blit_rect(m_instance, console.m_consolePtr, x, y, w, h, background.m_value);
 }
Esempio n. 9
0
 public void TestInvalidBackground1()
 {
     //Not alpha w\ alpha set.
     Background alpha = new Background(BackgroundFlag.Burn, .75f);
 }
Esempio n. 10
0
 /// <summary>
 /// Draw rectangle of color to console, setting background color to default
 /// </summary>
 /// <param name="x">Upper left corner x coord</param>
 /// <param name="y">Upper left corner y coord</param>
 /// <param name="w">Width of rectangle</param>
 /// <param name="h">Height of rectangle</param>
 /// <param name="clear">Clear cells of any ascii character</param>
 /// <param name="flag">Background flag</param>
 public void DrawRect(int x, int y, int w, int h, bool clear, Background flag)
 {
     TCOD_console_rect(m_consolePtr, x, y, w, h, clear, flag.m_value);
 }
Esempio n. 11
0
 /// <summary>
 /// Draw "Frame" with title onto console
 /// </summary>
 /// <param name="x">Upper left corner x coord</param>
 /// <param name="y">Upper left corner y coord</param>
 /// <param name="w">Width</param>
 /// <param name="h">Height</param>
 /// <param name="clear">Clear area</param>
 /// <param name="flag">How to interact with background</param>
 public void DrawFrame(int x, int y, int w, int h, bool clear, Background flag)
 {
     TCOD_console_print_frame(m_consolePtr, x, y, w, h, clear, flag.m_value, IntPtr.Zero);
 }
Esempio n. 12
0
 /// <summary>
 /// Draw "Frame" with title onto console
 /// </summary>
 /// <param name="x">Upper left corner x coord</param>
 /// <param name="y">Upper left corner y coord</param>
 /// <param name="w">Width</param>
 /// <param name="h">Height</param>
 /// <param name="clear">Clear area</param>
 /// <param name="flag">How to interact with background</param>
 /// <param name="str">Title of frame</param>
 public void DrawFrame(int x, int y, int w, int h, bool clear, Background flag, String str)
 {
     TCOD_console_print_frame(m_consolePtr, x, y, w, h, clear, flag.m_value, new StringBuilder(str));
 }
Esempio n. 13
0
 /// <summary>
 /// Blit entire image onto root console
 /// </summary>
 /// <param name="x">x coord of center of image on console</param>
 /// <param name="y">y coord of center of image on console</param>
 /// <param name="background">How image affects background color</param>
 /// <param name="scalex">Width scaling factor</param>
 /// <param name="scaley">Height scaling factor</param>
 /// <param name="angle">Rotation angle in radians</param>
 public void Blit(float x, float y, Background background, double scalex, double scaley, double angle)
 {
     TCOD_image_blit(m_instance, IntPtr.Zero, x, y, background.m_value, (float)scalex, (float)scaley, (float)angle);
 }
Esempio n. 14
0
 /// <summary>
 /// Blit entire image onto console
 /// </summary>
 /// <param name="console">Console target</param>
 /// <param name="x">x coord of center of image on console</param>
 /// <param name="y">y coord of center of image on console</param>
 /// <param name="background">How image affects background color</param>
 /// <param name="scalex">Width scaling factor</param>
 /// <param name="scaley">Height scaling factor</param>
 /// <param name="angle">Rotation angle in radians</param>
 public void Blit(Console console, float x, float y, Background background, double scalex, double scaley, double angle)
 {
     TCOD_image_blit(m_instance, console.m_consolePtr, x, y, background.m_value, (float)scalex, (float)scaley, (float)angle);
 }
Esempio n. 15
0
 /// <summary>
 /// Blit part of a image to the root console
 /// </summary>
 /// <param name="x">x coord of upper left of image on console</param>
 /// <param name="y">y coord of upper right of image on console</param>
 /// <param name="w">Width of part of image to blit</param>
 /// <param name="h">Height of part of image to blit</param>
 /// <param name="background">How image affects background color</param>
 public void BlitRect(int x, int y, int w, int h, Background background)
 {
     TCOD_image_blit_rect(m_instance, IntPtr.Zero, x, y, w, h, background.m_value);
 }
Esempio n. 16
0
 /// <summary>
 /// Print string to line of console, using default foreground/background colors
 /// </summary>
 /// <param name="str">String to print</param>
 /// <param name="x">x (Width) position of first character</param>
 /// <param name="y">y (Height) position of first character</param>
 /// <param name="flag">Background flag</param>
 /// <param name="align">Alignment of string</param>
 public void PrintLine(string str, int x, int y, Background flag, LineAlignment align)
 {
     switch (align)
     {
         case LineAlignment.Left:
             TCOD_console_print_left(m_consolePtr, x, y, flag.m_value, new StringBuilder(str));
             break;
         case LineAlignment.Center:
             TCOD_console_print_center(m_consolePtr, x, y, flag.m_value, new StringBuilder(str));
             break;
         case LineAlignment.Right:
             TCOD_console_print_right(m_consolePtr, x, y, flag.m_value, new StringBuilder(str));
             break;
     }
 }
Esempio n. 17
0
 /// <summary>
 /// Print aligned string inside the defined rectangle, truncating if bottom is reached
 /// </summary>
 /// <param name="str">String to print</param>
 /// <param name="x">x (Width) position of first character</param>
 /// <param name="y">y (Height) position of first character</param>
 /// <param name="w">Width of rectangle to print in</param>
 /// <param name="h">Height of rectangle to print in. If 0, string is only truncated if reaches bottom of console.</param>
 /// <param name="flag">Background flag</param>
 /// <param name="align">Alignment of string</param>
 /// <returns>Number of lines printed</returns>
 public int PrintLineRect(string str, int x, int y, int w, int h, Background flag, LineAlignment align)
 {
     switch (align)
     {
         case LineAlignment.Left:
             return TCOD_console_print_left_rect(m_consolePtr, x, y, w, h, flag.m_value, new StringBuilder(str));
         case LineAlignment.Center:
             return TCOD_console_print_center_rect(m_consolePtr, x, y, w, h, flag.m_value, new StringBuilder(str));
         case LineAlignment.Right:
             return TCOD_console_print_right_rect(m_consolePtr, x, y, w, h, flag.m_value, new StringBuilder(str));
         default:
             throw new Exception("Must Pass Alignment to PrintLineRect");
     }
 }
Esempio n. 18
0
 public void TestIncrementOffEdge()
 {
     Background b = new Background(BackgroundFlag.Overlay);
     b++;
     b++;
 }
Esempio n. 19
0
 /// <summary>
 /// Put ascii character onto console
 /// </summary>
 /// <param name="x">x (Width) position</param>
 /// <param name="y">y (Height) position</param>
 /// <param name="c">SpecialCharacter or ascii byte</param>
 /// <param name="flag">Background flag</param>
 public void PutChar(int x, int y, byte c, Background flag)
 {
     TCOD_console_put_char(m_consolePtr, x, y, c, flag.m_value);
 }
Esempio n. 20
0
 public void TestInvalidBackground3()
 {
     //Alpha w\o alpha set.
     Background alpha = new Background(BackgroundFlag.Alph);
 }
Esempio n. 21
0
        void render_lines(bool first, KeyPress key)
        {
            sampleConsole.Clear();
            if (key.KeyCode == KeyCode.TCODK_ENTER || key.KeyCode == KeyCode.TCODK_KPENTER)
            {
                // switch to the next blending mode
                if (line_bkFlag.BackgroundFlag == BackgroundFlag.Alph)
                    line_bkFlag = Background.None;
                else
                    line_bkFlag++;
            }
            if (line_bkFlag.BackgroundFlag == BackgroundFlag.Alph)
            {
                // for the alpha mode, update alpha every frame
                double alpha = (1.0f + Math.Cos(TCODSystem.ElapsedSeconds * 2)) / 2.0f;
                line_bkFlag = new Background(BackgroundFlag.Alph, alpha);
            }
            else if (line_bkFlag.BackgroundFlag == BackgroundFlag.AddA)
            {
                // for the add alpha mode, update alpha every frame
                double alpha = (1.0f + Math.Cos(TCODSystem.ElapsedSeconds * 2)) / 2.0f;
                line_bkFlag = new Background(BackgroundFlag.AddA, alpha);
            }

            if (!line_init)
            {
                // initialize the colored background
                for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
                {
                    for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++)
                    {
                        Color col = Color.FromRGB((byte)(x * 255 / (SAMPLE_SCREEN_WIDTH - 1)),
                                        (byte)((x + y) * 255 / (SAMPLE_SCREEN_WIDTH - 1 + SAMPLE_SCREEN_HEIGHT - 1)),
                                        (byte)(y * 255 / (SAMPLE_SCREEN_HEIGHT - 1)));

                        line_bk.SetCharBackground(x, y, col, Background.Set);
                    }
                }
                line_init = true;
            }
            if (first)
            {
                TCODSystem.FPS = 30; // fps limited to 30
                sampleConsole.ForegroundColor = ColorPresets.White;
            }

            // blit the background
            line_bk.Blit(0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, sampleConsole, 0, 0);

            // render the gradient
            int recty = (int)((SAMPLE_SCREEN_HEIGHT - 2) * ((1.0f + Math.Cos(TCODSystem.ElapsedSeconds)) / 2.0f));
            for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++)
            {
                Color col = Color.FromRGB((byte)(x * 255 / SAMPLE_SCREEN_WIDTH),
                                    (byte)(x * 255 / SAMPLE_SCREEN_WIDTH),
                                    (byte)(x * 255 / SAMPLE_SCREEN_WIDTH));
                sampleConsole.SetCharBackground(x, recty, col, line_bkFlag);
                sampleConsole.SetCharBackground(x, recty + 1, col, line_bkFlag);
                sampleConsole.SetCharBackground(x, recty + 2, col, line_bkFlag);
            }

            // calculate the segment ends
            float angle = TCODSystem.ElapsedSeconds * 2.0f;
            float cosAngle = (float)Math.Cos(angle);
            float sinAngle = (float)Math.Sin(angle);
            int xo = (int)(SAMPLE_SCREEN_WIDTH / 2 * (1 + cosAngle));
            int yo = (int)(SAMPLE_SCREEN_HEIGHT / 2 + sinAngle * SAMPLE_SCREEN_WIDTH / 2);
            int xd = (int)(SAMPLE_SCREEN_WIDTH / 2 * (1 - cosAngle));
            int yd = (int)(SAMPLE_SCREEN_HEIGHT / 2 - sinAngle * SAMPLE_SCREEN_WIDTH / 2);

            // render the line
            int xx = xo, yy = yo;
            TCODLineDrawing.InitLine(xx, yy, xd, yd);
            do
            {
                if (xx >= 0 && yy >= 0 && xx < SAMPLE_SCREEN_WIDTH && yy < SAMPLE_SCREEN_HEIGHT)
                {
                    sampleConsole.SetCharBackground(xx, yy, ColorPresets.Blue, line_bkFlag);
                }
            }
            while (!TCODLineDrawing.StepLine(ref xx, ref yy));

            // print the current flag
            sampleConsole.PrintLine(line_bkFlag.BackgroundFlag.ToString() + " (ENTER to change)", 2, 2, LineAlignment.Left);
        }