1 #include "video/video.h"
2 #include "Nebu_scripting.h"
3
4 #include <string.h>
5
drawMenu(Visual * d)6 void drawMenu(Visual *d) {
7 /* draw Menu pCurrent */
8
9 int i;
10 int x, y, size, lineheight;
11 int hsize, vsize;
12 int max_label = 0;
13 int max_data = 0;
14 int nEntries;
15 char pMenuName[200];
16 int iActiveItem;
17
18 rasonly(d);
19
20 #define MENU_TEXT_START_X 0.08
21 #define MENU_TEXT_START_Y 0.40
22
23 #define MENU_WIDTH 0.80
24 #define MENU_HEIGHT 0.40
25
26 #define MENU_TEXT_LINEHEIGHT 1.5
27
28 x = (int) (d->vp_w * MENU_TEXT_START_X);
29 y = (int) (d->vp_h * MENU_TEXT_START_Y);
30
31 /* obtain menu name */
32 scripting_Run("return Menu.current");
33 scripting_CopyStringResult(pMenuName, 200);
34 /* obtain some information about the active menu */
35 scripting_RunFormat("return getn( Menu.%s.items )", pMenuName);
36 scripting_GetIntegerResult(&nEntries);
37
38 /* new stuff: calculate menu dimensions */
39 for(i = 0; i < nEntries; i++) {
40 int len_label = 0;
41 int len_data = 0;
42
43 scripting_RunFormat("return strlen( Menu[Menu.%s.items[%d]].caption )",
44 pMenuName, i + 1);
45 scripting_GetIntegerResult(&len_label);
46 len_label += 2; /* add ': ' */
47 scripting_RunFormat("return GetMenuValueWidth( Menu.%s.items[%d] )",
48 pMenuName, i + 1);
49 scripting_GetIntegerResult(&len_data);
50
51 if(len_label > max_label) max_label = len_label;
52 if(len_data > max_data) max_data = len_data;
53 }
54
55 /* adjust size so menu fits into MENU_WIDTH/HEIGHT */
56
57 hsize = (int) ((float)d->vp_w * MENU_WIDTH / (float) (max_label + max_data));
58 vsize = (int) ((float)d->vp_h * MENU_HEIGHT /
59 ( (float)nEntries * MENU_TEXT_LINEHEIGHT));
60
61 size = (hsize < vsize) ? hsize : vsize;
62
63 lineheight = (int)( (float) size * MENU_TEXT_LINEHEIGHT);
64
65 /* printf("%d %d %d %d %d\n", x, y, size, maxw, pCurrent->nEntries); */
66 /* draw the entries */
67
68 scripting_Run("return Menu.active");
69 scripting_GetIntegerResult(&iActiveItem);
70
71 glEnable(GL_BLEND);
72 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
73 for(i = 0; i < nEntries; i++) {
74 if(i == iActiveItem - 1) {
75 float color[4];
76 float active1[4];
77 float active2[4];
78 int j;
79 float t;
80 int time = SystemGetElapsedTime() & 4095;
81 t = sinf( time * PI / 2048.0 ) / 2.0f + 0.5f;
82
83 scripting_GetGlobal("menu_item_active1", NULL);
84 scripting_GetFloatArrayResult(active1, 4);
85 scripting_GetGlobal("menu_item_active2", NULL);
86 scripting_GetFloatArrayResult(active2, 4);
87
88 for(j = 0; j < 4; j++) {
89 color[j] = t * active1[j] + (1 - t) * active2[j];
90 }
91 glColor4fv(color);
92 /* fprintf(stderr, "%.2f: %.2f %.2f %.2f\n",
93 t, color[0], color[1], color[2]); */
94 } else {
95 float color[4];
96 scripting_GetGlobal("menu_item", NULL);
97 scripting_GetFloatArrayResult(color, 4);
98 glColor4fv(color);
99 }
100
101 {
102 char line_label[100];
103 char line_data[100];
104 scripting_RunFormat("return "
105 "GetMenuValueString( Menu.%s.items[%d] )",
106 pMenuName, i + 1);
107 scripting_CopyStringResult(line_data, sizeof(line_data));
108
109 if(line_data[0] != 0)
110 scripting_RunFormat("return "
111 "Menu[Menu.%s.items[%d]].caption .. ': '",
112 pMenuName, i + 1);
113 else
114 scripting_RunFormat("return "
115 "Menu[Menu.%s.items[%d]].caption",
116 pMenuName, i + 1);
117
118 scripting_CopyStringResult(line_label, sizeof(line_label));
119
120 drawText(guiFtx, x, y, size, line_label);
121 drawText(guiFtx, x + max_label * size, y, size, line_data);
122 }
123
124 /*
125 if(i == pCurrent->iHighlight)
126 drawSoftwareHighlight(x, y, size, ((Menu*)*(pCurrent->pEntries + i))->display.szCaption);
127 */
128 y -= lineheight;
129 }
130
131 glDisable(GL_BLEND);
132 }
133
134
135
136
137
138