The quest continues, almost done, but have an idea to rework GLFont.drawString() completly, TODO next time

This commit is contained in:
vsonnier
2016-06-22 21:21:32 +02:00
parent 9962e606a6
commit 83b62cddeb
8 changed files with 49 additions and 20 deletions
+16 -7
View File
@@ -385,6 +385,7 @@ GLTextPanel::GLTextPanel() : GLPanel() {
coord = GLPANEL_Y_UP;
horizAlign = GLFont::GLFONT_ALIGN_CENTER;
vertAlign = GLFont::GLFONT_ALIGN_CENTER;
useNativeFont = true;
}
void GLTextPanel::drawPanelContents() {
@@ -393,10 +394,14 @@ 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();
//we must negate it here to compute "user" font selection.
float pdimy = pdim.y;
if (!useNativeFont) {
pdimy /= GLFont::getScaleFactor();
}
if (pdimy <= 16) {
if (pdimy <= 14) {
sz = GLFont::GLFONT_SIZE12;
} else if (pdimy <= 18) {
@@ -410,7 +415,6 @@ void GLTextPanel::drawPanelContents() {
}
else if (pdimy <= 32) {
sz = GLFont::GLFONT_SIZE27;
}
else if (pdimy <= 36) {
sz = GLFont::GLFONT_SIZE32;
@@ -437,14 +441,19 @@ void GLTextPanel::drawPanelContents() {
}
GLFont::getFont(sz).drawString(textVal, mid, mid, horizAlign, vertAlign, (int)pdim.x, (int)pdim.y);
if (useNativeFont) {
GLFont::getRawFont(sz).drawString(textVal, mid, mid, horizAlign, vertAlign, (int)pdim.x, (int)pdim.y);
}
else {
GLFont::getFont(sz).drawString(textVal, mid, mid, horizAlign, vertAlign, (int)pdim.x, (int)pdim.y);
}
}
void GLTextPanel::setText(std::string text, GLFont::Align hAlign, GLFont::Align vAlign) {
void GLTextPanel::setText(std::string text, GLFont::Align hAlign, GLFont::Align vAlign, bool useNative) {
textVal = text;
horizAlign = hAlign;
vertAlign = vAlign;
useNativeFont = useNative;
}
std::string GLTextPanel::getText() {
+3 -1
View File
@@ -99,11 +99,13 @@ private:
std::string textVal;
GLFont::Align horizAlign;
GLFont::Align vertAlign;
boolean useNativeFont;
public:
GLTextPanel();
void drawPanelContents();
void setText(std::string text, GLFont::Align hAlign = GLFont::GLFONT_ALIGN_CENTER, GLFont::Align vAlign = GLFont::GLFONT_ALIGN_CENTER);
void setText(std::string text, GLFont::Align hAlign = GLFont::GLFONT_ALIGN_CENTER, GLFont::Align vAlign = GLFont::GLFONT_ALIGN_CENTER , bool useNativeFont = false);
std::string getText();
};