First/gui.c

93 lines
2.1 KiB
C
Raw Normal View History

/* gui.c
This file is part of the "First" CPU simulator project.
Copyright (c) 2024 Efthymios Kritikos
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <ncurses.h>
int terminal_width;
int terminal_height;
WINDOW *tabs;
int monochrome;
int get_terminal_size(){
int new_height,new_width;
getmaxyx(stdscr,new_height,new_width);
int changed=(new_width!=terminal_width)||(new_height!=terminal_height);
terminal_width=new_width;
terminal_height=new_height;
return changed;
}
int gui_ncurses_refresh(){
if(refresh()==ERR)
return 1;
if(wrefresh(tabs)==ERR)
return 1;
return 0;
}
int start_gui(){
if(!initscr())
return 1;
monochrome=( has_colors() == FALSE );
if(!monochrome){
start_color();
init_pair(1, COLOR_RED, COLOR_BLACK);
}
curs_set(0);
get_terminal_size();
mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator...");
tabs = newwin(3,terminal_width,0,0);
box(tabs, 0 , 0);
mvwprintw(tabs,1,2,"[ 0 Overview ]");
mvwprintw(tabs,1,17," 1 Memory ");
if(gui_ncurses_refresh())
return 1;
return 0;
}
int gui_error(char *str){
WINDOW *error_win = newwin(3,40,terminal_height/2-1,terminal_width/2-20);
box(error_win, 0 , 0);
if(!monochrome)
wattron(error_win,COLOR_PAIR(1));
mvwprintw(error_win,1,1,"%s",str);
if(wrefresh(error_win)==ERR)
return 1;
getch();
delwin(error_win);
return 0;
if(!monochrome)
wattroff(error_win,COLOR_PAIR(1));
}
int gui_continue_request(){
if(getch()==ERR)
return 1;
return 0;
}
int end_gui(){
if(endwin()==ERR)
return 1;
return 0;
}