PanelList SubPanel

From Valve Developer Community
Jump to navigation Jump to search
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

CPP

///////////  Copyright © 2007, Mark Chandler. All rights reserved.  ///////////
//
// Description:
//	This is the core of the subpanel
//
//	Mark Chandler 2007 [email protected]
//
////////////////////////////////////////////////////////////////////////////////

#include "cbase.h"
#include "pd_mappanel.h"

#define ROUND(arg) floor(arg+0.5)
#define MARG 5

SubPanel::SubPanel(Panel *parent, const char *name) : PD_BasePanel(parent, name)
{

	m_pNameLab = new vgui::Label(this, "NameLabel", "Sub Name");
	m_pTextLab= new vgui::Label(this, "TextLabel", "Sub Text");

	m_pNameLab->SetMouseInputEnabled(false);
	m_pTextLab->SetMouseInputEnabled(false);

	m_bNeedsUpdate = true;
	Q_strncpy(m_szName,"Sub NAME", 256);
	Q_strncpy(m_szText,"Sub Text", 256);
	m_iLevel = 0;

	OnSizeChanged(GetWide(), GetTall());
}

void SubPanel::OnThink( void )
{
	if (m_bNeedsUpdate)
	{

		m_pNameLab->SetText(m_szName);
		m_pTextLab->SetText(m_szSubName);

		m_pNameLab->SetFgColor(Color(0,0,0,255));
		m_pTextLab->SetFgColor(Color(0,0,0,255));
	}
}

void SubPanel::OnSizeChanged(int newWide, int newTall)
{
	int w = newWide - MARG;
	int h = (newTall - MARG*4 - 2 - 2)/3;

	int y1 = MARG+MARG;
	int y2 = y1 + 2 + h;

	m_pNameLab->SetBounds(newTall+MARG, y1, w, h);
	m_pTextLab->SetBounds(newTall+MARG, y2, w, h);
}

Header

///////////  Copyright © 2007, Mark Chandler. All rights reserved.  ///////////
//
// Description:
//	This is the sub panel for the panel list
//
//	Mark Chandler 2007 [email protected]
//
////////////////////////////////////////////////////////////////////////////////

#ifndef SUBPanel_H
#define SUBPanel_H
#ifdef _WIN32
#pragma once
#endif

#include <vgui_controls/panel.h>
#include <vgui_controls/Label.h>

#include "pd_panel_list.h"

using namespace vgui;

class SubPanel : public PD_BasePanel
{
	DECLARE_CLASS_SIMPLE( PD_MapPanel, PD_BasePanel );

	PD_MapPanel(Panel *parent, const char *name);

	void SetTitle( char* name){Q_strncpy(m_szName,name,256);m_bNeedsUpdate=true;}
	void SetText( char* text){Q_strncpy(m_szText,text,256);m_bNeedsUpdate=true;}

	void OnThink( void );
	void OnSizeChanged(int newWide, int newTall);

private:
	vgui::Label *m_pNameLab;
	vgui::Label *m_pTextLab;

	bool m_bNeedsUpdate;
	char m_szName[256];
	char m_szText[256];
};

#endif