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.

151 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef INPUTDIALOG_H
  7. #define INPUTDIALOG_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include <vgui_controls/Controls.h>
  12. #include <vgui_controls/Frame.h>
  13. namespace vgui
  14. {
  15. class Label;
  16. class Button;
  17. class TextEntry;
  18. //-----------------------------------------------------------------------------
  19. // Purpose: Utility dialog base class - just has context kv and ok/cancel buttons
  20. //-----------------------------------------------------------------------------
  21. class BaseInputDialog : public Frame
  22. {
  23. DECLARE_CLASS_SIMPLE( BaseInputDialog, Frame );
  24. public:
  25. BaseInputDialog( vgui::Panel *parent, const char *title, bool bShowCancelButton = true );
  26. ~BaseInputDialog();
  27. void DoModal( KeyValues *pContextKeyValues = NULL );
  28. protected:
  29. virtual void PerformLayout();
  30. virtual void PerformLayout( int x, int y, int w, int h ) {}
  31. // command buttons
  32. virtual void OnCommand( const char *command );
  33. virtual void WriteDataToKeyValues( KeyValues *pKV, bool bOk ) {}
  34. void CleanUpContextKeyValues();
  35. KeyValues *m_pContextKeyValues;
  36. vgui::Button *m_pCancelButton;
  37. vgui::Button *m_pOKButton;
  38. };
  39. //-----------------------------------------------------------------------------
  40. // Purpose: Utility dialog, used to ask yes/no questions of the user
  41. //-----------------------------------------------------------------------------
  42. class InputMessageBox : public BaseInputDialog
  43. {
  44. DECLARE_CLASS_SIMPLE( InputMessageBox, BaseInputDialog );
  45. public:
  46. InputMessageBox( vgui::Panel *parent, const char *title, char const *prompt );
  47. ~InputMessageBox();
  48. protected:
  49. virtual void PerformLayout( int x, int y, int w, int h );
  50. private:
  51. vgui::Label *m_pPrompt;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Purpose: Utility dialog, used to let user type in some text
  55. //-----------------------------------------------------------------------------
  56. class InputDialog : public BaseInputDialog
  57. {
  58. DECLARE_CLASS_SIMPLE( InputDialog, BaseInputDialog );
  59. public:
  60. InputDialog( vgui::Panel *parent, const char *title, char const *prompt, char const *defaultValue = "" );
  61. ~InputDialog();
  62. void SetMultiline( bool state );
  63. /* action signals
  64. "InputCompleted"
  65. "text" - the text entered
  66. "InputCanceled"
  67. */
  68. void AllowNumericInputOnly( bool bOnlyNumeric );
  69. protected:
  70. virtual void PerformLayout( int x, int y, int w, int h );
  71. // command buttons
  72. virtual void WriteDataToKeyValues( KeyValues *pKV, bool bOk );
  73. private:
  74. vgui::Label *m_pPrompt;
  75. vgui::TextEntry *m_pInput;
  76. };
  77. //-----------------------------------------------------------------------------
  78. // Purpose: Utility dialog, used to let user specify multiple bool/float/string values
  79. //-----------------------------------------------------------------------------
  80. class MultiInputDialog : public Frame
  81. {
  82. DECLARE_CLASS_SIMPLE( MultiInputDialog, Frame );
  83. public:
  84. MultiInputDialog( Panel *pParent, const char *pTitle, const char *pOKText = "#VGui_OK", const char *pCancelText = "#VGui_Cancel" );
  85. ~MultiInputDialog();
  86. void SetOKCommand ( KeyValues *pOKCommand ); // defaults to "InputCompleted" to match InputDialog
  87. void SetCancelCommand( KeyValues *pCancelCommand ); // defaults to "InputCanceled" to match InputDialog (yes, this is spelled incorrectly)
  88. void AddText( const char *pText );
  89. void AddEntry( const char *pName, const char *pPrompt, bool bDefaultValue );
  90. void AddEntry( const char *pName, const char *pPrompt, float flDefaultValue );
  91. void AddEntry( const char *pName, const char *pPrompt, const char *pDefaultValue );
  92. virtual void DoModal();
  93. virtual void PerformLayout();
  94. virtual void OnCommand( const char *pCommand );
  95. private:
  96. void WriteDataToKeyValues( KeyValues *pKV );
  97. void PerformLayout( int x, int y, int w, int h );
  98. int GetLabelWidth();
  99. int GetContentWidth();
  100. Label *AddLabel( const char *pText );
  101. TextEntry *AddTextEntry( const char *pName, const char *pDefaultValue );
  102. enum EntryType_t { T_NONE, T_BOOL, T_FLOAT, T_STRING };
  103. CUtlVector< Label* > m_prompts;
  104. CUtlVector< Panel* > m_inputs; // TextEntry or CheckButton
  105. CUtlVector< EntryType_t > m_entryTypes;
  106. Button *m_pOKButton;
  107. Button *m_pCancelButton;
  108. KeyValues *m_pOKCommand;
  109. KeyValues *m_pCancelCommand;
  110. int m_nCurrentTabPosition;
  111. };
  112. } // namespace vgui
  113. #endif // INPUTDIALOG_H