pan.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* possible TODO: add support for magnify (zoom=) */
  2. #include <grass/gis.h>
  3. #include <grass/display.h>
  4. #include "local_proto.h"
  5. #include <grass/glocale.h>
  6. int do_pan(struct Cell_head *window)
  7. {
  8. int screen_x, screen_y, button;
  9. int end = 0, printmenu = 1;
  10. while (!end) {
  11. if (printmenu) {
  12. fprintf(stderr, _("\n\nButtons:\n"));
  13. fprintf(stderr, _("Left: Pan\n"));
  14. fprintf(stderr, _("Right: Quit\n"));
  15. printmenu = 0;
  16. }
  17. R_get_location_with_pointer(&screen_x, &screen_y, &button);
  18. if (button == 1) {
  19. /* pan */
  20. pan_window(window, screen_x, screen_y);
  21. printmenu = 1;
  22. }
  23. else if (button == 2) {
  24. /* noop */
  25. printmenu = 1;
  26. }
  27. else if (button == 3) {
  28. end = 1;
  29. }
  30. }
  31. return (0);
  32. }
  33. int pan_window(struct Cell_head *window, int screen_x, int screen_y)
  34. {
  35. double px, py, uxc, uyc, ux1, uy1, ux2, uy2;
  36. double north, south, east, west, ns, ew;
  37. int t;
  38. px = D_d_to_u_col((double)screen_x);
  39. py = D_d_to_u_row((double)screen_y);
  40. fprintf(stderr, "\n");
  41. print_coor(window, py, px);
  42. fprintf(stderr, "\n");
  43. uxc = D_d_to_u_col((double)screen_x);
  44. uyc = D_d_to_u_row((double)screen_y);
  45. t = uxc / window->ew_res;
  46. uxc = t * window->ew_res;
  47. t = uyc / window->ns_res;
  48. uyc = t * window->ns_res;
  49. ew = window->east - window->west;
  50. ns = window->north - window->south;
  51. ux1 = uxc - ew / 2;
  52. ux2 = uxc + ew / 2;
  53. uy1 = uyc - ns / 2;
  54. uy2 = uyc + ns / 2;
  55. north = uy1 > uy2 ? uy1 : uy2;
  56. south = uy1 < uy2 ? uy1 : uy2;
  57. west = ux1 < ux2 ? ux1 : ux2;
  58. east = ux1 > ux2 ? ux1 : ux2;
  59. if (window->proj == PROJECTION_LL) {
  60. if (north > 90) {
  61. north = 90;
  62. south = 90 - ns;
  63. }
  64. else if (south < -90) {
  65. south = -90;
  66. north = -90 + ns;
  67. }
  68. }
  69. set_win(window, east, north, west, south, 0);
  70. return (0);
  71. }