1
#include <grass/raster.h>
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 *);
14
#define TEXT_COLOR BLACK
15
#define FILL_COLOR GREY
16
#define OUTLINE_COLOR WHITE
18
/* Input: drive mouse. returns status of handler that returns != 0 */
19
int Input_pointer(Objects * objects)
21
return mouse(objects, 0, 0, 0);
24
int Input_box(Objects * objects, int ax, int ay)
26
return mouse(objects, ax, ay, 1);
29
int Input_other(int (*function) (), char *type)
34
sprintf(msg, "%s input required", type);
36
stat = (*function) ();
44
static int mouse(Objects * objects, int ax, int ay, int box)
65
draw_objects(objects);
68
Mouse_box_anchored(ax, ay, &x, &y, &button);
70
Mouse_pointer(&x, &y, &button);
72
if (!(obj = find(objects, x, y)))
78
stat = (*obj->handler) (x, y, button);
81
select_option(objects, obj);
82
draw_option_boxes(objects);
87
/* if we are first call, mark not active
88
* indicate that objects above use must be replotted.
97
static int use_mouse_msg(void)
99
Curses_write_window(PROMPT_WINDOW, 1, 1, "Use mouse now ...\n");
104
static int draw_objects(Objects * objects)
107
int top, bottom, left, right;
111
/* erase the menu window */
112
Erase_view(VIEW_MENU);
115
/* determine sizes and text indentation */
116
size = VIEW_MENU->nrows - 4;
119
R_text_size(size, size);
121
left = VIEW_MENU->left;
122
top = VIEW_MENU->top;
123
bottom = VIEW_MENU->bottom;
126
/* put the (boxed) text on the menu view */
127
for (obj = objects; obj->type; obj++) {
133
right = left + 2 * edge + Text_width(obj->label);
137
obj->bottom = bottom;
139
R_standard_color(FILL_COLOR);
140
R_box_abs(left, top, right, bottom);
142
R_standard_color(TEXT_COLOR);
143
Text(obj->label, top, bottom, left, right, edge);
145
R_standard_color(OUTLINE_COLOR);
146
Outline_box(top, bottom, left, right);
152
if (*obj->label == 0)
154
if (*obj->status < 0)
156
right = left + 2 * edge + Text_width(obj->label);
157
R_standard_color(WHITE);
158
Text(obj->label, top, bottom, left, right, edge);
164
draw_option_boxes(objects);
170
static Objects *find(Objects * objects, int x, int y)
175
for (; objects->type; objects++) {
176
if (!visible(objects))
178
switch (objects->type) {
181
if (x >= objects->left && x <= objects->right
182
&& y >= objects->top && y <= objects->bottom)
193
static int select_option(Objects * objects, Objects * obj)
195
while (objects->type) {
196
if (objects->type == OPTION_OBJECT && *objects->status >= 0 &&
197
objects->binding == obj->binding)
198
*objects->status = 0;
206
static int draw_option_boxes(Objects * objects)
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);
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);
225
static int visible(Objects * object)
227
if (object->type == OPTION_OBJECT)
228
return (*object->status >= 0);
229
return (*object->status > 0);
232
int Menu_msg(char *msg)
236
size = VIEW_MENU->nrows - 4;
239
Erase_view(VIEW_MENU);
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);
253
int Start_mouse_in_menu(void)
255
Set_mouse_xy((VIEW_MENU->left + 2 * VIEW_MENU->right) / 3,
256
(VIEW_MENU->top + VIEW_MENU->bottom) / 2);