summaryrefslogtreecommitdiffstats
path: root/menu_demo/menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu_demo/menu.c')
-rw-r--r--menu_demo/menu.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/menu_demo/menu.c b/menu_demo/menu.c
index 9a3c081..c08540e 100644
--- a/menu_demo/menu.c
+++ b/menu_demo/menu.c
@@ -3,9 +3,9 @@
#include <windows.h>
#endif
-#include <GL/gl.h>
-
#include <stdlib.h>
+#include <GL/gl.h>
+#include <GL/glut.h>
#include "menu.h"
#include "button.h"
@@ -34,12 +34,12 @@ int g_iWinHeight;
-void MenuAddButton(double f_dXPos, double f_dYPos, double f_dWidth, char *f_pcTitle, int f_iType)
+void MenuAddButton(int f_dXPos, int f_dYPos, int f_dWidth, int f_dHeight, char *f_pcTitle, int f_iType)
{
int i;
i = g_sMenuMain.m_iButtonCount;
- g_sMenuMain.m_sButtons[i] = ButtonCreate(f_dXPos, f_dYPos, f_dWidth, f_pcTitle, f_iType);
+ g_sMenuMain.m_sButtons[i] = ButtonCreate(f_dXPos, f_dYPos, f_dWidth, f_dHeight, f_pcTitle, f_iType);
i++;
g_sMenuMain.m_iButtonCount = i;
@@ -56,7 +56,8 @@ void MenuInit(int f_iWinWidth, int f_iWinHeight)
// init main menu
g_sMenuMain.m_eMenuId = MENU_MAIN;
- MenuAddButton(0, 0, 200, "Start", BUTTON_CLICK);
+ MenuAddButton(50, 50, 200, 100, "Start", BUTTON_CLICK);
+ MenuAddButton(200, 200, 180, 180, "Start", BUTTON_RADIO);
// init start menu
g_sMenuStart.m_eMenuId = MENU_START;
@@ -75,27 +76,34 @@ void MenuInit(int f_iWinWidth, int f_iWinHeight)
void MenuRender(void)
{
- int i = 0;
+ int i;
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
- glColor3d(1, 1, 1);
+ glColor4d(1, 1, 1, 1);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
- glOrtho(0, (GLfloat)g_iWinWidth, (GLfloat)g_iWinHeight, 0, 0, 1);
+ glOrtho(1, (GLfloat)g_iWinWidth, (GLfloat)g_iWinHeight, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
- // render the buttons on the current menu
+ glEnable(GL_BLEND);
+ //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ // render the buttons (mask) on the current menu
+ i = 0;
while (i < g_pCurMenu->m_iButtonCount)
{
ButtonRender(&g_pCurMenu->m_sButtons[i]);
i++;
}
+ glDisable(GL_BLEND);
+
//restore the previous projection matrix
glMatrixMode(GL_PROJECTION);
@@ -120,8 +128,23 @@ void MenuMouseHandle(int f_iGlutButton, int f_iGlutState, int f_iXPos, int f_iYP
// f_iGlutState
// # GLUT_DOWN
// # GLUT_UP
+
+ // button released
+ if (f_iGlutButton == GLUT_LEFT_BUTTON && f_iGlutState == GLUT_UP)
+ {
+ i = 0;
+ while (i < g_pCurMenu->m_iButtonCount)
+ {
+ if (ButtonGetType(&g_pCurMenu->m_sButtons[i]) == BUTTON_CLICK)
+ {
+ ButtonRelease(&g_pCurMenu->m_sButtons[i]);
+ }
+ i++;
+ }
+ }
// check if any button needs attention from the mouse
+ i = 0;
while (i < g_pCurMenu->m_iButtonCount)
{
l_dXPos = g_pCurMenu->m_sButtons[i].m_dXPos;
@@ -131,11 +154,17 @@ void MenuMouseHandle(int f_iGlutButton, int f_iGlutState, int f_iXPos, int f_iYP
if (l_dXPos <= f_iXPos && l_dXPos + l_iWidth >= f_iXPos &&l_dYPos <= f_iYPos && l_dYPos + l_iHeight >= f_iYPos)
{
- ButtonHover(&g_pCurMenu->m_sButtons[i]);
+ ButtonEnter(&g_pCurMenu->m_sButtons[i]);
+
+ // button pressed?
+ if (f_iGlutButton == GLUT_LEFT_BUTTON && f_iGlutState == GLUT_DOWN)
+ {
+ ButtonPress(&g_pCurMenu->m_sButtons[i]);
+ }
}
- else
+ else // mouse leaves button
{
- g_pCurMenu->m_sButtons[i].m_bHover = FALSE;
+ ButtonExit(&g_pCurMenu->m_sButtons[i]);
}
i++;
}