GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <stdio.h> 00002 #include <grass/raster.h> 00003 00004 int get_win_w_mouse(float *top, float *bottom, float *left, float *right) 00005 { 00006 int button; 00007 int st, sb, sl, sr; 00008 int t, b, l, r; 00009 00010 st = R_screen_top(); 00011 sb = R_screen_bot(); 00012 sl = R_screen_left(); 00013 sr = R_screen_rite(); 00014 00015 fprintf(stderr, "\nButtons:\n"); 00016 fprintf(stderr, "Left: Establish a corner\n"); 00017 fprintf(stderr, "Right: Accept window\n"); 00018 00019 l = sl; 00020 b = sb; 00021 r = l + 10; 00022 t = b - 10; 00023 00024 do { 00025 R_get_location_with_box(l, b, &r, &t, &button); 00026 if (button == 1) { 00027 l = r; 00028 b = t; 00029 } 00030 } while (button != 3); 00031 00032 if (l > r) { 00033 button = l; 00034 l = r; 00035 r = button; 00036 } 00037 00038 if (t > b) { 00039 button = t; 00040 t = b; 00041 b = button; 00042 } 00043 *bottom = 100. - 100. * (b - st) / (sb - st); 00044 *top = 100. - 100. * (t - st) / (sb - st); 00045 *left = 100. * (l - sl) / (sr - sl); 00046 *right = 100. * (r - sl) / (sr - sl); 00047 00048 return 0; 00049 }