1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <stdio.h>
#include <grass/raster.h>
int get_win_w_mouse(float *top, float *bottom, float *left, float *right)
{
int button;
int st, sb, sl, sr;
int t, b, l, r;
st = R_screen_top();
sb = R_screen_bot();
sl = R_screen_left();
sr = R_screen_rite();
fprintf(stderr, "\nButtons:\n");
fprintf(stderr, "Left: Establish a corner\n");
fprintf(stderr, "Right: Accept window\n");
l = sl;
b = sb;
r = l + 10;
t = b - 10;
do {
R_get_location_with_box(l, b, &r, &t, &button);
if (button == 1) {
l = r;
b = t;
}
} while (button != 3);
if (l > r) {
button = l;
l = r;
r = button;
}
if (t > b) {
button = t;
t = b;
b = button;
}
*bottom = 100. - 100. * (b - st) / (sb - st);
*top = 100. - 100. * (t - st) / (sb - st);
*left = 100. * (l - sl) / (sr - sl);
*right = 100. * (r - sl) / (sr - sl);
return 0;
}
|