touch gui fix (#40)
parent
66c5b30f60
commit
86a8336992
|
@ -394,12 +394,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(int 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<int>::iterator id =
|
std::vector<size_t>::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())
|
||||||
|
@ -436,9 +436,9 @@ bool TouchScreenGUI::isHUDButton(const SEvent &event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TouchScreenGUI::isReleaseHUDButton(int eventID)
|
bool TouchScreenGUI::isReleaseHUDButton(size_t eventID)
|
||||||
{
|
{
|
||||||
std::map<int,irr::EKEY_CODE>::iterator 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();
|
SEvent* translated = new SEvent();
|
||||||
|
@ -457,7 +457,7 @@ 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)
|
size_t eventID, bool action)
|
||||||
{
|
{
|
||||||
button_info* btn = &m_buttons[button];
|
button_info* btn = &m_buttons[button];
|
||||||
SEvent* translated = new SEvent();
|
SEvent* translated = new SEvent();
|
||||||
|
@ -484,7 +484,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
||||||
/* remove event */
|
/* remove event */
|
||||||
if ((!action) || (btn->immediate_release)) {
|
if ((!action) || (btn->immediate_release)) {
|
||||||
|
|
||||||
std::vector<int>::iterator pos =
|
std::vector<size_t>::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());
|
||||||
|
@ -500,7 +500,7 @@ void TouchScreenGUI::handleButtonEvent(touch_gui_button_id button,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TouchScreenGUI::handleReleaseEvent(int 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);
|
||||||
|
|
||||||
|
@ -611,7 +611,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
toadd.Y = event.TouchInput.Y;
|
toadd.Y = event.TouchInput.Y;
|
||||||
m_known_ids.push_back(toadd);
|
m_known_ids.push_back(toadd);
|
||||||
|
|
||||||
int eventID = event.TouchInput.ID;
|
size_t eventID = event.TouchInput.ID;
|
||||||
|
|
||||||
touch_gui_button_id button =
|
touch_gui_button_id button =
|
||||||
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
getButtonID(event.TouchInput.X, event.TouchInput.Y);
|
||||||
|
@ -636,7 +636,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pointerpos[event.TouchInput.ID] = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
storePointerPos(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;
|
||||||
|
@ -644,9 +644,9 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert(event.TouchInput.Event == ETIE_MOVED);
|
assert(event.TouchInput.Event == ETIE_MOVED);
|
||||||
int move_idx = event.TouchInput.ID;
|
size_t move_idx = event.TouchInput.ID;
|
||||||
|
|
||||||
if (m_pointerpos[event.TouchInput.ID] ==
|
if (loadPointerPos(event.TouchInput.ID) ==
|
||||||
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
v2s32(event.TouchInput.X, event.TouchInput.Y)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -655,11 +655,12 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
if ((event.TouchInput.ID == m_move_id) &&
|
if ((event.TouchInput.ID == m_move_id) &&
|
||||||
(!m_move_sent_as_mouse_event || !g_settings->getBool("touchtarget"))) {
|
(!m_move_sent_as_mouse_event || !g_settings->getBool("touchtarget"))) {
|
||||||
|
|
||||||
|
v2s32 old_pos = loadPointerPos(event.TouchInput.ID);
|
||||||
double distance = sqrt(
|
double distance = sqrt(
|
||||||
(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) *
|
(old_pos.X - event.TouchInput.X) *
|
||||||
(m_pointerpos[event.TouchInput.ID].X - event.TouchInput.X) +
|
(old_pos.X - event.TouchInput.X) +
|
||||||
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y) *
|
(old_pos.Y - event.TouchInput.Y) *
|
||||||
(m_pointerpos[event.TouchInput.ID].Y - event.TouchInput.Y));
|
(old_pos.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)) {
|
||||||
|
@ -668,8 +669,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
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;
|
s32 dx = X - loadPointerPos(event.TouchInput.ID).X;
|
||||||
s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y;
|
s32 dy = Y - loadPointerPos(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");
|
||||||
|
@ -690,7 +691,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
||||||
->getSceneManager()
|
->getSceneManager()
|
||||||
->getSceneCollisionManager()
|
->getSceneCollisionManager()
|
||||||
->getRayFromScreenCoordinates(v2s32(X, Y));
|
->getRayFromScreenCoordinates(v2s32(X, Y));
|
||||||
m_pointerpos[event.TouchInput.ID] = v2s32(X, Y);
|
storePointerPos(event.TouchInput.ID, v2s32(X, Y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((event.TouchInput.ID == m_move_id) &&
|
else if ((event.TouchInput.ID == m_move_id) &&
|
||||||
|
@ -714,7 +715,7 @@ void TouchScreenGUI::handleChangedButton(const SEvent &event)
|
||||||
if (m_buttons[i].ids.empty()) {
|
if (m_buttons[i].ids.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (std::vector<int>::iterator iter = m_buttons[i].ids.begin();
|
for (std::vector<size_t>::iterator 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) {
|
||||||
|
@ -917,3 +918,16 @@ void TouchScreenGUI::show()
|
||||||
|
|
||||||
Toggle(true);
|
Toggle(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void TouchScreenGUI::storePointerPos(size_t ID, v2s32 pos)
|
||||||
|
{
|
||||||
|
m_pointerpos[ID] = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline v2s32 TouchScreenGUI::loadPointerPos(size_t ID)
|
||||||
|
{
|
||||||
|
std::map<size_t, v2s32>::const_iterator it = m_pointerpos.find(ID);
|
||||||
|
if (it == m_pointerpos.cend())
|
||||||
|
return v2s32(0, 0);
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
|
@ -63,7 +63,6 @@ typedef enum {
|
||||||
} touch_gui_button_id;
|
} touch_gui_button_id;
|
||||||
|
|
||||||
#define MIN_DIG_TIME_MS 500
|
#define MIN_DIG_TIME_MS 500
|
||||||
#define MAX_TOUCH_COUNT 64
|
|
||||||
#define BUTTON_REPEAT_DELAY 0.2f
|
#define BUTTON_REPEAT_DELAY 0.2f
|
||||||
|
|
||||||
extern const char *touchgui_button_imagenames[];
|
extern const char *touchgui_button_imagenames[];
|
||||||
|
@ -90,6 +89,9 @@ public:
|
||||||
void hide();
|
void hide();
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
|
void storePointerPos(size_t ID, v2s32 pos);
|
||||||
|
v2s32 loadPointerPos(size_t ID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IrrlichtDevice* m_device;
|
IrrlichtDevice* m_device;
|
||||||
IGUIEnvironment* m_guienv;
|
IGUIEnvironment* m_guienv;
|
||||||
|
@ -97,7 +99,7 @@ private:
|
||||||
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<int,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 */
|
||||||
|
@ -108,7 +110,7 @@ private:
|
||||||
|
|
||||||
rect<s32> m_control_pad_rect;
|
rect<s32> m_control_pad_rect;
|
||||||
|
|
||||||
int m_move_id;
|
size_t m_move_id;
|
||||||
bool m_move_has_really_moved;
|
bool m_move_has_really_moved;
|
||||||
s32 m_move_downtime;
|
s32 m_move_downtime;
|
||||||
bool m_move_sent_as_mouse_event;
|
bool m_move_sent_as_mouse_event;
|
||||||
|
@ -118,7 +120,7 @@ private:
|
||||||
float repeatcounter;
|
float repeatcounter;
|
||||||
float repeatdelay;
|
float repeatdelay;
|
||||||
irr::EKEY_CODE keycode;
|
irr::EKEY_CODE keycode;
|
||||||
std::vector<int> ids;
|
std::vector<size_t> ids;
|
||||||
IGUIButton* guibutton;
|
IGUIButton* guibutton;
|
||||||
bool immediate_release;
|
bool immediate_release;
|
||||||
};
|
};
|
||||||
|
@ -129,7 +131,7 @@ private:
|
||||||
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(int 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);
|
||||||
|
@ -143,7 +145,7 @@ private:
|
||||||
void loadButtonTexture(button_info* btn, const char* path, rect<s32> button_rect);
|
void loadButtonTexture(button_info* btn, const char* path, rect<s32> button_rect);
|
||||||
|
|
||||||
struct id_status{
|
struct id_status{
|
||||||
int id;
|
size_t id;
|
||||||
int X;
|
int X;
|
||||||
int Y;
|
int Y;
|
||||||
};
|
};
|
||||||
|
@ -152,19 +154,19 @@ private:
|
||||||
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, int 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(int eventID);
|
bool isReleaseHUDButton(size_t eventID);
|
||||||
|
|
||||||
/* handle double taps */
|
/* handle double taps */
|
||||||
bool doubleTapDetection();
|
bool doubleTapDetection();
|
||||||
|
|
||||||
/* handle release event */
|
/* handle release event */
|
||||||
void handleReleaseEvent(int evt_id);
|
void handleReleaseEvent(size_t evt_id);
|
||||||
|
|
||||||
/* get size of regular gui control button */
|
/* get size of regular gui control button */
|
||||||
int getGuiButtonSize();
|
int getGuiButtonSize();
|
||||||
|
@ -177,7 +179,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/* array for saving last known position of a pointer */
|
/* array for saving last known position of a pointer */
|
||||||
v2s32 m_pointerpos[MAX_TOUCH_COUNT];
|
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];
|
||||||
|
|
Loading…
Reference in New Issue