Luanti
5.11.0-dev
Loading...
Searching...
No Matches
irr_gui_ptr.h
Go to the documentation of this file.
1
// Luanti
2
// SPDX-License-Identifier: LGPL-2.1-or-later
3
// Copyright (C) 2024 grorp, Gregor Parzefall <grorp@posteo.de>
4
5
#pragma once
6
#include <memory>
7
#include "IGUIElement.h"
8
9
// We cannot use irr_ptr for Irrlicht GUI elements we own.
10
// Option 1: Pass IGUIElement* returned by IGUIEnvironment::add* into irr_ptr
11
// constructor.
12
// -> We steal the reference owned by IGUIEnvironment and drop it later,
13
// causing the IGUIElement to be deleted while IGUIEnvironment still
14
// references it.
15
// Option 2: Pass IGUIElement* returned by IGUIEnvironment::add* into irr_ptr::grab.
16
// -> We add another reference and drop it later, but since IGUIEnvironment
17
// still references the IGUIElement, it is never deleted.
18
// To make IGUIEnvironment drop its reference to the IGUIElement, we have to call
19
// IGUIElement::remove, so that's what we'll do.
20
template
<
typename
T>
21
std::shared_ptr<T>
grab_gui_element
(T *element)
22
{
23
static_assert
(std::is_base_of_v<irr::gui::IGUIElement, T>,
24
"grab_gui_element only works for IGUIElement"
);
25
return
std::shared_ptr<T>(element, [](T *e) {
26
e->remove();
27
});
28
}
grab_gui_element
std::shared_ptr< T > grab_gui_element(T *element)
Definition
irr_gui_ptr.h:21
irr_gui_ptr.h
Generated on Sun Dec 1 2024 10:42:55 for Luanti by
1.11.0