curses.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #include <curses.h>
  2. #include <grass/gis.h>
  3. #include <grass/colors.h>
  4. /* " <------------ Room for text --------------> " */
  5. #define LINE01 " R/r increase/decrease RED"
  6. #define LINE02 " G/g increase/decrease GREEN"
  7. #define LINE03 " B/b increase/decrease BLUE"
  8. #define LINE04 " I/i increase/decrease increment"
  9. #define LINE05 " h highlight current category"
  10. #define LINE06 ""
  11. #define LINE07 " D/d down; move to next category"
  12. #define LINE08 " U/u up ; move to previous category"
  13. #define LINE09 " +/- shift entire color table"
  14. #define LINE10 " c save color table"
  15. #define LINE11 " t toggle different color table"
  16. #define LINE12 " Q quit"
  17. #define LINE13 " * Replot screen"
  18. WINDOW *newwin();
  19. WINDOW *CAT_WIN;
  20. WINDOW *COLR_WIN;
  21. WINDOW *MENU_WIN;
  22. WINDOW *MESG_WIN;
  23. int Initialize_curses(void)
  24. {
  25. initscr();
  26. raw();
  27. crmode();
  28. noecho();
  29. nonl();
  30. /* newwin(NROWS, NCOLS, BEGROW, BEGCOL) ; */
  31. CAT_WIN = newwin(9, 80, 0, 0);
  32. COLR_WIN = newwin(9, 30, 8, 0);
  33. MENU_WIN = newwin(15, 51, 8, 29);
  34. MESG_WIN = newwin(5, 30, 16, 0);
  35. werase(CAT_WIN);
  36. werase(COLR_WIN);
  37. werase(MENU_WIN);
  38. werase(MESG_WIN);
  39. return 0;
  40. }
  41. int Close_curses(void)
  42. {
  43. clear();
  44. refresh();
  45. mvcur(0, COLS - 1, LINES - 1, 0);
  46. endwin();
  47. return 0;
  48. }
  49. int Write_cats(struct Categories *pcats, int current_cat)
  50. {
  51. char buffer[128];
  52. CELL tmp = current_cat;
  53. int start_cat, end_cat, at_cat, at_line;
  54. if (Rast_is_c_null_value(&tmp))
  55. current_cat = 0;
  56. else
  57. current_cat++;
  58. Rast_set_c_null_value(&tmp, 1);
  59. start_cat = current_cat - 2;
  60. start_cat = start_cat > 0 ? start_cat : 0;
  61. end_cat = start_cat + 4;
  62. end_cat = end_cat < pcats->num + 1 ? end_cat : pcats->num + 1;
  63. werase(CAT_WIN);
  64. wmove(CAT_WIN, 1, 20);
  65. sprintf(buffer, "CATEGORIES: %3d to %3d of %3d",
  66. start_cat, end_cat, pcats->num);
  67. waddstr(CAT_WIN, buffer);
  68. at_line = 3;
  69. for (at_cat = start_cat; at_cat <= pcats->num + 1; at_cat++) {
  70. if (at_cat == current_cat) {
  71. if (!at_cat)
  72. sprintf(buffer, "-> %3s %s", "N",
  73. Rast_get_c_cat(&tmp, pcats));
  74. else
  75. sprintf(buffer, "-> %3d %s", at_cat - 1,
  76. Rast_get_c_cat(at_cat - 1, pcats));
  77. }
  78. else {
  79. if (!at_cat)
  80. sprintf(buffer, " %3s %s", "N",
  81. Rast_get_c_cat(&tmp, pcats));
  82. else
  83. sprintf(buffer, " %3d %s", at_cat - 1,
  84. Rast_get_c_cat(at_cat - 1, pcats));
  85. }
  86. wmove(CAT_WIN, at_line++, 1);
  87. waddstr(CAT_WIN, buffer);
  88. }
  89. box(CAT_WIN, '|', '-');
  90. wrefresh(CAT_WIN);
  91. return (0);
  92. }
  93. int Write_menu(void)
  94. {
  95. werase(MENU_WIN);
  96. wmove(MENU_WIN, 1, 1);
  97. waddstr(MENU_WIN, LINE01);
  98. wmove(MENU_WIN, 2, 1);
  99. waddstr(MENU_WIN, LINE02);
  100. wmove(MENU_WIN, 3, 1);
  101. waddstr(MENU_WIN, LINE03);
  102. wmove(MENU_WIN, 4, 1);
  103. waddstr(MENU_WIN, LINE04);
  104. wmove(MENU_WIN, 5, 1);
  105. waddstr(MENU_WIN, LINE05);
  106. wmove(MENU_WIN, 6, 1);
  107. waddstr(MENU_WIN, LINE06);
  108. wmove(MENU_WIN, 7, 1);
  109. waddstr(MENU_WIN, LINE07);
  110. wmove(MENU_WIN, 8, 1);
  111. waddstr(MENU_WIN, LINE08);
  112. wmove(MENU_WIN, 9, 1);
  113. waddstr(MENU_WIN, LINE09);
  114. wmove(MENU_WIN, 10, 1);
  115. waddstr(MENU_WIN, LINE10);
  116. wmove(MENU_WIN, 11, 1);
  117. waddstr(MENU_WIN, LINE11);
  118. wmove(MENU_WIN, 12, 1);
  119. waddstr(MENU_WIN, LINE12);
  120. wmove(MENU_WIN, 13, 1);
  121. waddstr(MENU_WIN, LINE13);
  122. box(MENU_WIN, '|', '-');
  123. wrefresh(MENU_WIN);
  124. return 0;
  125. }
  126. int
  127. Write_status(int red, int grn, int blu, int shift_incr, int at_cat,
  128. int hi_mode)
  129. {
  130. char buffer[40];
  131. CELL tmp = at_cat;
  132. werase(COLR_WIN);
  133. if (hi_mode)
  134. sprintf(buffer, "HIGHLIGHT COLOR");
  135. else {
  136. if (!Rast_is_c_null_value(&tmp))
  137. sprintf(buffer, "CATEGORY NUMBER: %d", at_cat);
  138. else
  139. sprintf(buffer, "CATEGORY NUMBER: N");
  140. }
  141. wmove(COLR_WIN, 1, 3);
  142. waddstr(COLR_WIN, buffer);
  143. sprintf(buffer, " RED: %3d %3d%%", red, (int)((float)red / 2.56));
  144. wmove(COLR_WIN, 3, 3);
  145. waddstr(COLR_WIN, buffer);
  146. sprintf(buffer, " GREEN: %3d %3d%%", grn, (int)((float)grn / 2.56));
  147. wmove(COLR_WIN, 4, 3);
  148. waddstr(COLR_WIN, buffer);
  149. sprintf(buffer, " BLUE: %3d %3d%%", blu, (int)((float)blu / 2.56));
  150. wmove(COLR_WIN, 5, 3);
  151. waddstr(COLR_WIN, buffer);
  152. sprintf(buffer, "SHIFT INCR: %3d %3d%%", shift_incr,
  153. (int)((float)shift_incr / 2.56));
  154. wmove(COLR_WIN, 7, 3);
  155. waddstr(COLR_WIN, buffer);
  156. box(COLR_WIN, '|', '-');
  157. wmove(COLR_WIN, 0, 0);
  158. wrefresh(COLR_WIN);
  159. return 0;
  160. }
  161. int Write_message(int line, char *message)
  162. {
  163. wmove(MESG_WIN, line, 1);
  164. waddstr(MESG_WIN, " ");
  165. wmove(MESG_WIN, line, 1);
  166. waddstr(MESG_WIN, message);
  167. wmove(MESG_WIN, 0, 0);
  168. wrefresh(MESG_WIN);
  169. return 0;
  170. }
  171. int Clear_message(void)
  172. {
  173. werase(MESG_WIN);
  174. wrefresh(MESG_WIN);
  175. return 0;
  176. }
  177. int Clear_menu(void)
  178. {
  179. werase(MENU_WIN);
  180. box(MENU_WIN, '|', '-');
  181. return 0;
  182. }
  183. int Write_menu_line(int line, char *message)
  184. {
  185. wmove(MENU_WIN, line, 1);
  186. wclrtoeol(MENU_WIN);
  187. wmove(MENU_WIN, line, 1);
  188. waddstr(MENU_WIN, message);
  189. wrefresh(MENU_WIN);
  190. return 0;
  191. }
  192. int Replot_screen(void)
  193. {
  194. wrefresh(curscr);
  195. return 0;
  196. }
  197. int Get_curses_text(char answer[])
  198. {
  199. char newchar;
  200. char *pointer;
  201. int curx, cury;
  202. pointer = answer;
  203. for (;;) {
  204. newchar = wgetch(MENU_WIN) & 0177;
  205. if ((newchar > '\037') && (newchar < '\177')) { /* octal codes: accept space to '~' */
  206. *(pointer++) = newchar;
  207. *pointer = 000;
  208. waddch(MENU_WIN, newchar);
  209. wrefresh(MENU_WIN);
  210. }
  211. else if (newchar == '\b' || newchar == '\177') { /* backspace or DEL */
  212. if (pointer > answer) {
  213. *(pointer--) = 000;
  214. getyx(MENU_WIN, cury, curx);
  215. wmove(MENU_WIN, cury, curx - 1);
  216. waddch(MENU_WIN, ' ');
  217. wmove(MENU_WIN, cury, curx - 1);
  218. wrefresh(MENU_WIN);
  219. }
  220. }
  221. else
  222. break;
  223. }
  224. return 0;
  225. }