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

View File

@ -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

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() {

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

View File

@ -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) {

View File

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

View File

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

View File

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

View File

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