Permalink
Browse files

Use big digit font to display the kart rank inside of the speedometer.

  • Loading branch information...
1 parent 508431b commit 02b0cfd069fd62571e5a2725047132cb531082c2 @hiker hiker committed Jun 9, 2014
Showing with 50 additions and 61 deletions.
  1. +8 −9 src/guiengine/engine.cpp
  2. +4 −5 src/guiengine/scalable_font.cpp
  3. +1 −1 src/guiengine/scalable_font.hpp
  4. +37 −46 src/states_screens/race_gui.cpp
View
@@ -687,11 +687,11 @@ namespace GUIEngine
{
IGUIEnvironment* g_env;
Skin* g_skin = NULL;
- ScalableFont* g_font;
- ScalableFont* g_large_font;
- ScalableFont* g_title_font;
- ScalableFont* g_small_font;
- ScalableFont* g_digit_font;
+ ScalableFont *g_font;
+ ScalableFont *g_large_font;
+ ScalableFont *g_title_font;
+ ScalableFont *g_small_font;
+ ScalableFont *g_digit_font;
IrrlichtDevice* g_device;
IVideoDriver* g_driver;
@@ -1062,21 +1062,20 @@ namespace GUIEngine
ScalableFont* sfont =
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
- "StkFont.xml",true).c_str() );
+ "StkFont.xml",true) );
sfont->setScale(normal_text_scale);
sfont->setKerningHeight(-5);
g_font = sfont;
ScalableFont* digit_font =
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
- "BigDigitFont.xml",true).c_str());
+ "BigDigitFont.xml",true));
digit_font->lazyLoadTexture(0); // make sure the texture is loaded for this one
g_digit_font = digit_font;
Private::font_height = g_font->getDimension( L"X" ).Height;
-
ScalableFont* sfont_larger = sfont->getHollowCopy();
sfont_larger->setScale(normal_text_scale*1.4f);
sfont_larger->setKerningHeight(-5);
@@ -1097,7 +1096,7 @@ namespace GUIEngine
new ScalableFont(g_env,
file_manager->getAssetChecked(FileManager::FONT,
"title_font.xml",
- true).c_str() );
+ true) );
sfont2->m_fallback_font = sfont;
// Because the fallback font is much smaller than the title font:
sfont2->m_fallback_font_scale = 4.0f;
@@ -21,9 +21,9 @@ namespace gui
{
//! constructor
-ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename)
-: Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0),
- MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0)
+ScalableFont::ScalableFont(IGUIEnvironment *env, const std::string &filename)
+ : Driver(0), SpriteBank(0), Environment(env), WrongCharacter(0),
+ MaxHeight(0), GlobalKerningWidth(0), GlobalKerningHeight(0)
{
#ifdef _DEBUG
setDebugName("ScalableFont");
@@ -44,7 +44,7 @@ ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename)
// don't grab environment, to avoid circular references
Driver = Environment->getVideoDriver();
- SpriteBank = Environment->addEmptySpriteBank(filename);
+ SpriteBank = Environment->addEmptySpriteBank(io::path(filename.c_str()));
if (SpriteBank)
SpriteBank->grab();
}
@@ -676,7 +676,6 @@ void ScalableFont::draw(const core::stringw& text,
source,
clip,
color, true);
-
#ifdef FONT_DEBUG
driver->draw2DLine(core::position2d<s32>(dest.UpperLeftCorner.X, dest.UpperLeftCorner.Y),
core::position2d<s32>(dest.UpperLeftCorner.X, dest.LowerRightCorner.Y),
@@ -72,7 +72,7 @@ class ScalableFont : public IGUIFontBitmap
int m_fallback_kerning_width;
//! constructor
- ScalableFont(IGUIEnvironment* env, const io::path& filename);
+ ScalableFont(IGUIEnvironment* env, const std::string &filename);
/** Creates a hollow copy of this font; i.e. the underlying font data is the *same* for
* both fonts. The advantage of doing this is that you can change "view" parameters
@@ -219,6 +219,8 @@ void RaceGUI::renderPlayerView(const Camera *camera, float dt)
} // renderPlayerView
//-----------------------------------------------------------------------------
+/** Shows the current soccer result.
+ */
void RaceGUI::drawScores()
{
SoccerWorld* soccerWorld = (SoccerWorld*)World::getWorld();
@@ -271,7 +273,8 @@ void RaceGUI::drawScores()
numLeader++;
offsetX += position.LowerRightCorner.X;
}
-}
+} // drawScores
+
//-----------------------------------------------------------------------------
/** Displays the racing time on the screen.s
*/
@@ -388,10 +391,10 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart,
const core::recti &viewport,
const core::vector2df &scaling)
{
- float minRatio = std::min(scaling.X, scaling.Y);
+ float min_ratio = std::min(scaling.X, scaling.Y);
const int GAUGEWIDTH = 78;
- int gauge_width = (int)(GAUGEWIDTH*minRatio);
- int gauge_height = (int)(GAUGEWIDTH*minRatio);
+ int gauge_width = (int)(GAUGEWIDTH*min_ratio);
+ int gauge_height = (int)(GAUGEWIDTH*min_ratio);
float state = (float)(kart->getEnergy())
/ kart->getKartProperties()->getNitroMax();
@@ -581,10 +584,8 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart,
irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count,
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
-
}
-
} // drawEnergyMeter
//-----------------------------------------------------------------------------
@@ -593,10 +594,10 @@ void RaceGUI::drawSpeedAndEnergy(const AbstractKart* kart,
const core::recti &viewport,
const core::vector2df &scaling)
{
- float minRatio = std::min(scaling.X, scaling.Y);
+ float min_ratio = std::min(scaling.X, scaling.Y);
const int SPEEDWIDTH = 128;
- int meter_width = (int)(SPEEDWIDTH*minRatio);
- int meter_height = (int)(SPEEDWIDTH*minRatio);
+ int meter_width = (int)(SPEEDWIDTH*min_ratio);
+ int meter_height = (int)(SPEEDWIDTH*min_ratio);
drawEnergyMeter(viewport.LowerRightCorner.X ,
(int)(viewport.LowerRightCorner.Y),
@@ -699,30 +700,35 @@ void RaceGUI::drawSpeedAndEnergy(const AbstractKart* kart,
index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN);
- // Draw Speed in Numbers
+ // Draw rank
+ WorldWithRank *world = dynamic_cast<WorldWithRank*>(World::getWorld());
- core::recti pos;
- pos.UpperLeftCorner.X=(int)(offset.X + 0.5f*meter_width);
- pos.UpperLeftCorner.Y=(int)(offset.Y - 0.62f*meter_height);
- pos.LowerRightCorner.X=(int)(offset.X + 0.8f*meter_width);
- pos.LowerRightCorner.Y=(int)(offset.X - 0.5f*meter_height);
-
- gui::ScalableFont* font;
-
- if (pos.getWidth() > 55)
- font = GUIEngine::getLargeFont();
- else if (pos.getWidth() > 40)
- font = GUIEngine::getFont();
- else
- font = GUIEngine::getSmallFont();
-
- static video::SColor color = video::SColor(255, 255, 255, 255);
- std::ostringstream oss;
- oss << (int)(speed*10);
-
- font->draw(oss.str().c_str(), pos, color);
+ if (world && world->displayRank())
+ {
+ core::recti pos;
+ pos.UpperLeftCorner.X = (int)(offset.X + 0.5f*meter_width);
+ pos.UpperLeftCorner.Y = (int)(offset.Y - 0.62f*meter_height);
+ pos.LowerRightCorner.X = (int)(offset.X + 0.8f*meter_width);
+ pos.LowerRightCorner.Y = (int)(offset.X - 0.5f*meter_height);
+
+ gui::ScalableFont* font;
+
+ font = GUIEngine::getHighresDigitFont();
+ font->setScale(min_ratio * 0.7f);
+ font->setShadow(video::SColor(255, 128, 0, 0));
+ static video::SColor color = video::SColor(255, 255, 255, 255);
+ std::ostringstream oss;
+ oss << kart->getPosition(); // the current font has no . :( << ".";
+
+ pos.LowerRightCorner = core::vector2di(offset.X+int(0.6f*meter_width),
+ offset.Y-0.5f*meter_height);
+ pos.UpperLeftCorner = core::vector2di(offset.X+int(0.6f*meter_width),
+ offset.Y-0.5f*meter_height);
+
+ font->draw(oss.str().c_str(), pos, color, true, true);
+ }
-}
+} // drawSpeedAndEnergy
//-----------------------------------------------------------------------------
/** Displays the rank and the lap of the kart.
@@ -755,21 +761,6 @@ void RaceGUI::drawRankLap(const AbstractKart* kart,
static video::SColor color = video::SColor(255, 255, 255, 255);
WorldWithRank *world = (WorldWithRank*)(World::getWorld());
- if (world->displayRank())
- {
- const int rank = kart->getPosition();
-
- font->draw(m_string_rank.c_str(), pos, color);
- pos.UpperLeftCorner.Y += font_height;
- pos.LowerRightCorner.Y += font_height;
-
- char str[256];
- const unsigned int kart_amount = world->getCurrentNumKarts();
- sprintf(str, "%d/%d", rank, kart_amount);
- font->draw(core::stringw(str).c_str(), pos, color);
- pos.UpperLeftCorner.Y += font_height;
- pos.LowerRightCorner.Y += font_height;
- }
// Don't display laps in follow the leader mode
if(world->raceHasLaps())

0 comments on commit 02b0cfd

Please sign in to comment.