diff options
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/camera.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 11f8a1c90..9a08254b4 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -691,10 +691,11 @@ void Camera::drawNametags() core::matrix4 trans = m_cameranode->getProjectionMatrix(); trans *= m_cameranode->getViewMatrix(); - for (std::list<Nametag *>::const_iterator - i = m_nametags.begin(); - i != m_nametags.end(); ++i) { - Nametag *nametag = *i; + gui::IGUIFont *font = g_fontengine->getFont(); + video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + v2u32 screensize = driver->getScreenSize(); + + for (const Nametag *nametag : m_nametags) { if (nametag->nametag_color.getAlpha() == 0) { // Enforce hiding nametag, // because if freetype is enabled, a grey @@ -707,21 +708,29 @@ void Camera::drawNametags() if (transformed_pos[3] > 0) { std::wstring nametag_colorless = unescape_translate(utf8_to_wide(nametag->nametag_text)); - core::dimension2d<u32> textsize = - g_fontengine->getFont()->getDimension( + core::dimension2d<u32> textsize = font->getDimension( nametag_colorless.c_str()); f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f : core::reciprocal(transformed_pos[3]); - v2u32 screensize = RenderingEngine::get_video_driver()->getScreenSize(); v2s32 screen_pos; screen_pos.X = screensize.X * (0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2; screen_pos.Y = screensize.Y * (0.5 - transformed_pos[1] * zDiv * 0.5) - textsize.Height / 2; core::rect<s32> size(0, 0, textsize.Width, textsize.Height); - g_fontengine->getFont()->draw( + core::rect<s32> bg_size(-2, 0, textsize.Width+2, textsize.Height); + + video::SColor textColor = nametag->nametag_color; + + bool darkBackground = textColor.getLuminance() > 186; + video::SColor backgroundColor = darkBackground + ? video::SColor(50, 50, 50, 50) + : video::SColor(50, 255, 255, 255); + driver->draw2DRectangle(backgroundColor, bg_size + screen_pos); + + font->draw( translate_string(utf8_to_wide(nametag->nametag_text)).c_str(), - size + screen_pos, nametag->nametag_color); + size + screen_pos, textColor); } } } |