From Garry's Mod
Jump to: navigation, search


This is the base panel for every other VGUI panel.

It contains all of the basic methods, some of which may only work on certain VGUI elements. As their functionality is provided at the game's C/C++ level rather than by its Lua script extension, they are unfortunately unavailable for most practical purposes, however, they can still be obtained in a way similar to that provided by the baseclass library:

-- Create a new panel type NewPanel that inherits all of its functionality from DLabel,
-- but has a different SetText method than DLabel does - all without the hassle of that
-- old DLabel's default text getting in the way. Fun stuff.

local PANEL = {}

function PANEL:Init()

	self:SetText_Base( "" )
	self:SetText( "Time for something different!" )


function PANEL:Paint( aWide, aTall )

	local TextX, TextY = 0, 0
	local TextColor = Color( 255, 000, 000, 255 )

	surface.SetFont( self:GetFont() or "default" )
	surface.SetTextColor( TextColor )
	surface.SetTextPos( TextX, TextY )
	surface.DrawText( self:GetText() )


-- And here we go:
PANEL.SetText_Base = FindMetaTable( "Panel" ).SetText

function PANEL:SetText( aText ) 

	self.Text = tostring( aText ) 


function PANEL:GetText() 

	return self.Text or "" 


vgui.Register( "NewPanel", PANEL, "DLabel" )

Pages in category "Panel"

The following 271 pages are in this category, out of 271 total.


P cont.

P cont.

Personal tools