Console.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  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 "Object.h"
  25. class BorderImage;
  26. class Engine;
  27. class Font;
  28. class LineEdit;
  29. class Text;
  30. class UIElement;
  31. class XMLFile;
  32. /// Console window with log history and AngelScript prompt
  33. class Console : public Object
  34. {
  35. OBJECT(Console);
  36. public:
  37. /// Construct
  38. Console(Context* context);
  39. /// Destruct
  40. ~Console();
  41. /// Set UI elements' style from an XML file
  42. void SetStyle(XMLFile* style);
  43. /// Show or hide. Showing automatically focuses the line edit
  44. void SetVisible(bool enable);
  45. /// Toggle visibility
  46. void Toggle();
  47. /// Set number of displayed rows
  48. void SetNumRows(unsigned rows);
  49. /// Set command history maximum size, 0 disables history
  50. void SetNumHistoryRows(unsigned rows);
  51. /// Update elements to layout properly. Call this after manually adjusting the sub-elements
  52. void UpdateElements();
  53. /// Return the UI style file
  54. XMLFile* GetStyle() const { return style_; }
  55. /// Return the background element
  56. BorderImage* GetBackground() const { return background_; }
  57. /// Return the line edit element
  58. LineEdit* GetLineEdit() const { return lineEdit_; }
  59. /// Return whether is visible
  60. bool IsVisible() const;
  61. /// Return number of displayed rows
  62. unsigned GetNumRows() const { return rows_.Size(); }
  63. /// Return history maximum size
  64. unsigned GetNumHistoryRows() const { return historyRows_; }
  65. /// Return current history position
  66. unsigned GetHistoryPosition() const { return historyPosition_; }
  67. /// Return history row at index
  68. const String& GetHistoryRow(unsigned index) const;
  69. private:
  70. /// Handle enter pressed on the line edit
  71. void HandleTextFinished(StringHash eventType, VariantMap& eventData);
  72. /// Handle unhandled key on the line edit for scrolling the history
  73. void HandleLineEditKey(StringHash eventType, VariantMap& eventData);
  74. /// Handle rendering window resize
  75. void HandleScreenMode(StringHash eventType, VariantMap& eventData);
  76. /// Handle a log message
  77. void HandleLogMessage(StringHash eventType, VariantMap& eventData);
  78. /// UI style file
  79. SharedPtr<XMLFile> style_;
  80. /// Background
  81. SharedPtr<BorderImage> background_;
  82. /// Container for text rows
  83. SharedPtr<UIElement> rowContainer_;
  84. /// Text rows
  85. Vector<SharedPtr<Text> > rows_;
  86. /// Line edit
  87. SharedPtr<LineEdit> lineEdit_;
  88. /// Command history
  89. Vector<String> history_;
  90. /// Current row being edited
  91. String current_Row;
  92. /// Command history maximum rows
  93. unsigned historyRows_;
  94. /// Command history current position
  95. unsigned historyPosition_;
  96. /// Currently printing a log message -flag
  97. bool inLogMessage_;
  98. };