Gain UI working (minus mousewheel)

This commit is contained in:
Charles J. Cliffe 2016-07-07 22:37:57 -04:00
parent 4ec2d8bcbd
commit ebf2443fe2
6 changed files with 117 additions and 213 deletions

View File

@ -309,7 +309,7 @@ AppFrame::AppFrame() :
waterfallCanvas->attachSpectrumCanvas(spectrumCanvas); waterfallCanvas->attachSpectrumCanvas(spectrumCanvas);
spectrumCanvas->attachWaterfallCanvas(waterfallCanvas); spectrumCanvas->attachWaterfallCanvas(waterfallCanvas);
/* */ /* * /
vbox->AddSpacer(1); vbox->AddSpacer(1);
testCanvas = new UITestCanvas(this, attribList); testCanvas = new UITestCanvas(this, attribList);
vbox->Add(testCanvas, 20, wxEXPAND | wxALL, 0); vbox->Add(testCanvas, 20, wxEXPAND | wxALL, 0);

View File

@ -17,7 +17,7 @@
#include "FFTVisualDataThread.h" #include "FFTVisualDataThread.h"
#include "SDRDeviceInfo.h" #include "SDRDeviceInfo.h"
#include "ModemProperties.h" #include "ModemProperties.h"
#include "UITestCanvas.h" //#include "UITestCanvas.h"
#include "FrequencyDialog.h" #include "FrequencyDialog.h"
#include <map> #include <map>
@ -122,7 +122,7 @@ private:
MeterCanvas *demodSignalMeter; MeterCanvas *demodSignalMeter;
MeterCanvas *demodGainMeter; MeterCanvas *demodGainMeter;
TuningCanvas *demodTuner; TuningCanvas *demodTuner;
UITestCanvas *testCanvas; // UITestCanvas *testCanvas;
MeterCanvas *spectrumAvgMeter; MeterCanvas *spectrumAvgMeter;
MeterCanvas *waterfallSpeedMeter; MeterCanvas *waterfallSpeedMeter;
ModeSelectorCanvas *demodMuteButton, *peakHoldButton, *soloModeButton, *deltaLockButton; ModeSelectorCanvas *demodMuteButton, *peakHoldButton, *soloModeButton, *deltaLockButton;

View File

@ -56,10 +56,19 @@ MeterPanel::MeterPanel(std::string name, float low, float high, float current) {
addChild(&valuePanel); addChild(&valuePanel);
} }
MeterPanel::~MeterPanel() {
}
void MeterPanel::setName(std::string name_in) { void MeterPanel::setName(std::string name_in) {
name = name_in; name = name_in;
} }
std::string MeterPanel::getName() {
return name;
}
void MeterPanel::setRange(float low, float high) { void MeterPanel::setRange(float low, float high) {
this->low = low; this->low = low;
this->high = high; this->high = high;
@ -73,7 +82,7 @@ void MeterPanel::setValue(float value) {
value = low; value = low;
} }
current = low + (value * (high-low)); current = value;
setValueLabel(std::to_string(int(current))); setValueLabel(std::to_string(int(current)));
setPanelLevel(value, levelPanel); setPanelLevel(value, levelPanel);
} }
@ -86,12 +95,11 @@ void MeterPanel::setHighlight(float value) {
value = low; value = low;
} }
if (value == 0) { setPanelLevel(value, highlightPanel);
highlightPanel.visible = false; }
} else {
setPanelLevel(value, highlightPanel); void MeterPanel::setHighlightVisible(bool vis) {
highlightPanel.visible = true; highlightPanel.visible = vis;
}
} }
float MeterPanel::getValue() { float MeterPanel::getValue() {
@ -112,7 +120,7 @@ float MeterPanel::getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel) {
CubicVR::vec2 hitResult; CubicVR::vec2 hitResult;
if (bgPanel.hitTest(mousePoint, hitResult)) { if (bgPanel.hitTest(mousePoint, hitResult)) {
float hitLevel = hitResult.y; float hitLevel = ((hitResult.y + 1.0) * 0.5);
if (hitLevel < 0.0f) { if (hitLevel < 0.0f) {
hitLevel = 0.0f; hitLevel = 0.0f;
@ -145,7 +153,7 @@ void MeterPanel::drawPanelContents() {
float labelPad = 8.0f; float labelPad = 8.0f;
if (viewHeight > 400.0f) { if (viewHeight > 400.0f) {
labelHeight *= 2.0f; labelHeight = 32.0f;
} }
float pScale = (1.0f/viewHeight); float pScale = (1.0f/viewHeight);
@ -187,3 +195,11 @@ void MeterPanel::setPanelLevel(float setValue, GLPanel &panel) {
panel.setSize(1.0, valueNorm); panel.setSize(1.0, valueNorm);
panel.setPosition(0.0, (-1.0+(valueNorm))); panel.setPosition(0.0, (-1.0+(valueNorm)));
} }
bool MeterPanel::getChanged() {
return changed;
}
void MeterPanel::setChanged(bool changed) {
this->changed = changed;
}

View File

@ -6,13 +6,18 @@ class MeterPanel : public GLPanel {
public: public:
MeterPanel(std::string name, float low, float high, float current); MeterPanel(std::string name, float low, float high, float current);
~MeterPanel();
void setName(std::string name_in); void setName(std::string name_in);
std::string getName();
void setRange(float low, float high); void setRange(float low, float high);
void setValue(float value); void setValue(float value);
void setHighlight(float value); void setHighlight(float value);
void setHighlightVisible(bool vis);
float getValue(); float getValue();
bool isMeterHit(CubicVR::vec2 mousePoint); bool isMeterHit(CubicVR::vec2 mousePoint);
float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel); float getMeterHitValue(CubicVR::vec2 mousePoint, GLPanel &panel);
void setChanged(bool changed);
bool getChanged();
protected: protected:
void drawPanelContents(); void drawPanelContents();
@ -22,7 +27,7 @@ protected:
private: private:
std::string name; std::string name;
float low, high, current; float low, high, current;
GLPanel panel; bool changed;
GLPanel bgPanel; GLPanel bgPanel;
GLPanel levelPanel; GLPanel levelPanel;
GLPanel highlightPanel; GLPanel highlightPanel;

View File

@ -53,20 +53,8 @@ void GainCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glViewport(0, 0, ClientSize.x, ClientSize.y); glViewport(0, 0, ClientSize.x, ClientSize.y);
float i = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (std::vector<GainInfo *>::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;
}
bgPanel.draw(); bgPanel.draw();
SwapBuffers(); SwapBuffers();
@ -79,65 +67,44 @@ void GainCanvas::OnIdle(wxIdleEvent &event) {
event.Skip(); event.Skip();
} }
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { for (auto gi : gainPanels) {
GainInfo *gInfo = (*gi); if (gi->getChanged()) {
if (gInfo->changed) { wxGetApp().setGain(gi->getName(), gi->getValue());
wxGetApp().setGain(gInfo->name, gInfo->current); gi->setChanged(false);
gInfo->changed = false;
} }
} }
} }
int GainCanvas::GetPanelHit(CubicVR::vec2 &result) {
std::vector<GainInfo *>::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() { void GainCanvas::SetLevel() {
CubicVR::vec2 hitResult; CubicVR::vec2 mpos = mouseTracker.getGLXY();
int panelHit = GetPanelHit(hitResult);
if (panelHit >= 0) { for (auto gi : gainPanels) {
gainInfo[panelHit]->levelPanel.setSize(1.0, hitResult.y); if (gi->isMeterHit(mpos)) {
gainInfo[panelHit]->levelPanel.setPosition(0.0, (-1.0+(hitResult.y))); float value = gi->getMeterHitValue(mpos, *gi);
gainInfo[panelHit]->current = round(gainInfo[panelHit]->low+(hitResult.y * (gainInfo[panelHit]->high-gainInfo[panelHit]->low)));
gainInfo[panelHit]->changed = true; gi->setValue(value);
gainInfo[panelHit]->valuePanel.setText(std::to_string(int(gainInfo[panelHit]->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); gi->setChanged(true);
break;
}
} }
} }
void GainCanvas::OnMouseMoved(wxMouseEvent& event) { void GainCanvas::OnMouseMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseMoved(event); InteractiveCanvas::OnMouseMoved(event);
CubicVR::vec2 hitResult; CubicVR::vec2 mpos = mouseTracker.getGLXY();
int panelHit = GetPanelHit(hitResult);
if (panelHit >= 0) { for (auto gi : gainPanels) {
gainInfo[panelHit]->highlightPanel.setSize(1.0, hitResult.y); if (gi->isMeterHit(mpos)) {
gainInfo[panelHit]->highlightPanel.setPosition(0.0, (-1.0+(hitResult.y))); float value = gi->getMeterHitValue(mpos, *gi);
}
gi->setHighlight(value);
int i = 0; gi->setHighlightVisible(true);
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { wxGetApp().setActiveGainEntry(gi->getName());
(*gi)->highlightPanel.visible = (i==panelHit); } else {
if (i==panelHit) { gi->setHighlightVisible(false);
wxGetApp().setActiveGainEntry((*gi)->name);
} }
i++;
} }
if (mouseTracker.mouseDown()) { if (mouseTracker.mouseDown()) {
@ -154,33 +121,33 @@ void GainCanvas::OnMouseWheelMoved(wxMouseEvent& event) {
InteractiveCanvas::OnMouseWheelMoved(event); InteractiveCanvas::OnMouseWheelMoved(event);
CubicVR::vec2 hitResult; CubicVR::vec2 hitResult;
int panelHit = GetPanelHit(hitResult); // int panelHit = GetPanelHit(hitResult);
//
if (panelHit >= 0) { // if (panelHit >= 0) {
float movement = 3.0 * (float)event.GetWheelRotation(); // float movement = 3.0 * (float)event.GetWheelRotation();
//
GainInfo *gInfo; // GainInfo *gInfo;
//
gInfo = gainInfo[panelHit]; // gInfo = gainInfo[panelHit];
//
gInfo->current = gInfo->current + ((movement / 100.0) * ((gInfo->high - gInfo->low) / 100.0)); // gInfo->current = gInfo->current + ((movement / 100.0) * ((gInfo->high - gInfo->low) / 100.0));
//
//BEGIN Clamp to prevent the meter to escape // //BEGIN Clamp to prevent the meter to escape
if (gInfo->current > gInfo->high) { // if (gInfo->current > gInfo->high) {
gInfo->current = gInfo->high; // gInfo->current = gInfo->high;
} // }
if (gInfo->current < gInfo->low) { // if (gInfo->current < gInfo->low) {
gInfo->current = gInfo->low; // gInfo->current = gInfo->low;
} // }
//
gInfo->changed = true; // gInfo->changed = true;
//
float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low); // float levelVal = float(gInfo->current-gInfo->low)/float(gInfo->high-gInfo->low);
gInfo->levelPanel.setSize(1.0, levelVal); // gInfo->levelPanel.setSize(1.0, levelVal);
gInfo->levelPanel.setPosition(0.0, levelVal-1.0); // 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); // 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) { void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event); InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
int i = 0; for (auto gi : gainPanels) {
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) { gi->setHighlightVisible(false);
(*gi)->highlightPanel.visible = false;
i++;
} }
Refresh(); Refresh();
} }
@ -217,8 +183,6 @@ void GainCanvas::setHelpTip(std::string tip) {
} }
void GainCanvas::updateGainUI() { void GainCanvas::updateGainUI() {
const wxSize ClientSize = GetClientSize();
SDRDeviceInfo *devInfo = wxGetApp().getDevice(); SDRDeviceInfo *devInfo = wxGetApp().getDevice();
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(devInfo->getDeviceId()); DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(devInfo->getDeviceId());
@ -235,77 +199,24 @@ void GainCanvas::updateGainUI() {
spacing = 2.0/numGains; spacing = 2.0/numGains;
barWidth = (1.0/numGains)*0.7; barWidth = (1.0/numGains)*0.7;
startPos = spacing/2.0; startPos = spacing/2.0;
barHeight = 0.8f; barHeight = 1.0f;
RGBA4f c1, c2; while (gainPanels.size()) {
MeterPanel *mDel = gainPanels.back();
while (gainInfo.size()) { gainPanels.pop_back();
GainInfo *giDel; bgPanel.removeChild(mDel);
giDel = gainInfo.back(); delete mDel;
gainInfo.pop_back();
giDel->panel.removeChild(&giDel->levelPanel);
bgPanel.removeChild(&(giDel->labelPanel));
bgPanel.removeChild(&(giDel->valuePanel));
bgPanel.removeChild(&(giDel->panel));
delete giDel;
} }
for (gi = gains.begin(); gi != gains.end(); gi++) { for (auto gi : gains) {
GainInfo *gInfo = new GainInfo; 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; float midPos = -1.0+startPos+spacing*i;
mPanel->setPosition(midPos, 0);
mPanel->setSize(barWidth, barHeight);
bgPanel.addChild(mPanel);
gInfo->name = gi->first; gainPanels.push_back(mPanel);
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);
i++; i++;
} }
@ -313,34 +224,6 @@ void GainCanvas::updateGainUI() {
} }
void GainCanvas::setThemeColors() { void GainCanvas::setThemeColors() {
std::vector<GainInfo *>::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(); Refresh();
} }

View File

@ -14,17 +14,17 @@
#include "Timer.h" #include "Timer.h"
#include "MeterPanel.h" #include "MeterPanel.h"
class GainInfo { //class GainInfo {
public: //public:
std::string name; // std::string name;
float low, high, current; // float low, high, current;
bool changed; // bool changed;
GLPanel panel; // GLPanel panel;
GLPanel levelPanel; // GLPanel levelPanel;
GLPanel highlightPanel; // GLPanel highlightPanel;
GLTextPanel labelPanel; // GLTextPanel labelPanel;
GLTextPanel valuePanel; // GLTextPanel valuePanel;
}; //};
class GainCanvas: public InteractiveCanvas { class GainCanvas: public InteractiveCanvas {
public: public:
@ -39,7 +39,7 @@ private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnIdle(wxIdleEvent &event); void OnIdle(wxIdleEvent &event);
int GetPanelHit(CubicVR::vec2 &result); // int GetPanelHit(CubicVR::vec2 &result);
void SetLevel(); void SetLevel();
void OnShow(wxShowEvent& event); void OnShow(wxShowEvent& event);
@ -52,7 +52,7 @@ private:
PrimaryGLContext *glContext; PrimaryGLContext *glContext;
std::string helpTip; std::string helpTip;
std::vector<GainInfo *> gainInfo; // std::vector<GainInfo *> gainInfo;
std::vector<MeterPanel *> gainPanels; std::vector<MeterPanel *> gainPanels;
GLPanel bgPanel; GLPanel bgPanel;
SDRRangeMap gains; SDRRangeMap gains;