window.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * D_new_window(name, t, b, l, r)
  3. * creates a new window with given coordinates
  4. * if "name" is an empty string, the routine returns a unique
  5. * string in "name"
  6. *
  7. * D_reset_screen_window(t, b, l, r)
  8. * resets the edges of the current window
  9. *
  10. * D_show_window(color)
  11. * outlines current window in color (from ../colors.h)
  12. *
  13. * D_get_screen_window(t, b, l, r)
  14. * returns current window's coordinates
  15. *
  16. * D_check_map_window(wind)
  17. * if map window (m_win) already assigned
  18. * map window is read into the struct "wind"
  19. * else
  20. * struct "wind" is written to map window (m_win)
  21. *
  22. * D_remove_window()
  23. * remove any trace of window
  24. *
  25. * D_erase_window()
  26. * Erases the window on scree. Does not affect window contents list.
  27. */
  28. #include <string.h>
  29. #include <grass/colors.h>
  30. #include <grass/gis.h>
  31. #include <grass/display.h>
  32. #include <grass/raster.h>
  33. static struct {
  34. int t, b, l, r;
  35. } screen_window;
  36. static int screen_window_set;
  37. static struct Cell_head map_window;
  38. static int map_window_set;
  39. static void D_set_window(int t, int b, int l, int r)
  40. {
  41. screen_window.t = t;
  42. screen_window.b = b;
  43. screen_window.l = l;
  44. screen_window.r = r;
  45. screen_window_set = 1;
  46. }
  47. /*!
  48. * \brief retrieve current frame coordinates
  49. *
  50. * Returns current frame's
  51. * coordinates in the pointers <b>top, bottom, left</b>, and <b>right.</b>
  52. *
  53. * \param top
  54. * \param bottom
  55. * \param left
  56. * \param right
  57. * \return int
  58. */
  59. int D_get_screen_window(int *t, int *b, int *l, int *r)
  60. {
  61. if (!screen_window_set)
  62. {
  63. screen_window.t = R_screen_top();
  64. screen_window.b = R_screen_bot();
  65. screen_window.l = R_screen_left();
  66. screen_window.r = R_screen_rite();
  67. screen_window_set = 1;
  68. }
  69. *t = screen_window.t;
  70. *b = screen_window.b;
  71. *l = screen_window.l;
  72. *r = screen_window.r;
  73. return 0;
  74. }
  75. /*!
  76. * \brief create new graphics frame
  77. *
  78. * Creates a new frame <b>name</b> with
  79. * coordinates <b>top, bottom, left</b>, and <b>right.</b> If <b>name</b>
  80. * is the empty string '''' (i.e., *<b>name</b> = = 0), the routine returns a
  81. * unique string in <b>name.</b>
  82. *
  83. * \param name
  84. * \param top
  85. * \param bottom
  86. * \param left
  87. * \param right
  88. * \return int
  89. */
  90. void D_new_window(char *name, int t, int b, int l, int r)
  91. {
  92. screen_window_set = 0;
  93. map_window_set = 0;
  94. /* Display outline of new window */
  95. D_show_window(GRAY);
  96. D_set_window(t, b, l, r);
  97. }
  98. /*!
  99. * \brief create new graphics frame, with coordinates in percent
  100. *
  101. * Creates a new frame <b>name</b> with coordinates <b>top, bottom,
  102. * left</b>, and <b>right</b> as percentages of the screen size.
  103. * If <b>name</b> is the empty string "" (i.e., *<b>name</b> == 0),
  104. * the routine returns a unique string in <b>name.</b>
  105. *
  106. * \param name
  107. * \param bottom
  108. * \param top
  109. * \param left
  110. * \param right
  111. * \return int
  112. */
  113. void D_new_window_percent(char *name, float b, float t, float l, float r)
  114. {
  115. int scr_t = R_screen_top();
  116. int scr_b = R_screen_bot();
  117. int scr_l = R_screen_left();
  118. int scr_r = R_screen_rite();
  119. int win_t = 0.5 + scr_t + (scr_b - scr_t) * (100. - t) / 100.0;
  120. int win_b = 0.5 + scr_t + (scr_b - scr_t) * (100. - b) / 100.0;
  121. int win_l = 0.5 + scr_l + (scr_r - scr_l) * l / 100.0;
  122. int win_r = 0.5 + scr_l + (scr_r - scr_l) * r / 100.0;
  123. if (win_t < scr_t)
  124. win_t = scr_t;
  125. if (win_b > scr_b)
  126. win_b = scr_b;
  127. if (win_l < scr_l)
  128. win_l = scr_l;
  129. if (win_r > scr_r)
  130. win_r = scr_r;
  131. D_new_window(name, win_t, win_b, win_l, win_r);
  132. }
  133. /*!
  134. * \brief outlines current frame
  135. *
  136. * Outlines
  137. * current frame in <b>color.</b> Appropriate colors are found in
  138. * $GISBASE/src/D/libes/colors.h\remarks{$GISBASE is the directory where GRASS
  139. * is installed. See UNIX_Environment for details.} and are spelled
  140. * with lowercase letters.
  141. *
  142. * \param color
  143. * \return int
  144. */
  145. void D_show_window(int color)
  146. {
  147. int t, b, l, r;
  148. D_get_screen_window(&t, &b, &l, &r);
  149. D_set_window(t - 1, b + 1, l - 1, r + 1);
  150. R_standard_color(color);
  151. R_move_abs(l - 1, b);
  152. R_cont_abs(l - 1, t - 1);
  153. R_cont_abs(r, t - 1);
  154. R_cont_abs(r, b);
  155. R_cont_abs(l - 1, b);
  156. R_flush();
  157. D_set_window(t, b, l, r);
  158. }
  159. /*!
  160. * \brief assign/retrieve current map region
  161. *
  162. * Graphics frames can have GRASS map regions associated with
  163. * them. This routine passes the map <b>region</b> to the current graphics
  164. * frame. If a GRASS region is already associated with the graphics frame, its
  165. * information is copied into <b>region</b> for use by the calling module.
  166. * Otherwise <b>region</b> is associated with the current graphics frame.
  167. * Note this routine is called by <i>D_setup.</i>
  168. *
  169. * \param region
  170. * \return int
  171. */
  172. void D_check_map_window(struct Cell_head *wind)
  173. {
  174. if (map_window_set)
  175. *wind = map_window;
  176. else
  177. {
  178. map_window = *wind;
  179. map_window_set = 1;
  180. }
  181. }
  182. /*!
  183. * \brief resets current frame position
  184. *
  185. * Re-establishes the screen position of a
  186. * frame at the location specified by <b>top, bottom, left, and right.</b>
  187. *
  188. * \param top
  189. * \param bottom
  190. * \param left
  191. * \param right
  192. * \return int
  193. */
  194. void D_reset_screen_window(int t, int b, int l, int r)
  195. {
  196. D_show_window(D_translate_color(DEFAULT_BG_COLOR));
  197. D_set_window(t, b, l, r);
  198. D_show_window(D_translate_color(DEFAULT_FG_COLOR));
  199. }
  200. /*!
  201. * \brief remove a frame
  202. *
  203. * Removes any trace of the
  204. * current frame.
  205. *
  206. * \param ~
  207. */
  208. void D_remove_window(void)
  209. {
  210. screen_window_set = 0;
  211. map_window_set = 0;
  212. }
  213. /*!
  214. * \brief erase current frame
  215. *
  216. * Erases the frame on the
  217. * screen using the currently selected color.
  218. *
  219. * \param ~
  220. */
  221. void D_erase_window(void)
  222. {
  223. int t, b, l, r;
  224. D_get_screen_window(&t, &b, &l, &r);
  225. R_box_abs(l, t, r, b);
  226. R_flush();
  227. }
  228. void D_erase(const char *color)
  229. {
  230. int t, b, l, r;
  231. int colorindex;
  232. D_get_screen_window(&t, &b, &l, &r);
  233. D_clear_window();
  234. /* Parse and select background color */
  235. colorindex = D_parse_color(color, 0);
  236. D_raster_use_color(colorindex);
  237. /* Do the plotting */
  238. R_box_abs(l, t, r, b);
  239. /* Add erase item to the pad */
  240. D_set_erase_color(color);
  241. }
  242. void D_remove_windows(void)
  243. {
  244. screen_window_set = 0;
  245. map_window_set = 0;
  246. }
  247. void D_full_screen(void)
  248. {
  249. D_remove_windows();
  250. D_new_window_percent("full_screen", 0.0, 100.0, 0.0, 100.0);
  251. R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
  252. R_erase();
  253. }