mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-25 21:28:38 -05:00
FIX out-of-bounds dB display
This commit is contained in:
parent
85178095ca
commit
9962e606a6
@ -265,8 +265,8 @@ void SpectrumPanel::drawPanelContents() {
|
||||
glLineWidth(1.0);
|
||||
|
||||
if (showDb) {
|
||||
float dbPanelWidth = (1.0/viewWidth)*75.0;
|
||||
float dbPanelHeight = (1.0/viewHeight)*14.0;
|
||||
float dbPanelWidth = (1.0 / viewWidth)*75.0 * GLFont::getScaleFactor();
|
||||
float dbPanelHeight = (1.0/viewHeight)*14.0 * GLFont::getScaleFactor();
|
||||
|
||||
|
||||
std::stringstream ssLabel("");
|
||||
@ -276,6 +276,7 @@ void SpectrumPanel::drawPanelContents() {
|
||||
dbPanelCeil.setText(ssLabel.str(), GLFont::GLFONT_ALIGN_RIGHT);
|
||||
dbPanelCeil.setSize(dbPanelWidth, dbPanelHeight);
|
||||
dbPanelCeil.setPosition(-1.0 + dbPanelWidth, 1.0 - dbPanelHeight);
|
||||
|
||||
|
||||
ssLabel.str("");
|
||||
if (getCeilValue() != getFloorValue() && fftSize) {
|
||||
|
@ -391,24 +391,48 @@ void GLTextPanel::drawPanelContents() {
|
||||
glColor4f(1, 1, 1, 1.0);
|
||||
|
||||
GLFont::GLFontSize sz;
|
||||
|
||||
|
||||
if (pdim.y <= 16) {
|
||||
//beware here: the really applied font may have been scaled up compared to the "user" requested one, so that
|
||||
//we must negate it here to compute "user" font selection.
|
||||
float pdimy = pdim.y / GLFont::getScaleFactor();
|
||||
|
||||
if (pdimy <= 16) {
|
||||
sz = GLFont::GLFONT_SIZE12;
|
||||
|
||||
} else if (pdim.y <= 18) {
|
||||
} else if (pdimy <= 18) {
|
||||
sz = GLFont::GLFONT_SIZE16;
|
||||
|
||||
} else if(pdim.y <= 24) {
|
||||
} else if(pdimy <= 24) {
|
||||
sz = GLFont::GLFONT_SIZE18;
|
||||
|
||||
} else if(pdim.y <= 32) {
|
||||
}else if (pdimy <= 27) {
|
||||
sz = GLFont::GLFONT_SIZE24;
|
||||
}
|
||||
else if (pdimy <= 32) {
|
||||
sz = GLFont::GLFONT_SIZE27;
|
||||
|
||||
} else if(pdim.y <= 48) {
|
||||
}
|
||||
else if (pdimy <= 36) {
|
||||
sz = GLFont::GLFONT_SIZE32;
|
||||
|
||||
} else {
|
||||
}
|
||||
else if (pdimy <= 48) {
|
||||
sz = GLFont::GLFONT_SIZE36;
|
||||
|
||||
}
|
||||
else if (pdimy <= 64) {
|
||||
sz = GLFont::GLFONT_SIZE48;
|
||||
|
||||
}
|
||||
else if (pdimy <= 72) {
|
||||
sz = GLFont::GLFONT_SIZE64;
|
||||
|
||||
}
|
||||
else if (pdimy <= 96) {
|
||||
sz = GLFont::GLFONT_SIZE72;
|
||||
|
||||
}
|
||||
else {
|
||||
sz = GLFont::GLFONT_SIZE48;
|
||||
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
GLPanel();
|
||||
|
||||
void setPosition(float x, float y);
|
||||
|
||||
|
||||
void setSize(float w, float h);
|
||||
float getWidth();
|
||||
float getHeight();
|
||||
|
@ -17,7 +17,7 @@ static std::wstring getExePath(void)
|
||||
#define RES_FOLDER ""
|
||||
#endif
|
||||
|
||||
#define GC_PERIOD 50
|
||||
#define GC_DRAW_COUNT_PERIOD 50
|
||||
#define GC_DRAW_COUNT_LIMIT 10
|
||||
|
||||
GLFontStringCache::GLFontStringCache() {
|
||||
@ -57,7 +57,7 @@ GLFont::GLFontSize GLFont::userFontZoomMapping[GLFont::GLFontSize::GLFONT_SIZE_M
|
||||
GLFont::GLFontSize::GLFONT_SIZE96
|
||||
};
|
||||
|
||||
GLFont::GLFontScale GLFont::currentScaleFactor = GLFont::GLFontScale::GLFONT_SCALE_NORMAL;
|
||||
std::atomic<GLFont::GLFontScale> GLFont::currentScale{ GLFont::GLFontScale::GLFONT_SCALE_NORMAL };
|
||||
|
||||
std::mutex GLFont::g_userFontZoomMappingMutex;
|
||||
|
||||
@ -520,7 +520,7 @@ void GLFont::drawString(const std::wstring& str, float xpos, float ypos, Align h
|
||||
|
||||
std::lock_guard<std::mutex> lock(cache_busy);
|
||||
|
||||
if (gcCounter > GC_PERIOD) {
|
||||
if (gcCounter > GC_DRAW_COUNT_PERIOD) {
|
||||
|
||||
doCacheGC();
|
||||
gcCounter = 0;
|
||||
@ -837,34 +837,33 @@ GLFont &GLFont::getFont(GLFontSize esize) {
|
||||
|
||||
void GLFont::setScale(GLFontScale scale) {
|
||||
|
||||
//By default, populate with normal font (1:1 matching) then overrides
|
||||
//0) Normal:
|
||||
//safety vs. inputs
|
||||
if (scale < GLFONT_SCALE_NORMAL || scale > GLFONT_SCALE_LARGE) {
|
||||
|
||||
scale = GLFontScale::GLFONT_SCALE_NORMAL;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(g_userFontZoomMappingMutex);
|
||||
|
||||
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE12;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE16;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE18] = GLFont::GLFONT_SIZE18;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE24] = GLFont::GLFONT_SIZE24;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE27] = GLFont::GLFONT_SIZE27;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE32] = GLFont::GLFONT_SIZE32;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE36;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE48;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE64;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE72] = GLFont::GLFONT_SIZE72;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE96] = GLFont::GLFONT_SIZE96;
|
||||
//Normal font (1:1 matching)
|
||||
if (scale == GLFontScale::GLFONT_SCALE_NORMAL) {
|
||||
|
||||
currentScaleFactor = scale;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE12;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE16;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE18] = GLFont::GLFONT_SIZE18;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE24] = GLFont::GLFONT_SIZE24;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE27] = GLFont::GLFONT_SIZE27;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE32] = GLFont::GLFONT_SIZE32;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE36;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE48;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE64;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE72] = GLFont::GLFONT_SIZE72;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE96] = GLFont::GLFONT_SIZE96;
|
||||
|
||||
//safety vs. inputs
|
||||
if (currentScaleFactor < GLFONT_SCALE_NORMAL || currentScaleFactor > GLFONT_SCALE_LARGE) {
|
||||
|
||||
currentScaleFactor = GLFontScale::GLFONT_SCALE_NORMAL;
|
||||
//override depending of zoom level:
|
||||
//Medium : more or less 1.5 x
|
||||
}
|
||||
|
||||
//override depending of zoom level:
|
||||
//Medium : more or less 1.5 x
|
||||
if (currentScaleFactor == GLFontScale::GLFONT_SCALE_MEDIUM) {
|
||||
else if (scale == GLFontScale::GLFONT_SCALE_MEDIUM) {
|
||||
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE18;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE24;
|
||||
@ -875,9 +874,13 @@ void GLFont::setScale(GLFontScale scale) {
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE48;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE72;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE96;
|
||||
|
||||
//too big: not-scaled properly and saturating:
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE72] = GLFont::GLFONT_SIZE96;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE96] = GLFont::GLFONT_SIZE96;
|
||||
}
|
||||
//Large : 2x normal, more or less
|
||||
else if (currentScaleFactor == GLFontScale::GLFONT_SCALE_LARGE) {
|
||||
else if (scale == GLFontScale::GLFONT_SCALE_LARGE) {
|
||||
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE24;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE32;
|
||||
@ -887,7 +890,14 @@ void GLFont::setScale(GLFontScale scale) {
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE32] = GLFont::GLFONT_SIZE64;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE72;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE96;
|
||||
|
||||
//too big: not-scaled properly or saturating:
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE96;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE72] = GLFont::GLFONT_SIZE96;
|
||||
userFontZoomMapping[GLFont::GLFONT_SIZE96] = GLFont::GLFONT_SIZE96;
|
||||
}
|
||||
|
||||
currentScale.store(scale);
|
||||
|
||||
//Flush all the GC stuff
|
||||
clearAllCaches();
|
||||
@ -895,8 +905,22 @@ void GLFont::setScale(GLFontScale scale) {
|
||||
|
||||
GLFont::GLFontScale GLFont::getScale() {
|
||||
|
||||
std::lock_guard<std::mutex> lock(g_userFontZoomMappingMutex);
|
||||
|
||||
return currentScaleFactor;
|
||||
return currentScale.load();
|
||||
}
|
||||
|
||||
double GLFont::getScaleFactor() {
|
||||
|
||||
GLFontScale scale = currentScale.load();
|
||||
|
||||
if (scale == GLFONT_SCALE_MEDIUM) {
|
||||
|
||||
return 1.5;
|
||||
}
|
||||
else if (scale == GLFONT_SCALE_LARGE) {
|
||||
|
||||
return 2.0;
|
||||
}
|
||||
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,9 @@ public:
|
||||
|
||||
static GLFontScale getScale();
|
||||
|
||||
//Mean current scale factor: 1.0 in normal, 1.5 medium, 2.0 for large
|
||||
static double getScaleFactor();
|
||||
|
||||
//Public drawing font, 16 bit char version.
|
||||
void drawString(const std::wstring& str, float xpos, float ypos, Align hAlign = GLFONT_ALIGN_LEFT, Align vAlign = GLFONT_ALIGN_TOP, int vpx=0, int vpy=0, bool cacheable = false);
|
||||
|
||||
@ -128,7 +131,7 @@ private:
|
||||
//which map a user-requested font to a final one depending of the zoom level.
|
||||
static GLFontSize userFontZoomMapping[GLFontSize::GLFONT_SIZE_MAX];
|
||||
|
||||
static GLFontScale currentScaleFactor;
|
||||
static std::atomic<GLFontScale> currentScale;
|
||||
|
||||
//load a given font file, (lazy loading)
|
||||
void loadFontOnce();
|
||||
|
Loading…
Reference in New Issue
Block a user