~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

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