pplugins/pui/container.cpp

112 lines
2.6 KiB
C++

#include <pugl/pugl.h>
#include "pui.h"
Container::~Container()
{
std::list<Widget *>::iterator it;
for (it = children.begin(); it != children.end(); ++it) {
delete *it;
}
}
void Container::OnPaint(const PUi *pui) const
{
if (this->back) {
float tw = (float)w / pui->w[TEX_BACKTILE];
float th = (float)h / pui->h[TEX_BACKTILE];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, pui->tex[TEX_BACKTILE]);
glBegin(GL_QUADS);
glColor4f(colour.r, colour.g, colour.b, colour.a);
glTexCoord2f(.0, .0);
glVertex2f( x, y);
glTexCoord2f(.0, th);
glVertex2f( x, h + y);
glTexCoord2f(tw, th);
glVertex2f(w + x, h + y);
glTexCoord2f(tw, .0);
glVertex2f(w + x, y);
glEnd();
glBindTexture(GL_TEXTURE_2D, pui->tex[TEX_BACKGLOW]);
glBegin(GL_QUADS);
glColor4f(colour.r, colour.g, colour.b, colour.a * 0.3f);
glTexCoord2f(.0, .0);
glVertex2f( x, y);
glTexCoord2f(.0, 1);
glVertex2f( x, h + y);
glTexCoord2f(1, 1);
glVertex2f(w + x, h + y);
glTexCoord2f(1, .0);
glVertex2f(w + x, y);
glEnd();
glDisable(GL_TEXTURE_2D);
} else if (this->colour.a) {
glBegin(GL_QUADS);
glColor4f(colour.r, colour.g, colour.b, colour.a);
glVertex2f( x, y);
glVertex2f( x, h + y);
glVertex2f(w + x, h + y);
glVertex2f(w + x, y);
glEnd();
}
if (this->frame.a) {
if (true) {
glBegin(GL_LINE_LOOP);
glColor4f(frame.r, frame.g, frame.b, frame.a);
glVertex2f( x + .5f, y + .5f);
glVertex2f( x + .5f, h + y - .5f);
glVertex2f(w + x - .5f, h + y - .5f);
glVertex2f(w + x - .5f, y + .5f);
glEnd();
} else {
glBegin(GL_LINE_LOOP);
glColor4f(1, 1, 1, frame.a);
glVertex2f( x + 1.5f, y + 1.5f);
glVertex2f( x + 1.5f, h + y - .5f);
glVertex2f(w + x - .5f, h + y - .5f);
glVertex2f(w + x - .5f, y + 1.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glColor4f(0, 0, 0, frame.a);
glVertex2f( x + .5f, y + .5f);
glVertex2f( x + .5f, h + y - 1.5f);
glVertex2f(w + x - 1.5f, h + y - 1.5f);
glVertex2f(w + x - 1.5f, y + .5f);
glEnd();
}
}
std::list<Widget *>::const_iterator it;
for (it = children.begin(); it != children.end(); ++it) {
(*it)->OnPaint(pui);
}
}
Widget *Container::GetWidget(int x, int y)
{
std::list<Widget *>::iterator it;
for (it = children.begin(); it != children.end(); ++it) {
if ((*it)->Hit(x, y)) return (*it)->GetWidget(x, y);
}
return NULL;
}
Widget *Container::GetWidget(uint32_t port)
{
if (this->port == port) return this;
std::list<Widget *>::iterator it;
for (it = children.begin(); it != children.end(); ++it) {
Widget *w = (*it)->GetWidget(port);
if (w) return w;
}
return NULL;
}