setup.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * 1. Makes sure there is a current graphics frame
  7. * (will create a full-screen one, if not
  8. * 2. Sets the region coordinates so that the graphics frame
  9. * and the active program region agree
  10. * (may change active program region to do this).
  11. * 3. Performs graphic frame/region coordinate conversion intialization
  12. *
  13. * Returns: 0 if ok. Exits with error message if failure.
  14. *
  15. * Note: Connection to driver must already be made.
  16. *
  17. * clear values:
  18. * 1: clear frame (visually and coordinates)
  19. * 0: do not clear frame
  20. */
  21. #include <string.h>
  22. #include <grass/gis.h>
  23. #include <grass/display.h>
  24. #include <grass/raster.h>
  25. /*!
  26. * \brief graphics frame setup
  27. *
  28. * Performs a full setup
  29. * for the current graphics frame: 1) Makes sure there is a current graphics
  30. * frame (will create a full-screen one, if not); 2) Sets the region coordinates
  31. * so that the graphics frame and the active module region agree (may change
  32. * active module region to do this); and 3) performs graphic frame/region
  33. * coordinate conversion initialization.
  34. * If <b>clear</b> is true, the frame is cleared (same as running
  35. * <i>d.erase.</i>) Otherwise, it is not cleared.
  36. *
  37. * \param clear
  38. * \return int
  39. */
  40. void D_setup(int clear)
  41. {
  42. struct Cell_head region;
  43. double dt, db, dl, dr;
  44. R_get_window(&dt, &db, &dl, &dr);
  45. G_get_set_window(&region);
  46. if (G_set_window(&region) < 0)
  47. G_fatal_error("Invalid graphics coordinates");
  48. D_do_conversions(&region, dt, db, dl, dr);
  49. if (clear)
  50. D_erase(DEFAULT_BG_COLOR);
  51. }
  52. void D_setup_unity(int clear)
  53. {
  54. double dt, db, dl, dr;
  55. R_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. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  63. {
  64. double dt, db, dl, dr;
  65. R_get_window(&dt, &db, &dl, &dr);
  66. D_set_src(st, sb, sl, sr);
  67. D_set_dst(dt, db, dl, dr);
  68. if (fit)
  69. D_fit_d_to_u();
  70. D_update_conversions();
  71. if (clear)
  72. D_erase(DEFAULT_BG_COLOR);
  73. }