mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Implement an editor to customize the touchscreen controls (#14933)
- The editor is accessible via the pause menu and the settings menu. - Buttons can be moved via drag & drop. - Buttons can be added/removed. The grid menu added by #14918 is used to show all buttons not included in the layout. - Custom layouts are responsive and adapt to changed screen size / DPI / hud_scaling. - The layout is saved as JSON in the "touch_layout" setting.
This commit is contained in:
parent
4faa16fe0d
commit
6a1d22b2c5
18 changed files with 1122 additions and 195 deletions
28
src/irr_gui_ptr.h
Normal file
28
src/irr_gui_ptr.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
// Copyright (C) 2024 grorp, Gregor Parzefall <grorp@posteo.de>
|
||||
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "IGUIElement.h"
|
||||
|
||||
// We cannot use irr_ptr for Irrlicht GUI elements we own.
|
||||
// Option 1: Pass IGUIElement* returned by IGUIEnvironment::add* into irr_ptr
|
||||
// constructor.
|
||||
// -> We steal the reference owned by IGUIEnvironment and drop it later,
|
||||
// causing the IGUIElement to be deleted while IGUIEnvironment still
|
||||
// references it.
|
||||
// Option 2: Pass IGUIElement* returned by IGUIEnvironment::add* into irr_ptr::grab.
|
||||
// -> We add another reference and drop it later, but since IGUIEnvironment
|
||||
// still references the IGUIElement, it is never deleted.
|
||||
// To make IGUIEnvironment drop its reference to the IGUIElement, we have to call
|
||||
// IGUIElement::remove, so that's what we'll do.
|
||||
template <typename T>
|
||||
std::shared_ptr<T> grab_gui_element(T *element)
|
||||
{
|
||||
static_assert(std::is_base_of_v<irr::gui::IGUIElement, T>,
|
||||
"grab_gui_element only works for IGUIElement");
|
||||
return std::shared_ptr<T>(element, [](T *e) {
|
||||
e->remove();
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue