void DrawMap(int x, int y, std::vector<int>& map) { terminal_layer(base_layer); for (int j=0; j<map_height; j++) { for (int i=0; i<map_width; i++) { int v = map[j*map_width+i]; if (i == player_x && j == player_y) { terminal_color("orange"); terminal_put(x+i, y+j, '@'); } else if (i == foe_x && j == foe_y && foe_hp > 0) { terminal_color("white"); terminal_put(x+i, y+j, 'g'); } else if (v == 0 || v == 1) { terminal_color(v? "red": "gray"); terminal_put(x+i, y+j, 0x2219); } else { terminal_color("white"); terminal_put(x+i, y+j, v); } } } }
void monitor_process_key_press(uint8_t scancode) { struct terminal_position p = terminal_position(); uint8_t code = scancodes[scancode]; const char *command = NULL; terminal_set_position(command_line_position); if (scancode == KEY_BACKSPACE && command_line_position.column > COMMAND_LINE_PROMPT_LEN) { command_line_position.column--; terminal_set_position(command_line_position); terminal_put(' '); } else if (code == '\n') { command = terminal_read_command(COMMAND_LINE_PROMPT_LEN); assert(command != NULL); terminal_clear_line(); } else if (code != 0) { if (command_line_position.column < TERMINAL_COL_COUNT-1) { command_line_position.column++; terminal_put(code); } } if (command != NULL) { // redraw command line prompt terminal_printf("%s", COMMAND_LINE_PROMPT); command_line_position = terminal_position(); } terminal_set_position(p); if (command != NULL) monitor_process_command(command); }
void drawBoard(Board *theBoard, Game *theGame ) { int mx1 = BOARD_POSITION - (BLOCK_SIZE * (BOARD_WIDTH / 2)); int mx2 = BOARD_POSITION + (BLOCK_SIZE * (BOARD_WIDTH / 2)); int my = SCREEN_HEIGHT - (BLOCK_SIZE * BOARD_HEIGHT); drawRectangle(mx1 - BOARD_LINE_WIDTH, my, mx1, SCREEN_HEIGHT - 1, "blue"); drawRectangle(mx2, my, mx2 + BOARD_LINE_WIDTH, SCREEN_HEIGHT - 1, "blue"); for(int i = BOARD_POSITION - (BOARD_WIDTH / 2) - 1; i < BOARD_POSITION + (BOARD_WIDTH / 2)+1; i++){ terminal_color(color_from_name("blue")); terminal_put(i, 24, 0x2588); } //mx1 += 1; for (int i = 0; i < BOARD_WIDTH; i++){ for(int j = 0; j < BOARD_HEIGHT; j++){ if (!isFreeBlock(theBoard, i, j)){ terminal_color(color_from_name("red")); terminal_put(mx1 + i, my+ j-1, 0x2588); } } } }
void drawPiece(int x, int y, int thePiece, int pRot) { color_t pColor; int newX, newY; getPiecePosition( x, y, &newX, &newY ); for (int i = 0; i < PIECE_BLOCKS; i++){ for (int j = 0; j < PIECE_BLOCKS; j++){ int cTest = getBlockType(thePiece, pRot, j, i); if (cTest == 1) pColor = color_from_name("orange"); else if (cTest == 2) pColor = color_from_name("blue"); if (cTest != 0){ terminal_color(pColor); terminal_put(newX + i, newY + j, 0x2588); } } } }
void TestTilesets() { terminal_set("window.title='Omni: tilesets'"); terminal_composition(TK_ON); // Load tilesets terminal_set("U+E100: ../Media/Runic.png, size=8x16"); terminal_set("U+E200: ../Media/Tiles.png, size=32x32, align=top-left"); terminal_set("U+E300: ../Media/fontawesome-webfont.ttf, size=24x24, spacing=3x2, codepage=../Media/fontawesome-codepage.txt"); terminal_set("zodiac font: ../Media/Zodiac-S.ttf, size=24x36, spacing=3x3, codepage=437"); terminal_clear(); terminal_color("white"); terminal_print(2, 1, "[color=orange]1.[/color] Of course, there is default font tileset."); terminal_print(2, 3, "[color=orange]2.[/color] You can load some arbitrary tiles and use them as glyphs:"); terminal_print ( 2+3, 4, "Fire rune ([color=red][U+E102][/color]), " "water rune ([color=lighter blue][U+E103][/color]), " "earth rune ([color=darker green][U+E104][/color])" ); terminal_print(2, 6, "[color=orange]3.[/color] Tiles are not required to be of the same size as font symbols:"); terminal_put(2+3+0, 7, 0xE200+7); terminal_put(2+3+5, 7, 0xE200+8); terminal_put(2+3+10, 7, 0xE200+9); terminal_print(2, 10, "[color=orange]4.[/color] Like font characters, tiles may be freely colored and combined:"); terminal_put(2+3+0, 11, 0xE200+8); terminal_color("lighter orange"); terminal_put(2+3+5, 11, 0xE200+8); terminal_color("orange"); terminal_put(2+3+10, 11, 0xE200+8); terminal_color("dark orange"); terminal_put(2+3+15, 11, 0xE200+8); terminal_color("white"); std::vector<int> order = {11, 10, 14, 12, 13}; for (int i=0; i<order.size(); i++) { terminal_put(2+3+25+i*4, 11, 0xE200+order[i]); terminal_put(2+3+25+(order.size()+1)*4, 11, 0xE200+order[i]); } terminal_put(2+3+25+order.size()*4, 11, 0xE200+15); terminal_print(2, 14, "[color=orange]5.[/color] And tiles can even come from TrueType fonts like this:"); for (int i=0; i<6; i++) { terminal_put(2+3+i*5, 15, 0xE300+i); } terminal_print(2+3, 18, "...or like this:\n[font=zodiac]D F G S C"); terminal_refresh(); for (int key=0; key!=TK_CLOSE && key!=TK_ESCAPE; key=terminal_read()); // Clean up terminal_set("U+E100: none; U+E200: none; U+E300: none; zodiac font: none"); terminal_composition(TK_OFF); }
void DrawOverlayRectangle(int x, int y, int w, int h, color_t border, color_t background) { const wchar_t kLowerRightQuad = 0x2597, kLowerHalf = 0x2584, kLowerLeftQuad = 0x2596, kRightHalf = 0x2590, kFullBlock = 0x2588, kLeftHalf = 0x258C, kUpperRightQuad = 0x259D, kUpperHalf = 0x2580, kUpperLeftQuad = 0x2598; const wchar_t kUpperLeftCorner = 0x250C, kHorisontal = 0x2500, kUpperRightCorner = 0x2510, kVertical = 0x2502, /* none */ /* kVertical */ kLowerLeftCorner = 0x2514, /* kHorisontal */ kLowerRightCorner = 0x2518; // First, background terminal_color(background); for ( int i = x+1; i < (x+w)-1; i++ ) { for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(i, j, kFullBlock); } terminal_put(i, y, kLowerHalf); terminal_put(i, y+h-1, kUpperHalf); } for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(x, j, kRightHalf); terminal_put(x+w-1, j, kLeftHalf); } terminal_put(x, y, kLowerRightQuad); terminal_put(x+w-1, y, kLowerLeftQuad); terminal_put(x, y+h-1, kUpperRightQuad); terminal_put(x+w-1, y+h-1, kUpperLeftQuad); // Then, border terminal_color(border); for ( int i = x+1; i < (x+w)-1; i++ ) { terminal_put(i, y, kHorisontal); terminal_put(i, y+h-1, kHorisontal); } for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(x, j, kVertical); terminal_put(x+w-1, j, kVertical); } terminal_put(x, y, kUpperLeftCorner); terminal_put(x+w-1, y, kUpperRightCorner); terminal_put(x, y+h-1, kLowerLeftCorner); terminal_put(x+w-1, y+h-1, kLowerRightCorner); }
void BasicOutput() { terminal_options("title=BearLibTerminal demo: output facilities"); terminal_options("font.name=default; font.supplement=Media/Omni/supplement-runic.png"); terminal_blending(BLENDING_ADDITIVE); terminal_color(COLOR_WHITE); terminal_clear(); // Simple output with postformatting terminal_printf(1, 1, "[color=gray]1. Most basic:[/color] ABC abc"); // Wide color range int n = terminal_printf(1, 3, "[color=gray]2. Colors: "); const char long_word[] = "Antidisestablishmentarianism"; const size_t long_word_length = sizeof(long_word)-1; for ( size_t i = 0; i < long_word_length; i++ ) { float factor = float(i)/long_word_length; int red = (1.0f - factor) * 255; int green = factor * 255; terminal_color(color_from_argb(255, red, green, 0)); terminal_put(n+1+i, 3, long_word[i]); } terminal_color(color_from_name("white")); // Tile backgrounds terminal_printf(1, 5, "[color=gray]3. Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red "); // Simple unicode output terminal_printf(1, 7, "[color=gray]4. Unicode:[/color] Latin Русский Ελληνικά"); // Composite (overlay) tiles n = terminal_printf(1, 9, "[color=gray]5. Tile overlay: "); terminal_printf(n+1, 9, "a+ = a, a+ = a, a vs. [color=red]ä"); terminal_printf(n+1, 9, "[color=red] / / ▔ ▔ [/color]a"); // Unicode Box Drawing characters terminal_printf(1, 11, "[color=gray]6. Box drawing:"); const char* box_lines[] = { " ┌──┬───┐ ╔═════╗ ", " ┌───┬─┘ │ ├──┐ ╟──┐ ║ ", " └─┐ └─┐ ├───┘ │ ║ └──╢ ", " └───┴──┴──────┘ ╚═════╝ " }; for ( size_t i = 0; i < sizeof(box_lines)/sizeof(box_lines[i]); i++ ) { terminal_printf(1, 12+i, "%s", box_lines[i]); } // Box drawing + overlay application terminal_printf(1, 17, "[color=gray]7. Box drawing + overlay:"); terminal_color(0xFF006000); for ( int y = 0; y < 6; y++ ) { for ( int x = 0; x < 19; x++ ) { terminal_put(1+x, 18+y, 'A'+(x+y)%26); } } DrawOverlayRectangle(3, 19, 15, 4, 0xFFFFFFFF, 0xA0909090); terminal_printf(4, 20, "[color=white]Itym:\nHeavy draggon"); terminal_printf(40, 17, "[color=gray]8. Font supplement:"); terminal_printf(40, 19, "fire ([color=red][uE001][/color]) - water ([color=lighter blue][uE004][/color]) - earth ([color=dark green][uE00F][/color])"); terminal_printf(40, 20, "\uE001\uE002\uE003, \uE004\uE005\uE006\uE007\uE008! \uE009\uE00A\uE00B \uE00C \uE00D\uE00E\uE00F\uE010."); terminal_refresh(); int key = 0; do { key = terminal_get(); } while ( key != VK_CLOSE && key != VK_ESCAPE ); }
void draw_rectangle(int x, int y, int w, int h, color_t border, color_t back) { // Background parts const wchar_t kLowerRightQuad = 0x2597, kLowerHalf = 0x2584, kLowerLeftQuad = 0x2596, kRightHalf = 0x2590, kFullBlock = 0x2588, kLeftHalf = 0x258C, kUpperRightQuad = 0x259D, kUpperHalf = 0x2580, kUpperLeftQuad = 0x2598; // Border parts const wchar_t kUpperLeftCorner = 0x250C, kHorisontal = 0x2500, kUpperRightCorner = 0x2510, kVertical = 0x2502, /* none */ /* kVertical */ kLowerLeftCorner = 0x2514, /* kHorisontal */ kLowerRightCorner = 0x2518; // FIXME terminal_blending(BLENDING_ADDITIVE); // First, background if (color_alpha(back) > 0) { terminal_color(back); for ( int i = x+1; i < (x+w)-1; i++ ) { for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(i, j, kFullBlock); } terminal_put(i, y, kLowerHalf); terminal_put(i, y+h-1, kUpperHalf); } for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(x, j, kRightHalf); terminal_put(x+w-1, j, kLeftHalf); } terminal_put(x, y, kLowerRightQuad); terminal_put(x+w-1, y, kLowerLeftQuad); terminal_put(x, y+h-1, kUpperRightQuad); terminal_put(x+w-1, y+h-1, kUpperLeftQuad); } // Then, border terminal_color(border); for ( int i = x+1; i < (x+w)-1; i++ ) { terminal_put(i, y, kHorisontal); terminal_put(i, y+h-1, kHorisontal); } for ( int j = y+1; j < (y+h)-1; j++ ) { terminal_put(x, j, kVertical); terminal_put(x+w-1, j, kVertical); } terminal_put(x, y, kUpperLeftCorner); terminal_put(x+w-1, y, kUpperRightCorner); terminal_put(x, y+h-1, kLowerLeftCorner); terminal_put(x+w-1, y+h-1, kLowerRightCorner); }