diff --git a/src/panel/MeterPanel.cpp b/src/panel/MeterPanel.cpp index f43cb77..54cbe12 100644 --- a/src/panel/MeterPanel.cpp +++ b/src/panel/MeterPanel.cpp @@ -148,32 +148,28 @@ void MeterPanel::drawPanelContents() { glGetIntegerv( GL_VIEWPORT, vp); - float viewHeight = (float) vp[3]; + double viewHeight = vp[3]; CubicVR::vec4 t = CubicVR::mat4::vec4_multiply(CubicVR::vec4(0,0.5,0,1), transform); CubicVR::vec4 b = CubicVR::mat4::vec4_multiply(CubicVR::vec4(0,-0.5,0,1), transform); - float hScale = t.y-b.y; + double hScale = t.y-b.y; - viewHeight = round(viewHeight * hScale); + viewHeight = viewHeight * hScale; - float labelHeight = 24.0f; - float labelPad = 8.0f; + double labelHeight = GLFont::getScaledPx(18, GLFont::getScaleFactor()); + double labelPad = 8.0; - if (viewHeight > 400.0f) { - labelHeight = 32.0f; - } - - float pScale = (1.0f/viewHeight); + double pScale = (1.0/viewHeight); RGBA4f c1, c2; - bgPanel.setSize(1.0f, 1.0f - pScale * (labelHeight + labelPad * 2.0f)); + bgPanel.setSize(1.0f, 1.0 - pScale * (labelHeight + labelPad * 2.0)); - valuePanel.setPosition(0.0f, (pScale * (labelHeight / 2.0f + labelPad) ) - 1.0f); - valuePanel.setSize(1.0f, pScale*labelHeight); + valuePanel.setPosition(0.0, (pScale * (labelHeight / 2.0 + labelPad) ) - 1.0); + valuePanel.setSize(1.0, pScale*labelHeight); - labelPanel.setPosition(0.0f, 1.0f - (pScale * (labelHeight / 2.0f + labelPad))); - labelPanel.setSize(1.0f, pScale*labelHeight); + labelPanel.setPosition(0.0, 1.0 - (pScale * (labelHeight / 2.0 + labelPad))); + labelPanel.setSize(1.0, pScale*labelHeight); c1 = ThemeMgr::mgr.currentTheme->generalBackground; c2 = ThemeMgr::mgr.currentTheme->generalBackground * 0.5; diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 36f4616..ee20ef9 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -857,6 +857,30 @@ double GLFont::getScaleFactor() { return 1.0; } +int GLFont::getScaledPx(int basicFontSize, double scaleFactor) { + //try to align on an integer pixel size if the targetSize font is available + int targetSize = round(basicFontSize * scaleFactor); + int resultIndex = 0; + + fonts[0].loadFontOnce(); + + for (int i = 0; i < GLFONT_SIZE_MAX - 1; i++) { + + fonts[i + 1].loadFontOnce(); + + if (fonts[i + 1].pixHeight <= targetSize) { + resultIndex = i + 1; + } + else { + break; + } + } //end for + + // return font height px + return fonts[resultIndex].pixHeight; +} + + GLFont::Drawer::Drawer(int basicFontSize, double scaleFactor) { //Selection of the final font: scan GLFont::fonts to find the biggest font such as diff --git a/src/util/GLFont.h b/src/util/GLFont.h index 13d5281..3feac86 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -112,6 +112,9 @@ public: //Mean current scale factor: 1.0 in normal, 1.5 medium, 2.0 for large static double getScaleFactor(); + + //Return a valid font px height given the font size and scale factor + static int getScaledPx(int basicFontSize, double scaleFactor); private: