summaryrefslogtreecommitdiff
path: root/ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/ui.c b/ui.c
new file mode 100644
index 0000000..b6d38be
--- /dev/null
+++ b/ui.c
@@ -0,0 +1,61 @@
+#include <ncurses.h>
+#include "pieces.h"
+
+/*
+ * ncurses ui has an x scale factor of 2
+ */
+
+void printrect(int y, int x, int h, int w) {
+ // print rectangle whose left corner is at (y, x) and internal area is h*w
+ // top & bottom
+ for (int c = 0; c < 2 * w; c++) {
+ mvaddch(y, x + c + 1, ACS_HLINE);
+ mvaddch(y + h + 1, x + c + 1, ACS_HLINE);
+ }
+ // left & right
+ for (int r = 0; r < h; r++) {
+ mvaddch(y + r + 1, x, ACS_VLINE);
+ mvaddch(y + r + 1, x + 2 * w + 1, ACS_VLINE);
+ }
+ // corners
+ mvaddch(y, x, ACS_ULCORNER);
+ mvaddch(y, x + 2 * w + 1, ACS_URCORNER);
+ mvaddch(y + h + 1, x, ACS_LLCORNER);
+ mvaddch(y + h + 1, x + 2 * w + 1, ACS_LRCORNER);
+ refresh();
+}
+
+void printmap(char** map, int y, int x, int mapH, int mapW) {
+ for (int r = 0; r < mapH; r++) {
+ for (int c = 0; c < mapW; c++) {
+ if (map[r][c] == '+') {
+ mvaddch(y + r + 1, x + 2 * c + 1, (' ' | A_REVERSE));
+ addch(' ' | A_REVERSE);
+ }
+ }
+ }
+ refresh();
+}
+
+void printpieces(struct piece** hand, int y, int x, int nhand) {
+ for (int i = 0; i < nhand; i++) {
+ if (hand[i] == NULL)
+ continue;
+
+ struct piece* pc = hand[i];
+ move(y, x);
+ printw("%d", i);
+ printrect(y + 1, x, pc->h + 2, pc->w + 2);
+ for (int r = 0; r < pc->h; r++) {
+ for (int c = 0; c < pc->w; c++) {
+ if (pc->blocks[r * pc->w + c] == '+') {
+ mvaddch(y + r + 3, x + 2 * c + 3, (' '| A_REVERSE));
+ addch(' ' | A_REVERSE);
+ }
+ }
+ }
+ x += 2 * pc->w + 8;
+ }
+ refresh();
+}
+