Team Fortress 2 Source Code as on 22/4/2020
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.

87 lines
2.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "DemoPage.h"
  8. #include <VGUI/IVGui.h>
  9. #include <vgui_controls/TextEntry.h>
  10. #include <vgui/KeyCode.h>
  11. using namespace vgui;
  12. //-----------------------------------------------------------------------------
  13. // Text Entry controls are notepad-like windows that hold text.
  14. // In this demo we create an editable text entry window that holds multiple lines
  15. // of text. We initialize it with some starting text.
  16. // We override the enter key to clear the text. To add a newline manually you can
  17. // type ctrl-enter
  18. //-----------------------------------------------------------------------------
  19. class TextEntryDemo5: public DemoPage
  20. {
  21. public:
  22. TextEntryDemo5(Panel *parent, const char *name);
  23. ~TextEntryDemo5();
  24. private:
  25. void OnKeyCodeTyped(KeyCode code);
  26. TextEntry *m_pTextEntry;
  27. };
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Constructor
  30. //-----------------------------------------------------------------------------
  31. TextEntryDemo5::TextEntryDemo5(Panel *parent, const char *name) : DemoPage(parent, name)
  32. {
  33. m_pTextEntry = new TextEntry(this, "AnotherTextEntry");
  34. // Position the window and make it nice and wide.
  35. // Make it tall enough to fit several lines of text.
  36. m_pTextEntry->SetBounds(100, 100, 200, 100);
  37. // Make this window hold multiple lines of text.
  38. // This will turn off horizontal scrolling,
  39. // and wrap text from line to line.
  40. m_pTextEntry->SetMultiline(true);
  41. // Insert text after you have set the size and position of the window
  42. m_pTextEntry->InsertString("Some starting text and a pile of text. ");
  43. m_pTextEntry->InsertString("Some more text to make mutiple lines. ");
  44. m_pTextEntry->InsertString("Even more scrumptious, chocolatey delicious text. ");
  45. m_pTextEntry->InsertString("Enough text to get that scroll bar a-scrolling. ");
  46. m_pTextEntry->InsertString("That's it a nice number of chars.");
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Destructor
  50. //-----------------------------------------------------------------------------
  51. TextEntryDemo5::~TextEntryDemo5()
  52. {
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Purpose: When the enter key is pressed we clear the textentry.
  56. // To add a newline use ctrl-return.
  57. //-----------------------------------------------------------------------------
  58. void TextEntryDemo5::OnKeyCodeTyped(KeyCode code)
  59. {
  60. if (code == KEY_ENTER)
  61. {
  62. m_pTextEntry->SetText("");
  63. }
  64. DemoPage::OnKeyCodeTyped(code);
  65. }
  66. Panel* TextEntryDemo5_Create(Panel *parent)
  67. {
  68. return new TextEntryDemo5(parent, "TextEntryDemo5");
  69. }