Console.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // Copyright (c) 2017 the Atomic project.
  3. // Copyright (c) 2008-2015 the Urho3D project.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "../../Core/Object.h"
  25. namespace Atomic
  26. {
  27. /// %Console window with log history and command line prompt.
  28. class ATOMIC_API Console : public Object
  29. {
  30. ATOMIC_OBJECT(Console, Object);
  31. public:
  32. /// Construct.
  33. Console(Context* context);
  34. /// Destruct.
  35. ~Console();
  36. /// Show or hide.
  37. void SetVisible(bool enable);
  38. /// Toggle visibility.
  39. void Toggle();
  40. /// Automatically set console to visible when receiving an error log message.
  41. void SetAutoVisibleOnError(bool enable) { autoVisibleOnError_ = enable; }
  42. /// Set the command interpreter.
  43. void SetCommandInterpreter(const String& interpreter);
  44. /// Set command history maximum size, 0 disables history.
  45. void SetNumHistoryRows(unsigned rows);
  46. /// Return whether is visible.
  47. bool IsVisible() const;
  48. /// Return true when console is set to automatically visible when receiving an error log message.
  49. bool IsAutoVisibleOnError() const { return autoVisibleOnError_; }
  50. /// Return the last used command interpreter.
  51. const String& GetCommandInterpreter() const { return interpreters_[currentInterpreter_]; }
  52. /// Return history maximum size.
  53. unsigned GetNumHistoryRows() const { return historyRows_; }
  54. /// Remove all rows.
  55. void Clear();
  56. private:
  57. /// Populate the command line interpreters that could handle the console command.
  58. bool PopulateInterpreter();
  59. ///
  60. void HandleScreenMode(StringHash eventType, VariantMap& eventData);
  61. /// Handle a log message.
  62. void HandleLogMessage(StringHash eventType, VariantMap& eventData);
  63. /// Render system ui.
  64. void RenderUi(StringHash eventType, VariantMap& eventData);
  65. /// Auto visible on error flag.
  66. bool autoVisibleOnError_;
  67. /// List of command interpreters.
  68. Vector<String> interpreters_;
  69. /// Pointers to c strings in interpreters_ list for efficient UI rendering.
  70. PODVector<const char*> interpretersPointers_;
  71. /// Last used command interpreter.
  72. int currentInterpreter_;
  73. /// Command history.
  74. Vector<String> history_;
  75. /// Command history maximum rows.
  76. unsigned historyRows_;
  77. /// Is console window open.
  78. bool isOpen_;
  79. /// Input box buffer.
  80. char inputBuffer_[0x1000];
  81. IntVector2 windowSize_;
  82. bool scrollToEnd_ = false;
  83. bool focusInput_ = false;
  84. };
  85. }