Merge dd228df291
into f54d209bc8
This commit is contained in:
commit
3343e0ab4d
@ -112,7 +112,8 @@ public:
|
|||||||
|
|
||||||
void resize(u32 scrollback);
|
void resize(u32 scrollback);
|
||||||
|
|
||||||
protected:
|
// Get the current scroll position
|
||||||
|
s32 getScrollPosition() const { return m_scroll; }
|
||||||
s32 getTopScrollPos() const;
|
s32 getTopScrollPos() const;
|
||||||
s32 getBottomScrollPos() const;
|
s32 getBottomScrollPos() const;
|
||||||
|
|
||||||
|
@ -1800,7 +1800,9 @@ void Game::processUserInput(f32 dtime)
|
|||||||
m_game_focused = true;
|
m_game_focused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!guienv->hasFocus(gui_chat_console.get()) && gui_chat_console->isOpen()) {
|
if (!guienv->hasFocus(gui_chat_console.get()) && gui_chat_console->isOpen()
|
||||||
|
&& !gui_chat_console->isMyChild(guienv->getFocus()))
|
||||||
|
{
|
||||||
gui_chat_console->closeConsoleAtOnce();
|
gui_chat_console->closeConsoleAtOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "irrlicht_changes/CGUITTFont.h"
|
#include "irrlicht_changes/CGUITTFont.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
#include "guiScrollBar.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
inline u32 clamp_u8(s32 value)
|
inline u32 clamp_u8(s32 value)
|
||||||
@ -28,6 +29,11 @@ inline bool isInCtrlKeys(const irr::EKEY_CODE& kc)
|
|||||||
return kc == KEY_LCONTROL || kc == KEY_RCONTROL || kc == KEY_CONTROL;
|
return kc == KEY_LCONTROL || kc == KEY_RCONTROL || kc == KEY_CONTROL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline u32 getScrollbarSize(IGUIEnvironment* env)
|
||||||
|
{
|
||||||
|
return env->getSkin()->getSize(gui::EGDS_SCROLLBAR_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
GUIChatConsole::GUIChatConsole(
|
GUIChatConsole::GUIChatConsole(
|
||||||
gui::IGUIEnvironment* env,
|
gui::IGUIEnvironment* env,
|
||||||
gui::IGUIElement* parent,
|
gui::IGUIElement* parent,
|
||||||
@ -81,12 +87,20 @@ GUIChatConsole::GUIChatConsole(
|
|||||||
// track ctrl keys for mouse event
|
// track ctrl keys for mouse event
|
||||||
m_is_ctrl_down = false;
|
m_is_ctrl_down = false;
|
||||||
m_cache_clickable_chat_weblinks = g_settings->getBool("clickable_chat_weblinks");
|
m_cache_clickable_chat_weblinks = g_settings->getBool("clickable_chat_weblinks");
|
||||||
|
|
||||||
|
m_scrollbar = new GUIScrollBar(env, this, -1, core::rect<s32>(0, 0, 30, m_height), false, true, tsrc);
|
||||||
|
m_scrollbar->setSubElement(true);
|
||||||
|
m_scrollbar->setLargeStep(1);
|
||||||
|
m_scrollbar->setSmallStep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUIChatConsole::~GUIChatConsole()
|
GUIChatConsole::~GUIChatConsole()
|
||||||
{
|
{
|
||||||
if (m_font)
|
if (m_font)
|
||||||
m_font->drop();
|
m_font->drop();
|
||||||
|
|
||||||
|
if (m_scrollbar)
|
||||||
|
m_scrollbar->drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIChatConsole::openConsole(f32 scale)
|
void GUIChatConsole::openConsole(f32 scale)
|
||||||
@ -121,6 +135,7 @@ void GUIChatConsole::closeConsole()
|
|||||||
m_open = false;
|
m_open = false;
|
||||||
Environment->removeFocus(this);
|
Environment->removeFocus(this);
|
||||||
m_menumgr->deletingMenu(this);
|
m_menumgr->deletingMenu(this);
|
||||||
|
m_scrollbar->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIChatConsole::closeConsoleAtOnce()
|
void GUIChatConsole::closeConsoleAtOnce()
|
||||||
@ -180,7 +195,10 @@ void GUIChatConsole::draw()
|
|||||||
m_screensize = screensize;
|
m_screensize = screensize;
|
||||||
m_desired_height = m_desired_height_fraction * m_screensize.Y;
|
m_desired_height = m_desired_height_fraction * m_screensize.Y;
|
||||||
reformatConsole();
|
reformatConsole();
|
||||||
}
|
} else if (!m_scrollbar->getAbsolutePosition().isPointInside(core::vector2di(screensize.X, m_height)))
|
||||||
|
// the height of the chat window is no longer the height of the scrollbar
|
||||||
|
// happens while opening/closing the window
|
||||||
|
updateScrollbar(true);
|
||||||
|
|
||||||
// Animation
|
// Animation
|
||||||
u64 now = porting::getTimeMs();
|
u64 now = porting::getTimeMs();
|
||||||
@ -204,6 +222,9 @@ void GUIChatConsole::reformatConsole()
|
|||||||
s32 rows = m_desired_height / m_fontsize.Y - 1; // make room for the input prompt
|
s32 rows = m_desired_height / m_fontsize.Y - 1; // make room for the input prompt
|
||||||
if (cols <= 0 || rows <= 0)
|
if (cols <= 0 || rows <= 0)
|
||||||
cols = rows = 0;
|
cols = rows = 0;
|
||||||
|
|
||||||
|
updateScrollbar(true);
|
||||||
|
|
||||||
recalculateConsolePosition();
|
recalculateConsolePosition();
|
||||||
m_chat_backend->reformat(cols, rows);
|
m_chat_backend->reformat(cols, rows);
|
||||||
}
|
}
|
||||||
@ -313,6 +334,14 @@ void GUIChatConsole::drawText()
|
|||||||
core::rect<s32> destrect(
|
core::rect<s32> destrect(
|
||||||
x, y, x + m_fontsize.X * fragment.text.size(), y + m_fontsize.Y);
|
x, y, x + m_fontsize.X * fragment.text.size(), y + m_fontsize.Y);
|
||||||
|
|
||||||
|
|
||||||
|
core::recti rect;
|
||||||
|
if (m_scrollbar->isVisible())
|
||||||
|
rect = core::rect<s32> (0, 0, m_screensize.X - getScrollbarSize(Environment), m_height);
|
||||||
|
else
|
||||||
|
rect = AbsoluteClippingRect;
|
||||||
|
|
||||||
|
|
||||||
if (m_font->getType() == irr::gui::EGFT_CUSTOM) {
|
if (m_font->getType() == irr::gui::EGFT_CUSTOM) {
|
||||||
// Draw colored text if possible
|
// Draw colored text if possible
|
||||||
gui::CGUITTFont *tmp = static_cast<gui::CGUITTFont*>(m_font);
|
gui::CGUITTFont *tmp = static_cast<gui::CGUITTFont*>(m_font);
|
||||||
@ -321,7 +350,7 @@ void GUIChatConsole::drawText()
|
|||||||
destrect,
|
destrect,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
&AbsoluteClippingRect);
|
&rect);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise use standard text
|
// Otherwise use standard text
|
||||||
m_font->draw(
|
m_font->draw(
|
||||||
@ -330,10 +359,12 @@ void GUIChatConsole::drawText()
|
|||||||
video::SColor(255, 255, 255, 255),
|
video::SColor(255, 255, 255, 255),
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
&AbsoluteClippingRect);
|
&rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateScrollbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIChatConsole::drawPrompt()
|
void GUIChatConsole::drawPrompt()
|
||||||
@ -680,6 +711,11 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
prompt.input(std::wstring(event.StringInput.Str->c_str()));
|
prompt.input(std::wstring(event.StringInput.Str->c_str()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_SCROLL_BAR_CHANGED &&
|
||||||
|
(void*) event.GUIEvent.Caller == (void*) m_scrollbar)
|
||||||
|
{
|
||||||
|
m_chat_backend->getConsoleBuffer().scrollAbsolute(m_scrollbar->getPos());
|
||||||
|
}
|
||||||
|
|
||||||
return Parent ? Parent->OnEvent(event) : false;
|
return Parent ? Parent->OnEvent(event) : false;
|
||||||
}
|
}
|
||||||
@ -692,6 +728,7 @@ void GUIChatConsole::setVisible(bool visible)
|
|||||||
m_height = 0;
|
m_height = 0;
|
||||||
recalculateConsolePosition();
|
recalculateConsolePosition();
|
||||||
}
|
}
|
||||||
|
m_scrollbar->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GUIChatConsole::weblinkClick(s32 col, s32 row)
|
bool GUIChatConsole::weblinkClick(s32 col, s32 row)
|
||||||
@ -763,3 +800,17 @@ void GUIChatConsole::updatePrimarySelection()
|
|||||||
std::string selected = wide_to_utf8(wselected);
|
std::string selected = wide_to_utf8(wselected);
|
||||||
Environment->getOSOperator()->copyToPrimarySelection(selected.c_str());
|
Environment->getOSOperator()->copyToPrimarySelection(selected.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GUIChatConsole::updateScrollbar(bool update_size)
|
||||||
|
{
|
||||||
|
m_scrollbar->setMin(m_chat_backend->getConsoleBuffer().getTopScrollPos());
|
||||||
|
m_scrollbar->setMax(m_chat_backend->getConsoleBuffer().getBottomScrollPos());
|
||||||
|
m_scrollbar->setPos(m_chat_backend->getConsoleBuffer().getScrollPosition());
|
||||||
|
m_scrollbar->setVisible(m_scrollbar->getMin() != m_scrollbar->getMax());
|
||||||
|
m_scrollbar->setPageSize(m_fontsize.Y * m_chat_backend->getConsoleBuffer().getLineCount());
|
||||||
|
|
||||||
|
if (update_size) {
|
||||||
|
const core::rect<s32> rect (m_screensize.X - getScrollbarSize(Environment), 0, m_screensize.X, m_height);
|
||||||
|
m_scrollbar->setRelativePosition(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
class Client;
|
class Client;
|
||||||
|
class GUIScrollBar;
|
||||||
|
|
||||||
class GUIChatConsole : public gui::IGUIElement
|
class GUIChatConsole : public gui::IGUIElement
|
||||||
{
|
{
|
||||||
@ -76,10 +77,13 @@ private:
|
|||||||
// If the selected text changed, we need to update the (X11) primary selection.
|
// If the selected text changed, we need to update the (X11) primary selection.
|
||||||
void updatePrimarySelection();
|
void updatePrimarySelection();
|
||||||
|
|
||||||
|
void updateScrollbar(bool update_size = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChatBackend* m_chat_backend;
|
ChatBackend* m_chat_backend;
|
||||||
Client* m_client;
|
Client* m_client;
|
||||||
IMenuManager* m_menumgr;
|
IMenuManager* m_menumgr;
|
||||||
|
GUIScrollBar* m_scrollbar = nullptr;
|
||||||
|
|
||||||
// current screen size
|
// current screen size
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
|
Loading…
Reference in New Issue
Block a user