summaryrefslogtreecommitdiff
path: root/sem_3/project/Documents du Projet-20171011/window.cpp
diff options
context:
space:
mode:
authorGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
committerGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
commit9fe033ea88c2f705ec18c232873d056e0c229d72 (patch)
tree0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_3/project/Documents du Projet-20171011/window.cpp
Initial commit
Diffstat (limited to 'sem_3/project/Documents du Projet-20171011/window.cpp')
-rw-r--r--sem_3/project/Documents du Projet-20171011/window.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/sem_3/project/Documents du Projet-20171011/window.cpp b/sem_3/project/Documents du Projet-20171011/window.cpp
new file mode 100644
index 0000000..65694a7
--- /dev/null
+++ b/sem_3/project/Documents du Projet-20171011/window.cpp
@@ -0,0 +1,114 @@
+#include "window.h"
+
+
+void init_colors(void)
+{
+ start_color();
+ init_pair(WBLACK, COLOR_WHITE, COLOR_BLACK);
+ init_pair(WCYAN, COLOR_WHITE, COLOR_CYAN);
+ init_pair(WBLUE, COLOR_WHITE, COLOR_BLUE);
+ init_pair(WYELLOW, COLOR_WHITE, COLOR_YELLOW);
+ init_pair(WGREEN, COLOR_WHITE, COLOR_GREEN);
+ init_pair(WMAGENTA, COLOR_WHITE, COLOR_MAGENTA);
+ init_pair(WRED, COLOR_WHITE, COLOR_RED);
+ init_pair(BWHITE, COLOR_BLACK, COLOR_WHITE);
+ init_pair(BCYAN, COLOR_BLACK, COLOR_CYAN);
+ init_pair(BBLUE, COLOR_BLACK, COLOR_BLUE);
+ init_pair(BYELLOW, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(BGREEN, COLOR_BLACK, COLOR_GREEN);
+ init_pair(BMAGENTA, COLOR_BLACK, COLOR_MAGENTA);
+ init_pair(BRED, COLOR_BLACK, COLOR_RED);
+}
+
+
+void startProgramX() {
+ initscr(); // initialize curses
+ cbreak(); // pass key presses to program, but not signals
+ noecho(); // don't echo key presses to screen
+ keypad(stdscr, TRUE); // allow arrow keys
+ timeout(0); // no blocking on getch()
+ curs_set(0); // set the cursor to invisible
+ init_colors();
+}
+
+void stopProgramX() {
+ refresh();
+ getch();
+ endwin();
+}
+
+
+
+void Window::update() const{
+ wrefresh(win);
+ wrefresh(frame);
+ refresh();
+}
+
+
+Window::Window(int h,int w, int x, int y, char c)
+ : height(h), width(w), startx(x), starty(y), bord(c)
+{
+ colorwin=WCYAN;
+ colorframe=WBLACK;
+ frame=newwin(h+2,w+2,y,x);
+ win=subwin(frame,h,w,y+1,x+1);
+ wbkgd(frame,COLOR_PAIR(colorwin));
+ wbkgd(win,COLOR_PAIR(colorframe));
+ wborder(frame, c,c,c,c,c,c,c,c);
+ wattron(win,COLOR_PAIR(colorwin));
+ wattron(frame,COLOR_PAIR(colorframe));
+ update();
+}
+
+Window::~Window(){
+ wborder(frame, ' ', ' ', ' ',' ',' ',' ',' ',' ');
+ wattroff(win,COLOR_PAIR(colorwin));
+ wattroff(win,COLOR_PAIR(colorframe));
+ werase(win);
+ update();
+ delwin(win);
+}
+
+void Window::print(int x, int y, std::string s, Color c) const {
+ wattron(win,COLOR_PAIR(c));
+ mvwprintw(win,y,x,s.c_str());
+ wattroff(win,COLOR_PAIR(c));
+ update();
+}
+void Window::print(int x, int y, char s, Color c) const{
+ wattron(win,COLOR_PAIR(c));
+ mvwaddch(win,y,x,s);
+ wattroff(win,COLOR_PAIR(c));
+ update();
+}
+void Window::print(int x, int y, std::string s) const{
+ mvwprintw(win,y,x,s.c_str());
+ update();
+}
+void Window::print(int x, int y, char s) const{
+ mvwaddch(win,y,x,s);
+ update();
+}
+
+
+int Window::getX() const { return startx;}
+int Window::getY() const { return starty;}
+int Window::getHauteur() const { return height;}
+int Window::getLargeur() const { return width;}
+Color Window::getCouleurBordure() const{ return colorframe;}
+Color Window::getCouleurFenetre() const{ return colorwin;}
+void Window::setCouleurBordure(Color c){
+ colorframe=c;
+ wattron(frame,COLOR_PAIR(colorframe));
+ wborder(frame, bord,bord,bord,bord,bord,bord,bord,bord);
+ update();
+}
+void Window::setCouleurFenetre(Color c){
+ colorwin=c;
+ wattron(win,COLOR_PAIR(colorwin));
+ wbkgd(win,COLOR_PAIR(colorwin));
+ update();
+}
+
+void Window::clear() const{ werase(win); update(); }