Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested GUI tweak #158

Open
GoogleCodeExporter opened this issue Apr 26, 2015 · 2 comments
Open

Suggested GUI tweak #158

GoogleCodeExporter opened this issue Apr 26, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

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

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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 comment by [email protected] on 1 Dec 2013 at 1:38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant