Merge pull request #400 from cjcliffe/gain_gui_cleanup

Gain GUI cleanup
This commit is contained in:
Charles J. Cliffe 2016-07-08 19:14:22 -04:00 committed by GitHub
commit 6f11140e47
10 changed files with 339 additions and 200 deletions

View File

@ -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

View File

@ -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);

213
src/panel/MeterPanel.cpp Normal file
View File

@ -0,0 +1,213 @@
#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);
}
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;
}
float MeterPanel::getLow() {
return this->low;
}
float MeterPanel::getHigh() {
return this->high;
}
void MeterPanel::setValue(float value) {
if (value > high) {
value = high;
}
if (value < low) {
value = low;
}
current = value;
setValueLabel(std::to_string(int(current)));
setPanelLevel(value, levelPanel);
}
void MeterPanel::setHighlight(float value) {
if (value > high) {
value = high;
}
if (value < low) {
value = low;
}
setPanelLevel(value, highlightPanel);
}
void MeterPanel::setHighlightVisible(bool vis) {
highlightPanel.visible = vis;
}
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 + 1.0) * 0.5);
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 = 32.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)));
}
bool MeterPanel::getChanged() {
return changed;
}
void MeterPanel::setChanged(bool changed) {
this->changed = changed;
}

38
src/panel/MeterPanel.h Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include "GLPanel.h"
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);
float getLow();
float getHigh();
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();
void setValueLabel(std::string label);
void setPanelLevel(float setValue, GLPanel &panel);
private:
std::string name;
float low, high, current;
bool changed;
GLPanel bgPanel;
GLPanel levelPanel;
GLPanel highlightPanel;
GLTextPanel labelPanel;
GLTextPanel valuePanel;
};

View File

@ -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() {

View File

@ -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;
};

View File

@ -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;
}

View File

@ -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();

View File

@ -53,20 +53,8 @@ void GainCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glViewport(0, 0, ClientSize.x, ClientSize.y);
float i = 0;
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;
}
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<GainInfo *>::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<GainInfo *>::iterator gi;
int i = 0;
for (gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
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)) {
// 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<GainInfo *>::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,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;
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;
}
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);
}
}
void GainCanvas::OnMouseReleased(wxMouseEvent& event) {
@ -191,12 +141,11 @@ void GainCanvas::OnMouseReleased(wxMouseEvent& event) {
void GainCanvas::OnMouseLeftWindow(wxMouseEvent& event) {
InteractiveCanvas::OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS);
int i = 0;
for (std::vector<GainInfo *>::iterator gi = gainInfo.begin(); gi != gainInfo.end(); gi++) {
(*gi)->highlightPanel.visible = false;
i++;
for (auto gi : gainPanels) {
gi->setHighlightVisible(false);
}
Refresh();
}
@ -217,8 +166,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 +182,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 +207,14 @@ void GainCanvas::updateGainUI() {
}
void GainCanvas::setThemeColors() {
std::vector<GainInfo *>::iterator gi;
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);
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();
}

View File

@ -12,18 +12,19 @@
#include "PrimaryGLContext.h"
#include "SDRDeviceInfo.h"
#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:
@ -38,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);
@ -51,7 +52,8 @@ private:
PrimaryGLContext *glContext;
std::string helpTip;
std::vector<GainInfo *> gainInfo;
// std::vector<GainInfo *> gainInfo;
std::vector<MeterPanel *> gainPanels;
GLPanel bgPanel;
SDRRangeMap gains;