Add small & large button widgets
parent
a72b7d37df
commit
9dfea26e0e
|
@ -4,7 +4,8 @@ LDFLAGS := -lm
|
|||
CFLAGS += `pkg-config ftgl pugl-0 --cflags`
|
||||
LDFLAGS += `pkg-config ftgl pugl-0 --libs`
|
||||
|
||||
PUISRC := container.cpp
|
||||
PUISRC := button.cpp
|
||||
PUISRC += container.cpp
|
||||
PUISRC += label.cpp
|
||||
PUISRC += knob.cpp
|
||||
PUISRC += pui.cpp
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
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
|
||||
{
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
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
|
||||
{
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
#ifndef BUTTON_H
|
||||
#define BUTTON_H
|
||||
|
||||
struct Button : Widget {
|
||||
Colour colour;
|
||||
|
||||
/* virtual */ float GetNewValue(int x, int y) { return 1 - this->value; }
|
||||
};
|
||||
|
||||
struct SmallButton : Button {
|
||||
SmallButton();
|
||||
|
||||
/* virtual */ void OnPaint(const PUi *pui) const;
|
||||
};
|
||||
|
||||
struct LargeButton : Button {
|
||||
LargeButton();
|
||||
|
||||
/* virtual */ void OnPaint(const PUi *pui) const;
|
||||
};
|
||||
|
||||
#endif /* BUTTON_H */
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "textures.h"
|
||||
#include "widget.h"
|
||||
#include "button.h"
|
||||
#include "container.h"
|
||||
#include "label.h"
|
||||
#include "knob.h"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "pui.h"
|
||||
|
||||
#include "textures/sliders.c"
|
||||
#include "textures/buttons.c"
|
||||
|
||||
#include "textures/knob.c"
|
||||
#include "textures/knob-prelight.c"
|
||||
|
@ -99,6 +100,11 @@ void PTextures::InitTextures()
|
|||
sliders.height,
|
||||
sliders.pixel_data);
|
||||
|
||||
BindTexture(TEX_BUTTONS,
|
||||
buttons.width,
|
||||
buttons.height,
|
||||
buttons.pixel_data);
|
||||
|
||||
BindTexture(TEX_KNOB,
|
||||
knob.width,
|
||||
knob.height,
|
||||
|
|
|
@ -22,6 +22,7 @@ enum {
|
|||
TEX_BACKGLOW,
|
||||
|
||||
TEX_SLIDERS,
|
||||
TEX_BUTTONS,
|
||||
|
||||
TEX_KNOB,
|
||||
TEX_KNOB_PRE,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue