mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-15 13:07:58 -04:00
more intuitive SSB range selection, drawing code cleanup
This commit is contained in:
parent
ddbdd81699
commit
ff5660055e
@ -97,7 +97,7 @@ GLFont &PrimaryGLContext::getFont(GLFontSize esize) {
|
||||
return fonts[esize];
|
||||
}
|
||||
|
||||
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float g, float b, long long center_freq, long long srate) {
|
||||
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, RGBColor color, long long center_freq, long long srate) {
|
||||
if (!demod) {
|
||||
return;
|
||||
}
|
||||
@ -122,7 +122,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(r, g, b, 0.6);
|
||||
glColor4f(color.r, color.g, color.b, 0.6);
|
||||
|
||||
float ofs = ((float) demod->getBandwidth()) / (float) srate;
|
||||
float ofsLeft = (demod->getDemodulatorType()!=DEMOD_TYPE_USB)?ofs:0, ofsRight = (demod->getDemodulatorType()!=DEMOD_TYPE_LSB)?ofs:0;
|
||||
@ -143,7 +143,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
|
||||
glColor4f(r, g, b, 0.2);
|
||||
glColor4f(color.r, color.g, color.b, 0.2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(uxPos - ofsLeft, 1.0, 0.0);
|
||||
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
||||
@ -155,7 +155,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
|
||||
if (ofs * 2.0 < 16.0 / viewWidth) {
|
||||
ofs = 16.0 / viewWidth;
|
||||
|
||||
glColor4f(r, g, b, 0.2);
|
||||
glColor4f(color.r, color.g, color.b, 0.2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(uxPos - ofsLeft, hPos + labelHeight, 0.0);
|
||||
glVertex3f(uxPos - ofsLeft, -1.0, 0.0);
|
||||
@ -180,7 +180,7 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float
|
||||
|
||||
}
|
||||
|
||||
void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b, long long center_freq, long long srate) {
|
||||
void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGBColor color, long long center_freq, long long srate) {
|
||||
if (!demod) {
|
||||
return;
|
||||
}
|
||||
@ -198,7 +198,7 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glColor4f(r, g, b, 0.6);
|
||||
glColor4f(color.r, color.g, color.b, 0.6);
|
||||
|
||||
float ofs = ((float) demod->getBandwidth()) / (float) srate;
|
||||
float ofsLeft = (demod->getDemodulatorType()!=DEMOD_TYPE_USB)?ofs:0, ofsRight = (demod->getDemodulatorType()!=DEMOD_TYPE_LSB)?ofs:0;
|
||||
@ -216,7 +216,7 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
|
||||
glEnd();
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glColor4f(r, g, b, 0.2);
|
||||
glColor4f(color.r, color.g, color.b, 0.2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofsLeft, -1.0, 0.0);
|
||||
@ -277,11 +277,13 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
|
||||
|
||||
}
|
||||
|
||||
void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b, float w, long long center_freq, long long srate) {
|
||||
void PrimaryGLContext::DrawFreqSelector(float uxPos, RGBColor color, float w, long long center_freq, long long srate) {
|
||||
DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
|
||||
|
||||
long long bw = 0;
|
||||
|
||||
int last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
||||
|
||||
if (!demod) {
|
||||
bw = wxGetApp().getDemodMgr().getLastBandwidth();
|
||||
} else {
|
||||
@ -296,9 +298,10 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glColor4f(r, g, b, 0.6);
|
||||
glColor4f(color.r, color.g, color.b, 0.6);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
|
||||
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0, -1.0, 0.0);
|
||||
|
||||
@ -310,17 +313,55 @@ void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b,
|
||||
ofs = ((float) bw) / (float) srate;
|
||||
}
|
||||
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
||||
if (last_type != DEMOD_TYPE_USB) {
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
|
||||
}
|
||||
|
||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
||||
if (last_type != DEMOD_TYPE_LSB) {
|
||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, 1.0, 0.0);
|
||||
glVertex3f((uxPos - 0.5) * 2.0 + ofs, -1.0, 0.0);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
}
|
||||
|
||||
void PrimaryGLContext::DrawRangeSelector(float uxPos1, float uxPos2, RGBColor color) {
|
||||
if (uxPos2 < uxPos1) {
|
||||
float temp = uxPos2;
|
||||
uxPos2=uxPos1;
|
||||
uxPos1=temp;
|
||||
}
|
||||
|
||||
int last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glColor4f(color.r, color.g, color.b, 0.6);
|
||||
|
||||
glLineWidth((last_type == DEMOD_TYPE_USB)?2.0:1.0);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f((uxPos1 - 0.5) * 2.0, 1.0, 0.0);
|
||||
glVertex3f((uxPos1 - 0.5) * 2.0, -1.0, 0.0);
|
||||
glEnd();
|
||||
|
||||
glLineWidth((last_type == DEMOD_TYPE_LSB)?2.0:1.0);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f((uxPos2 - 0.5) * 2.0, 1.0, 0.0);
|
||||
glVertex3f((uxPos2 - 0.5) * 2.0, -1.0, 0.0);
|
||||
glEnd();
|
||||
|
||||
glLineWidth(1.0);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void PrimaryGLContext::BeginDraw(float r, float g, float b) {
|
||||
glClearColor(r,g,b, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "CubicSDRDefs.h"
|
||||
#include "GLFont.h"
|
||||
#include "DemodulatorMgr.h"
|
||||
#include "ColorTheme.h"
|
||||
|
||||
class PrimaryGLContext: public wxGLContext {
|
||||
public:
|
||||
@ -23,9 +24,10 @@ public:
|
||||
void BeginDraw(float r, float g, float b);
|
||||
void EndDraw();
|
||||
|
||||
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1, float w = 0, long long center_freq = -1, long long srate = 0);
|
||||
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = 0);
|
||||
void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1, long long center_freq = -1, long long srate = 0);
|
||||
void DrawFreqSelector(float uxPos, RGBColor color, float w = 0, long long center_freq = -1, long long srate = 0);
|
||||
void DrawRangeSelector(float uxPos1, float uxPos2, RGBColor color);
|
||||
void DrawDemod(DemodulatorInstance *demod, RGBColor color, long long center_freq = -1, long long srate = 0);
|
||||
void DrawDemodInfo(DemodulatorInstance *demod, RGBColor color, long long center_freq = -1, long long srate = 0);
|
||||
|
||||
static GLFont &getFont(GLFontSize esize);
|
||||
|
||||
|
@ -83,7 +83,7 @@ void SpectrumCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||
glContext->DrawDemodInfo(demods[i], ThemeMgr::mgr.currentTheme->fftHighlight.r, ThemeMgr::mgr.currentTheme->fftHighlight.g, ThemeMgr::mgr.currentTheme->fftHighlight.b, getCenterFrequency(), getBandwidth());
|
||||
glContext->DrawDemodInfo(demods[i], ThemeMgr::mgr.currentTheme->fftHighlight, getCenterFrequency(), getBandwidth());
|
||||
}
|
||||
|
||||
glContext->EndDraw();
|
||||
|
@ -137,56 +137,49 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
int currentBandwidth = getBandwidth();
|
||||
long long currentCenterFreq = getCenterFrequency();
|
||||
|
||||
float demodColor, selectorColor;
|
||||
ColorTheme *currentTheme = ThemeMgr::mgr.currentTheme;
|
||||
int last_type = wxGetApp().getDemodMgr().getLastDemodulatorType();
|
||||
|
||||
if (mouseTracker.mouseInView()) {
|
||||
if (nextDragState == WF_DRAG_RANGE) {
|
||||
if (mouseTracker.mouseDown()) {
|
||||
float width = mouseTracker.getOriginDeltaMouseX();
|
||||
float centerPos = mouseTracker.getOriginMouseX() + width / 2.0;
|
||||
float width = (1.0 / (float) ClientSize.x);
|
||||
float rangeWidth = mouseTracker.getOriginDeltaMouseX();
|
||||
float centerPos;
|
||||
|
||||
if (isNew) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(centerPos, ThemeMgr::mgr.currentTheme->waterfallNew.r, ThemeMgr::mgr.currentTheme->waterfallNew.g, ThemeMgr::mgr.currentTheme->waterfallNew.b, width ? width : (1.0 / (float) ClientSize.x), currentCenterFreq,
|
||||
currentBandwidth);
|
||||
} else {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallDestroy.r, ThemeMgr::mgr.currentTheme->waterfallDestroy.g, ThemeMgr::mgr.currentTheme->waterfallDestroy.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(centerPos, ThemeMgr::mgr.currentTheme->waterfallHover.r, ThemeMgr::mgr.currentTheme->waterfallHover.g, ThemeMgr::mgr.currentTheme->waterfallHover.b, width ? width : (1.0 / (float) ClientSize.x), currentCenterFreq,
|
||||
currentBandwidth);
|
||||
if (mouseTracker.mouseDown()) {
|
||||
if (rangeWidth) {
|
||||
width = rangeWidth;
|
||||
}
|
||||
centerPos = mouseTracker.getOriginMouseX() + width / 2.0;
|
||||
} else {
|
||||
if (isNew) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ThemeMgr::mgr.currentTheme->waterfallNew.r, ThemeMgr::mgr.currentTheme->waterfallNew.g, ThemeMgr::mgr.currentTheme->waterfallNew.b, 1.0 / (float) ClientSize.x, currentCenterFreq, currentBandwidth);
|
||||
} else {
|
||||
glContext->DrawDemod(lastActiveDemodulator,ThemeMgr::mgr.currentTheme->waterfallDestroy.r, ThemeMgr::mgr.currentTheme->waterfallDestroy.g, ThemeMgr::mgr.currentTheme->waterfallDestroy.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ThemeMgr::mgr.currentTheme->waterfallHover.r, ThemeMgr::mgr.currentTheme->waterfallHover.g, ThemeMgr::mgr.currentTheme->waterfallHover.b, 1.0 / (float) ClientSize.x, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
centerPos = mouseTracker.getMouseX();
|
||||
}
|
||||
|
||||
glContext->DrawDemod(lastActiveDemodulator, isNew?currentTheme->waterfallHighlight:currentTheme->waterfallDestroy, currentCenterFreq, currentBandwidth);
|
||||
|
||||
if ((last_type == DEMOD_TYPE_LSB || last_type == DEMOD_TYPE_USB) && mouseTracker.mouseDown()) {
|
||||
centerPos = mouseTracker.getMouseX();
|
||||
glContext->DrawRangeSelector(centerPos, centerPos-width, isNew?currentTheme->waterfallNew:currentTheme->waterfallHover);
|
||||
} else {
|
||||
glContext->DrawFreqSelector(centerPos, isNew?currentTheme->waterfallNew:currentTheme->waterfallHover, width, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
} else {
|
||||
if (lastActiveDemodulator) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ((isNew && activeDemodulator == NULL) || (activeDemodulator != NULL))?currentTheme->waterfallHighlight:currentTheme->waterfallDestroy, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
if (activeDemodulator == NULL) {
|
||||
if (lastActiveDemodulator) {
|
||||
if (isNew) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ThemeMgr::mgr.currentTheme->waterfallNew.r, ThemeMgr::mgr.currentTheme->waterfallNew.g, ThemeMgr::mgr.currentTheme->waterfallNew.b, 0, currentCenterFreq, currentBandwidth);
|
||||
} else {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallDestroy.r, ThemeMgr::mgr.currentTheme->waterfallDestroy.g, ThemeMgr::mgr.currentTheme->waterfallDestroy.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ThemeMgr::mgr.currentTheme->waterfallHover.r, ThemeMgr::mgr.currentTheme->waterfallHover.g, ThemeMgr::mgr.currentTheme->waterfallHover.b, 0, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
} else {
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ThemeMgr::mgr.currentTheme->waterfallNew.r, ThemeMgr::mgr.currentTheme->waterfallNew.g, ThemeMgr::mgr.currentTheme->waterfallNew.b, 0, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
glContext->DrawFreqSelector(mouseTracker.getMouseX(), ((isNew && lastActiveDemodulator) || (!lastActiveDemodulator) )?currentTheme->waterfallNew:currentTheme->waterfallHover, 0, currentCenterFreq, currentBandwidth);
|
||||
} else {
|
||||
if (lastActiveDemodulator) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
glContext->DrawDemod(activeDemodulator, ThemeMgr::mgr.currentTheme->waterfallHover.r, ThemeMgr::mgr.currentTheme->waterfallHover.g, ThemeMgr::mgr.currentTheme->waterfallHover.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawDemod(activeDemodulator, currentTheme->waterfallHover, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (activeDemodulator) {
|
||||
glContext->DrawDemod(activeDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawDemod(activeDemodulator, currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
if (lastActiveDemodulator) {
|
||||
glContext->DrawDemod(lastActiveDemodulator, ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawDemod(lastActiveDemodulator, currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +187,7 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
if (activeDemodulator == demods[i] || lastActiveDemodulator == demods[i]) {
|
||||
continue;
|
||||
}
|
||||
glContext->DrawDemod(demods[i], ThemeMgr::mgr.currentTheme->waterfallHighlight.r, ThemeMgr::mgr.currentTheme->waterfallHighlight.g, ThemeMgr::mgr.currentTheme->waterfallHighlight.b, currentCenterFreq, currentBandwidth);
|
||||
glContext->DrawDemod(demods[i], currentTheme->waterfallHighlight, currentCenterFreq, currentBandwidth);
|
||||
}
|
||||
|
||||
glContext->EndDraw();
|
||||
@ -811,7 +804,25 @@ void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
|
||||
}
|
||||
} else if (dragState == WF_DRAG_RANGE) {
|
||||
float width = mouseTracker.getOriginDeltaMouseX();
|
||||
float pos = mouseTracker.getOriginMouseX() + width / 2.0;
|
||||
|
||||
float pos;
|
||||
int last_type = mgr->getLastDemodulatorType();
|
||||
|
||||
if (last_type == DEMOD_TYPE_LSB || last_type == DEMOD_TYPE_USB) {
|
||||
float pos1 = mouseTracker.getOriginMouseX();
|
||||
float pos2 = mouseTracker.getMouseX();
|
||||
|
||||
if (pos2 < pos1) {
|
||||
float tmp = pos1;
|
||||
pos1 = pos2;
|
||||
pos2 = tmp;
|
||||
}
|
||||
|
||||
pos = (last_type == DEMOD_TYPE_LSB)?pos2:pos1;
|
||||
width *= 2;
|
||||
} else {
|
||||
pos = mouseTracker.getOriginMouseX() + width / 2.0;
|
||||
}
|
||||
|
||||
long long input_center_freq = getCenterFrequency();
|
||||
long long freq = input_center_freq - (long long) (0.5 * (float) getBandwidth()) + (long long) ((float) pos * (float) getBandwidth());
|
||||
|
Loading…
x
Reference in New Issue
Block a user