Can now drag tuner values

This commit is contained in:
Charles J. Cliffe 2015-01-04 19:32:51 -05:00
parent 9f945026b8
commit 482ff41382
3 changed files with 65 additions and 9 deletions

View File

@ -25,7 +25,7 @@ EVT_ENTER_WINDOW(TuningCanvas::OnMouseEnterWindow)
wxEND_EVENT_TABLE()
TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) :
InteractiveCanvas(parent, attribList) {
InteractiveCanvas(parent, attribList), dragAccum(0) {
glContext = new TuningContext(this, &wxGetApp().GetContext(this));
}
@ -46,7 +46,9 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
if (activeDemod != NULL) {
glContext->DrawDemodFreqBw(activeDemod->getFrequency(),activeDemod->getBandwidth(),wxGetApp().getFrequency());
glContext->DrawDemodFreqBw(activeDemod->getFrequency(), activeDemod->getBandwidth(), wxGetApp().getFrequency());
} else {
glContext->DrawDemodFreqBw(0, 0, wxGetApp().getFrequency());
}
glContext->DrawEnd();
@ -61,11 +63,37 @@ void TuningCanvas::OnIdle(wxIdleEvent &event) {
void TuningCanvas::OnMouseMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseMoved(event);
if (mouseTracker.mouseDown()) {
DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
float uxPos = 2.0 * (mouseTracker.getMouseX() - 0.5);
dragAccum += mouseTracker.getDeltaMouseX();
if (uxPos < -0.275 && activeDemod != NULL) {
if (abs(dragAccum * 100.0) >= 1) {
activeDemod->setFrequency(activeDemod->getFrequency() + (int) (dragAccum * 100.0));
dragAccum = 0;
}
} else if (uxPos > 0.275) {
wxGetApp().setFrequency(wxGetApp().getFrequency() + (int) (mouseTracker.getDeltaMouseX() * SRATE * 100.0));
dragAccum = 0;
} else if (activeDemod != NULL) {
if (abs(dragAccum * 100.0) >= 1) {
activeDemod->setBandwidth(activeDemod->getBandwidth() + (int) (dragAccum * 100.0));
dragAccum = 0;
}
}
}
}
void TuningCanvas::OnMouseDown(wxMouseEvent& event) {
InteractiveCanvas::OnMouseDown(event);
mouseTracker.setHorizDragLock(true);
mouseTracker.setVertDragLock(true);
dragAccum = 0;
SetCursor(wxCURSOR_IBEAM);
}
void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
@ -74,6 +102,9 @@ void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
void TuningCanvas::OnMouseReleased(wxMouseEvent& event) {
InteractiveCanvas::OnMouseReleased(event);
mouseTracker.setHorizDragLock(false);
mouseTracker.setVertDragLock(false);
SetCursor(wxCURSOR_SIZEWE);
}
void TuningCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
@ -83,7 +114,7 @@ void TuningCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
void TuningCanvas::OnMouseEnterWindow(wxMouseEvent& event) {
InteractiveCanvas::mouseTracker.OnMouseEnterWindow(event);
SetCursor(wxCURSOR_CROSS);
SetCursor(wxCURSOR_SIZEWE);
}
void TuningCanvas::setHelpTip(std::string tip) {

View File

@ -34,6 +34,7 @@ private:
TuningContext *glContext;
std::string helpTip;
float dragAccum;
//
wxDECLARE_EVENT_TABLE();
};

View File

@ -70,18 +70,42 @@ void TuningContext::DrawDemodFreqBw(long long freq, unsigned int bw, long long c
}
getFont(fontSize).drawString("Freq: ", -0.75, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
freqStr.str("");
freqStr << std::fixed << freq << "Hz";
if (bw) {
freqStr.str("");
freqStr << std::fixed << freq << "Hz";
} else {
freqStr.str("---");
}
getFont(fontSize).drawString(freqStr.str(), -0.75, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
glColor3f(0.65, 0.65, 0.65);
glBegin(GL_LINES);
glVertex2f(-0.275, -1.0);
glVertex2f(-0.275, 1.0);
glEnd();
getFont(fontSize).drawString("BW: ", -0.10, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
freqStr.str("");
freqStr << std::fixed << bw << "Hz";
if (bw) {
freqStr.str("");
freqStr << std::fixed << bw << "Hz";
} else {
freqStr.str("---");
}
getFont(fontSize).drawString(freqStr.str(), -0.10, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
glColor3f(0.65, 0.65, 0.65);
glBegin(GL_LINES);
glVertex2f(0.275, -1.0);
glVertex2f(0.275, 1.0);
glEnd();
getFont(fontSize).drawString("CTR: ", 0.50, 0, fontHeight, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
freqStr.str("");
freqStr << std::fixed << center << "Hz";
if (center) {
freqStr.str("");
freqStr << std::fixed << center << "Hz";
} else {
freqStr.str("---");
}
getFont(fontSize).drawString(freqStr.str(), 0.50, 0, fontHeight, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
}