From 8553878b4adf856a64d1c86643d118a0a58bf7d0 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Mon, 22 Mar 2021 12:26:13 +0300 Subject: [PATCH] start of draw realisation --- .gitignore | 3 ++- src/out_api/draw.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ src/out_api/draw.hpp | 42 ++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 61b8896..2c1fa6b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ cmake_install.cmake install_manifest.txt compile_commands.json CTestTestfile.cmake -_deps \ No newline at end of file +_deps +testing \ No newline at end of file diff --git a/src/out_api/draw.cpp b/src/out_api/draw.cpp index e69de29..6f0b354 100644 --- a/src/out_api/draw.cpp +++ b/src/out_api/draw.cpp @@ -0,0 +1,61 @@ +#include "draw.hpp" +#include +#include +#include + +namespace draw { + + enum Color { + black = 0, + red = 1, + green = 2, + yellow = 3, + blue = 4, + magneta = 5, + cyan = 6, + white = 7, + }; + + void initColorPairs() { + init_pair(ColorScheme::simple, COLOR_BLACK, COLOR_WHITE); + init_pair(ColorScheme::active, COLOR_WHITE, COLOR_BLACK); + init_pair(ColorScheme::player0, COLOR_BLACK, COLOR_RED); + init_pair(ColorScheme::player1, COLOR_BLACK, COLOR_BLUE); + init_pair(ColorScheme::player2, COLOR_BLACK, COLOR_MAGENTA); + init_pair(ColorScheme::player3, COLOR_BLACK, COLOR_YELLOW); + init_pair(ColorScheme::neutral, COLOR_WHITE, COLOR_GREEN); + init_pair(ColorScheme::enviroment, COLOR_BLACK, COLOR_WHITE); + } + + void begin() { + initscr(); + noecho(); + curs_set(false); + start_color(); + initColorPairs(); + } + + void step() { + refresh(); + usleep(STEP_DELAY_USEC); + } + + void end() { + endwin(); + } + + void clearAll() { + clear(); + } + + void drawCh(uint32_t x, uint32_t y, + Cell cell, ColorScheme colorScheme) { + attron(COLOR_PAIR(colorScheme)); + mvaddch(y, x, cell); + attroff(COLOR_PAIR(colorScheme)); + } + + void getSize(uint32_t& x, uint32_t& y) { + getmaxyx(stdscr, y, x); + } +} \ No newline at end of file diff --git a/src/out_api/draw.hpp b/src/out_api/draw.hpp index e69de29..29d98f0 100644 --- a/src/out_api/draw.hpp +++ b/src/out_api/draw.hpp @@ -0,0 +1,42 @@ +#include +#include + +namespace draw { + + enum ColorScheme { + simple, + active, + player0, + player1, + player2, + player3, + neutral, + enviroment + }; + + enum Cell { + blank = ' ', + menu_h = '-', + menu_v = '|', + field = '.', + mountain = '^', + unit = '#' + }; + + const uint32_t STEP_DELAY_USEC = 30000; + + void begin(); + + void step(); + + void end(); + + void clearAll(); + + void drawCh(uint32_t x, uint32_t y, + Cell cell, ColorScheme colorScheme = ColorScheme::simple); + + // void setxy(uint32_t x, uint32_t y); + + void getSize(uint32_t& x, uint32_t& y); +}