Skip to content

Commit

Permalink
Use irr_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Jan 10, 2025
1 parent 89749be commit 5c59851
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
22 changes: 6 additions & 16 deletions src/gui/guiChatConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ GUIChatConsole::GUIChatConsole(
}

const u16 chat_font_size = g_settings->getU16("chat_font_size");
m_font = g_fontengine->getFont(chat_font_size != 0 ?
rangelim(chat_font_size, 5, 72) : FONT_SIZE_UNSPECIFIED, FM_Mono);
m_font.grab(g_fontengine->getFont(chat_font_size != 0 ?
rangelim(chat_font_size, 5, 72) : FONT_SIZE_UNSPECIFIED, FM_Mono));

if (!m_font) {
errorstream << "GUIChatConsole: Unable to load mono font" << std::endl;
} else {
core::dimension2d<u32> dim = m_font->getDimension(L"M");
m_fontsize = v2u32(dim.Width, dim.Height);
m_font->grab();
}
m_fontsize.X = MYMAX(m_fontsize.X, 1);
m_fontsize.Y = MYMAX(m_fontsize.Y, 1);
Expand All @@ -88,21 +87,12 @@ GUIChatConsole::GUIChatConsole(
m_is_ctrl_down = false;
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.reset(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()
{
if (m_font)
m_font->drop();

if (m_scrollbar)
m_scrollbar->drop();
}

void GUIChatConsole::openConsole(f32 scale)
{
if (m_open)
Expand Down Expand Up @@ -315,7 +305,7 @@ void GUIChatConsole::drawBackground()

void GUIChatConsole::drawText()
{
if (m_font == NULL)
if (!m_font)
return;

ChatBuffer& buf = m_chat_backend->getConsoleBuffer();
Expand Down Expand Up @@ -344,7 +334,7 @@ void GUIChatConsole::drawText()

if (m_font->getType() == irr::gui::EGFT_CUSTOM) {
// Draw colored text if possible
gui::CGUITTFont *tmp = static_cast<gui::CGUITTFont*>(m_font);
auto *tmp = static_cast<gui::CGUITTFont*>(m_font.get());
tmp->draw(
fragment.text,
destrect,
Expand Down Expand Up @@ -712,7 +702,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
return true;
}
else if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_SCROLL_BAR_CHANGED &&
(void*) event.GUIEvent.Caller == (void*) m_scrollbar)
(void*) event.GUIEvent.Caller == (void*) m_scrollbar.get())
{
m_chat_backend->getConsoleBuffer().scrollAbsolute(m_scrollbar->getPos());
}
Expand Down
6 changes: 3 additions & 3 deletions src/gui/guiChatConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "modalMenu.h"
#include "chat.h"
#include "config.h"
#include "irr_ptr.h"

class Client;
class GUIScrollBar;
Expand All @@ -21,7 +22,6 @@ class GUIChatConsole : public gui::IGUIElement
ChatBackend* backend,
Client* client,
IMenuManager* menumgr);
virtual ~GUIChatConsole();

// Open the console (height = desired fraction of screen size)
// This doesn't open immediately but initiates an animation.
Expand Down Expand Up @@ -83,7 +83,7 @@ class GUIChatConsole : public gui::IGUIElement
ChatBackend* m_chat_backend;
Client* m_client;
IMenuManager* m_menumgr;
GUIScrollBar* m_scrollbar = nullptr;
irr_ptr<GUIScrollBar> m_scrollbar;

// current screen size
v2u32 m_screensize;
Expand Down Expand Up @@ -120,7 +120,7 @@ class GUIChatConsole : public gui::IGUIElement
video::SColor m_background_color = video::SColor(255, 0, 0, 0);

// font
gui::IGUIFont *m_font = nullptr;
irr_ptr<gui::IGUIFont> m_font;
v2u32 m_fontsize;

// Enable clickable chat weblinks
Expand Down

0 comments on commit 5c59851

Please sign in to comment.