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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include "Menu.h"
Menu::Menu(int width, int height, bool isWide)
{
Resize(width, height);
LoadMenuTextures(isWide);
}
Menu::~Menu() {}
void Menu::Resize(int width, int height)
{
//SETUP THE BACKGROUND
bg.x1 = 0;
bg.y1 = 0;
bg.x2 = width;
bg.y2 = height;
//SETUP THE BUTTONS
double btnStartX = (width * 0.66666);
double btnStartY = (height * 0.25);
double btnWidth = (width * 0.25);
double btnHeight = (height * 0.125);
//SET THE BUTTONS
btns[0].x1 = btnStartX;
btns[0].y1 = btnStartY;
btns[0].x2 = btnStartX + btnWidth;
btns[0].y2 = btnStartY + btnHeight;
btns[1].x1 = btnStartX;
btns[1].y1 = btnStartY + (btnHeight *2);
btns[1].x2 = btnStartX + btnWidth;
btns[1].y2 = btnStartY + (btnHeight *3);
btns[2].x1 = btnStartX;
btns[2].y1 = btnStartY + (btnHeight *4);
btns[2].x2 = btnStartX + btnWidth;
btns[2].y2 = btnStartY + (btnHeight *5);
}
uint Menu::Click(int x, int y)
{
//COLLISION TEST ON THE BUTTONS
for(int i = 0; i < 3; ++i)
{
if(x > btns[i].x1 && y > btns[i].y1)
{
if(x < btns[i].x2 && y < btns[i].y2)
{
return (i + 1);
}
}
}
return 0;
}
void Menu::DrawMenu()
{
glPushMatrix();
//DRAW THE BACKGROUND
glColor4d(1.0, 1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, tex[0]);
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2d(bg.x1, bg.y1);
glTexCoord2d(0, 1);
glVertex2d(bg.x1, bg.y2);
glTexCoord2d(1, 1);
glVertex2d(bg.x2, bg.y2);
glTexCoord2d(1, 0);
glVertex2d(bg.x2, bg.y1);
glEnd();
//DRAW THE BUTTONS
glColor4d(1.0, 1.0, 1.0, 1.0); //The Default Color of the Buttons is Cyan
for(int i = 0; i < 3; ++i)
{
glBindTexture(GL_TEXTURE_2D, tex[(i + 1)]);
glBegin(GL_QUADS);
glTexCoord2d(0, 0);
glVertex2d(btns[i].x1, btns[i].y1);
glTexCoord2d(0, 1);
glVertex2d(btns[i].x1, btns[i].y2);
glTexCoord2d(1, 1);
glVertex2d(btns[i].x2, btns[i].y2);
glTexCoord2d(1, 0);
glVertex2d(btns[i].x2, btns[i].y1);
glEnd();
}
glPopMatrix();
}
void Menu::LoadMenuTextures(bool isWide)
{
YsRawPngDecoder *png = new YsRawPngDecoder();
glGenTextures(4, tex);
for(int i = 0; i < 4; ++i)
{
glBindTexture(GL_TEXTURE_2D, tex[i]);
switch(i)
{
case 0:
{
if(isWide)
{
png->Decode("Data/Art/16by9/menubg.png");
}
else
{
png->Decode("Data/Art/4by3/menubg.png");
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);
continue;
}
case 1:
{
if(isWide)
{
png->Decode("Data/Art/16by9/menuStart.png");
}
else
{
png->Decode("Data/Art/4by3/menuStart.png");
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);
continue;
}
case 2:
{
if(isWide)
{
png->Decode("Data/Art/16by9/menuOpt.png");
}
else
{
png->Decode("Data/Art/4by3/menuOpt.png");
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);
continue;
}
case 3:
{
if(isWide)
{
png->Decode("Data/Art/16by9/menuExit.png");
}
else
{
png->Decode("Data/Art/4by3/menuExit.png");
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, png->wid, png->hei, GL_RGBA, GL_UNSIGNED_BYTE, png->rgba);
continue;
}
}
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
free(png);
}
|