2
/****************************************************************
6
* AUTHOR(S): James Westervelt, U.S. Army CERL
8
* PURPOSE: Creates an interactive menu on the display monitor using
9
* lines from stdin as options. Returns selected entry.
11
* COPYRIGHT: (c) 1999, 2006 by the GRASS Development Team
13
* This program is free software under the
14
* GNU General Public License (>=v2).
15
* Read the file COPYING that comes with GRASS
18
****************************************************************
20
* Lines beginning with:
21
* # are comments and ignored
22
* .B contains the background color
23
* .C contains the text color
24
* .D contains the line divider color
25
* .F contains the font name
26
* .S contains the text size (in pixles)
27
* .T contains the panel's top edge
28
* .L contains the panel's left edge
30
* Of the remaining lines, the first is the menu name; the rest
31
* are the menu options.
33
* Returns option number chosen.
35
****************************************************************/
40
#include "grass/gis.h"
41
#include "grass/display.h"
42
#include "grass/raster.h"
43
#include "grass/glocale.h"
45
int main(int argc, char **argv)
59
struct GModule *module;
60
struct Option *opt1, *opt2, *opt3, *opt4;
62
/* Initialize the GIS calls */
65
module = G_define_module();
66
module->keywords = _("display");
68
_("Creates and displays a menu within the active "
69
"frame on the graphics monitor.");
71
opt1 = G_define_option();
73
opt1->type = TYPE_STRING;
74
opt1->answer = DEFAULT_BG_COLOR;
76
opt1->options = D_color_list();
77
opt1->description = _("Sets the color of the menu background");
79
opt2 = G_define_option();
81
opt2->type = TYPE_STRING;
82
opt2->answer = DEFAULT_FG_COLOR;
84
opt2->options = D_color_list();
85
opt2->description = _("Sets the color of the menu text");
87
opt3 = G_define_option();
89
opt3->type = TYPE_STRING;
90
opt3->answer = DEFAULT_FG_COLOR;
92
opt3->options = D_color_list();
93
opt3->description = _("Sets the color dividing lines of text");
95
opt4 = G_define_option();
97
opt4->type = TYPE_INTEGER;
100
opt4->options = "1-100";
101
opt4->description = _("Sets the menu text size (in percent)");
103
/* Check command line */
104
if (G_parser(argc, argv))
107
if (R_open_driver() != 0)
108
G_fatal_error(_("No graphics device selected"));
110
backcolor = D_translate_color(opt1->answer);
111
if (backcolor == 0) {
113
G_fatal_error(_("Don't know the color %s"), opt1->answer);
116
textcolor = D_translate_color(opt2->answer);
117
if (textcolor == 0) {
119
G_fatal_error(_("Don't know the color %s"), opt2->answer);
122
dividercolor = D_translate_color(opt3->answer);
123
if (dividercolor == 0) {
125
G_fatal_error(_("Don't know the color %s"), opt3->answer);
129
sscanf(opt4->answer, "%d", &size);
131
/* Read the options */
133
while (fgets(buff, 128, stdin) != NULL) {
144
for (cmd_ptr = buff + 2; *cmd_ptr == ' ' && *cmd_ptr != '\0';
146
switch (buff[1] & 0x7F) {
148
case 'B': /* background color */
149
backcolor = D_translate_color(cmd_ptr);
151
case 'C': /* text color */
152
textcolor = D_translate_color(cmd_ptr);
154
case 'D': /* divider color */
155
dividercolor = D_translate_color(cmd_ptr);
161
sscanf(cmd_ptr, "%d", &size);
163
case 'T': /* top edge */
164
sscanf(cmd_ptr, "%d", &top);
167
case 'L': /* left edge */
168
sscanf(cmd_ptr, "%d", &left);
177
tmp = malloc(len + 1);
186
G_fatal_error(_("Menu must contain a title and at least one option"));
189
i = D_popup(backcolor, textcolor, dividercolor, top, /* The col of the top left corner */
190
left, /* The row of the top left corner */
191
size, /* The size of the characters in pixles */
192
options); /* The text */
196
/* Provide the result to standard output */
197
fprintf(stdout, "%d\n", i);