X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=src%2Fdraw_wins.c;h=eca0f75bcf79c502954ad883add947e67ba785ae;hb=dd29efee173dfad19a4ea5fa16f35aabb17c4642;hp=b6d13c21e5e14d54fef8f49e85d9f9601f43d706;hpb=93bc319c3b6790f580c6fb17bf08f80713ce16c5;p=plomrogue diff --git a/src/draw_wins.c b/src/draw_wins.c index b6d13c2..eca0f75 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -1,3 +1,5 @@ +/* draw_wins.c */ + #include "draw_wins.h" #include /* for malloc(), free() */ #include /* for uint16_t */ @@ -12,121 +14,19 @@ +/* Write "text" into window "win" as far as possible. Start on row "start_y". */ +static void draw_with_linebreaks(struct Win * win, char * text, + uint16_t start_y); + +/* Write "text" not starting from the top but from the bottom of "win". */ +static void draw_text_from_bottom(struct Win * win, char * text); + /* Draw onto "map" in "win" the objects in the chain at "start". */ static void draw_map_objects(struct World * world, struct MapObj * start, struct Map * map, struct Win * win); -extern void draw_with_linebreaks(struct Win * win, char * text, - uint16_t start_y) -{ - uint16_t x, y; - char toggle; - char fin = 0; - int16_t z = -1; - for (y = start_y; y < win->frame.size.y; y++) - { - if (0 == fin) - { - toggle = 0; - } - for (x = 0; x < win->frame.size.x; x++) - { - if (0 == toggle) - { - z++; - if ('\n' == text[z]) - { - toggle = 1; - continue; - } - else - { - mvwaddch(win->frame.curses_win, y, x, text[z]); - } - if ('\n' == text[z+1]) - { - z++; - toggle = 1; - } - else if (0 == text[z+1]) - { - toggle = 1; - fin = 1; - } - } - } - } -} - - - -extern void draw_text_from_bottom (struct Win * win, char * text) -{ - /* Determine number of lines text would have in a window of win's width, - * but infinite height. Treat \n and \0 as control chars for incrementing - * y and stopping the loop. Make sure +they* don't count as cell space. - */ - char toggle = 0; - uint16_t x, y, offset; - int16_t z = -1; - for (y = 0; 0 == toggle; y++) - { - for (x = 0; x < win->frame.size.x; x++) - { - z++; - if ('\n' == text[z]) - { - break; - } - if ('\n' == text[z+1]) - { - z++; - break; - } - else if (0 == text[z+1]) - { - toggle = 1; - break; - } - } - } - z = -1; - - /* Depending on what's bigger, determine start point in window or text. */ - uint16_t start_y = 0; - if (y < win->frame.size.y) - { - start_y = win->frame.size.y - y; - } - else if (y > win->frame.size.y) - { - offset = y - win->frame.size.y; - for (y = 0; y < offset; y++) - { - for (x = 0; x < win->frame.size.x; x++) - { - z++; - if ('\n' == text[z]) - { - break; - } - if ('\n' == text[z+1]) - { - z++; - break; - } - } - } - text = text + (sizeof(char) * (z + 1)); - } - - draw_with_linebreaks(win, text, start_y); -} - - - extern void draw_log_win(struct Win * win) { struct World * world = (struct World *) win->data; @@ -244,6 +144,115 @@ extern void draw_keys_win(struct Win * win) +static void draw_with_linebreaks(struct Win * win, char * text, + uint16_t start_y) +{ + uint16_t x, y; + char toggle; + char fin = 0; + int16_t z = -1; + for (y = start_y; y < win->frame.size.y; y++) + { + if (0 == fin) + { + toggle = 0; + } + for (x = 0; x < win->frame.size.x; x++) + { + if (0 == toggle) + { + z++; + if ('\n' == text[z]) + { + toggle = 1; + continue; + } + else + { + mvwaddch(win->frame.curses_win, y, x, text[z]); + } + if ('\n' == text[z+1]) + { + z++; + toggle = 1; + } + else if (0 == text[z+1]) + { + toggle = 1; + fin = 1; + } + } + } + } +} + + + +static void draw_text_from_bottom (struct Win * win, char * text) +{ + /* Determine number of lines text would have in a window of win's width, + * but infinite height. Treat \n and \0 as control chars for incrementing + * y and stopping the loop. Make sure +they* don't count as cell space. + */ + char toggle = 0; + uint16_t x, y, offset; + int16_t z = -1; + for (y = 0; 0 == toggle; y++) + { + for (x = 0; x < win->frame.size.x; x++) + { + z++; + if ('\n' == text[z]) + { + break; + } + if ('\n' == text[z+1]) + { + z++; + break; + } + else if (0 == text[z+1]) + { + toggle = 1; + break; + } + } + } + z = -1; + + /* Depending on what's bigger, determine start point in window or text. */ + uint16_t start_y = 0; + if (y < win->frame.size.y) + { + start_y = win->frame.size.y - y; + } + else if (y > win->frame.size.y) + { + offset = y - win->frame.size.y; + for (y = 0; y < offset; y++) + { + for (x = 0; x < win->frame.size.x; x++) + { + z++; + if ('\n' == text[z]) + { + break; + } + if ('\n' == text[z+1]) + { + z++; + break; + } + } + } + text = text + (sizeof(char) * (z + 1)); + } + + draw_with_linebreaks(win, text, start_y); +} + + + static void draw_map_objects(struct World * world, struct MapObj * start, struct Map * map, struct Win * win) {