mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-29 23:28:39 -05:00
Move static fonts to GLFont
This commit is contained in:
parent
8ccb060237
commit
b28c8dbc3e
@ -8,6 +8,9 @@
|
|||||||
#define RES_FOLDER ""
|
#define RES_FOLDER ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
GLFont GLFont::fonts[GLFONT_MAX];
|
||||||
|
|
||||||
GLFontChar::GLFontChar() :
|
GLFontChar::GLFontChar() :
|
||||||
id(0), x(0), y(0), width(0), height(0), xoffset(0), yoffset(0), xadvance(0), aspect(1), index(0) {
|
id(0), x(0), y(0), width(0), height(0), xoffset(0), yoffset(0), xadvance(0), aspect(1), index(0) {
|
||||||
|
|
||||||
@ -475,3 +478,38 @@ void GLFont::drawString(std::string str, float xpos, float ypos, int pxHeight, A
|
|||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GLFont &GLFont::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;
|
||||||
|
default:
|
||||||
|
fontName = "vera_sans_mono12.fnt";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fonts[esize].loadFont(fontName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fonts[esize];
|
||||||
|
}
|
||||||
|
@ -56,6 +56,9 @@ public:
|
|||||||
enum Align {
|
enum Align {
|
||||||
GLFONT_ALIGN_LEFT, GLFONT_ALIGN_RIGHT, GLFONT_ALIGN_CENTER, GLFONT_ALIGN_TOP, GLFONT_ALIGN_BOTTOM
|
GLFONT_ALIGN_LEFT, GLFONT_ALIGN_RIGHT, GLFONT_ALIGN_CENTER, GLFONT_ALIGN_TOP, GLFONT_ALIGN_BOTTOM
|
||||||
};
|
};
|
||||||
|
enum GLFontSize {
|
||||||
|
GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX
|
||||||
|
};
|
||||||
|
|
||||||
GLFont();
|
GLFont();
|
||||||
~GLFont();
|
~GLFont();
|
||||||
@ -65,6 +68,9 @@ public:
|
|||||||
float getStringWidth(std::string str, float size, float viewAspect);
|
float getStringWidth(std::string str, float size, float viewAspect);
|
||||||
void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP);
|
void drawString(std::string str, float xpos, float ypos, int pxHeight, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP);
|
||||||
|
|
||||||
|
static GLFont fonts[GLFONT_MAX];
|
||||||
|
static GLFont &getFont(GLFontSize esize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string nextParam(std::istringstream &str);
|
std::string nextParam(std::istringstream &str);
|
||||||
std::string getParamKey(std::string param_str);
|
std::string getParamKey(std::string param_str);
|
||||||
|
@ -29,12 +29,12 @@ void ModeSelectorContext::DrawSelector(std::string label, int c, int cMax, bool
|
|||||||
float viewHeight = (float) vp[3];
|
float viewHeight = (float) vp[3];
|
||||||
float viewWidth = (float) vp[2];
|
float viewWidth = (float) vp[2];
|
||||||
|
|
||||||
PrimaryGLContext::GLFontSize fontSize = GLFONT_SIZE16;
|
GLFont::GLFontSize fontSize = GLFont::GLFONT_SIZE16;
|
||||||
|
|
||||||
int fontHeight = 16;
|
int fontHeight = 16;
|
||||||
|
|
||||||
if (viewWidth < 30) {
|
if (viewWidth < 30) {
|
||||||
fontSize = GLFONT_SIZE12;
|
fontSize = GLFont::GLFONT_SIZE12;
|
||||||
fontHeight = 12;
|
fontHeight = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ void ModeSelectorContext::DrawSelector(std::string label, int c, int cMax, bool
|
|||||||
glColor4f(0, 0, 0, a);
|
glColor4f(0, 0, 0, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFont(fontSize).drawString(label, 0.0, y + height / 2.0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(fontSize).drawString(label, 0.0, y + height / 2.0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModeSelectorContext::DrawEnd() {
|
void ModeSelectorContext::DrawEnd() {
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
#include "AppFrame.h"
|
#include "AppFrame.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
GLFont PrimaryGLContext::fonts[GLFONT_MAX];
|
|
||||||
|
|
||||||
wxString PrimaryGLContext::glGetwxString(GLenum name) {
|
wxString PrimaryGLContext::glGetwxString(GLenum name) {
|
||||||
const GLubyte *v = glGetString(name);
|
const GLubyte *v = glGetString(name);
|
||||||
if (v == 0) {
|
if (v == 0) {
|
||||||
@ -61,40 +59,6 @@ PrimaryGLContext::PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContex
|
|||||||
//#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
default:
|
|
||||||
fontName = "vera_sans_mono12.fnt";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fonts[esize].loadFont(fontName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fonts[esize];
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, RGB color, long long center_freq, long long srate) {
|
void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, RGB color, long long center_freq, long long srate) {
|
||||||
if (!demod) {
|
if (!demod) {
|
||||||
return;
|
return;
|
||||||
@ -165,11 +129,11 @@ void PrimaryGLContext::DrawDemodInfo(DemodulatorInstance *demod, RGB color, long
|
|||||||
glColor4f(1.0, 1.0, 1.0, 0.8);
|
glColor4f(1.0, 1.0, 1.0, 0.8);
|
||||||
|
|
||||||
if (demod->getDemodulatorType() == DEMOD_TYPE_USB) {
|
if (demod->getDemodulatorType() == DEMOD_TYPE_USB) {
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_LEFT, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
} else if (demod->getDemodulatorType() == DEMOD_TYPE_LSB) {
|
} else if (demod->getDemodulatorType() == DEMOD_TYPE_LSB) {
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
} else {
|
} else {
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demod->getLabel(), uxPos, hPos, 16, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
@ -264,10 +228,10 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGB color, long lon
|
|||||||
}
|
}
|
||||||
|
|
||||||
glColor3f(0, 0, 0);
|
glColor3f(0, 0, 0);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, -1.0 + hPos - yOfs, 16, demodAlign,
|
GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, -1.0 + hPos - yOfs, 16, demodAlign,
|
||||||
GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::GLFONT_ALIGN_CENTER);
|
||||||
glColor3f(0.8, 0.8, 0.8);
|
glColor3f(0.8, 0.8, 0.8);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, 16, demodAlign, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, 16, demodAlign, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@
|
|||||||
|
|
||||||
class PrimaryGLContext: public wxGLContext {
|
class PrimaryGLContext: public wxGLContext {
|
||||||
public:
|
public:
|
||||||
enum GLFontSize {
|
|
||||||
GLFONT_SIZE12, GLFONT_SIZE16, GLFONT_SIZE18, GLFONT_SIZE24, GLFONT_SIZE32, GLFONT_SIZE48, GLFONT_MAX
|
|
||||||
};
|
|
||||||
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
|
PrimaryGLContext(wxGLCanvas *canvas, wxGLContext *sharedContext);
|
||||||
|
|
||||||
static wxString glGetwxString(GLenum name);
|
static wxString glGetwxString(GLenum name);
|
||||||
@ -29,12 +26,9 @@ public:
|
|||||||
void DrawDemod(DemodulatorInstance *demod, RGB color, long long center_freq = -1, long long srate = 0);
|
void DrawDemod(DemodulatorInstance *demod, RGB color, long long center_freq = -1, long long srate = 0);
|
||||||
void DrawDemodInfo(DemodulatorInstance *demod, RGB color, long long center_freq = -1, long long srate = 0);
|
void DrawDemodInfo(DemodulatorInstance *demod, RGB color, long long center_freq = -1, long long srate = 0);
|
||||||
|
|
||||||
static GLFont &getFont(GLFontSize esize);
|
|
||||||
|
|
||||||
void setHoverAlpha(float hoverAlpha);
|
void setHoverAlpha(float hoverAlpha);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static GLFont fonts[GLFONT_MAX];
|
|
||||||
DemodulatorThreadParameters defaultDemodParams;
|
DemodulatorThreadParameters defaultDemodParams;
|
||||||
float hoverAlpha;
|
float hoverAlpha;
|
||||||
};
|
};
|
||||||
|
@ -81,9 +81,9 @@ void ScopeContext::Plot(std::vector<float> &points, bool stereo, bool ppmMode) {
|
|||||||
|
|
||||||
glColor3f(0.65, 0.65, 0.65);
|
glColor3f(0.65, 0.65, 0.65);
|
||||||
|
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString(ppmMode?"Device PPM":"Frequency", -0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(ppmMode?"Device PPM":"Frequency", -0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString("Bandwidth", 0.0, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString("Bandwidth", 0.0, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString("Center Frequency", 0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString("Center Frequency", 0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
|
|
||||||
|
|
||||||
if (stereo) {
|
if (stereo) {
|
||||||
@ -151,7 +151,7 @@ void ScopeContext::DrawDeviceName(std::string deviceName) {
|
|||||||
float hPos = (float) (viewHeight - 20) / viewHeight;
|
float hPos = (float) (viewHeight - 20) / viewHeight;
|
||||||
|
|
||||||
glColor3f(0.65, 0.65, 0.65);
|
glColor3f(0.65, 0.65, 0.65);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString(deviceName.c_str(), 1.0, hPos, 12, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(deviceName.c_str(), 1.0, hPos, 12, GLFont::GLFONT_ALIGN_RIGHT, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScopeContext::DrawEnd() {
|
void ScopeContext::DrawEnd() {
|
||||||
|
@ -147,7 +147,7 @@ void SpectrumContext::Draw(std::vector<float> &points, long long freq, int bandw
|
|||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glColor4f(ThemeMgr::mgr.currentTheme->text.r, ThemeMgr::mgr.currentTheme->text.g, ThemeMgr::mgr.currentTheme->text.b,1.0);
|
glColor4f(ThemeMgr::mgr.currentTheme->text.r, ThemeMgr::mgr.currentTheme->text.g, ThemeMgr::mgr.currentTheme->text.b,1.0);
|
||||||
getFont(PrimaryGLContext::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(GLFont::GLFONT_SIZE12).drawString(label.str(), m, hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
|
|
||||||
label.str(std::string());
|
label.str(std::string());
|
||||||
|
|
||||||
|
@ -74,19 +74,19 @@ void TuningContext::DrawTuner(long long freq, int count, float displayPos, float
|
|||||||
freqStr << freq;
|
freqStr << freq;
|
||||||
std::string freqChars = freqStr.str();
|
std::string freqChars = freqStr.str();
|
||||||
|
|
||||||
PrimaryGLContext::GLFontSize fontSize = GLFONT_SIZE24;
|
GLFont::GLFontSize fontSize = GLFont::GLFONT_SIZE24;
|
||||||
int fontHeight = 24;
|
int fontHeight = 24;
|
||||||
|
|
||||||
if (viewHeight < 28) {
|
if (viewHeight < 28) {
|
||||||
fontSize = GLFONT_SIZE18;
|
fontSize = GLFont::GLFONT_SIZE18;
|
||||||
fontHeight = 18;
|
fontHeight = 18;
|
||||||
}
|
}
|
||||||
if (viewHeight < 24) {
|
if (viewHeight < 24) {
|
||||||
fontSize = GLFONT_SIZE16;
|
fontSize = GLFont::GLFONT_SIZE16;
|
||||||
fontHeight = 16;
|
fontHeight = 16;
|
||||||
}
|
}
|
||||||
if (viewHeight < 18) {
|
if (viewHeight < 18) {
|
||||||
fontSize = GLFONT_SIZE12;
|
fontSize = GLFont::GLFONT_SIZE12;
|
||||||
fontHeight = 12;
|
fontHeight = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ void TuningContext::DrawTuner(long long freq, int count, float displayPos, float
|
|||||||
int ofs = count - numChars;
|
int ofs = count - numChars;
|
||||||
for (int i = ofs; i < count; i++) {
|
for (int i = ofs; i < count; i++) {
|
||||||
float xpos = displayPos + (displayWidth / (float) count) * (float) i + ((displayWidth / 2.0) / (float) count);
|
float xpos = displayPos + (displayWidth / (float) count) * (float) i + ((displayWidth / 2.0) / (float) count);
|
||||||
getFont(fontSize).drawString(freqStr.str().substr(i - ofs, 1), xpos, 0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
GLFont::getFont(fontSize).drawString(freqStr.str().substr(i - ofs, 1), xpos, 0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor4f(0.65, 0.65, 0.65, 0.25);
|
glColor4f(0.65, 0.65, 0.65, 0.25);
|
||||||
|
Loading…
Reference in New Issue
Block a user