1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-16 09:55:22 +02:00

Remove gui_button abstraction from joystick

It brings no benefit and doesn't make sense there
This commit is contained in:
Gregor Parzefall
2024-03-14 12:55:34 +01:00
parent 7a9315362b
commit 28ea8da7ca
2 changed files with 47 additions and 53 deletions

View File

@@ -122,7 +122,7 @@ static EKEY_CODE id_to_keycode(touch_gui_button_id id)
return code; return code;
} }
static void load_button_texture(button_info &btn, const std::string &path, static void load_button_texture(IGUIButton *gui_button, const std::string &path,
const rect<s32> &button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver) const rect<s32> &button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver)
{ {
u32 tid; u32 tid;
@@ -130,19 +130,19 @@ static void load_button_texture(button_info &btn, const std::string &path,
tsrc->getTexture(path, &tid), button_rect.getWidth(), tsrc->getTexture(path, &tid), button_rect.getWidth(),
button_rect.getHeight()); button_rect.getHeight());
if (texture) { if (texture) {
btn.gui_button->setUseAlphaChannel(true); gui_button->setUseAlphaChannel(true);
if (g_settings->getBool("gui_scaling_filter")) { if (g_settings->getBool("gui_scaling_filter")) {
rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), button_rect.getHeight()); rect<s32> txr_rect = rect<s32>(0, 0, button_rect.getWidth(), button_rect.getHeight());
btn.gui_button->setImage(texture, txr_rect); gui_button->setImage(texture, txr_rect);
btn.gui_button->setPressedImage(texture, txr_rect); gui_button->setPressedImage(texture, txr_rect);
btn.gui_button->setScaleImage(false); gui_button->setScaleImage(false);
} else { } else {
btn.gui_button->setImage(texture); gui_button->setImage(texture);
btn.gui_button->setPressedImage(texture); gui_button->setPressedImage(texture);
btn.gui_button->setScaleImage(true); gui_button->setScaleImage(true);
} }
btn.gui_button->setDrawBorder(false); gui_button->setDrawBorder(false);
btn.gui_button->setText(L""); gui_button->setText(L"");
} }
} }
@@ -166,7 +166,7 @@ AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device, ISimpleTextureSourc
m_starter.immediate_release = true; m_starter.immediate_release = true;
m_starter.pointer_ids.clear(); m_starter.pointer_ids.clear();
load_button_texture(m_starter, starter_img, starter_rect, load_button_texture(starter_gui_button, starter_img, starter_rect,
m_texturesource, m_driver); m_texturesource, m_driver);
m_dir = dir; m_dir = dir;
@@ -229,7 +229,7 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, const wchar_t *
btn.immediate_release = true; btn.immediate_release = true;
btn.pointer_ids.clear(); btn.pointer_ids.clear();
load_button_texture(btn, btn_image, current_button, m_texturesource, m_driver); load_button_texture(btn_gui_button, btn_image, current_button, m_texturesource, m_driver);
m_buttons.push_back(btn); m_buttons.push_back(btn);
} }
@@ -282,12 +282,12 @@ bool AutoHideButtonBar::isButton(const SEvent &event)
if (button.toggleable == button_info::FIRST_TEXTURE) { if (button.toggleable == button_info::FIRST_TEXTURE) {
button.toggleable = button_info::SECOND_TEXTURE; button.toggleable = button_info::SECOND_TEXTURE;
load_button_texture(button, button.textures[1], load_button_texture(button.gui_button.get(),button.textures[1],
button.gui_button->getRelativePosition(), button.gui_button->getRelativePosition(),
m_texturesource, m_driver); m_texturesource, m_driver);
} else if (button.toggleable == button_info::SECOND_TEXTURE) { } else if (button.toggleable == button_info::SECOND_TEXTURE) {
button.toggleable = button_info::FIRST_TEXTURE; button.toggleable = button_info::FIRST_TEXTURE;
load_button_texture(button, button.textures[0], load_button_texture(button.gui_button.get(), button.textures[0],
button.gui_button->getRelativePosition(), button.gui_button->getRelativePosition(),
m_texturesource, m_driver); m_texturesource, m_driver);
} }
@@ -394,28 +394,27 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, ISimpleTextureSource *tsr
// Initialize joystick display "button". // Initialize joystick display "button".
// Joystick is placed on the bottom left of screen. // Joystick is placed on the bottom left of screen.
if (m_fixed_joystick) { if (m_fixed_joystick) {
m_joystick_btn_off = initJoystickButton(joystick_off_id, m_joystick_btn_off.grab(initJoystickButton(joystick_off_id,
rect<s32>(m_button_size, rect<s32>(m_button_size,
m_screensize.Y - m_button_size * 4, m_screensize.Y - m_button_size * 4,
m_button_size * 4, m_button_size * 4,
m_screensize.Y - m_button_size), 0); m_screensize.Y - m_button_size), true));
} else { } else {
m_joystick_btn_off = initJoystickButton(joystick_off_id, m_joystick_btn_off.grab(initJoystickButton(joystick_off_id,
rect<s32>(m_button_size, rect<s32>(m_button_size,
m_screensize.Y - m_button_size * 3, m_screensize.Y - m_button_size * 3,
m_button_size * 3, m_button_size * 3,
m_screensize.Y - m_button_size), 0); m_screensize.Y - m_button_size), true));
} }
m_joystick_btn_bg = initJoystickButton(joystick_bg_id, m_joystick_btn_bg.grab(initJoystickButton(joystick_bg_id,
rect<s32>(m_button_size, rect<s32>(m_button_size,
m_screensize.Y - m_button_size * 4, m_screensize.Y - m_button_size * 4,
m_button_size * 4, m_button_size * 4,
m_screensize.Y - m_button_size), m_screensize.Y - m_button_size), false));
1, false);
m_joystick_btn_center = initJoystickButton(joystick_center_id, m_joystick_btn_center.grab(initJoystickButton(joystick_center_id,
rect<s32>(0, 0, m_button_size, m_button_size), 2, false); rect<s32>(0, 0, m_button_size, m_button_size), false));
// init jump button // init jump button
initButton(jump_id, initButton(jump_id,
@@ -521,24 +520,20 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, const rect<s32> &button_
btn.immediate_release = immediate_release; btn.immediate_release = immediate_release;
btn.pointer_ids.clear(); btn.pointer_ids.clear();
load_button_texture(btn, button_image_names[id], button_rect, load_button_texture(btn_gui_button, button_image_names[id], button_rect,
m_texturesource, m_device->getVideoDriver()); m_texturesource, m_device->getVideoDriver());
} }
button_info TouchScreenGUI::initJoystickButton(touch_gui_button_id id, IGUIButton *TouchScreenGUI::initJoystickButton(touch_gui_button_id id,
const rect<s32> &button_rect, int texture_id, bool visible) const rect<s32> &button_rect, bool visible)
{ {
IGUIButton *btn_gui_button = m_guienv->addButton(button_rect, nullptr, id, L"O"); IGUIButton *btn_gui_button = m_guienv->addButton(button_rect, nullptr, id);
btn_gui_button->setVisible(visible);
button_info btn; load_button_texture(btn_gui_button, joystick_image_names[id], button_rect,
btn.gui_button.grab(btn_gui_button);
btn.gui_button->setVisible(visible);
btn.pointer_ids.clear();
load_button_texture(btn, joystick_image_names[texture_id], button_rect,
m_texturesource, m_device->getVideoDriver()); m_texturesource, m_device->getVideoDriver());
return btn; return btn_gui_button;
} }
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y) touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
@@ -666,9 +661,9 @@ void TouchScreenGUI::handleReleaseEvent(size_t pointer_id)
m_joystick_status_aux1 = false; m_joystick_status_aux1 = false;
applyJoystickStatus(); applyJoystickStatus();
m_joystick_btn_off.gui_button->setVisible(true); m_joystick_btn_off->setVisible(true);
m_joystick_btn_bg.gui_button->setVisible(false); m_joystick_btn_bg->setVisible(false);
m_joystick_btn_center.gui_button->setVisible(false); m_joystick_btn_center->setVisible(false);
} else { } else {
infostream << "TouchScreenGUI::translateEvent released unknown button: " infostream << "TouchScreenGUI::translateEvent released unknown button: "
<< pointer_id << std::endl; << pointer_id << std::endl;
@@ -749,16 +744,16 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
m_joystick_id = pointer_id; m_joystick_id = pointer_id;
m_joystick_has_really_moved = false; m_joystick_has_really_moved = false;
m_joystick_btn_off.gui_button->setVisible(false); m_joystick_btn_off->setVisible(false);
m_joystick_btn_bg.gui_button->setVisible(true); m_joystick_btn_bg->setVisible(true);
m_joystick_btn_center.gui_button->setVisible(true); m_joystick_btn_center->setVisible(true);
// If it's a fixed joystick, don't move the joystick "button". // If it's a fixed joystick, don't move the joystick "button".
if (!m_fixed_joystick) if (!m_fixed_joystick)
m_joystick_btn_bg.gui_button->setRelativePosition( m_joystick_btn_bg->setRelativePosition(
touch_pos - half_button_size * 3); touch_pos - half_button_size * 3);
m_joystick_btn_center.gui_button->setRelativePosition( m_joystick_btn_center->setRelativePosition(
touch_pos - half_button_size); touch_pos - half_button_size);
} }
} else { } else {
@@ -833,13 +828,13 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
// move joystick "button" // move joystick "button"
v2s32 new_offset = dir * m_button_size / distance - half_button_size; v2s32 new_offset = dir * m_button_size / distance - half_button_size;
if (m_fixed_joystick) if (m_fixed_joystick)
m_joystick_btn_center.gui_button->setRelativePosition( m_joystick_btn_center->setRelativePosition(
fixed_joystick_center + new_offset); fixed_joystick_center + new_offset);
else else
m_joystick_btn_center.gui_button->setRelativePosition( m_joystick_btn_center->setRelativePosition(
free_joystick_center + new_offset); free_joystick_center + new_offset);
} else { } else {
m_joystick_btn_center.gui_button->setRelativePosition( m_joystick_btn_center->setRelativePosition(
touch_pos - half_button_size); touch_pos - half_button_size);
} }
} }
@@ -972,8 +967,8 @@ void TouchScreenGUI::setVisible(bool visible)
button.gui_button->setVisible(visible); button.gui_button->setVisible(visible);
} }
if (m_joystick_btn_off.gui_button) if (m_joystick_btn_off)
m_joystick_btn_off.gui_button->setVisible(visible); m_joystick_btn_off->setVisible(visible);
// clear all active buttons // clear all active buttons
if (!visible) { if (!visible) {

View File

@@ -251,9 +251,9 @@ private:
bool m_fixed_joystick = false; bool m_fixed_joystick = false;
bool m_joystick_triggers_aux1 = false; bool m_joystick_triggers_aux1 = false;
bool m_draw_crosshair = false; bool m_draw_crosshair = false;
button_info m_joystick_btn_off; irr_ptr<IGUIButton> m_joystick_btn_off;
button_info m_joystick_btn_bg; irr_ptr<IGUIButton> m_joystick_btn_bg;
button_info m_joystick_btn_center; irr_ptr<IGUIButton> m_joystick_btn_center;
button_info m_buttons[after_last_element_id]; button_info m_buttons[after_last_element_id];
@@ -272,9 +272,8 @@ private:
float repeat_delay = BUTTON_REPEAT_DELAY); float repeat_delay = BUTTON_REPEAT_DELAY);
// initialize a joystick button // initialize a joystick button
button_info initJoystickButton(touch_gui_button_id id, IGUIButton *initJoystickButton(touch_gui_button_id id,
const rect<s32> &button_rect, int texture_id, const rect<s32> &button_rect, bool visible);
bool visible = true);
// handle a button event // handle a button event
void handleButtonEvent(touch_gui_button_id id, size_t pointer_id, bool action); void handleButtonEvent(touch_gui_button_id id, size_t pointer_id, bool action);