guiChatConsole.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes_extrabloated.h"
  18. #include "modalMenu.h"
  19. #include "chat.h"
  20. #include "config.h"
  21. class Client;
  22. class GUIChatConsole : public gui::IGUIElement
  23. {
  24. public:
  25. GUIChatConsole(gui::IGUIEnvironment* env,
  26. gui::IGUIElement* parent,
  27. s32 id,
  28. ChatBackend* backend,
  29. Client* client,
  30. IMenuManager* menumgr);
  31. virtual ~GUIChatConsole();
  32. // Open the console (height = desired fraction of screen size)
  33. // This doesn't open immediately but initiates an animation.
  34. // You should call isOpenInhibited() before this.
  35. void openConsole(f32 scale);
  36. bool isOpen() const;
  37. // Check if the console should not be opened at the moment
  38. // This is to avoid reopening the console immediately after closing
  39. bool isOpenInhibited() const;
  40. // Close the console, equivalent to openConsole(0).
  41. // This doesn't close immediately but initiates an animation.
  42. void closeConsole();
  43. // Close the console immediately, without animation.
  44. void closeConsoleAtOnce();
  45. // Set whether to close the console after the user presses enter.
  46. void setCloseOnEnter(bool close) { m_close_on_enter = close; }
  47. // Return the desired height (fraction of screen size)
  48. // Zero if the console is closed or getting closed
  49. f32 getDesiredHeight() const;
  50. // Replace actual line when adding the actual to the history (if there is any)
  51. void replaceAndAddToHistory(std::wstring line);
  52. // Change how the cursor looks
  53. void setCursor(
  54. bool visible,
  55. bool blinking = false,
  56. f32 blink_speed = 1.0,
  57. f32 relative_height = 1.0);
  58. // Irrlicht draw method
  59. virtual void draw();
  60. bool canTakeFocus(gui::IGUIElement* element) { return false; }
  61. virtual bool OnEvent(const SEvent& event);
  62. virtual void setVisible(bool visible);
  63. private:
  64. void reformatConsole();
  65. void recalculateConsolePosition();
  66. // These methods are called by draw
  67. void animate(u32 msec);
  68. void drawBackground();
  69. void drawText();
  70. void drawPrompt();
  71. private:
  72. ChatBackend* m_chat_backend;
  73. Client* m_client;
  74. IMenuManager* m_menumgr;
  75. // current screen size
  76. v2u32 m_screensize;
  77. // used to compute how much time passed since last animate()
  78. u64 m_animate_time_old;
  79. // should the console be opened or closed?
  80. bool m_open = false;
  81. // should it close after you press enter?
  82. bool m_close_on_enter = false;
  83. // current console height [pixels]
  84. s32 m_height = 0;
  85. // desired height [pixels]
  86. f32 m_desired_height = 0.0f;
  87. // desired height [screen height fraction]
  88. f32 m_desired_height_fraction = 0.0f;
  89. // console open/close animation speed [screen height fraction / second]
  90. f32 m_height_speed = 5.0f;
  91. // if nonzero, opening the console is inhibited [milliseconds]
  92. u32 m_open_inhibited = 0;
  93. // cursor blink frame (16-bit value)
  94. // cursor is off during [0,32767] and on during [32768,65535]
  95. u32 m_cursor_blink = 0;
  96. // cursor blink speed [on/off toggles / second]
  97. f32 m_cursor_blink_speed = 0.0f;
  98. // cursor height [line height]
  99. f32 m_cursor_height = 0.0f;
  100. // background texture
  101. video::ITexture *m_background = nullptr;
  102. // background color (including alpha)
  103. video::SColor m_background_color = video::SColor(255, 0, 0, 0);
  104. // font
  105. gui::IGUIFont *m_font = nullptr;
  106. v2u32 m_fontsize;
  107. };