-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBase.cpp
More file actions
61 lines (55 loc) · 1.34 KB
/
MenuBase.cpp
File metadata and controls
61 lines (55 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "MenuBase.h"
#include "Controller.h"
#include <string>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
MenuBase::MenuBase(std::string title, Controller* c)
{
this->title = title;
this->c = c;
}
void MenuBase::Keyboard(int key)
{
switch(key) {
case 13:
SelectMenuItem(position);
break;
}
}
void MenuBase::SpecialKeyboard(int key)
{
switch(key) {
case GLUT_KEY_UP:
position = abs(position-1) % items.size();
break;
case GLUT_KEY_DOWN:
position = abs(position+1) % items.size();
break;
}
}
void MenuBase::Render()
{
glColor3ub( 0, 0, 0);
glRectf(0,0,800,600);
glColor3ub( 0, 222, 18);
glRasterPos3d(WIDTH/2-title.length()*4.5, HEIGHT - 30, 0);
glutBitmapString(GLUT_BITMAP_9_BY_15, (unsigned char*)title.c_str());
int offset_y = 250;
int i = 0;
for(std::string& s: items)
{
if(i == position)
{
glRasterPos3d(WIDTH/2-s.length()*4.5 - 40, HEIGHT - offset_y, 0);
glutBitmapString(GLUT_BITMAP_9_BY_15, (unsigned char*)">");
glRasterPos3d(WIDTH/2+s.length()*3.5 + 40, HEIGHT - offset_y, 0);
glutBitmapString(GLUT_BITMAP_9_BY_15, (unsigned char*)"<");
}
glRasterPos3d(WIDTH/2-s.length()*4.5, HEIGHT - offset_y, 0);
glutBitmapString(GLUT_BITMAP_9_BY_15, (unsigned char*)s.c_str());
offset_y += 40;
i++;
}
}