guiConsoleEditCtrl.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUICONSOLEEDITCTRL_H_
  23. #define _GUICONSOLEEDITCTRL_H_
  24. #ifndef _GUITYPES_H_
  25. #include "gui/guiTypes.h"
  26. #endif
  27. #ifndef _GUITEXTEDITCTRL_H_
  28. #include "gui/guiTextEditCtrl.h"
  29. #endif
  30. #ifndef _GUISCROLLCTRL_H_
  31. #include "gui/containers/guiScrollCtrl.h"
  32. #endif
  33. class GuiConsoleEditHistory
  34. {
  35. private:
  36. vector<string> historyList;
  37. string workingText;
  38. U32 index;
  39. public:
  40. GuiConsoleEditHistory();
  41. inline void clearHistory() { historyList.clear(); workingText.clear(); index = 0; }
  42. inline void updateHistory(const string& text) { historyList.push_back(text); index = historyList.size(); workingText.clear(); }
  43. inline void setWorkingText(const string& text) { workingText = text; index = historyList.size(); }
  44. const string& getPrevHistory();
  45. const string& getNextHistory();
  46. };
  47. class GuiConsoleEditCtrl : public GuiTextEditCtrl
  48. {
  49. private:
  50. typedef GuiTextEditCtrl Parent;
  51. GuiConsoleEditHistory mHistory;
  52. protected:
  53. bool mUseSiblingScroller;
  54. GuiScrollCtrl* mSiblingScroller;
  55. virtual bool handleCharacterInput(const GuiEvent& event);
  56. virtual bool handleEnterKey();
  57. virtual bool handleArrowKey(GuiDirection direction);
  58. virtual bool handleBackSpace();
  59. virtual bool handleDelete();
  60. public:
  61. GuiConsoleEditCtrl();
  62. DECLARE_CONOBJECT(GuiConsoleEditCtrl);
  63. static void initPersistFields();
  64. bool onKeyDown(const GuiEvent &event);
  65. void onLoseFirstResponder();
  66. };
  67. #endif //_GUI_TEXTEDIT_CTRL_H