VGUI TextImage

From Valve Developer Community
Revision as of 21:32, 18 June 2012 by Stucuk (talk | contribs) (TextImage only has one parameter in its constructor (For setting the text).)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

A TextImage is a vgui2 element defined in the vgui_controls library, in the file TextImage.cpp. TextImages are available in all source games. TextImage is not really a full functioning control, it's used by VGUI Label to draw text.

You can, however, use TextImage to draw text, but you will need to call TextImage's paint function, as it is not automatically called.

Example Usage

Before creating anything, we first need to include the TextImage header file and use the vgui namespace.

 #include <vgui_controls/TextImage.h>

 using namespace vgui;

First, lets add a new variable to our class's header file:

TextImage* text;

TextImages can be created via the c++ keyword new with a simple call to TextImage:

 text = new TextImage("Text");

Once we've created our TextImage, we now need to do some configuration, usually done in ApplySchemeSettings:

 void CExample::ApplySchemeSettings( vgui::IScheme *pScheme )
    BaseClass::ApplySchemeSettings( pScheme );
    text->SetFont(pScheme->GetFont( "DefaultVerySmall" ));
    text->SetColor( Color( 200, 255, 200, 255 ) );

As mentioned above, TextImages will not automatically paint themselves, so, we need to paint them. Don't worry, its fairly simple.

 void CExample::Paint()

Heres what it should look like when you're done: