aHardyX

ncurses trial 1

Aug 3rd, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define FALSE   0
  7. #define TRUE    1
  8.  
  9. /*
  10.  * GLOBAL VARIABLES
  11.  */
  12.  
  13. WINDOW *layer1, *layer2, *layertop, *layerbottom;
  14.  
  15. char *TEXT_LIBRARY[2] =
  16.         {
  17.             "All Contacts",
  18.             "Press tab to move the cursor across the program."
  19.         };
  20.  
  21. int scrX;
  22. int scrY;
  23.  
  24. /*
  25.  * FUNCTION DECLARATIONS
  26.  */
  27. int     checkScrSize();
  28.  
  29.  
  30. /* Prints the text at center of Window/Layer. Parameters: WINDOW*, the row number and the string */
  31. void    wprintwc(WINDOW*, int, const char*);
  32.  
  33. /*
  34.  * FUNCTION DEFINATIONS
  35.  */
  36.  
  37. int checkScrSize()
  38. {
  39.     getmaxyx(stdscr, scrY, scrX);
  40.     if(scrX < 80 || scrY < 24)
  41.     {
  42.         printw("Please change you terminal size to atleast 80x24 and restart the program");
  43.         return FALSE;
  44.     }
  45.     return TRUE;
  46. }
  47.  
  48. void wprintwc(WINDOW *win, int textY, const char *text)
  49. {
  50.     int length = strlen(text);
  51.     int winX, winY, textX;
  52.  
  53.     getmaxyx(win, winY, winX);
  54.  
  55.     textX = (winX/2)-(length/2);
  56.  
  57.     mvwprintw(win, textY,textX, "%s", *text);
  58. }
  59.  
  60. int main()
  61. {
  62.     initscr();
  63.     if (checkScrSize() == FALSE)
  64.     {
  65.         getch();
  66.         endwin();
  67.         exit(0);
  68.     }
  69.     refresh();
  70.  
  71.     /* Window/Layer Properties */
  72.     layer1 = newwin(scrY-3, scrX/2, 1,0);
  73.         box(layer1,0,0);
  74.     layer2 = newwin(scrY-3, (scrX/2)-1, 1,(scrX/2)+1);
  75.         box(layer2,0,0);
  76.  
  77.     wprintwc(layer1, 0, TEXT_LIBRARY[0]);
  78.  
  79.     /* Window/Layer Initialization */
  80.     wrefresh(layer1);
  81.     wrefresh(layer2);
  82.  
  83.     getch();
  84.  
  85.     endwin();
  86. }
Advertisement
Add Comment
Please, Sign In to add comment