Test of draggable scope area + fixes

- Will be able to drag back/forth to cycle scope/spectrum/plot
- Fix for two crashes
This commit is contained in:
Charles J. Cliffe
2015-08-19 23:22:46 -04:00
parent 03c8619c5a
commit 7a0f523eaf
8 changed files with 161 additions and 18 deletions
+102 -6
View File
@@ -14,18 +14,28 @@
#include "CubicSDRDefs.h"
#include "AppFrame.h"
#include <algorithm>
#include <cmath>
wxBEGIN_EVENT_TABLE(ScopeCanvas, wxGLCanvas) EVT_PAINT(ScopeCanvas::OnPaint)
EVT_IDLE(ScopeCanvas::OnIdle)
EVT_MOTION(ScopeCanvas::OnMouseMoved)
EVT_LEFT_DOWN(ScopeCanvas::OnMouseDown)
EVT_LEFT_UP(ScopeCanvas::OnMouseReleased)
EVT_RIGHT_DOWN(ScopeCanvas::OnMouseRightDown)
EVT_RIGHT_UP(ScopeCanvas::OnMouseRightReleased)
EVT_LEAVE_WINDOW(ScopeCanvas::OnMouseLeftWindow)
EVT_ENTER_WINDOW(ScopeCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), stereo(false), ppmMode(false) {
ScopeCanvas::ScopeCanvas(wxWindow *parent, int *attribList) : InteractiveCanvas(parent, attribList), stereo(false), ppmMode(false), ctr(0), ctrTarget(0), dragAccel(0) {
glContext = new ScopeContext(this, &wxGetApp().GetContext(this));
inputData.set_max_num_items(1);
bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_Y);
bgPanel.setSize(1.0, 0.5);
bgPanel.setPosition(0.0, -0.5);
panelSpacing = 0.2;
}
ScopeCanvas::~ScopeCanvas() {
@@ -71,21 +81,74 @@ void ScopeCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
initGLExtensions();
glViewport(0, 0, ClientSize.x, ClientSize.y);
glContext->DrawBegin();
bgPanel.setFillColor(ThemeMgr::mgr.currentTheme->scopeBackground * 3.0, RGBA4f(0,0,0,0));
bgPanel.calcTransform(CubicVR::mat4::identity());
bgPanel.draw();
scopePanel.setMode(stereo?ScopePanel::SCOPE_MODE_2Y:ScopePanel::SCOPE_MODE_Y);
scopePanel.calcTransform(CubicVR::mat4::identity());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glLoadMatrixf(CubicVR::mat4::perspective(45.0, 1.0, 1.0, 1000.0));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
CubicVR::mat4 modelView = CubicVR::mat4::lookat(0, 0, -1.2, 0, 0, 0, 0, -1, 0);
float panelWidth = 1.0;
float panelInterval = (panelWidth * 2.0 + panelSpacing);
if (!mouseTracker.mouseDown()) {
if (!dragAccel) {
ctrTarget = round(ctr / panelInterval);
if (ctrTarget < -1.0) {
ctrTarget = -1.0;
} else if (ctrTarget > 0.0) {
ctrTarget = 0.0;
}
ctrTarget *= panelInterval;
if (ctr != ctrTarget) {
ctr += (ctrTarget-ctr)*0.2;
}
} else {
dragAccel -= dragAccel * 0.01;
if (abs(dragAccel) < 0.1 || ctr < ctrTarget-panelInterval/2.0 || ctr > ctrTarget+panelInterval/2.0 ) {
dragAccel = 0;
} else {
ctr += dragAccel;
}
}
}
scopePanel.setPosition(ctr, 0);
float roty = atan2(scopePanel.pos[0],1.2);
scopePanel.rot[1] = -(roty * (180.0 / M_PI));
scopePanel.calcTransform(modelView);
scopePanel.draw();
scopePanel.setPosition(panelInterval+ctr, 0);
roty = atan2(scopePanel.pos[0],1.2);
scopePanel.rot[1] = -(roty * (180.0 / M_PI));
scopePanel.calcTransform(modelView);
scopePanel.draw();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glContext->DrawTunerTitles(ppmMode);
if (!deviceName.empty()) {
glContext->DrawDeviceName(deviceName);
}
glContext->DrawEnd();
SwapBuffers();
}
void ScopeCanvas::OnIdle(wxIdleEvent &event) {
Refresh();
event.RequestMore();
@@ -94,3 +157,36 @@ void ScopeCanvas::OnIdle(wxIdleEvent &event) {
ScopeRenderDataQueue *ScopeCanvas::getInputQueue() {
return &inputData;
}
void ScopeCanvas::OnMouseMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseMoved(event);
if (mouseTracker.mouseDown()) {
dragAccel = 4.0*mouseTracker.getDeltaMouseX();
ctr += dragAccel;
}
}
void ScopeCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
}
void ScopeCanvas::OnMouseDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseDown(event);
}
void ScopeCanvas::OnMouseReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseReleased(event);
}
void ScopeCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseEnterWindow(event);
}
void ScopeCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event);
}
+13 -1
View File
@@ -10,8 +10,9 @@
#include "ScopeVisualProcessor.h"
#include "ScopePanel.h"
#include "fftw3.h"
#include "InteractiveCanvas.h"
class ScopeCanvas: public wxGLCanvas {
class ScopeCanvas: public InteractiveCanvas {
public:
ScopeCanvas(wxWindow *parent, int *attribList = NULL);
~ScopeCanvas();
@@ -26,13 +27,24 @@ public:
private:
void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent &event);
void OnMouseMoved(wxMouseEvent& event);
void OnMouseWheelMoved(wxMouseEvent& event);
void OnMouseDown(wxMouseEvent& event);
void OnMouseReleased(wxMouseEvent& event);
void OnMouseEnterWindow(wxMouseEvent& event);
void OnMouseLeftWindow(wxMouseEvent& event);
ScopeRenderDataQueue inputData;
ScopePanel scopePanel;
GLPanel bgPanel;
ScopeContext *glContext;
std::string deviceName;
bool stereo;
bool ppmMode;
float panelSpacing;
float ctr;
float ctrTarget;
float dragAccel;
// event table
wxDECLARE_EVENT_TABLE();
};