Luanti 5.19.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);
80
81private:
85 irr_ptr<GUIScrollBar> m_scrollbar;
89
90 // current screen size
92
93 // used to compute how much time passed since last animate()
95
96 // should the console be opened or closed?
97 bool m_open = false;
98 // should it close after you press enter?
99 bool m_close_on_enter = false;
100 // current console height [pixels]
101 s32 m_height = 0;
102 // desired height [pixels]
104 // desired height [screen height fraction]
106 // console open/close animation speed [screen height fraction / second]
107 f32 m_height_speed = 5.0f;
108 // if nonzero, opening the console is inhibited [milliseconds]
110
111 // cursor blink frame (16-bit value)
112 // cursor is off during [0,32767] and on during [32768,65535]
114 // cursor blink speed [on/off toggles / second]
116 // cursor height [line height]
117 f32 m_cursor_height = 0.0f;
118
119 // background texture
120 video::ITexture *m_background = nullptr;
121 // background color (including alpha)
122 video::SColor m_background_color = video::SColor(255, 0, 0, 0);
123
124 // font
125 irr_ptr<gui::IGUIFont> m_font;
127
128 // Enable clickable chat weblinks
130 // Track if a ctrl key is currently held down
132};
Definition chat.h:270
Definition client.h:108
void drawPrompt()
Definition guiChatConsole.cpp:365
u32 m_open_inhibited
Definition guiChatConsole.h:109
IMenuManager * m_menumgr
Definition guiChatConsole.h:84
Client * m_client
Definition guiChatConsole.h:83
v2u32 m_fontsize
Definition guiChatConsole.h:126
GUIChatConsole(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, ChatBackend *backend, Client *client, IMenuManager *menumgr)
Definition guiChatConsole.cpp:42
bool m_open
Definition guiChatConsole.h:97
void closeConsole()
Definition guiChatConsole.cpp:129
bool weblinkClick(s32 col, s32 row)
Definition guiChatConsole.cpp:735
virtual void draw()
Definition guiChatConsole.cpp:175
void updateScrollbar(bool update_size)
Definition guiChatConsole.cpp:805
s32 m_pos_scrolled_by_scrollbar
Tells apart whether the chat was scrolled by the scrollbar or directly (new messages,...
Definition guiChatConsole.h:88
virtual bool OnEvent(const SEvent &event)
Definition guiChatConsole.cpp:423
video::SColor m_background_color
Definition guiChatConsole.h:122
f32 m_cursor_blink_speed
Definition guiChatConsole.h:115
void replaceAndAddToHistory(const std::wstring &line)
Definition guiChatConsole.cpp:143
void updatePrimarySelection()
Definition guiChatConsole.cpp:798
video::ITexture * m_background
Definition guiChatConsole.h:120
bool m_is_ctrl_down
Definition guiChatConsole.h:131
s32 m_height
Definition guiChatConsole.h:101
u32 m_cursor_blink
Definition guiChatConsole.h:113
f32 m_cursor_height
Definition guiChatConsole.h:117
bool m_cache_clickable_chat_weblinks
Definition guiChatConsole.h:129
void animate(u32 msec)
Definition guiChatConsole.cpp:235
irr_ptr< GUIScrollBar > m_scrollbar
Definition guiChatConsole.h:85
bool isOpenInhibited() const
Definition guiChatConsole.cpp:124
void reformatConsole()
Definition guiChatConsole.cpp:215
void recalculateConsolePosition()
Definition guiChatConsole.cpp:228
virtual bool acceptsIME()
Definition guiChatConsole.h:60
virtual void setVisible(bool visible)
Definition guiChatConsole.cpp:724
f32 m_height_speed
Definition guiChatConsole.h:107
ChatBackend * m_chat_backend
Definition guiChatConsole.h:82
v2u32 m_screensize
Definition guiChatConsole.h:91
bool m_close_on_enter
Definition guiChatConsole.h:99
f32 m_desired_height
Definition guiChatConsole.h:103
void drawText()
Definition guiChatConsole.cpp:311
void closeConsoleAtOnce()
Definition guiChatConsole.cpp:136
irr_ptr< gui::IGUIFont > m_font
Definition guiChatConsole.h:125
u64 m_animate_time_old
Definition guiChatConsole.h:94
void openConsole(f32 scale)
Definition guiChatConsole.cpp:102
bool isOpen() const
Definition guiChatConsole.cpp:119
void drawBackground()
Definition guiChatConsole.cpp:288
void setCloseOnEnter(bool close)
Definition guiChatConsole.h:41
f32 m_desired_height_fraction
Definition guiChatConsole.h:105
void setCursor(bool visible, bool blinking=false, f32 blink_speed=1.0, f32 relative_height=1.0)
Definition guiChatConsole.cpp:151
Definition guiScrollBar.h:16
Definition modalMenu.h:26
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
Definition activeobjectmgr.cpp:11