GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
int l
Definition: dataquad.c:292
float b
Definition: named_colr.c:8
int D_set_cur_wind(const char *name)
set current graphics frame
int R_screen_bot(void)
bottom of screen
Definition: com_proto.c:52
int G_get_set_window(struct Cell_head *window)
Get the current working window.
Definition: set_window.c:30
void R_box_abs(int x1, int y1, int x2, int y2)
fill a box
Definition: com_proto.c:350
int D_check_map_window(struct Cell_head *wind)
assign/retrieve current map region
string name
Definition: render.py:1314
float r
Definition: named_colr.c:8
int G_set_window(struct Cell_head *window)
Establishes &#39;window&#39; as the current working window.
Definition: set_window.c:49
int D_move_abs(int x, int y)
move to pixel
Definition: display/draw.c:215
void R_standard_color(int index)
select standard color
Definition: com_proto.c:90
int D_get_cur_wind(char *name)
identify current graphics frame
int D_clear_window(void)
clears information about current frame
Definition: display/list.c:233
int R_screen_rite(void)
screen right edge
Definition: com_proto.c:38
int D_do_conversions(const struct Cell_head *window, int t, int b, int l, int r)
initialize conversions
Definition: cnversions.c:69
int R_screen_left(void)
screen left edge
Definition: com_proto.c:24
void R_move_abs(int x, int y)
move current location
Definition: com_proto.c:153
int R_screen_top(void)
top of screen
Definition: com_proto.c:67
int D_new_window(char *name, int t, int b, int l, int r)
create new graphics frame
int D_translate_color(const char *str)
color name to number
Definition: tran_colr.c:27
int D_get_screen_window(int *t, int *b, int *l, int *r)
retrieve current frame coordinates
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void R_set_window(int t, int b, int l, int r)
set text clipping frame
Definition: com_proto.c:406
int D_setup(int clear)
initialize/create a frame
Definition: display/setup.c:59