From e79b483c44e69b3e97719311aeb43f17ed28ef03 Mon Sep 17 00:00:00 2001 From: laochailan Date: Fri, 4 Sep 2015 11:22:13 +0200 Subject: [PATCH] make the fft refresh trigger at every resize --- src/FFTView.cpp | 8 +++++--- src/FFTView.h | 2 +- src/widgets/Application.cpp | 4 +++- src/widgets/Widget.cpp | 10 ++++++++++ src/widgets/Widget.h | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/FFTView.cpp b/src/FFTView.cpp index 48e0027..1322cf7 100644 --- a/src/FFTView.cpp +++ b/src/FFTView.cpp @@ -1,5 +1,6 @@ #include "FFTView.h" #include "AudioView.h" +#include "Log.h" #include "engine/RecordingManager.h" #include "engine/FFTBackend.h" #include "widgets/Application.h" @@ -60,7 +61,7 @@ static void val2hue(uint8_t *p, double val) { } FFTView::FFTView(AudioView &av, RecordingManager &manager, Widget *parent) : Widget(parent), _active(0), - _startTime(-2000), _manager(manager), _av(av) + _startTime(-2000), _manager(manager), _av(av),_ffttex(0) { setSizeHint(Widgets::Size()); setSizePolicy(Widgets::SizePolicy(Widgets::SizePolicy::Expanding, Widgets::SizePolicy::Fixed)); @@ -170,8 +171,9 @@ void FFTView::paintEvent() { drawScale(); } -void FFTView::resizeEvent(Widgets::ResizeEvent *event) { - glDeleteTextures(1, &_ffttex); +void FFTView::glResetEvent() { + if(_ffttex != 0) + glDeleteTextures(1, &_ffttex); init_texture(_ffttex); update(1); } diff --git a/src/FFTView.h b/src/FFTView.h index 6e8e6da..34ef7ad 100644 --- a/src/FFTView.h +++ b/src/FFTView.h @@ -59,7 +59,7 @@ class FFTView : public Widgets::Widget { void drawScale() const; void initTextures(); void paintEvent(); - void resizeEvent(Widgets::ResizeEvent *event); + void glResetEvent(); void advance(); }; diff --git a/src/widgets/Application.cpp b/src/widgets/Application.cpp index 530bfe1..7eb08f0 100644 --- a/src/widgets/Application.cpp +++ b/src/widgets/Application.cpp @@ -352,8 +352,10 @@ void Application::createWindow(int w, int h) { glBindTexture(GL_TEXTURE_2D, 0); - for(WidgetList::iterator it = _windowStack.begin(); it != _windowStack.end(); it++) + for(WidgetList::iterator it = _windowStack.begin(); it != _windowStack.end(); it++) { (*it)->setSize(Size(std::max(MIN_WINDOW_W,w), std::max(MIN_WINDOW_H,h))); + (*it)->_DoGlResetEvents(); + } } diff --git a/src/widgets/Widget.cpp b/src/widgets/Widget.cpp index 4f7ad36..8135a96 100644 --- a/src/widgets/Widget.cpp +++ b/src/widgets/Widget.cpp @@ -166,6 +166,13 @@ void Widget::_DoPaintEvents(const Point &offset, const Rect &clipRect) { } +void Widget::_DoGlResetEvents() { + glResetEvent(); + for(WidgetVector::iterator it = _children.begin(); it != _children.end(); ++it) + (*it)->_DoGlResetEvents(); +} + + Point Widget::mapToParent(const Point &point) const { Point result = point; if (parentWidget()) @@ -231,6 +238,9 @@ void Widget::advance() { void Widget::resizeEvent(ResizeEvent *event) { } +void Widget::glResetEvent() { +} + void Widget::paintEvent() { } diff --git a/src/widgets/Widget.h b/src/widgets/Widget.h index 73464e6..899aa85 100644 --- a/src/widgets/Widget.h +++ b/src/widgets/Widget.h @@ -74,6 +74,7 @@ class Widget : public sigslot::has_slots<> virtual void advance(); virtual void resizeEvent(ResizeEvent *event); + virtual void glResetEvent(); // happens when the GL context is reset. textures have to be reloaded in that case. virtual void paintEvent(); virtual void enterEvent(); virtual void leaveEvent(); @@ -84,6 +85,7 @@ class Widget : public sigslot::has_slots<> virtual void mouseMotionEvent(MouseEvent *event); void _DoPaintEvents(const Point &offset, const Rect &clipRect); + void _DoGlResetEvents(); void _CallAdvance(); private: Widget *_parentWidget;