Luanti 5.10.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
12class Client;
13
14class GUIChatConsole : public gui::IGUIElement
15{
16public:
17 GUIChatConsole(gui::IGUIEnvironment* env,
18 gui::IGUIElement* parent,
19 s32 id,
20 ChatBackend* backend,
22 IMenuManager* menumgr);
23 virtual ~GUIChatConsole();
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
79private:
83
84 // current screen size
86
87 // used to compute how much time passed since last animate()
89
90 // should the console be opened or closed?
91 bool m_open = false;
92 // should it close after you press enter?
93 bool m_close_on_enter = false;
94 // current console height [pixels]
95 s32 m_height = 0;
96 // desired height [pixels]
97 f32 m_desired_height = 0.0f;
98 // desired height [screen height fraction]
100 // console open/close animation speed [screen height fraction / second]
101 f32 m_height_speed = 5.0f;
102 // if nonzero, opening the console is inhibited [milliseconds]
104
105 // cursor blink frame (16-bit value)
106 // cursor is off during [0,32767] and on during [32768,65535]
108 // cursor blink speed [on/off toggles / second]
110 // cursor height [line height]
111 f32 m_cursor_height = 0.0f;
112
113 // background texture
114 video::ITexture *m_background = nullptr;
115 // background color (including alpha)
116 video::SColor m_background_color = video::SColor(255, 0, 0, 0);
117
118 // font
119 gui::IGUIFont *m_font = nullptr;
121
122 // Enable clickable chat weblinks
124 // Track if a ctrl key is currently held down
126};
Definition chat.h:270
Definition client.h:105
Definition guiChatConsole.h:15
void drawPrompt()
Definition guiChatConsole.cpp:339
u32 m_open_inhibited
Definition guiChatConsole.h:103
IMenuManager * m_menumgr
Definition guiChatConsole.h:82
Client * m_client
Definition guiChatConsole.h:81
v2u32 m_fontsize
Definition guiChatConsole.h:120
GUIChatConsole(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id, ChatBackend *backend, Client *client, IMenuManager *menumgr)
Definition guiChatConsole.cpp:31
bool m_open
Definition guiChatConsole.h:91
void closeConsole()
Definition guiChatConsole.cpp:119
bool weblinkClick(s32 col, s32 row)
Definition guiChatConsole.cpp:697
virtual void draw()
Definition guiChatConsole.cpp:165
virtual bool OnEvent(const SEvent &event)
Definition guiChatConsole.cpp:397
video::SColor m_background_color
Definition guiChatConsole.h:116
f32 m_cursor_blink_speed
Definition guiChatConsole.h:109
void replaceAndAddToHistory(const std::wstring &line)
Definition guiChatConsole.cpp:133
void updatePrimarySelection()
Definition guiChatConsole.cpp:760
video::ITexture * m_background
Definition guiChatConsole.h:114
bool m_is_ctrl_down
Definition guiChatConsole.h:125
s32 m_height
Definition guiChatConsole.h:95
gui::IGUIFont * m_font
Definition guiChatConsole.h:119
u32 m_cursor_blink
Definition guiChatConsole.h:107
f32 m_cursor_height
Definition guiChatConsole.h:111
bool m_cache_clickable_chat_weblinks
Definition guiChatConsole.h:123
void animate(u32 msec)
Definition guiChatConsole.cpp:218
bool isOpenInhibited() const
Definition guiChatConsole.cpp:114
void reformatConsole()
Definition guiChatConsole.cpp:201
void recalculateConsolePosition()
Definition guiChatConsole.cpp:211
virtual bool acceptsIME()
Definition guiChatConsole.h:60
virtual void setVisible(bool visible)
Definition guiChatConsole.cpp:687
virtual ~GUIChatConsole()
Definition guiChatConsole.cpp:86
f32 m_height_speed
Definition guiChatConsole.h:101
ChatBackend * m_chat_backend
Definition guiChatConsole.h:80
v2u32 m_screensize
Definition guiChatConsole.h:85
bool m_close_on_enter
Definition guiChatConsole.h:93
f32 m_desired_height
Definition guiChatConsole.h:97
void drawText()
Definition guiChatConsole.cpp:294
void closeConsoleAtOnce()
Definition guiChatConsole.cpp:126
u64 m_animate_time_old
Definition guiChatConsole.h:88
void openConsole(f32 scale)
Definition guiChatConsole.cpp:92
bool isOpen() const
Definition guiChatConsole.cpp:109
void drawBackground()
Definition guiChatConsole.cpp:271
void setCloseOnEnter(bool close)
Definition guiChatConsole.h:41
f32 m_desired_height_fraction
Definition guiChatConsole.h:99
void setCursor(bool visible, bool blinking=false, f32 blink_speed=1.0, f32 relative_height=1.0)
Definition guiChatConsole.cpp:141
Definition modalMenu.h:25
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
Definition activeobjectmgr.cpp:11