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