66 lines
1.8 KiB
C++
66 lines
1.8 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"
|
|
|
|
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();
|
|
}
|
|
|