GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
display/window.c
Go to the documentation of this file.
1 /*
2  * D_new_window(name, t, b, l, r)
3  * creates a new window with given coordinates
4  * if "name" is an empty string, the routine returns a unique
5  * string in "name"
6  *
7  * D_reset_screen_window(t, b, l, r)
8  * resets the edges of the current window
9  *
10  * D_set_cur_wind(name)
11  * saves "name" in cur_w field in "no-name" pad
12  * outlines previous current window in GRAY
13  * outlines "name" in DEFAULT_FG_COLOR
14  *
15  * D_get_cur_wind(name)
16  * gets the current name stored in cur_w field in "no_name" pad
17  *
18  * D_show_window(color)
19  * outlines current window in color (from ../colors.h)
20  *
21  * D_get_screen_window(t, b, l, r)
22  * returns current window's coordinates
23  *
24  * D_check_map_window(wind)
25  * if map window (m_win) already assigned
26  * map window is read into the struct "wind"
27  * else
28  * struct "wind" is written to map window (m_win)
29  *
30  * D_remove_window()
31  * remove any trace of window
32  *
33  * D_erase_window()
34  * Erases the window on scree. Does not affect window contents list.
35  */
36 
37 #include <string.h>
38 #include <grass/colors.h>
39 #include <grass/gis.h>
40 #include <grass/display.h>
41 #include <grass/raster.h>
42 
43 
60 int D_new_window(char *name, int t, int b, int l, int r)
61 {
62  int stat;
63  char buff[256];
64 
65  /* If no name was sent, get a unique name for the window */
66  if (!*name)
67  R_pad_invent(name);
68 
69  /* Create the work pad */
70  if ((stat = R_pad_create(name))) {
71  R_pad_perror(name, stat);
72  return (-1);
73  }
74 
75  /* Select work pad for use */
76  if ((stat = R_pad_select(name)))
77  goto pad_error;
78 
79  /* Timestamp current pad */
80  D_timestamp();
81 
82  sprintf(buff, "%d %d %d %d", t, b, l, r);
83  if ((stat = R_pad_set_item("d_win", buff)))
84  goto pad_error;
85 
86  /* Display outline of new window */
87  D_show_window(GRAY);
88 
89  R_set_window(t, b, l, r);
90 
91  return (0);
92 
93  pad_error:
94  R_pad_delete();
95  sprintf(buff, "window <%s>, item <%s>", name, "d_win");
96  R_pad_perror(buff, stat);
97 
98  return (-1);
99 }
100 
101 
118 int D_new_window_percent(char *name, float b, float t, float l, float r)
119 {
120  int scr_t = R_screen_top();
121  int scr_b = R_screen_bot();
122  int scr_l = R_screen_left();
123  int scr_r = R_screen_rite();
124 
125  int win_t = 0.5 + scr_t + (scr_b - scr_t) * (100. - t) / 100.0;
126  int win_b = 0.5 + scr_t + (scr_b - scr_t) * (100. - b) / 100.0;
127  int win_l = 0.5 + scr_l + (scr_r - scr_l) * l / 100.0;
128  int win_r = 0.5 + scr_l + (scr_r - scr_l) * r / 100.0;
129 
130  if (win_t < scr_t)
131  win_t = scr_t;
132  if (win_b > scr_b)
133  win_b = scr_b;
134  if (win_l < scr_l)
135  win_l = scr_l;
136  if (win_r > scr_r)
137  win_r = scr_r;
138 
139  return D_new_window(name, win_t, win_b, win_l, win_r);
140 }
141 
142 
154 int D_set_cur_wind(const char *name)
155 {
156  char pad_cur[64];
157  int stat;
158  int not_same_window;
159  int t, b, l, r;
160 
161  /* Abort if window name is null */
162  if (!strlen(name))
163  return (-1);
164 
165  /* Abort if window name is not available */
166  if ((stat = R_pad_select(name)))
167  return (stat);
168 
169  /* Get name of current window pad */
170  D_get_cur_wind(pad_cur);
171 
172  /* Establish whether it is the same as the currently selected pad */
173  if (strlen(pad_cur)) {
174  not_same_window = strcmp(name, pad_cur);
175  if (not_same_window) {
176  R_pad_select(pad_cur);
177  D_show_window(GRAY);
178  }
179  }
180  else {
181  not_same_window = 1;
182  }
183 
184  if (not_same_window) {
185  /* Delete the current window name in no-name pad */
186  R_pad_select("");
187  if ((stat = R_pad_delete_item("cur_w")))
188  return (stat);
189 
190  /* Update the current window name in no-name pad */
191  if ((stat = R_pad_set_item("cur_w", name)))
192  return (stat);
193 
194  /* Select new window pad */
195  if ((stat = R_pad_select(name)))
196  return (stat);
197 
198  /* Outline new window in highlight color */
199  D_show_window(D_translate_color(DEFAULT_FG_COLOR));
200 
201  /* Tell driver of current window */
202  D_get_screen_window(&t, &b, &l, &r);
203  R_set_window(t, b, l, r);
204  }
205  else {
206  /* Select new window pad */
207  if ((stat = R_pad_select(name)))
208  return (stat);
209  }
210 
211  return (0);
212 }
213 
214 
225 {
226  int count;
227  int stat;
228  char **list;
229 
230  if ((stat = R_pad_select("")))
231  return (stat);
232 
233  if ((stat = R_pad_get_item("cur_w", &list, &count))) {
234  strcpy(name, "");
235  return (stat);
236  }
237 
238  strcpy(name, list[0]);
239  R_pad_freelist(list, count);
240  R_pad_select(name);
241  return (0);
242 }
243 
244 
259 {
260  int t, b, l, r;
261  int stat;
262 
263  if ((stat = D_get_screen_window(&t, &b, &l, &r)))
264  return (stat);
265 
266  R_set_window(t - 1, b + 1, l - 1, r + 1);
267 
268  R_standard_color(color);
269  R_move_abs(l - 1, b);
270  R_cont_abs(l - 1, t - 1);
271  R_cont_abs(r, t - 1);
272  R_cont_abs(r, b);
273  R_cont_abs(l - 1, b);
274  R_flush();
275 
276  R_set_window(t, b, l, r);
277 
278  return (0);
279 }
280 
281 
295 int D_get_screen_window(int *t, int *b, int *l, int *r)
296 {
297  int stat;
298  int count;
299  char **list;
300 
301  if ((stat = R_pad_get_item("d_win", &list, &count)))
302  return (stat);
303 
304  sscanf(list[0], "%d %d %d %d", t, b, l, r);
305 
306  R_pad_freelist(list, count);
307 
308  return (0);
309 }
310 
311 
326 int D_check_map_window(struct Cell_head *wind)
327 {
328  char buff[256];
329  char ebuf[64], nbuf[64], sbuf[64], wbuf[64];
330  int num;
331  int count;
332  char **list;
333  char *err;
334 
335  if (0 != R_pad_get_item("m_win", &list, &count)) {
336  G_format_easting(wind->east, ebuf, wind->proj);
337  G_format_easting(wind->west, wbuf, wind->proj);
338  G_format_northing(wind->north, nbuf, wind->proj);
339  G_format_northing(wind->south, sbuf, wind->proj);
340  sprintf(buff, "%d %d %s %s %s %s %d %d",
341  wind->proj, wind->zone,
342  ebuf, wbuf, nbuf, sbuf, wind->rows, wind->cols);
343  if (R_pad_set_item("m_win", buff))
344  return (-1);
345  return (0);
346  }
347  else {
348  num = sscanf(list[0], "%d %d %s %s %s %s %d %d",
349  &wind->proj, &wind->zone,
350  ebuf, wbuf, nbuf, sbuf, &wind->rows, &wind->cols);
351 
352  R_pad_freelist(list, count);
353 
354  if (num != 8)
355  return -2;
356 
357  if (!G_scan_easting(ebuf, &wind->east, wind->proj))
358  return -2;
359  if (!G_scan_easting(wbuf, &wind->west, wind->proj))
360  return -2;
361  if (!G_scan_northing(nbuf, &wind->north, wind->proj))
362  return -2;
363  if (!G_scan_northing(sbuf, &wind->south, wind->proj))
364  return -2;
365 
366  if ((err = G_adjust_Cell_head(wind, 1, 1)))
367  return -2;
368 
369  return 0;
370  }
371 }
372 
373 
387 int D_reset_screen_window(int t, int b, int l, int r)
388 {
389  int stat;
390  char buff[256];
391 
392  D_show_window(D_translate_color(DEFAULT_BG_COLOR));
393 
394  sprintf(buff, "%d %d %d %d", t, b, l, r);
395  R_pad_delete_item("d_win");
396  if ((stat = R_pad_set_item("d_win", buff)))
397  return (stat);
398 
399  D_show_window(D_translate_color(DEFAULT_FG_COLOR));
400 
401  return (0);
402 }
403 
404 
416 int D_timestamp(void)
417 {
418  char buff[128];
419  int stat;
420  int count;
421  char **list;
422  char cur_pad[64];
423  int cur_time;
424 
425  R_pad_current(cur_pad);
426 
427  R_pad_select("");
428  if ((stat = R_pad_get_item("time", &list, &count))) {
429  R_pad_set_item("time", "1");
430  R_pad_select(cur_pad);
431  R_pad_set_item("time", "1");
432  return (1);
433  }
434 
435  sscanf(list[0], "%d", &cur_time);
436  sprintf(buff, "%d", cur_time + 1);
437  R_pad_set_item("time", buff);
438 
439  R_pad_freelist(list, count);
440 
441  R_pad_select(cur_pad);
442 
443  R_pad_delete_item("time");
444  return (R_pad_set_item("time", buff));
445 }
446 
447 
457 void D_remove_window(void)
458 {
459  R_pad_delete();
460  R_pad_select("");
461  R_pad_delete_item("cur_w");
462 }
463 
473 void D_erase_window(void)
474 {
475  int t, b, l, r;
476 
477  D_get_screen_window(&t, &b, &l, &r);
478  R_box_abs(l, t, r, b);
479  R_flush();
480 }
481 
482 void D_erase(const char *color)
483 {
484  int t, b, l, r;
485  int colorindex;
486 
487  D_get_screen_window(&t, &b, &l, &r);
488  D_clear_window();
489 
490  /* Parse and select background color */
491  colorindex = D_parse_color(color, 0);
492  D_raster_use_color(colorindex);
493 
494  /* Do the plotting */
495  R_box_abs(l, t, r, b);
496 
497  /* Add erase item to the pad */
498  D_set_erase_color(color);
499 }
500 
502 {
503  char **pads;
504  int npads;
505  int i;
506 
507  R_pad_list(&pads, &npads);
508 
509  R_pad_select("");
510  R_pad_delete_item("time");
511  R_pad_delete_item("cur_w");
512 
513  for (i = 0; i < npads; i++) {
514  R_pad_select(pads[i]);
515  R_pad_delete();
516  }
517 }
518 
519 void D_full_screen(void)
520 {
522 
523  D_new_window_percent("full_screen", 0.0, 100.0, 0.0, 100.0);
524  if (D_set_cur_wind("full_screen") == 0)
525  D_timestamp();
526 
527  R_standard_color(D_translate_color(DEFAULT_BG_COLOR));
528  R_erase();
529 }
void R_flush(void)
flush graphics
Definition: common.c:17
void D_erase(const char *color)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
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 R_pad_delete(void)
Definition: com_pad.c:29
int R_pad_list(char ***list, int *count)
Definition: com_pad.c:39
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
int D_reset_screen_window(int t, int b, int l, int r)
resets current frame position
string name
Definition: render.py:1314
void R_pad_perror(const char *msg, int code)
Definition: common.c:22
void D_erase_window(void)
erase current frame
float r
Definition: named_colr.c:8
int D_new_window_percent(char *name, float b, float t, float l, float r)
create new graphics frame, with coordinates in percent
int count
long num
Definition: g3dcats.c:93
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 R_pad_set_item(const char *name, const char *value)
Definition: com_pad.c:69
const char * err
Definition: g3dcolor.c:50
void D_remove_window(void)
remove a frame
int D_clear_window(void)
clears information about current frame
Definition: display/list.c:233
void R_erase(void)
erase screen
Definition: com_proto.c:137
int R_screen_rite(void)
screen right edge
Definition: com_proto.c:38
char buff[1024]
Definition: g3dcats.c:89
int R_pad_current(char *name)
Definition: com_pad.c:24
int D_raster_use_color(int color)
draw with a color from D_parse_color
Definition: tran_colr.c:146
void R_cont_abs(int x, int y)
draw line
Definition: com_proto.c:190
int stat
Definition: g3dcolor.c:369
int D_set_erase_color(const char *colorname)
Definition: display/list.c:247
void D_full_screen(void)
int R_screen_left(void)
screen left edge
Definition: com_proto.c:24
tuple color
Definition: tools.py:1703
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 R_pad_delete_item(const char *name)
Definition: com_pad.c:54
int R_pad_select(const char *pad)
Definition: com_pad.c:44
char * G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
Definition: adj_cellhd.c:43
int D_new_window(char *name, int t, int b, int l, int r)
create new graphics frame
void D_remove_windows(void)
int D_show_window(int color)
outlines current frame
int D_translate_color(const char *str)
color name to number
Definition: tran_colr.c:27
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Definition: wind_scan.c:37
void R_pad_freelist(char **list, int count)
Definition: common.c:56
int G_format_easting(double east, char *buf, int projection)
Easting to ASCII.
Definition: wind_format.c:61
int D_get_screen_window(int *t, int *b, int *l, int *r)
retrieve current frame coordinates
int R_pad_invent(char *pad)
Definition: com_pad.c:34
void R_set_window(int t, int b, int l, int r)
set text clipping frame
Definition: com_proto.c:406
int G_format_northing(double north, char *buf, int projection)
Northing to ASCII.
Definition: wind_format.c:36
int R_pad_create(const char *pad)
Definition: com_pad.c:19
int D_timestamp(void)
give current time to frame
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
Definition: wind_scan.c:65
int R_pad_get_item(const char *name, char ***list, int *count)
Definition: com_pad.c:59
int D_parse_color(const char *str, int none_acceptable)
color option text to usable color number
Definition: tran_colr.c:123