shading of labels now dependent on the font size

main
Martin Felis 2011-04-19 10:38:59 +02:00
parent 7fddb0848d
commit 8954cf0db0
6 changed files with 77 additions and 25 deletions

View File

@ -794,7 +794,7 @@ void Model::OnKillEntity (const Engine::EntityBase *entity) {
const AsteroidEntity *asteroid = static_cast<const AsteroidEntity*>(entity);
if (GetPlayerEntityId() != Engine::NullEntityId) {
mLevelPoints += 150 + asteroid->mSubAsteroidsCount * 75;
mLevelPoints += (150 + asteroid->mSubAsteroidsCount * 75) * 6;
}
for (i = 0; i < mAsteroids.size(); i++) {

View File

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

View File

@ -7,6 +7,8 @@
#include "DrawingsGL.h"
#include "keytable.h"
#include <sstream>
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);
}
}

View File

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

View File

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

View File

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