Touchscreengui. Some improvements
31
src/game.cpp
@ -3838,9 +3838,12 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
|
|||||||
|
|
||||||
ClientMap &map = client->getEnv().getClientMap();
|
ClientMap &map = client->getEnv().getClientMap();
|
||||||
|
|
||||||
|
bool digging = false;
|
||||||
if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
|
if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
|
||||||
&& client->checkPrivilege("interact")) {
|
&& client->checkPrivilege("interact")) {
|
||||||
handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
|
handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
|
||||||
|
digging = true;
|
||||||
|
runData.noplace_delay_timer = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should be done after digging handling
|
// This should be done after digging handling
|
||||||
@ -3857,22 +3860,10 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool digging = false;
|
if ((getRightClicked() ||
|
||||||
|
|
||||||
if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
|
|
||||||
&& client->checkPrivilege("interact")) {
|
|
||||||
handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
|
|
||||||
digging = true;
|
|
||||||
runData.noplace_delay_timer = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool place = (input->getRightClicked() || input->getLeftReleased() ||
|
|
||||||
runData.repeat_rightclick_timer >= m_repeat_right_click_time) &&
|
runData.repeat_rightclick_timer >= m_repeat_right_click_time) &&
|
||||||
client->checkPrivilege("interact");
|
!digging && runData.noplace_delay_timer <= 0.0 &&
|
||||||
place &= !digging;
|
client->checkPrivilege("interact")) {
|
||||||
place &= runData.noplace_delay_timer <= 0.0;
|
|
||||||
|
|
||||||
if (place) {
|
|
||||||
runData.repeat_rightclick_timer = 0;
|
runData.repeat_rightclick_timer = 0;
|
||||||
infostream << "Ground right-clicked" << std::endl;
|
infostream << "Ground right-clicked" << std::endl;
|
||||||
|
|
||||||
@ -3952,7 +3943,11 @@ void Game::handlePointingAtObject(const PointedThing &pointed, const ItemStack &
|
|||||||
playeritem.getDefinition(itemdef_manager);
|
playeritem.getDefinition(itemdef_manager);
|
||||||
bool nohit_enabled = ((ItemGroupList) playeritem_def.groups)["nohit"] != 0;
|
bool nohit_enabled = ((ItemGroupList) playeritem_def.groups)["nohit"] != 0;
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
|
if (input->getRightClicked() && !nohit_enabled) {
|
||||||
|
#else
|
||||||
if (input->getLeftState() && !nohit_enabled) {
|
if (input->getLeftState() && !nohit_enabled) {
|
||||||
|
#endif
|
||||||
bool do_punch = false;
|
bool do_punch = false;
|
||||||
bool do_punch_damage = false;
|
bool do_punch_damage = false;
|
||||||
|
|
||||||
@ -3989,7 +3984,11 @@ void Game::handlePointingAtObject(const PointedThing &pointed, const ItemStack &
|
|||||||
if (!disable_send)
|
if (!disable_send)
|
||||||
client->interact(0, pointed);
|
client->interact(0, pointed);
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
|
} else if (input->getLeftClicked() || (input->getRightClicked() && nohit_enabled)) {
|
||||||
|
#else
|
||||||
} else if (input->getRightClicked() || (input->getLeftClicked() && nohit_enabled)) {
|
} else if (input->getRightClicked() || (input->getLeftClicked() && nohit_enabled)) {
|
||||||
|
#endif
|
||||||
infostream << "Right-clicked object" << std::endl;
|
infostream << "Right-clicked object" << std::endl;
|
||||||
client->interact(3, pointed); // place
|
client->interact(3, pointed); // place
|
||||||
}
|
}
|
||||||
@ -4141,7 +4140,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
if (draw_control->range_all) {
|
if (draw_control->range_all) {
|
||||||
runData.fog_range = 100000 * BS;
|
runData.fog_range = 100000 * BS;
|
||||||
#if defined(__ANDROID__) || defined(__IOS__)
|
#if defined(__ANDROID__) || defined(__IOS__)
|
||||||
runData.fog_range = 4 * draw_control->wanted_range * BS;
|
runData.fog_range = draw_control->wanted_range * BS * 4;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
runData.fog_range = draw_control->wanted_range * BS;
|
runData.fog_range = draw_control->wanted_range * BS;
|
||||||
|
@ -2616,7 +2616,10 @@ void GUIFormSpecMenu::drawMenu()
|
|||||||
NULL, m_client, IT_ROT_HOVERED);
|
NULL, m_client, IT_ROT_HOVERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO find way to show tooltips on touchscreen */
|
||||||
|
#ifndef HAVE_TOUCHSCREENGUI
|
||||||
m_pointer = m_device->getCursorControl()->getPosition();
|
m_pointer = m_device->getCursorControl()->getPosition();
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Draw static text elements
|
Draw static text elements
|
||||||
@ -3182,16 +3185,10 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|||||||
}
|
}
|
||||||
dont_send_event = true;
|
dont_send_event = true;
|
||||||
}
|
}
|
||||||
// ignore unhandled 2 touch events ... accidental moving for example
|
// ignore unhandled 2 touch events, accidental moving for example
|
||||||
else if (event.TouchInput.touchedCount == 2) {
|
else if (event.TouchInput.touchedCount >= 2) {
|
||||||
dont_send_event = true;
|
dont_send_event = true;
|
||||||
}
|
}
|
||||||
else if (event.TouchInput.touchedCount > 2) {
|
|
||||||
errorstream << "GUIModalMenu::preprocessEvent"
|
|
||||||
<< " to many multitouch events "
|
|
||||||
<< event.TouchInput.touchedCount << " ignoring them"
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dont_send_event) {
|
if (dont_send_event) {
|
||||||
return true;
|
return true;
|
||||||
@ -3207,7 +3204,7 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
|
|||||||
|
|
||||||
if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
||||||
// reset pointer
|
// reset pointer
|
||||||
//m_pointer = v2s32(0, 0);
|
m_pointer = v2s32(0, 0);
|
||||||
}
|
}
|
||||||
drop();
|
drop();
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -33,43 +33,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
|
|
||||||
#include <ISceneCollisionManager.h>
|
#include <ISceneCollisionManager.h>
|
||||||
|
|
||||||
// Very slow button repeat frequency (in seconds)
|
|
||||||
#define SLOW_BUTTON_REPEAT (1.0f)
|
|
||||||
|
|
||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
|
|
||||||
extern Settings *g_settings;
|
const char **touchgui_button_imagenames = (const char *[]) {
|
||||||
|
"up_one_btn.png",
|
||||||
const char** touchgui_button_imagenames = (const char*[]) {
|
"up_two_btn.png",
|
||||||
"up_one.png",
|
"up_three_btn.png",
|
||||||
"up_two.png",
|
"down_one_btn.png",
|
||||||
"up_three.png",
|
"down_two_btn.png",
|
||||||
"down_one.png",
|
"down_three_btn.png",
|
||||||
"down_two.png",
|
"left_btn.png",
|
||||||
"down_three.png",
|
"right_btn.png",
|
||||||
"left.png",
|
"inventory_btn.png",
|
||||||
"right.png",
|
"drop_btn.png",
|
||||||
"inventory.png",
|
"jump_btn.png",
|
||||||
"drop.png",
|
"down_btn.png",
|
||||||
"jump.png",
|
// "noclip_btn.png",
|
||||||
"down.png",
|
"escape_btn.png",
|
||||||
/*#ifdef ENABLE_ANDROID_NOCLIP
|
|
||||||
"fly_btn.png",
|
|
||||||
"noclip_btn.png",
|
|
||||||
#endif*/
|
|
||||||
"minimap_btn.png",
|
"minimap_btn.png",
|
||||||
|
"rangeview_btn.png",
|
||||||
|
"chat_btn.png",
|
||||||
// "debug_btn.png",
|
// "debug_btn.png",
|
||||||
"chat.png",
|
// "camera_btn.png",
|
||||||
// "camera.png",
|
"empty_btn.png"
|
||||||
"rangeview.png",
|
|
||||||
"rangeview_ios.png",
|
|
||||||
"empty.png",
|
|
||||||
"escape.png",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
static irr::EKEY_CODE id2keycode(touch_gui_button_id id) {
|
||||||
{
|
std::string key = key;
|
||||||
std::string key = "";
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case forward_one:
|
case forward_one:
|
||||||
key = "forward";
|
key = "forward";
|
||||||
@ -107,54 +97,49 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
|
|||||||
case crunch_id:
|
case crunch_id:
|
||||||
key = "sneak";
|
key = "sneak";
|
||||||
break;
|
break;
|
||||||
/*#ifdef ENABLE_ANDROID_NOCLIP
|
/* case noclip_id:
|
||||||
case fly_id:
|
|
||||||
key = "freemove";
|
|
||||||
break;
|
|
||||||
case noclip_id:
|
|
||||||
key = "noclip";
|
key = "noclip";
|
||||||
break;
|
break;
|
||||||
case fast_id:
|
case fast_id:
|
||||||
key = "fast";
|
key = "fast";
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case debug_id:
|
case debug_id:
|
||||||
key = "toggle_debug";
|
key = "toggle_debug";
|
||||||
break;*/
|
break;*/
|
||||||
|
case escape_id:
|
||||||
|
return irr::KEY_ESCAPE;
|
||||||
case minimap_id:
|
case minimap_id:
|
||||||
key = "minimap";
|
key = "minimap";
|
||||||
break;
|
break;
|
||||||
|
case range_id:
|
||||||
|
key = "rangeselect";
|
||||||
|
break;
|
||||||
case chat_id:
|
case chat_id:
|
||||||
key = "chat";
|
key = "chat";
|
||||||
break;
|
break;
|
||||||
/* case camera_id:
|
/* case camera_id:
|
||||||
key = "camera_mode";
|
key = "camera_mode";
|
||||||
break;*/
|
break;*/
|
||||||
case range_id:
|
|
||||||
key = "rangeselect";
|
|
||||||
break;
|
|
||||||
case range_ios_id:
|
|
||||||
key = "rangeselect";
|
|
||||||
break;
|
|
||||||
case empty_id:
|
case empty_id:
|
||||||
key = "forward";
|
key = "forward";
|
||||||
break;
|
break;
|
||||||
case escape_id:
|
case after_last_element_id:
|
||||||
return irr::KEY_ESCAPE;
|
break;
|
||||||
}
|
}
|
||||||
assert(key != "");
|
assert(!key.empty());
|
||||||
return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
|
return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
const 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,
|
||||||
tsrc->getTexture(path, &tid), button_rect.getWidth(),
|
tsrc->getTexture(path, &tid),
|
||||||
button_rect.getHeight());
|
button_rect.getWidth(),
|
||||||
|
button_rect.getHeight());
|
||||||
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")) {
|
||||||
@ -169,10 +154,10 @@ static void load_button_texture(button_info* btn, const char* path,
|
|||||||
}
|
}
|
||||||
btn->guibutton->setDrawBorder(false);
|
btn->guibutton->setDrawBorder(false);
|
||||||
btn->guibutton->setText(L"");
|
btn->guibutton->setText(L"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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_camera_yaw_change(0.0),
|
m_camera_yaw_change(0.0),
|
||||||
@ -183,24 +168,22 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver)
|
|||||||
m_move_has_really_moved(false),
|
m_move_has_really_moved(false),
|
||||||
m_move_downtime(0),
|
m_move_downtime(0),
|
||||||
m_move_sent_as_mouse_event(false),
|
m_move_sent_as_mouse_event(false),
|
||||||
// use some downlocation way off screen as init value to avoid invalid behaviour
|
// use some downlocation way off screen as init value to avoid invalid behaviour
|
||||||
m_move_downlocation(v2s32(-10000, -10000))
|
m_move_downlocation(v2s32(-10000, -10000)) {
|
||||||
{
|
for (auto &m_button : m_buttons) {
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
m_button.guibutton = nullptr;
|
||||||
m_buttons[i].guibutton = 0;
|
m_button.repeatcounter = -1;
|
||||||
m_buttons[i].repeatcounter = -1;
|
m_button.repeatdelay = BUTTON_REPEAT_DELAY;
|
||||||
m_buttons[i].repeatdelay = BUTTON_REPEAT_DELAY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
m_screensize = m_device->getVideoDriver()->getScreenSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
|
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, nullptr, id, caption.c_str());
|
||||||
btn->guibutton->grab();
|
btn->guibutton->grab();
|
||||||
btn->repeatcounter = -1;
|
btn->repeatcounter = -1;
|
||||||
btn->repeatdelay = repeat_delay;
|
btn->repeatdelay = repeat_delay;
|
||||||
@ -208,35 +191,22 @@ 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getMaxControlPadSize(float density) {
|
void TouchScreenGUI::init(ISimpleTextureSource *tsrc) {
|
||||||
return 260 * density * g_settings->getFloat("hud_scaling");
|
assert(tsrc != nullptr);
|
||||||
}
|
|
||||||
|
|
||||||
int TouchScreenGUI::getGuiButtonSize()
|
float control_pad_size =
|
||||||
{
|
MYMIN(m_screensize.Y / 1.5,
|
||||||
u32 control_pad_size = MYMIN((2 * m_screensize.Y) / 3,
|
porting::getDisplayDensity() * g_settings->getFloat("hud_scaling") * 260);
|
||||||
getMaxControlPadSize(porting::getDisplayDensity()));
|
|
||||||
|
|
||||||
return control_pad_size / 3;
|
u32 button_size = control_pad_size / 3;
|
||||||
}
|
|
||||||
|
|
||||||
void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|
||||||
{
|
|
||||||
assert(tsrc != 0);
|
|
||||||
|
|
||||||
u32 control_pad_size =
|
|
||||||
MYMIN((2 * m_screensize.Y) / 3,
|
|
||||||
getMaxControlPadSize(porting::getDisplayDensity()));
|
|
||||||
|
|
||||||
u32 button_size = getGuiButtonSize();
|
|
||||||
m_visible = true;
|
m_visible = true;
|
||||||
m_texturesource = tsrc;
|
m_texturesource = tsrc;
|
||||||
m_control_pad_rect = rect<s32>(0, m_screensize.Y - control_pad_size,
|
m_control_pad_rect = rect<s32>(0, m_screensize.Y - control_pad_size,
|
||||||
control_pad_size, m_screensize.Y);
|
control_pad_size, m_screensize.Y);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
draw control pad
|
draw control pad
|
||||||
@ -256,149 +226,126 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|||||||
touch_gui_button_id id = after_last_element_id;
|
touch_gui_button_id id = after_last_element_id;
|
||||||
std::wstring caption;
|
std::wstring caption;
|
||||||
switch (number) {
|
switch (number) {
|
||||||
case 0:
|
case 0:
|
||||||
id = forward_one;
|
id = forward_one;
|
||||||
caption = L"^";
|
caption = L"^";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
id = forward_two;
|
id = forward_two;
|
||||||
caption = L"^";
|
caption = L"^";
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
id = forward_three;
|
id = forward_three;
|
||||||
caption = L"^";
|
caption = L"^";
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
id = left_id;
|
id = left_id;
|
||||||
caption = L"<";
|
caption = L"<";
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
id = empty_id;
|
id = empty_id;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
id = backward_one;
|
id = backward_one;
|
||||||
caption = L"v";
|
caption = L"v";
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
id = backward_two;
|
id = backward_two;
|
||||||
caption = L"v";
|
caption = L"v";
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
id = backward_three;
|
id = backward_three;
|
||||||
caption = L"v";
|
caption = L"v";
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
id = right_id;
|
id = right_id;
|
||||||
caption = L">";
|
caption = L">";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (id != after_last_element_id) {
|
if (id != after_last_element_id) {
|
||||||
initButton(id, button_rect, caption, false);
|
initButton(id, button_rect, caption, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// init inventory button
|
// init inventory button
|
||||||
initButton(inventory_id,
|
initButton(inventory_id,
|
||||||
rect<s32>(m_screensize.X - (button_size),
|
rect<s32>(m_screensize.X - (button_size),
|
||||||
m_screensize.Y - (button_size),
|
m_screensize.Y - (button_size),
|
||||||
m_screensize.X,
|
m_screensize.X,
|
||||||
m_screensize.Y),
|
m_screensize.Y),
|
||||||
L"inv", false, SLOW_BUTTON_REPEAT);
|
L"inv", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
// init drop button
|
// init drop button
|
||||||
initButton(drop_id,
|
initButton(drop_id,
|
||||||
rect<s32>(m_screensize.X - (button_size * 0.75),
|
rect<s32>(m_screensize.X - (button_size * 0.75),
|
||||||
m_screensize.Y / 2 - (button_size * 1.5),
|
m_screensize.Y / 2 - (button_size * 1.5),
|
||||||
m_screensize.X,
|
m_screensize.X,
|
||||||
m_screensize.Y /2 - (0.75 * button_size)),
|
m_screensize.Y / 2 - (0.75 * button_size)),
|
||||||
L"drop", false, SLOW_BUTTON_REPEAT);
|
L"drop", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
// init crunch button
|
// init crunch button
|
||||||
initButton(crunch_id,
|
initButton(crunch_id,
|
||||||
rect<s32>(m_screensize.X - (button_size * 2),
|
rect<s32>(m_screensize.X - (button_size * 2),
|
||||||
m_screensize.Y - (button_size * 0.5),
|
m_screensize.Y - (button_size * 0.5),
|
||||||
m_screensize.X - (button_size),
|
m_screensize.X - (button_size),
|
||||||
m_screensize.Y),
|
m_screensize.Y),
|
||||||
L"H", false, SLOW_BUTTON_REPEAT);
|
L"H", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
// init jump button
|
// init jump button
|
||||||
initButton(jump_id,
|
initButton(jump_id,
|
||||||
rect<s32>(m_screensize.X - (button_size * 2),
|
rect<s32>(m_screensize.X - (button_size * 2),
|
||||||
m_screensize.Y - (button_size * 2),
|
m_screensize.Y - (button_size * 2),
|
||||||
m_screensize.X - (button_size),
|
m_screensize.X - (button_size),
|
||||||
m_screensize.Y - (button_size)),
|
m_screensize.Y - (button_size)),
|
||||||
L"x", false, SLOW_BUTTON_REPEAT);
|
L"x", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
/*#ifdef ENABLE_ANDROID_NOCLIP
|
/*
|
||||||
// init fly button
|
|
||||||
initButton(fly_id,
|
|
||||||
rect<s32>(m_screensize.X - (button_size * 0.75),
|
|
||||||
m_screensize.Y - (button_size * 3.25),
|
|
||||||
m_screensize.X,
|
|
||||||
m_screensize.Y - (button_size * 2.5)),
|
|
||||||
L"fly", false, SLOW_BUTTON_REPEAT);
|
|
||||||
|
|
||||||
// init noclip button
|
// init noclip button
|
||||||
initButton(noclip_id,
|
initButton(noclip_id,
|
||||||
rect<s32>(m_screensize.X - (button_size * 0.75),
|
rect<s32>(m_screensize.X - (button_size * 0.75),
|
||||||
m_screensize.Y - (button_size * 4.75),
|
m_screensize.Y - (button_size * 4.75),
|
||||||
m_screensize.X,
|
m_screensize.X,
|
||||||
m_screensize.Y - (button_size * 4)),
|
m_screensize.Y - (button_size * 4)),
|
||||||
L"clip", false, SLOW_BUTTON_REPEAT);
|
L"clip", false, SLOW_BUTTON_REPEAT);
|
||||||
// init fast button
|
// init fast button
|
||||||
initButton(fast_id,
|
initButton(fast_id,
|
||||||
rect<s32>(m_screensize.X - (button_size * 0.75),
|
rect<s32>(m_screensize.X - (button_size * 0.75),
|
||||||
m_screensize.Y - (button_size * 4),
|
m_screensize.Y - (button_size * 4),
|
||||||
m_screensize.X,
|
m_screensize.X,
|
||||||
m_screensize.Y - (button_size * 3.25)),
|
m_screensize.Y - (button_size * 3.25)),
|
||||||
L"fast", false, SLOW_BUTTON_REPEAT);
|
L"fast", false, SLOW_BUTTON_REPEAT);
|
||||||
#endif*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// iOS does not have a physical pause button and have memory leak with minimap
|
||||||
#ifdef __IOS__
|
#ifdef __IOS__
|
||||||
// iOS bar
|
|
||||||
// init pause button
|
// init pause button
|
||||||
initButton(escape_id,
|
initButton(escape_id,
|
||||||
rect<s32>(m_screensize.X / 2 - (button_size * 0.75), 0,
|
rect<s32>(m_screensize.X / 2 - (button_size * 1.125), 0,
|
||||||
m_screensize.X / 2, (button_size * 0.75)),
|
m_screensize.X / 2 - (button_size * 0.375),
|
||||||
|
(button_size * 0.75)),
|
||||||
L"Exit", false, SLOW_BUTTON_REPEAT);
|
L"Exit", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
// init rangeselect button
|
|
||||||
initButton(range_ios_id,
|
|
||||||
rect<s32>(m_screensize.X / 2, 0,
|
|
||||||
m_screensize.X / 2 + (button_size * 0.75),
|
|
||||||
(button_size * 0.75)),
|
|
||||||
L"far", false, SLOW_BUTTON_REPEAT);
|
|
||||||
// init chat button
|
|
||||||
initButton(chat_id,
|
|
||||||
rect<s32>(m_screensize.X / 2 + (button_size * 0.75), 0,
|
|
||||||
m_screensize.X / 2 + (button_size * 1.5),
|
|
||||||
(button_size * 0.75)),
|
|
||||||
L"Chat", false, SLOW_BUTTON_REPEAT);
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// Android and Windows bar
|
|
||||||
// init rangeselect button
|
|
||||||
initButton(range_id,
|
|
||||||
rect<s32>(m_screensize.X / 2 - (button_size * 1.125), 0,
|
|
||||||
m_screensize.X / 2 - (button_size * 0.375),
|
|
||||||
(button_size * 0.75)),
|
|
||||||
L"far", false, SLOW_BUTTON_REPEAT);
|
|
||||||
|
|
||||||
// init minimap button
|
// init minimap button
|
||||||
initButton(minimap_id,
|
initButton(minimap_id,
|
||||||
rect<s32>(m_screensize.X / 2 - (button_size * 0.375), 0,
|
rect<s32>(m_screensize.X / 2 - (button_size * 1.125), 0,
|
||||||
m_screensize.X / 2 + (button_size * 0.375),
|
m_screensize.X / 2 - (button_size * 0.375),
|
||||||
(button_size * 0.75)),
|
(button_size * 0.75)),
|
||||||
L"minimap", false, SLOW_BUTTON_REPEAT);
|
L"minimap", false, SLOW_BUTTON_REPEAT);
|
||||||
|
#endif
|
||||||
|
// init rangeselect button
|
||||||
|
initButton(range_id,
|
||||||
|
rect<s32>(m_screensize.X / 2 - (button_size * 0.375), 0,
|
||||||
|
m_screensize.X / 2 + (button_size * 0.375),
|
||||||
|
(button_size * 0.75)),
|
||||||
|
L"far", false, SLOW_BUTTON_REPEAT);
|
||||||
|
|
||||||
// init chat button
|
// init chat button
|
||||||
initButton(chat_id,
|
initButton(chat_id,
|
||||||
rect<s32>(m_screensize.X / 2 + (button_size * 0.375), 0,
|
rect<s32>(m_screensize.X / 2 + (button_size * 0.375), 0,
|
||||||
m_screensize.X / 2 + (button_size * 1.125),
|
m_screensize.X / 2 + (button_size * 1.125),
|
||||||
(button_size * 0.75)),
|
(button_size * 0.75)),
|
||||||
L"Chat", false, SLOW_BUTTON_REPEAT);
|
L"Chat", false, SLOW_BUTTON_REPEAT);
|
||||||
#endif
|
|
||||||
|
|
||||||
// init camera button
|
// init camera button
|
||||||
/* initButton(camera_id,
|
/* initButton(camera_id,
|
||||||
@ -407,13 +354,12 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc)
|
|||||||
L"cam", false, SLOW_BUTTON_REPEAT);*/
|
L"cam", false, SLOW_BUTTON_REPEAT);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
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 != nullptr) {
|
||||||
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++) {
|
||||||
@ -426,13 +372,12 @@ touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
|
|||||||
return after_last_element_id;
|
return after_last_element_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID)
|
touch_gui_button_id TouchScreenGUI::getButtonID(size_t 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<size_t>::iterator id =
|
auto 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;
|
||||||
@ -441,20 +386,18 @@ touch_gui_button_id TouchScreenGUI::getButtonID(size_t eventID)
|
|||||||
return after_last_element_id;
|
return after_last_element_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (auto &m_hud_rect : m_hud_rects) {
|
||||||
iter != m_hud_rects.end(); ++iter) {
|
if (m_hud_rect.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 (m_hud_rect.first < 9) {
|
||||||
SEvent* translated = new SEvent();
|
auto *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 + m_hud_rect.first);
|
||||||
translated->KeyInput.Control = false;
|
translated->KeyInput.Control = false;
|
||||||
translated->KeyInput.Shift = false;
|
translated->KeyInput.Shift = false;
|
||||||
translated->KeyInput.PressedDown = true;
|
translated->KeyInput.PressedDown = true;
|
||||||
@ -468,12 +411,11 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchScreenGUI::isReleaseHUDButton(size_t eventID)
|
bool TouchScreenGUI::isReleaseHUDButton(size_t eventID) {
|
||||||
{
|
auto iter = m_hud_ids.find(eventID);
|
||||||
std::map<size_t,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();
|
auto *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;
|
||||||
@ -489,10 +431,9 @@ bool TouchScreenGUI::isReleaseHUDButton(size_t eventID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
||||||
size_t eventID, bool action)
|
size_t eventID, bool action) {
|
||||||
{
|
button_info *btn = &m_buttons[button];
|
||||||
button_info* btn = &m_buttons[button];
|
auto *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;
|
||||||
@ -500,29 +441,30 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
translated->KeyInput.Shift = false;
|
translated->KeyInput.Shift = false;
|
||||||
translated->KeyInput.Char = 0;
|
translated->KeyInput.Char = 0;
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
if (btn->ids.size() > 1) return;
|
if (btn->ids.size() > 1)
|
||||||
|
return;
|
||||||
|
|
||||||
btn->repeatcounter = 0;
|
btn->repeatcounter = 0;
|
||||||
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);
|
||||||
}
|
}
|
||||||
/* remove event */
|
// remove event
|
||||||
if ((!action) || (btn->immediate_release)) {
|
if ((!action) || (btn->immediate_release)) {
|
||||||
|
|
||||||
std::vector<size_t>::iterator pos =
|
auto 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);
|
||||||
|
|
||||||
if (btn->ids.size() > 0) { return; }
|
if (!btn->ids.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
translated->KeyInput.PressedDown = false;
|
translated->KeyInput.PressedDown = false;
|
||||||
btn->repeatcounter = -1;
|
btn->repeatcounter = -1;
|
||||||
@ -532,25 +474,24 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/* handle button events */
|
// handle button events
|
||||||
if (button != after_last_element_id) {
|
if (button != after_last_element_id) {
|
||||||
handleButtonEvent(button, evt_id, false);
|
handleButtonEvent(button, evt_id, false);
|
||||||
}
|
}
|
||||||
/* handle hud button events */
|
// handle hud button events
|
||||||
else if (isReleaseHUDButton(evt_id)) {
|
else if (isReleaseHUDButton(evt_id)) {
|
||||||
/* nothing to do here */
|
// nothing to do here
|
||||||
}
|
}
|
||||||
/* handle the point used for moving view */
|
// handle the point used for moving view
|
||||||
else if (evt_id == m_move_id) {
|
else if (evt_id == m_move_id) {
|
||||||
m_move_id = -1;
|
m_move_id = -1;
|
||||||
|
|
||||||
/* 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;
|
auto *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;
|
||||||
@ -561,10 +502,8 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id)
|
|||||||
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
||||||
m_receiver->OnEvent(*translated);
|
m_receiver->OnEvent(*translated);
|
||||||
delete translated;
|
delete translated;
|
||||||
} else if (m_control_pad_rect.isPointInside(v2s32(m_move_downlocation.X, m_move_downlocation.Y))) {
|
} else if (!m_move_has_really_moved) {
|
||||||
// ignore events inside the control pad not already handled
|
auto *translated = new SEvent;
|
||||||
} else if (!m_move_has_really_moved) {
|
|
||||||
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;
|
||||||
@ -575,21 +514,20 @@ void TouchScreenGUI::handleReleaseEvent(size_t evt_id)
|
|||||||
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
translated->MouseInput.Event = EMIE_LMOUSE_LEFT_UP;
|
||||||
m_receiver->OnEvent(*translated);
|
m_receiver->OnEvent(*translated);
|
||||||
delete translated;
|
delete translated;
|
||||||
doubleTapDetection();
|
quickTapDetection();
|
||||||
m_shootline = m_device
|
m_shootline = m_device
|
||||||
->getSceneManager()
|
->getSceneManager()
|
||||||
->getSceneCollisionManager()
|
->getSceneCollisionManager()
|
||||||
->getRayFromScreenCoordinates(
|
->getRayFromScreenCoordinates(
|
||||||
v2s32(m_move_downlocation.X,m_move_downlocation.Y));
|
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
infostream
|
infostream
|
||||||
<< "TouchScreenGUI::translateEvent released unknown button: "
|
<< "TouchScreenGUI::translateEvent released unknown button: "
|
||||||
<< evt_id << std::endl;
|
<< evt_id << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::vector<id_status>::iterator iter = m_known_ids.begin();
|
for (auto iter = m_known_ids.begin();
|
||||||
iter != m_known_ids.end(); ++iter) {
|
iter != m_known_ids.end(); ++iter) {
|
||||||
if (iter->id == evt_id) {
|
if (iter->id == evt_id) {
|
||||||
m_known_ids.erase(iter);
|
m_known_ids.erase(iter);
|
||||||
@ -609,24 +547,21 @@ void TouchScreenGUI::handleReleaseAll()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void TouchScreenGUI::translateEvent(const SEvent &event)
|
void TouchScreenGUI::translateEvent(const SEvent &event) {
|
||||||
{
|
|
||||||
if (!m_visible) {
|
if (!m_visible) {
|
||||||
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
infostream << "TouchScreenGUI::translateEvent got event but not visible?!" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.EventType != EET_TOUCH_INPUT_EVENT) {
|
if (event.EventType != EET_TOUCH_INPUT_EVENT)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
if (event.TouchInput.Event == ETIE_PRESSED_DOWN) {
|
||||||
|
|
||||||
/* add to own copy of eventlist ...
|
/* add to own copy of eventlist ...
|
||||||
* android would provide this information but irrlicht guys don't
|
* android would provide this information but irrlicht guys don't
|
||||||
* wanna design a efficient interface
|
* wanna design a efficient interface */
|
||||||
*/
|
id_status toadd{};
|
||||||
id_status toadd;
|
|
||||||
toadd.id = event.TouchInput.ID;
|
toadd.id = event.TouchInput.ID;
|
||||||
toadd.X = event.TouchInput.X;
|
toadd.X = event.TouchInput.X;
|
||||||
toadd.Y = event.TouchInput.Y;
|
toadd.Y = event.TouchInput.Y;
|
||||||
@ -637,17 +572,14 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
touch_gui_button_id button =
|
touch_gui_button_id button =
|
||||||
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
||||||
|
|
||||||
/* handle button events */
|
// handle button events
|
||||||
if (button != after_last_element_id) {
|
if (button != after_last_element_id) {
|
||||||
handleButtonEvent(button, eventID, true);
|
handleButtonEvent(button, eventID, true);
|
||||||
} else if (isHUDButton(event)) {
|
} else if (m_control_pad_rect.isPointInside(v2s32(toadd.X, toadd.Y)) || (isHUDButton(event))) {
|
||||||
/* already handled in isHUDButton() */
|
|
||||||
} else if (m_control_pad_rect.isPointInside(v2s32(toadd.X, toadd.Y))) {
|
|
||||||
// ignore events inside the control pad not already handled
|
// ignore events inside the control pad not already handled
|
||||||
}
|
} else {
|
||||||
/* handle non button events */
|
// handle non button events
|
||||||
else {
|
// if we don't already have a moving point make this the moving one
|
||||||
/* if we don't already have a moving point make this the moving one */
|
|
||||||
if (m_move_id == -1) {
|
if (m_move_id == -1) {
|
||||||
m_move_id = event.TouchInput.ID;
|
m_move_id = event.TouchInput.ID;
|
||||||
m_move_has_really_moved = false;
|
m_move_has_really_moved = false;
|
||||||
@ -662,7 +594,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
->getRayFromScreenCoordinates(m_move_downlocation);
|
->getRayFromScreenCoordinates(m_move_downlocation);
|
||||||
|
|
||||||
// send a middle click event so the game can handle single touches
|
// send a middle click event so the game can handle single touches
|
||||||
SEvent *translated = new SEvent;
|
auto *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;
|
||||||
@ -675,17 +607,15 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
||||||
}
|
} else if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
||||||
else if (event.TouchInput.Event == ETIE_LEFT_UP) {
|
|
||||||
verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
|
verbosestream << "Up event for pointerid: " << event.TouchInput.ID << std::endl;
|
||||||
handleReleaseEvent(event.TouchInput.ID);
|
handleReleaseEvent(event.TouchInput.ID);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
assert(event.TouchInput.Event == ETIE_MOVED);
|
assert(event.TouchInput.Event == ETIE_MOVED);
|
||||||
size_t move_idx = event.TouchInput.ID;
|
size_t move_idx = event.TouchInput.ID;
|
||||||
|
|
||||||
if (m_pointerpos[event.TouchInput.ID] ==
|
if (m_pointerpos[event.TouchInput.ID] ==
|
||||||
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,16 +630,16 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
||||||
|
|
||||||
if ((distance > g_settings->getU16("touchscreen_threshold")) ||
|
if ((distance > g_settings->getU16("touchscreen_threshold")) ||
|
||||||
(m_move_has_really_moved)) {
|
(m_move_has_really_moved)) {
|
||||||
m_move_has_really_moved = true;
|
m_move_has_really_moved = true;
|
||||||
s32 X = event.TouchInput.X;
|
s32 X = event.TouchInput.X;
|
||||||
s32 Y = event.TouchInput.Y;
|
s32 Y = event.TouchInput.Y;
|
||||||
|
|
||||||
// update camera_yaw and camera_pitch
|
// update camera_yaw and camera_pitch
|
||||||
s32 dx = X - m_pointerpos[event.TouchInput.ID].X;
|
auto dx = X - m_pointerpos[event.TouchInput.ID].X;
|
||||||
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
auto dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
||||||
|
|
||||||
/* adapt to similar behaviour as pc screen */
|
// adapt to similar behaviour as pc screen
|
||||||
double d = g_settings->getFloat("mouse_sensitivity");
|
double d = g_settings->getFloat("mouse_sensitivity");
|
||||||
double old_yaw = m_camera_yaw_change;
|
double old_yaw = m_camera_yaw_change;
|
||||||
double old_pitch = m_camera_pitch;
|
double old_pitch = m_camera_pitch;
|
||||||
@ -724,14 +654,13 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
->getRayFromScreenCoordinates(v2s32(X, Y));
|
->getRayFromScreenCoordinates(v2s32(X, Y));
|
||||||
m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
|
m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
|
||||||
}
|
}
|
||||||
}
|
} else if ((event.TouchInput.ID == m_move_id) &&
|
||||||
else if ((event.TouchInput.ID == m_move_id) &&
|
|
||||||
(m_move_sent_as_mouse_event)) {
|
(m_move_sent_as_mouse_event)) {
|
||||||
m_shootline = m_device
|
m_shootline = m_device
|
||||||
->getSceneManager()
|
->getSceneManager()
|
||||||
->getSceneCollisionManager()
|
->getSceneCollisionManager()
|
||||||
->getRayFromScreenCoordinates(
|
->getRayFromScreenCoordinates(
|
||||||
v2s32(event.TouchInput.X,event.TouchInput.Y));
|
v2s32(event.TouchInput.X, event.TouchInput.Y));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
handleChangedButton(event);
|
handleChangedButton(event);
|
||||||
@ -739,32 +668,30 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
void TouchScreenGUI::handleChangedButton(const SEvent &event) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
||||||
|
|
||||||
if (m_buttons[i].ids.empty()) {
|
if (m_buttons[i].ids.empty())
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
for (std::vector<size_t>::iterator iter = m_buttons[i].ids.begin();
|
for (auto iter = m_buttons[i].ids.begin();
|
||||||
iter != m_buttons[i].ids.end(); ++iter) {
|
iter != m_buttons[i].ids.end(); ++iter) {
|
||||||
|
|
||||||
if (event.TouchInput.ID == *iter) {
|
if (event.TouchInput.ID == *iter) {
|
||||||
|
|
||||||
int current_button_id =
|
int current_button_id =
|
||||||
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
||||||
|
|
||||||
if (current_button_id == i) {
|
if (current_button_id == i)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -773,42 +700,44 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
|||||||
|
|
||||||
int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
int current_button_id = getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
||||||
|
|
||||||
if (current_button_id == after_last_element_id) {
|
if (current_button_id == after_last_element_id)
|
||||||
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,
|
||||||
event.TouchInput.ID, true);
|
event.TouchInput.ID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchScreenGUI::doubleTapDetection()
|
// Punch or left click
|
||||||
{
|
bool TouchScreenGUI::quickTapDetection() {
|
||||||
m_key_events[0].down_time = m_key_events[1].down_time;
|
m_key_events[0].down_time = m_key_events[1].down_time;
|
||||||
m_key_events[0].x = m_key_events[1].x;
|
m_key_events[0].x = m_key_events[1].x;
|
||||||
m_key_events[0].y = m_key_events[1].y;
|
m_key_events[0].y = m_key_events[1].y;
|
||||||
m_key_events[1].down_time = m_move_downtime;
|
/* m_key_events[1].down_time = m_move_downtime;
|
||||||
m_key_events[1].x = m_move_downlocation.X;
|
m_key_events[1].x = m_move_downlocation.X;
|
||||||
m_key_events[1].y = m_move_downlocation.Y;
|
m_key_events[1].y = m_move_downlocation.Y;
|
||||||
|
|
||||||
u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
|
u64 delta = porting::getDeltaMs(m_key_events[0].down_time, porting::getTimeMs());
|
||||||
if (delta > 400)
|
if (delta > 400)
|
||||||
|
return false;*/
|
||||||
|
|
||||||
|
// ignore the occasional touch
|
||||||
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
||||||
|
if (delta < 50)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
double distance = sqrt(
|
/*double distance = sqrt(
|
||||||
(m_key_events[0].x - m_key_events[1].x) * (m_key_events[0].x - m_key_events[1].x) +
|
(m_key_events[0].x - m_key_events[1].x) * (m_key_events[0].x - m_key_events[1].x) +
|
||||||
(m_key_events[0].y - m_key_events[1].y) * (m_key_events[0].y - m_key_events[1].y));
|
(m_key_events[0].y - m_key_events[1].y) * (m_key_events[0].y - m_key_events[1].y));
|
||||||
|
|
||||||
|
|
||||||
if (distance > (20 + g_settings->getU16("touchscreen_threshold")))
|
if (distance > (20 + g_settings->getU16("touchscreen_threshold")))
|
||||||
return false;
|
return false;*/
|
||||||
|
|
||||||
SEvent* translated = new SEvent();
|
auto *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;
|
||||||
@ -833,38 +762,30 @@ bool TouchScreenGUI::doubleTapDetection()
|
|||||||
m_receiver->OnEvent(*translated);
|
m_receiver->OnEvent(*translated);
|
||||||
delete translated;
|
delete translated;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TouchScreenGUI::~TouchScreenGUI()
|
TouchScreenGUI::~TouchScreenGUI() {
|
||||||
{
|
for (auto &m_button : m_buttons) {
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
button_info *btn = &m_button;
|
||||||
button_info* btn = &m_buttons[i];
|
if (btn->guibutton != nullptr) {
|
||||||
if (btn->guibutton != 0) {
|
|
||||||
btn->guibutton->drop();
|
btn->guibutton->drop();
|
||||||
btn->guibutton = NULL;
|
btn->guibutton = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::step(float dtime)
|
void TouchScreenGUI::step(float dtime) {
|
||||||
{
|
// simulate keyboard repeats
|
||||||
/* simulate keyboard repeats */
|
for (auto &m_button : m_buttons) {
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
button_info *btn = &m_button;
|
||||||
button_info* btn = &m_buttons[i];
|
|
||||||
|
|
||||||
if (btn->ids.size() > 0) {
|
if (!btn->ids.empty()) {
|
||||||
btn->repeatcounter += dtime;
|
btn->repeatcounter += dtime;
|
||||||
|
|
||||||
/* in case we're moving around digging does not happen */
|
|
||||||
/* If the sneak button is required, it will not let you interact!
|
|
||||||
if (m_move_id != -1)
|
|
||||||
m_move_has_really_moved = true;*/
|
|
||||||
|
|
||||||
if (btn->repeatcounter < btn->repeatdelay) continue;
|
if (btn->repeatcounter < btn->repeatdelay) continue;
|
||||||
|
|
||||||
btn->repeatcounter = 0;
|
btn->repeatcounter = 0;
|
||||||
SEvent translated;
|
SEvent translated{};
|
||||||
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;
|
||||||
@ -876,21 +797,21 @@ void TouchScreenGUI::step(float dtime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if a new placed pointer isn't moved for some time start digging */
|
// if a new placed pointer isn't moved for some time start digging
|
||||||
if ((m_move_id != -1) &&
|
if ((m_move_id != -1) &&
|
||||||
(!m_move_has_really_moved) &&
|
(!m_move_has_really_moved) &&
|
||||||
(!m_move_sent_as_mouse_event)) {
|
(!m_move_sent_as_mouse_event)) {
|
||||||
|
|
||||||
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
u64 delta = porting::getDeltaMs(m_move_downtime, porting::getTimeMs());
|
||||||
|
|
||||||
if (delta > MIN_DIG_TIME_MS) {
|
if (delta > (MIN_DIG_TIME * 1000.F)) {
|
||||||
m_shootline = m_device
|
m_shootline = m_device
|
||||||
->getSceneManager()
|
->getSceneManager()
|
||||||
->getSceneCollisionManager()
|
->getSceneCollisionManager()
|
||||||
->getRayFromScreenCoordinates(
|
->getRayFromScreenCoordinates(
|
||||||
v2s32(m_move_downlocation.X,m_move_downlocation.Y));
|
v2s32(m_move_downlocation.X, m_move_downlocation.Y));
|
||||||
|
|
||||||
SEvent translated;
|
SEvent translated{};
|
||||||
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;
|
||||||
@ -906,45 +827,39 @@ void TouchScreenGUI::step(float dtime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::resetHud()
|
void TouchScreenGUI::resetHud() {
|
||||||
{
|
|
||||||
m_hud_rects.clear();
|
m_hud_rects.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect)
|
void TouchScreenGUI::registerHudItem(int index, const rect<s32> &rect) {
|
||||||
{
|
|
||||||
m_hud_rects[index] = rect;
|
m_hud_rects[index] = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::Toggle(bool visible)
|
void TouchScreenGUI::Toggle(bool visible) {
|
||||||
{
|
|
||||||
m_visible = visible;
|
m_visible = visible;
|
||||||
for (unsigned int i = 0; i < after_last_element_id; i++) {
|
for (auto &m_button : m_buttons) {
|
||||||
button_info* btn = &m_buttons[i];
|
button_info *btn = &m_button;
|
||||||
if (btn->guibutton != 0) {
|
if (btn->guibutton != nullptr) {
|
||||||
btn->guibutton->setVisible(visible);
|
btn->guibutton->setVisible(visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear all active buttons */
|
// clear all active buttons
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
while (m_known_ids.size() > 0) {
|
while (!m_known_ids.empty()) {
|
||||||
handleReleaseEvent(m_known_ids.begin()->id);
|
handleReleaseEvent(m_known_ids.begin()->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::hide()
|
void TouchScreenGUI::hide() {
|
||||||
{
|
|
||||||
if (!m_visible)
|
if (!m_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Toggle(false);
|
Toggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TouchScreenGUI::show()
|
void TouchScreenGUI::show() {
|
||||||
{
|
|
||||||
if (m_visible)
|
if (m_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -30,14 +30,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "client/tile.h"
|
#include "client/tile.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
//#define ENABLE_ANDROID_NOCLIP
|
|
||||||
|
|
||||||
using namespace irr;
|
using namespace irr;
|
||||||
using namespace irr::core;
|
using namespace irr::core;
|
||||||
using namespace irr::gui;
|
using namespace irr::gui;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
forward_one = 0,
|
forward_one,
|
||||||
forward_two,
|
forward_two,
|
||||||
forward_three,
|
forward_three,
|
||||||
backward_one,
|
backward_one,
|
||||||
@ -49,48 +47,44 @@ typedef enum {
|
|||||||
drop_id,
|
drop_id,
|
||||||
jump_id,
|
jump_id,
|
||||||
crunch_id,
|
crunch_id,
|
||||||
#ifdef ENABLE_ANDROID_NOCLIP
|
// noclip_id,
|
||||||
fly_id,
|
// fast_id,
|
||||||
noclip_id,
|
|
||||||
fast_id,
|
|
||||||
#endif
|
|
||||||
minimap_id,
|
|
||||||
// debug_id,
|
// debug_id,
|
||||||
|
escape_id,
|
||||||
|
minimap_id,
|
||||||
|
range_id,
|
||||||
chat_id,
|
chat_id,
|
||||||
// camera_id,
|
// camera_id,
|
||||||
range_id,
|
|
||||||
range_ios_id,
|
|
||||||
empty_id,
|
empty_id,
|
||||||
escape_id,
|
|
||||||
after_last_element_id
|
after_last_element_id
|
||||||
} touch_gui_button_id;
|
} touch_gui_button_id;
|
||||||
|
|
||||||
#define MIN_DIG_TIME_MS 500
|
#define SLOW_BUTTON_REPEAT 1.0f
|
||||||
|
#define MIN_DIG_TIME 0.5f
|
||||||
#define BUTTON_REPEAT_DELAY 0.2f
|
#define BUTTON_REPEAT_DELAY 0.2f
|
||||||
|
|
||||||
extern const char **touchgui_button_imagenames;
|
extern const char **touchgui_button_imagenames;
|
||||||
|
|
||||||
struct button_info
|
struct button_info {
|
||||||
{
|
float repeatcounter;
|
||||||
float repeatcounter;
|
float repeatdelay;
|
||||||
float repeatdelay;
|
irr::EKEY_CODE keycode;
|
||||||
irr::EKEY_CODE keycode;
|
std::vector<size_t> ids;
|
||||||
std::vector<size_t> ids;
|
IGUIButton *guibutton = NULL;
|
||||||
IGUIButton *guibutton = NULL;
|
bool immediate_release;
|
||||||
bool immediate_release;
|
};
|
||||||
};
|
|
||||||
class TouchScreenGUI
|
class TouchScreenGUI {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
|
TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
|
||||||
|
|
||||||
~TouchScreenGUI();
|
~TouchScreenGUI();
|
||||||
|
|
||||||
void translateEvent(const SEvent &event);
|
void translateEvent(const SEvent &event);
|
||||||
|
|
||||||
void init(ISimpleTextureSource *tsrc);
|
void init(ISimpleTextureSource *tsrc);
|
||||||
|
|
||||||
double getYawChange()
|
double getYawChange() {
|
||||||
{
|
|
||||||
double res = m_camera_yaw_change;
|
double res = m_camera_yaw_change;
|
||||||
m_camera_yaw_change = 0;
|
m_camera_yaw_change = 0;
|
||||||
return res;
|
return res;
|
||||||
@ -98,22 +92,24 @@ public:
|
|||||||
|
|
||||||
double getPitch() { return m_camera_pitch; }
|
double getPitch() { return m_camera_pitch; }
|
||||||
|
|
||||||
/*!
|
/* Returns a line which describes what the player is pointing at.
|
||||||
* Returns a line which describes what the player is pointing at.
|
|
||||||
* The starting point and looking direction are significant,
|
* The starting point and looking direction are significant,
|
||||||
* the line should be scaled to match its length to the actual distance
|
* the line should be scaled to match its length to the actual distance
|
||||||
* the player can reach.
|
* the player can reach.
|
||||||
* The line starts at the camera and ends on the camera's far plane.
|
* The line starts at the camera and ends on the camera's far plane.
|
||||||
* The coordinates do not contain the camera offset.
|
* The coordinates do not contain the camera offset. */
|
||||||
*/
|
|
||||||
line3d<f32> getShootline() { return m_shootline; }
|
line3d<f32> getShootline() { return m_shootline; }
|
||||||
|
|
||||||
void step(float dtime);
|
void step(float dtime);
|
||||||
|
|
||||||
void resetHud();
|
void resetHud();
|
||||||
|
|
||||||
void registerHudItem(int index, const rect<s32> &rect);
|
void registerHudItem(int index, const rect<s32> &rect);
|
||||||
|
|
||||||
void Toggle(bool visible);
|
void Toggle(bool visible);
|
||||||
|
|
||||||
void hide();
|
void hide();
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
#ifdef __IOS__
|
#ifdef __IOS__
|
||||||
@ -121,25 +117,23 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IrrlichtDevice* m_device;
|
IrrlichtDevice *m_device;
|
||||||
IGUIEnvironment* m_guienv;
|
IGUIEnvironment *m_guienv;
|
||||||
IEventReceiver* m_receiver;
|
IEventReceiver *m_receiver;
|
||||||
ISimpleTextureSource* m_texturesource;
|
ISimpleTextureSource *m_texturesource;
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
std::map<int,rect<s32> > m_hud_rects;
|
std::map<int, rect<s32> > m_hud_rects;
|
||||||
std::map<size_t, irr::EKEY_CODE> m_hud_ids;
|
std::map<size_t, irr::EKEY_CODE> m_hud_ids;
|
||||||
bool m_visible; // is the gui visible
|
bool m_visible; // is the gui visible
|
||||||
|
|
||||||
/* value in degree */
|
// value in degree
|
||||||
double m_camera_yaw_change;
|
double m_camera_yaw_change;
|
||||||
double m_camera_pitch;
|
double m_camera_pitch;
|
||||||
|
|
||||||
/*!
|
/* A line starting at the camera and pointing towards the
|
||||||
* A line starting at the camera and pointing towards the
|
|
||||||
* selected object.
|
* selected object.
|
||||||
* The line ends on the camera's far plane.
|
* The line ends on the camera's far plane.
|
||||||
* The coordinates do not contain the camera offset.
|
* The coordinates do not contain the camera offset. */
|
||||||
*/
|
|
||||||
line3d<f32> m_shootline;
|
line3d<f32> m_shootline;
|
||||||
|
|
||||||
rect<s32> m_control_pad_rect;
|
rect<s32> m_control_pad_rect;
|
||||||
@ -152,65 +146,57 @@ private:
|
|||||||
|
|
||||||
button_info m_buttons[after_last_element_id];
|
button_info m_buttons[after_last_element_id];
|
||||||
|
|
||||||
/* gui button detection */
|
// gui button detection
|
||||||
touch_gui_button_id getButtonID(s32 x, s32 y);
|
touch_gui_button_id getButtonID(s32 x, s32 y);
|
||||||
|
|
||||||
/* gui button by eventID */
|
// gui button by eventID
|
||||||
touch_gui_button_id getButtonID(size_t eventID);
|
touch_gui_button_id getButtonID(size_t eventID);
|
||||||
|
|
||||||
/* check if a button has changed */
|
// check if a button has changed
|
||||||
void handleChangedButton(const SEvent &event);
|
void handleChangedButton(const SEvent &event);
|
||||||
|
|
||||||
/* initialize a button */
|
// initialize a button
|
||||||
void initButton(touch_gui_button_id id, rect<s32> button_rect,
|
void initButton(touch_gui_button_id id, rect<s32> button_rect,
|
||||||
std::wstring caption, bool immediate_release,
|
std::wstring caption, bool immediate_release,
|
||||||
float repeat_delay = BUTTON_REPEAT_DELAY);
|
float repeat_delay = BUTTON_REPEAT_DELAY);
|
||||||
|
|
||||||
/* load texture */
|
struct id_status {
|
||||||
void loadButtonTexture(button_info *btn, const char *path, rect<s32> button_rect);
|
|
||||||
|
|
||||||
struct id_status
|
|
||||||
{
|
|
||||||
size_t id;
|
size_t id;
|
||||||
int X;
|
int X;
|
||||||
int Y;
|
int Y;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* vector to store known ids and their initial touch positions*/
|
// vector to store known ids and their initial touch positions
|
||||||
std::vector<id_status> m_known_ids;
|
std::vector<id_status> m_known_ids;
|
||||||
|
|
||||||
/* handle a button event */
|
// handle a button event
|
||||||
void handleButtonEvent(touch_gui_button_id bID, size_t eventID, bool action);
|
void handleButtonEvent(touch_gui_button_id bID, size_t eventID, bool action);
|
||||||
|
|
||||||
/* handle pressed hud buttons */
|
// handle pressed hud buttons
|
||||||
bool isHUDButton(const SEvent &event);
|
bool isHUDButton(const SEvent &event);
|
||||||
|
|
||||||
/* handle released hud buttons */
|
// handle released hud buttons
|
||||||
bool isReleaseHUDButton(size_t eventID);
|
bool isReleaseHUDButton(size_t eventID);
|
||||||
|
|
||||||
/* handle double taps */
|
// handle quick touch
|
||||||
bool doubleTapDetection();
|
bool quickTapDetection();
|
||||||
|
|
||||||
/* handle release event */
|
// handle release event
|
||||||
void handleReleaseEvent(size_t evt_id);
|
void handleReleaseEvent(size_t evt_id);
|
||||||
|
|
||||||
/* get size of regular gui control button */
|
// doubleclick detection variables
|
||||||
int getGuiButtonSize();
|
struct key_event {
|
||||||
|
|
||||||
/* doubleclick detection variables */
|
|
||||||
struct key_event
|
|
||||||
{
|
|
||||||
unsigned int down_time;
|
unsigned int down_time;
|
||||||
s32 x;
|
s32 x;
|
||||||
s32 y;
|
s32 y;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* array for saving last known position of a pointer */
|
// array for saving last known position of a pointer
|
||||||
std::map<size_t, v2s32> m_pointerpos;
|
std::map<size_t, v2s32> m_pointerpos;
|
||||||
|
|
||||||
/* array for doubletap detection */
|
// array for doubletap detection
|
||||||
key_event m_key_events[2];
|
key_event m_key_events[2];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TouchScreenGUI *g_touchscreengui;
|
extern TouchScreenGUI *g_touchscreengui;
|
||||||
#endif
|
#endif
|
||||||
|
Before Width: | Height: | Size: 293 B After Width: | Height: | Size: 293 B |
Before Width: | Height: | Size: 269 B After Width: | Height: | Size: 269 B |
Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 283 B |
Before Width: | Height: | Size: 279 B After Width: | Height: | Size: 279 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 545 B After Width: | Height: | Size: 545 B |
Before Width: | Height: | Size: 210 B After Width: | Height: | Size: 210 B |
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
Before Width: | Height: | Size: 259 B After Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 291 B After Width: | Height: | Size: 291 B |
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 220 B |
Before Width: | Height: | Size: 360 B After Width: | Height: | Size: 427 B |
Before Width: | Height: | Size: 400 B |
Before Width: | Height: | Size: 392 B After Width: | Height: | Size: 392 B |
Before Width: | Height: | Size: 259 B After Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 280 B |
Before Width: | Height: | Size: 262 B After Width: | Height: | Size: 262 B |
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B |