setup.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* D_setup (clear)
  2. *
  3. * This is a high level D call.
  4. * It does a full setup for the current graphics frame.
  5. *
  6. * Note: Connection to driver must already be made.
  7. *
  8. * clear values:
  9. * 1: clear frame (visually and coordinates)
  10. * 0: do not clear frame
  11. */
  12. #include <string.h>
  13. #include <grass/gis.h>
  14. #include <grass/display.h>
  15. #include <grass/raster.h>
  16. /*!
  17. * \brief graphics frame setup
  18. *
  19. * D_setup() sets the source coordinate system to the current region, and
  20. * adjusts the destination coordinate system to preserve the aspect
  21. * ratio.
  22. *
  23. * Performs a full setup for the current graphics frame:
  24. * 1) Makes sure there is a current graphics frame (will create a full-screen
  25. * one, if not);
  26. * 2) Sets the region coordinates so that the graphics frame and the active
  27. * module region agree (may change active module region to do this); and
  28. * 3) Performs graphic frame/region coordinate conversion initialization.
  29. *
  30. * If <b>clear</b> is true, the frame is cleared (same as running
  31. * <i>d.erase</i>.) Otherwise, it is not cleared.
  32. *
  33. * \param clear
  34. * \return none
  35. */
  36. void D_setup(int clear)
  37. {
  38. struct Cell_head region;
  39. double dt, db, dl, dr;
  40. R_get_window(&dt, &db, &dl, &dr);
  41. G_get_set_window(&region);
  42. if (G_set_window(&region) < 0)
  43. G_fatal_error("Invalid graphics coordinates");
  44. D_do_conversions(&region, dt, db, dl, dr);
  45. if (clear)
  46. D_erase(DEFAULT_BG_COLOR);
  47. }
  48. /*!
  49. * \brief
  50. *
  51. * D_setup_unity() sets the source coordinate system to match the
  52. * destination coordinate system, so that D_* functions use the same
  53. * coordinate system as R_* functions.
  54. *
  55. * If <b>clear</b> is true, the frame is cleared (same as running
  56. * <i>d.erase</i>.) Otherwise, it is not cleared.
  57. *
  58. * \param clear
  59. * \return none
  60. */
  61. void D_setup_unity(int clear)
  62. {
  63. double dt, db, dl, dr;
  64. R_get_window(&dt, &db, &dl, &dr);
  65. D_set_src(dt, db, dl, dr);
  66. D_set_dst(dt, db, dl, dr);
  67. D_update_conversions();
  68. if (clear)
  69. D_erase(DEFAULT_BG_COLOR);
  70. }
  71. /*!
  72. * \brief
  73. *
  74. * D_setup2() sets the source coordinate system to its arguments, and if
  75. * the <b>fit</b> argument is non-zero, adjusts the destination coordinate
  76. * system to preserve the aspect ratio.
  77. *
  78. * If <b>clear</b> is true, the frame is cleared (same as running
  79. * <i>d.erase</i>.) Otherwise, it is not cleared.
  80. *
  81. * \param clear
  82. * \param fit
  83. * \param s_top
  84. * \param s_bottom
  85. * \param s_left
  86. * \param s_right
  87. * \return none
  88. */
  89. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  90. {
  91. double dt, db, dl, dr;
  92. R_get_window(&dt, &db, &dl, &dr);
  93. D_set_src(st, sb, sl, sr);
  94. D_set_dst(dt, db, dl, dr);
  95. if (fit)
  96. D_fit_d_to_u();
  97. D_update_conversions();
  98. if (clear)
  99. D_erase(DEFAULT_BG_COLOR);
  100. }