GRASS Programmer's Manual  6.4.2(2012)
display/setup.c
Go to the documentation of this file.
00001 /* D_setup (clear)
00002  *
00003  * This is a high level D call.
00004  * It does a full setup for the current graphics frame.
00005  *
00006  *   1. Makes sure there is a current graphics frame
00007  *      (will create a full-screen one, if not
00008  *   2. Sets the region coordinates so that the graphics frame
00009  *      and the active program region agree
00010  *      (may change active program region to do this).
00011  *   3. Performs graphic frame/region coordinate conversion intialization
00012  *
00013  * Returns: 0 if ok. Exits with error message if failure.
00014  *
00015  * Note: Connection to driver must already be made.
00016  *
00017  * clear values:
00018  *   1: clear frame (visually and coordinates)
00019  *   0: do not clear frame
00020  */
00021 #include <string.h>
00022 #include <grass/gis.h>
00023 #include <grass/display.h>
00024 #include <grass/raster.h>
00025 
00026 
00059 int D_setup(int clear)
00060 {
00061     struct Cell_head region;
00062     char name[128];
00063     int t, b, l, r;
00064 
00065     if (D_get_cur_wind(name)) {
00066         t = R_screen_top();
00067         b = R_screen_bot();
00068         l = R_screen_left();
00069         r = R_screen_rite();
00070         strcpy(name, "full_screen");
00071         D_new_window(name, t, b, l, r);
00072     }
00073 
00074     if (D_set_cur_wind(name))
00075         G_fatal_error("Current graphics frame not available");
00076     if (D_get_screen_window(&t, &b, &l, &r))
00077         G_fatal_error("Getting graphics coordinates");
00078 
00079     /* clear the frame, if requested to do so */
00080     if (clear) {
00081         D_clear_window();
00082         R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
00083         R_box_abs(l, t, r, b);
00084     }
00085 
00086     /* Set the map region associated with graphics frame */
00087     G_get_set_window(&region);
00088     if (D_check_map_window(&region))
00089         G_fatal_error("Setting graphics coordinates");
00090     if (G_set_window(&region) < 0)
00091         G_fatal_error("Invalid graphics coordinates");
00092 
00093     /* Determine conversion factors */
00094     if (D_do_conversions(&region, t, b, l, r))
00095         G_fatal_error("Error calculating graphics-region conversions");
00096 
00097     /* set text clipping, for good measure */
00098     R_set_window(t, b, l, r);
00099     R_move_abs(0, 0);
00100     D_move_abs(0, 0);
00101     return 0;
00102 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines