Functional MeterPanel

This commit is contained in:
Charles J. Cliffe 2016-07-06 23:16:25 -04:00
parent baa5d93ba6
commit 4ec2d8bcbd
6 changed files with 213 additions and 142 deletions

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

View File

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

View File

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

View File

@ -5,141 +5,19 @@
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 setPanelLevel(float setValue, GLPanel &panel) {
float valueNorm = (setValue - low) / (high - low);
panel.setSize(1.0, valueNorm);
panel.setPosition(0.0, (-1.0+(valueNorm)));
}
void drawPanelContents();
void setValueLabel(std::string label);
void setPanelLevel(float setValue, GLPanel &panel);
private:
std::string name;

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