mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add setting callbacks for Camera and TouchControls (#15700)
This commit is contained in:
parent
b5e084c9a5
commit
41dfac96c1
6 changed files with 71 additions and 25 deletions
|
@ -201,19 +201,40 @@ static EKEY_CODE id_to_keycode(touch_gui_button_id id)
|
|||
}
|
||||
|
||||
|
||||
static const char *setting_names[] = {
|
||||
"touchscreen_threshold", "touch_long_tap_delay",
|
||||
"fixed_virtual_joystick", "virtual_joystick_triggers_aux1",
|
||||
"touch_layout",
|
||||
};
|
||||
|
||||
TouchControls::TouchControls(IrrlichtDevice *device, ISimpleTextureSource *tsrc):
|
||||
m_device(device),
|
||||
m_guienv(device->getGUIEnvironment()),
|
||||
m_receiver(device->getEventReceiver()),
|
||||
m_texturesource(tsrc)
|
||||
{
|
||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||
m_button_size = ButtonLayout::getButtonSize(m_screensize);
|
||||
|
||||
readSettings();
|
||||
for (auto name : setting_names)
|
||||
g_settings->registerChangedCallback(name, settingChangedCallback, this);
|
||||
}
|
||||
|
||||
void TouchControls::settingChangedCallback(const std::string &name, void *data)
|
||||
{
|
||||
static_cast<TouchControls *>(data)->readSettings();
|
||||
}
|
||||
|
||||
void TouchControls::readSettings()
|
||||
{
|
||||
m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold");
|
||||
m_long_tap_delay = g_settings->getU16("touch_long_tap_delay");
|
||||
m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick");
|
||||
m_joystick_triggers_aux1 = g_settings->getBool("virtual_joystick_triggers_aux1");
|
||||
|
||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||
m_button_size = ButtonLayout::getButtonSize(m_screensize);
|
||||
// Note that "fixed_virtual_joystick" and "virtual_joystick_triggers_aux1"
|
||||
// also affect the layout.
|
||||
applyLayout(ButtonLayout::loadFromSettings());
|
||||
}
|
||||
|
||||
|
@ -314,6 +335,7 @@ void TouchControls::applyLayout(const ButtonLayout &layout)
|
|||
|
||||
TouchControls::~TouchControls()
|
||||
{
|
||||
g_settings->deregisterAllChangedCallbacks(this);
|
||||
releaseAll();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue