pplugins/pui/widget.cpp

51 lines
1.0 KiB
C++

#include <pugl/pugl.h>
#include "pui.h"
bool Widget::SetValue(float newvalue)
{
/* Clamp new value */
if (newvalue <= this->min) newvalue = this->min;
if (newvalue >= this->max) newvalue = this->max;
/* Value is different? */
if (newvalue == this->value) return false;
snprintf(this->text, sizeof this->text, "%s: %0.4f", this->label, newvalue);
this->value = newvalue;
return true;
}
void Widget::Pad(int xpad, int ypad)
{
this->x += xpad;
this->y += ypad;
this->w -= xpad + xpad;
this->h -= ypad + ypad;
}
void Widget::OnPaint(const PUi *pui) const
{
if (this->active) {
glBegin(GL_LINE_LOOP);
glColor4f(1.f, 1.f, 1.0f, 0.25f);
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();
}
}
void Frame::OnPaint(const PUi *pui) const
{
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();
}