-
Notifications
You must be signed in to change notification settings - Fork 0
/
glwmenu.c
67 lines (60 loc) · 1.53 KB
/
glwmenu.c
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
62
63
64
65
66
67
/*
* glwmenu.c
*
* Created on: 23.05.2010
* Author: cdev
*/
#include "widgets.h"
GLWMenu * glw_menu_make(GLuint x, GLuint y, GLsizei bnums, char ** captions, glw_action * handls)
{
GLWMenu * glww = (GLWMenu *)malloc(sizeof(GLWMenu));
glww->showed = false;
glww->bnums = bnums;
glww->buttons = (GLWButton **)malloc(sizeof(GLWButton *) * bnums);
GLuint maxbsize = 0;
GLuint h = y + (text->h * (bnums - 1) + border * 3 * (bnums - 1)) / 2;
for(GLsizei i = 0; i < bnums; i++)
{
GLuint sbuf = strlen(captions[i]);
if(sbuf > maxbsize) maxbsize = sbuf;
glww->buttons[i] = glw_button_make(x, h, 0.3, captions[i], handls[i]);
h -= 3 * border + text->h;
}
glww->frame = glw_frame_make(x, y, maxbsize * text->h + 2 * border,
text->h * bnums + border * 3 * bnums, 0.3);
return glww;
}
void glw_menu_focus(GLWMenu * glww, GLuint x, GLuint y)
{
for(GLsizei i = 0; i < glww->bnums; i++)
glw_button_focus(glww->buttons[i], x, y);
}
void glw_menu_action(GLWMenu * glww)
{
for(GLsizei i = 0; i < glww->bnums; i++)
if(glww->buttons[i]->focused)
{
glw_menu_close(glww);
glw_button_action(glww->buttons[i]);
return;
}
}
void glw_menu_raise(GLWMenu * glww)
{
SDL_ShowCursor(1);
glww->showed = true;
}
void glw_menu_close(GLWMenu * glww)
{
SDL_ShowCursor(0);
glww->showed = false;
}
void glw_menu_show(GLWMenu * glww)
{
if(glww->showed)
{
glCallList(glww->frame->call_list);
for(GLsizei i = 0; i < glww->bnums; i++)
glw_button_show(glww->buttons[i]);
}
}