Include background drawing functions that set and reset colors
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ba21104974
commit
c4cebfe0d7
58
main.c
58
main.c
@ -45,11 +45,37 @@ boolean ToggleWindow(WINDOW**win,int w,int h,int x,int y) {
|
|||||||
*win=NULL;
|
*win=NULL;
|
||||||
delwin(*win);
|
delwin(*win);
|
||||||
clear();
|
clear();
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
*win=newwin(h,w,y,x);
|
*win=newwin(h,w,y,x);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void changeColor(int*oldcol,int newcol) {
|
||||||
|
attroff(COLOR_PAIR(*oldcol));
|
||||||
|
attron(COLOR_PAIR(newcol));
|
||||||
|
*oldcol=newcol;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Provide the width and height that the background needs to cover as well as an offset x and y value.
|
||||||
|
void drawBackground(int*currentcol,int background_id,int x,int y,int w,int h) {
|
||||||
|
int oldcol=*currentcol;
|
||||||
|
switch(background_id) {
|
||||||
|
case 0:{
|
||||||
|
move(y,x);
|
||||||
|
changeColor(currentcol,3);
|
||||||
|
for (int yy=0;yy<h;yy++) {
|
||||||
|
for (int xx=0;xx<w;xx++) {
|
||||||
|
addch(ACS_DIAMOND);
|
||||||
|
}
|
||||||
|
move(getcury(stdscr)+1,x);
|
||||||
|
}
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
changeColor(currentcol,oldcol);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc,char**argv) {
|
int main(int argc,char**argv) {
|
||||||
int*keyLog=calloc(25,sizeof(int));
|
int*keyLog=calloc(25,sizeof(int));
|
||||||
unsigned short currentLogCounter=0;
|
unsigned short currentLogCounter=0;
|
||||||
@ -57,16 +83,27 @@ int main(int argc,char**argv) {
|
|||||||
int rows,cols;
|
int rows,cols;
|
||||||
clock_t lastTime = clock();
|
clock_t lastTime = clock();
|
||||||
int FRAMETIME = CLOCKS_PER_SEC/60;
|
int FRAMETIME = CLOCKS_PER_SEC/60;
|
||||||
|
int currentcol=1;
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
|
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1,COLOR_RED,COLOR_BLACK);
|
|
||||||
getmaxyx(stdscr,rows,cols);
|
getmaxyx(stdscr,rows,cols);
|
||||||
cbreak();
|
cbreak();
|
||||||
keypad(stdscr,TRUE);
|
keypad(stdscr,TRUE);
|
||||||
nodelay(stdscr,TRUE);
|
nodelay(stdscr,TRUE);
|
||||||
noecho();
|
noecho();
|
||||||
|
|
||||||
|
init_pair(1,COLOR_BLACK,COLOR_BLACK);
|
||||||
|
init_pair(2,COLOR_RED,COLOR_BLACK);
|
||||||
|
init_pair(3,COLOR_GREEN,COLOR_BLACK);
|
||||||
|
init_pair(4,COLOR_YELLOW,COLOR_BLACK);
|
||||||
|
init_pair(5,COLOR_BLUE,COLOR_BLACK);
|
||||||
|
init_pair(6,COLOR_MAGENTA,COLOR_BLACK);
|
||||||
|
init_pair(7,COLOR_CYAN,COLOR_BLACK);
|
||||||
|
init_pair(8,COLOR_WHITE,COLOR_BLACK);
|
||||||
|
changeColor(¤tcol,6);
|
||||||
|
|
||||||
WINDOW*messageBox=newwin(4,cols-2,rows-5,1);
|
WINDOW*messageBox=newwin(4,cols-2,rows-5,1);
|
||||||
drawBorder(messageBox);
|
drawBorder(messageBox);
|
||||||
//box(messageBox,0,0);
|
//box(messageBox,0,0);
|
||||||
@ -80,12 +117,21 @@ int main(int argc,char**argv) {
|
|||||||
if ((ch=getch())!=ERR) {
|
if ((ch=getch())!=ERR) {
|
||||||
keyLog[currentLogCounter]=ch;
|
keyLog[currentLogCounter]=ch;
|
||||||
currentLogCounter=(currentLogCounter+1)%25;
|
currentLogCounter=(currentLogCounter+1)%25;
|
||||||
if (ch=='A') {
|
switch (ch) {
|
||||||
|
case 'A':
|
||||||
|
case 'a':{
|
||||||
ToggleWindow(&messageBox,cols-2,4,1,rows-5);
|
ToggleWindow(&messageBox,cols-2,4,1,rows-5);
|
||||||
}
|
}break;
|
||||||
if (ch==KEY_RESIZE) {
|
case KEY_RESIZE:{
|
||||||
resizeOccured=true;
|
resizeOccured=true;
|
||||||
getmaxyx(stdscr,rows,cols);
|
getmaxyx(stdscr,rows,cols);
|
||||||
|
}break;
|
||||||
|
case KEY_RIGHT:{
|
||||||
|
changeColor(¤tcol,(currentcol+1)%8);
|
||||||
|
}break;
|
||||||
|
case KEY_LEFT:{
|
||||||
|
changeColor(¤tcol,(currentcol-1>=0)?currentcol-1:7);
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (clock()-lastTime>FRAMETIME) {
|
if (clock()-lastTime>FRAMETIME) {
|
||||||
@ -96,6 +142,7 @@ int main(int argc,char**argv) {
|
|||||||
messageBox=newwin(4,cols-2,rows-5,1);
|
messageBox=newwin(4,cols-2,rows-5,1);
|
||||||
}
|
}
|
||||||
//mvprintw(5,7,"There are %dx%d squares. (%d)",cols,rows,frameCount++);
|
//mvprintw(5,7,"There are %dx%d squares. (%d)",cols,rows,frameCount++);
|
||||||
|
drawBackground(¤tcol,0,4,4,4,4);
|
||||||
if (messageBox!=NULL) {
|
if (messageBox!=NULL) {
|
||||||
drawBorder(messageBox);
|
drawBorder(messageBox);
|
||||||
mvwprintw(messageBox,0,0,"There are %dx%d squares. (%d) It is good!",cols,rows,frameCount);
|
mvwprintw(messageBox,0,0,"There are %dx%d squares. (%d) It is good!",cols,rows,frameCount);
|
||||||
@ -103,6 +150,9 @@ int main(int argc,char**argv) {
|
|||||||
for (int i=0;i<25;i++) {
|
for (int i=0;i<25;i++) {
|
||||||
if (keyLog[i]>0) {
|
if (keyLog[i]>0) {
|
||||||
mvprintw(6+i,2,"Key %d was pressed.",keyLog[i]);
|
mvprintw(6+i,2,"Key %d was pressed.",keyLog[i]);
|
||||||
|
short r,g,b;
|
||||||
|
color_content(currentcol,&r,&g,&b);
|
||||||
|
mvprintw(6+i,30,"%d %d %d",r,g,b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refresh();
|
refresh();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user