handle controller button events

This commit is contained in:
Josh Holtrop 2018-01-15 21:46:31 -05:00
parent 29baefe85a
commit e1b28e52e3

View File

@ -19,14 +19,14 @@ static struct
GLint color; GLint color;
GLint position; GLint position;
} uniforms; } uniforms;
int color = 0; unsigned int color = 0u;
GLfloat size = 0.2; GLfloat size = 0.2;
GLfloat position[2] = {0.0, 0.0}; GLfloat position[2] = {0.0, 0.0};
GLfloat colors[][4] = { GLfloat colors[][4] = {
{1.0, 0.7, 0.0, 1.0}, {1.0, 0.7, 0.0, 1.0},
{0.0, 0.5, 1.0, 1.0}, {0.0, 0.2, 1.0, 1.0},
{1.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
{0.2, 0.2, 1.0, 1.0}, {0.2, 1.0, 1.0, 1.0},
}; };
float movement[2]; float movement[2];
static SDL_Event UpdateEvent; static SDL_Event UpdateEvent;
@ -194,9 +194,23 @@ int main(int argc, char *argv[])
movement[1] = 0.0; movement[1] = 0.0;
} }
} }
else if (event.type == SDL_CONTROLLERBUTTONDOWN) else if ((event.type == SDL_CONTROLLERBUTTONDOWN) &&
(event.cbutton.state == SDL_PRESSED))
{ {
std::cerr << "button!" << std::endl; switch (event.cbutton.button)
{
case SDL_CONTROLLER_BUTTON_A:
size *= 0.8;
break;
case SDL_CONTROLLER_BUTTON_B:
size *= 1.2;
break;
case SDL_CONTROLLER_BUTTON_X:
color++;
if (color >= sizeof(colors) / sizeof(colors[0]))
color = 0u;
break;
}
} }
else if (event.type == SDL_USEREVENT) else if (event.type == SDL_USEREVENT)
{ {