shading of labels now dependent on the font size
This commit is contained in:
+25
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+17
-1
@@ -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 ();
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user