~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to imagery/i.vpoints/ask_lineclr.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <grass/gis.h>
2
 
#include "globals.h"
3
 
#define NLINES 18
4
 
struct box
5
 
{
6
 
    int top, bottom, left, right;
7
 
};
8
 
 
9
 
static int text_size;
10
 
static int which;
11
 
static struct box cancel, more, less;
12
 
static int height, size, edge, count;
13
 
static int page, npages;
14
 
static struct
15
 
{
16
 
    char name[100], mapset[100];
17
 
    struct box box;
18
 
} list[NLINES * 2];
19
 
 
20
 
int ask_line_color(char *colors, int len1, char *xname, int position)
21
 
{
22
 
    static int use = 1;
23
 
    int pick();
24
 
    static Objects objects[] = {
25
 
        OTHER(pick, &use),
26
 
        {0}
27
 
    };
28
 
 
29
 
    char msg[100];
30
 
    int width;
31
 
    int len2 = 0, len;
32
 
    long offset;
33
 
    long *page_offset;
34
 
    int col, nlist;
35
 
    int line;
36
 
    int stat;
37
 
    char buf[100];
38
 
    int top, bottom, left, right, center;
39
 
    int topx, bottomx, leftx, rightx, widthx;
40
 
    char name[100], mapset[100], cur_mapset[100];
41
 
    int new_mapset;
42
 
 
43
 
    Menu_msg("");
44
 
 
45
 
    sprintf(msg, "Double click on color to assign to vector layer");
46
 
 
47
 
    /*
48
 
     * build a popup window at center of the screen.
49
 
     * 35% the height and wide enough to hold 2 columms of file names
50
 
     *
51
 
     * the window is for choosing file names and will be laid out in 2 columns
52
 
     *
53
 
     *             ------------------------------------------
54
 
     *             |     CANCEL           | (MORE) | (LESS) | 
55
 
     *             ------------------------------------------
56
 
     *             |             mapset                     |
57
 
     *             ------------------------------------------
58
 
     *             |      name1        |   name2            |
59
 
     *             ------------------------------------------
60
 
     *             |      name3        |   name4            |
61
 
     *             ------------------------------------------
62
 
     *             |      name5        |   name6            |
63
 
     *             |                   .                    |
64
 
     *             |                   .                    |
65
 
     *             |                   .                    |
66
 
     *             ------------------------------------------
67
 
     */
68
 
 
69
 
    /* height of 1 line, based on NLINES taking up 35% vertical space */
70
 
    height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;
71
 
 
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 */
75
 
 
76
 
    /* indent for the text */
77
 
    edge = .1 * height + 1;
78
 
 
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);
83
 
 
84
 
    /* width is for max chars plus sidecar for more/less */
85
 
    width = len * size + height;
86
 
    widthx = strlen(msg) * size;
87
 
    if (widthx < width)
88
 
        widthx = width;
89
 
 
90
 
    /* define the window */
91
 
    top = (SCREEN_TOP + SCREEN_BOTTOM - height * NLINES) / 2;
92
 
    bottom = top + height * NLINES;
93
 
 
94
 
    center = (SCREEN_LEFT + SCREEN_RIGHT) / 2;
95
 
    if (position > 0) {
96
 
        right = (center + SCREEN_RIGHT + width) / 2;
97
 
        if (right >= SCREEN_RIGHT)
98
 
            right = SCREEN_RIGHT - 1;
99
 
        left = right - width;
100
 
    }
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;
106
 
    }
107
 
    else {
108
 
        left = center + width / 2;
109
 
        right = left + width;
110
 
    }
111
 
 
112
 
    topx = top - 3 * height;
113
 
    bottomx = topx + 2 * height;
114
 
    leftx = (left + right - widthx) / 2;
115
 
    if (leftx < SCREEN_LEFT)
116
 
        leftx = SCREEN_LEFT;
117
 
    rightx = leftx + widthx;
118
 
 
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);
122
 
 
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);
128
 
 
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);
133
 
 
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,
137
 
           rightx, 1);
138
 
    cancel.top = topx;
139
 
    cancel.bottom = bottomx;
140
 
    cancel.left = leftx;
141
 
    cancel.right = rightx;
142
 
 
143
 
    /* start the mouse in the cancel box */
144
 
    Set_mouse_xy((leftx + rightx) / 2, (topx + bottomx) / 2);
145
 
 
146
 
    dobox(&less, "", WHITE, top, right, right + height, 0);
147
 
    dobox(&more, "", WHITE, bottom - height, right, right + height, 0);
148
 
 
149
 
    /* as we read the file of names, keep track of pages so we can
150
 
     * page backward
151
 
     */
152
 
    page = 0;
153
 
    page_offset = (long *)G_calloc(npages = 1, sizeof(long));
154
 
    *page_offset = ftell(fd);
155
 
 
156
 
    nlist = sizeof(list) / sizeof(list[0]);
