From a87c58c4a83bcfb91f1bbcb42793ff2099c06138 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Sun, 3 Jul 2016 20:59:49 -0400 Subject: [PATCH 1/4] Initial Meter Panel work --- CMakeLists.txt | 2 + src/panel/MeterPanel.cpp | 0 src/panel/MeterPanel.h | 153 ++++++++++++++++++++++++++++++++++++++ src/util/MouseTracker.cpp | 4 + src/util/MouseTracker.h | 2 + src/visual/GainCanvas.cpp | 2 +- src/visual/GainCanvas.h | 2 + 7 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/panel/MeterPanel.cpp create mode 100644 src/panel/MeterPanel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 22f1e66..386d1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,6 +304,8 @@ SET (cubicsdr_sources src/panel/ScopePanel.cpp src/panel/SpectrumPanel.cpp src/panel/WaterfallPanel.cpp + src/panel/MeterPanel.cpp + src/panel/MeterPanel.h src/visual/ColorTheme.cpp src/visual/PrimaryGLContext.cpp src/visual/InteractiveCanvas.cpp diff --git a/src/panel/MeterPanel.cpp b/src/panel/MeterPanel.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/panel/MeterPanel.h b/src/panel/MeterPanel.h new file mode 100644 index 0000000..7ad3d6f --- /dev/null +++ b/src/panel/MeterPanel.h @@ -0,0 +1,153 @@ +#pragma once + +#include "GLPanel.h" + +class MeterPanel : public GLPanel { + +public: + MeterPanel(std::string name, float low, float high, float current) { + this->name = name; + this->low = low; + this->high = high; + this->current = current; + + setBorderPx(1); + setFill(GLPanel::GLPANEL_FILL_NONE); + + bgPanel.setCoordinateSystem(GLPanel::GLPANEL_Y_UP); + bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_X); + + levelPanel.setBorderPx(0); + levelPanel.setMarginPx(1); + + setPanelLevel(current, levelPanel); + levelPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); + levelPanel.setBlend(GL_ONE, GL_ONE); + + bgPanel.addChild(&levelPanel); + + setPanelLevel(current, highlightPanel); + highlightPanel.setBorderPx(0); + highlightPanel.setMarginPx(1); + highlightPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); + highlightPanel.setBlend(GL_ONE, GL_ONE); + highlightPanel.visible = false; + + bgPanel.addChild(&highlightPanel); + + labelPanel.setSize(1.0, 0.1); + labelPanel.setPosition(0.5, 1.0); + labelPanel.setText(name,GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); + labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE); + + addChild(&labelPanel); + + valuePanel.setSize(1.0, 0.1); + valuePanel.setPosition(0.5, -1.0); + + setValueLabel(std::to_string(int(current))); + valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE); + + addChild(&valuePanel); + } + + void setName(std::string name_in) { + name = name_in; + } + + void setRange(float low, float high) { + this->low = low; + this->high = high; + } + + void setValue(float value) { + if (value > high) { + value = high; + } + if (value < low) { + value = low; + } + + current = low + (value * (high-low)); + setValueLabel(std::to_string(int(current))); + setPanelLevel(value, levelPanel); + } + + void setHighlight(float value) { + if (value > high) { + value = high; + } + if (value < low) { + value = low; + } + + if (value == 0) { + highlightPanel.visible = false; + } else { + setPanelLevel(value, highlightPanel); + highlightPanel.visible = true; + } + } + + float getValue() { + return current; + } + + bool isMeterHit(CubicVR::vec2 mousePoint) { + CubicVR::vec2 hitResult; + + if (bgPanel.hitTest(mousePoint, hitResult)) { + return true; + } + + return false; + } + + float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel) { + CubicVR::vec2 hitResult; + + if (bgPanel.hitTest(mousePoint, hitResult)) { + float hitLevel = hitResult.y; + + if (hitLevel < 0.0f) { + hitLevel = 0.0f; + } + if (hitLevel > 1.0f) { + hitLevel = 1.0f; + } + + return low + (hitLevel * (high-low)); + } else { + return 0; + } + } + +protected: + void drawPanelContents() { + drawChildren(); + } + + void setValueLabel(std::string label) { + valuePanel.setText(label, + GLFont::GLFONT_ALIGN_CENTER, + GLFont::GLFONT_ALIGN_CENTER, + true); + + } + + void setPanelLevel(float setValue, GLPanel &panel) { + float valueNorm = (setValue - low) / (high - low); + panel.setSize(1.0, valueNorm); + panel.setPosition(0.0, (-1.0+(valueNorm))); + } + +private: + std::string name; + float low, high, current; + GLPanel panel; + GLPanel bgPanel; + GLPanel levelPanel; + GLPanel highlightPanel; + GLTextPanel labelPanel; + GLTextPanel valuePanel; +}; \ No newline at end of file diff --git a/src/util/MouseTracker.cpp b/src/util/MouseTracker.cpp index 2b7faa4..00fb878 100644 --- a/src/util/MouseTracker.cpp +++ b/src/util/MouseTracker.cpp @@ -135,6 +135,10 @@ float MouseTracker::getLastMouseY() { return lastMouseY; } +CubicVR::vec2 MouseTracker::getGLXY() { + return CubicVR::vec2((getMouseX()-0.5)*2.0, (getMouseY()-0.5)*2.0); +} + float MouseTracker::getMouseX() { return mouseX; } diff --git a/src/util/MouseTracker.h b/src/util/MouseTracker.h index 33640ff..e23455a 100644 --- a/src/util/MouseTracker.h +++ b/src/util/MouseTracker.h @@ -1,6 +1,7 @@ #pragma once #include "wx/window.h" +#include "cubic_math.h" class MouseTracker { public: @@ -24,6 +25,7 @@ public: float getDeltaMouseY(); float getLastMouseX(); float getLastMouseY(); + CubicVR::vec2 getGLXY(); float getMouseX(); float getMouseY(); diff --git a/src/visual/GainCanvas.cpp b/src/visual/GainCanvas.cpp index 6ad56fa..b482771 100644 --- a/src/visual/GainCanvas.cpp +++ b/src/visual/GainCanvas.cpp @@ -96,7 +96,7 @@ int GainCanvas::GetPanelHit(CubicVR::vec2 &result) { GainInfo *gInfo = (*gi); CubicVR::vec2 hitResult; - if (gInfo->panel.hitTest(CubicVR::vec2((mouseTracker.getMouseX()-0.5)*2.0, (mouseTracker.getMouseY()-0.5)*2.0), 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; diff --git a/src/visual/GainCanvas.h b/src/visual/GainCanvas.h index ed23a8f..67d7624 100644 --- a/src/visual/GainCanvas.h +++ b/src/visual/GainCanvas.h @@ -12,6 +12,7 @@ #include "PrimaryGLContext.h" #include "SDRDeviceInfo.h" #include "Timer.h" +#include "MeterPanel.h" class GainInfo { public: @@ -52,6 +53,7 @@ private: PrimaryGLContext *glContext; std::string helpTip; std::vector gainInfo; + std::vector gainPanels; GLPanel bgPanel; SDRRangeMap gains; From 4ec2d8bcbdc8b41dafe1530b9aee38c3679ad302 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Wed, 6 Jul 2016 23:16:25 -0400 Subject: [PATCH 2/4] Functional MeterPanel --- src/AppFrame.cpp | 2 +- src/AppFrame.h | 4 +- src/panel/MeterPanel.cpp | 189 +++++++++++++++++++++++++++++++++++++++ src/panel/MeterPanel.h | 144 +++-------------------------- src/ui/UITestContext.cpp | 14 +-- src/ui/UITestContext.h | 2 + 6 files changed, 213 insertions(+), 142 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 6b10723..f764084 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 5c9774b..96db6e3 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 e69de29..cf8d10d 100644 --- a/src/panel/MeterPanel.cpp +++ b/src/panel/MeterPanel.cpp @@ -0,0 +1,189 @@ + +#include "MeterPanel.h" +#include "ColorTheme.h" + + +MeterPanel::MeterPanel(std::string name, float low, float high, float current) { + this->name = name; + this->low = low; + this->high = high; + this->current = current; + + RGBA4f c1, c2; + + setFill(GLPanel::GLPANEL_FILL_NONE); + + bgPanel.setBorderPx(1); + bgPanel.setCoordinateSystem(GLPanel::GLPANEL_Y_UP); + bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_X); + + levelPanel.setBorderPx(0); + levelPanel.setMarginPx(1); + + setPanelLevel(current, levelPanel); + levelPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); + levelPanel.setBlend(GL_ONE, GL_ONE); + + bgPanel.addChild(&levelPanel); + + setPanelLevel(current, highlightPanel); + highlightPanel.setBorderPx(0); + highlightPanel.setMarginPx(1); + highlightPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); + highlightPanel.setBlend(GL_ONE, GL_ONE); + highlightPanel.visible = false; + c1 = RGBA4f(0.3f,0.3f,0.3f,1.0f); + c2 = RGBA4f(0.65f,0.65f,0.65f,1.0f);; + highlightPanel.setFillColor(c1, c2); + + bgPanel.addChild(&highlightPanel); + + addChild(&bgPanel); + + labelPanel.setSize(1.0, 0.1); + labelPanel.setPosition(0.0, 1.0); + labelPanel.setText(name,GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); + labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE); + + addChild(&labelPanel); + + valuePanel.setSize(1.0, 0.1); + valuePanel.setPosition(0.0, -1.0); + + setValueLabel(std::to_string(int(current))); + valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE); + + addChild(&valuePanel); +} + +void MeterPanel::setName(std::string name_in) { + name = name_in; +} + +void MeterPanel::setRange(float low, float high) { + this->low = low; + this->high = high; +} + +void MeterPanel::setValue(float value) { + if (value > high) { + value = high; + } + if (value < low) { + value = low; + } + + current = low + (value * (high-low)); + setValueLabel(std::to_string(int(current))); + setPanelLevel(value, levelPanel); +} + +void MeterPanel::setHighlight(float value) { + if (value > high) { + value = high; + } + if (value < low) { + value = low; + } + + if (value == 0) { + highlightPanel.visible = false; + } else { + setPanelLevel(value, highlightPanel); + highlightPanel.visible = true; + } +} + +float MeterPanel::getValue() { + return current; +} + +bool MeterPanel::isMeterHit(CubicVR::vec2 mousePoint) { + CubicVR::vec2 hitResult; + + if (bgPanel.hitTest(mousePoint, hitResult)) { + return true; + } + + return false; +} + +float MeterPanel::getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel) { + CubicVR::vec2 hitResult; + + if (bgPanel.hitTest(mousePoint, hitResult)) { + float hitLevel = hitResult.y; + + if (hitLevel < 0.0f) { + hitLevel = 0.0f; + } + if (hitLevel > 1.0f) { + hitLevel = 1.0f; + } + + return low + (hitLevel * (high-low)); + } else { + return 0; + } +} + +void MeterPanel::drawPanelContents() { + GLint vp[4]; + + glGetIntegerv( GL_VIEWPORT, vp); + + float viewHeight = (float) vp[3]; + + CubicVR::vec4 t = CubicVR::mat4::vec4_multiply(CubicVR::vec4(0,0.5,0,1), transform); + CubicVR::vec4 b = CubicVR::mat4::vec4_multiply(CubicVR::vec4(0,-0.5,0,1), transform); + + float hScale = t.y-b.y; + + viewHeight = round(viewHeight * hScale); + + float labelHeight = 24.0f; + float labelPad = 8.0f; + + if (viewHeight > 400.0f) { + labelHeight *= 2.0f; + } + + float pScale = (1.0f/viewHeight); + RGBA4f c1, c2; + + bgPanel.setSize(1.0f, 1.0f - pScale * (labelHeight + labelPad * 2.0f)); + + valuePanel.setPosition(0.0f, (pScale * (labelHeight / 2.0f + labelPad) ) - 1.0f); + valuePanel.setSize(1.0f, pScale*labelHeight); + + labelPanel.setPosition(0.0f, 1.0f - (pScale * (labelHeight / 2.0f + labelPad))); + labelPanel.setSize(1.0f, pScale*labelHeight); + + c1 = ThemeMgr::mgr.currentTheme->generalBackground; + c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5; + c1.a = 1.0; + c2.a = 1.0; + bgPanel.setFillColor(c1, c2); + + c1 = ThemeMgr::mgr.currentTheme->meterLevel * 0.5; + c2 = ThemeMgr::mgr.currentTheme->meterLevel; + c1.a = 1.0; + c2.a = 1.0; + levelPanel.setFillColor(c1, c2); + + drawChildren(); +} + +void MeterPanel::setValueLabel(std::string label) { + valuePanel.setText(label, + GLFont::GLFONT_ALIGN_CENTER, + GLFont::GLFONT_ALIGN_CENTER, + true); + +} + +void MeterPanel::setPanelLevel(float setValue, GLPanel &panel) { + float valueNorm = (setValue - low) / (high - low); + panel.setSize(1.0, valueNorm); + panel.setPosition(0.0, (-1.0+(valueNorm))); +} diff --git a/src/panel/MeterPanel.h b/src/panel/MeterPanel.h index 7ad3d6f..188eeb3 100644 --- a/src/panel/MeterPanel.h +++ b/src/panel/MeterPanel.h @@ -5,142 +5,20 @@ class MeterPanel : public GLPanel { public: - MeterPanel(std::string name, float low, float high, float current) { - this->name = name; - this->low = low; - this->high = high; - this->current = current; - - setBorderPx(1); - setFill(GLPanel::GLPANEL_FILL_NONE); - - bgPanel.setCoordinateSystem(GLPanel::GLPANEL_Y_UP); - bgPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_X); - - levelPanel.setBorderPx(0); - levelPanel.setMarginPx(1); - - setPanelLevel(current, levelPanel); - levelPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); - levelPanel.setBlend(GL_ONE, GL_ONE); - - bgPanel.addChild(&levelPanel); - - setPanelLevel(current, highlightPanel); - highlightPanel.setBorderPx(0); - highlightPanel.setMarginPx(1); - highlightPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_X); - highlightPanel.setBlend(GL_ONE, GL_ONE); - highlightPanel.visible = false; - - bgPanel.addChild(&highlightPanel); - - labelPanel.setSize(1.0, 0.1); - labelPanel.setPosition(0.5, 1.0); - labelPanel.setText(name,GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); - labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE); - - addChild(&labelPanel); - - valuePanel.setSize(1.0, 0.1); - valuePanel.setPosition(0.5, -1.0); - - setValueLabel(std::to_string(int(current))); - valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE); - - addChild(&valuePanel); - } - - void setName(std::string name_in) { - name = name_in; - } - - void setRange(float low, float high) { - this->low = low; - this->high = high; - } - - void setValue(float value) { - if (value > high) { - value = high; - } - if (value < low) { - value = low; - } - - current = low + (value * (high-low)); - setValueLabel(std::to_string(int(current))); - setPanelLevel(value, levelPanel); - } - - void setHighlight(float value) { - if (value > high) { - value = high; - } - if (value < low) { - value = low; - } - - if (value == 0) { - highlightPanel.visible = false; - } else { - setPanelLevel(value, highlightPanel); - highlightPanel.visible = true; - } - } - - float getValue() { - return current; - } - - bool isMeterHit(CubicVR::vec2 mousePoint) { - CubicVR::vec2 hitResult; - - if (bgPanel.hitTest(mousePoint, hitResult)) { - return true; - } - - return false; - } - - float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel) { - CubicVR::vec2 hitResult; - - if (bgPanel.hitTest(mousePoint, hitResult)) { - float hitLevel = hitResult.y; - - if (hitLevel < 0.0f) { - hitLevel = 0.0f; - } - if (hitLevel > 1.0f) { - hitLevel = 1.0f; - } - - return low + (hitLevel * (high-low)); - } else { - return 0; - } - } + MeterPanel(std::string name, float low, float high, float current); + void setName(std::string name_in); + void setRange(float low, float high); + void setValue(float value); + void setHighlight(float value); + float getValue(); + bool isMeterHit(CubicVR::vec2 mousePoint); + float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel); protected: - void drawPanelContents() { - drawChildren(); - } - - void setValueLabel(std::string label) { - valuePanel.setText(label, - GLFont::GLFONT_ALIGN_CENTER, - GLFont::GLFONT_ALIGN_CENTER, - true); - - } + void drawPanelContents(); + void setValueLabel(std::string label); + void setPanelLevel(float setValue, GLPanel &panel); - void setPanelLevel(float setValue, GLPanel &panel) { - float valueNorm = (setValue - low) / (high - low); - panel.setSize(1.0, valueNorm); - panel.setPosition(0.0, (-1.0+(valueNorm))); - } - private: std::string name; float low, high, current; diff --git a/src/ui/UITestContext.cpp b/src/ui/UITestContext.cpp index c31f2e6..1f5696a 100644 --- a/src/ui/UITestContext.cpp +++ b/src/ui/UITestContext.cpp @@ -3,13 +3,13 @@ #include "ColorTheme.h" UITestContext::UITestContext(UITestCanvas *canvas, wxGLContext *sharedContext) : -PrimaryGLContext(canvas, sharedContext) { +PrimaryGLContext(canvas, sharedContext), testMeter("TEST",0,100,50) { testPanel.setPosition(0.0, 0.0); testPanel.setSize(1.0, 1.0); testPanel.setMarginPx(10); - testPanel.setFill(GLPanel::GLPANEL_FILL_GRAD_BAR_Y); - testPanel.setFillColor(RGBA4f(0.0,0.0,1.0), RGBA4f(0.0,1.0,0.0)); + testPanel.setFill(GLPanel::GLPANEL_FILL_SOLID); + testPanel.setFillColor(RGBA4f(0.0,0.0,1.0)); testChildPanel.setPosition(0.0, 0.0); testChildPanel.setMarginPx(5); @@ -39,9 +39,11 @@ PrimaryGLContext(canvas, sharedContext) { testText1.setFill(GLPanel::GLPANEL_FILL_NONE); testChildPanel2.addChild(&testText1); - testPanel.addChild(&testChildPanel); - testPanel.addChild(&testChildPanel2); - testPanel.addChild(&testChildPanel3); +// testPanel.addChild(&testChildPanel); +// testPanel.addChild(&testChildPanel2); +// testPanel.addChild(&testChildPanel3); + testMeter.setSize(0.1,0.9); + testPanel.addChild(&testMeter); } void UITestContext::DrawBegin() { diff --git a/src/ui/UITestContext.h b/src/ui/UITestContext.h index f392336..45dd3e3 100644 --- a/src/ui/UITestContext.h +++ b/src/ui/UITestContext.h @@ -2,6 +2,7 @@ #include "PrimaryGLContext.h" #include "GLPanel.h" +#include "MeterPanel.h" class UITestCanvas; @@ -19,4 +20,5 @@ private: GLPanel testChildPanel2; GLPanel testChildPanel3; GLTextPanel testText1; + MeterPanel testMeter; }; From ebf2443fe2adfbfeb4c1a396280712a1f3b32959 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 7 Jul 2016 22:37:57 -0400 Subject: [PATCH 3/4] 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; From aa813db490c62c4215f9fe7aa8513bd2f9d035c8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 7 Jul 2016 23:47:58 -0400 Subject: [PATCH 4/4] Fix Mousewheel support --- src/panel/MeterPanel.cpp | 8 +++++++ src/panel/MeterPanel.h | 2 ++ src/visual/GainCanvas.cpp | 47 ++++++++++++++++----------------------- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/panel/MeterPanel.cpp b/src/panel/MeterPanel.cpp index dfeb8c1..f43cb77 100644 --- a/src/panel/MeterPanel.cpp +++ b/src/panel/MeterPanel.cpp @@ -74,6 +74,14 @@ void MeterPanel::setRange(float low, float high) { this->high = high; } +float MeterPanel::getLow() { + return this->low; +} + +float MeterPanel::getHigh() { + return this->high; +} + void MeterPanel::setValue(float value) { if (value > high) { value = high; diff --git a/src/panel/MeterPanel.h b/src/panel/MeterPanel.h index 40c9590..75781d7 100644 --- a/src/panel/MeterPanel.h +++ b/src/panel/MeterPanel.h @@ -10,6 +10,8 @@ public: void setName(std::string name_in); std::string getName(); void setRange(float low, float high); + float getLow(); + float getHigh(); void setValue(float value); void setHighlight(float value); void setHighlightVisible(bool vis); diff --git a/src/visual/GainCanvas.cpp b/src/visual/GainCanvas.cpp index 27c30d6..6f64193 100644 --- a/src/visual/GainCanvas.cpp +++ b/src/visual/GainCanvas.cpp @@ -121,34 +121,17 @@ 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); -// } - + + CubicVR::vec2 mpos = mouseTracker.getGLXY(); + + for (auto gi : gainPanels) { + if (gi->isMeterHit(mpos)) { + float movement = 3.0 * (float)event.GetWheelRotation(); + gi->setValue(gi->getValue() + ((movement / 100.0) * ((gi->getHigh() - gi->getLow()) / 100.0))); + gi->setChanged(true); + break; + } + } } void GainCanvas::OnMouseReleased(wxMouseEvent& event) { @@ -224,6 +207,14 @@ void GainCanvas::updateGainUI() { } void GainCanvas::setThemeColors() { + RGBA4f c1, c2; + + c1 = ThemeMgr::mgr.currentTheme->generalBackground; + c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5; + c1.a = 1.0; + c2.a = 1.0; + bgPanel.setFillColor(c1, c2); + Refresh(); }