2014-04-21 14:10:59 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 sapier
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOUCHSCREENGUI_HEADER
|
|
|
|
#define TOUCHSCREENGUI_HEADER
|
|
|
|
|
|
|
|
#include <IEventReceiver.h>
|
2017-04-07 23:22:00 +02:00
|
|
|
#include <IGUIButton.h>
|
|
|
|
#include <IGUIEnvironment.h>
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
#include <map>
|
2017-04-07 23:22:00 +02:00
|
|
|
#include <vector>
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2015-03-05 11:52:57 +01:00
|
|
|
#include "client/tile.h"
|
2017-04-07 23:22:00 +02:00
|
|
|
#include "game.h"
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
using namespace irr;
|
|
|
|
using namespace irr::core;
|
|
|
|
using namespace irr::gui;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
forward_id = 0,
|
|
|
|
backward_id,
|
|
|
|
left_id,
|
|
|
|
right_id,
|
|
|
|
jump_id,
|
|
|
|
crunch_id,
|
2015-12-13 23:00:05 +01:00
|
|
|
after_last_element_id,
|
|
|
|
settings_starter_id,
|
|
|
|
rare_controls_starter_id,
|
2014-12-10 04:57:25 +01:00
|
|
|
fly_id,
|
|
|
|
noclip_id,
|
|
|
|
fast_id,
|
|
|
|
debug_id,
|
|
|
|
camera_id,
|
|
|
|
range_id,
|
2015-12-13 23:00:05 +01:00
|
|
|
chat_id,
|
|
|
|
inventory_id,
|
|
|
|
drop_id
|
2014-04-21 14:10:59 +02:00
|
|
|
} touch_gui_button_id;
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
typedef enum {
|
|
|
|
AHBB_Dir_Top_Bottom,
|
|
|
|
AHBB_Dir_Bottom_Top,
|
|
|
|
AHBB_Dir_Left_Right,
|
|
|
|
AHBB_Dir_Right_Left
|
|
|
|
} autohide_button_bar_dir;
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
#define MIN_DIG_TIME_MS 500
|
|
|
|
#define MAX_TOUCH_COUNT 64
|
2015-03-24 13:19:32 +01:00
|
|
|
#define BUTTON_REPEAT_DELAY 0.2f
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
#define SETTINGS_BAR_Y_OFFSET 6.5
|
|
|
|
#define RARE_CONTROLS_BAR_Y_OFFSET 4
|
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
extern const char **touchgui_button_imagenames;
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
struct button_info
|
|
|
|
{
|
|
|
|
float repeatcounter;
|
|
|
|
float repeatdelay;
|
|
|
|
irr::EKEY_CODE keycode;
|
2015-12-13 23:00:05 +01:00
|
|
|
std::vector<int> ids;
|
2017-06-21 11:51:29 +02:00
|
|
|
IGUIButton *guibutton = nullptr;
|
2017-04-07 23:22:00 +02:00
|
|
|
bool immediate_release;
|
2015-12-13 23:00:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class AutoHideButtonBar
|
|
|
|
{
|
|
|
|
public:
|
2017-04-07 23:22:00 +02:00
|
|
|
AutoHideButtonBar(IrrlichtDevice *device, IEventReceiver *receiver);
|
2015-12-13 23:00:05 +01:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
void init(ISimpleTextureSource *tsrc, const char *starter_img, int button_id,
|
|
|
|
v2s32 UpperLeft, v2s32 LowerRight, autohide_button_bar_dir dir,
|
|
|
|
float timeout);
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
~AutoHideButtonBar();
|
|
|
|
|
|
|
|
/* add button to be shown */
|
2017-04-07 23:22:00 +02:00
|
|
|
void addButton(touch_gui_button_id id, const wchar_t *caption,
|
|
|
|
const char *btn_image);
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
/* detect settings bar button events */
|
|
|
|
bool isButton(const SEvent &event);
|
|
|
|
|
|
|
|
/* handle released hud buttons */
|
|
|
|
bool isReleaseButton(int eventID);
|
|
|
|
|
|
|
|
/* step handler */
|
|
|
|
void step(float dtime);
|
|
|
|
|
|
|
|
/* deactivate button bar */
|
|
|
|
void deactivate();
|
|
|
|
|
|
|
|
/* hide the whole buttonbar */
|
|
|
|
void hide();
|
|
|
|
|
|
|
|
/* unhide the buttonbar */
|
|
|
|
void show();
|
|
|
|
|
|
|
|
private:
|
2017-06-21 11:51:29 +02:00
|
|
|
ISimpleTextureSource *m_texturesource = nullptr;
|
2017-04-07 23:22:00 +02:00
|
|
|
irr::video::IVideoDriver *m_driver;
|
|
|
|
IGUIEnvironment *m_guienv;
|
|
|
|
IEventReceiver *m_receiver;
|
|
|
|
button_info m_starter;
|
|
|
|
std::vector<button_info *> m_buttons;
|
2015-12-13 23:00:05 +01:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
v2s32 m_upper_left;
|
|
|
|
v2s32 m_lower_right;
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
/* show settings bar */
|
2017-06-21 11:51:29 +02:00
|
|
|
bool m_active = false;
|
2015-12-13 23:00:05 +01:00
|
|
|
|
2017-06-21 11:51:29 +02:00
|
|
|
bool m_visible = true;
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
/* settings bar timeout */
|
2017-06-21 11:51:29 +02:00
|
|
|
float m_timeout = 0.0f;
|
|
|
|
float m_timeout_value = 3.0f;
|
|
|
|
bool m_initialized = false;
|
|
|
|
autohide_button_bar_dir m_dir = AHBB_Dir_Right_Left;
|
2015-12-13 23:00:05 +01:00
|
|
|
};
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
class TouchScreenGUI
|
|
|
|
{
|
|
|
|
public:
|
2017-04-07 23:22:00 +02:00
|
|
|
TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver);
|
2014-04-21 14:10:59 +02:00
|
|
|
~TouchScreenGUI();
|
|
|
|
|
|
|
|
void translateEvent(const SEvent &event);
|
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
void init(ISimpleTextureSource *tsrc);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
double getYawChange()
|
|
|
|
{
|
2016-12-11 22:57:43 +01:00
|
|
|
double res = m_camera_yaw_change;
|
|
|
|
m_camera_yaw_change = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
double getPitch() { return m_camera_pitch; }
|
2016-12-11 22:57:43 +01:00
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
line3d<f32> getShootline() { return m_shootline; }
|
|
|
|
|
|
|
|
void step(float dtime);
|
|
|
|
void resetHud();
|
|
|
|
void registerHudItem(int index, const rect<s32> &rect);
|
|
|
|
void Toggle(bool visible);
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
void hide();
|
|
|
|
void show();
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
private:
|
2017-04-07 23:22:00 +02:00
|
|
|
IrrlichtDevice *m_device;
|
|
|
|
IGUIEnvironment *m_guienv;
|
|
|
|
IEventReceiver *m_receiver;
|
|
|
|
ISimpleTextureSource *m_texturesource;
|
|
|
|
v2u32 m_screensize;
|
2017-05-26 17:03:46 +02:00
|
|
|
std::map<int, rect<s32>> m_hud_rects;
|
2017-04-07 23:22:00 +02:00
|
|
|
std::map<int, irr::EKEY_CODE> m_hud_ids;
|
|
|
|
bool m_visible; // is the gui visible
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
/* value in degree */
|
2017-06-21 11:51:29 +02:00
|
|
|
double m_camera_yaw_change = 0.0;
|
|
|
|
double m_camera_pitch = 0.0;
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
line3d<f32> m_shootline;
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2017-06-21 11:51:29 +02:00
|
|
|
int m_move_id = -1;
|
|
|
|
bool m_move_has_really_moved = false;
|
|
|
|
s64 m_move_downtime = 0;
|
|
|
|
bool m_move_sent_as_mouse_event = false;
|
|
|
|
v2s32 m_move_downlocation = v2s32(-10000, -10000);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
button_info m_buttons[after_last_element_id];
|
|
|
|
|
|
|
|
/* gui button detection */
|
|
|
|
touch_gui_button_id getButtonID(s32 x, s32 y);
|
|
|
|
|
|
|
|
/* gui button by eventID */
|
|
|
|
touch_gui_button_id getButtonID(int eventID);
|
|
|
|
|
|
|
|
/* check if a button has changed */
|
|
|
|
void handleChangedButton(const SEvent &event);
|
|
|
|
|
|
|
|
/* initialize a button */
|
|
|
|
void initButton(touch_gui_button_id id, rect<s32> button_rect,
|
2015-03-24 13:19:32 +01:00
|
|
|
std::wstring caption, bool immediate_release,
|
|
|
|
float repeat_delay = BUTTON_REPEAT_DELAY);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
2017-04-07 23:22:00 +02:00
|
|
|
struct id_status
|
|
|
|
{
|
2014-04-21 14:10:59 +02:00
|
|
|
int id;
|
|
|
|
int X;
|
|
|
|
int Y;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* vector to store known ids and their initial touch positions*/
|
|
|
|
std::vector<id_status> m_known_ids;
|
|
|
|
|
|
|
|
/* handle a button event */
|
2015-12-13 23:00:05 +01:00
|
|
|
void handleButtonEvent(touch_gui_button_id bID, int eventID, bool action);
|
2014-04-21 14:10:59 +02:00
|
|
|
|
|
|
|
/* handle pressed hud buttons */
|
|
|
|
bool isHUDButton(const SEvent &event);
|
|
|
|
|
|
|
|
/* handle released hud buttons */
|
|
|
|
bool isReleaseHUDButton(int eventID);
|
|
|
|
|
|
|
|
/* handle double taps */
|
|
|
|
bool doubleTapDetection();
|
|
|
|
|
2015-12-17 20:43:25 +01:00
|
|
|
/* handle release event */
|
|
|
|
void handleReleaseEvent(int evt_id);
|
|
|
|
|
2015-12-13 23:00:05 +01:00
|
|
|
/* get size of regular gui control button */
|
|
|
|
int getGuiButtonSize();
|
|
|
|
|
2014-04-21 14:10:59 +02:00
|
|
|
/* doubleclick detection variables */
|
2017-04-07 23:22:00 +02:00
|
|
|
struct key_event
|
|
|
|
{
|
2014-04-21 14:10:59 +02:00
|
|
|
unsigned int down_time;
|
|
|
|
s32 x;
|
|
|
|
s32 y;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* array for saving last known position of a pointer */
|
|
|
|
v2s32 m_pointerpos[MAX_TOUCH_COUNT];
|
|
|
|
|
|
|
|
/* array for doubletap detection */
|
|
|
|
key_event m_key_events[2];
|
2015-12-13 23:00:05 +01:00
|
|
|
|
|
|
|
/* settings bar */
|
|
|
|
AutoHideButtonBar m_settingsbar;
|
|
|
|
|
|
|
|
/* rare controls bar */
|
|
|
|
AutoHideButtonBar m_rarecontrolsbar;
|
2014-04-21 14:10:59 +02:00
|
|
|
};
|
|
|
|
extern TouchScreenGUI *g_touchscreengui;
|
|
|
|
#endif
|