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.c89
1 files changed, 76 insertions, 13 deletions
diff --git a/menu_demo/menu.c b/menu_demo/menu.c
index 265c4d8..9159d13 100644
--- a/menu_demo/menu.c
+++ b/menu_demo/menu.c
@@ -32,6 +32,22 @@ struct MenuStruct *g_pCurMenu; // current menu
int g_iWinWidth;
int g_iWinHeight;
+
+
+void MenuAddButton(double f_dXPos, double f_dYPos, double f_dWidth, 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);
+
+ i++;
+ g_sMenuMain.m_iButtonCount = i;
+
+} // MenuAddButton
+
+
+
void MenuInit(int f_iWinWidth, int f_iWinHeight)
{
// init menu props
@@ -40,12 +56,7 @@ void MenuInit(int f_iWinWidth, int f_iWinHeight)
// init main menu
g_sMenuMain.m_eMenuId = MENU_MAIN;
- g_sMenuMain.m_sButtons[0].m_dWidth = 200;
- g_sMenuMain.m_sButtons[0].m_dXPos = 0;
- g_sMenuMain.m_sButtons[0].m_dYPos = 0;
- g_sMenuMain.m_sButtons[0].m_iType = BUTTON_CLICK;
-
- g_sMenuMain.m_iButtonCount = 1;
+ MenuAddButton(0, 0, 200, "Start", BUTTON_CLICK);
// init start menu
g_sMenuStart.m_eMenuId = MENU_START;
@@ -58,7 +69,9 @@ void MenuInit(int f_iWinWidth, int f_iWinHeight)
// set pointer to the current menu
g_pCurMenu = &g_sMenuMain;
-} // InitMenu
+} // MenuInit
+
+
void MenuRender(void)
{
@@ -67,16 +80,66 @@ void MenuRender(void)
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
- glColor3d(1, 1, 1);
-
- glPushMatrix();
-
+ glColor3d(1, 1, 1);
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+
+ glLoadIdentity();
+ glOrtho(0, (GLfloat)g_iWinWidth, (GLfloat)g_iWinHeight, 0, 0, 1);
+ glMatrixMode(GL_MODELVIEW);
+
+ // render the buttons on the current menu
while (i < g_pCurMenu->m_iButtonCount)
{
ButtonRender(&g_pCurMenu->m_sButtons[i]);
i++;
+ }
+
+ //restore the previous projection matrix
+ glMatrixMode(GL_PROJECTION);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+
+} // MenuRender
+
+
+
+void MenuMouseHandle(int f_iGlutButton, int f_iGlutState, int f_iXPos, int f_iYPos)
+{
+ int i = 0;
+ double l_dXPos, l_dYPos;
+ double l_iWidth, l_iHeight;
+
+ // f_iGlutButton:
+ // # GLUT_LEFT_BUTTON
+ // # GLUT_MIDDLE_BUTTON
+ // # GLUT_RIGHT_BUTTON
+
+ // f_iGlutState
+ // # GLUT_DOWN
+ // # GLUT_UP
+
+ // check if any button needs attention from the mouse
+ while (i < g_pCurMenu->m_iButtonCount)
+ {
+ l_dXPos = g_pCurMenu->m_sButtons[i].m_dXPos;
+ l_dYPos = g_pCurMenu->m_sButtons[i].m_dYPos;
+ l_iWidth = g_pCurMenu->m_sButtons[i].m_dWidth;
+ l_iHeight = g_pCurMenu->m_sButtons[i].m_dHeight;
+
+ 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]);
}
+ else
+ {
+ g_pCurMenu->m_sButtons[i].m_bHover = FALSE;
+ }
+ i++;
+ }
+
+} // MenuMouseHandle
- glPopMatrix();
-} // Render