guiChatConsole.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef GUICHATCONSOLE_HEADER
  17. #define GUICHATCONSOLE_HEADER
  18. #include "irrlichttypes_extrabloated.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. virtual ~GUIChatConsole();
  31. // Open the console (height = desired fraction of screen size)
  32. // This doesn't open immediately but initiates an animation.
  33. // You should call isOpenInhibited() before this.
  34. void openConsole(f32 height);
  35. bool isOpen() const;
  36. // Check if the console should not be opened at the moment
  37. // This is to avoid reopening the console immediately after closing
  38. bool isOpenInhibited() const;
  39. // Close the console, equivalent to openConsole(0).
  40. // This doesn't close immediately but initiates an animation.
  41. void closeConsole();
  42. // Close the console immediately, without animation.
  43. void closeConsoleAtOnce();
  44. // Return the desired height (fraction of screen size)
  45. // Zero if the console is closed or getting closed
  46. f32 getDesiredHeight() const;
  47. // Change how the cursor looks
  48. void setCursor(
  49. bool visible,
  50. bool blinking = false,
  51. f32 blink_speed = 1.0,
  52. f32 relative_height = 1.0);
  53. // Irrlicht draw method
  54. virtual void draw();
  55. bool canTakeFocus(gui::IGUIElement* element) { return false; }
  56. virtual bool OnEvent(const SEvent& event);
  57. private:
  58. void reformatConsole();
  59. void recalculateConsolePosition();
  60. // These methods are called by draw
  61. void animate(u32 msec);
  62. void drawBackground();
  63. void drawText();
  64. void drawPrompt();
  65. private:
  66. // pointer to the chat backend
  67. ChatBackend* m_chat_backend;
  68. // pointer to the client
  69. Client* m_client;
  70. // current screen size
  71. v2u32 m_screensize;
  72. // used to compute how much time passed since last animate()
  73. u32 m_animate_time_old;
  74. // should the console be opened or closed?
  75. bool m_open;
  76. // current console height [pixels]
  77. s32 m_height;
  78. // desired height [pixels]
  79. f32 m_desired_height;
  80. // desired height [screen height fraction]
  81. f32 m_desired_height_fraction;
  82. // console open/close animation speed [screen height fraction / second]
  83. f32 m_height_speed;
  84. // if nonzero, opening the console is inhibited [milliseconds]
  85. u32 m_open_inhibited;
  86. // cursor blink frame (16-bit value)
  87. // cursor is off during [0,32767] and on during [32768,65535]
  88. u32 m_cursor_blink;
  89. // cursor blink speed [on/off toggles / second]
  90. f32 m_cursor_blink_speed;
  91. // cursor height [line height]
  92. f32 m_cursor_height;
  93. // background texture
  94. video::ITexture* m_background;
  95. // background color (including alpha)
  96. video::SColor m_background_color;
  97. // font
  98. gui::IGUIFont* m_font;
  99. v2u32 m_fontsize;
  100. #if USE_FREETYPE
  101. bool m_use_freetype;
  102. #endif
  103. };
  104. #endif