6
int top, bottom, left, right;
11
static struct box cancel, more, less;
12
static int height, size, edge, count;
13
static int page, npages;
16
char name[100], mapset[100];
20
int ask_line_color(char *colors, int len1, char *xname, int position)
24
static Objects objects[] = {
38
int top, bottom, left, right, center;
39
int topx, bottomx, leftx, rightx, widthx;
40
char name[100], mapset[100], cur_mapset[100];
45
sprintf(msg, "Double click on color to assign to vector layer");
48
* build a popup window at center of the screen.
49
* 35% the height and wide enough to hold 2 columms of file names
51
* the window is for choosing file names and will be laid out in 2 columns
53
* ------------------------------------------
54
* | CANCEL | (MORE) | (LESS) |
55
* ------------------------------------------
57
* ------------------------------------------
59
* ------------------------------------------
61
* ------------------------------------------
66
* ------------------------------------------
69
/* height of 1 line, based on NLINES taking up 35% vertical space */
70
height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;
72
/* size of text, 80% of line height */
73
text_size = .8 * height;
74
size = text_size - 1; /* fudge for computing pixels width of text */
76
/* indent for the text */
77
edge = .1 * height + 1;
79
/* this is a fudge to determine the length of the largest text */
80
len1 = 2 * len1; /* name in 2 columns */
81
len2 += strlen("mapset ");
82
len = (len1 > len2 ? len1 : len2);
84
/* width is for max chars plus sidecar for more/less */
85
width = len * size + height;
86
widthx = strlen(msg) * size;
90
/* define the window */
91
top = (SCREEN_TOP + SCREEN_BOTTOM - height * NLINES) / 2;
92
bottom = top + height * NLINES;
94
center = (SCREEN_LEFT + SCREEN_RIGHT) / 2;
96
right = (center + SCREEN_RIGHT + width) / 2;
97
if (right >= SCREEN_RIGHT)
98
right = SCREEN_RIGHT - 1;
101
else if (position < 0) {
102
left = (center + SCREEN_LEFT - width) / 2;
103
if (left <= SCREEN_LEFT)
104
left = SCREEN_LEFT + 1;
105
right = left + width;
108
left = center + width / 2;
109
right = left + width;
112
topx = top - 3 * height;
113
bottomx = topx + 2 * height;
114
leftx = (left + right - widthx) / 2;
115
if (leftx < SCREEN_LEFT)
117
rightx = leftx + widthx;
119
/* save what is under these areas, so they can be restored */
120
R_panel_save(tempfile1, top, bottom, left, right);
121
R_panel_save(tempfile2, topx, bottomx, leftx, rightx);
123
/* fill it top with GREY, pick area with white */
124
R_standard_color(WHITE);
125
R_box_abs(left, top, right, bottom);
126
R_standard_color(GREY);
127
R_box_abs(leftx, topx, rightx, bottomx);
129
R_standard_color(BLACK);
130
Outline_box(top, bottom, left, right);
131
right -= height; /* reduce it to exclude sidecar */
132
Outline_box(top, bottom, left, right);
134
/* print messages above the files */
135
dotext(msg, topx, topx + height, leftx, rightx, 1);
136
dotext("Double click here to cancel", topx + height, bottomx, leftx,
139
cancel.bottom = bottomx;
141
cancel.right = rightx;
143
/* start the mouse in the cancel box */
144
Set_mouse_xy((leftx + rightx) / 2, (topx + bottomx) / 2);
146
dobox(&less, "", WHITE, top, right, right + height, 0);
147
dobox(&more, "", WHITE, bottom - height, right, right + height, 0);
149
/* as we read the file of names, keep track of pages so we can
153
page_offset = (long *)G_calloc(npages = 1, sizeof(long));
154
*page_offset = ftell(fd);
156
nlist = sizeof(list) / sizeof(list[0]);
157
for (stat = -1; stat < 0;) {
165
if (fgets (buf, sizeof buf, fd) == NULL
166
|| sscanf (buf, "%s %s", name, mapset) != 2)
168
if(new_mapset = (strcmp (cur_mapset,mapset) != 0))
174
if (count >= nlist || line+new_mapset >= NLINES)
176
if (page+1 == npages)
179
page_offset = (long *) G_realloc (page_offset, npages * sizeof (long));
180
page_offset[npages-1] = offset;
189
strcpy (cur_mapset, mapset);
190
sprintf (label, "Mapset %s", mapset);
191
dobox (&dummy, label, WHITE, top+line*height, left, right, 0);
196
dobox (&list[count].box, name, GREY, top+line*height, left+width/2, right, 0);
202
dobox (&list[count].box, name, GREY, top+line*height, left, left+width/2, 0);
205
strcpy (list[count].name, name);
206
strcpy (list[count].mapset, mapset);
209
downarrow (&more, page+1 < npages ? BLACK : WHITE);
210
uparrow (&less, page > 0 ? BLACK : WHITE);
212
switch(Input_pointer(objects))
214
case -1: /* more or less */
216
case -2: /* cancel */
219
default: /* file picked */
220
strcpy(xname, list[which].name);
224
fseek(fd, page_offset[page], 0);
225
R_standard_color(WHITE);
226
R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
229
/* all done. restore what was under the window */
230
right += height; /* move it back over the sidecar */
231
R_standard_color(WHITE);
232
R_box_abs(left, top, right, bottom);
233
R_panel_restore(tempfile1);
234
R_panel_restore(tempfile2);
235
R_panel_delete(tempfile1);
236
R_panel_delete(tempfile2);
243
static dobox(box, text, color, top, left, right, centered)
249
bottom = top + height;
250
/* fill inside of box with color */
251
R_standard_color(color);
252
R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
254
/* draw box outline and text in black */
255
R_standard_color(BLACK);
256
Outline_box(top, bottom, left, right);
257
dotext(text, top, bottom, left, right, centered);
260
box->bottom = bottom;
265
static uparrow(box, color)
268
R_standard_color(color);
269
Uparrow(box->top + edge, box->bottom - edge, box->left + edge,
273
static downarrow(box, color)
276
R_standard_color(color);
277
Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
281
static pick(int x, int y, int button)
285
if (inbox(&more, x, y)) {
287
if (page + 1 >= npages)
292
if (inbox(&less, x, y)) {
299
if (inbox(&cancel, x, y)) {
304
R_standard_color(RED);
305
Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
308
/* search name list. handle double click */
309
for (n = 0; n < count; n++)
310
if (inbox(&list[n].box, x, y)) {
311
if (n == which) /* second click! */
315
R_standard_color(RED);
316
Outline_box(list[n].box.top, list[n].box.bottom,
317
list[n].box.left, list[n].box.right);
318
return 0; /* ignore first click */
325
static cancel_which(void)
328
R_standard_color(BLACK);
329
Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
331
else if (which >= 0) {
332
R_standard_color(BLACK);
333
Outline_box(list[which].box.top, list[which].box.bottom,
334
list[which].box.left, list[which].box.right);
339
static inbox(box, x, y)
342
return (x > box->left && x < box->right && y > box->top &&
347
dotext(char *text, int top, int bottom, int left, int right, int centered)
349
R_text_size(text_size, text_size);
350
R_move_abs(left + 1 + edge, bottom - 1 - edge);
352
R_move_rel((right - left - strlen(text) * size) / 2, 0);
353
R_set_window(top, bottom, left, right); /* for text clipping */
355
R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);