// ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Construct a Pigment given foreground and background colors and background flag. /// </summary> public Pigment(long foreground, long background, TCODBackgroundFlag bgFlag) : this(new Color(foreground), new Color(background), bgFlag) { }
/// <summary> /// Returns a new Pigment by replacing the background flag. This isntance remains /// unchanged. /// </summary> /// <param name="newBGFlag"></param> /// <returns></returns> public Pigment ReplaceBGFlag(TCODBackgroundFlag newBGFlag) { return(new Pigment(Foreground, Background, newBGFlag)); }
// ///////////////////////////////////////////////////////////////////////////////// /// <summary> /// Construct a Pigment given foreground and background colors and background flag /// </summary> /// <param name="foreground"></param> /// <param name="background"></param> /// <param name="bgFlag"></param> public Pigment(Color foreground, Color background, TCODBackgroundFlag bgFlag) { fgColor = foreground; bgColor = background; this.bgFlag = bgFlag; }
/// <summary> /// Returns a new Pigment by replacing the background flag. This isntance remains /// unchanged. /// </summary> /// <param name="newBGFlag"></param> /// <returns></returns> public Pigment ReplaceBGFlag(TCODBackgroundFlag newBGFlag) { return new Pigment(Foreground, Background, newBGFlag); }
void render_lines(bool first, TCODKey key) { sampleConsole.clear(); if (key.KeyCode == TCODKeyCode.Enter || key.KeyCode == TCODKeyCode.KeypadEnter) { // switch to the next blending mode if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.Alpha) line_bkFlag = TCODBackgroundFlag.None; else line_bkFlag++; } if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.Alpha) { // for the alpha mode, update alpha every frame double alpha = (1.0f + Math.Cos(TCODSystem.getElapsedSeconds() * 2)) / 2.0f; line_bkFlag = TCODCBackgroundHelpers.CreateAlphaBackground((float)alpha); } else if (libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag) == TCODBackgroundFlag.AddAlpha) { // for the add alpha mode, update alpha every frame double alpha = (1.0f + Math.Cos(TCODSystem.getElapsedSeconds() * 2)) / 2.0f; line_bkFlag = TCODCBackgroundHelpers.CreateAddAlphaBackground((float)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++) { TCODColor col = new TCODColor((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, TCODBackgroundFlag.Set); } } line_init = true; } if (first) { TCODSystem.setFps(30); // fps limited to 30 sampleConsole.setForegroundColor(TCODColor.white); } // blit the background TCODConsole.blit(line_bk, 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.getElapsedSeconds())) / 2.0f)); for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) { TCODColor col = new TCODColor((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.getElapsedSeconds() * 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; TCODLine.init(xx, yy, xd, yd); do { if (xx >= 0 && yy >= 0 && xx < SAMPLE_SCREEN_WIDTH && yy < SAMPLE_SCREEN_HEIGHT) { sampleConsole.setCharBackground(xx, yy, TCODColor.blue, line_bkFlag); } } while (!TCODLine.step(ref xx, ref yy)); // print the current flag sampleConsole.print(2, 2, libtcod.libtcod.TCODBackgroundAlphaMask(line_bkFlag).ToString() + " (ENTER to change)"); }