You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find it difficult to see the FPS counter at times, so I wrote a method
similar to DrawText in SimContext.cpp that draws a contrasting rectangle behind
the text, eliminating the possibility of a the FPS text being invisible against
a matching background. I've attached the code.
Original issue reported on code.google.com by [email protected] on 10 Nov 2013 at 10:17
The text was updated successfully, but these errors were encountered:
Seems like the attachment is missing. Here is the code:
/// Same as DrawText but draw text onto a contrasting rectangle to make it readable on a matching background.
static void DrawTextOnContrastingRect( const Vector2i& topLeft, const SColor& color, const std::string& msg, IrrlichtDevice_IPtr device )
{
Assert( device );
const std::wstring wMsg = boost::lexical_cast<std::wstring>(msg.c_str());
// grab the drawing tools we need as well
irr::gui::IGUIFont* font = device->getGUIEnvironment()->getFont( "common/data/gui/fonthaettenschweiler.bmp" );
irr::core::dimension2du optionsSize = font->getDimension(wMsg.c_str());
irr::core::rect<int32_t> msgPos;
msgPos.UpperLeftCorner.X = topLeft.X;
msgPos.UpperLeftCorner.Y = topLeft.Y;
msgPos.LowerRightCorner.X = topLeft.X + optionsSize.Width;
msgPos.LowerRightCorner.Y = topLeft.Y + optionsSize.Height;
// Draw a contrasting color rectangle behind the text
video::IVideoDriver* driver = device->getVideoDriver();
irr::core::rect<int32_t> backgroundBox;
backgroundBox.UpperLeftCorner.X = msgPos.UpperLeftCorner.X - 1;
backgroundBox.UpperLeftCorner.Y = msgPos.UpperLeftCorner.Y;
backgroundBox.LowerRightCorner.X = msgPos.LowerRightCorner.X + 1;
backgroundBox.LowerRightCorner.Y = msgPos.LowerRightCorner.Y;
// Draw on either white or black depending on the luminance of the text color.
u32 luminance = (u32)(0.2126 * color.getRed() + 0.7152 * color.getGreen() + 0.0722 * color.getBlue());
SColor contrastingColor;
if (luminance >= 128)
{
SColor white(255, 0, 0, 0);
contrastingColor = white;
}
else
{
SColor black(255, 255, 255, 255);
contrastingColor = black;
}
driver->draw2DRectangle(contrastingColor, backgroundBox);
//driver->endScene(); // is this necessary?
font->draw( wMsg.c_str(), msgPos, color, false, false, 0 );
}
Original issue reported on code.google.com by
[email protected]
on 10 Nov 2013 at 10:17The text was updated successfully, but these errors were encountered: