GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ident_win.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <grass/raster.h>
3 #include <grass/display.h>
4 
5 int ident_win(char *cur_pad)
6 {
7  char **list;
8  char **pads;
9  int count;
10  int closest;
11  int npads;
12  int p;
13  int stat;
14  int x, y, t, b, l, r;
15  int button;
16  int gotone;
17 
18  /* Get list of pads (windows) */
19  R_pad_list(&pads, &npads);
20 
21  button = 1;
22 
23  x = (R_screen_rite() + R_screen_left()) / 2;
24  y = (R_screen_top() + R_screen_bot()) / 2;
25 
26  while (button == 1) {
27  closest = 9999999;
28  gotone = 0;
29 
30  R_get_location_with_pointer(&x, &y, &button);
31  for (p = 0; p < npads; p++) {
32  if (!strlen(pads[p]))
33  continue;
34 
35  stat = R_pad_select(pads[p]);
36  if (stat) {
37  R_pad_perror("ERROR", stat);
38  continue;
39  }
40 
41  /* Check each window's "d_win" */
42  stat = R_pad_get_item("d_win", &list, &count);
43  if (stat) {
44  R_pad_perror("ERROR", stat);
45  continue;
46  }
47  sscanf(list[0], "%d %d %d %d", &t, &b, &l, &r);
48  R_pad_freelist(list, count);
49 
50  /* If chosen point is outside pad window, continue */
51  if (x < l || x > r || y < t || y > b)
52  continue;
53 
54  /* If right edge closer than closest, the save pad name */
55  if ((r - x) >= 0 && (r - x) < closest) {
56  closest = r - x;
57  gotone = 1;
58  strcpy(cur_pad, pads[p]);
59  }
60  }
61 
62  if (gotone)
63  D_set_cur_wind(cur_pad);
64  }
65  return (button);
66 }
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_list(char ***list, int *count)
Definition: com_pad.c:39
void R_pad_perror(const char *msg, int code)
Definition: common.c:22
float r
Definition: named_colr.c:8
int count
int y
Definition: plot.c:34
int R_screen_rite(void)
screen right edge
Definition: com_proto.c:38
int stat
Definition: g3dcolor.c:369
int R_screen_left(void)
screen left edge
Definition: com_proto.c:24
int R_screen_top(void)
top of screen
Definition: com_proto.c:67
int R_pad_select(const char *pad)
Definition: com_pad.c:44
void R_pad_freelist(char **list, int count)
Definition: common.c:56
void R_get_location_with_pointer(int *wx, int *wy, int *button)
Definition: com_get.c:17
int ident_win(char *cur_pad)
Definition: ident_win.c:5
int R_pad_get_item(const char *name, char ***list, int *count)
Definition: com_pad.c:59