aboutsummaryrefslogtreecommitdiff
path: root/src/gui.c
blob: 29ad55417d1e0e2f6bf54ac7003eb8e749260b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "gui.h"
#include "meeple.h"

void initialize_colors() {
  use_default_colors();
  start_color();
  for (int i = 1; i < 6; i++) init_pair(i, COLOR_BLACK + i, COLOR_BLACK);
}

int get_player_color(int player) {
  return player ? COLOR_PAIR(player + 2) : COLOR_PAIR(0);
}

void draw_board(BoardUnit* board, int* meeple_map, WINDOW* win) {
  wmove(win, 0, 0);
  for (int i = 0; i < BOARD_UNITS; i++) {
    if (board[i].feature == EMPTY && is_center_index(i)) waddch(win, '.');
    else waddch(
      win,
      board[i].feature
      | get_player_color(get_structure_dominator(board[i].structure_group, meeple_map))
    );
  }
  wrefresh(win);
}

WINDOW* create_framed_window(char* name, int lines, int cols, int x, int y) {
  WINDOW* frame = newwin(lines, cols, x, y);
  WINDOW* window = derwin(frame, lines - 2, cols - 2, 1, 1);
  box(frame, 0, 0);
  mvwaddstr(frame, 0, 1, name);
  wrefresh(frame);
  return window;
}