Pass PUi object as parameter of OnPaint instead of requiring to be during widget creation.

This commit is contained in:
2013-02-03 20:11:09 +00:00
parent 464856b95a
commit 35a44308d9
10 changed files with 35 additions and 43 deletions

View File

@@ -9,14 +9,14 @@ Container::~Container()
}
}
void Container::OnPaint() const
void Container::OnPaint(const PUi *pui) const
{
if (this->back) {
float tw = (float)w / tex->w[TEX_BACKTILE];
float th = (float)h / tex->h[TEX_BACKTILE];
float tw = (float)w / pui->w[TEX_BACKTILE];
float th = (float)h / pui->h[TEX_BACKTILE];
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex->tex[TEX_BACKTILE]);
glBindTexture(GL_TEXTURE_2D, pui->tex[TEX_BACKTILE]);
glBegin(GL_QUADS);
glColor4f(colour.r, colour.g, colour.b, colour.a);
glTexCoord2f(.0, .0);
@@ -29,7 +29,7 @@ void Container::OnPaint() const
glVertex2f(w + x, y);
glEnd();
glBindTexture(GL_TEXTURE_2D, tex->tex[TEX_BACKGLOW]);
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);
@@ -84,7 +84,7 @@ void Container::OnPaint() const
std::list<Widget *>::const_iterator it;
for (it = children.begin(); it != children.end(); ++it) {
(*it)->OnPaint();
(*it)->OnPaint(pui);
}
}

View File

@@ -15,7 +15,7 @@ struct Container : Widget {
/* virtual */ Widget *GetWidget(uint32_t port);
/* virtual */ void OnPaint() const;
/* virtual */ void OnPaint(const PUi *pui) const;
};
#endif /* CONTAINER_H */

View File

@@ -19,7 +19,7 @@ float Knob::GetNewValue(int x, int y)
}
}
void Knob::OnPaint() const
void Knob::OnPaint(const PUi *pui) const
{
// float m = (value - min) / (max - min);
@@ -30,13 +30,13 @@ void Knob::OnPaint() const
glEnable(GL_TEXTURE_2D);
int t = TEX_KNOB;
int w2 = tex->w[t];
int h2 = tex->h[t];
int w2 = pui->w[t];
int h2 = pui->h[t];
int mx, my;
mx = (w - w2) * 0.5f + x;
my = (h - h2) * 0.5f + y;
glBindTexture(GL_TEXTURE_2D, tex->tex[t]);
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0);

View File

@@ -4,7 +4,7 @@
struct Knob : Widget {
/* virtual */ float GetNewValue(int x, int y);
/* virtual */ void OnPaint() const;
/* virtual */ void OnPaint(const PUi *pui) const;
};
#endif /* KNOB_H */

View File

@@ -23,7 +23,7 @@ void PUi::OnDisplay()
if (!this->initialised) this->InitTextures();
glClear(GL_COLOR_BUFFER_BIT);
this->widget->OnPaint();
this->widget->OnPaint(this);
}
void PUi::OnKeyboard(bool press, uint32_t key)

View File

