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.c210
1 files changed, 175 insertions, 35 deletions
diff --git a/menu_demo/button.c b/menu_demo/button.c
index 365619b..cd5a561 100644
--- a/menu_demo/button.c
+++ b/menu_demo/button.c
@@ -11,15 +11,15 @@
-struct ButtonStruct ButtonCreate(double f_dXPos, double f_dYPos, double f_dWidth, char *f_pcTitle, int f_iType)
+struct ButtonStruct ButtonCreate(int f_dXPos, int f_dYPos, int f_dCenterWidth, int f_dHeight, 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;
+ l_sButton.m_dXPos = f_dXPos;
+ l_sButton.m_dYPos = f_dYPos;
+ l_sButton.m_iType = f_iType;
+ l_sButton.m_dHeight = f_dHeight;
// copy title
memcpy(l_sButton.m_pcTitle, f_pcTitle, sizeof(f_pcTitle));
@@ -27,22 +27,30 @@ struct ButtonStruct ButtonCreate(double f_dXPos, double f_dYPos, double f_dWidth
switch (f_iType)
{
case BUTTON_CLICK:
+ l_sButton.m_dCenterWidth = f_dCenterWidth;
+
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");
+ l_sButton.m_piImgHover[0] = BitmapLoad("img/button_click_left_hover.bmp");
+ l_sButton.m_piImgHover[1] = BitmapLoad("img/button_click_center_hover.bmp");
+ l_sButton.m_piImgHover[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;
+ l_sButton.m_dWidth = f_dCenterWidth + l_sButton.m_piImgNormal[0].m_iWidth + l_sButton.m_piImgNormal[2].m_iWidth;
+ break;
- // retrieve image height
+ case BUTTON_RADIO:
+ l_sButton.m_piImgNormal[0] = BitmapLoad("img/button_radio.bmp");
+ l_sButton.m_piImgHover[0] = BitmapLoad("img/button_radio_hover.bmp");
+ l_sButton.m_piImgPressed[0] = BitmapLoad("img/button_radio_pressed.bmp");
+
+ l_sButton.m_dCenterWidth = 0;
+ l_sButton.m_dWidth = l_sButton.m_piImgNormal[0].m_iWidth;
l_sButton.m_dHeight = l_sButton.m_piImgNormal[0].m_iHeight;
break;
- case BUTTON_RADIO:
case BUTTON_LABEL:
default:
break;
@@ -57,20 +65,55 @@ struct ButtonStruct ButtonCreate(double f_dXPos, double f_dYPos, double f_dWidth
+int ButtonGetType(struct ButtonStruct *f_sButton)
+{
+ return f_sButton->m_iType;
+
+} // ButtonGetType
+
+
+
void ButtonClickRender(struct ButtonStruct *f_sButton)
{
char l_pcTitle[BUTTON_MAX_TITLE];
+ struct ImageStruct *l_sImgButton;
+ int l_iImgWidth, l_iImageIdLeft, l_iImageIdCenter, l_iImageIdRight;
+ double l_dXOffset, l_dYOffset;
+
+ double l_dYCoordTop = 1;
+ double l_dYCoordBot = 0;
// 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;
+ double l_dCnWdt = f_sButton->m_dCenterWidth;
+ double l_dHeight = f_sButton->m_dHeight;
+ double l_dXPos = f_sButton->m_dXPos;
+ double l_dYPos = f_sButton->m_dYPos;
+
+ if (f_sButton->m_bPressed)
+ {
+ //l_dYCoordBot += l_dYCoordTop;
+ //l_dYCoordTop -= l_dYCoordTop;
+ glColor3d(0.8, 0.9, 1);
+ }
+ else
+ {
+ glColor3d(1, 1, 1);
+ }
+
+ // get the right image struct
+ if (f_sButton->m_bHover)
+ {
+ l_sImgButton = f_sButton->m_piImgHover;
+ }
+ else
+ {
+ l_sImgButton = f_sButton->m_piImgNormal;
+ }
// 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;
+ l_iImageIdLeft = l_sImgButton[0].m_iImageId;
+ l_iImageIdCenter = l_sImgButton[1].m_iImageId;
+ l_iImageIdRight = l_sImgButton[2].m_iImageId;
// copy button title
memset(&l_pcTitle, 0, sizeof(l_pcTitle));
@@ -79,37 +122,106 @@ void ButtonClickRender(struct ButtonStruct *f_sButton)
// render left side of button
glBindTexture(GL_TEXTURE_2D, l_iImageIdLeft);
+ l_iImgWidth = l_sImgButton[0].m_iWidth;
+ l_dXOffset = l_dXPos;
+ l_dYOffset = l_dYPos;
+
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);
+ glTexCoord2d(0, l_dYCoordTop); glVertex3d(l_dXOffset, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordTop); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordBot); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset + l_dHeight, 0);
+ glTexCoord2d(0, l_dYCoordBot); glVertex3d(l_dXOffset, l_dYOffset + l_dHeight, 0);
glEnd();
+ l_dXOffset += l_iImgWidth;
+
+ // render center of button
+ if (l_dCnWdt > 0)
+ {
+ glBindTexture(GL_TEXTURE_2D, l_iImageIdCenter);
+
+ l_iImgWidth = l_sImgButton[2].m_iWidth;
+
+ glBegin(GL_QUADS);
+ glTexCoord2d(0, l_dYCoordTop); glVertex3d(l_dXOffset, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordTop); glVertex3d(l_dXOffset + l_dCnWdt, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordBot); glVertex3d(l_dXOffset + l_dCnWdt, l_dYOffset + l_dHeight, 0);
+ glTexCoord2d(0, l_dYCoordBot); glVertex3d(l_dXOffset, l_dYOffset + l_dHeight, 0);
+ glEnd();
+ }
+
+ l_dXOffset += l_dCnWdt;
+
// render right side of button
glBindTexture(GL_TEXTURE_2D, l_iImageIdRight);
+ l_iImgWidth = l_sImgButton[2].m_iWidth;
+
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);
+ glTexCoord2d(0, l_dYCoordTop); glVertex3d(l_dXOffset, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordTop); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset, 0);
+ glTexCoord2d(1, l_dYCoordBot); glVertex3d(l_dXOffset + l_iImgWidth, l_dYOffset + l_dHeight, 0);
+ glTexCoord2d(0, l_dYCoordBot); glVertex3d(l_dXOffset, l_dYOffset + l_dHeight, 0);
glEnd();
- // render center of button
- if (l_dWidth > 0)
+ if (f_sButton->m_bPressed)
{
- glBindTexture(GL_TEXTURE_2D, l_iImageIdCenter);
+ glColor3d(1, 1, 1);
+ }
+
+} // ButtonClickRender
+
+
+
+void ButtonRadioRender(struct ButtonStruct *f_sButton)
+{
+ struct ImageStruct *l_sImgButton;
+ int l_iImageId;
+
+ // copy button attributes
+ double l_dWidth = f_sButton->m_dWidth;
+ double l_dHeight = f_sButton->m_dHeight;
+ double l_dXPos = f_sButton->m_dXPos;
+ double l_dYPos = f_sButton->m_dYPos;
+
+ // get the right image struct
+ if (f_sButton->m_bHover)
+ {
+ l_sImgButton = f_sButton->m_piImgHover;
+ }
+ else
+ {
+ l_sImgButton = f_sButton->m_piImgNormal;
+ }
+
+ // copy buttom images
+ l_iImageId = l_sImgButton[0].m_iImageId;
+
+ // render left side of button
+ glBindTexture(GL_TEXTURE_2D, l_iImageId);
+
+ glBegin(GL_QUADS);
+ glTexCoord2d(0, 1); glVertex3d(l_dXPos, l_dYPos, 0);
+ glTexCoord2d(1, 1); glVertex3d(l_dXPos + l_dWidth, l_dYPos, 0);
+ glTexCoord2d(1, 0); glVertex3d(l_dXPos + l_dWidth, l_dYPos + l_dHeight, 0);
+ glTexCoord2d(0, 0); glVertex3d(l_dXPos, l_dYPos + l_dHeight, 0);
+ glEnd();
+
+ if (f_sButton->m_bPressed)
+ {
+ l_iImageId = f_sButton->m_piImgPressed[0].m_iImageId;
+ glBindTexture(GL_TEXTURE_2D, l_iImageId);
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);
+ glTexCoord2d(0, 1); glVertex3d(l_dXPos, l_dYPos, 0);
+ glTexCoord2d(1, 1); glVertex3d(l_dXPos + l_dWidth, l_dYPos, 0);
+ glTexCoord2d(1, 0); glVertex3d(l_dXPos + l_dWidth, l_dYPos + l_dHeight, 0);
+ glTexCoord2d(0, 0); glVertex3d(l_dXPos, l_dYPos + l_dHeight, 0);
glEnd();
}
-} // ButtonClickRender
+} // ButtonRadioRender
+
@@ -124,6 +236,9 @@ void ButtonRender(struct ButtonStruct *f_sButton)
break;
case BUTTON_RADIO:
+ ButtonRadioRender(f_sButton);
+ break;
+
case BUTTON_LABEL:
default:
break;
@@ -133,8 +248,33 @@ void ButtonRender(struct ButtonStruct *f_sButton)
-void ButtonHover(struct ButtonStruct *f_sButton)
+void ButtonEnter(struct ButtonStruct *f_sButton)
{
f_sButton->m_bHover = TRUE;
} // ButtonHover
+
+
+
+void ButtonExit(struct ButtonStruct *f_sButton)
+{
+ f_sButton->m_bHover = FALSE;
+
+} // ButtonHover
+
+
+
+void ButtonPress(struct ButtonStruct *f_sButton)
+{
+// f_sButton->m_bPressed = TRUE;
+ f_sButton->m_bPressed = !f_sButton->m_bPressed;
+
+} // ButtonPress
+
+
+
+void ButtonRelease(struct ButtonStruct *f_sButton)
+{
+ f_sButton->m_bPressed = FALSE;
+
+} // ButtonPress