Added frequency labels, 100khz intervals

This commit is contained in:
Charles J. Cliffe
2014-12-09 21:28:08 -05:00
parent 33e2e18c57
commit 34a6d3f5e0
26 changed files with 1423 additions and 197 deletions
+51 -8
View File
@@ -15,7 +15,7 @@
#include "AppFrame.h"
#include <algorithm>
GLFont *PrimaryGLContext::font = NULL;
GLFont PrimaryGLContext::fonts[GLFONT_MAX];
wxString PrimaryGLContext::glGetwxString(GLenum name) {
const GLubyte *v = glGetString(name);
@@ -58,15 +58,60 @@ PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContex
CheckGLError();
}
GLFont *PrimaryGLContext::getFont() {
if (font == NULL) {
font = new GLFont();
font->loadFont("vera_sans_mono.fnt");
GLFont &PrimaryGLContext::getFont(GLFontSize esize) {
if (!fonts[esize].isLoaded()) {
std::string fontName;
switch (esize) {
case GLFONT_SIZE12: fontName = "vera_sans_mono12.fnt";
break;
case GLFONT_SIZE16: fontName = "vera_sans_mono16.fnt";
break;
case GLFONT_SIZE18: fontName = "vera_sans_mono18.fnt";
break;
case GLFONT_SIZE24: fontName = "vera_sans_mono24.fnt";
break;
case GLFONT_SIZE32: fontName = "vera_sans_mono32.fnt";
break;
case GLFONT_SIZE48: fontName = "vera_sans_mono48.fnt";
break;
}
fonts[esize].loadFont(fontName);
}
return font;
return fonts[esize];
}
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, float r, float g, float b) {
if (!demod) {
return;
}
float uxPos = (float) (demod->getParams().frequency - (wxGetApp().getFrequency() - SRATE / 2)) / (float) SRATE;
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
glColor4f(r, g, b, 0.6);
float ofs = ((float) demod->getParams().bandwidth) / (float) SRATE;
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
glColor4f(r, g, b, 0.2);
glBegin(GL_QUADS);
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);
glEnd();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
if (!demod) {
@@ -108,7 +153,6 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, float r, float g, f
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
void PrimaryGLContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
@@ -150,7 +194,6 @@ void PrimaryGLContext::BeginDraw() {
glLoadIdentity();
}
void PrimaryGLContext::EndDraw() {
glFlush();
+4 -2
View File
@@ -12,6 +12,7 @@
class PrimaryGLContext: public wxGLContext {
public:
enum GLFontSize { GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX };
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
static wxString glGetwxString(GLenum name);
@@ -22,9 +23,10 @@ public:
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1);
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
void DrawDemodInfo(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
static GLFont *getFont();
static GLFont &getFont(GLFontSize esize);
private:
static GLFont *font;
static GLFont fonts[GLFONT_MAX];
};
+1 -1
View File
@@ -67,7 +67,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->DrawDemod(demods[i]);
glContext->DrawDemodInfo(demods[i]);
}
glContext->EndDraw();
+53 -1
View File
@@ -1,6 +1,9 @@
#include "SpectrumContext.h"
#include "SpectrumCanvas.h"
#include "CubicSDR.h"
#include <sstream>
#include <iostream>
SpectrumContext::SpectrumContext(SpectrumCanvas *canvas, wxGLContext *sharedContext) :
PrimaryGLContext(canvas, sharedContext) {
@@ -28,7 +31,56 @@ void SpectrumContext::Draw(std::vector<float> &points) {
glPopMatrix();
}
getFont()->drawString("Welcome to CubicSDR -- This is a test string. 01234567890!@#$%^&*()_[]",0.0,0.0,31,GLFont::GLFONT_ALIGN_CENTER,GLFont::GLFONT_ALIGN_CENTER);
GLint vp[4];
glGetIntegerv( GL_VIEWPORT, vp);
float viewHeight = (float) vp[3];
float leftFreq = (float) wxGetApp().getFrequency() - ((float) SRATE / 2.0);
float rightFreq = leftFreq + (float) SRATE;
float firstMhz = floor(leftFreq / 1000000.0) * 1000000.0;
float mhzStart = ((firstMhz - leftFreq) / (rightFreq - leftFreq)) * 2.0;
float mhzStep = (100000.0 / (rightFreq - leftFreq)) * 2.0;
double currentMhz = trunc(floor(firstMhz / 1000000.0));
std::stringstream label;
label.precision(2);
float hPos = 1.0 - (16.0 / viewHeight);
float lMhzPos = 1.0 - (5.0 / viewHeight);
for (float m = -1.0 + mhzStart, mMax = 1.0 + fabs(mhzStart); m <= mMax; m += mhzStep) {
label << std::fixed << currentMhz;
double fractpart, intpart;
fractpart = modf(currentMhz, &intpart);
if (fractpart < 0.001) {
glLineWidth(4.0);
glColor3f(1.0, 1.0, 1.0);
} else {
glLineWidth(1.0);
glColor3f(0.55, 0.55, 0.55);
}
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2f(m, lMhzPos);
glVertex2f(m, 1);
glEnd();
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
label.str(std::string());
currentMhz += 0.1f;
}
glLineWidth(1.0);
// getFont(PrimaryGLContext::GLFONT_SIZE16).drawString("Welcome to CubicSDR -- This is a test string. 01234567890!@#$%^&*()_[]",0.0,0.0,16,GLFont::GLFONT_ALIGN_CENTER,GLFont::GLFONT_ALIGN_CENTER);
CheckGLError();
}