Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeShaderPickerPanel.h"
  9. #include "dme_controls/AttributeTextEntry.h"
  10. #include "matsys_controls/Picker.h"
  11. #include "tier1/keyvalues.h"
  12. #include "matsys_controls/matsyscontrols.h"
  13. #include "materialsystem/imaterialsystem.h"
  14. #include "materialsystem/ishader.h"
  15. using namespace vgui;
  16. //-----------------------------------------------------------------------------
  17. // Constructor
  18. //-----------------------------------------------------------------------------
  19. CAttributeShaderPickerPanel::CAttributeShaderPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  20. BaseClass( parent, info )
  21. {
  22. }
  23. CAttributeShaderPickerPanel::~CAttributeShaderPickerPanel()
  24. {
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Called when it's time to show the picker
  28. //-----------------------------------------------------------------------------
  29. void CAttributeShaderPickerPanel::ShowPickerDialog()
  30. {
  31. CPickerFrame *pShaderPickerDialog = new CPickerFrame( this, "Select Shader", "Shader", "shaderName" );
  32. int nCount = vgui::MaterialSystem()->ShaderCount();
  33. IShader** ppShaderList = (IShader**)_alloca( nCount * sizeof(IShader) );
  34. vgui::MaterialSystem()->GetShaders( 0, nCount, ppShaderList );
  35. PickerList_t shaderList( 0, nCount );
  36. for ( int i = 0; i < nCount; ++i )
  37. {
  38. if ( ( ppShaderList[i]->GetFlags() & SHADER_NOT_EDITABLE ) == 0 )
  39. {
  40. int j = shaderList.AddToTail( );
  41. shaderList[j].m_pChoiceString = ppShaderList[i]->GetName();
  42. shaderList[j].m_pChoiceValue = ppShaderList[i]->GetName();
  43. }
  44. }
  45. pShaderPickerDialog->AddActionSignalTarget( this );
  46. pShaderPickerDialog->DoModal( shaderList );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Called by the picker dialog if a asset was selected
  50. //-----------------------------------------------------------------------------
  51. void CAttributeShaderPickerPanel::OnPicked( KeyValues *pKeyValues )
  52. {
  53. // Get the asset name back
  54. const char *pShaderName = pKeyValues->GetString( "choice", NULL );
  55. if ( !pShaderName || !pShaderName[ 0 ] )
  56. return;
  57. // Apply to text panel
  58. m_pData->SetText( pShaderName );
  59. SetDirty(true);
  60. if ( IsAutoApply() )
  61. {
  62. Apply();
  63. }
  64. }