setup.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. \file lib/display/setup.c
  3. \brief Display Driver - setup
  4. (C) 2006-2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Glynn Clements <glynn gclements.plus.com> (original contributor)
  8. \author Huidae Cho <grass4u gmail.com>
  9. */
  10. #include <string.h>
  11. #include <grass/gis.h>
  12. #include <grass/raster.h>
  13. #include <grass/display.h>
  14. /*!
  15. \brief Graphics frame setup
  16. This is a high level D call. It does a full setup for the current
  17. graphics frame.
  18. Note: Connection to driver must already be made.
  19. Sets the source coordinate system to the current region, and
  20. adjusts the destination coordinate system to preserve the aspect
  21. ratio.
  22. Performs a full setup for the current graphics frame:
  23. - Makes sure there is a current graphics frame (will create a full-screen
  24. one, if not);
  25. - Sets the region coordinates so that the graphics frame and the active
  26. module region agree (may change active module region to do this); and
  27. - Performs graphic frame/region coordinate conversion initialization.
  28. If <b>clear</b> is true, the frame is cleared (same as running
  29. <i>d.erase</i>.) Otherwise, it is not cleared.
  30. \param clear 1 to clear frame (visually and coordinates)
  31. */
  32. void D_setup(int clear)
  33. {
  34. struct Cell_head region;
  35. double dt, db, dl, dr;
  36. D_get_frame(&dt, &db, &dl, &dr);
  37. G_get_set_window(&region);
  38. Rast_set_window(&region);
  39. D_do_conversions(&region, dt, db, dl, dr);
  40. D_set_clip_window_to_screen_window();
  41. if (clear)
  42. D_erase(DEFAULT_BG_COLOR);
  43. D_set_clip_window_to_map_window();
  44. }
  45. /*!
  46. \brief Graphics frame setup
  47. Sets the source coordinate system to match the
  48. destination coordinate system, so that D_* functions use the same
  49. coordinate system as R_* functions.
  50. If <b>clear</b> is true, the frame is cleared (same as running
  51. <i>d.erase</i>). Otherwise, it is not cleared.
  52. \param clear non-zero code to clear the frame
  53. */
  54. void D_setup_unity(int clear)
  55. {
  56. double dt, db, dl, dr;
  57. D_get_frame(&dt, &db, &dl, &dr);
  58. D_set_src(dt, db, dl, dr);
  59. D_set_dst(dt, db, dl, dr);
  60. D_update_conversions();
  61. D_set_clip_window_to_screen_window();
  62. if (clear)
  63. D_erase(DEFAULT_BG_COLOR);
  64. D_set_clip_window_to_map_window();
  65. }
  66. /*!
  67. \brief Sets source coordinate system
  68. Sets the source coordinate system to its arguments, and if
  69. the <b>fit</b> argument is non-zero, adjusts the destination coordinate
  70. system to preserve the aspect ratio.
  71. If <b>clear</b> is true, the frame is cleared (same as running
  72. <i>d.erase</i>). Otherwise, it is not cleared.
  73. \param clear non-zero code to clear the frame
  74. \param fit non-zero code to adjust destination coordinate system
  75. \param s_top
  76. \param s_bottom
  77. \param s_left
  78. \param s_right
  79. */
  80. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  81. {
  82. double dt, db, dl, dr;
  83. D_get_frame(&dt, &db, &dl, &dr);
  84. D_set_src(st, sb, sl, sr);
  85. D_set_dst(dt, db, dl, dr);
  86. if (fit)
  87. D_fit_d_to_u();
  88. D_update_conversions();
  89. D_set_clip_window_to_screen_window();
  90. if (clear)
  91. D_erase(DEFAULT_BG_COLOR);
  92. D_set_clip_window_to_map_window();
  93. }