Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
guiChatConsole.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
23#include "modalMenu.h"
24#include "chat.h"
25#include "config.h"
26
27class Client;
28
29class GUIChatConsole : public gui::IGUIElement
30{
31public:
32 GUIChatConsole(gui::IGUIEnvironment* env,
33 gui::IGUIElement* parent,
34 s32 id,
35 ChatBackend* backend,
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
77private:
78 void reformatConsole();
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 // Returns true if, and only if a web url was pressed.
89 bool weblinkClick(s32 col, s32 row);
90
91 // If the selected text changed, we need to update the (X11) primary selection.
93
94private:
98
99 // current screen size
101
102 // used to compute how much time passed since last animate()
104
105 // should the console be opened or closed?
106 bool m_open = false;
107 // should it close after you press enter?
108 bool m_close_on_enter = false;
109 // current console height [pixels]
110 s32 m_height = 0;
111 // desired height [pixels]
113 // desired height [screen height fraction]
115 // console open/close animation speed [screen height fraction / second]
116 f32 m_height_speed = 5.0f;
117 // if nonzero, opening the console is inhibited [milliseconds]
119
120 // cursor blink frame (16-bit value)
121 // cursor is off during [0,32767] and on during [32768,65535]
123 // cursor blink speed [on/off toggles / second]
125 // cursor height [line height]
126 f32 m_cursor_height = 0.0f;
127
128 // background texture
129 video::ITexture *m_background = nullptr;
130 // background color (including alpha)
131 video::SColor m_background_color = video::SColor(255, 0, 0, 0);
132
133 // font
134 gui::IGUIFont *m_font = nullptr;
136
137 // Enable clickable chat weblinks
139 // Track if a ctrl key is currently held down
141};
Definition: chat.h:285
Definition: client.h:119
Definition: guiChatConsole.h:30
void drawPrompt()
Definition: guiChatConsole.cpp:354
u32 m_open_inhibited
Definition: guiChatConsole.h:118
IMenuManager * m_menumgr
Definition: guiChatConsole.h:97
Client * m_client
Definition: guiChatConsole.h:96
v2u32 m_fontsize
Definition: guiChatConsole.h:135
bool m_open
Definition: guiChatConsole.h:106
void closeConsole()
Definition: guiChatConsole.cpp:134
bool weblinkClick(s32 col, s32 row)
Definition: guiChatConsole.cpp:712
virtual void draw()
Definition: guiChatConsole.cpp:180
virtual bool OnEvent(const SEvent &event)
Definition: guiChatConsole.cpp:412
video::SColor m_background_color
Definition: guiChatConsole.h:131
f32 m_cursor_blink_speed
Definition: guiChatConsole.h:124
void replaceAndAddToHistory(const std::wstring &line)
Definition: guiChatConsole.cpp:148
void updatePrimarySelection()
Definition: guiChatConsole.cpp:775
video::ITexture * m_background
Definition: guiChatConsole.h:129
bool m_is_ctrl_down
Definition: guiChatConsole.h:140
s32 m_height
Definition: guiChatConsole.h:110
gui::IGUIFont * m_font
Definition: guiChatConsole.h:134
u32 m_cursor_blink
Definition: guiChatConsole.h:122
f32 m_cursor_height
Definition: guiChatConsole.h:126
bool m_cache_clickable_chat_weblinks
Definition: guiChatConsole.h:138
void animate(u32 msec)
Definition: guiChatConsole.cpp:233
bool isOpenInhibited() const
Definition: guiChatConsole.cpp:129
void reformatConsole()
Definition: guiChatConsole.cpp:216
void recalculateConsolePosition()
Definition: guiChatConsole.cpp:226
virtual bool acceptsIME()
Definition: guiChatConsole.h:75
virtual void setVisible(bool visible)
Definition: guiChatConsole.cpp:702
virtual ~GUIChatConsole()
Definition: guiChatConsole.cpp:101
f32 m_height_speed
Definition: guiChatConsole.h:116
ChatBackend * m_chat_backend
Definition: guiChatConsole.h:95
v2u32 m_screensize
Definition: guiChatConsole.h:100
bool m_close_on_enter
Definition: guiChatConsole.h:108
f32 m_desired_height
Definition: guiChatConsole.h:112
void drawText()
Definition: guiChatConsole.cpp:309
void closeConsoleAtOnce()
Definition: guiChatConsole.cpp:141
u64 m_animate_time_old
Definition: guiChatConsole.h:103
void openConsole(f32 scale)
Definition: guiChatConsole.cpp:107
bool isOpen() const
Definition: guiChatConsole.cpp:124
void drawBackground()
Definition: guiChatConsole.cpp:286
void setCloseOnEnter(bool close)
Definition: guiChatConsole.h:56
f32 m_desired_height_fraction
Definition: guiChatConsole.h:114
void setCursor(bool visible, bool blinking=false, f32 blink_speed=1.0, f32 relative_height=1.0)
Definition: guiChatConsole.cpp:156
Definition: modalMenu.h:37
core::vector2d< u32 > v2u32
Definition: irr_v2d.h:29
Definition: activeobjectmgr.cpp:26