1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
luanti/src/gui/touchscreeneditor.h
grorp 6a1d22b2c5
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.
2024-11-24 11:33:39 +01:00

81 lines
2 KiB
C++

// Luanti
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2024 grorp, Gregor Parzefall <grorp@posteo.de>
#pragma once
#include "touchscreenlayout.h"
#include "modalMenu.h"
#include <memory>
#include <unordered_map>
class ISimpleTextureSource;
namespace irr::gui
{
class IGUIImage;
}
class GUITouchscreenLayout : public GUIModalMenu
{
public:
GUITouchscreenLayout(gui::IGUIEnvironment* env,
gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, ISimpleTextureSource *tsrc);
~GUITouchscreenLayout();
void regenerateGui(v2u32 screensize);
void drawMenu();
bool OnEvent(const SEvent& event);
protected:
std::wstring getLabelByID(s32 id) { return L""; }
std::string getNameByID(s32 id) { return ""; }
private:
ISimpleTextureSource *m_tsrc;
ButtonLayout m_layout;
v2u32 m_last_screensize;
s32 m_button_size;
enum class Mode {
Default,
Dragging,
Add,
};
Mode m_mode = Mode::Default;
std::unordered_map<touch_gui_button_id, std::shared_ptr<gui::IGUIImage>> m_gui_images;
// unused if m_mode == Mode::Add
std::unordered_map<touch_gui_button_id, v2s32> m_gui_images_target_pos;
void clearGUIImages();
void regenerateGUIImagesRegular(v2u32 screensize);
void regenerateGUIImagesAddMode(v2u32 screensize);
void interpolateGUIImages();
// interaction state
bool m_mouse_down = false;
v2s32 m_last_mouse_pos;
touch_gui_button_id m_selected_btn = touch_gui_button_id_END;
// dragging
ButtonLayout m_last_good_layout;
std::vector<core::recti> m_error_rects;
void updateDragState(v2u32 screensize, v2s32 mouse_movement);
// add mode
ButtonLayout m_add_layout;
std::vector<std::shared_ptr<gui::IGUIStaticText>> m_add_button_titles;
// Menu GUI elements
std::shared_ptr<gui::IGUIStaticText> m_gui_help_text;
std::shared_ptr<gui::IGUIButton> m_gui_add_btn;
std::shared_ptr<gui::IGUIButton> m_gui_reset_btn;
std::shared_ptr<gui::IGUIButton> m_gui_done_btn;
std::shared_ptr<gui::IGUIButton> m_gui_remove_btn;
void regenerateMenu(v2u32 screensize);
};