157
 
    for (stat = -1; stat < 0;) {
158
 
        line = 0;
159
 
        count = 0;
160
 
        *cur_mapset = 0;
161
 
        col = 0;
162
 
        while (1) {
163
 
            /*
164
 
               offset = ftell (fd);
165
 
               if (fgets (buf, sizeof buf, fd) == NULL
166
 
               || sscanf (buf, "%s %s", name, mapset) != 2)
167
 
               break;
168
 
               if(new_mapset = (strcmp (cur_mapset,mapset) != 0))
169
 
               {
170
 
               if(line) line++;
171
 
               if (col) line++;
172
 
               col = 0;
173
 
               }
174
 
               if (count >= nlist || line+new_mapset >= NLINES)
175
 
               {
176
 
               if (page+1 == npages)
177
 
               {
178
 
               npages++;
179
 
               page_offset = (long *) G_realloc (page_offset, npages * sizeof (long));
180
 
               page_offset[npages-1] = offset;
181
 
               }
182
 
               break;
183
 
               }
184
 
               if (new_mapset)
185
 
               {
186
 
               struct box dummy;
187
 
               char label[100];
188
 
 
189
 
               strcpy (cur_mapset, mapset);
190
 
               sprintf (label, "Mapset %s", mapset);
191
 
               dobox (&dummy, label, WHITE, top+line*height, left, right, 0);
192
 
               line++;
193
 
               }
194
 
               if (col)
195
 
               {
196
 
               dobox (&list[count].box, name, GREY, top+line*height, left+width/2, right, 0);
197
 
               line++;
198
 
               col = 0;
199
 
               }
200
 
               else
201
 
               {
202
 
               dobox (&list[count].box, name, GREY, top+line*height, left, left+width/2, 0);
203
 
               col = 1;
204
 
               }
205
 
               strcpy (list[count].name, name);
206
 
               strcpy (list[count].mapset, mapset);
207
 
               count++;
208
 
               }
209
 
               downarrow (&more, page+1 < npages ? BLACK : WHITE);
210
 
               uparrow   (&less, page   > 0      ? BLACK : WHITE);
211
 
               which = -1;
212
 
               switch(Input_pointer(objects))
213
 
               {
214
 
               case -1: /* more or less */
215
 
            break;
216
 
case -2:                        /* cancel */
217
 
            stat = 0;
218
 
            continue;
219
 
default:                        /* file picked */
220
 
            strcpy(xname, list[which].name);
221
 
            stat = 1;
222
 
            continue;
223
 
        }
224
 
        fseek(fd, page_offset[page], 0);
225
 
        R_standard_color(WHITE);
226
 
        R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
227
 
    }
228
 
 
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);
237
 
    R_flush();
238
 
 
239
 
    G_free(page_offset);
240
 
    return stat;
241
 
}
242
 
 
243
 
static dobox(box, text, color, top, left, right, centered)
244
 
     struct box *box;
245
 
     char *text;
246
 
{
247
 
    int bottom;
248
 
 
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);
253
 
 
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);
258
 
 
259
 
    box->top = top;
260
 
    box->bottom = bottom;
261
 
    box->left = left;
262
 
    box->right = right;
263
 
}
264
 
 
265
 
static uparrow(box, color)
266
 
     struct box *box;
267
 
{
268
 
    R_standard_color(color);
269
 
    Uparrow(box->top + edge, box->bottom - edge, box->left + edge,
270
 
            box->right - edge);
271
 
}
272
 
 
273
 
static downarrow(box, color)
274
 
     struct box *box;
275
 
{
276
 
    R_standard_color(color);
277
 
    Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
278
 
              box->right - edge);
279
 
}
280
 
 
281
 
static pick(int x, int y, int button)
282
 
{
283
 
    int n;
284
 
 
285
 
    if (inbox(&more, x, y)) {
286
 
        cancel_which();
287
 
        if (page + 1 >= npages)
288
 
            return 0;
289
 
        page++;
290
 
        return -1;
291
 
    }
292
 
    if (inbox(&less, x, y)) {
293
 
        cancel_which();
294
 
        if (page == 0)
295
 
            return 0;
296
 
        page--;
297
 
        return -1;
298
 
    }
299
 
    if (inbox(&cancel, x, y)) {
300
 
        if (which == -2)
301
 
            return -2;
302
 
        cancel_which();
303
 
        which = -2;
304
 
        R_standard_color(RED);
305
 
        Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
306
 
        return 0;
307
 
    }
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! */
312
 
                return 1;
313
 
            cancel_which();
314
 
            which = n;
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 */
319
 
        }
320
 
 
321
 
    cancel_which();
322
 
    return 0;
323
 
}
324
 
 
325
 
static cancel_which(void)
326
 
{
327
 
    if (which == -2) {
328
 
        R_standard_color(BLACK);
329
 
        Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
330
 
    }
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);
335
 
    }
336
 
    which = -1;
337
 
}
338
 
 
339
 
static inbox(box, x, y)
340
 
     struct box *box;
341
 
{
342
 
    return (x > box->left && x < box->right && y > box->top &&
343
 
            y < box->bottom);
344
 
}
345
 
 
346
 
static
347
 
dotext(char *text, int top, int bottom, int left, int right, int centered)
348
 
{
349
 
    R_text_size(text_size, text_size);
350
 
    R_move_abs(left + 1 + edge, bottom - 1 - edge);
351
 
    if (centered)
352
 
        R_move_rel((right - left - strlen(text) * size) / 2, 0);
353
 
    R_set_window(top, bottom, left, right);     /* for text clipping */
354
 
    R_text(text);
355
 
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);
356
 
}