122 lines
3.3 KiB
C++
122 lines
3.3 KiB
C++
/*
|
|
Copyright 2013 Peter Nelson
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
#include <pugl/pugl.h>
|
|
#include "pui.h"
|
|
|
|
static const float button_coords[][4] = {
|
|
{ 0, .75f, .25f, 1 }, /// Raised small button
|
|
{ .25f, .75f, .5f, 1 }, /// Lowered small button
|
|
|
|
{ 0, 0, .25f, .375f }, /// Raised large button left
|
|
{ .25f, 0, .5f, .375f }, /// Raised large button middle
|
|
{ .75f, 0, 1, .375f }, /// Raised large button right
|
|
|
|
{ 0, .375f, .25f, .75f }, /// Lowered large button left
|
|
{ .25f, .375f, .5f, .75f }, /// Lowered large button middle
|
|
{ .75f, .375f, 1, .75f }, /// Lowered large button right
|
|
};
|
|
|
|
enum ButtonPart {
|
|
BP_RSMALL,
|
|
BP_LSMALL,
|
|
|
|
BP_RL_LEFT,
|
|
BP_RL_MIDDLE,
|
|
BP_RL_RIGHT,
|
|
|
|
BP_LL_LEFT,
|
|
BP_LL_MIDDLE,
|
|
BP_LL_RIGHT,
|
|
};
|
|
|
|
SmallButton::SmallButton()
|
|
{
|
|
this->min = 0;
|
|
this->max = 1;
|
|
|
|
/* Fixed size as we've no access to textures here */
|
|
this->w = 32;
|
|
this->h = 32;
|
|
}
|
|
|
|
LargeButton::LargeButton()
|
|
{
|
|
this->min = 0;
|
|
this->max = 1;
|
|
|
|
/* Fixed size as we've no access to textures here */
|
|
this->w = -1;
|
|
this->h = 48;
|
|
}
|
|
|
|
static void button_rect(ButtonPart part, int x1, int y1, int x2, int y2)
|
|
{
|
|
const float *p = button_coords[part];
|
|
glTexCoord2f(p[0], p[1]);
|
|
glVertex2f(x1, y1);
|
|
glTexCoord2f(p[0], p[3]);
|
|
glVertex2f(x1, y2);
|
|
glTexCoord2f(p[2], p[3]);
|
|
glVertex2f(x2, y2);
|
|
glTexCoord2f(p[2], p[1]);
|
|
glVertex2f(x2, y1);
|
|
}
|
|
|
|
void SmallButton::OnPaint(const PUi *pui) const
|
|
{
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
GLuint t = TEX_BUTTONS;
|
|
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
|
|
glBegin(GL_QUADS);
|
|
if (colour.a) glColor4f(colour.r, colour.g, colour.b, colour.a);
|
|
else glColor4f(1, 1, 1, 1);
|
|
button_rect(this->value ? BP_LSMALL : BP_RSMALL, x, y, x + 32, y + 32);
|
|
glEnd();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
Widget::OnPaint(pui);
|
|
}
|
|
|
|
|
|
void LargeButton::OnPaint(const PUi *pui) const
|
|
{
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
GLuint t = TEX_BUTTONS;
|
|
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
|
|
glBegin(GL_QUADS);
|
|
if (colour.a) glColor4f(colour.r, colour.g, colour.b, colour.a);
|
|
else glColor4f(1, 1, 1, 1);
|
|
|
|
if (w <= 64) {
|
|
float w2 = w * .5f;
|
|
button_rect(this->value ? BP_LL_LEFT : BP_RL_LEFT, x, y, x + w2, y + 48);
|
|
button_rect(this->value ? BP_LL_RIGHT : BP_RL_RIGHT, x + w2 - 32, y, x + w, y + 48);
|
|
} else {
|
|
button_rect(this->value ? BP_LL_LEFT : BP_RL_LEFT, x, y, x + 32, y + 48);
|
|
button_rect(this->value ? BP_LL_MIDDLE : BP_RL_MIDDLE, x + 32, y, x + w - 32, y + 48);
|
|
button_rect(this->value ? BP_LL_RIGHT : BP_RL_RIGHT, x + w - 32, y, x + w, y + 48);
|
|
}
|
|
glEnd();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
Widget::OnPaint(pui);
|
|
}
|
|
|