GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
display/setup.c
Go to the documentation of this file.
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 
59 int D_setup(int clear)
60 {
61  struct Cell_head region;
62  char name[128];
63  int t, b, l, r;
64 
65  if (D_get_cur_wind(name)) {
66  t = R_screen_top();
67  b = R_screen_bot();
68  l = R_screen_left();
69  r = R_screen_rite();
70  strcpy(name, "full_screen");
71  D_new_window(name, t, b, l, r);
72  }
73 
74  if (D_set_cur_wind(name))
75  G_fatal_error("Current graphics frame not available");
76  if (D_get_screen_window(&t, &b, &l, &r))
77  G_fatal_error("Getting graphics coordinates");
78 
79  /* clear the frame, if requested to do so */
80  if (clear) {
82  R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
83  R_box_abs(l, t, r, b);
84  }
85 
86  /* Set the map region associated with graphics frame */
87  G_get_set_window(&region);
88  if (D_check_map_window(&region))
89  G_fatal_error("Setting graphics coordinates");
90  if (G_set_window(&region) < 0)
91  G_fatal_error("Invalid graphics coordinates");
92 
93  /* Determine conversion factors */
94  if (D_do_conversions(&region, t, b, l, r))
95  G_fatal_error("Error calculating graphics-region conversions");
96 
97  /* set text clipping, for good measure */
98  R_set_window(t, b, l, r);
99  R_move_abs(0, 0);
100  D_move_abs(0, 0);
101  return 0;
102 }