~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/photo.2target/input.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <grass/raster.h>
2
 
#include "globals.h"
3
 
#include "local_proto.h"
4
 
 
5
 
static int active = 0;
6
 
static int replot;
7
 
 
8
 
#define TEXT_COLOR BLACK
9
 
#define FILL_COLOR GREY
10
 
#define OUTLINE_COLOR WHITE
11
 
 
12
 
static int mouse(Objects *, int, int, int);
13
 
static int use_mouse_msg(void);
14
 
static int draw_objects(Objects *);
15
 
static Objects *find(Objects *, int, int);
16
 
static int select_option(Objects *, Objects *);
17
 
static int draw_option_boxes(Objects *);
18
 
static int visible(Objects *);
19
 
 
20
 
/* Input: drive mouse. returns status of handler that returns != 0 */
21
 
int Input_pointer(Objects * objects)
22
 
{
23
 
    return mouse(objects, 0, 0, 0);
24
 
}
25
 
 
26
 
int Input_box(Objects * objects, int ax, int ay)
27
 
{
28
 
    return mouse(objects, ax, ay, 1);
29
 
}
30
 
 
31
 
int Input_other(int (*function) (void), char *type)
32
 
{
33
 
    int stat;
34
 
    char msg[1024];
35
 
 
36
 
    sprintf(msg, "%s input required", type);
37
 
    Menu_msg(msg);
38
 
    stat = (*function) ();
39
 
    if (active)
40
 
        use_mouse_msg();
41
 
 
42
 
    return stat;
43
 
}
44
 
 
45
 
static int mouse(Objects * objects, int ax, int ay, int box)
46
 
{
47
 
    int first;
48
 
    int stat;
49
 
    int x, y, button;
50
 
    Objects *obj;
51
 
 
52
 
    first = !active;
53
 
    active = 1;
54
 
    if (first)
55
 
        use_mouse_msg();
56
 
 
57
 
    if (box) {
58
 
        x = ax + 20;
59
 
        y = ay + 20;
60
 
    }
61
 
    stat = 0;
62
 
    replot = 1;
63
 
    while (stat == 0) {
64
 
        if (replot) {
65
 
            replot = 0;
66
 
            draw_objects(objects);
67
 
        }
68
 
        R_stabilize();
69
 
        if (box)
70
 
            Mouse_box_anchored(ax, ay, &x, &y, &button);
71
 
        else
72
 
            Mouse_pointer(&x, &y, &button);
73
 
 
74
 
        if (!(obj = find(objects, x, y)))
75
 
            continue;
76
 
 
77
 
        switch (obj->type) {
78
 
        case MENU_OBJECT:
79
 
        case OTHER_OBJECT:
80
 
            stat = (*obj->handler) (x, y, button);
81
 
            break;
82
 
        case OPTION_OBJECT:
83
 
            select_option(objects, obj);
84
 
            draw_option_boxes(objects);
85
 
            break;
86
 
        }
87
 
    }
88
 
 
89
 
    /* if we are first call, mark not active
90
 
     * indicate that objects above use must be replotted.
91
 
     */
92
 
    if (first)
93
 
        active = 0;
94
 
    Menu_msg("");
95
 
 
96
 
    return stat;
97
 
}
98
 
 
99
 
 
100
 
static int use_mouse_msg(void)
101
 
{
102
 
    Curses_write_window(PROMPT_WINDOW, 1, 1, "Use mouse now ...\n");
103
 
 
104
 
    return 0;
105
 
}
106
 
 
107
 
static int draw_objects(Objects * objects)
108
 
