1
#include <grass/raster.h>
3
#include "local_proto.h"
8
#define TEXT_COLOR BLACK
9
#define FILL_COLOR GREY
10
#define OUTLINE_COLOR WHITE
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 *);
20
/* Input: drive mouse. returns status of handler that returns != 0 */
21
int Input_pointer(Objects * objects)
23
return mouse(objects, 0, 0, 0);
26
int Input_box(Objects * objects, int ax, int ay)
28
return mouse(objects, ax, ay, 1);
31
int Input_other(int (*function) (void), char *type)
36
sprintf(msg, "%s input required", type);
38
stat = (*function) ();
45
static int mouse(Objects * objects, int ax, int ay, int box)
66
draw_objects(objects);
70
Mouse_box_anchored(ax, ay, &x, &y, &button);
72
Mouse_pointer(&x, &y, &button);
74
if (!(obj = find(objects, x, y)))
80
stat = (*obj->handler) (x, y, button);
83
select_option(objects, obj);
84
draw_option_boxes(objects);
89
/* if we are first call, mark not active
90
* indicate that objects above use must be replotted.
100
static int use_mouse_msg(void)
102
Curses_write_window(PROMPT_WINDOW, 1, 1, "Use mouse now ...\n");
107
static int draw_objects(Objects * objects)
110
int top, bottom, left, right;
114
/* erase the menu window */
115
Erase_view(VIEW_MENU);
118
/* determine sizes and text indentation */
119
size = VIEW_MENU->nrows - 4;
122
R_text_size(size, size);
124
left = VIEW_MENU->left;
125
top = VIEW_MENU->top;
126
bottom = VIEW_MENU->bottom;
129
/* put the (boxed) text on the menu view */
130
for (obj = objects; obj->type; obj++) {
136
right = left + 2 * edge + Text_width(obj->label);
140
obj->bottom = bottom;
142
R_standard_color(FILL_COLOR);
143
R_box_abs(left, top, right, bottom);
145
R_standard_color(TEXT_COLOR);
146
Text(obj->label, top, bottom, left, right, edge);
148
R_standard_color(OUTLINE_COLOR);
149
Outline_box(top, bottom, left, right);
155
if (*obj->label == 0)
157
if (*obj->status < 0)
159
right = left + 2 * edge + Text_width(obj->label);
160
R_standard_color(WHITE);
161
Text(obj->label, top, bottom, left, right, edge);
167
draw_option_boxes(objects);
173
static Objects *find(Objects * objects, int x, int y)
178
for (; objects->type; objects++) {
179
if (!visible(objects))
181
switch (objects->type) {
184
if (x >= objects->left && x <= objects->right
185
&& y >= objects->top && y <= objects->bottom)
196
static int select_option(Objects * objects, Objects * obj)
198
while (objects->type) {
199
if (objects->type == OPTION_OBJECT && *objects->status >= 0 &&
200
objects->binding == obj->binding)
201
*objects->status = 0;
209
static int draw_option_boxes(Objects * objects)
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);
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);
228
static int visible(Objects * object)
230
if (object->type == OPTION_OBJECT)
231
return (*object->status >= 0);
232
return (*object->status > 0);
235
int Menu_msg(char *msg)
239
size = VIEW_MENU->nrows - 4;
242
Erase_view(VIEW_MENU);
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);
256
int Start_mouse_in_menu(void)
258
Set_mouse_xy((VIEW_MENU->left + 2 * VIEW_MENU->right) / 3,
259
(VIEW_MENU->top + VIEW_MENU->bottom) / 2);