graphics.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "globals.h"
  2. #include "local_proto.h"
  3. #include <grass/display.h>
  4. static View *makeview(double bottom, double top, double left, double right)
  5. {
  6. View *view;
  7. view = (View *) G_malloc(sizeof(View));
  8. top = 100 - top;
  9. bottom = 100 - bottom;
  10. view->top = SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP) * top / 100.0;
  11. view->bottom = SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP) * bottom / 100.0;
  12. view->left = SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT) * left / 100.0;
  13. view->right = SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT) * right / 100.0;
  14. if (view->top < SCREEN_TOP)
  15. view->top = SCREEN_TOP;
  16. if (view->bottom > SCREEN_BOTTOM)
  17. view->bottom = SCREEN_BOTTOM;
  18. if (view->left < SCREEN_LEFT)
  19. view->left = SCREEN_LEFT;
  20. if (view->right > SCREEN_RIGHT)
  21. view->right = SCREEN_RIGHT;
  22. Outline_box(view->top, view->bottom, view->left, view->right);
  23. view->top++;
  24. view->bottom--;
  25. view->left++;
  26. view->right--;
  27. view->nrows = view->bottom - view->top + 1;
  28. view->ncols = view->right - view->left + 1;
  29. view->cell.configured = 0;
  30. return view;
  31. }
  32. int Init_graphics(void)
  33. {
  34. D_full_screen();
  35. SCREEN_TOP = R_screen_top();
  36. SCREEN_BOTTOM = R_screen_bot();
  37. SCREEN_LEFT = R_screen_left();
  38. SCREEN_RIGHT = R_screen_rite();
  39. BLACK = D_translate_color("black");
  40. BLUE = D_translate_color("blue");
  41. BROWN = D_translate_color("brown");
  42. GREEN = D_translate_color("green");
  43. GREY = D_translate_color("grey");
  44. ORANGE = D_translate_color("orange");
  45. PURPLE = D_translate_color("purple");
  46. RED = D_translate_color("red");
  47. WHITE = D_translate_color("white");
  48. YELLOW = D_translate_color("yellow");
  49. R_standard_color(WHITE);
  50. VIEW_TITLE1 = makeview(97.5, 100.0, 0.0, 50.0);
  51. VIEW_TITLE2 = makeview(97.5, 100.0, 50.0, 100.0);
  52. VIEW_MAP1 = makeview(51.0, 97.5, 0.0, 50.0);
  53. VIEW_MAP2 = makeview(51.0, 97.5, 50.0, 100.0);
  54. VIEW_TITLE1_ZOOM = makeview(47.5, 51.0, 0.0, 50.0);
  55. VIEW_TITLE2_ZOOM = makeview(47.5, 51.0, 50.0, 100.0);
  56. VIEW_MAP1_ZOOM = makeview(2.5, 47.5, 0.0, 50.0);
  57. VIEW_MAP2_ZOOM = makeview(2.5, 47.5, 50.0, 100.0);
  58. VIEW_MENU = makeview(0.0, 2.5, 0.0, 100.0);
  59. Rast_init_colors(&VIEW_MAP1->cell.colors);
  60. Rast_init_colors(&VIEW_MAP2->cell.colors);
  61. return 0;
  62. }
  63. int Outline_box(int top, int bottom, int left, int right)
  64. {
  65. R_move_abs(left, top);
  66. R_cont_abs(left, bottom);
  67. R_cont_abs(right, bottom);
  68. R_cont_abs(right, top);
  69. R_cont_abs(left, top);
  70. return 0;
  71. }
  72. int Text_width(char *text)
  73. {
  74. double top, bottom, left, right;
  75. R_get_text_box(text, &top, &bottom, &left, &right);
  76. if (right > left)
  77. return right - left + 1;
  78. else
  79. return left - right + 1;
  80. }
  81. int Text(char *text, int top, int bottom, int left, int right, int edge)
  82. {
  83. R_set_window(top, bottom, left, right);
  84. R_move_abs(left + edge, bottom - edge);
  85. R_text(text);
  86. R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);
  87. return 0;
  88. }
  89. int Uparrow(int top, int bottom, int left, int right)
  90. {
  91. R_move_abs((left + right) / 2, bottom);
  92. R_cont_abs((left + right) / 2, top);
  93. R_cont_rel((left - right) / 2, (bottom - top) / 2);
  94. R_move_abs((left + right) / 2, top);
  95. R_cont_rel((right - left) / 2, (bottom - top) / 2);
  96. return 0;
  97. }
  98. int Downarrow(int top, int bottom, int left, int right)
  99. {
  100. R_move_abs((left + right) / 2, top);
  101. R_cont_abs((left + right) / 2, bottom);
  102. R_cont_rel((left - right) / 2, (top - bottom) / 2);
  103. R_move_abs((left + right) / 2, bottom);
  104. R_cont_rel((right - left) / 2, (top - bottom) / 2);
  105. return 0;
  106. }