1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
19 #include "backend/video.h"
20 #include "backend/input.h"
21 #include "backend/shapes.h"
28 static void gl_perspective()
30 glMatrixMode(GL_PROJECTION
);
33 double w
= v_info()->width
, h
= v_info()->height
;
36 gluPerspective(45,aspect
,1,1001);
38 glEnable(GL_DEPTH_TEST
);
41 glEnable(GL_CULL_FACE
);
44 glShadeModel(GL_SMOOTH
);
46 glEnable(GL_TEXTURE_2D
);
48 glBlendFunc(GL_SRC_ALPHA
,GL_ONE_MINUS_SRC_ALPHA
);
51 Menu::Menu(std::string name
, Menu::MENU_MODE m
)
52 : Element(name
), m_background(0), m_selected(0)
54 m_keyrep
.setDelay(150);
55 m_keyrep
.setTime(300);
65 void Menu::setDefaults()
67 m_entry_spacing
= 2.0; // units step per entry
68 m_entry_padding
= 3.0; // units of padding around the entry
69 m_entry_distance
= -9.0; // z distance from camera
73 m_rot_friction
= 1.0 - 0.2;
77 void Menu::addChild(Element
*e
)
79 m_children
.push_back(e
);
84 v_title(m_name
.c_str(), m_name
.c_str());
85 v_resizecb(gl_perspective
);
87 if (m_mode
== OVERLAY
) {
88 // take snapshot of background to render later
92 m_background
= Texture::Screenshot();
103 int result
= handleInput();
108 else if (result
== 1) {
110 const char *name
= m_children
[m_selected
]->getName().c_str();
112 ret
= m_children
[m_selected
]->run();
126 int Menu::handleInput()
129 keysym_t
*key
= i_keystate();
134 else if (key
[K_UP
]) {
135 if (m_selected
!= 0 && m_keyrep
.repeat()) {
139 else if (key
[K_DOWN
]) {
140 if (m_selected
+1 < (int)m_children
.size() && m_keyrep
.repeat()) {
144 else if (key
[K_RETURN
]) {
145 if (m_keyrep
.repeat()) {
158 static float brightness
= 0.4;
159 static float bg_col
[] = { 0, 0, 0 };
160 static int bg_last
= rand()%3;
161 static int bg_curr
= -1;
162 //bg_col[bg_last] = 1;
164 if (m_mode
== BACKGROUND
) {
167 while (bg_last
== bg_curr
) bg_curr
= rand()%3;
169 if (bg_col
[bg_curr
] >= 1) {
173 bg_col
[bg_curr
] += 0.01;
174 bg_col
[bg_last
] -= 0.01;
176 glClearColor(bg_col
[0]*brightness
, bg_col
[1]*brightness
, bg_col
[2]*brightness
, 0);
179 int draw_start
= m_selected
-m_entry_padding
;
180 int draw_end
= m_selected
+m_entry_padding
+1;
182 int lower_bound
= m_children
.size()-1;
184 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
186 if (m_mode
== OVERLAY
) {
188 glDisable(GL_DEPTH_TEST
);
189 glDisable(GL_LIGHTING
);
190 glEnable(GL_TEXTURE_2D
);
191 glMatrixMode(GL_MODELVIEW
);
193 glMatrixMode(GL_PROJECTION
);
196 glColor3f(1.0, 1.0, 1.0);
197 m_background
->apply();
198 glScalef(2.0, 2.0, 1.0);
201 glMatrixMode(GL_MODELVIEW
);
205 glMatrixMode(GL_MODELVIEW
);
207 glTranslatef(0,0,-10);
209 for (int i
=draw_start
; i
!=draw_end
; i
++) {
210 //float r = m_rot_curr - m_entry_spacing*i;
211 float r
= m_rot_curr
- i
* m_entry_spacing
;
214 glRotatef(r
*10,1,0,0);
215 glTranslatef(0,0,m_entry_distance
);
219 //glColor4f(1,1,1,1);
222 //glColor4f(1,1,1,0);
227 if (i
>= upper_bound
&& i
<= lower_bound
)
228 m_children
[i
]->draw();
233 void Menu::simulate()
235 m_rot_target
= m_selected
*m_entry_spacing
;
237 // smoothly scroll the list
238 float delta
= m_rot_target
-m_rot_curr
;
240 m_rot_vel
+= m_rot_accel
* delta
;
241 m_rot_curr
+= m_rot_vel
;
244 m_rot_vel
*= m_rot_friction
;
247 void Menu::init_perspective()