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;