zoom_box.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include <grass/display.h>
  2. #include <grass/glocale.h>
  3. #include "globals.h"
  4. #include "local_proto.h"
  5. static int x1, y1, x2, y2;
  6. static View *pick_view, *zoom_view, *main_view;
  7. static int cancel(void);
  8. static int zoom1(int, int, int);
  9. static int zoom2(int, int, int);
  10. int zoom_box(void)
  11. {
  12. static int use = 1;
  13. static Objects objects[] = {
  14. MENU("Cancel", cancel, &use),
  15. INFO(" Mark first corner of window ", &use),
  16. OTHER(zoom1, &use),
  17. {0}
  18. };
  19. pick_view = zoom_view = main_view = NULL;
  20. Input_pointer(objects);
  21. return 0;
  22. }
  23. static int zoom1( /* called by Input_pointer */
  24. int x, int y, int b)
  25. { /* called by Input_pointer */
  26. static int use = 1;
  27. static Objects objects[] = {
  28. MENU("Cancel", cancel, &use),
  29. INFO(" Define the window ", &use),
  30. OTHER(zoom2, &use),
  31. {0}
  32. };
  33. /*
  34. * user has marked first corner
  35. * this determines which view is being zoomed
  36. */
  37. G_debug(4, "\nX, Y, B in zoom1 %d %d %d", x, y, b);
  38. x1 = x;
  39. y1 = y;
  40. if (In_view(pick_view = VIEW_MAP1, x1, y1)) {
  41. main_view = VIEW_MAP1;
  42. zoom_view = VIEW_MAP1_ZOOM;
  43. }
  44. else if (In_view(pick_view = VIEW_MAP1_ZOOM, x1, y1)) {
  45. if (!pick_view->cell.configured)
  46. return 0; /* ignore the mouse event */
  47. main_view = VIEW_MAP1;
  48. zoom_view = VIEW_MAP1_ZOOM;
  49. }
  50. else
  51. return 0; /* ignore the mouse event */
  52. if (!pick_view->cell.configured)
  53. return 0; /* just to be sure */
  54. return Input_box(objects, x, y);
  55. }
  56. static int zoom2(int x, int y, int b)
  57. {
  58. int top, bottom, left, right;
  59. int row, col;
  60. struct Cell_head cellhd;
  61. G_debug(4, "\nX, Y, B in zoom2 %d %d %d", x, y, b);
  62. x2 = x;
  63. y2 = y;
  64. /*
  65. * user has completed the zoom window.
  66. * must be in same view as first corner
  67. */
  68. if (x1 == x2 || y1 == y2)
  69. return 0; /* ignore event */
  70. if (!In_view(pick_view, x2, y2))
  71. return 0;
  72. /*
  73. * ok, erase menu messages
  74. */
  75. Menu_msg("");
  76. /*
  77. * assign window coordinates to top,bottom,left,right
  78. */
  79. if (x1 < x2) {
  80. left = x1;
  81. right = x2;
  82. }
  83. else {
  84. left = x2;
  85. right = x1;
  86. }
  87. if (y1 < y2) {
  88. top = y1;
  89. bottom = y2;
  90. }
  91. else {
  92. top = y2;
  93. bottom = y1;
  94. }
  95. G_debug(4, "\nleft right top bottom %d %d %d %d",
  96. left, right, top, bottom);
  97. /*
  98. * Determine the the zoom window (ie, cellhd)
  99. * must copy the current view cellhd first, to preserve header info
  100. * (such as projection, zone, and other items.)
  101. * compute zoom window northings,eastings, rows, cols, and resolution
  102. */
  103. G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));
  104. /* convert top to northing at top edge of cell
  105. * left to easting at left edge
  106. */
  107. col = view_to_col(pick_view, left);
  108. row = view_to_row(pick_view, top);
  109. cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
  110. cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);
  111. /* convert bottom to northing at bottom edge of cell
  112. * right to easting at right edge
  113. */
  114. col = view_to_col(pick_view, right);
  115. row = view_to_row(pick_view, bottom);
  116. cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
  117. cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);
  118. cellhd.rows = bottom - top + 1;
  119. cellhd.cols = right - left + 1;
  120. cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
  121. cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
  122. G_debug(4, "\nnorth,south,east,west,nsres,ewres %f %f %f %f %f %f",
  123. cellhd.north, cellhd.south, cellhd.east, cellhd.west,
  124. cellhd.ns_res, cellhd.ew_res);
  125. /*
  126. * Outline the zoom window on the main map
  127. * Turn previous one to grey.
  128. */
  129. if (zoom_view->cell.configured) {
  130. R_standard_color(GREY);
  131. Outline_cellhd(main_view, &zoom_view->cell.head);
  132. }
  133. R_standard_color(RED);
  134. Outline_cellhd(main_view, &cellhd);
  135. /* If a region is drawn in the zoom window erase it and the saved
  136. region, if any */
  137. if (Region.area.define && Region.view == VIEW_MAP1_ZOOM) {
  138. erase_region();
  139. if (Region.area.saved) {
  140. Region.saved_npoints = 0;
  141. Region.area.saved = 0;
  142. Region.saved_view = NULL;
  143. }
  144. }
  145. /*
  146. * zoom
  147. */
  148. G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
  149. zoom_view->ncols);
  150. Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
  151. pick_view->cell.ns_res, pick_view->cell.ew_res);
  152. draw_cell(zoom_view, OVER_WRITE);
  153. return 1; /* pop back */
  154. }
  155. static int cancel(void)
  156. {
  157. return -1;
  158. }