@@ -14,7 +14,7 @@ float HSlider::GetNewValue(int x, int y)
return (x - x2) * (max - min) / w2 + min;
}
void HSlider::OnPaint() const
void HSlider::OnPaint(const PUi *pui) const
{
float m = (value - min) / (max - min);
@@ -25,8 +25,8 @@ void HSlider::OnPaint() const
glEnable(GL_TEXTURE_2D);
int t = big ? TEX_TROUGH1 : TEX_TROUGH1;
int w2 = tex->w[t];
int h2 = tex->h[t];
int w2 = pui->w[t];
int h2 = pui->h[t];
int mx, my;
mx = (w - w2) * 0.5f + x;
my = (h - h2) * 0.5f + y;
@@ -34,7 +34,7 @@ void HSlider::OnPaint() const
int cut = big ? trough2_cut : trough1_cut;
float fc = (float)cut / h2;
glBindTexture(GL_TEXTURE_2D, tex->tex[t]);
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0);
@@ -79,15 +79,15 @@ void HSlider::OnPaint() const
} else {
t = active ? TEX_SLIDER1_PRE : TEX_SLIDER1;
}
w2 = tex->w[t];
h2 = tex->h[t];
w2 = pui->w[t];
h2 = pui->h[t];
int x3 = this->x + pad;
int w3 = this->w - pad - pad;
mx = w3 * m + x3 - w2 * 0.5f;
my = (h - h2) * 0.5f + y;
glBindTexture(GL_TEXTURE_2D, tex->tex[t]);
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
glBegin(GL_QUADS);
if (this->colour.a) glColor4f(colour.r, colour.g, colour.b, colour.a);
glTexCoord2f(0.0, 0.0);
@@ -121,7 +121,7 @@ float VSlider::GetNewValue(int x, int y)
return (y2 + h2 - y) * (max - min) / h2 + min;
}
void VSlider::OnPaint() const
void VSlider::OnPaint(const PUi *pui) const
{
float m = (value - min) / (max - min);
@@ -132,8 +132,8 @@ void VSlider::OnPaint() const
glEnable(GL_TEXTURE_2D);
int t = big ? TEX_TROUGH1 : TEX_TROUGH1;
int w2 = tex->w[t];
int h2 = tex->h[t];
int w2 = pui->w[t];
int h2 = pui->h[t];
int mx, my;
mx = (w - w2) * 0.5f + x;
my = (h - h2) * 0.5f + y;
@@ -141,7 +141,7 @@ void VSlider::OnPaint() const
int cut = big ? trough2_cut : trough1_cut;
float fc = (float)cut / h2;
glBindTexture(GL_TEXTURE_2D, tex->tex[t]);
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
@@ -187,14 +187,14 @@ void VSlider::OnPaint() const
} else {
t = active ? TEX_SLIDER1_PRE : TEX_SLIDER1;
}
w2 = tex->w[t];
h2 = tex->h[t];
w2 = pui->w[t];
h2 = pui->h[t];
int y3 = this->y + pad;
int h3 = this->h - pad - pad;
mx = (w - w2) * 0.5f + x;
my = h3 - h3 * m + y3 - h2 * 0.5f;
glBindTexture(GL_TEXTURE_2D, tex->tex[t]);
glBindTexture(GL_TEXTURE_2D, pui->tex[t]);
glBegin(GL_QUADS);
if (this->colour.a) glColor4f(colour.r, colour.g, colour.b, colour.a);
glTexCoord2f(0.0, 0.0);

View File

@@ -9,13 +9,13 @@ struct Slider : Widget {
struct HSlider : Slider {
/* virtual */ float GetNewValue(int x, int y);
/* virtual */ void OnPaint() const;
/* virtual */ void OnPaint(const PUi *pui) const;
};
struct VSlider : Slider {
/* virtual */ float GetNewValue(int x, int y);
/* virtual */ void OnPaint() const;
/* virtual */ void OnPaint(const PUi *pui) const;
};
#endif /* SLIDER_H */

View File

@@ -22,7 +22,7 @@ void Widget::Pad(int xpad, int ypad)
this->h -= ypad + ypad;
}
void Frame::OnPaint() const
void Frame::OnPaint(const PUi *pui) const
{
glBegin(GL_QUADS);
glColor4f(colour.r, colour.g, colour.b, colour.a);

View File

@@ -24,9 +24,10 @@ struct Colour {
Colour(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {}
};
struct Widget : Rect {
const PTextures *tex;
/* Forward declaration of PUi for OnPaint() member */
struct PUi;
struct Widget : Rect {
uint32_t port;
float min;
float max;
@@ -43,7 +44,7 @@ struct Widget : Rect {
virtual float GetNewValue(int x, int y) { return this->value; }
virtual bool SetValue(float newvalue);
virtual void OnPaint() const {}
virtual void OnPaint(const PUi *pui) const {}
void Pad(int xpad, int ypad);
};
@@ -51,11 +52,7 @@ struct Widget : Rect {
struct Frame : Widget {
Colour colour;
/* virtual */ void OnPaint() const;
};
struct Label : Widget {
char *text;
/* virtual */ void OnPaint(const PUi *pui) const;
};
#endif /* WIDGET_H */