3
* This is a high level D call.
4
* It does a full setup for the current graphics frame.
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
13
* Returns: 0 if ok. Exits with error message if failure.
15
* Note: Connection to driver must already be made.
18
* 1: clear frame (visually and coordinates)
19
* 0: do not clear frame
2
\file lib/display/setup.c
4
\brief Display Driver - setup
6
(C) 2006-2011 by the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Glynn Clements <glynn gclements.plus.com> (original contributor)
12
\author Huidae Cho <grass4u gmail.com>
21
15
#include <string.h>
22
16
#include <grass/gis.h>
17
#include <grass/raster.h>
23
18
#include <grass/display.h>
24
#include <grass/raster.h>
28
* \brief initialize/create a frame
31
* performs a series of initialization steps for the current frame. It also
32
* creates a full screen frame if there is no current frame. The <b>clear</b>
33
* flag, if set to 1, tells this routine to clear any information associated with
34
* the frame: graphics as well as region information.
35
* This routine relieves the programmer of having to perform the following
36
* idiomatic function call sequence
44
* \brief graphics frame setup
46
* Performs a full setup
47
* for the current graphics frame: 1) Makes sure there is a current graphics
48
* frame (will create a full-screen one, if not); 2) Sets the region coordinates
49
* so that the graphics frame and the active module region agree (may change
50
* active module region to do this); and 3) performs graphic frame/region
51
* coordinate conversion initialization.
52
* If <b>clear</b> is true, the frame is cleared (same as running
53
* <i>d.erase.</i>) Otherwise, it is not cleared.
59
int D_setup(int clear)
23
\brief Graphics frame setup
25
This is a high level D call. It does a full setup for the current
28
Note: Connection to driver must already be made.
30
Sets the source coordinate system to the current region, and
31
adjusts the destination coordinate system to preserve the aspect
34
Performs a full setup for the current graphics frame:
35
- Makes sure there is a current graphics frame (will create a full-screen
37
- Sets the region coordinates so that the graphics frame and the active
38
module region agree (may change active module region to do this); and
39
- Performs graphic frame/region coordinate conversion initialization.
41
If <b>clear</b> is true, the frame is cleared (same as running
42
<i>d.erase</i>.) Otherwise, it is not cleared.
44
\param clear 1 to clear frame (visually and coordinates)
46
void D_setup(int clear)
61
48
struct Cell_head region;
65
if (D_get_cur_wind(name)) {
70
strcpy(name, "full_screen");
71
D_new_window(name, t, b, l, r);
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");
79
/* clear the frame, if requested to do so */
82
R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
83
R_box_abs(l, t, r, b);
86
/* Set the map region associated with graphics frame */
49
double dt, db, dl, dr;
51
D_get_frame(&dt, &db, &dl, &dr);
87
53
G_get_set_window(®ion);
88
if (D_check_map_window(®ion))
89
G_fatal_error("Setting graphics coordinates");
90
if (G_set_window(®ion) < 0)
91
G_fatal_error("Invalid graphics coordinates");
93
/* Determine conversion factors */
94
if (D_do_conversions(®ion, t, b, l, r))
95
G_fatal_error("Error calculating graphics-region conversions");
97
/* set text clipping, for good measure */
98
R_set_window(t, b, l, r);
54
Rast_set_window(®ion);
56
D_do_conversions(®ion, dt, db, dl, dr);
58
D_set_clip_window_to_screen_window();
61
D_erase(DEFAULT_BG_COLOR);
63
D_set_clip_window_to_map_window();
67
\brief Graphics frame setup
69
Sets the source coordinate system to match the
70
destination coordinate system, so that D_* functions use the same
71
coordinate system as R_* functions.
73
If <b>clear</b> is true, the frame is cleared (same as running
74
<i>d.erase</i>). Otherwise, it is not cleared.
76
\param clear non-zero code to clear the frame
78
void D_setup_unity(int clear)
80
double dt, db, dl, dr;
82
D_get_frame(&dt, &db, &dl, &dr);
84
D_set_src(dt, db, dl, dr);
85
D_set_dst(dt, db, dl, dr);
87
D_update_conversions();
89
D_set_clip_window_to_screen_window();
92
D_erase(DEFAULT_BG_COLOR);
94
D_set_clip_window_to_map_window();
98
\brief Sets source coordinate system
100
Sets the source coordinate system to its arguments, and if
101
the <b>fit</b> argument is non-zero, adjusts the destination coordinate
102
system to preserve the aspect ratio.
104
If <b>clear</b> is true, the frame is cleared (same as running
105
<i>d.erase</i>). Otherwise, it is not cleared.
107
\param clear non-zero code to clear the frame
108
\param fit non-zero code to adjust destination coordinate system
114
void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
116
double dt, db, dl, dr;
118
D_get_frame(&dt, &db, &dl, &dr);
120
D_set_src(st, sb, sl, sr);
121
D_set_dst(dt, db, dl, dr);
126
D_update_conversions();
128
D_set_clip_window_to_screen_window();
131
D_erase(DEFAULT_BG_COLOR);
133
D_set_clip_window_to_map_window();
137
\brief Get driver output file
139
\return file name or NULL if not defined
141
const char *D_get_file(void)
143
return COM_Graph_get_file();