From 35a44308d9e9409ee24c43c9af1f870b43051705 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 3 Feb 2013 20:11:09 +0000 Subject: [PATCH] Pass PUi object as parameter of OnPaint instead of requiring to be during widget creation. --- ptap/ptapui.cpp | 5 ----- pui/container.cpp | 12 ++++++------ pui/container.h | 2 +- pui/knob.cpp | 8 ++++---- pui/knob.h | 2 +- pui/pui.cpp | 2 +- pui/slider.cpp | 28 ++++++++++++++-------------- pui/slider.h | 4 ++-- pui/widget.cpp | 2 +- pui/widget.h | 13 +++++-------- 10 files changed, 35 insertions(+), 43 deletions(-) diff --git a/ptap/ptapui.cpp b/ptap/ptapui.cpp index 4069551..f28b173 100644 --- a/ptap/ptapui.cpp +++ b/ptap/ptapui.cpp @@ -54,7 +54,6 @@ void PTapUI::InitWidgets() scale = 1.0f; widget = new Container(); - widget->tex = this; widget->back = true; widget->colour = Colour(1, 1, 1, 1); widget->w = this->width * scale; @@ -115,7 +114,6 @@ void PTapUI::InitWidgets() for (int j = 0; j < TAPS; j++) { Slider *slider = new VSlider(); - slider->tex = this; slider->big = false; if (i == j) { slider->colour = Colour(.5f, .7f, 1, 1); @@ -135,7 +133,6 @@ void PTapUI::InitWidgets() for (int j = 0; j < 2; j++) { Slider *slider = new VSlider(); - slider->tex = this; slider->big = false; slider->x = c3->x + j * slide_w;//(j & 1) * slide_w; slider->y = c3->y;// + (j >> 1) * slide_h; @@ -150,7 +147,6 @@ void PTapUI::InitWidgets() for (int j = 0; j < 1; j++) { Slider *slider = new VSlider(); - slider->tex = this; slider->big = i >= TAPS; slider->colour = Colour(1, .2f, .2f, 1); slider->x = c4->x + j * slide_w;//(j & 1) * slide_w; @@ -173,7 +169,6 @@ void PTapUI::InitWidgets() c->children.push_back(c5); Knob *k = new Knob(); - k->tex = this; k->x = c5->x; k->y = c5->y; k->w = c5->w; diff --git a/pui/container.cpp b/pui/container.cpp index a97e16e..1aa8fe6 100644 --- a/pui/container.cpp +++ b/pui/container.cpp @@ -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::const_iterator it; for (it = children.begin(); it != children.end(); ++it) { - (*it)->OnPaint(); + (*it)->OnPaint(pui); } } diff --git a/pui/container.h b/pui/container.h index 4e4c66b..bad711b 100644 --- a/pui/container.h +++ b/pui/container.h @@ -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 */ diff --git a/pui/knob.cpp b/pui/knob.cpp index 2f30c8e..6cde78b 100644 --- a/pui/knob.cpp +++ b/pui/knob.cpp @@ -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); diff --git a/pui/knob.h b/pui/knob.h index 23ca0ae..6b521e7 100644 --- a/pui/knob.h +++ b/pui/knob.h @@ -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 */ diff --git a/pui/pui.cpp b/pui/pui.cpp index bf2025d..8da3331 100644 --- a/pui/pui.cpp +++ b/pui/pui.cpp @@ -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) diff --git a/pui/slider.cpp b/pui/slider.cpp index a1bbd8f..cddb235 100644 --- a/pui/slider.cpp +++ b/pui/slider.cpp @@ -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); diff --git a/pui/slider.h b/pui/slider.h index 03e8d6c..3cd8320 100644 --- a/pui/slider.h +++ b/pui/slider.h @@ -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 */ diff --git a/pui/widget.cpp b/pui/widget.cpp index 64c54e9..ac7be57 100644 --- a/pui/widget.cpp +++ b/pui/widget.cpp @@ -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); diff --git a/pui/widget.h b/pui/widget.h index 3e93394..d5c58f0 100644 --- a/pui/widget.h +++ b/pui/widget.h @@ -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 */