1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-27 08:34:02 +00:00

BmpFont usage is now a ref instead of a ptr, const-ify glfont

This commit is contained in:
fgenesis 2023-05-31 17:08:52 +02:00
parent 69ae4bdb20
commit 4e632f9f6c
16 changed files with 99 additions and 98 deletions

View file

@ -77,7 +77,7 @@ KeyframeWidget::KeyframeWidget(int key) : Quad()
{ {
setTexture("keyframe"); setTexture("keyframe");
setWidthHeight(15, 30); setWidthHeight(15, 30);
b = new BitmapText(&dsq->smallFont); b = new BitmapText(dsq->smallFont);
b->position = Vector(1, -15); b->position = Vector(1, -15);
b->setFontSize(12); b->setFontSize(12);
addChild(b, PM_POINTER); addChild(b, PM_POINTER);

View file

@ -42,7 +42,7 @@ AquariaComboBox::AquariaComboBox(Vector textscale) : RenderObject()
scrollBtnDown->alpha = 0; scrollBtnDown->alpha = 0;
addChild(scrollBtnDown, PM_POINTER); addChild(scrollBtnDown, PM_POINTER);
selectedItemLabel = new BitmapText(&dsq->smallFont); selectedItemLabel = new BitmapText(dsq->smallFont);
selectedItemLabel->setAlign(ALIGN_LEFT); selectedItemLabel->setAlign(ALIGN_LEFT);
selectedItemLabel->setFontSize(8); selectedItemLabel->setFontSize(8);
selectedItemLabel->offset.y = -10; selectedItemLabel->offset.y = -10;
@ -355,7 +355,7 @@ AquariaComboBoxItem::AquariaComboBoxItem(const std::string &str, size_t idx, Aqu
setTexture("gui/combo-drop"); setTexture("gui/combo-drop");
label = new BitmapText(&dsq->smallFont); label = new BitmapText(dsq->smallFont);
label->setAlign(ALIGN_LEFT); label->setAlign(ALIGN_LEFT);
label->setFontSize(8); label->setFontSize(8);
label->setText(str); label->setText(str);

View file

@ -937,12 +937,12 @@ AquariaMenuItem::AquariaMenuItem() : Quad(), ActionMapper(), AquariaGuiElement()
font = 0; font = 0;
font = new BitmapText(&dsq->font); font = new BitmapText(dsq->font);
font->setFontSize(sz); font->setFontSize(sz);
font->position = Vector(0, -sz/2, 0); font->position = Vector(0, -sz/2, 0);
addChild(font, PM_POINTER, RBP_ON); addChild(font, PM_POINTER, RBP_ON);
glowFont = new BitmapText(&dsq->font); glowFont = new BitmapText(dsq->font);
glowFont->setFontSize(sz); glowFont->setFontSize(sz);
glowFont->position = Vector(0, -sz/2, 0); glowFont->position = Vector(0, -sz/2, 0);
glowFont->setBlendType(BLEND_ADD); glowFont->setBlendType(BLEND_ADD);

View file

@ -40,10 +40,10 @@ AquariaSaveSlot::AquariaSaveSlot(int slot) : AquariaGuiQuad()
text1 = new BitmapText(&dsq->smallFont); text1 = new BitmapText(dsq->smallFont);
text1->setFontSize(14); text1->setFontSize(14);
glowText = new BitmapText(&dsq->smallFont); glowText = new BitmapText(dsq->smallFont);
glowText->alpha = 0; glowText->alpha = 0;
glowText->setBlendType(BLEND_ADD); glowText->setBlendType(BLEND_ADD);
glowText->setFontSize(14); glowText->setFontSize(14);

View file

@ -350,9 +350,9 @@ void DSQ::centerMessage(const std::string &text, float y, int type)
BitmapText *t = 0; BitmapText *t = 0;
if (type == 1) if (type == 1)
t = new BitmapText(&smallFontRed); t = new BitmapText(smallFontRed);
else else
t = new BitmapText(&smallFont); t = new BitmapText(smallFont);
t->position = pos; t->position = pos;
t->alpha.ensureData(); t->alpha.ensureData();
t->alpha.data->path.addPathNode(1, 0); t->alpha.data->path.addPathNode(1, 0);
@ -372,7 +372,7 @@ void DSQ::centerText(const std::string &text)
Vector pos(400,200); Vector pos(400,200);
float time = 8; float time = 8;
BitmapText *s = new BitmapText(&font); BitmapText *s = new BitmapText(font);
s->color = Vector(0,0,0); s->color = Vector(0,0,0);
s->position = pos; s->position = pos;
s->offset = Vector(1,1); s->offset = Vector(1,1);
@ -389,7 +389,7 @@ void DSQ::centerText(const std::string &text)
getTopStateData()->addRenderObject(s, LR_HUD); getTopStateData()->addRenderObject(s, LR_HUD);
BitmapText *t = new BitmapText(&font); BitmapText *t = new BitmapText(font);
t->position =pos; t->position =pos;
@ -1053,7 +1053,7 @@ void DSQ::init()
debugLog("2"); debugLog("2");
versionLabel = new BitmapText(&smallFont); versionLabel = new BitmapText(smallFont);
{ {
setVersionLabelText(); setVersionLabelText();
@ -1076,7 +1076,7 @@ void DSQ::init()
subbox->color = 0; subbox->color = 0;
addRenderObject(subbox, LR_SUBTITLES); addRenderObject(subbox, LR_SUBTITLES);
subtext = new BitmapText(&dsq->subsFont); subtext = new BitmapText(dsq->subsFont);
subtext->position = Vector(400,570); subtext->position = Vector(400,570);
subtext->followCamera = 1; subtext->followCamera = 1;
@ -1096,7 +1096,7 @@ void DSQ::init()
achievement_box->color = 0; achievement_box->color = 0;
addRenderObject(achievement_box, LR_SUBTITLES); addRenderObject(achievement_box, LR_SUBTITLES);
achievement_text = new BitmapText(&dsq->subsFont); achievement_text = new BitmapText(dsq->subsFont);
achievement_text->position = Vector(603, 5); achievement_text->position = Vector(603, 5);
achievement_text->followCamera = 1; achievement_text->followCamera = 1;
achievement_text->alpha = 0; achievement_text->alpha = 0;
@ -1115,14 +1115,14 @@ void DSQ::init()
cutscene_bg->followCamera = 1; cutscene_bg->followCamera = 1;
addRenderObject(cutscene_bg, LR_SUBTITLES); addRenderObject(cutscene_bg, LR_SUBTITLES);
cutscene_text = new BitmapText(&dsq->font); cutscene_text = new BitmapText(dsq->font);
cutscene_text->setText(stringbank.get(2004)); cutscene_text->setText(stringbank.get(2004));
cutscene_text->position = Vector(400,300-16); cutscene_text->position = Vector(400,300-16);
cutscene_text->alpha.x = 0; cutscene_text->alpha.x = 0;
cutscene_text->followCamera = 1; cutscene_text->followCamera = 1;
addRenderObject(cutscene_text, LR_SUBTITLES); addRenderObject(cutscene_text, LR_SUBTITLES);
cutscene_text2 = new BitmapText(&dsq->smallFont); cutscene_text2 = new BitmapText(dsq->smallFont);
cutscene_text2->setText(stringbank.get(2005)); cutscene_text2->setText(stringbank.get(2005));
cutscene_text2->position = Vector(400,300+10); cutscene_text2->position = Vector(400,300+10);
cutscene_text2->alpha.x = 0; cutscene_text2->alpha.x = 0;
@ -2559,7 +2559,7 @@ void DSQ::createSaveSlots(SaveSlotMode ssm)
watch(t); watch(t);
saveSlotPageCount = new BitmapText(&dsq->smallFont); saveSlotPageCount = new BitmapText(dsq->smallFont);
saveSlotPageCount->followCamera = 1; saveSlotPageCount->followCamera = 1;
saveSlotPageCount->setAlign(ALIGN_LEFT); saveSlotPageCount->setAlign(ALIGN_LEFT);
saveSlotPageCount->position = Vector(590, 300); saveSlotPageCount->position = Vector(590, 300);
@ -2605,7 +2605,7 @@ void DSQ::createSaveSlots(SaveSlotMode ssm)
menu[3] = arrowDown; menu[3] = arrowDown;
BitmapText *txt = new BitmapText(&dsq->font); BitmapText *txt = new BitmapText(dsq->font);
if (ssm == SSM_LOAD) if (ssm == SSM_LOAD)
txt->setText(stringbank.get(2001)); txt->setText(stringbank.get(2001));
else else
@ -3035,7 +3035,7 @@ bool DSQ::confirm(const std::string &text, const std::string &image, bool ok, fl
yes->setDirMove(DIR_LEFT, yes); yes->setDirMove(DIR_LEFT, yes);
} }
BitmapText *txt = new BitmapText(&dsq->smallFont); BitmapText *txt = new BitmapText(dsq->smallFont);
txt->followCamera = 1; txt->followCamera = 1;
txt->position = Vector(400,250); txt->position = Vector(400,250);
txt->setText(text); txt->setText(text);

View file

@ -2831,7 +2831,7 @@ void Game::applyState()
} }
addRenderObject(controlHint_bg, LR_HELP); addRenderObject(controlHint_bg, LR_HELP);
controlHint_text = new BitmapText(&dsq->smallFont); controlHint_text = new BitmapText(dsq->smallFont);
{ {
controlHint_text->alpha = 0; controlHint_text->alpha = 0;
controlHint_text->setWidth(700); controlHint_text->setWidth(700);
@ -3007,7 +3007,7 @@ void Game::applyState()
miniMapRender->scale = Vector(0.55f, 0.55f); miniMapRender->scale = Vector(0.55f, 0.55f);
addRenderObject(miniMapRender, LR_MINIMAP); addRenderObject(miniMapRender, LR_MINIMAP);
timerText = new BitmapText(&dsq->smallFont); timerText = new BitmapText(dsq->smallFont);
timerText->position = Vector(745, 550); timerText->position = Vector(745, 550);
timerText->alpha = 0; timerText->alpha = 0;
timerText->followCamera = 1; timerText->followCamera = 1;

View file

@ -1726,7 +1726,7 @@ void InGameMenu::create()
float scale = menuBg->scale.x; float scale = menuBg->scale.x;
/* /*
songDescription = new BitmapText(&dsq->font); songDescription = new BitmapText(dsq->font);
songDescription->position = Vector(0,100); songDescription->position = Vector(0,100);
songDescription->parentManagedPointer = 1; songDescription->parentManagedPointer = 1;
menuBg->addChild(songDescription); menuBg->addChild(songDescription);
@ -1902,7 +1902,7 @@ void InGameMenu::create()
// Vector(575,250); // Vector(575,250);
songLabel = new BitmapText(&dsq->smallFont); songLabel = new BitmapText(dsq->smallFont);
{ {
songLabel->alpha = 0; songLabel->alpha = 0;
songLabel->setAlign(ALIGN_CENTER); songLabel->setAlign(ALIGN_CENTER);
@ -2296,7 +2296,7 @@ void InGameMenu::create()
nextTreasure->setCanDirMove(false); nextTreasure->setCanDirMove(false);
game->addRenderObject(nextTreasure, LR_MENU); game->addRenderObject(nextTreasure, LR_MENU);
circlePageNum = new BitmapText(&dsq->smallFont); circlePageNum = new BitmapText(dsq->smallFont);
circlePageNum->color = Vector(0,0,0); circlePageNum->color = Vector(0,0,0);
circlePageNum->position = worldLeftCenter + Vector(0, -142); circlePageNum->position = worldLeftCenter + Vector(0, -142);
circlePageNum->alpha = 0; circlePageNum->alpha = 0;
@ -2342,7 +2342,7 @@ void InGameMenu::create()
recipeMenu.scrollEnd->alpha = 0; recipeMenu.scrollEnd->alpha = 0;
game->addRenderObject(recipeMenu.scrollEnd, LR_RECIPES); game->addRenderObject(recipeMenu.scrollEnd, LR_RECIPES);
recipeMenu.header = new BitmapText(&dsq->font); recipeMenu.header = new BitmapText(dsq->font);
recipeMenu.header->color = 0; recipeMenu.header->color = 0;
recipeMenu.header->followCamera = 1; recipeMenu.header->followCamera = 1;
recipeMenu.header->setText(stringbank.get(2007)); recipeMenu.header->setText(stringbank.get(2007));
@ -2350,7 +2350,7 @@ void InGameMenu::create()
recipeMenu.header->position = Vector(scrollx, 5); //10 recipeMenu.header->position = Vector(scrollx, 5); //10
game->addRenderObject(recipeMenu.header, LR_RECIPES); game->addRenderObject(recipeMenu.header, LR_RECIPES);
recipeMenu.page = new BitmapText(&dsq->smallFont); recipeMenu.page = new BitmapText(dsq->smallFont);
recipeMenu.page->color = 0; recipeMenu.page->color = 0;
recipeMenu.page->followCamera = 1; recipeMenu.page->followCamera = 1;
recipeMenu.page->position = Vector(scrollx, 400); recipeMenu.page->position = Vector(scrollx, 400);
@ -2423,7 +2423,7 @@ void InGameMenu::create()
menuBg->addChild(songSlots[i], PM_POINTER); menuBg->addChild(songSlots[i], PM_POINTER);
} }
menuDescription = new BitmapText(&dsq->smallFont); menuDescription = new BitmapText(dsq->smallFont);
menuDescription->setFontSize(14); menuDescription->setFontSize(14);
menuDescription->position = Vector(400, 450); menuDescription->position = Vector(400, 450);
menuDescription->setAlign(ALIGN_CENTER); menuDescription->setAlign(ALIGN_CENTER);
@ -2595,7 +2595,7 @@ void InGameMenu::create()
} }
foodLabel = new BitmapText(&dsq->smallFont); foodLabel = new BitmapText(dsq->smallFont);
{ {
foodLabel->alpha = 0; foodLabel->alpha = 0;
foodLabel->setAlign(ALIGN_CENTER); foodLabel->setAlign(ALIGN_CENTER);
@ -2606,7 +2606,7 @@ void InGameMenu::create()
} }
menuBg->addChild(foodLabel, PM_POINTER); menuBg->addChild(foodLabel, PM_POINTER);
foodDescription = new BitmapText(&dsq->smallFont); foodDescription = new BitmapText(dsq->smallFont);
{ {
foodDescription->alpha = 0; foodDescription->alpha = 0;
foodDescription->setAlign(ALIGN_CENTER); foodDescription->setAlign(ALIGN_CENTER);
@ -2643,7 +2643,7 @@ void InGameMenu::create()
game->addRenderObject(treasureSlots[i], LR_MENU); game->addRenderObject(treasureSlots[i], LR_MENU);
} }
treasureLabel = new BitmapText(&dsq->smallFont); treasureLabel = new BitmapText(dsq->smallFont);
{ {
treasureLabel->alpha = 0; treasureLabel->alpha = 0;
treasureLabel->setAlign(ALIGN_CENTER); treasureLabel->setAlign(ALIGN_CENTER);

View file

@ -43,10 +43,10 @@ static bool _modname_cmp(const ModIcon *a, const ModIcon *b)
ModSelectorScreen::ModSelectorScreen() ModSelectorScreen::ModSelectorScreen()
: Quad() : Quad()
, ActionMapper() , ActionMapper()
, dlText(&dsq->smallFont) , dlText(dsq->smallFont)
, gotServerList(false) , gotServerList(false)
, currentPanel(-1) , currentPanel(-1)
, subtext(&dsq->subsFont) , subtext(dsq->subsFont)
{ {
followCamera = 1; followCamera = 1;
shareAlphaWithChildren = false; shareAlphaWithChildren = false;
@ -377,7 +377,7 @@ void ModSelectorScreen::close()
dsq->toggleVersionLabel(true); dsq->toggleVersionLabel(true);
} }
JuicyProgressBar::JuicyProgressBar() : Quad(), txt(&dsq->smallFont) JuicyProgressBar::JuicyProgressBar() : Quad(), txt(dsq->smallFont)
{ {
setTexture("modselect/tube"); setTexture("modselect/tube");
followCamera = 1; followCamera = 1;

View file

@ -60,7 +60,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
result->scale = Vector(0.7f, 0.7f); result->scale = Vector(0.7f, 0.7f);
addChild(result, PM_POINTER); addChild(result, PM_POINTER);
BitmapText *text = new BitmapText(&dsq->smallFont); BitmapText *text = new BitmapText(dsq->smallFont);
text->scale = Vector(0.7f, 0.7f); text->scale = Vector(0.7f, 0.7f);
text->color = 0; text->color = 0;
text->position = result->position + Vector(0, 18); text->position = result->position + Vector(0, 18);
@ -100,7 +100,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
ing[c]->scale = Vector(0.7f, 0.7f); ing[c]->scale = Vector(0.7f, 0.7f);
addChild(ing[c], PM_POINTER); addChild(ing[c], PM_POINTER);
BitmapText *text = new BitmapText(&dsq->smallFont); BitmapText *text = new BitmapText(dsq->smallFont);
text->scale = Vector(0.7f, 0.7f); text->scale = Vector(0.7f, 0.7f);
text->color = 0; text->color = 0;
text->position = ing[c]->position + Vector(0, 18); text->position = ing[c]->position + Vector(0, 18);
@ -130,7 +130,7 @@ RecipeMenuEntry::RecipeMenuEntry(Recipe *recipe) : RenderObject(), recipe(recipe
for (int j = 0; j < recipe->types[i].amount; j++) for (int j = 0; j < recipe->types[i].amount; j++)
{ {
// any type of whatever... // any type of whatever...
BitmapText *text = new BitmapText(&dsq->smallFont); BitmapText *text = new BitmapText(dsq->smallFont);
text->color = 0; text->color = 0;
text->scale = Vector(0.8f, 0.8f); text->scale = Vector(0.8f, 0.8f);
text->position = Vector(100*c, 0); text->position = Vector(100*c, 0);
@ -418,7 +418,7 @@ void RecipeMenu::createPage(int p)
} }
description = new BitmapText(&dsq->smallFont); description = new BitmapText(dsq->smallFont);
description->followCamera = 1; description->followCamera = 1;
description->scale = Vector(0.7f, 0.7f); description->scale = Vector(0.7f, 0.7f);
description->setAlign(ALIGN_LEFT); description->setAlign(ALIGN_LEFT);

View file

@ -4426,6 +4426,7 @@ luaFunc(entity_isFollowingPath)
luaReturnBool(false); luaReturnBool(false);
} }
// deprecated
luaFunc(entity_toggleBone) luaFunc(entity_toggleBone)
{ {
Entity *e = entity(L); Entity *e = entity(L);
@ -5705,7 +5706,7 @@ luaFunc(entity_debugText)
const char *txt = lua_tostring(L, 2); const char *txt = lua_tostring(L, 2);
if (e && txt) if (e && txt)
{ {
BitmapText *f = new BitmapText(&dsq->smallFont); BitmapText *f = new BitmapText(dsq->smallFont);
f->setText(txt); f->setText(txt);
f->position = e->position; f->position = e->position;
core->getTopStateData()->addRenderObject(f, LR_DEBUG_TEXT); core->getTopStateData()->addRenderObject(f, LR_DEBUG_TEXT);
@ -9418,8 +9419,7 @@ luaFunc(createDebugText)
luaFunc(createBitmapText) luaFunc(createBitmapText)
{ {
BmpFont *font = &dsq->smallFont; BitmapText *txt = new BitmapText(dsq->smallFont);
BitmapText *txt = new BitmapText(font);
txt->setText(getString(L, 1)); txt->setText(getString(L, 1));
txt->setFontSize(lua_tointeger(L, 2)); txt->setFontSize(lua_tointeger(L, 2));
txt->position = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4)); txt->position = Vector(lua_tonumber(L, 3), lua_tonumber(L, 4));

View file

@ -38,7 +38,7 @@ ToolTip::ToolTip() : RenderObject()
back->renderCenter = false; back->renderCenter = false;
addChild(back, PM_POINTER); addChild(back, PM_POINTER);
text = new BitmapText(&dsq->smallFont); text = new BitmapText(dsq->smallFont);
text->alpha = 0.9f; text->alpha = 0.9f;
text->setAlign(ALIGN_LEFT); text->setAlign(ALIGN_LEFT);
addChild(text, PM_POINTER); addChild(text, PM_POINTER);

View file

@ -704,7 +704,7 @@ WorldMapRender::WorldMapRender() : RenderObject(), ActionMapper()
float sz = 0.6f; float sz = 0.6f;
//hover //hover
areaLabel = new BitmapText(&dsq->smallFont); areaLabel = new BitmapText(dsq->smallFont);
areaLabel->scale = Vector(sz,sz); areaLabel->scale = Vector(sz,sz);
areaLabel->setAlign(ALIGN_CENTER); areaLabel->setAlign(ALIGN_CENTER);
@ -714,7 +714,7 @@ WorldMapRender::WorldMapRender() : RenderObject(), ActionMapper()
areaLabel->alpha = 0; areaLabel->alpha = 0;
//in //in
areaLabel2 = new BitmapText(&dsq->smallFont); areaLabel2 = new BitmapText(dsq->smallFont);
areaLabel2->scale = Vector(sz,sz); areaLabel2->scale = Vector(sz,sz);
areaLabel2->followCamera = 1; areaLabel2->followCamera = 1;
@ -724,7 +724,7 @@ WorldMapRender::WorldMapRender() : RenderObject(), ActionMapper()
areaLabel2->alpha = 0; areaLabel2->alpha = 0;
//select //select
areaLabel3 = new BitmapText(&dsq->smallFont); areaLabel3 = new BitmapText(dsq->smallFont);
areaLabel3->scale = Vector(sz,sz); areaLabel3->scale = Vector(sz,sz);
areaLabel3->followCamera = 1; areaLabel3->followCamera = 1;

View file

@ -70,10 +70,9 @@ void BmpFont::load(const std::string &file, float scale, bool loadTexture)
loaded = true; loaded = true;
} }
BitmapText::BitmapText(BmpFont *bmpFont) BitmapText::BitmapText(const BmpFont& bmpFont)
: bmpFont(bmpFont)
{ {
this->bmpFont = bmpFont;
currentScrollLine = currentScrollChar = 0; currentScrollLine = currentScrollChar = 0;
scrollDelay = 0; scrollDelay = 0;
scrolling = false; scrolling = false;
@ -126,13 +125,13 @@ float BitmapText::getSetWidth()
float BitmapText::getHeight() const float BitmapText::getHeight() const
{ {
float sz = bmpFont->font->GetCharHeight('A') * bmpFont->scale; float sz = bmpFont.font->GetCharHeight('A') * bmpFont.scale;
return lines.size()*sz; return lines.size()*sz;
} }
float BitmapText::getLineHeight() const float BitmapText::getLineHeight() const
{ {
return bmpFont->font->GetCharHeight('A') * bmpFont->scale; return bmpFont.font->GetCharHeight('A') * bmpFont.scale;
} }
void BitmapText::formatText() void BitmapText::formatText()
@ -148,7 +147,7 @@ void BitmapText::formatText()
for (size_t i = 0; i < text.size(); i++) for (size_t i = 0; i < text.size(); i++)
{ {
float sz = bmpFont->font->GetCharWidth(text[i])*bmpFont->scale; float sz = bmpFont.font->GetCharWidth(text[i])*bmpFont.scale;
currentWidth += sz; currentWidth += sz;
if (currentWidth+sz >= textWidth || text[i] == '\n') if (currentWidth+sz >= textWidth || text[i] == '\n')
@ -268,22 +267,24 @@ Vector BitmapText::getColorIndex(size_t i, size_t j)
void BitmapText::onRender(const RenderState& rs) const void BitmapText::onRender(const RenderState& rs) const
{ {
if (!bmpFont) return; const Vector top = bmpFont.fontTopColor;
float top_color[3] = {bmpFont->fontTopColor.x*color.x, bmpFont->fontTopColor.y*color.y, bmpFont->fontTopColor.z*color.z}; const Vector btm = bmpFont.fontBtmColor;
float bottom_color[3] = {bmpFont->fontBtmColor.x*color.x, bmpFont->fontBtmColor.y*color.y, bmpFont->fontBtmColor.z*color.z}; float top_color[3] = {top.x*color.x, top.y*color.y, top.z*color.z};
float bottom_color[3] = {btm.x*color.x, btm.y*color.y, btm.z*color.z};
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
const glfont::GLFont * const font = bmpFont.font;
font->Begin();
bmpFont->font->Begin(); if (bmpFont.overrideTexture) bmpFont.overrideTexture->apply();
if (bmpFont->overrideTexture) bmpFont->overrideTexture->apply();
const float scale = bmpFont.scale;
float y=0; float y=0;
float x=0; float x=0;
float adj = bmpFont->font->GetCharHeight('A') * bmpFont->scale; float adj = font->GetCharHeight('A') * scale;
if (scrolling) if (scrolling)
{ {
@ -297,13 +298,13 @@ void BitmapText::onRender(const RenderState& rs) const
if (align == ALIGN_CENTER) if (align == ALIGN_CENTER)
{ {
std::pair<int, int> sz; std::pair<int, int> sz;
bmpFont->font->GetStringSize(lines[i], &sz); font->GetStringSize(lines[i], &sz);
x = -sz.first*0.5f*bmpFont->scale; x = -sz.first*0.5f*scale;
} }
float la = 1.0f-(scrollDelay/scrollSpeed); float la = 1.0f-(scrollDelay/scrollSpeed);
bmpFont->font->DrawString(theLine, bmpFont->scale, x, y, top_color, bottom_color, alpha.x, la); font->DrawString(theLine, scale, x, y, top_color, bottom_color, alpha.x, la);
y += adj; y += adj;
} }
} }
@ -315,10 +316,10 @@ void BitmapText::onRender(const RenderState& rs) const
if (align == ALIGN_CENTER) if (align == ALIGN_CENTER)
{ {
std::pair<int, int> sz; std::pair<int, int> sz;
bmpFont->font->GetStringSize(lines[i], &sz); font->GetStringSize(lines[i], &sz);
x = -sz.first*0.5f*bmpFont->scale; x = -sz.first*0.5f*scale;
} }
bmpFont->font->DrawString(lines[i], bmpFont->scale, x, y, top_color, bottom_color, alpha.x, 1); font->DrawString(lines[i], scale, x, y, top_color, bottom_color, alpha.x, 1);
y += adj; y += adj;
} }
} }
@ -364,7 +365,7 @@ float BitmapText::getStringWidth(const std::string& text) const
if(text[i] == '\n') if(text[i] == '\n')
{ {
std::pair<int, int> dim; std::pair<int, int> dim;
bmpFont->font->GetStringSize(tmp, &dim); bmpFont.font->GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first); maxsize = std::max(maxsize, dim.first);
tmp.resize(0); tmp.resize(0);
} }
@ -372,10 +373,10 @@ float BitmapText::getStringWidth(const std::string& text) const
tmp += text[i]; tmp += text[i];
} }
std::pair<int, int> dim; std::pair<int, int> dim;
bmpFont->font->GetStringSize(tmp, &dim); bmpFont.font->GetStringSize(tmp, &dim);
maxsize = std::max(maxsize, dim.first); maxsize = std::max(maxsize, dim.first);
return maxsize * bmpFont->scale; return maxsize * bmpFont.scale;
} }

View file

@ -47,7 +47,7 @@ struct BmpFont
class BitmapText : public BaseText class BitmapText : public BaseText
{ {
public: public:
BitmapText(BmpFont *bmpFont); BitmapText(const BmpFont& bmpFont);
void setText(const std::string &text) OVERRIDE; void setText(const std::string &text) OVERRIDE;
void setWidth(float width) OVERRIDE; void setWidth(float width) OVERRIDE;
float getSetWidth(); // get the width that was set float getSetWidth(); // get the width that was set
@ -71,8 +71,8 @@ public:
size_t getNumLines() const OVERRIDE; size_t getNumLines() const OVERRIDE;
protected: protected:
const BmpFont& bmpFont;
float scrollSpeed; float scrollSpeed;
BmpFont *bmpFont;
void onUpdate(float dt) OVERRIDE; void onUpdate(float dt) OVERRIDE;
float scrollDelay; float scrollDelay;
bool scrolling; bool scrolling;

View file

@ -151,45 +151,45 @@ void GLFont::Destroy (void)
} }
} }
//******************************************************************* //*******************************************************************
void GLFont::GetTexSize (std::pair<int, int> *size) void GLFont::GetTexSize (std::pair<int, int> *size) const
{ {
//Retrieve texture size //Retrieve texture size
size->first = header.tex_width; size->first = header.tex_width;
size->second = header.tex_height; size->second = header.tex_height;
} }
//******************************************************************* //*******************************************************************
int GLFont::GetTexWidth (void) int GLFont::GetTexWidth (void) const
{ {
//Return texture width //Return texture width
return header.tex_width; return header.tex_width;
} }
//******************************************************************* //*******************************************************************
int GLFont::GetTexHeight (void) int GLFont::GetTexHeight (void) const
{ {
//Return texture height //Return texture height
return header.tex_height; return header.tex_height;
} }
//******************************************************************* //*******************************************************************
void GLFont::GetCharInterval (std::pair<int, int> *interval) void GLFont::GetCharInterval (std::pair<int, int> *interval) const
{ {
//Retrieve character interval //Retrieve character interval
interval->first = header.start_char; interval->first = header.start_char;
interval->second = header.end_char; interval->second = header.end_char;
} }
//******************************************************************* //*******************************************************************
int GLFont::GetStartChar (void) int GLFont::GetStartChar (void) const
{ {
//Return start character //Return start character
return header.start_char; return header.start_char;
} }
//******************************************************************* //*******************************************************************
int GLFont::GetEndChar (void) int GLFont::GetEndChar (void) const
{ {
//Return end character //Return end character
return header.end_char; return header.end_char;
} }
//******************************************************************* //*******************************************************************
void GLFont::GetCharSize (unsigned char c, std::pair<int, int> *size) void GLFont::GetCharSize (unsigned char c, std::pair<int, int> *size) const
{ {
//Make sure character is in range //Make sure character is in range
if (c < header.start_char || c > header.end_char) if (c < header.start_char || c > header.end_char)
@ -210,7 +210,7 @@ void GLFont::GetCharSize (unsigned char c, std::pair<int, int> *size)
} }
} }
//******************************************************************* //*******************************************************************
int GLFont::GetCharWidth (unsigned char c) int GLFont::GetCharWidth (unsigned char c) const
{ {
//Make sure in range //Make sure in range
if (c < header.start_char || c > header.end_char) if (c < header.start_char || c > header.end_char)
@ -234,7 +234,7 @@ int GLFont::GetCharWidth (unsigned char c)
} }
} }
//******************************************************************* //*******************************************************************
int GLFont::GetCharHeight (unsigned char c) int GLFont::GetCharHeight (unsigned char c) const
{ {
//Make sure in range //Make sure in range
if (c < header.start_char || c > header.end_char) if (c < header.start_char || c > header.end_char)
@ -249,13 +249,13 @@ int GLFont::GetCharHeight (unsigned char c)
} }
} }
//******************************************************************* //*******************************************************************
void GLFont::Begin (void) void GLFont::Begin (void) const
{ {
//Bind to font texture //Bind to font texture
glBindTexture(GL_TEXTURE_2D, header.tex); glBindTexture(GL_TEXTURE_2D, header.tex);
} }
//******************************************************************* //*******************************************************************
void GLFont::GetStringSize (const std::string &text, std::pair<int, int> *size) void GLFont::GetStringSize (const std::string &text, std::pair<int, int> *size) const
{ {
unsigned int i; unsigned int i;
unsigned int c; unsigned int c;

View file

@ -60,30 +60,30 @@ public:
void Destroy (void); void Destroy (void);
//Texture size retrieval methods //Texture size retrieval methods
void GetTexSize (std::pair<int, int> *size); void GetTexSize (std::pair<int, int> *size) const;
int GetTexWidth (void); int GetTexWidth (void) const;
int GetTexHeight (void); int GetTexHeight (void) const;
//Character interval retrieval methods //Character interval retrieval methods
void GetCharInterval (std::pair<int, int> *interval); void GetCharInterval (std::pair<int, int> *interval) const;
int GetStartChar (void); int GetStartChar (void) const;
int GetEndChar (void); int GetEndChar (void) const;
//Character size retrieval methods //Character size retrieval methods
void GetCharSize (unsigned char c, std::pair<int, int> *size); void GetCharSize (unsigned char c, std::pair<int, int> *size) const;
int GetCharWidth (unsigned char c); int GetCharWidth (unsigned char c) const;
int GetCharHeight (unsigned char c); int GetCharHeight (unsigned char c) const;
void GetStringSize (const std::string &text, std::pair<int, int> *size); void GetStringSize (const std::string &text, std::pair<int, int> *size) const;
//Begins text output with this font //Begins text output with this font
void Begin (void); void Begin (void) const;
//Template function to output a scaled, colored std::basic_string //Template function to output a scaled, colored std::basic_string
template<class T> void DrawString ( template<class T> void DrawString (
const std::basic_string<T> &text, float scalar, float x, const std::basic_string<T> &text, float scalar, float x,
float y, const float *top_color, const float *bottom_color, float alpha, float lastAlpha) float y, const float *top_color, const float *bottom_color, float alpha, float lastAlpha) const
{ {
unsigned int i; unsigned int i;
GLFontChar *glfont_char; GLFontChar *glfont_char;