VGUI PanelList: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (recat, very minor clean)
Line 1: Line 1:
[[Category:VGUI]]
[[Category:VGUI]]
[[Category:Free source code]]


==Panel List==
This is a simple panel list that I made for use on Perfect Dark SP Source. It lists a bunch of panels and has the ability to group them as well. This is not final code but it should work (might be a couple of bugs).
This is a simple panel list that i made for use on Perfect Dark SP Source. It lists a bunch of panels and has the ability to group them as well. This is not final code but it should work (might be a couple of bugs).


==The Result==
==The Result==
From the picture you can see the header, and the sub panels with the ability to scroll and select. This image is from PerfectDark Source SP.<br>
From the picture you can see the header, and the sub panels with the ability to scroll and select. This image is from PerfectDark Source SP.
 
[[Image:Panellist_example.jpg]]
[[Image:Panellist_example.jpg]]


==The Code==
==The Code==
CPP: [[PanelList_cpp]]<br>
 
H: [[PanelList_h]]
* [[PanelList_cpp]]
<p>
* [[PanelList_h]]
Save these two files and add them to your client project.
* [[PanelList_SubPanel]]
 
Save these files and add them to your client project.


==How to use them==
==How to use them==
To use this you will ether need to make a new panel or use and existing panel. This is covered in other tutorials on this site!
To use this you will ether need to make a new panel or use and existing panel. This is covered in other tutorials on this site!


===Header===
===Header===
Add this to the top of the header file
Add this to the top of the header file
<pre>
 
//make sure you change this to reflect your file name!
//make sure you change this to reflect your file name!
#include "pd_panel_list.h"
#include "pd_panel_list.h"
</pre>
 
Add this to your class:
Add this to your class:
<pre>
private:
PD_PanelList *m_pPanelList;
</pre>


private:
PD_PanelList *m_pPanelList;


===Constructor===
===Constructor===
<pre>
//makes new object
m_pPanelList = new PD_PanelList(this, "Map_PL");


//sets the x, y pos and the w, h
//makes new object
m_pPanelList->SetBounds(15,40,350,255);
m_pPanelList = new PD_PanelList(this, "Map_PL");
//sets the x, y pos and the w, h
m_pPanelList->SetBounds(15,40,350,255);
//Very Important. Means it will relay messages to this panel
m_pPanelList->AddActionSignalTarget( this );
//usefull if you want key commands to go up/down
m_pPanelList->SetKeyBoardInputEnabled( true );


//Very Important. Means it will relay messages to this panel
===The sub panel===
m_pPanelList->AddActionSignalTarget( this );


//usefull if you want key commands to go up/down
Sub-panels must inherit from <code>SubPanel</code> (in [[PanelList_SubPanel]]). Things to note:
m_pPanelList->SetKeyBoardInputEnabled( true );
</pre>


===The sub panel===
Main Code: [[PanelList_SubPanel]]
<br><br>
Things to note:
*Parent class must be PD_BasePanel as this sets up mouse events
*Parent class must be PD_BasePanel as this sets up mouse events
*Must have a resize method (other wise it will never look right) which resizes the elements
*Must have a resize method (other wise it will never look right) which resizes the elements
Line 56: Line 54:
*Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events
*Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events


===Adding panels===


===Adding panels===
Addding panels is as easy as making a new panel then adding it to the panellist.
Addding panels is as easy as making a new panel then adding it to the panellist.
<pre>
//make sure you pass the panel list as parent because it will control the panel!
SubPanel *temp= new SubPanel(m_pPanelList, name);
//Set the sub panel up
temp->SetTitle("Panel Title");
temp->SetText("Some Text");


//this is to fix a bug that i havnt fixed yet. If adding a duplicate panel it doesnt delete temp
//make sure you pass the panel list as parent because it will control the panel!
//but doesnt add it to the list ether
SubPanel *temp= new SubPanel(m_pPanelList, name);
if (m_pPanelList->AddPanel(temp)==-1)
{
//Set the sub panel up
delete temp;
temp->SetTitle("Panel Title");
}
temp->SetText("Some Text");
</pre>
//this is to fix a bug that i havnt fixed yet. If adding a duplicate panel it doesnt delete temp
//but doesnt add it to the list ether
if (m_pPanelList->AddPanel(temp)==-1)
{
delete temp;
}

Revision as of 02:11, 14 June 2008


This is a simple panel list that I made for use on Perfect Dark SP Source. It lists a bunch of panels and has the ability to group them as well. This is not final code but it should work (might be a couple of bugs).

The Result

From the picture you can see the header, and the sub panels with the ability to scroll and select. This image is from PerfectDark Source SP.

Panellist example.jpg

The Code

Save these files and add them to your client project.

How to use them

To use this you will ether need to make a new panel or use and existing panel. This is covered in other tutorials on this site!

Header

Add this to the top of the header file

	//make sure you change this to reflect your file name!
	#include "pd_panel_list.h"

Add this to your class:

private:
	PD_PanelList *m_pPanelList;

Constructor

	//makes new object
	m_pPanelList = new PD_PanelList(this, "Map_PL");

	//sets the x, y pos and the w, h
	m_pPanelList->SetBounds(15,40,350,255);

	//Very Important. Means it will relay messages to this panel
	m_pPanelList->AddActionSignalTarget( this );

	//usefull if you want key commands to go up/down
	m_pPanelList->SetKeyBoardInputEnabled( true );

The sub panel

Sub-panels must inherit from SubPanel (in PanelList_SubPanel). Things to note:

  • Parent class must be PD_BasePanel as this sets up mouse events
  • Must have a resize method (other wise it will never look right) which resizes the elements
  • Can have any panel elements on it
  • Need to set mouse imput enabled to false on all child elements. Other wise this will over ride the panellist mouse events

Adding panels

Addding panels is as easy as making a new panel then adding it to the panellist.

	//make sure you pass the panel list as parent because it will control the panel!
	SubPanel *temp= new SubPanel(m_pPanelList, name);

	//Set the sub panel up
	temp->SetTitle("Panel Title");
	temp->SetText("Some Text");

	//this is to fix a bug that i havnt fixed yet. If adding a duplicate panel it doesnt delete temp
	//but doesnt add it to the list ether
	if (m_pPanelList->AddPanel(temp)==-1)
	{
		delete temp;
	}