forked from Mirrorlandia_minetest/minetest
Android: Modify touch screen GUI's buttons (#7240)
* Android: Add zoom, minimap, and toggle chat button Zoom button is put above jump button. Minimap and toggle chat button are put in settings bar. * Jump button is rotated down button * Move three buttons on the right screen higher
This commit is contained in:
parent
cca925377b
commit
b1e58c9c35
@ -31,6 +31,14 @@ erlehmann:
|
|||||||
JRottm
|
JRottm
|
||||||
textures/base/pack/player_marker.png
|
textures/base/pack/player_marker.png
|
||||||
|
|
||||||
|
srifqi
|
||||||
|
textures/base/pack/chat_hide_btn.png
|
||||||
|
textures/base/pack/chat_show_btn.png
|
||||||
|
textures/base/pack/joystick_bg.png
|
||||||
|
textures/base/pack/joystick_center.png
|
||||||
|
textures/base/pack/joystick_off.png
|
||||||
|
textures/base/pack/minimap_btn.png
|
||||||
|
|
||||||
License of Minetest source code
|
License of Minetest source code
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
@ -39,9 +39,10 @@ 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 = (const char *[]) {
|
||||||
"jump_btn.png",
|
"jump_btn.png",
|
||||||
"down.png"
|
"down.png",
|
||||||
|
"zoom.png"
|
||||||
};
|
};
|
||||||
|
|
||||||
const char **touchgui_joystick_imagenames = (const char *[]) {
|
const char **touchgui_joystick_imagenames = (const char *[]) {
|
||||||
@ -78,6 +79,9 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
|||||||
case crunch_id:
|
case crunch_id:
|
||||||
key = "sneak";
|
key = "sneak";
|
||||||
break;
|
break;
|
||||||
|
case zoom_id:
|
||||||
|
key = "zoom";
|
||||||
|
break;
|
||||||
case fly_id:
|
case fly_id:
|
||||||
key = "freemove";
|
key = "freemove";
|
||||||
break;
|
break;
|
||||||
@ -90,6 +94,12 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
|||||||
case debug_id:
|
case debug_id:
|
||||||
key = "toggle_debug";
|
key = "toggle_debug";
|
||||||
break;
|
break;
|
||||||
|
case toggle_chat_id:
|
||||||
|
key = "toggle_chat";
|
||||||
|
break;
|
||||||
|
case minimap_id:
|
||||||
|
key = "minimap";
|
||||||
|
break;
|
||||||
case chat_id:
|
case chat_id:
|
||||||
key = "chat";
|
key = "chat";
|
||||||
break;
|
break;
|
||||||
@ -106,8 +116,8 @@ 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, const char *path,
|
||||||
rect<s32> button_rect, ISimpleTextureSource* tsrc, video::IVideoDriver *driver)
|
rect<s32> button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver)
|
||||||
{
|
{
|
||||||
unsigned int tid;
|
unsigned int tid;
|
||||||
video::ITexture *texture = guiScalingImageButton(driver,
|
video::ITexture *texture = guiScalingImageButton(driver,
|
||||||
@ -131,15 +141,15 @@ static void load_button_texture(button_info* btn, const char* path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device,
|
AutoHideButtonBar::AutoHideButtonBar(IrrlichtDevice *device,
|
||||||
IEventReceiver* receiver) :
|
IEventReceiver *receiver) :
|
||||||
m_driver(device->getVideoDriver()),
|
m_driver(device->getVideoDriver()),
|
||||||
m_guienv(device->getGUIEnvironment()),
|
m_guienv(device->getGUIEnvironment()),
|
||||||
m_receiver(receiver)
|
m_receiver(receiver)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoHideButtonBar::init(ISimpleTextureSource* tsrc,
|
void AutoHideButtonBar::init(ISimpleTextureSource *tsrc,
|
||||||
const char* starter_img, int button_id, v2s32 UpperLeft,
|
const char *starter_img, int button_id, v2s32 UpperLeft,
|
||||||
v2s32 LowerRight, autohide_button_bar_dir dir, float timeout)
|
v2s32 LowerRight, autohide_button_bar_dir dir, float timeout)
|
||||||
{
|
{
|
||||||
m_texturesource = tsrc;
|
m_texturesource = tsrc;
|
||||||
@ -177,7 +187,7 @@ AutoHideButtonBar::~AutoHideButtonBar()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
||||||
const wchar_t* caption, const char* btn_image)
|
const wchar_t *caption, const char *btn_image)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!m_initialized) {
|
if (!m_initialized) {
|
||||||
@ -230,7 +240,7 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
|||||||
y_end);
|
y_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
button_info* btn = new button_info();
|
button_info *btn = new button_info();
|
||||||
btn->guibutton = m_guienv->addButton(current_button, 0, button_id, caption, 0);
|
btn->guibutton = m_guienv->addButton(current_button, 0, button_id, caption, 0);
|
||||||
btn->guibutton->grab();
|
btn->guibutton->grab();
|
||||||
btn->guibutton->setVisible(false);
|
btn->guibutton->setVisible(false);
|
||||||
@ -246,9 +256,20 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id,
|
|||||||
m_buttons.push_back(btn);
|
m_buttons.push_back(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoHideButtonBar::addToggleButton(touch_gui_button_id button_id,
|
||||||
|
const wchar_t *caption, const char *btn_image_1,
|
||||||
|
const char *btn_image_2)
|
||||||
|
{
|
||||||
|
addButton(button_id, caption, btn_image_1);
|
||||||
|
button_info *btn = m_buttons.back();
|
||||||
|
btn->togglable = 1;
|
||||||
|
btn->textures.push_back(btn_image_1);
|
||||||
|
btn->textures.push_back(btn_image_2);
|
||||||
|
}
|
||||||
|
|
||||||
bool AutoHideButtonBar::isButton(const SEvent &event)
|
bool AutoHideButtonBar::isButton(const SEvent &event)
|
||||||
{
|
{
|
||||||
IGUIElement* rootguielement = m_guienv->getRootGUIElement();
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
||||||
|
|
||||||
if (rootguielement == NULL) {
|
if (rootguielement == NULL) {
|
||||||
return false;
|
return false;
|
||||||
@ -264,12 +285,12 @@ bool AutoHideButtonBar::isButton(const SEvent &event)
|
|||||||
if (m_active) {
|
if (m_active) {
|
||||||
// check for all buttons in vector
|
// check for all buttons in vector
|
||||||
|
|
||||||
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
||||||
|
|
||||||
while (iter != m_buttons.end()) {
|
while (iter != m_buttons.end()) {
|
||||||
if ((*iter)->guibutton == element) {
|
if ((*iter)->guibutton == element) {
|
||||||
|
|
||||||
SEvent* translated = new SEvent();
|
SEvent *translated = new SEvent();
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = (*iter)->keycode;
|
translated->KeyInput.Key = (*iter)->keycode;
|
||||||
@ -291,6 +312,18 @@ bool AutoHideButtonBar::isButton(const SEvent &event)
|
|||||||
|
|
||||||
m_timeout = 0;
|
m_timeout = 0;
|
||||||
|
|
||||||
|
if ((*iter)->togglable == 1) {
|
||||||
|
(*iter)->togglable = 2;
|
||||||
|
load_button_texture(*iter, (*iter)->textures[1],
|
||||||
|
(*iter)->guibutton->getRelativePosition(),
|
||||||
|
m_texturesource, m_driver);
|
||||||
|
} else if ((*iter)->togglable == 2) {
|
||||||
|
(*iter)->togglable = 1;
|
||||||
|
load_button_texture(*iter, (*iter)->textures[0],
|
||||||
|
(*iter)->guibutton->getRelativePosition(),
|
||||||
|
m_texturesource, m_driver);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
@ -328,7 +361,7 @@ bool AutoHideButtonBar::isReleaseButton(int eventID)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
||||||
|
|
||||||
while (iter != m_buttons.end()) {
|
while (iter != m_buttons.end()) {
|
||||||
std::vector<int>::iterator id = std::find((*iter)->ids.begin(),
|
std::vector<int>::iterator id = std::find((*iter)->ids.begin(),
|
||||||
@ -364,7 +397,7 @@ void AutoHideButtonBar::deactivate()
|
|||||||
}
|
}
|
||||||
m_active = false;
|
m_active = false;
|
||||||
|
|
||||||
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
||||||
|
|
||||||
while (iter != m_buttons.end()) {
|
while (iter != m_buttons.end()) {
|
||||||
(*iter)->guibutton->setVisible(false);
|
(*iter)->guibutton->setVisible(false);
|
||||||
@ -379,7 +412,7 @@ void AutoHideButtonBar::hide()
|
|||||||
m_starter.guibutton->setVisible(false);
|
m_starter.guibutton->setVisible(false);
|
||||||
m_starter.guibutton->setEnabled(false);
|
m_starter.guibutton->setEnabled(false);
|
||||||
|
|
||||||
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
||||||
|
|
||||||
while (iter != m_buttons.end()) {
|
while (iter != m_buttons.end()) {
|
||||||
(*iter)->guibutton->setVisible(false);
|
(*iter)->guibutton->setVisible(false);
|
||||||
@ -393,7 +426,7 @@ void AutoHideButtonBar::show()
|
|||||||
m_visible = true;
|
m_visible = true;
|
||||||
|
|
||||||
if (m_active) {
|
if (m_active) {
|
||||||
std::vector<button_info*>::iterator iter = m_buttons.begin();
|
std::vector<button_info *>::iterator iter = m_buttons.begin();
|
||||||
|
|
||||||
while (iter != m_buttons.end()) {
|
while (iter != m_buttons.end()) {
|
||||||
(*iter)->guibutton->setVisible(true);
|
(*iter)->guibutton->setVisible(true);
|
||||||
@ -406,7 +439,7 @@ void AutoHideButtonBar::show()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver):
|
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver):
|
||||||
m_device(device),
|
m_device(device),
|
||||||
m_guienv(device->getGUIEnvironment()),
|
m_guienv(device->getGUIEnvironment()),
|
||||||
m_receiver(receiver),
|
m_receiver(receiver),
|
||||||
@ -428,7 +461,7 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
|||||||
std::wstring caption, bool immediate_release, float repeat_delay)
|
std::wstring caption, bool immediate_release, float repeat_delay)
|
||||||
{
|
{
|
||||||
|
|
||||||
button_info* btn = &m_buttons[id];
|
button_info *btn = &m_buttons[id];
|
||||||
btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str());
|
btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str());
|
||||||
btn->guibutton->grab();
|
btn->guibutton->grab();
|
||||||
btn->repeatcounter = -1;
|
btn->repeatcounter = -1;
|
||||||
@ -437,7 +470,7 @@ 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, touchgui_button_imagenames[id], button_rect,
|
||||||
m_texturesource, m_device->getVideoDriver());
|
m_texturesource, m_device->getVideoDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,7 +501,7 @@ int TouchScreenGUI::getGuiButtonSize()
|
|||||||
return control_pad_size / 3;
|
return control_pad_size / 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
|
||||||
{
|
{
|
||||||
assert(tsrc);
|
assert(tsrc);
|
||||||
|
|
||||||
@ -505,19 +538,27 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|||||||
|
|
||||||
// init jump button
|
// init jump button
|
||||||
initButton(jump_id,
|
initButton(jump_id,
|
||||||
rect<s32>(m_screensize.X-(1.75*button_size),
|
rect<s32>(m_screensize.X - (1.75 * button_size),
|
||||||
m_screensize.Y - (0.5*button_size),
|
m_screensize.Y - button_size,
|
||||||
m_screensize.X-(0.25*button_size),
|
m_screensize.X - (0.25 * button_size),
|
||||||
m_screensize.Y),
|
m_screensize.Y - (0.5 * button_size)),
|
||||||
L"x",false);
|
L"x", false);
|
||||||
|
|
||||||
// init crunch button
|
// init crunch button
|
||||||
initButton(crunch_id,
|
initButton(crunch_id,
|
||||||
rect<s32>(m_screensize.X-(3.25*button_size),
|
rect<s32>(m_screensize.X - (3.25 * button_size),
|
||||||
m_screensize.Y - (0.5*button_size),
|
m_screensize.Y - button_size,
|
||||||
m_screensize.X-(1.75*button_size),
|
m_screensize.X - (1.75 * button_size),
|
||||||
m_screensize.Y),
|
m_screensize.Y - (0.5 * button_size)),
|
||||||
L"H",false);
|
L"H", false);
|
||||||
|
|
||||||
|
// init zoom button
|
||||||
|
initButton(zoom_id,
|
||||||
|
rect<s32>(m_screensize.X - (1.25 * button_size),
|
||||||
|
m_screensize.Y - (3 * button_size),
|
||||||
|
m_screensize.X - (0.25 * button_size),
|
||||||
|
m_screensize.Y - (2 * button_size)),
|
||||||
|
L"z", false);
|
||||||
|
|
||||||
m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
|
m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id,
|
||||||
v2s32(m_screensize.X - (button_size / 2),
|
v2s32(m_screensize.X - (button_size / 2),
|
||||||
@ -528,12 +569,17 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|||||||
+ (button_size * 0.5)), AHBB_Dir_Right_Left,
|
+ (button_size * 0.5)), AHBB_Dir_Right_Left,
|
||||||
3.0);
|
3.0);
|
||||||
|
|
||||||
m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png");
|
m_settingsbar.addButton(fly_id, L"fly", "fly_btn.png");
|
||||||
m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png");
|
m_settingsbar.addButton(noclip_id, L"noclip", "noclip_btn.png");
|
||||||
m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png");
|
m_settingsbar.addButton(fast_id, L"fast", "fast_btn.png");
|
||||||
m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
|
m_settingsbar.addButton(debug_id, L"debug", "debug_btn.png");
|
||||||
m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
|
m_settingsbar.addButton(camera_id, L"camera", "camera_btn.png");
|
||||||
m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
|
m_settingsbar.addButton(range_id, L"rangeview", "rangeview_btn.png");
|
||||||
|
m_settingsbar.addButton(minimap_id, L"minimap", "minimap_btn.png");
|
||||||
|
|
||||||
|
// Chat is shown by default, so chat_hide_btn.png is shown first.
|
||||||
|
m_settingsbar.addToggleButton(toggle_chat_id, L"togglechat",
|
||||||
|
"chat_hide_btn.png", "chat_show_btn.png");
|
||||||
|
|
||||||
m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
|
m_rarecontrolsbar.init(m_texturesource, "rare_controls.png",
|
||||||
rare_controls_starter_id,
|
rare_controls_starter_id,
|
||||||
@ -554,11 +600,11 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|||||||
|
|
||||||
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
||||||
{
|
{
|
||||||
IGUIElement* rootguielement = m_guienv->getRootGUIElement();
|
IGUIElement *rootguielement = m_guienv->getRootGUIElement();
|
||||||
|
|
||||||
if (rootguielement != NULL) {
|
if (rootguielement != NULL) {
|
||||||
gui::IGUIElement *element =
|
gui::IGUIElement *element =
|
||||||
rootguielement->getElementFromPoint(core::position2d<s32>(x,y));
|
rootguielement->getElementFromPoint(core::position2d<s32>(x, y));
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
for (unsigned int i=0; i < after_last_element_id; i++) {
|
for (unsigned int i=0; i < after_last_element_id; i++) {
|
||||||
@ -574,10 +620,10 @@ touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
|||||||
touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
|
touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
|
||||||
{
|
{
|
||||||
for (unsigned int i=0; i < after_last_element_id; i++) {
|
for (unsigned int i=0; i < after_last_element_id; i++) {
|
||||||
button_info* btn = &m_buttons[i];
|
button_info *btn = &m_buttons[i];
|
||||||
|
|
||||||
std::vector<int>::iterator id =
|
std::vector<int>::iterator id =
|
||||||
std::find(btn->ids.begin(),btn->ids.end(), eventID);
|
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
||||||
|
|
||||||
if (id != btn->ids.end())
|
if (id != btn->ids.end())
|
||||||
return (touch_gui_button_id) i;
|
return (touch_gui_button_id) i;
|
||||||
@ -589,15 +635,15 @@ touch_gui_button_id TouchScreenGUI::getButtonID(int eventID)
|
|||||||
bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
||||||
{
|
{
|
||||||
// check if hud item is pressed
|
// check if hud item is pressed
|
||||||
for (std::map<int,rect<s32> >::iterator iter = m_hud_rects.begin();
|
for (std::map<int, rect<s32> >::iterator iter = m_hud_rects.begin();
|
||||||
iter != m_hud_rects.end(); ++iter) {
|
iter != m_hud_rects.end(); ++iter) {
|
||||||
if (iter->second.isPointInside(
|
if (iter->second.isPointInside(
|
||||||
v2s32(event.TouchInput.X,
|
v2s32(event.TouchInput.X,
|
||||||
event.TouchInput.Y)
|
event.TouchInput.Y)
|
||||||
)) {
|
)) {
|
||||||
if ( iter->first < 8) {
|
if ( iter->first < 8) {
|
||||||
SEvent* translated = new SEvent();
|
SEvent *translated = new SEvent();
|
||||||
memset(translated,0,sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
|
translated->KeyInput.Key = (irr::EKEY_CODE) (KEY_KEY_1 + iter->first);
|
||||||
translated->KeyInput.Control = false;
|
translated->KeyInput.Control = false;
|
||||||
@ -615,11 +661,11 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
|||||||
|
|
||||||
bool TouchScreenGUI::isReleaseHUDButton(int eventID)
|
bool TouchScreenGUI::isReleaseHUDButton(int eventID)
|
||||||
{
|
{
|
||||||
std::map<int,irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);
|
std::map<int, irr::EKEY_CODE>::iterator iter = m_hud_ids.find(eventID);
|
||||||
|
|
||||||
if (iter != m_hud_ids.end()) {
|
if (iter != m_hud_ids.end()) {
|
||||||
SEvent* translated = new SEvent();
|
SEvent *translated = new SEvent();
|
||||||
memset(translated,0,sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = iter->second;
|
translated->KeyInput.Key = iter->second;
|
||||||
translated->KeyInput.PressedDown = false;
|
translated->KeyInput.PressedDown = false;
|
||||||
@ -636,9 +682,9 @@ bool TouchScreenGUI::isReleaseHUDButton(int eventID)
|
|||||||
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
||||||
int eventID, bool action)
|
int eventID, bool action)
|
||||||
{
|
{
|
||||||
button_info* btn = &m_buttons[button];
|
button_info *btn = &m_buttons[button];
|
||||||
SEvent* translated = new SEvent();
|
SEvent *translated = new SEvent();
|
||||||
memset(translated,0,sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
translated->EventType = irr::EET_KEY_INPUT_EVENT;
|
||||||
translated->KeyInput.Key = btn->keycode;
|
translated->KeyInput.Key = btn->keycode;
|
||||||
translated->KeyInput.Control = false;
|
translated->KeyInput.Control = false;
|
||||||
@ -647,7 +693,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
|
|
||||||
// add this event
|
// add this event
|
||||||
if (action) {
|
if (action) {
|
||||||
assert(std::find(btn->ids.begin(),btn->ids.end(), eventID) == btn->ids.end());
|
assert(std::find(btn->ids.begin(), btn->ids.end(), eventID) == btn->ids.end());
|
||||||
|
|
||||||
btn->ids.push_back(eventID);
|
btn->ids.push_back(eventID);
|
||||||
|
|
||||||
@ -662,7 +708,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
if ((!action) || (btn->immediate_release)) {
|
if ((!action) || (btn->immediate_release)) {
|
||||||
|
|
||||||
std::vector<int>::iterator pos =
|
std::vector<int>::iterator pos =
|
||||||
std::find(btn->ids.begin(),btn->ids.end(), eventID);
|
std::find(btn->ids.begin(), btn->ids.end(), eventID);
|
||||||
// has to be in touch list
|
// has to be in touch list
|
||||||
assert(pos != btn->ids.end());
|
assert(pos != btn->ids.end());
|
||||||
btn->ids.erase(pos);
|
btn->ids.erase(pos);
|
||||||
@ -699,8 +745,8 @@ void TouchScreenGUI::handleReleaseEvent(int evt_id)
|
|||||||
|
|
||||||
// if this pointer issued a mouse event issue symmetric release here
|
// if this pointer issued a mouse event issue symmetric release here
|
||||||
if (m_move_sent_as_mouse_event) {
|
if (m_move_sent_as_mouse_event) {
|
||||||
SEvent* translated = new SEvent;
|
SEvent *translated = new SEvent;
|
||||||
memset(translated,0,sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_move_downlocation.X;
|
translated->MouseInput.X = m_move_downlocation.X;
|
||||||
translated->MouseInput.Y = m_move_downlocation.Y;
|
translated->MouseInput.Y = m_move_downlocation.Y;
|
||||||
@ -1000,12 +1046,12 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove old button
|
// remove old button
|
||||||
handleButtonEvent((touch_gui_button_id) i,*iter,false);
|
handleButtonEvent((touch_gui_button_id) i, *iter, false);
|
||||||
|
|
||||||
if (current_button_id == after_last_element_id) {
|
if (current_button_id == after_last_element_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handleButtonEvent((touch_gui_button_id) current_button_id,*iter,true);
|
handleButtonEvent((touch_gui_button_id) current_button_id, *iter, true);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1018,8 +1064,8 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
button_info* btn = &m_buttons[current_button_id];
|
button_info *btn = &m_buttons[current_button_id];
|
||||||
if (std::find(btn->ids.begin(),btn->ids.end(), event.TouchInput.ID)
|
if (std::find(btn->ids.begin(), btn->ids.end(), event.TouchInput.ID)
|
||||||
== btn->ids.end())
|
== btn->ids.end())
|
||||||
{
|
{
|
||||||
handleButtonEvent((touch_gui_button_id) current_button_id,
|
handleButtonEvent((touch_gui_button_id) current_button_id,
|
||||||
@ -1049,7 +1095,7 @@ bool TouchScreenGUI::doubleTapDetection()
|
|||||||
if (distance > (20 + m_touchscreen_threshold))
|
if (distance > (20 + m_touchscreen_threshold))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SEvent* translated = new SEvent();
|
SEvent *translated = new SEvent();
|
||||||
memset(translated, 0, sizeof(SEvent));
|
memset(translated, 0, sizeof(SEvent));
|
||||||
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
translated->EventType = EET_MOUSE_INPUT_EVENT;
|
||||||
translated->MouseInput.X = m_key_events[0].x;
|
translated->MouseInput.X = m_key_events[0].x;
|
||||||
@ -1096,7 +1142,7 @@ void TouchScreenGUI::applyJoystickStatus()
|
|||||||
TouchScreenGUI::~TouchScreenGUI()
|
TouchScreenGUI::~TouchScreenGUI()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info* btn = &m_buttons[i];
|
button_info *btn = &m_buttons[i];
|
||||||
if (btn->guibutton) {
|
if (btn->guibutton) {
|
||||||
btn->guibutton->drop();
|
btn->guibutton->drop();
|
||||||
btn->guibutton = NULL;
|
btn->guibutton = NULL;
|
||||||
@ -1123,7 +1169,7 @@ void TouchScreenGUI::step(float dtime)
|
|||||||
{
|
{
|
||||||
// simulate keyboard repeats
|
// simulate keyboard repeats
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info* btn = &m_buttons[i];
|
button_info *btn = &m_buttons[i];
|
||||||
|
|
||||||
if (btn->ids.size() > 0) {
|
if (btn->ids.size() > 0) {
|
||||||
btn->repeatcounter += dtime;
|
btn->repeatcounter += dtime;
|
||||||
@ -1197,7 +1243,7 @@ void TouchScreenGUI::Toggle(bool visible)
|
|||||||
{
|
{
|
||||||
m_visible = visible;
|
m_visible = visible;
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
button_info* btn = &m_buttons[i];
|
button_info *btn = &m_buttons[i];
|
||||||
if (btn->guibutton) {
|
if (btn->guibutton) {
|
||||||
btn->guibutton->setVisible(visible);
|
btn->guibutton->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ using namespace irr::gui;
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
jump_id = 0,
|
jump_id = 0,
|
||||||
crunch_id,
|
crunch_id,
|
||||||
|
zoom_id,
|
||||||
after_last_element_id,
|
after_last_element_id,
|
||||||
settings_starter_id,
|
settings_starter_id,
|
||||||
rare_controls_starter_id,
|
rare_controls_starter_id,
|
||||||
@ -45,6 +46,8 @@ typedef enum {
|
|||||||
debug_id,
|
debug_id,
|
||||||
camera_id,
|
camera_id,
|
||||||
range_id,
|
range_id,
|
||||||
|
minimap_id,
|
||||||
|
toggle_chat_id,
|
||||||
chat_id,
|
chat_id,
|
||||||
inventory_id,
|
inventory_id,
|
||||||
drop_id,
|
drop_id,
|
||||||
@ -70,7 +73,7 @@ typedef enum {
|
|||||||
#define MAX_TOUCH_COUNT 64
|
#define MAX_TOUCH_COUNT 64
|
||||||
#define BUTTON_REPEAT_DELAY 0.2f
|
#define BUTTON_REPEAT_DELAY 0.2f
|
||||||
|
|
||||||
#define SETTINGS_BAR_Y_OFFSET 6.5
|
#define SETTINGS_BAR_Y_OFFSET 5
|
||||||
#define RARE_CONTROLS_BAR_Y_OFFSET 4
|
#define RARE_CONTROLS_BAR_Y_OFFSET 4
|
||||||
|
|
||||||
extern const char **touchgui_button_imagenames;
|
extern const char **touchgui_button_imagenames;
|
||||||
@ -84,6 +87,10 @@ struct button_info
|
|||||||
std::vector<int> ids;
|
std::vector<int> ids;
|
||||||
IGUIButton *guibutton = nullptr;
|
IGUIButton *guibutton = nullptr;
|
||||||
bool immediate_release;
|
bool immediate_release;
|
||||||
|
|
||||||
|
// 0: false, 1: (true) first texture, 2: (true) second texture
|
||||||
|
int togglable = 0;
|
||||||
|
std::vector<const char *> textures;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AutoHideButtonBar
|
class AutoHideButtonBar
|
||||||
@ -101,6 +108,10 @@ public:
|
|||||||
void addButton(touch_gui_button_id id, const wchar_t *caption,
|
void addButton(touch_gui_button_id id, const wchar_t *caption,
|
||||||
const char *btn_image);
|
const char *btn_image);
|
||||||
|
|
||||||
|
// add toggle button to be shown
|
||||||
|
void addToggleButton(touch_gui_button_id id, const wchar_t *caption,
|
||||||
|
const char *btn_image_1, const char *btn_image_2);
|
||||||
|
|
||||||
// detect settings bar button events
|
// detect settings bar button events
|
||||||
bool isButton(const SEvent &event);
|
bool isButton(const SEvent &event);
|
||||||
|
|
||||||
|
BIN
textures/base/pack/chat_hide_btn.png
Executable file
BIN
textures/base/pack/chat_hide_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 289 B |
BIN
textures/base/pack/chat_show_btn.png
Executable file
BIN
textures/base/pack/chat_show_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 188 B |
BIN
textures/base/pack/jump_btn.png
Normal file → Executable file
BIN
textures/base/pack/jump_btn.png
Normal file → Executable file
Binary file not shown.
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 396 B |
BIN
textures/base/pack/minimap_btn.png
Executable file
BIN
textures/base/pack/minimap_btn.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 218 B |
BIN
textures/base/pack/zoom.png
Executable file
BIN
textures/base/pack/zoom.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue
Block a user