]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gui/guiChatConsole.h
Various code improvements
[dragonfireclient.git] / src / gui / 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 #pragma once
21
22 #include "irrlichttypes_extrabloated.h"
23 #include "modalMenu.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                         IMenuManager* menumgr);
38         virtual ~GUIChatConsole();
39
40         // Open the console (height = desired fraction of screen size)
41         // This doesn't open immediately but initiates an animation.
42         // You should call isOpenInhibited() before this.
43         void openConsole(f32 scale);
44
45         bool isOpen() const;
46
47         // Check if the console should not be opened at the moment
48         // This is to avoid reopening the console immediately after closing
49         bool isOpenInhibited() const;
50         // Close the console, equivalent to openConsole(0).
51         // This doesn't close immediately but initiates an animation.
52         void closeConsole();
53         // Close the console immediately, without animation.
54         void closeConsoleAtOnce();
55         // Set whether to close the console after the user presses enter.
56         void setCloseOnEnter(bool close) { m_close_on_enter = close; }
57
58         // Replace actual line when adding the actual to the history (if there is any)
59         void replaceAndAddToHistory(const std::wstring &line);
60
61         // Change how the cursor looks
62         void setCursor(
63                 bool visible,
64                 bool blinking = false,
65                 f32 blink_speed = 1.0,
66                 f32 relative_height = 1.0);
67
68         // Irrlicht draw method
69         virtual void draw();
70
71         virtual bool OnEvent(const SEvent& event);
72
73         virtual void setVisible(bool visible);
74
75         virtual bool acceptsIME() { return true; }
76
77 private:
78         void reformatConsole();
79         void recalculateConsolePosition();
80
81         // These methods are called by draw
82         void animate(u32 msec);
83         void drawBackground();
84         void drawText();
85         void drawPrompt();
86
87         // If clicked fragment has a web url, send it to the system default web browser
88         void middleClick(s32 col, s32 row);
89
90 private:
91         ChatBackend* m_chat_backend;
92         Client* m_client;
93         IMenuManager* m_menumgr;
94
95         // current screen size
96         v2u32 m_screensize;
97
98         // used to compute how much time passed since last animate()
99         u64 m_animate_time_old;
100
101         // should the console be opened or closed?
102         bool m_open = false;
103         // should it close after you press enter?
104         bool m_close_on_enter = false;
105         // current console height [pixels]
106         s32 m_height = 0;
107         // desired height [pixels]
108         f32 m_desired_height = 0.0f;
109         // desired height [screen height fraction]
110         f32 m_desired_height_fraction = 0.0f;
111         // console open/close animation speed [screen height fraction / second]
112         f32 m_height_speed = 5.0f;
113         // if nonzero, opening the console is inhibited [milliseconds]
114         u32 m_open_inhibited = 0;
115
116         // cursor blink frame (16-bit value)
117         // cursor is off during [0,32767] and on during [32768,65535]
118         u32 m_cursor_blink = 0;
119         // cursor blink speed [on/off toggles / second]
120         f32 m_cursor_blink_speed = 0.0f;
121         // cursor height [line height]
122         f32 m_cursor_height = 0.0f;
123
124         // background texture
125         video::ITexture *m_background = nullptr;
126         // background color (including alpha)
127         video::SColor m_background_color = video::SColor(255, 0, 0, 0);
128
129         // font
130         gui::IGUIFont *m_font = nullptr;
131         v2u32 m_fontsize;
132
133         // Enable clickable chat weblinks
134         bool m_cache_clickable_chat_weblinks;
135         // Track if a ctrl key is currently held down
136         bool m_is_ctrl_down;
137 };