]> git.lizzy.rs Git - minetest.git/blob - src/guiChatConsole.h
Works for debian and a few other distributions but fails for even more so back to...
[minetest.git] / src / guiChatConsole.h
1 /*
2 Minetest
3 Copyright (C) 2013 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 #include "config.h"
26
27 class Client;
28
29 class GUIChatConsole : public gui::IGUIElement
30 {
31 public:
32         GUIChatConsole(gui::IGUIEnvironment* env,
33                         gui::IGUIElement* parent,
34                         s32 id,
35                         ChatBackend* backend,
36                         Client* client);
37         virtual ~GUIChatConsole();
38
39         // Open the console (height = desired fraction of screen size)
40         // This doesn't open immediately but initiates an animation.
41         // You should call isOpenInhibited() before this.
42         void openConsole(f32 height);
43
44         bool isOpen() const;
45
46         // Check if the console should not be opened at the moment
47         // This is to avoid reopening the console immediately after closing
48         bool isOpenInhibited() const;
49         // Close the console, equivalent to openConsole(0).
50         // This doesn't close immediately but initiates an animation.
51         void closeConsole();
52         // Close the console immediately, without animation.
53         void closeConsoleAtOnce();
54
55         // Return the desired height (fraction of screen size)
56         // Zero if the console is closed or getting closed
57         f32 getDesiredHeight() const;
58
59         // Change how the cursor looks
60         void setCursor(
61                 bool visible,
62                 bool blinking = false,
63                 f32 blink_speed = 1.0,
64                 f32 relative_height = 1.0);
65
66         // Irrlicht draw method
67         virtual void draw();
68
69         bool canTakeFocus(gui::IGUIElement* element) { return false; }
70
71         virtual bool OnEvent(const SEvent& event);
72
73 private:
74         void reformatConsole();
75         void recalculateConsolePosition();
76
77         // These methods are called by draw
78         void animate(u32 msec);
79         void drawBackground();
80         void drawText();
81         void drawPrompt();
82
83 private:
84         // pointer to the chat backend
85         ChatBackend* m_chat_backend;
86
87         // pointer to the client
88         Client* m_client;
89
90         // current screen size
91         v2u32 m_screensize;
92
93         // used to compute how much time passed since last animate()
94         u32 m_animate_time_old;
95
96         // should the console be opened or closed?
97         bool m_open;
98         // current console height [pixels]
99         s32 m_height;
100         // desired height [pixels]
101         f32 m_desired_height;
102         // desired height [screen height fraction]
103         f32 m_desired_height_fraction;
104         // console open/close animation speed [screen height fraction / second]
105         f32 m_height_speed;
106         // if nonzero, opening the console is inhibited [milliseconds]
107         u32 m_open_inhibited;
108
109         // cursor blink frame (16-bit value)
110         // cursor is off during [0,32767] and on during [32768,65535]
111         u32 m_cursor_blink;
112         // cursor blink speed [on/off toggles / second]
113         f32 m_cursor_blink_speed;
114         // cursor height [line height]
115         f32 m_cursor_height;
116
117         // background texture
118         video::ITexture* m_background;
119         // background color (including alpha)
120         video::SColor m_background_color;
121
122         // font
123         gui::IGUIFont* m_font;
124         v2u32 m_fontsize;
125 #if USE_FREETYPE
126         bool m_use_freetype;
127 #endif
128 };
129
130
131 #endif
132