Android: add mouse support (#102)
Co-authored-by: Deve <deveee@gmail.com>
This commit is contained in:
parent
8f74118a43
commit
e9157515b9
@ -555,7 +555,7 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
|
||||
infostream << "Waited for other menus" << std::endl;
|
||||
|
||||
// Cursor can be non-visible when coming from the game
|
||||
#if !defined(__ANDROID__) && !defined(__IOS__)
|
||||
#ifndef __IOS__
|
||||
RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true);
|
||||
#endif
|
||||
|
||||
|
@ -954,6 +954,10 @@ private:
|
||||
|
||||
int m_reset_HW_buffer_counter = 0;
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
bool m_cache_touchtarget;
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__) || defined(__IOS__)
|
||||
bool m_android_chat_open;
|
||||
#endif
|
||||
@ -1356,12 +1360,6 @@ bool Game::createClient(const GameStartData &start_data)
|
||||
return false;
|
||||
|
||||
bool could_connect, connect_aborted;
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (g_touchscreengui) {
|
||||
g_touchscreengui->init(texture_src);
|
||||
g_touchscreengui->hide();
|
||||
}
|
||||
#endif
|
||||
if (!connectToServer(start_data, &could_connect, &connect_aborted))
|
||||
return false;
|
||||
|
||||
@ -1470,10 +1468,11 @@ bool Game::initGui()
|
||||
-1, chat_backend, client, &g_menumgr);
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
|
||||
if (g_touchscreengui)
|
||||
g_touchscreengui->show();
|
||||
|
||||
if (g_touchscreengui) {
|
||||
g_touchscreengui->init(texture_src);
|
||||
if (g_touchscreengui->isActive())
|
||||
g_touchscreengui->show();
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@ -1883,7 +1882,6 @@ void Game::processUserInput(f32 dtime)
|
||||
else if (g_touchscreengui) {
|
||||
/* on touchscreengui step may generate own input events which ain't
|
||||
* what we want in case we just did clear them */
|
||||
g_touchscreengui->show();
|
||||
g_touchscreengui->step(dtime);
|
||||
}
|
||||
#endif
|
||||
@ -2436,7 +2434,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
|
||||
if ((device->isWindowActive() && device->isWindowFocused()
|
||||
&& !isMenuActive()) || input->isRandom()) {
|
||||
|
||||
#if !defined(__ANDROID__) && !defined(__IOS__)
|
||||
#ifndef __IOS__
|
||||
if (!input->isRandom()) {
|
||||
// Mac OSX gets upset if this is set every frame
|
||||
if (device->getCursorControl()->isVisible())
|
||||
@ -2455,7 +2453,7 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
|
||||
|
||||
} else {
|
||||
|
||||
#if !defined(__ANDROID__) && !defined(__IOS__)
|
||||
#ifndef __IOS__
|
||||
// Mac OSX gets upset if this is set every frame
|
||||
if (!device->getCursorControl()->isVisible())
|
||||
device->getCursorControl()->setVisible(true);
|
||||
@ -2471,9 +2469,10 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (g_touchscreengui) {
|
||||
cam->camera_yaw += g_touchscreengui->getYawChange();
|
||||
cam->camera_pitch = g_touchscreengui->getPitch();
|
||||
} else {
|
||||
cam->camera_pitch += g_touchscreengui->getPitchChange();
|
||||
}
|
||||
#endif
|
||||
{
|
||||
v2s32 center(driver->getScreenSize().Width / 2, driver->getScreenSize().Height / 2);
|
||||
v2s32 dist = input->getMousePos() - center;
|
||||
|
||||
@ -2486,9 +2485,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
|
||||
|
||||
if (dist.X != 0 || dist.Y != 0)
|
||||
input->setMousePos(center.X, center.Y);
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_cache_enable_joysticks) {
|
||||
f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime;
|
||||
@ -3142,7 +3139,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
|
||||
if ((g_settings->getBool("touchtarget")) && (g_touchscreengui)) {
|
||||
if (g_touchscreengui && g_touchscreengui->isActive() && m_cache_touchtarget) {
|
||||
shootline = g_touchscreengui->getShootline();
|
||||
// Scale shootline to the acual distance the player can reach
|
||||
shootline.end = shootline.start
|
||||
@ -4000,10 +3997,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
||||
(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
|
||||
(camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
try {
|
||||
draw_crosshair = !g_settings->getBool("touchtarget");
|
||||
} catch (SettingNotFoundException) {
|
||||
}
|
||||
draw_crosshair = !m_cache_touchtarget || !g_touchscreengui->isActive();
|
||||
#endif
|
||||
|
||||
video::SOverrideMaterial &mat = driver->getOverrideMaterial();
|
||||
@ -4207,6 +4201,10 @@ void Game::readSettings()
|
||||
|
||||
m_cache_fog_start = g_settings->getFloat("fog_start");
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
m_cache_touchtarget = g_settings->getBool("touchtarget");
|
||||
#endif
|
||||
|
||||
m_cache_cam_smoothing = 0;
|
||||
if (g_settings->getBool("cinematic"))
|
||||
m_cache_cam_smoothing = 1 - g_settings->getFloat("cinematic_camera_smoothing");
|
||||
@ -4225,7 +4223,9 @@ void Game::pauseGame()
|
||||
{
|
||||
if (g_menumgr.pausesGame() || !hud)
|
||||
return;
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
g_touchscreengui->handleReleaseAll();
|
||||
#endif
|
||||
showPauseMenu();
|
||||
runData.pause_game_timer = 0;
|
||||
}
|
||||
@ -4342,7 +4342,12 @@ void Game::showPauseMenu()
|
||||
#endif
|
||||
|
||||
float ypos = simple_singleplayer_mode ? 0.7f : 0.1f;
|
||||
#if __IOS__
|
||||
#ifdef __ANDROID__
|
||||
bool hasRealKeyboard = porting::hasRealKeyboard();
|
||||
if (simple_singleplayer_mode && hasRealKeyboard)
|
||||
ypos -= 0.6f;
|
||||
#endif
|
||||
#ifdef __IOS__
|
||||
ypos += 0.5f;
|
||||
#endif
|
||||
std::ostringstream os;
|
||||
@ -4369,7 +4374,10 @@ void Game::showPauseMenu()
|
||||
<< strgettext("Sound Volume") << ";;false]";
|
||||
}
|
||||
#endif
|
||||
#if !defined(__ANDROID__) && !defined(__IOS__)
|
||||
#ifndef __IOS__
|
||||
#ifdef __ANDROID__
|
||||
if (hasRealKeyboard)
|
||||
#endif
|
||||
os << "image_button_exit[3.5," << (ypos++) << ";4,0.9;;btn_key_config;"
|
||||
<< strgettext("Change Keys") << ";;false]";
|
||||
#endif
|
||||
|
@ -102,6 +102,19 @@ void KeyCache::populate()
|
||||
|
||||
bool MyEventReceiver::OnEvent(const SEvent &event)
|
||||
{
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (event.EventType == irr::EET_TOUCH_INPUT_EVENT) {
|
||||
TouchScreenGUI::setActive(true);
|
||||
if (m_touchscreengui && !isMenuActive())
|
||||
m_touchscreengui->show();
|
||||
} else if (event.EventType == irr::EET_MOUSE_INPUT_EVENT &&
|
||||
event.MouseInput.Event == irr::EMIE_MOUSE_MOVED) {
|
||||
TouchScreenGUI::setActive(false);
|
||||
if (m_touchscreengui && !isMenuActive())
|
||||
m_touchscreengui->hide();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
React to nothing here if a menu is active
|
||||
*/
|
||||
|
@ -155,7 +155,7 @@ void GUIChatConsole::closeConsoleAtOnce()
|
||||
m_height = 0;
|
||||
recalculateConsolePosition();
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (g_touchscreengui)
|
||||
if (g_touchscreengui && g_touchscreengui->isActive())
|
||||
g_touchscreengui->show();
|
||||
#endif
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "intlGUIEditBox.h"
|
||||
#include "guiHyperText.h"
|
||||
#include "guiScene.h"
|
||||
#include "touchscreengui.h"
|
||||
|
||||
#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#include <SDL.h>
|
||||
@ -3743,9 +3744,14 @@ void GUIFormSpecMenu::drawMenu()
|
||||
}
|
||||
|
||||
/* TODO find way to show tooltips on touchscreen */
|
||||
#ifndef HAVE_TOUCHSCREENGUI
|
||||
m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (!TouchScreenGUI::isActive())
|
||||
#endif
|
||||
{
|
||||
#ifndef __IOS__
|
||||
m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Draw fields/buttons tooltips and update the mouse cursor
|
||||
@ -3753,7 +3759,7 @@ void GUIFormSpecMenu::drawMenu()
|
||||
gui::IGUIElement *hovered =
|
||||
Environment->getRootGUIElement()->getElementFromPoint(m_pointer);
|
||||
|
||||
#ifndef HAVE_TOUCHSCREENGUI
|
||||
#ifndef __IOS__
|
||||
gui::ICursorControl *cursor_control = RenderingEngine::get_raw_device()->
|
||||
getCursorControl();
|
||||
gui::ECURSOR_ICON current_cursor_icon = cursor_control->getActiveIcon();
|
||||
@ -3793,7 +3799,7 @@ void GUIFormSpecMenu::drawMenu()
|
||||
m_tooltips[field.fname].bgcolor);
|
||||
}
|
||||
|
||||
#ifndef HAVE_TOUCHSCREENGUI
|
||||
#ifndef __IOS__
|
||||
if (field.ftype != f_HyperText && // Handled directly in guiHyperText
|
||||
current_cursor_icon != field.fcursor_icon)
|
||||
cursor_control->setActiveIcon(field.fcursor_icon);
|
||||
@ -3808,7 +3814,7 @@ void GUIFormSpecMenu::drawMenu()
|
||||
|
||||
if (!hovered_element_found) {
|
||||
// no element is hovered
|
||||
#ifndef HAVE_TOUCHSCREENGUI
|
||||
#ifndef __IOS__
|
||||
if (current_cursor_icon != ECI_NORMAL)
|
||||
cursor_control->setActiveIcon(ECI_NORMAL);
|
||||
#endif
|
||||
@ -3843,10 +3849,12 @@ void GUIFormSpecMenu::showTooltip(const std::wstring &text,
|
||||
int tooltip_offset_x = m_btn_height;
|
||||
int tooltip_offset_y = m_btn_height;
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
tooltip_offset_x *= 3;
|
||||
tooltip_offset_y = 0;
|
||||
if (m_pointer.X > (s32)screenSize.X / 2)
|
||||
tooltip_offset_x = -(tooltip_offset_x + tooltip_width);
|
||||
if (TouchScreenGUI::isActive()) {
|
||||
tooltip_offset_x *= 3;
|
||||
tooltip_offset_y = 0;
|
||||
if (m_pointer.X > (s32)screenSize.X / 2)
|
||||
tooltip_offset_x = -(tooltip_offset_x + tooltip_width);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Calculate and set the tooltip position
|
||||
@ -4413,7 +4421,7 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
||||
move_amount = MYMIN(m_selected_amount, 10);
|
||||
else if (button == BET_LEFT) {
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (s.listname == "craft")
|
||||
if (g_touchscreengui && g_touchscreengui->isActive() && s.listname == "craft")
|
||||
move_amount = 1;
|
||||
else
|
||||
#endif
|
||||
|
@ -111,7 +111,7 @@ void GUIModalMenu::quitMenu()
|
||||
m_menumgr->deletingMenu(this);
|
||||
this->remove();
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
if (g_touchscreengui && m_touchscreen_visible)
|
||||
if (g_touchscreengui && g_touchscreengui->isActive() && m_touchscreen_visible)
|
||||
g_touchscreengui->show();
|
||||
#endif
|
||||
}
|
||||
@ -324,7 +324,7 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
|
||||
if (event.TouchInput.Event == ETIE_PRESSED_DOWN || event.TouchInput.Event == ETIE_MOVED)
|
||||
m_pointer = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
||||
if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
|
||||
m_down_pos = m_pointer;
|
||||
m_old_pointer = m_pointer;
|
||||
gui::IGUIElement *hovered = Environment->getRootGUIElement()->getElementFromPoint(core::position2d<s32>(m_pointer));
|
||||
if (event.TouchInput.Event == ETIE_PRESSED_DOWN)
|
||||
Environment->setFocus(hovered);
|
||||
|
@ -78,7 +78,6 @@ protected:
|
||||
std::string m_jni_field_name;
|
||||
#endif
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
v2s32 m_down_pos;
|
||||
bool m_touchscreen_visible = true;
|
||||
#endif
|
||||
|
||||
|
@ -421,6 +421,8 @@ void AutoHideButtonBar::show()
|
||||
}
|
||||
}
|
||||
|
||||
bool TouchScreenGUI::m_active = true;
|
||||
|
||||
TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver):
|
||||
m_device(device),
|
||||
m_guienv(device->getGUIEnvironment()),
|
||||
@ -449,6 +451,7 @@ void TouchScreenGUI::initButton(touch_gui_button_id id, const rect<s32> &button_
|
||||
{
|
||||
button_info *btn = &m_buttons[id];
|
||||
btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, caption.c_str());
|
||||
btn->guibutton->setVisible(m_visible);
|
||||
btn->guibutton->grab();
|
||||
btn->repeatcounter = -1;
|
||||
btn->repeatdelay = repeat_delay;
|
||||
@ -465,7 +468,7 @@ button_info *TouchScreenGUI::initJoystickButton(touch_gui_button_id id,
|
||||
{
|
||||
auto *btn = new button_info();
|
||||
btn->guibutton = m_guienv->addButton(button_rect, nullptr, id, L"O");
|
||||
btn->guibutton->setVisible(visible);
|
||||
btn->guibutton->setVisible(visible && m_visible);
|
||||
btn->guibutton->grab();
|
||||
btn->ids.clear();
|
||||
|
||||
@ -479,7 +482,6 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc)
|
||||
{
|
||||
assert(tsrc);
|
||||
|
||||
m_visible = true;
|
||||
m_texturesource = tsrc;
|
||||
|
||||
/* Init joystick display "button"
|
||||
|
@ -155,6 +155,7 @@ private:
|
||||
// show settings bar
|
||||
bool m_active = false;
|
||||
|
||||
// is the gui visible
|
||||
bool m_visible = true;
|
||||
|
||||
// settings bar timeout
|
||||
@ -181,7 +182,12 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
double getPitch() { return m_camera_pitch; }
|
||||
double getPitchChange()
|
||||
{
|
||||
double res = m_camera_pitch;
|
||||
m_camera_pitch = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a line which describes what the player is pointing at.
|
||||
@ -204,6 +210,12 @@ public:
|
||||
// handle all buttons
|
||||
void handleReleaseAll();
|
||||
|
||||
// returns true if device is active
|
||||
static bool isActive() { return m_active; }
|
||||
|
||||
// set device active state
|
||||
static void setActive(bool active) { m_active = active; }
|
||||
|
||||
private:
|
||||
IrrlichtDevice *m_device;
|
||||
IGUIEnvironment *m_guienv;
|
||||
@ -318,6 +330,9 @@ private:
|
||||
|
||||
// rare controls bar
|
||||
AutoHideButtonBar m_rarecontrolsbar;
|
||||
|
||||
// device active state
|
||||
static bool m_active;
|
||||
};
|
||||
|
||||
extern TouchScreenGUI *g_touchscreengui;
|
||||
|
Loading…
x
Reference in New Issue
Block a user