Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
guiChatConsole.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "modalMenu.h"
8#include "chat.h"
9#include "irr_ptr.h"
10#include <IGUIEnvironment.h>
11
12class Client;
13class GUIScrollBar;
14
15class GUIChatConsole : public gui::IGUIElement
16{
17public:
18 GUIChatConsole(gui::IGUIEnvironment* env,
19 gui::IGUIElement* parent,
20 s32 id,
21 ChatBackend* backend,
23 IMenuManager* menumgr);
24
25 // Open the console (height = desired fraction of screen size)
26 // This doesn't open immediately but initiates an animation.
27 // You should call isOpenInhibited() before this.
28 void openConsole(f32 scale);
29
30 bool isOpen() const;
31
32 // Check if the console should not be opened at the moment
33 // This is to avoid reopening the console immediately after closing
34 bool isOpenInhibited() const;
35 // Close the console, equivalent to openConsole(0).
36 // This doesn't close immediately but initiates an animation.
37 void closeConsole();
38 // Close the console immediately, without animation.
39 void closeConsoleAtOnce();
40 // Set whether to close the console after the user presses enter.
41 void setCloseOnEnter(bool close) { m_close_on_enter = close; }
42
43 // Replace actual line when adding the actual to the history (if there is any)
44 void replaceAndAddToHistory(const std::wstring &line);
45
46 // Change how the cursor looks
47 void setCursor(
48 bool visible,
49 bool blinking = false,
50 f32 blink_speed = 1.0,
51 f32 relative_height = 1.0);
52
53 // Irrlicht draw method
54 virtual void draw();
55
56 virtual bool OnEvent(const SEvent& event);
57
58 virtual void setVisible(bool visible);
59
60 virtual bool acceptsIME() { return true; }
61
62private:
63 void reformatConsole();
65
66 // These methods are called by draw
67 void animate(u32 msec);
68 void drawBackground();
69 void drawText();
70 void drawPrompt();
71
72 // If clicked fragment has a web url, send it to the system default web browser.
73 // Returns true if, and only if a web url was pressed.
74 bool weblinkClick(s32 col, s32 row);
75
76 // If the selected text changed, we need to update the (X11) primary selection.
78
79 void updateScrollbar(bool update_size = false);
80
81private:
85 irr_ptr<GUIScrollBar> m_scrollbar;
86
87 // current screen size
89
90 // used to compute how much time passed since last animate()
92
93 // should the console be opened or closed?
94 bool m_open = false;
95 // should it close after you press enter?
96 bool m_close_on_enter = false;
97 // current console height [pixels]
98 s32 m_height = 0;
99 // desired height [pixels]
101 // desired height [screen height fraction]
103 // console open/close animation speed [screen height fraction / second]
104 f32 m_height_speed = 5.0f;
105 // if nonzero, opening the console is inhibited [milliseconds]
107
108 // cursor blink frame (16-bit value)
109 // cursor is off during [0,32767] and on during [32768,65535]
111 // cursor blink speed [on/off toggles / second]
113 // cursor height [line height]
114 f32 m_cursor_height = 0.0f;
115
116 // background texture
117 video::ITexture *m_background = nullptr;
118 // background color (including alpha)
119 video::SColor m_background_color = video::SColor(255, 0, 0, 0);
120
121 // font
122 irr_ptr<gui::IGUIFont> m_font;
124
125 // Enable clickable chat weblinks
127 // Track if a ctrl key is currently held down
129};
Definition chat.h:270
Definition client.h:106
Definition guiChatConsole.h:16
void drawPrompt()
Definition guiChatConsole.cpp:359
u32 m_open_inhibited
Definition guiChatConsole.h:106
IMenuManager * m_menumgr
Definition guiChatConsole.h:84
Client * m_client
Definition guiChatConsole.h:83
v2u32 m_fontsize
Definition guiChatConsole.h:123
GUIChatConsole(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, ChatBackend *backend, Client *client, IMenuManager *menumgr)
Definition guiChatConsole.cpp:36
bool m_open
Definition guiChatConsole.h:94
void closeConsole()
Definition guiChatConsole.cpp:122
bool weblinkClick(s32 col, s32 row)
Definition guiChatConsole.cpp:723
virtual void draw()
Definition guiChatConsole.cpp:169
virtual bool OnEvent(const SEvent &event)
Definition guiChatConsole.cpp:417
video::SColor m_background_color
Definition guiChatConsole.h:119
f32 m_cursor_blink_speed
Definition guiChatConsole.h:112
void replaceAndAddToHistory(const std::wstring &line)
Definition guiChatConsole.cpp:137
void updatePrimarySelection()
Definition guiChatConsole.cpp:786
video::ITexture * m_background
Definition guiChatConsole.h:117
bool m_is_ctrl_down
Definition guiChatConsole.h:128
s32 m_height
Definition guiChatConsole.h:98
u32 m_cursor_blink
Definition guiChatConsole.h:110
f32 m_cursor_height
Definition guiChatConsole.h:114
bool m_cache_clickable_chat_weblinks
Definition guiChatConsole.h:126
void animate(u32 msec)
Definition guiChatConsole.cpp:229
irr_ptr< GUIScrollBar > m_scrollbar
Definition guiChatConsole.h:85
bool isOpenInhibited() const
Definition guiChatConsole.cpp:117
void reformatConsole()
Definition guiChatConsole.cpp:209
void recalculateConsolePosition()
Definition guiChatConsole.cpp:222
virtual bool acceptsIME()
Definition guiChatConsole.h:60
virtual void setVisible(bool visible)
Definition guiChatConsole.cpp:712
f32 m_height_speed
Definition guiChatConsole.h:104
void updateScrollbar(bool update_size=false)
Definition guiChatConsole.cpp:793
ChatBackend * m_chat_backend
Definition guiChatConsole.h:82
v2u32 m_screensize
Definition guiChatConsole.h:88
bool m_close_on_enter
Definition guiChatConsole.h:96
f32 m_desired_height
Definition guiChatConsole.h:100
void drawText()
Definition guiChatConsole.cpp:305
void closeConsoleAtOnce()
Definition guiChatConsole.cpp:130
irr_ptr< gui::IGUIFont > m_font
Definition guiChatConsole.h:122
u64 m_animate_time_old
Definition guiChatConsole.h:91
void openConsole(f32 scale)
Definition guiChatConsole.cpp:95
bool isOpen() const
Definition guiChatConsole.cpp:112
void drawBackground()
Definition guiChatConsole.cpp:282
void setCloseOnEnter(bool close)
Definition guiChatConsole.h:41
f32 m_desired_height_fraction
Definition guiChatConsole.h:102
void setCursor(bool visible, bool blinking=false, f32 blink_speed=1.0, f32 relative_height=1.0)
Definition guiChatConsole.cpp:145
Definition guiScrollBar.h:25
Definition modalMenu.h:26
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
Definition activeobjectmgr.cpp:11