summaryrefslogtreecommitdiffstats
path: root/menu_demo/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'menu_demo/button.c')
-rw-r--r--menu_demo/button.c91
1 files changed, 79 insertions, 12 deletions
diff --git a/menu_demo/button.c b/menu_demo/button.c
index 7df7b08..365619b 100644
--- a/menu_demo/button.c
+++ b/menu_demo/button.c
@@ -4,56 +4,115 @@
#endif
#include <GL/gl.h>
+#include <string.h>
+#include <stdio.h>
#include "button.h"
-#include "bitmap.h"
-#define BUTTON_CLICK_HEIGHT 49
+
+
+struct ButtonStruct ButtonCreate(double f_dXPos, double f_dYPos, double f_dWidth, char *f_pcTitle, int f_iType)
+{
+ struct ButtonStruct l_sButton;
+
+ // copy parameters
+ l_sButton.m_dXPos = f_dXPos;
+ l_sButton.m_dYPos = f_dYPos;
+ l_sButton.m_iType = f_iType;
+ l_sButton.m_dWidth = f_dWidth;
+
+ // copy title
+ memcpy(l_sButton.m_pcTitle, f_pcTitle, sizeof(f_pcTitle));
+
+ switch (f_iType)
+ {
+ case BUTTON_CLICK:
+ l_sButton.m_piImgNormal[0] = BitmapLoad("img/button_click_left.bmp");
+ l_sButton.m_piImgNormal[1] = BitmapLoad("img/button_click_center.bmp");
+ l_sButton.m_piImgNormal[2] = BitmapLoad("img/button_click_right.bmp");
+
+ l_sButton.m_piImgPressed[0] = BitmapLoad("img/button_click_left_hover.bmp");
+ l_sButton.m_piImgPressed[1] = BitmapLoad("img/button_click_center_hover.bmp");
+ l_sButton.m_piImgPressed[2] = BitmapLoad("img/button_click_right_hover.bmp");
+
+ // calculate width of center image
+ l_sButton.m_dCenterWidth = f_dWidth - l_sButton.m_piImgNormal[0].m_iWidth - l_sButton.m_piImgNormal[2].m_iWidth;
+
+ // retrieve image height
+ l_sButton.m_dHeight = l_sButton.m_piImgNormal[0].m_iHeight;
+ break;
+
+ case BUTTON_RADIO:
+ case BUTTON_LABEL:
+ default:
+ break;
+ }
+
+ l_sButton.m_bPressed = FALSE;
+ l_sButton.m_bHover = FALSE;
+
+ return l_sButton;
+
+} // ButtonCreate
+
+
void ButtonClickRender(struct ButtonStruct *f_sButton)
{
char l_pcTitle[BUTTON_MAX_TITLE];
- double l_dWidth = f_sButton->m_dWidth;
+ // copy button attributes
+ double l_dWidth = f_sButton->m_dCenterWidth;
double l_dXPos = f_sButton->m_dXPos;
double l_dYPos = f_sButton->m_dYPos;
int l_iType = f_sButton->m_iType;
+ // copy buttom images
+ int l_iImageIdLeft = (!f_sButton->m_bHover) ? f_sButton->m_piImgNormal[0].m_iImageId : f_sButton->m_piImgPressed[0].m_iImageId;
+ int l_iImageIdCenter = (!f_sButton->m_bHover) ? f_sButton->m_piImgNormal[1].m_iImageId : f_sButton->m_piImgPressed[1].m_iImageId;
+ int l_iImageIdRight = (!f_sButton->m_bHover) ? f_sButton->m_piImgNormal[2].m_iImageId : f_sButton->m_piImgPressed[2].m_iImageId;
+
+ // copy button title
memset(&l_pcTitle, 0, sizeof(l_pcTitle));
memcpy(&l_pcTitle, f_sButton->m_pcTitle, sizeof(f_sButton->m_pcTitle));
- BitmapLoad("img/button_click_left.bmp");
+ // render left side of button
+ glBindTexture(GL_TEXTURE_2D, l_iImageIdLeft);
glBegin(GL_QUADS);
glTexCoord3d(0, 1, 0); glVertex3d(l_dXPos, l_dYPos, 0);
glTexCoord3d(1, 1, 0); glVertex3d(l_dXPos + 26, l_dYPos, 0);
- glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 26, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
- glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 26, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
glEnd();
- BitmapLoad("img/button_click_right.bmp");
+ // render right side of button
+ glBindTexture(GL_TEXTURE_2D, l_iImageIdRight);
glBegin(GL_QUADS);
glTexCoord3d(0, 1, 0); glVertex3d(l_dXPos + 24 + l_dWidth, l_dYPos, 0);
glTexCoord3d(1, 1, 0); glVertex3d(l_dXPos + 24 + l_dWidth + 25, l_dYPos, 0);
- glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 24 + l_dWidth + 25, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
- glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos + 24 + l_dWidth, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 24 + l_dWidth + 25, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos + 24 + l_dWidth, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
glEnd();
+ // render center of button
if (l_dWidth > 0)
{
- BitmapLoad("img/button_click_center.bmp");
+ glBindTexture(GL_TEXTURE_2D, l_iImageIdCenter);
glBegin(GL_QUADS);
glTexCoord3d(0, 1, 0); glVertex3d(l_dXPos + 25, l_dYPos, 0);
glTexCoord3d(1, 1, 0); glVertex3d(l_dXPos + 25 + l_dWidth, l_dYPos, 0);
- glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 25 + l_dWidth, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
- glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos + 25, l_dYPos - BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(1, 0, 0); glVertex3d(l_dXPos + 25 + l_dWidth, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
+ glTexCoord3d(0, 0, 0); glVertex3d(l_dXPos + 25, l_dYPos + BUTTON_CLICK_HEIGHT, 0);
glEnd();
}
} // ButtonClickRender
+
+
void ButtonRender(struct ButtonStruct *f_sButton)
{
int l_iType = f_sButton->m_iType;
@@ -71,3 +130,11 @@ void ButtonRender(struct ButtonStruct *f_sButton)
}
} // ButtonRender
+
+
+
+void ButtonHover(struct ButtonStruct *f_sButton)
+{
+ f_sButton->m_bHover = TRUE;
+
+} // ButtonHover