fast-nuclear-sim/src/display.cpp

55 lines
717 B
C++
Raw Normal View History

2024-01-14 16:57:13 +11:00
#include "display.hpp"
#include <curses.h>
2024-01-17 12:56:04 +11:00
#include <string.h>
#include <stdlib.h>
2024-01-14 16:57:13 +11:00
2024-01-17 12:56:04 +11:00
void display::draw_text(int x, int y, const char* at)
2024-01-14 16:57:13 +11:00
{
for(int i = 0;; i++)
{
2024-01-17 12:56:04 +11:00
const char* start = at;
char c = (at++)[0];
2024-01-14 16:57:13 +11:00
while(c != '\n' && c != '\0')
{
2024-01-17 12:56:04 +11:00
c = (at++)[0];
2024-01-14 16:57:13 +11:00
}
2024-01-17 12:56:04 +11:00
mvaddnstr(x + i, y, start, (size_t)(at - start));
2024-01-14 16:57:13 +11:00
2024-01-17 12:56:04 +11:00
if(c == '\0')
{
return;
}
2024-01-14 16:57:13 +11:00
}
}
void display::draw_box(int x, int y, int h, int w)
{
mvaddch(x, y, '+');
for(int i = 0; i < w - 2; i++)
{
addch('-');
}
addch('+');
for(int i = 0; i < h - 2; i++)
{
mvaddch(x + i + 1, y, '|');
mvaddch(x + i + 1, y + w - 1, '|');
}
mvaddch(x + h - 1, y, '+');
for(int i = 0; i < w - 2; i++)
{
addch('-');
}
addch('+');
}