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