{
109
 
    Objects *obj;
110
 
    int top, bottom, left, right;
111
 
    int size, edge;
112
 
 
113
 
 
114
 
    /* erase the menu window */
115
 
    Erase_view(VIEW_MENU);
116
 
    R_flush();
117
 
 
118
 
    /* determine sizes and text indentation */
119
 
    size = VIEW_MENU->nrows - 4;
120
 
    edge = 2;
121
 
 
122
 
    R_text_size(size, size);
123
 
 
124
 
    left = VIEW_MENU->left;
125
 
    top = VIEW_MENU->top;
126
 
    bottom = VIEW_MENU->bottom;
127
 
 
128
 
 
129
 
    /* put the (boxed) text on the menu view */
130
 
    for (obj = objects; obj->type; obj++) {
131
 
        if (!visible(obj))
132
 
            continue;
133
 
        switch (obj->type) {
134
 
        case OPTION_OBJECT:
135
 
        case MENU_OBJECT:
136
 
            right = left + 2 * edge + Text_width(obj->label);
137
 
            obj->left = left;
138
 
            obj->right = right;
139
 
            obj->top = top;
140
 
            obj->bottom = bottom;
141
 
 
142
 
            R_standard_color(FILL_COLOR);
143
 
            R_box_abs(left, top, right, bottom);
144
 
 
145
 
            R_standard_color(TEXT_COLOR);
146
 
            Text(obj->label, top, bottom, left, right, edge);
147
 
 
148
 
            R_standard_color(OUTLINE_COLOR);
149
 
            Outline_box(top, bottom, left, right);
150
 
 
151
 
            left = right;
152
 
            break;
153
 
 
154
 
        case INFO_OBJECT:
155
 
            if (*obj->label == 0)
156
 
                break;
157
 
            if (*obj->status < 0)
158
 
                break;
159
 
            right = left + 2 * edge + Text_width(obj->label);
160
 
            R_standard_color(WHITE);
161
 
            Text(obj->label, top, bottom, left, right, edge);
162
 
 
163
 
            left = right;
164
 
            break;
165
 
        }
166
 
    }
167
 
    draw_option_boxes(objects);
168
 
    R_flush();
169
 
 
170
 
    return 0;
171
 
}
172
 
 
173
 
static Objects *find(Objects * objects, int x, int y)
174
 
{
175
 
    Objects *other;
176
 
 
177
 
    other = NULL;
178
 
    for (; objects->type; objects++) {
179
 
        if (!visible(objects))
180
 
            continue;
181
 
        switch (objects->type) {
182
 
        case MENU_OBJECT:
183
 
        case OPTION_OBJECT:
184
 
            if (x >= objects->left && x <= objects->right
185
 
                && y >= objects->top && y <= objects->bottom)
186
 
                return objects;
187
 
            break;
188
 
        case OTHER_OBJECT:
189
 
            other = objects;
190
 
            break;
191
 
        }
192
 
    }
193
 
    return other;
194
 
}
195
 
 
196
 
static int select_option(Objects * objects, Objects * obj)
197
 
{
198
 
    while (objects->type) {
199
 
        if (objects->type == OPTION_OBJECT && *objects->status >= 0 &&
200
 
            objects->binding == obj->binding)
201
 
            *objects->status = 0;
202
 
        objects++;
203
 
    }
204
 
    *obj->status = 1;
205
 
 
206
 
    return 0;
207
 
}
208
 
 
209
 
static int draw_option_boxes(Objects * objects)
210
 
{
211
 
    Objects *x;
212
 
 
213
 
    R_standard_color(OUTLINE_COLOR);
214
 
    for (x = objects; x->type; x++) {
215
 
        if (x->type == OPTION_OBJECT && *x->status == 0)
216
 
            Outline_box(x->top +1, x->bottom, x->left, x->right -1);
217
 
    }
218
 
    R_standard_color(GREEN);
219
 
    for (x = objects; x->type; x++) {
220
 
        if (x->type == OPTION_OBJECT && *x->status > 0)
221
 
            Outline_box(x->top +1, x->bottom, x->left, x->right -1);
222
 
    }
223
 
    R_flush();
224
 
 
225
 
    return 0;
226
 
}
227
 
 
228
 
static int visible(Objects * object)
229
 
{
230
 
    if (object->type == OPTION_OBJECT)
231
 
        return (*object->status >= 0);
232
 
    return (*object->status > 0);
233
 
}
234
 
 
235
 
int Menu_msg(char *msg)
236
 
{
237
 
    int size, edge;
238
 
 
239
 
    size = VIEW_MENU->nrows - 4;
240
 
    edge = 2;
241
 
 
242
 
    Erase_view(VIEW_MENU);
243
 
 
244
 
    if (*msg) {
245
 
        R_text_size(size, size);
246
 
        R_standard_color(WHITE);
247
 
        Text(msg, VIEW_MENU->top, VIEW_MENU->bottom,
248
 
             VIEW_MENU->left, VIEW_MENU->right, edge);
249
 
    }
250
 
    R_flush();
251
 
    replot = 1;
252
 
 
253
 
    return 0;
254
 
}
255
 
 
256
 
int Start_mouse_in_menu(void)
257
 
{
258
 
    Set_mouse_xy((VIEW_MENU->left + 2 * VIEW_MENU->right) / 3,
259
 
                 (VIEW_MENU->top + VIEW_MENU->bottom) / 2);
260
 
 
261
 
    return 0;
262
 
}