From 8954cf0db020e65c469750e39e1a17e17f98a79b Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Tue, 19 Apr 2011 10:38:59 +0200 Subject: [PATCH] shading of labels now dependent on the font size --- asteroids/Model.cc | 2 +- asteroids/View.cc | 51 ++++++++++++++++++++++++++--------------- engine/IMGUIControls.cc | 28 +++++++++++++++++++--- engine/ViewBase.cc | 18 ++++++++++++++- engine/ViewBase.h | 2 +- engine/ViewBaseGlobal.h | 1 + 6 files changed, 77 insertions(+), 25 deletions(-) diff --git a/asteroids/Model.cc b/asteroids/Model.cc index 0c75f4a..72fb8f3 100644 --- a/asteroids/Model.cc +++ b/asteroids/Model.cc @@ -794,7 +794,7 @@ void Model::OnKillEntity (const Engine::EntityBase *entity) { const AsteroidEntity *asteroid = static_cast(entity); if (GetPlayerEntityId() != Engine::NullEntityId) { - mLevelPoints += 150 + asteroid->mSubAsteroidsCount * 75; + mLevelPoints += (150 + asteroid->mSubAsteroidsCount * 75) * 6; } for (i = 0; i < mAsteroids.size(); i++) { diff --git a/asteroids/View.cc b/asteroids/View.cc index 25cfbc7..1d78fd1 100644 --- a/asteroids/View.cc +++ b/asteroids/View.cc @@ -583,10 +583,40 @@ void View::DrawUiGameOver() { SelectFont("console.ttf size=23 color=#ffffff"); if (GetModel()->GetPlayerLives() == 0) { + int text_xpos = screen_right * 0.5, + text_ypos = screen_bottom * 0.5 - 64; + Engine::GUI::LabelCentered(5, "That was pathetic!", - screen_right * 0.5, - screen_bottom * 0.5 - 8); + text_xpos, + text_ypos); + + const static int value_width = 10; + + text_ypos += 64; + + // ----- New Score ----- + unsigned int player_points = GetModel()->GetPoints(); + + Engine::GUI::Label (1, "At least you made a score of:", + text_xpos, text_ypos + 3 + ); + + text_ypos += 32; + + stringstream temp_stream; + temp_stream.str(""); + + temp_stream << setw(value_width) << player_points; + Engine::GUI::Label (1, temp_stream.str().c_str(), + text_xpos, text_ypos + 3 + ); + + text_ypos += 64; + Engine::GUI::Label (1, "Play harder!", + text_xpos, text_ypos + 3 + ); + } else { Engine::GUI::LabelCentered (6, "You earned yourself the", screen_right * 0.5, @@ -667,28 +697,11 @@ void View::DrawUiLevelIntro() { level_title_dest_x - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_x - 2, level_title_dest_y - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_y + 2 + 40 ); - - SelectFont("console.ttf size=46 color=#ffffff"); - Engine::GUI::LabelCentered (22, first_line.c_str(), - level_title_dest_x - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_x, - level_title_dest_y - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_y - ); - - Engine::GUI::LabelCentered (22, second_line.c_str(), - level_title_dest_x - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_x, - level_title_dest_y - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_y + 40 - ); } else { Engine::GUI::LabelCentered (21, level_title.c_str(), level_title_dest_x - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_x - 2, level_title_dest_y - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_y + 2 ); - - SelectFont("console.ttf size=46 color=#ffffff"); - Engine::GUI::LabelCentered (22, level_title.c_str(), - level_title_dest_x - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_x, - level_title_dest_y - Engine::GetTimer("LevelIntroLevelTitle") * level_title_delta_y - ); } SelectFont ("console.ttf size=23"); diff --git a/engine/IMGUIControls.cc b/engine/IMGUIControls.cc index b2cdb30..792687e 100644 --- a/engine/IMGUIControls.cc +++ b/engine/IMGUIControls.cc @@ -7,6 +7,8 @@ #include "DrawingsGL.h" #include "keytable.h" +#include + Engine::ControllerBase *controller = NULL; Engine::ViewBase *view = NULL; @@ -129,9 +131,17 @@ void Label (int id, const char* caption, int x, int y) { view->DrawGLStringMeasure(caption, &width, &height); - SelectFont("console.ttf size=23 color=#808080"); - view->DrawGLString(x - 1 , y + height * 0.5 + 1, caption); - SelectFont("console.ttf size=23 color=#ffffff"); + std::stringstream font_spec(""); + float font_size = view->GetCurrentFontSize(); + + // we shift the gray a little left and up depending on the font size + font_spec << "console.ttf size=" << font_size << " color=#808080"; + SelectFont(font_spec.str().c_str()); + view->DrawGLString(x - font_size / 20.f , y + height * 0.5 + font_size / 20.f, caption); + + font_spec.str(""); + font_spec << "console.ttf size=" << font_size << " color=#ffffff"; + SelectFont(font_spec.str().c_str()); view->DrawGLString(x , y + height * 0.5, caption); } } @@ -154,6 +164,18 @@ void LabelCentered (int id, const char* caption, int x, int y) { view->DrawGLStringMeasure(caption, &width, &height); height = fabs (height); width = fabs (width); + + std::stringstream font_spec(""); + float font_size = view->GetCurrentFontSize(); + + // we shift the gray a little left and up depending on the font size + font_spec << "console.ttf size=" << font_size << " color=#808080"; + SelectFont(font_spec.str().c_str()); + view->DrawGLString(x - 0.5 * width - font_size / 20.f , y + height * 0.5 + font_size / 20.f, caption); + + font_spec.str(""); + font_spec << "console.ttf size=" << font_size << " color=#ffffff"; + SelectFont(font_spec.str().c_str()); view->DrawGLString(x - 0.5 * width, y + height * 0.5, caption); } } diff --git a/engine/ViewBase.cc b/engine/ViewBase.cc index 01b5514..5a17c13 100644 --- a/engine/ViewBase.cc +++ b/engine/ViewBase.cc @@ -350,6 +350,15 @@ void ViewBase::SelectFont (const char *font) { LogError("Error trying to load font %s", font); } +float ViewBase::GetCurrentFontSize() { + if (mCurrentFont == NULL) { + LogError ("Could not get current font size: no font selected!"); + return 0.; + } + + return mCurrentFont->pointSize(); +} + void ViewBase::SetFontJustification (FontJustification justification) { assert (mCurrentFont != NULL); @@ -358,7 +367,6 @@ void ViewBase::SetFontJustification (FontJustification justification) { else if (justification == FontJustificationCenter) mCurrentFont->setHorizontalJustification(OGLFT::Face::CENTER); else mCurrentFont->setHorizontalJustification(OGLFT::Face::LEFT); - } void ViewBase::DrawGLString (float x, float y, const char* str) { @@ -512,6 +520,14 @@ void SetFontJustification (FontJustification justification) { ViewInstance->SetFontJustification (justification); } +float GetCurrentFontSize() { + if (!ViewInstance) { + LogError ("Cannot get font size: View not yet initialized!"); + return 0.; + } + return ViewInstance->GetCurrentFontSize(); +} + unsigned int GetWindowWidth() { return ViewInstance->GetWindowWidth (); } diff --git a/engine/ViewBase.h b/engine/ViewBase.h index 1f27cc5..4024ac4 100644 --- a/engine/ViewBase.h +++ b/engine/ViewBase.h @@ -51,6 +51,7 @@ class ViewBase : public Module{ * Default size is 12 and default color is white (#ffffff). */ void SelectFont (const char *font_spec); + float GetCurrentFontSize(); void SetFontJustification (FontJustification justification); /** \brief Draws a string at the given position using current projection @@ -125,7 +126,6 @@ class ViewBase : public Module{ /** \brief The width of the screen in pixels */ unsigned int mScreenWidth; - /** \brief Stores the current frame rate */ int mFrameRate; diff --git a/engine/ViewBaseGlobal.h b/engine/ViewBaseGlobal.h index ae74fe2..070c8b8 100644 --- a/engine/ViewBaseGlobal.h +++ b/engine/ViewBaseGlobal.h @@ -10,6 +10,7 @@ namespace Engine { void DrawGLString (float x, float y, const char* str); void SelectFont (const char* font); void SetFontJustification (FontJustification justification); +float GetCurrentFontSize(); unsigned int GetWindowWidth(); unsigned int GetWindowHeight();