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.

116 lines
2.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. // Author: Matthew D. Campbell ([email protected]), 2003
  8. #include <vgui/KeyCode.h>
  9. #include "cvartextentry.h"
  10. #include "textentrybox.h"
  11. #include <vgui_controls/TextEntry.h>
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. using namespace vgui;
  15. //--------------------------------------------------------------------------------------------------------------
  16. CTextEntryBox::CTextEntryBox(const char *title, const char *queryText, const char *entryText, bool isCvar, vgui::Panel *parent) : QueryBox(title, queryText,parent)
  17. {
  18. if (isCvar)
  19. {
  20. m_pEntry = m_pCvarEntry = new CCvarTextEntry( this, "TextEntry", entryText );
  21. }
  22. else
  23. {
  24. m_pEntry = new TextEntry( this, "TextEntry" );
  25. m_pCvarEntry = NULL;
  26. }
  27. m_pEntry->SetTabPosition(3);
  28. m_pEntry->RequestFocus();
  29. m_pEntry->GotoTextEnd();
  30. }
  31. //--------------------------------------------------------------------------------------------------------------
  32. CTextEntryBox::~CTextEntryBox()
  33. {
  34. delete m_pEntry;
  35. }
  36. //--------------------------------------------------------------------------------------------------------------
  37. void CTextEntryBox::ShowWindow(Frame *pFrameOver)
  38. {
  39. BaseClass::ShowWindow( pFrameOver );
  40. m_pEntry->RequestFocus();
  41. InvalidateLayout();
  42. }
  43. //--------------------------------------------------------------------------------------------------------------
  44. void CTextEntryBox::PerformLayout()
  45. {
  46. BaseClass::PerformLayout();
  47. int x, y, wide, tall;
  48. GetClientArea(x, y, wide, tall);
  49. wide += x;
  50. tall += y;
  51. const int borderW = 10;
  52. int labelW, labelH;
  53. int entryW, entryH;
  54. m_pMessageLabel->GetSize( labelW, labelH );
  55. entryW = MAX(120, wide - borderW - borderW - borderW - labelW);
  56. entryH = MAX(24, labelH);
  57. m_pEntry->SetSize( entryW, entryH );
  58. int boxWidth, boxTall;
  59. GetSize(boxWidth, boxTall);
  60. if (boxWidth < labelW + entryW + borderW*3)
  61. SetSize( labelW + entryW + borderW*3, boxTall );
  62. m_pMessageLabel->GetPos( x, y );
  63. m_pMessageLabel->SetPos( borderW, y - (entryH - labelH)/2 );
  64. m_pEntry->SetPos( borderW + m_pMessageLabel->GetWide() + borderW, y - (entryH - labelH) );
  65. }
  66. //--------------------------------------------------------------------------------------------------------------
  67. void CTextEntryBox::OnCommand(const char *command)
  68. {
  69. if (!stricmp(command, "Ok"))
  70. {
  71. if (m_pCvarEntry)
  72. {
  73. m_pCvarEntry->ApplyChanges( true );
  74. }
  75. }
  76. BaseClass::OnCommand(command);
  77. }
  78. //--------------------------------------------------------------------------------------------------------------
  79. void CTextEntryBox::OnKeyCodeTyped(KeyCode code)
  80. {
  81. if (code == KEY_ESCAPE)
  82. {
  83. OnCommand("Cancel");
  84. }
  85. if (code == KEY_ENTER)
  86. {
  87. OnCommand("Ok");
  88. }
  89. else
  90. {
  91. BaseClass::OnKeyCodeTyped(code);
  92. }
  93. }