Skip to content

Commit

Permalink
make the fft refresh trigger at every resize
Browse files Browse the repository at this point in the history
  • Loading branch information
laochailan committed Sep 4, 2015
1 parent d197ffe commit e79b483
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/FFTView.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FFTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
4 changes: 3 additions & 1 deletion src/widgets/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}

Expand Down
10 changes: 10 additions & 0 deletions src/widgets/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -231,6 +238,9 @@ void Widget::advance() {
void Widget::resizeEvent(ResizeEvent *event) {
}

void Widget::glResetEvent() {
}

void Widget::paintEvent() {
}

Expand Down
2 changes: 2 additions & 0 deletions src/widgets/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit e79b483

Please sign in to comment.