setup.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_window(&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. if (clear)
  41. D_erase(DEFAULT_BG_COLOR);
  42. }
  43. /*!
  44. \brief Graphics frame setup
  45. Sets the source coordinate system to match the
  46. destination coordinate system, so that D_* functions use the same
  47. coordinate system as R_* functions.
  48. If <b>clear</b> is true, the frame is cleared (same as running
  49. <i>d.erase</i>). Otherwise, it is not cleared.
  50. \param clear non-zero code to clear the frame
  51. */
  52. void D_setup_unity(int clear)
  53. {
  54. double dt, db, dl, dr;
  55. D_get_window(&dt, &db, &dl, &dr);
  56. D_set_src(dt, db, dl, dr);
  57. D_set_dst(dt, db, dl, dr);
  58. D_update_conversions();
  59. if (clear)
  60. D_erase(DEFAULT_BG_COLOR);
  61. }
  62. /*!
  63. \brief Sets source coordinate system
  64. Sets the source coordinate system to its arguments, and if
  65. the <b>fit</b> argument is non-zero, adjusts the destination coordinate
  66. system to preserve the aspect ratio.
  67. If <b>clear</b> is true, the frame is cleared (same as running
  68. <i>d.erase</i>). Otherwise, it is not cleared.
  69. \param clear non-zero code to clear the frame
  70. \param fit non-zero code to adjust destination coordinate system
  71. \param s_top
  72. \param s_bottom
  73. \param s_left
  74. \param s_right
  75. */
  76. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  77. {
  78. double dt, db, dl, dr;
  79. D_get_window(&dt, &db, &dl, &dr);
  80. D_set_src(st, sb, sl, sr);
  81. D_set_dst(dt, db, dl, dr);
  82. if (fit)
  83. D_fit_d_to_u();
  84. D_update_conversions();
  85. if (clear)
  86. D_erase(DEFAULT_BG_COLOR);
  87. }