First Commit
commit
e543dd2bbb
@ -0,0 +1,82 @@
|
||||
#include <ncurses.h>
|
||||
#include <menu.h>
|
||||
#include <string.h>
|
||||
|
||||
void createPanel(WINDOW*,char**);
|
||||
void curses_init();
|
||||
int begX(WINDOW* window);
|
||||
int begY(WINDOW* window);
|
||||
int maxX(WINDOW* window);
|
||||
int maxY(WINDOW* window);
|
||||
|
||||
void createPanel(WINDOW* window, char** listOfElements) {
|
||||
int numCharsToIncrement = 1;
|
||||
int numElements = 0;
|
||||
int i=0;
|
||||
while(*(listOfElements+i) != NULL) {
|
||||
numElements++;
|
||||
i++;
|
||||
}
|
||||
i=0;
|
||||
for (int i=0;i<numElements;i++) {
|
||||
mvwprintw(window,1,numCharsToIncrement,"%s",*(listOfElements+i));
|
||||
numCharsToIncrement += strlen(*(listOfElements+i)) + 1;
|
||||
mvwprintw(window,1,numCharsToIncrement,"|");
|
||||
numCharsToIncrement+=2;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int begX(WINDOW* window) {
|
||||
int begX = 0;
|
||||
int begY = 0;
|
||||
getbegyx(window,begY,begX);
|
||||
return begX;
|
||||
}
|
||||
|
||||
int begY(WINDOW* window) {
|
||||
int begX = 0;
|
||||
int begY = 0;
|
||||
getbegyx(window,begY,begX);
|
||||
return begY;
|
||||
}
|
||||
|
||||
int maxX(WINDOW* window) {
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
getmaxyx(window,maxY,maxX);
|
||||
return maxX;
|
||||
}
|
||||
|
||||
int maxY(WINDOW* window) {
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
getmaxyx(window,maxY,maxX);
|
||||
return maxY;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void curses_init() {
|
||||
initscr();
|
||||
curs_set(0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
curses_init();
|
||||
WINDOW* mainwin = newwin(maxY(stdscr)/2,maxX(stdscr)/2,maxY(stdscr)/4,maxX(stdscr)/4);
|
||||
WINDOW* menuwin = newwin(3,maxX(mainwin),begY(mainwin),begX(mainwin));
|
||||
box(mainwin,0,0);
|
||||
box(menuwin,0,0);
|
||||
wrefresh(mainwin);
|
||||
char* stringArray[] = {"Apple", "Baseball", "Cat", NULL};
|
||||
createPanel(menuwin,stringArray);
|
||||
wrefresh(mainwin);
|
||||
wrefresh(menuwin);
|
||||
|
||||
wgetch(mainwin);
|
||||
endwin();
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue