2014-11-12 21:55:11 -05:00
|
|
|
#include "ScopeCanvas.h"
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild the library"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "CubicSDR.h"
|
|
|
|
#include "CubicSDRDefs.h"
|
|
|
|
#include "AppFrame.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint)
|
|
|
|
EVT_KEY_DOWN(ScopeCanvas::OnKeyDown)
|
|
|
|
EVT_IDLE(ScopeCanvas::OnIdle)
|
|
|
|
wxEND_EVENT_TABLE()
|
|
|
|
|
|
|
|
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) :
|
|
|
|
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
|
2014-11-16 23:20:48 -05:00
|
|
|
wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0) {
|
2014-11-12 21:55:11 -05:00
|
|
|
|
|
|
|
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
|
2014-11-16 23:20:48 -05:00
|
|
|
timer.start();
|
2014-11-12 21:55:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopeCanvas::~ScopeCanvas() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
void ScopeCanvas::setWaveformPoints(std::vector<float> &waveform_points_in) {
|
|
|
|
waveform_points = waveform_points_in;
|
|
|
|
}
|
|
|
|
|
2014-11-12 21:55:11 -05:00
|
|
|
void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
const wxSize ClientSize = GetClientSize();
|
|
|
|
|
|
|
|
glContext->SetCurrent(*this);
|
|
|
|
glViewport(0, 0, ClientSize.x, ClientSize.y);
|
|
|
|
|
2014-11-15 23:41:41 -05:00
|
|
|
glContext->Plot(waveform_points);
|
2014-11-12 21:55:11 -05:00
|
|
|
|
|
|
|
SwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeCanvas::OnKeyDown(wxKeyEvent& event) {
|
|
|
|
float angle = 5.0;
|
|
|
|
|
|
|
|
unsigned int freq;
|
|
|
|
switch (event.GetKeyCode()) {
|
|
|
|
case WXK_RIGHT:
|
2014-11-23 19:39:27 -05:00
|
|
|
freq = wxGetApp().getFrequency();
|
2014-11-12 21:55:11 -05:00
|
|
|
freq += 100000;
|
2014-11-23 19:39:27 -05:00
|
|
|
wxGetApp().setFrequency(freq);
|
2014-11-25 00:35:06 -05:00
|
|
|
((wxFrame*)parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"),freq));
|
|
|
|
break;
|
2014-11-12 21:55:11 -05:00
|
|
|
case WXK_LEFT:
|
2014-11-23 20:02:48 -05:00
|
|
|
freq = wxGetApp().getFrequency();
|
2014-11-12 21:55:11 -05:00
|
|
|
freq -= 100000;
|
2014-11-23 19:39:27 -05:00
|
|
|
wxGetApp().setFrequency(freq);
|
2014-11-25 00:35:06 -05:00
|
|
|
((wxFrame*)parent)->GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"),freq));
|
2014-11-12 21:55:11 -05:00
|
|
|
break;
|
|
|
|
case WXK_DOWN:
|
|
|
|
break;
|
|
|
|
case WXK_UP:
|
|
|
|
break;
|
|
|
|
case WXK_SPACE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeCanvas::OnIdle(wxIdleEvent &event) {
|
2014-11-21 00:49:41 -05:00
|
|
|
// timer.update();
|
|
|
|
// frameTimer += timer.lastUpdateSeconds();
|
|
|
|
// if (frameTimer > 1.0/30.0) {
|
2014-11-16 23:20:48 -05:00
|
|
|
Refresh(false);
|
2014-11-21 00:49:41 -05:00
|
|
|
// frameTimer = 0;
|
|
|
|
// }
|
2014-11-12 21:55:11 -05:00
|
|
|
}
|