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); glLineWidth(1.0);
if (showDb) { if (showDb) {
float dbPanelWidth = (1.0/viewWidth)*75.0; float dbPanelWidth = (1.0 / viewWidth)*75.0 * GLFont::getScaleFactor();
float dbPanelHeight = (1.0/viewHeight)*14.0; float dbPanelHeight = (1.0/viewHeight)*14.0 * GLFont::getScaleFactor();
std::stringstream ssLabel(""); std::stringstream ssLabel("");
@ -276,6 +276,7 @@ void SpectrumPanel::drawPanelContents() {
dbPanelCeil.setText(ssLabel.str(), GLFont::GLFONT_ALIGN_RIGHT); dbPanelCeil.setText(ssLabel.str(), GLFont::GLFONT_ALIGN_RIGHT);
dbPanelCeil.setSize(dbPanelWidth, dbPanelHeight); dbPanelCeil.setSize(dbPanelWidth, dbPanelHeight);
dbPanelCeil.setPosition(-1.0 + dbPanelWidth, 1.0 - dbPanelHeight); dbPanelCeil.setPosition(-1.0 + dbPanelWidth, 1.0 - dbPanelHeight);
ssLabel.str(""); ssLabel.str("");
if (getCeilValue() != getFloorValue() && fftSize) { if (getCeilValue() != getFloorValue() && fftSize) {

View File

@ -391,24 +391,48 @@ void GLTextPanel::drawPanelContents() {
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
GLFont::GLFontSize sz; 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; sz = GLFont::GLFONT_SIZE12;
} else if (pdim.y <= 18) { } else if (pdimy <= 18) {
sz = GLFont::GLFONT_SIZE16; sz = GLFont::GLFONT_SIZE16;
} else if(pdim.y <= 24) { } else if(pdimy <= 24) {
sz = GLFont::GLFONT_SIZE18; sz = GLFont::GLFONT_SIZE18;
} else if(pdim.y <= 32) { }else if (pdimy <= 27) {
sz = GLFont::GLFONT_SIZE24; 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; 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; sz = GLFont::GLFONT_SIZE48;
} }

View File

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

View File

@ -17,7 +17,7 @@ static std::wstring getExePath(void)
#define RES_FOLDER "" #define RES_FOLDER ""
#endif #endif
#define GC_PERIOD 50 #define GC_DRAW_COUNT_PERIOD 50
#define GC_DRAW_COUNT_LIMIT 10 #define GC_DRAW_COUNT_LIMIT 10
GLFontStringCache::GLFontStringCache() { GLFontStringCache::GLFontStringCache() {
@ -57,7 +57,7 @@ GLFont::GLFontSize GLFont::userFontZoomMapping[GLFont::GLFontSize::GLFONT_SIZE_M
GLFont::GLFontSize::GLFONT_SIZE96 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; 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); std::lock_guard<std::mutex> lock(cache_busy);
if (gcCounter > GC_PERIOD) { if (gcCounter > GC_DRAW_COUNT_PERIOD) {
doCacheGC(); doCacheGC();
gcCounter = 0; gcCounter = 0;
@ -837,34 +837,33 @@ GLFont &GLFont::getFont(GLFontSize esize) {
void GLFont::setScale(GLFontScale scale) { void GLFont::setScale(GLFontScale scale) {
//By default, populate with normal font (1:1 matching) then overrides //safety vs. inputs
//0) Normal: if (scale < GLFONT_SCALE_NORMAL || scale > GLFONT_SCALE_LARGE) {
scale = GLFontScale::GLFONT_SCALE_NORMAL;
}
std::lock_guard<std::mutex> lock(g_userFontZoomMappingMutex); std::lock_guard<std::mutex> lock(g_userFontZoomMappingMutex);
//Normal font (1:1 matching)
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE12; if (scale == GLFontScale::GLFONT_SCALE_NORMAL) {
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;
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 //override depending of zoom level:
if (currentScaleFactor < GLFONT_SCALE_NORMAL || currentScaleFactor > GLFONT_SCALE_LARGE) { //Medium : more or less 1.5 x
currentScaleFactor = GLFontScale::GLFONT_SCALE_NORMAL;
} }
else if (scale == GLFontScale::GLFONT_SCALE_MEDIUM) {
//override depending of zoom level:
//Medium : more or less 1.5 x
if (currentScaleFactor == GLFontScale::GLFONT_SCALE_MEDIUM) {
userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE18; userFontZoomMapping[GLFont::GLFONT_SIZE12] = GLFont::GLFONT_SIZE18;
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE24; 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_SIZE36] = GLFont::GLFONT_SIZE48;
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE72; userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE72;
userFontZoomMapping[GLFont::GLFONT_SIZE64] = GLFont::GLFONT_SIZE96; 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 //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_SIZE12] = GLFont::GLFONT_SIZE24;
userFontZoomMapping[GLFont::GLFONT_SIZE16] = GLFont::GLFONT_SIZE32; 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_SIZE32] = GLFont::GLFONT_SIZE64;
userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE72; userFontZoomMapping[GLFont::GLFONT_SIZE36] = GLFont::GLFONT_SIZE72;
userFontZoomMapping[GLFont::GLFONT_SIZE48] = GLFont::GLFONT_SIZE96; 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 //Flush all the GC stuff
clearAllCaches(); clearAllCaches();
@ -895,8 +905,22 @@ void GLFont::setScale(GLFontScale scale) {
GLFont::GLFontScale GLFont::getScale() { GLFont::GLFontScale GLFont::getScale() {
std::lock_guard<std::mutex> lock(g_userFontZoomMappingMutex); return currentScale.load();
}
return currentScaleFactor;
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(); 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. //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); 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. //which map a user-requested font to a final one depending of the zoom level.
static GLFontSize userFontZoomMapping[GLFontSize::GLFONT_SIZE_MAX]; static GLFontSize userFontZoomMapping[GLFontSize::GLFONT_SIZE_MAX];
static GLFontScale currentScaleFactor; static std::atomic<GLFontScale> currentScale;
//load a given font file, (lazy loading) //load a given font file, (lazy loading)
void loadFontOnce(); void loadFontOnce();