Frontend: Add color support
This commit is contained in:
parent
db58c196a9
commit
dea21b138a
|
@ -15,28 +15,38 @@ Engine::~Engine() {
|
|||
delete this->calendar;
|
||||
}
|
||||
|
||||
void Engine::draw(WINDOW *win) {
|
||||
void Engine::ui_draw(WINDOW *win) {
|
||||
this->cells_table.clear();
|
||||
|
||||
box(win, 0, 0);
|
||||
|
||||
calendar_information date_info = this->calendar->get_info();
|
||||
|
||||
|
||||
switch (this->view_mode) {
|
||||
case MONTH_VIEW:
|
||||
for (int i = 1; i <= date_info.current_month_days; i++)
|
||||
mvwprintw(win, i, 3, "D%d", i);
|
||||
this->ui_month_draw(win);
|
||||
break;
|
||||
case MONTHS_VIEW:
|
||||
for (int i = 1; i <= 12; i++)
|
||||
wprintw(win, "M%d", i);
|
||||
this->ui_months_draw(win);
|
||||
break;
|
||||
}
|
||||
|
||||
wprintw(win, "\n");
|
||||
|
||||
mvwprintw(win, LINES-1, 0, "Year: %d, Month: %d, Day: %d", date_info.current_year, date_info.current_month, date_info.current_day);
|
||||
this->ui_bottom_draw(win);
|
||||
|
||||
wrefresh(win);
|
||||
}
|
||||
|
||||
void Engine::ui_month_draw(WINDOW *win) {
|
||||
|
||||
}
|
||||
|
||||
void Engine::ui_months_draw(WINDOW *win) {
|
||||
|
||||
}
|
||||
|
||||
void Engine::ui_bottom_draw(WINDOW *win) {
|
||||
if (VIS_COLORING) wattron(win, COLOR_PAIR(1));
|
||||
|
||||
calendar_information date_info = this->calendar->get_info();
|
||||
mvwprintw(win, LINES-2, 1, "Year: %d, Month: %d, Day: %d", date_info.current_year, date_info.current_month, date_info.current_day);
|
||||
|
||||
if (VIS_COLORING) wattroff(win, COLOR_PAIR(1));
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <ncurses.h>
|
||||
#include <vector>
|
||||
#include "../calendar/calendar.hpp"
|
||||
#include "../global/global.hpp"
|
||||
|
||||
struct engine_child {
|
||||
int x;
|
||||
|
@ -22,7 +23,10 @@ class Engine {
|
|||
Engine(int padding = 10, calendar_view_mode view_mode = MONTH_VIEW);
|
||||
~Engine();
|
||||
|
||||
void draw(WINDOW *win);
|
||||
void ui_draw(WINDOW *win);
|
||||
void ui_month_draw(WINDOW *win);
|
||||
void ui_months_draw(WINDOW *win);
|
||||
void ui_bottom_draw(WINDOW *win);
|
||||
|
||||
Calendar *calendar;
|
||||
|
||||
|
|
8
src/global/global.hpp
Normal file
8
src/global/global.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef VIS_GLOBAL
|
||||
#define VIS_GLOBAL
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
#define VIS_COLORING has_colors() && can_change_color()
|
||||
|
||||
#endif
|
20
src/main.cpp
20
src/main.cpp
|
@ -4,6 +4,7 @@
|
|||
#include <ncurses.h>
|
||||
#include "calendar/calendar.hpp"
|
||||
#include "engine/engine.hpp"
|
||||
#include "global/global.hpp"
|
||||
|
||||
Engine engine = Engine(10, MONTH_VIEW);
|
||||
WINDOW *main_win;
|
||||
|
@ -17,7 +18,7 @@ void sig_winch(int sig) {
|
|||
wresize(main_win, LINES, COLS);
|
||||
|
||||
// redraw the TUI after the resize signal
|
||||
engine.draw(main_win);
|
||||
engine.ui_draw(main_win);
|
||||
|
||||
flushinp();
|
||||
}
|
||||
|
@ -31,15 +32,29 @@ int main() {
|
|||
refresh();
|
||||
noecho();
|
||||
|
||||
curs_set(0); // invisible cursor
|
||||
refresh();
|
||||
|
||||
main_win = newwin(LINES, COLS, 0, 0);
|
||||
|
||||
if (VIS_COLORING) {
|
||||
start_color();
|
||||
use_default_colors();
|
||||
|
||||
init_color(COLOR_BLACK, 0, 0, 0);
|
||||
init_color(COLOR_WHITE, 1000, 1000, 1000);
|
||||
|
||||
init_pair(0, COLOR_WHITE, COLOR_BLACK);
|
||||
init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
||||
}
|
||||
|
||||
// handle required signals
|
||||
signals();
|
||||
|
||||
for (;;) {
|
||||
wclear(main_win);
|
||||
wrefresh(main_win);
|
||||
engine.draw(main_win);
|
||||
engine.ui_draw(main_win);
|
||||
|
||||
char ch = getch();
|
||||
int month;
|
||||
|
@ -65,7 +80,6 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue
Block a user