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