/*
Copyright (C) 2014 sapier
Copyright (C) 2018 srifqi, Muhammad Rifqi Priyo Susanto
<muhammadrifqipriyosusanto@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "touchscreengui.h"
#include "irrlichttypes.h"
#include "irr_v2d.h"
#include "log.h"
#include "client/keycode.h"
#include "settings.h"
#include "gettime.h"
#include "util/numeric.h"
#include "porting.h"
#include "client/guiscalingfilter.h"
#include <iostream>
#include <algorithm>
#include <ISceneCollisionManager.h>
// Very slow button repeat frequency (in seconds)
#define SLOW_BUTTON_REPEAT (1.0f)
using namespace irr::core;
const char **touchgui_button_imagenames = (const char *[]) {
"jump_btn.png",
"down.png",
"zoom.png",
"aux_btn.png"
};
const char **touchgui_joystick_imagenames = (const char *[]) {
"joystick_off.png",
"joystick_bg.png",
"joystick_center.png"
};
static irr::EKEY_CODE id2keycode(touch_gui_button_id id)
{
std::string key = "";
switch (id) {
case forward_id:
key = "forward";
break;
case left_id:
key = "left";
break;
case right_id:
key = "right";
break;
case backward_id:
key = "backward";
break;
case inventory_id:
key = "inventory";
break;
case drop_id:
key = "drop";
break;
case jump_id:
key = "jump";
break;
case crunch_id:
key = "sneak";
break;
case zoom_id:
key = "zoom";
break;
case special1_id:
key = "special1";
break;
case fly_id:
key = "freemove";
break;
case noclip_id:
key = "noclip";
break;
case fast_id:
key = "fastmove";
break;
case debug_id:
key = "toggle_debug";
break;
case toggle_chat_id:
key = "toggle_chat";
break;
case minimap_id:
key = "minimap";
break;
case chat_id:
key = "chat";
break;
case camera_id:
key = "camera_mode";
break;
case range_id:
key = "rangeselect";
break;
}
assert(key != "");
return keyname_to_keycode(g_settings->get("keymap_" + key).c_str());
}
TouchScreenGUI *g_touchscreengui;
static void load_button_texture(button_info *btn, const char *path,
rect<s32> button_rect, ISimpleTextureSource *tsrc, video::IVideoDriver *driver)
{
unsigned int tid;
video::ITexture *texture = guiScalingImageButton(driver,
|