Added multi-line support for bounding box computation to font.

Re-adjusted the game mode hepl screen to display correctly with.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1897 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2008-05-15 02:49:32 +00:00
parent 3e6f860d57
commit a92f0c4365
4 changed files with 37 additions and 4 deletions

View File

@ -17,9 +17,12 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <vector>
#include "file_manager.hpp"
#include "user_config.hpp"
#include "gui/font.hpp"
#include "string_utils.hpp"
Font* font_gui;
Font* font_race;
@ -124,7 +127,7 @@ void Font::PrintBold(const std::string &text, int size, int x, int y,
int sz = (int)(size*std::max(scale_x,scale_y)*fontScaling);
float l,r,t,b;
m_fnt->getBBox(text.c_str(), (float)sz, 0, &l, &r, &b, &t);
getBBoxMultiLine(text, sz, 0, &l, &r, &b, &t);
const int W = (int)((r-l+0.99));
const int H = (int)((t-b+0.99));
@ -198,3 +201,31 @@ void Font::getBBox(const std::string &text, int size, bool italic,
}
}
// ----------------------------------------------------------------------------
void Font::getBBoxMultiLine(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top)
{
// Plib does not handle multi-lines strings as expected. So as a work
// around we split strings into lines, and compute the size for each
// line, and take the maximum size at the end.
std::vector<std::string> s=StringUtils::split(text,'\n');
m_fnt->getBBox(s[0].c_str(), (float)size, italic, left, right, bot, top);
for(unsigned int i=1; i<s.size(); i++)
{
float l,r,b,t;
m_fnt->getBBox(s[i].c_str(), (float)size, italic, &l, &r, &b, &t);
if(left) *left = std::min(*left, l);
if(bot ) *bot = std::min(*bot, b);
if(right)*right = std::max(*right, r);
if(top) *top = std::max(*top, t);
}
if(user_config->m_width<800) {
float fract=(float)user_config->m_width/800.0f;
*left *= fract;
*right *= fract;
if(bot) *bot *= fract;
if(top) *top *= fract;
}
}

View File

@ -39,6 +39,8 @@ public:
~Font();
void getBBox(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top);
void getBBoxMultiLine(const std::string &text, int size, bool italic,
float *left, float *right, float *bot, float *top);
// The actual main function which does everything
// ----------------------------------------------

View File

@ -71,7 +71,7 @@ most points wins (shortest time in case of a tie!) "));
if(!unlock_manager->isLocked("followleader"))
{
widget_manager->addTextWgt( WTOK_TXT4, 100, 10,
_("Follow the leader: Stay behind the leader kart.\n\
_("Follow the leader: Stay behind the leader kart. \n\
When the countdown reaches zero, a kart ahead\n\
of the leader or the last kart is eliminated."));
widget_manager->setWgtTextSize( WTOK_TXT4, WGT_FNT_SML );

View File

@ -113,7 +113,7 @@ void Widget::resizeToText()
if( !m_text.empty() )
{
float left, right, bottom, top;
m_font->getBBox(m_text.c_str(), m_text_size, false, &left, &right, &bottom, &top);
m_font->getBBoxMultiLine(m_text, m_text_size, false, &left, &right, &bottom, &top);
const int TEXT_WIDTH = (int)(right - left);
const int TEXT_HEIGHT = (int)(top - bottom);
@ -526,7 +526,7 @@ void Widget::updateVariables( const float DELTA )
// values to the left.
float left, right;
m_font->getBBox(m_text.c_str(), m_text_size, false, &left, &right, NULL, NULL);
m_font->getBBoxMultiLine(m_text, m_text_size, false, &left, &right, NULL, NULL);
int text_width = (int)(right - left + 0.99);