From 83b62cddeb34d5eeceb8af61aaf02aaf3a1b9c1b Mon Sep 17 00:00:00 2001 From: vsonnier Date: Wed, 22 Jun 2016 21:21:32 +0200 Subject: [PATCH] The quest continues, almost done, but have an idea to rework GLFont.drawString() completly, TODO next time --- src/AppFrame.cpp | 8 ++++---- src/ui/GLPanel.cpp | 23 ++++++++++++++++------- src/ui/GLPanel.h | 4 +++- src/util/GLFont.cpp | 11 +++++++++++ src/util/GLFont.h | 3 +++ src/visual/GainCanvas.cpp | 10 ++++++---- src/visual/ModeSelectorContext.cpp | 7 ++++--- src/visual/TuningContext.cpp | 3 ++- 8 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index f81f09c..6ec2448 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -84,8 +84,8 @@ AppFrame::AppFrame() : demodModeSelector->addChoice("I/Q"); demodModeSelector->setSelection("FM"); demodModeSelector->setHelpTip("Choose modulation type: Frequency Modulation (Hotkey F), Amplitude Modulation (A) and Lower (L), Upper (U), Double Side-Band and more."); - demodModeSelector->SetMinSize(wxSize(40,-1)); - demodModeSelector->SetMaxSize(wxSize(40,-1)); + demodModeSelector->SetMinSize(wxSize(44,-1)); + demodModeSelector->SetMaxSize(wxSize(44,-1)); demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0); #ifdef ENABLE_DIGITAL_LAB @@ -103,8 +103,8 @@ AppFrame::AppFrame() : demodModeSelectorAdv->addChoice("QAM"); demodModeSelectorAdv->addChoice("QPSK"); demodModeSelectorAdv->setHelpTip("Choose advanced modulation types."); - demodModeSelectorAdv->SetMinSize(wxSize(40,-1)); - demodModeSelectorAdv->SetMaxSize(wxSize(40,-1)); + demodModeSelectorAdv->SetMinSize(wxSize(44,-1)); + demodModeSelectorAdv->SetMaxSize(wxSize(44,-1)); demodTray->Add(demodModeSelectorAdv, 3, wxEXPAND | wxALL, 0); #endif diff --git a/src/ui/GLPanel.cpp b/src/ui/GLPanel.cpp index 3a5a105..030e07c 100644 --- a/src/ui/GLPanel.cpp +++ b/src/ui/GLPanel.cpp @@ -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() { diff --git a/src/ui/GLPanel.h b/src/ui/GLPanel.h index b1e3a32..468ee23 100644 --- a/src/ui/GLPanel.h +++ b/src/ui/GLPanel.h @@ -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(); }; diff --git a/src/util/GLFont.cpp b/src/util/GLFont.cpp index 8ed1c9f..54b7457 100644 --- a/src/util/GLFont.cpp +++ b/src/util/GLFont.cpp @@ -834,6 +834,17 @@ GLFont &GLFont::getFont(GLFontSize esize) { return fonts[internalFontSize]; } +GLFont &GLFont::getRawFont(GLFontSize esize) { + + //Do not apply the scaling, really returns the requested font. + + + //load lazily... + fonts[esize].loadFontOnce(); + + return fonts[esize]; +} + void GLFont::setScale(GLFontScale scale) { diff --git a/src/util/GLFont.h b/src/util/GLFont.h index 7d5573f..e96b1c6 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -102,6 +102,9 @@ public: //it will be translated to another font depending of the scale level static GLFont& getFont(GLFontSize esize); + //Return the requested raw font, without applying scaling. + static GLFont &GLFont::getRawFont(GLFontSize esize); + //Called to change the scale of the rendered fonts static void setScale(GLFontScale scale); diff --git a/src/visual/GainCanvas.cpp b/src/visual/GainCanvas.cpp index a7c5240..ac803f8 100644 --- a/src/visual/GainCanvas.cpp +++ b/src/visual/GainCanvas.cpp @@ -116,7 +116,7 @@ void GainCanvas::SetLevel() { gainInfo[panelHit]->levelPanel.setPosition(0.0, (-1.0+(hitResult.y))); gainInfo[panelHit]->current = round(gainInfo[panelHit]->low+(hitResult.y * (gainInfo[panelHit]->high-gainInfo[panelHit]->low))); gainInfo[panelHit]->changed = true; - gainInfo[panelHit]->valuePanel.setText(std::to_string(int(gainInfo[panelHit]->current))); + gainInfo[panelHit]->valuePanel.setText(std::to_string(int(gainInfo[panelHit]->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); } } @@ -179,7 +179,7 @@ void GainCanvas::OnMouseWheelMoved(wxMouseEvent& event) { gInfo->levelPanel.setSize(1.0, levelVal); gInfo->levelPanel.setPosition(0.0, levelVal-1.0); - gInfo->valuePanel.setText(std::to_string(int(gInfo->current))); + gInfo->valuePanel.setText(std::to_string(int(gInfo->current)),GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); } } @@ -290,14 +290,16 @@ void GainCanvas::updateGainUI() { gInfo->labelPanel.setSize(spacing/2.0,(15.0/float(ClientSize.y))); gInfo->labelPanel.setPosition(midPos, -barHeight-(20.0/float(ClientSize.y))); - gInfo->labelPanel.setText(gi->first); + + gInfo->labelPanel.setText(gi->first,GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); gInfo->labelPanel.setFill(GLPanel::GLPANEL_FILL_NONE); bgPanel.addChild(&(gInfo->labelPanel)); gInfo->valuePanel.setSize(spacing/2.0,(15.0/float(ClientSize.y))); gInfo->valuePanel.setPosition(midPos, barHeight+(20.0/float(ClientSize.y))); - gInfo->valuePanel.setText(std::to_string(int(gInfo->current))); + + gInfo->valuePanel.setText(std::to_string(int(gInfo->current)), GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER, true); gInfo->valuePanel.setFill(GLPanel::GLPANEL_FILL_NONE); bgPanel.addChild(&(gInfo->valuePanel)); diff --git a/src/visual/ModeSelectorContext.cpp b/src/visual/ModeSelectorContext.cpp index 35dc6b2..509ad73 100644 --- a/src/visual/ModeSelectorContext.cpp +++ b/src/visual/ModeSelectorContext.cpp @@ -29,10 +29,10 @@ void ModeSelectorContext::DrawSelector(std::string label, int c, int cMax, bool float viewHeight = (float) vp[3]; float viewWidth = (float) vp[2]; - GLFont::GLFontSize fontSize = GLFont::GLFONT_SIZE16; + GLFont::GLFontSize fontSize = GLFont::GLFONT_SIZE18; if (viewWidth < 30 || viewHeight < 200) { - fontSize = GLFont::GLFONT_SIZE12; + fontSize = GLFont::GLFONT_SIZE16; } glColor4f(r, g, b, a); @@ -59,7 +59,8 @@ void ModeSelectorContext::DrawSelector(std::string label, int c, int cMax, bool glColor4f(0, 0, 0, a); } - GLFont::getFont(fontSize).drawString(label, 0.0, y + height / 2.0, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); + //Do not zoom the selectors + GLFont::getRawFont(fontSize).drawString(label, 0.0, y + height / 2.0, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); } void ModeSelectorContext::DrawEnd() { diff --git a/src/visual/TuningContext.cpp b/src/visual/TuningContext.cpp index d6b5262..41b9390 100644 --- a/src/visual/TuningContext.cpp +++ b/src/visual/TuningContext.cpp @@ -94,7 +94,8 @@ void TuningContext::DrawTuner(long long freq, int count, float displayPos, float int numChars = freqChars.length(); int ofs = count - numChars; - GLFont& refDrawingFont = GLFont::getFont(fontSize); + //do not zoom this one: + GLFont& refDrawingFont = GLFont::getRawFont(fontSize); for (int i = ofs; i < count; i++) { float xpos = displayPos + (displayWidth / (float) count) * (float) i + ((displayWidth / 2.0) / (float) count);