box.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <grass/gis.h>
  5. #include <grass/display.h>
  6. #include "local_proto.h"
  7. int make_window_box(struct Cell_head *window, double magnify, int full,
  8. int hand)
  9. {
  10. int screen_x, screen_y;
  11. double px, py, ux1, uy1, ux2, uy2;
  12. double ns, ew;
  13. int button;
  14. int cur_screen_x, cur_screen_y;
  15. int mode; /* 1, 2 */
  16. int resetwin;
  17. struct Cell_head defwin;
  18. int printmenu = 1;
  19. G_get_default_window(&defwin);
  20. mode = 1;
  21. while (1) {
  22. resetwin = 0;
  23. if (!hand) {
  24. if (printmenu) {
  25. fprintf(stderr, "\n\nButtons:\n");
  26. fprintf(stderr, "Left: 1. corner\n");
  27. fprintf(stderr, "Middle: Unzoom\n");
  28. if (full)
  29. fprintf(stderr, "Right: Main menu\n\n");
  30. else
  31. fprintf(stderr, "Right: Quit\n\n");
  32. printmenu = 0;
  33. }
  34. }
  35. else {
  36. if (mode == 1)
  37. fprintf(stderr, "\r1. corner");
  38. else
  39. fprintf(stderr, "\r2. corner");
  40. }
  41. if (mode == 1) {
  42. if (!hand) {
  43. R_get_location_with_pointer(&screen_x, &screen_y, &button);
  44. }
  45. else {
  46. R_get_location_with_box(0, 0, &screen_x, &screen_y, &button);
  47. }
  48. cur_screen_x = screen_x;
  49. cur_screen_y = screen_y;
  50. }
  51. else {
  52. R_get_location_with_box(cur_screen_x, cur_screen_y, &screen_x,
  53. &screen_y, &button);
  54. }
  55. /* For print only */
  56. px = D_d_to_u_col((double)screen_x);
  57. py = D_d_to_u_row((double)screen_y);
  58. if (!hand)
  59. print_coor(window, py, px);
  60. if (button == 1) {
  61. if (!hand) {
  62. if (mode == 1) {
  63. fprintf(stderr, "\n\nButtons:\n");
  64. fprintf(stderr, "Left: 1. corner (reset)\n");
  65. fprintf(stderr, "Middle: 2. corner\n");
  66. if (full)
  67. fprintf(stderr, "Right: Main menu\n\n");
  68. else
  69. fprintf(stderr, "Right: Quit\n\n");
  70. mode = 2;
  71. }
  72. if (mode == 2) {
  73. cur_screen_x = screen_x;
  74. cur_screen_y = screen_y;
  75. }
  76. }
  77. else { /* hand */
  78. if (mode == 1) {
  79. mode = 2;
  80. }
  81. else {
  82. ux1 = D_d_to_u_col((double)cur_screen_x);
  83. uy1 = D_d_to_u_row((double)cur_screen_y);
  84. ux2 = D_d_to_u_col((double)screen_x);
  85. uy2 = D_d_to_u_row((double)screen_y);
  86. resetwin = 1;
  87. mode = 1;
  88. }
  89. }
  90. }
  91. else if (button == 2) {
  92. if (mode == 1) { /* unzoom */
  93. ux2 = D_d_to_u_col((double)screen_x);
  94. uy2 = D_d_to_u_row((double)screen_y);
  95. ew = window->east - window->west;
  96. ns = window->north - window->south;
  97. if (ns <= window->ns_res)
  98. ns = 2 * window->ns_res;
  99. else
  100. ew /= magnify;
  101. if (ew <= window->ew_res)
  102. ew = 2 * window->ew_res;
  103. else
  104. ns /= magnify;
  105. ux1 = window->east + ew / 2;
  106. ux2 = window->west - ew / 2;
  107. uy1 = window->north + ns / 2;
  108. uy2 = window->south - ns / 2;
  109. }
  110. else {
  111. ux1 = D_d_to_u_col((double)cur_screen_x);
  112. uy1 = D_d_to_u_row((double)cur_screen_y);
  113. ux2 = D_d_to_u_col((double)screen_x);
  114. uy2 = D_d_to_u_row((double)screen_y);
  115. printmenu = 1;
  116. mode = 1;
  117. }
  118. fprintf(stderr, "\n");
  119. resetwin = 1;
  120. }
  121. else {
  122. fprintf(stderr, "\n");
  123. return 1;
  124. }
  125. if (resetwin) {
  126. set_win(window, ux1, uy1, ux2, uy2, hand);
  127. }
  128. }
  129. fprintf(stderr, "\n");
  130. return 1; /* not reached */
  131. }