VGUI TextImage: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(New page: <!--<br clear=all> <div class="boilerplate metadata" id="stub" align=left>   ''This article is a stub. You can help by [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENA...)
 
m (→‎Example Usage: Unicodifying, replaced: [[Image: → [[File:)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<!--<br clear=all>
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.
<div class="boilerplate metadata" id="stub" align=left>&nbsp; &nbsp;''This article is a [[Help:Stubs|stub]]. You can help by [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit}} adding to it].'' </div>
 
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.
<source lang="cpp">
#include <vgui_controls/TextImage.h>
 
using namespace vgui;
</source>


<br clear=all>-->
First, lets add a new variable to our class's header file:
<div style="text-align: center; background: #B8C6FF; font-weight: bold; margin: 0.1em 10%; padding: 0.1em 0.1em; border: #E5E5E5 2px solid;">
<source lang="cpp">
''This article is a [[Help:Stubs|stub]]. You can help by [{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=edit}} adding to it].''
TextImage* text;
</div>
</source>


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.
TextImages can be created via the c++ keyword new with a simple call to TextImage:
<source lang="cpp">
text = new TextImage("Text");
</source>
 
Once we've created our TextImage, we now need to do some configuration, usually done in ApplySchemeSettings:
<source lang="cpp">
void CExample::ApplySchemeSettings( vgui::IScheme *pScheme )
{
    BaseClass::ApplySchemeSettings( pScheme );
    text->SetText("Text");
    text->SetPos(200,200);
    text->SetSize(100,50);
    text->SetFont(pScheme->GetFont( "DefaultVerySmall" ));
    text->SetColor( Color( 200, 255, 200, 255 ) );
}
</source>
 
As mentioned above, TextImages will not automatically paint themselves, so, we need to paint them. Don't worry, its fairly simple.
<source lang="cpp">
void CExample::Paint()
{
    BaseClass::Paint();
    text->Paint();
}
</source>


You can, however, use TextImage to draw text, but you will need to call TextImage's paint function, as it is not automatically called.
Heres what it should look like when you're done:


See [[VGUI Label]].
[[File:TextImage.jpg]]


[[Category:VGUI_Controls|I]]
[[Category:VGUI_Controls|T]]
[[Category:Stubs]]
[[Category:Stubs]]

Latest revision as of 02:10, 9 January 2024

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->SetText("Text");
    text->SetPos(200,200);
    text->SetSize(100,50);
    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()
 {
    BaseClass::Paint();
 
    text->Paint();
 }

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

TextImage.jpg