X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=draw_wins.c;h=7eadbe8cd7a69db1b50593fd3f6dae1352f7c2ec;hb=566e41ab42605e975937f1f2bd8566e1edc5589b;hp=3eaf491a1a41c5d043f90bc077e1bd5dfee12862;hpb=a470e49ace2874380e6018a6166dd2a61e3c689c;p=plomrogue diff --git a/draw_wins.c b/draw_wins.c index 3eaf491..7eadbe8 100644 --- a/draw_wins.c +++ b/draw_wins.c @@ -1,19 +1,22 @@ +#include +#include #include #include -#include #include "windows.h" +#include "draw_wins.h" #include "roguelike.h" +#include "keybindings.h" -void draw_with_linebreaks (struct Win * win, char * text, int start_y) { +void draw_with_linebreaks (struct Win * win, char * text, uint16_t start_y) { // Write text into window content space. Start on row start_y. Fill unused rows with whitespace. - int x, y; + uint16_t x, y; char toggle; char fin = 0; - int z = -1; - for (y = start_y; y < win->height; y++) { + int16_t z = -1; + for (y = start_y; y < win->size.y; y++) { if (0 == fin) toggle = 0; - for (x = 0; x < win->width; x++) { + for (x = 0; x < win->size.x; x++) { if (0 == toggle) { z++; if ('\n' == text[z]) { @@ -31,10 +34,10 @@ void draw_with_linebreaks (struct Win * win, char * text, int start_y) { void draw_text_from_bottom (struct Win * win, char * text) { // Draw text from end/bottom to the top. char toggle = 0; - int x, y, offset; - int z = -1; + uint16_t x, y, offset; + int16_t z = -1; for (y = 0; 0 == toggle; y++) // Determine number of lines text would have in - for (x = 0; x < win->width; x++) { // a window of available width, but infinite height. + for (x = 0; x < win->size.x; x++) { // a window of available width, but infinite height. z++; if ('\n' == text[z]) // Treat \n and \0 as control characters for incrementing y and stopping break; // the loop. Make sure they don't count as cell space themselves. @@ -45,13 +48,13 @@ void draw_text_from_bottom (struct Win * win, char * text) { toggle = 1; break; } } z = -1; - int start_y = 0; - if (y < win->height) // Depending on what is bigger, determine start point in window or in text. - start_y = win->height - y; - else if (y > win->height) { - offset = y - win->height; + uint16_t start_y = 0; + if (y < win->size.y) // Depending on what is bigger, determine start point in window or in text. + start_y = win->size.y - y; + else if (y > win->size.y) { + offset = y - win->size.y; for (y = 0; y < offset; y++) - for (x = 0; x < win->width; x++) { + for (x = 0; x < win->size.x; x++) { z++; if ('\n' == text[z]) break; @@ -73,12 +76,12 @@ void draw_map_win (struct Win * win) { struct Player * player = world->player; struct Monster * monster = world->monster; char * cells = map->cells; - int width_map_av = map->width - map->offset_x; - int height_map_av = map->height - map->offset_y; - int x, y, z; - for (y = 0; y < win->height; y++) { + uint16_t width_map_av = map->width - map->offset_x; + uint16_t height_map_av = map->height - map->offset_y; + uint16_t x, y, z; + for (y = 0; y < win->size.y; y++) { z = map->offset_x + (map->offset_y + y) * (map->width); - for (x = 0; x < win->width; x++) { + for (x = 0; x < win->size.x; x++) { if (y < height_map_av && x < width_map_av) { if (z == (map->width * player->y) + player->x) mvwaddch(win->curses, y, x, '@'); @@ -91,42 +94,60 @@ void draw_map_win (struct Win * win) { void draw_info_win (struct Win * win) { // Draw info window by appending win->data integer value to "Turn: " display. struct World * world = (struct World *) win->data; - int count = world->turn; + uint16_t count = world->turn; char text[100]; snprintf(text, 100, "Turn: %d", count); draw_with_linebreaks(win, text, 0); } +void draw_horizontal_scroll_hint (struct Win * win, uint16_t y, uint32_t more_lines, char dir) { +// Draw scroll hint line in win at row y, announce more_lines more lines in direction dir. + uint16_t x, offset; + char phrase[] = "more lines"; + char * scrolldesc = malloc((3 * sizeof(char)) + strlen(phrase) + 10); // 10 = max chars for uint32_t string + sprintf(scrolldesc, " %d %s ", more_lines, phrase); + offset = 1; + if (win->size.x > (strlen(scrolldesc) + 1)) + offset = (win->size.x - strlen(scrolldesc)) / 2; + for (x = 0; x < win->size.x; x++) + if (x >= offset && x < strlen(scrolldesc) + offset) + mvwaddch(win->curses, y, x, scrolldesc[x - offset] | A_REVERSE); + else + mvwaddch(win->curses, y, x, dir | A_REVERSE); + free(scrolldesc); } + void draw_keys_win (struct Win * win) { -// Draw keybinding window. +// Draw keybindings window. struct World * world = (struct World *) win->data; - struct KeysWinData * keyswindata = (struct KeysWinData *) world->keyswindata; - struct KeyBinding * keybindings = world->keybindings; - int offset = 0; - if (keyswindata->max >= win->height) { - if (keyswindata->select > win->height / 2) { - if (keyswindata->select < (keyswindata->max - (win->height / 2))) - offset = keyswindata->select - (win->height / 2); + uint16_t offset = 0, y, x; + if (world->keyswindata->max >= win->size.y) { + if (world->keyswindata->select > win->size.y / 2) { + if (world->keyswindata->select < (world->keyswindata->max - (win->size.y / 2))) + offset = world->keyswindata->select - (win->size.y / 2); else - offset = keyswindata->max - win->height + 1; } } - int keydescwidth = 9 + 1; // max length assured by get_keyname() + \0 - char * keydesc = malloc(keydescwidth); + offset = world->keyswindata->max - win->size.y + 1; } } + uint8_t keydescwidth = 9 + 1; // max length assured by get_keyname() + \0 + char * keydesc = malloc(keydescwidth), * keyname; attr_t attri; - int y, x; - char * keyname; - for (y = 0; y <= keyswindata->max && y < win->height; y++) { + for (y = 0; y <= world->keyswindata->max && y < win->size.y; y++) { + if (0 == y && offset > 0) { + draw_horizontal_scroll_hint (win, y, offset + 1, '^'); + continue; } + else if (win->size.y == y + 1 && 0 < world->keyswindata->max - (win->size.y + offset - 1)) { + draw_horizontal_scroll_hint (win, y, world->keyswindata->max - (offset + win->size.y) + 2, 'v'); + continue; } attri = 0; - if (y == keyswindata->select - offset) { + if (y == world->keyswindata->select - offset) { attri = A_REVERSE; - if (1 == keyswindata->edit) + if (1 == world->keyswindata->edit) attri = attri | A_BLINK; } - keyname = get_keyname(keybindings[y + offset].key); + keyname = get_keyname(world->keybindings[y + offset].key); snprintf(keydesc, keydescwidth, "%-9s", keyname); free(keyname); - for (x = 0; x < win->width; x++) + for (x = 0; x < win->size.x; x++) if (x < strlen(keydesc)) mvwaddch(win->curses, y, x, keydesc[x] | attri); - else if (strlen(keydesc) < x && x < strlen(keybindings[y + offset].name) + strlen(keydesc) + 1) - mvwaddch(win->curses, y, x, keybindings[y + offset].name[x - strlen(keydesc) - 1] | attri); + else if (strlen(keydesc) < x && x < strlen(world->keybindings[y + offset].name) + strlen(keydesc) + 1) + mvwaddch(win->curses, y, x, world->keybindings[y + offset].name[x - strlen(keydesc) - 1] | attri); else mvwaddch(win->curses, y, x, ' ' | attri); } free(keydesc); }