GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <string.h> 00002 #include <grass/raster.h> 00003 #include <grass/display.h> 00004 00005 int ident_win(char *cur_pad) 00006 { 00007 char **list; 00008 char **pads; 00009 int count; 00010 int closest; 00011 int npads; 00012 int p; 00013 int stat; 00014 int x, y, t, b, l, r; 00015 int button; 00016 int gotone; 00017 00018 /* Get list of pads (windows) */ 00019 R_pad_list(&pads, &npads); 00020 00021 button = 1; 00022 00023 x = (R_screen_rite() + R_screen_left()) / 2; 00024 y = (R_screen_top() + R_screen_bot()) / 2; 00025 00026 while (button == 1) { 00027 closest = 9999999; 00028 gotone = 0; 00029 00030 R_get_location_with_pointer(&x, &y, &button); 00031 for (p = 0; p < npads; p++) { 00032 if (!strlen(pads[p])) 00033 continue; 00034 00035 stat = R_pad_select(pads[p]); 00036 if (stat) { 00037 R_pad_perror("ERROR", stat); 00038 continue; 00039 } 00040 00041 /* Check each window's "d_win" */ 00042 stat = R_pad_get_item("d_win", &list, &count); 00043 if (stat) { 00044 R_pad_perror("ERROR", stat); 00045 continue; 00046 } 00047 sscanf(list[0], "%d %d %d %d", &t, &b, &l, &r); 00048 R_pad_freelist(list, count); 00049 00050 /* If chosen point is outside pad window, continue */ 00051 if (x < l || x > r || y < t || y > b) 00052 continue; 00053 00054 /* If right edge closer than closest, the save pad name */ 00055 if ((r - x) >= 0 && (r - x) < closest) { 00056 closest = r - x; 00057 gotone = 1; 00058 strcpy(cur_pad, pads[p]); 00059 } 00060 } 00061 00062 if (gotone) 00063 D_set_cur_wind(cur_pad); 00064 } 00065 return (button); 00066 }