FIX out-of-bounds dB display

This commit is contained in:
vsonnier 2016-06-22 19:04:59 +02:00
parent 85178095ca
commit 9962e606a6
5 changed files with 94 additions and 40 deletions

View File

@ -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("");
@ -277,6 +277,7 @@ void SpectrumPanel::drawPanelContents() {
dbPanelCeil.setSize(dbPanelWidth, dbPanelHeight);
dbPanelCeil.setPosition(-1.0 + dbPanelWidth, 1.0 - dbPanelHeight);
ssLabel.str("");
if (getCeilValue() != getFloorValue() && fftSize) {
ssLabel << (20.0 * log10(2.0*(getFloorValue())/(double)fftSize)) << "dB";

View File

@ -392,23 +392,47 @@ void GLTextPanel::drawPanelContents() {
GLFont::GLFontSize sz;
//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 (pdim.y <= 16) {
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;
}

View File

@ -62,6 +62,8 @@ public:
GLPanel();
void setPosition(float x, float y);
void setSize(float w, float h);
float getWidth();
float getHeight();

View File

@ -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,10 +837,16 @@ 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);
//Normal font (1:1 matching)
if (scale == GLFontScale::GLFONT_SCALE_NORMAL) {
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE12;
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE16;
@ -854,17 +860,10 @@ void GLFont::setScale(GLFontScale scale) {
userFontZoomMapping[GLFont::GLFONT_SIZE72] = GLFont::GLFONT_SIZE72;
userFontZoomMapping[GLFont::GLFONT_SIZE96] = GLFont::GLFONT_SIZE96;
currentScaleFactor = scale;
//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
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,16 +890,37 @@ 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();
}
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;
}

View File

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