Add visual feedback to touchscreen buttons

This commit is contained in:
MoNTE48 2019-09-11 18:28:44 +02:00
parent b953e12cc5
commit ed99c0b5bd
10 changed files with 78 additions and 70 deletions

View File

@ -35,27 +35,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
using namespace irr::core; using namespace irr::core;
const char **touchgui_button_imagenames = (const char *[]) { const char *touchgui_button_imagenames[][2] = {
"up_one_btn.png", {"up_one_btn.png", "up_one_press.png"},
"up_two_btn.png", {"up_two_btn.png","up_two_press.png"},
"up_three_btn.png", {"up_three_btn.png", "up_three_press.png"},
"down_one_btn.png", {"down_one_btn.png", "down_one_press.png"},
"down_two_btn.png", {"down_two_btn.png", "down_two_press.png"},
"down_three_btn.png", {"down_three_btn.png", "down_three_press.png"},
"left_btn.png", {"left_btn.png", "left_press.png"},
"right_btn.png", {"right_btn.png", "right_press.png"},
"inventory_btn.png", {"empty_btn.png"},
"drop_btn.png", {"inventory_btn.png"},
"jump_btn.png", {"drop_btn.png"},
"down_btn.png", {"jump_btn.png"},
// "noclip_btn.png", {"down_btn.png"},
"escape_btn.png", {"escape_btn.png"},
"minimap_btn.png", {"minimap_btn.png"},
"rangeview_btn.png", {"rangeview_btn.png"},
"chat_btn.png", {"chat_btn.png"}
// "debug_btn.png", /* {"noclip_btn.png"},
// "camera_btn.png", {"fast_btn.png"},
"empty_btn.png" {"camera_btn.png"} */
}; };
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) { static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
@ -85,6 +85,9 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
case right_id: case right_id:
key = "right"; key = "right";
break; break;
case empty_id:
key = "forward";
break;
case inventory_id: case inventory_id:
key = "inventory"; key = "inventory";
break; break;
@ -97,15 +100,6 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
case crunch_id: case crunch_id:
key = "sneak"; key = "sneak";
break; break;
/* case noclip_id:
key = "noclip";
break;
case fast_id:
key = "fast";
break;
case debug_id:
key = "toggle_debug";
break;*/
case escape_id: case escape_id:
return irr::KEY_ESCAPE; return irr::KEY_ESCAPE;
case minimap_id: case minimap_id:
@ -117,12 +111,15 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
case chat_id: case chat_id:
key = "chat"; key = "chat";
break; break;
/* case camera_id: /* case noclip_id:
key = "noclip";
break;
case fast_id:
key = "fast";
break;
case camera_id:
key = "camera_mode"; key = "camera_mode";
break; */ break; */
case empty_id:
key = "forward";
break;
case after_last_element_id: case after_last_element_id:
break; break;
} }
@ -132,24 +129,38 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
TouchScreenGUI *g_touchscreengui; TouchScreenGUI *g_touchscreengui;
static void load_button_texture(button_info *btn, const char *path, static void load_button_texture(button_info *btn, touch_gui_button_id id,
rect<s32> button_rect, ISimpleTextureSource *tsrc, rect<s32> button_rect, ISimpleTextureSource *tsrc,
video::IVideoDriver *driver) { video::IVideoDriver *driver) {
const char *path = touchgui_button_imagenames[id][0];
const char *path_pressed = (touchgui_button_imagenames[id][1]) ? touchgui_button_imagenames[id][1] : path;
unsigned int tid; unsigned int tid;
video::ITexture *texture = guiScalingImageButton(driver, video::ITexture *texture = guiScalingImageButton(driver,
tsrc->getTexture(path, &tid), tsrc->getTexture(path, &tid),
button_rect.getWidth(), button_rect.getWidth(),
button_rect.getHeight()); button_rect.getHeight());
video::ITexture *texture_pressed = texture;
if (strcmp(path, path_pressed) != 0) {
texture_pressed = guiScalingImageButton(driver,
tsrc->getTexture(path_pressed, &tid),
button_rect.getWidth(),
button_rect.getHeight());
texture_pressed = (texture_pressed) ? texture_pressed : texture;
}
if (texture) { if (texture) {
btn->guibutton->setUseAlphaChannel(true); btn->guibutton->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->guibutton->setImage(texture, txr_rect); btn->guibutton->setImage(texture, txr_rect);
btn->guibutton->setPressedImage(texture, txr_rect); btn->guibutton->setPressedImage(texture_pressed, txr_rect);
btn->guibutton->setScaleImage(false); btn->guibutton->setScaleImage(false);
} else { } else {
btn->guibutton->setImage(texture); btn->guibutton->setImage(texture);
btn->guibutton->setPressedImage(texture); btn->guibutton->setPressedImage(texture_pressed);
btn->guibutton->setScaleImage(true); btn->guibutton->setScaleImage(true);
} }
btn->guibutton->setDrawBorder(false); btn->guibutton->setDrawBorder(false);
@ -191,7 +202,8 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
btn->immediate_release = immediate_release; btn->immediate_release = immediate_release;
btn->ids.clear(); btn->ids.clear();
load_button_texture(btn, touchgui_button_imagenames[id], button_rect,
load_button_texture(btn, id, button_rect,
m_texturesource, m_device->getVideoDriver()); m_texturesource, m_device->getVideoDriver());
} }
@ -299,23 +311,6 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
m_screensize.Y - (button_size)), m_screensize.Y - (button_size)),
L"x", false, SLOW_BUTTON_REPEAT); L"x", false, SLOW_BUTTON_REPEAT);
/*
// init noclip button
initButton(noclip_id,
rect<s32>(m_screensize.X - (button_size * 0.75),
m_screensize.Y - (button_size * 4.75),
m_screensize.X,
m_screensize.Y - (button_size * 4)),
L"clip", false, SLOW_BUTTON_REPEAT);
// init fast button
initButton(fast_id,
rect<s32>(m_screensize.X - (button_size * 0.75),
m_screensize.Y - (button_size * 4),
m_screensize.X,
m_screensize.Y - (button_size * 3.25)),
L"fast", false, SLOW_BUTTON_REPEAT);
*/
// iOS does not have a physical pause button and have memory leak with minimap // iOS does not have a physical pause button and have memory leak with minimap
#ifdef __IOS__ #ifdef __IOS__
// init pause button // init pause button
@ -347,8 +342,23 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
(button_size * 0.75)), (button_size * 0.75)),
L"Chat", false, SLOW_BUTTON_REPEAT); L"Chat", false, SLOW_BUTTON_REPEAT);
// init noclip button
/* initButton(noclip_id,
rect<s32>(m_screensize.X - (button_size * 0.75),
m_screensize.Y - (button_size * 4.75),
m_screensize.X,
m_screensize.Y - (button_size * 4)),
L"clip", false, SLOW_BUTTON_REPEAT);
// init fast button
initButton(fast_id,
rect<s32>(m_screensize.X - (button_size * 0.75),
m_screensize.Y - (button_size * 4),
m_screensize.X,
m_screensize.Y - (button_size * 3.25)),
L"fast", false, SLOW_BUTTON_REPEAT);
// init camera button // init camera button
/* initButton(camera_id, initButton(camera_id,
rect<s32>(0, 0, rect<s32>(0, 0,
button_size * 0.75, button_size * 0.75), button_size * 0.75, button_size * 0.75),
L"cam", false, SLOW_BUTTON_REPEAT); */ L"cam", false, SLOW_BUTTON_REPEAT); */
@ -433,6 +443,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
return; return;
btn->repeatcounter = 0; btn->repeatcounter = 0;
m_buttons[button].guibutton->setPressed(true);
translated->KeyInput.PressedDown = true; translated->KeyInput.PressedDown = true;
translated->KeyInput.Key = btn->keycode; translated->KeyInput.Key = btn->keycode;
m_receiver->OnEvent(*translated); m_receiver->OnEvent(*translated);
@ -449,6 +460,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
if (!btn->ids.empty()) if (!btn->ids.empty())
return; return;
m_buttons[button].guibutton->setPressed(false);
translated->KeyInput.PressedDown = false; translated->KeyInput.PressedDown = false;
btn->repeatcounter = -1; btn->repeatcounter = -1;
m_receiver->OnEvent(*translated); m_receiver->OnEvent(*translated);
@ -456,7 +468,6 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
delete translated; delete translated;
} }
void TouchScreenGUI::handleReleaseEvent(size_t evt_id) { void TouchScreenGUI::handleReleaseEvent(size_t evt_id) {
touch_gui_button_id button = getButtonID(evt_id); touch_gui_button_id button = getButtonID(evt_id);

View File

@ -43,19 +43,18 @@ typedef enum {
backward_three, backward_three,
left_id, left_id,
right_id, right_id,
empty_id,
inventory_id, inventory_id,
drop_id, drop_id,
jump_id, jump_id,
crunch_id, crunch_id,
// noclip_id,
// fast_id,
// debug_id,
escape_id, escape_id,
minimap_id, minimap_id,
range_id, range_id,
chat_id, chat_id,
// camera_id, /* noclip_id,
empty_id, fast_id,
camera_id, */
after_last_element_id after_last_element_id
} touch_gui_button_id; } touch_gui_button_id;
@ -63,8 +62,6 @@ typedef enum {
#define MIN_DIG_TIME 0.5f #define MIN_DIG_TIME 0.5f
#define BUTTON_REPEAT_DELAY 0.2f #define BUTTON_REPEAT_DELAY 0.2f
extern const char **touchgui_button_imagenames;
struct button_info { struct button_info {
float repeatcounter; float repeatcounter;
float repeatdelay; float repeatdelay;

BIN
textures/base/down_one_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 627 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

BIN
textures/base/down_two_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

BIN
textures/base/left_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

BIN
textures/base/right_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

BIN
textures/base/up_one_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

BIN
textures/base/up_three_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

BIN
textures/base/up_two_press.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B