From ebf2443fe2adfbfeb4c1a396280712a1f3b32959 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 7 Jul 2016 22:37:57 -0400 Subject: [PATCH] Gain UI working (minus mousewheel) --- src/AppFrame.cpp | 2 +- src/AppFrame.h | 4 +- src/panel/MeterPanel.cpp | 34 +++-- src/panel/MeterPanel.h | 7 +- src/visual/GainCanvas.cpp | 257 +++++++++++--------------------------- src/visual/GainCanvas.h | 26 ++-- 6 files changed, 117 insertions(+), 213 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index f764084..beb8761 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -309,7 +309,7 @@ AppFrame::AppFrame() : waterfallCanvas->attachSpectrumCanvas(spectrumCanvas); spectrumCanvas->attachWaterfallCanvas(waterfallCanvas); -/* */ +/* * / vbox->AddSpacer(1); testCanvas = new UITestCanvas(this, attribList); vbox->Add(testCanvas, 20, wxEXPAND | wxALL, 0); diff --git a/src/AppFrame.h b/src/AppFrame.h index 96db6e3..5c9774b 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -17,7 +17,7 @@ #include "FFTVisualDataThread.h" #include "SDRDeviceInfo.h" #include "ModemProperties.h" -#include "UITestCanvas.h" +//#include "UITestCanvas.h" #include "FrequencyDialog.h" #include @@ -122,7 +122,7 @@ private: MeterCanvas *demodSignalMeter; MeterCanvas *demodGainMeter; TuningCanvas *demodTuner; - UITestCanvas *testCanvas; +// UITestCanvas *testCanvas; MeterCanvas *spectrumAvgMeter; MeterCanvas *waterfallSpeedMeter; ModeSelectorCanvas *demodMuteButton, *peakHoldButton, *soloModeButton, *deltaLockButton; diff --git a/src/panel/MeterPanel.cpp b/src/panel/MeterPanel.cpp index cf8d10d..dfeb8c1 100644 --- a/src/panel/MeterPanel.cpp +++ b/src/panel/MeterPanel.cpp @@ -56,10 +56,19 @@ MeterPanel::MeterPanel(std::string name, float low, float high, float current) { addChild(&valuePanel); } +MeterPanel::~MeterPanel() { + +} + + void MeterPanel::setName(std::string name_in) { name = name_in; } +std::string MeterPanel::getName() { + return name; +} + void MeterPanel::setRange(float low, float high) { this->low = low; this->high = high; @@ -73,7 +82,7 @@ void MeterPanel::setValue(float value) { value = low; } - current = low + (value * (high-low)); + current = value; setValueLabel(std::to_string(int(current))); setPanelLevel(value, levelPanel); } @@ -86,12 +95,11 @@ void MeterPanel::setHighlight(float value) { value = low; } - if (value == 0) { - highlightPanel.visible = false; - } else { - setPanelLevel(value, highlightPanel); - highlightPanel.visible = true; - } + setPanelLevel(value, highlightPanel); +} + +void MeterPanel::setHighlightVisible(bool vis) { + highlightPanel.visible = vis; } float MeterPanel::getValue() { @@ -112,7 +120,7 @@ float MeterPanel::getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel) { CubicVR::vec2 hitResult; if (bgPanel.hitTest(mousePoint, hitResult)) { - float hitLevel = hitResult.y; + float hitLevel = ((hitResult.y + 1.0) * 0.5); if (hitLevel < 0.0f) { hitLevel = 0.0f; @@ -145,7 +153,7 @@ void MeterPanel::drawPanelContents() { float labelPad = 8.0f; if (viewHeight > 400.0f) { - labelHeight *= 2.0f; + labelHeight = 32.0f; } float pScale = (1.0f/viewHeight); @@ -187,3 +195,11 @@ void MeterPanel::setPanelLevel(float setValue, GLPanel &panel) { panel.setSize(1.0, valueNorm); panel.setPosition(0.0, (-1.0+(valueNorm))); } + +bool MeterPanel::getChanged() { + return changed; +} + +void MeterPanel::setChanged(bool changed) { + this->changed = changed; +} diff --git a/src/panel/MeterPanel.h b/src/panel/MeterPanel.h index 188eeb3..40c9590 100644 --- a/src/panel/MeterPanel.h +++ b/src/panel/MeterPanel.h @@ -6,13 +6,18 @@ class MeterPanel : public GLPanel { public: MeterPanel(std::string name, float low, float high, float current); + ~MeterPanel(); void setName(std::string name_in); + std::string getName(); void setRange(float low, float high); void setValue(float value); void setHighlight(float value); + void setHighlightVisible(bool vis); float getValue(); bool isMeterHit(CubicVR::vec2 mousePoint); float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel); + void setChanged(bool changed); + bool getChanged(); protected: void drawPanelContents(); @@ -22,7 +27,7 @@ protected: private: std::string name; float low, high, current; - GLPanel panel; + bool changed; GLPanel bgPanel; GLPanel levelPanel; GLPanel highlightPanel; diff --git a/src/visual/GainCanvas.cpp b/src/visual/GainCanvas.cpp index b482771..27c30d6 100644 --- a/src/visual/GainCanvas.cpp +++ b/src/visual/GainCanvas.cpp @@ -53,20 +53,8 @@ void GainCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glViewport(0, 0, ClientSize.x, ClientSize.y); - float i = 0; - for (std::vector::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - GainInfo *gInfo = (*gi); - float midPos = -1.0+startPos+spacing*i; - - gInfo->labelPanel.setSize(spacing/2.0,(14.0/float(ClientSize.y))); - gInfo->labelPanel.setPosition(midPos, -barHeight-(20.0/float(ClientSize.y))); - - gInfo->valuePanel.setSize(spacing/2.0,(14.0/float(ClientSize.y))); - gInfo->valuePanel.setPosition(midPos, barHeight+(20.0/float(ClientSize.y))); - - i+=1.0; - } - + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + bgPanel.draw(); SwapBuffers(); @@ -79,65 +67,44 @@ void GainCanvas::OnIdle(wxIdleEvent &event) { event.Skip(); } - for (std::vector::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - GainInfo *gInfo = (*gi); - if (gInfo->changed) { - wxGetApp().setGain(gInfo->name, gInfo->current); - gInfo->changed = false; + for (auto gi : gainPanels) { + if (gi->getChanged()) { + wxGetApp().setGain(gi->getName(), gi->getValue()); + gi->setChanged(false); } } } -int GainCanvas::GetPanelHit(CubicVR::vec2 &result) { - std::vector::iterator gi; - - int i = 0; - for (gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - GainInfo *gInfo = (*gi); - - CubicVR::vec2 hitResult; - if (gInfo->panel.hitTest(mouseTracker.getGLXY(), hitResult)) { -// std::cout << "Hit #" << i << " result: " << hitResult << std::endl; - result = (hitResult + CubicVR::vec2(1.0,1.0)) * 0.5; - return i; - } - i++; - } - return -1; -} - - void GainCanvas::SetLevel() { - CubicVR::vec2 hitResult; - int panelHit = GetPanelHit(hitResult); + CubicVR::vec2 mpos = mouseTracker.getGLXY(); - if (panelHit >= 0) { - gainInfo[panelHit]->levelPanel.setSize(1.0, hitResult.y); - gainInfo[panelHit]->levelPanel.setPosition(0.0, (-1.0+(hitResult.y))); - gainInfo[panelHit]->current = round(gainInfo[panelHit]->low+(hitResult.y * (gainInfo[panelHit]->high-gainInfo[panelHit]->low))); - gainInfo[panelHit]->changed = true; - gainInfo[panelHit]->valuePanel.setText(std::to_string(int(gainInfo[panelHit]->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); + for (auto gi : gainPanels) { + if (gi->isMeterHit(mpos)) { + float value = gi->getMeterHitValue(mpos, *gi); + + gi->setValue(value); + gi->setChanged(true); + + break; + } } } void GainCanvas::OnMouseMoved(wxMouseEvent& event) { InteractiveCanvas::OnMouseMoved(event); - CubicVR::vec2 hitResult; - int panelHit = GetPanelHit(hitResult); + CubicVR::vec2 mpos = mouseTracker.getGLXY(); - if (panelHit >= 0) { - gainInfo[panelHit]->highlightPanel.setSize(1.0, hitResult.y); - gainInfo[panelHit]->highlightPanel.setPosition(0.0, (-1.0+(hitResult.y))); - } - - int i = 0; - for (std::vector::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - (*gi)->highlightPanel.visible = (i==panelHit); - if (i==panelHit) { - wxGetApp().setActiveGainEntry((*gi)->name); + for (auto gi : gainPanels) { + if (gi->isMeterHit(mpos)) { + float value = gi->getMeterHitValue(mpos, *gi); + + gi->setHighlight(value); + gi->setHighlightVisible(true); + wxGetApp().setActiveGainEntry(gi->getName()); + } else { + gi->setHighlightVisible(false); } - i++; } if (mouseTracker.mouseDown()) { @@ -154,33 +121,33 @@ void GainCanvas::OnMouseWheelMoved(wxMouseEvent& event) { InteractiveCanvas::OnMouseWheelMoved(event); CubicVR::vec2 hitResult; - int panelHit = GetPanelHit(hitResult); - - if (panelHit >= 0) { - float movement = 3.0 * (float)event.GetWheelRotation(); - - GainInfo *gInfo; - - gInfo = gainInfo[panelHit]; - - gInfo->current = gInfo->current + ((movement / 100.0) * ((gInfo->high - gInfo->low) / 100.0)); - - //BEGIN Clamp to prevent the meter to escape - if (gInfo->current > gInfo->high) { - gInfo->current = gInfo->high; - } - if (gInfo->current < gInfo->low) { - gInfo->current = gInfo->low; - } - - gInfo->changed = true; - - float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low); - gInfo->levelPanel.setSize(1.0, levelVal); - gInfo->levelPanel.setPosition(0.0, levelVal-1.0); - - gInfo->valuePanel.setText(std::to_string(int(gInfo->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); - } +// int panelHit = GetPanelHit(hitResult); +// +// if (panelHit >= 0) { +// float movement = 3.0 * (float)event.GetWheelRotation(); +// +// GainInfo *gInfo; +// +// gInfo = gainInfo[panelHit]; +// +// gInfo->current = gInfo->current + ((movement / 100.0) * ((gInfo->high - gInfo->low) / 100.0)); +// +// //BEGIN Clamp to prevent the meter to escape +// if (gInfo->current > gInfo->high) { +// gInfo->current = gInfo->high; +// } +// if (gInfo->current < gInfo->low) { +// gInfo->current = gInfo->low; +// } +// +// gInfo->changed = true; +// +// float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low); +// gInfo->levelPanel.setSize(1.0, levelVal); +// gInfo->levelPanel.setPosition(0.0, levelVal-1.0); +// +// gInfo->valuePanel.setText(std::to_string(int(gInfo->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); +// } } @@ -191,12 +158,11 @@ void GainCanvas::OnMouseReleased(wxMouseEvent& event) { void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) { InteractiveCanvas::OnMouseLeftWindow(event); SetCursor(wxCURSOR_CROSS); - - int i = 0; - for (std::vector::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - (*gi)->highlightPanel.visible = false; - i++; + + for (auto gi : gainPanels) { + gi->setHighlightVisible(false); } + Refresh(); } @@ -217,8 +183,6 @@ void GainCanvas::setHelpTip(std::string tip) { } void GainCanvas::updateGainUI() { - const wxSize ClientSize = GetClientSize(); - SDRDeviceInfo *devInfo = wxGetApp().getDevice(); DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(devInfo->getDeviceId()); @@ -235,77 +199,24 @@ void GainCanvas::updateGainUI() { spacing = 2.0/numGains; barWidth = (1.0/numGains)*0.7; startPos = spacing/2.0; - barHeight = 0.8f; + barHeight = 1.0f; - RGBA4f c1, c2; - - while (gainInfo.size()) { - GainInfo *giDel; - giDel = gainInfo.back(); - gainInfo.pop_back(); - - giDel->panel.removeChild(&giDel->levelPanel); - bgPanel.removeChild(&(giDel->labelPanel)); - bgPanel.removeChild(&(giDel->valuePanel)); - bgPanel.removeChild(&(giDel->panel)); - delete giDel; + while (gainPanels.size()) { + MeterPanel *mDel = gainPanels.back(); + gainPanels.pop_back(); + bgPanel.removeChild(mDel); + delete mDel; } - for (gi = gains.begin(); gi != gains.end(); gi++) { - GainInfo *gInfo = new GainInfo; + for (auto gi : gains) { + MeterPanel *mPanel = new MeterPanel(gi.first, gi.second.minimum(), gi.second.maximum(), devConfig->getGain(gi.first,wxGetApp().getGain(gi.first))); + float midPos = -1.0+startPos+spacing*i; + mPanel->setPosition(midPos, 0); + mPanel->setSize(barWidth, barHeight); + bgPanel.addChild(mPanel); - gInfo->name = gi->first; - gInfo->low = gi->second.minimum(); - gInfo->high = gi->second.maximum(); - gInfo->current = devConfig->getGain(gInfo->name,wxGetApp().getGain(gInfo->name)); - gInfo->changed = false; - - gInfo->panel.setBorderPx(1); - gInfo->panel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); - gInfo->panel.setPosition(midPos, 0); - gInfo->panel.setSize(barWidth, barHeight); - gInfo->panel.setBlend(GL_ONE, GL_ONE); - - gInfo->levelPanel.setBorderPx(0); - gInfo->levelPanel.setMarginPx(1); - gInfo->levelPanel.setSize(1.0,0.8f); - float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low); - gInfo->levelPanel.setSize(1.0, levelVal); - gInfo->levelPanel.setPosition(0.0, (-1.0+(levelVal))); - gInfo->levelPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); - gInfo->levelPanel.setBlend(GL_ONE, GL_ONE); - - gInfo->panel.addChild(&gInfo->levelPanel); - - gInfo->highlightPanel.setBorderPx(0); - gInfo->highlightPanel.setMarginPx(1); - gInfo->highlightPanel.setSize(1.0,0.8f); - gInfo->highlightPanel.setPosition(0.0,-0.2f); - gInfo->highlightPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); - gInfo->highlightPanel.setBlend(GL_ONE, GL_ONE); - gInfo->highlightPanel.visible = false; - - gInfo->panel.addChild(&gInfo->highlightPanel); - - gInfo->labelPanel.setSize(spacing/2.0,(14.0/float(ClientSize.y))); - gInfo->labelPanel.setPosition(midPos, -barHeight-(20.0/float(ClientSize.y))); - - gInfo->labelPanel.setText(gi->first,GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); - gInfo->labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE); - - bgPanel.addChild(&(gInfo->labelPanel)); - - gInfo->valuePanel.setSize(spacing/2.0,(14.0/float(ClientSize.y))); - gInfo->valuePanel.setPosition(midPos, barHeight+(20.0/float(ClientSize.y))); - - gInfo->valuePanel.setText(std::to_string(int(gInfo->current)), GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); - gInfo->valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE); - - bgPanel.addChild(&(gInfo->valuePanel)); - - bgPanel.addChild(&(gInfo->panel)); - gainInfo.push_back(gInfo); + gainPanels.push_back(mPanel); i++; } @@ -313,34 +224,6 @@ void GainCanvas::updateGainUI() { } void GainCanvas::setThemeColors() { - std::vector::iterator gi; - - RGBA4f c1, c2; - - c1 = ThemeMgr::mgr.currentTheme->generalBackground; - c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5; - - bgPanel.setFillColor(c1, c2); - - for (gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { - GainInfo *gInfo = (*gi); - - c1 = ThemeMgr::mgr.currentTheme->generalBackground; - c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5; - c1.a = 1.0; - c2.a = 1.0; - gInfo->panel.setFillColor(c1, c2); - - c1 = ThemeMgr::mgr.currentTheme->meterLevel * 0.5; - c2 = ThemeMgr::mgr.currentTheme->meterLevel; - c1.a = 1.0; - c2.a = 1.0; - gInfo->levelPanel.setFillColor(c1, c2); - - c1 = RGBA4f(0.3f,0.3f,0.3f,1.0f); - c2 = RGBA4f(0.65f,0.65f,0.65f,1.0f);; - gInfo->highlightPanel.setFillColor(c1, c2); - } Refresh(); } diff --git a/src/visual/GainCanvas.h b/src/visual/GainCanvas.h index 67d7624..1e8266d 100644 --- a/src/visual/GainCanvas.h +++ b/src/visual/GainCanvas.h @@ -14,17 +14,17 @@ #include "Timer.h" #include "MeterPanel.h" -class GainInfo { -public: - std::string name; - float low, high, current; - bool changed; - GLPanel panel; - GLPanel levelPanel; - GLPanel highlightPanel; - GLTextPanel labelPanel; - GLTextPanel valuePanel; -}; +//class GainInfo { +//public: +// std::string name; +// float low, high, current; +// bool changed; +// GLPanel panel; +// GLPanel levelPanel; +// GLPanel highlightPanel; +// GLTextPanel labelPanel; +// GLTextPanel valuePanel; +//}; class GainCanvas: public InteractiveCanvas { public: @@ -39,7 +39,7 @@ private: void OnPaint(wxPaintEvent& event); void OnIdle(wxIdleEvent &event); - int GetPanelHit(CubicVR::vec2 &result); +// int GetPanelHit(CubicVR::vec2 &result); void SetLevel(); void OnShow(wxShowEvent& event); @@ -52,7 +52,7 @@ private: PrimaryGLContext *glContext; std::string helpTip; - std::vector gainInfo; +// std::vector gainInfo; std::vector gainPanels; GLPanel bgPanel; SDRRangeMap gains;