Skip to content

Commit 9fbc3a8

Browse files
committedMar 24, 2015
Slow down the "key repeat" touch speed for some Android controls
Increases the key/buttons repeat delay for fly, noclip, fast, debug and camera buttons
1 parent 732d7b9 commit 9fbc3a8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed
 

Diff for: ‎src/touchscreengui.cpp

+13-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3131

3232
#include <ISceneCollisionManager.h>
3333

34+
// Very slow button repeat frequency (in seconds)
35+
#define SLOW_BUTTON_REPEAT (1.0f)
36+
3437
using namespace irr::core;
3538

3639
extern Settings *g_settings;
@@ -121,6 +124,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver* receiver)
121124
for (unsigned int i=0; i < after_last_element_id; i++) {
122125
m_buttons[i].guibutton = 0;
123126
m_buttons[i].repeatcounter = -1;
127+
m_buttons[i].repeatdelay = BUTTON_REPEAT_DELAY;
124128
}
125129

126130
m_screensize = m_device->getVideoDriver()->getScreenSize();
@@ -141,13 +145,14 @@ void TouchScreenGUI::loadButtonTexture(button_info* btn, const char* path)
141145
}
142146

143147
void TouchScreenGUI::initButton(touch_gui_button_id id, rect<s32> button_rect,
144-
std::wstring caption, bool immediate_release )
148+
std::wstring caption, bool immediate_release, float repeat_delay)
145149
{
146150

147151
button_info* btn = &m_buttons[id];
148152
btn->guibutton = m_guienv->addButton(button_rect, 0, id, caption.c_str());
149153
btn->guibutton->grab();
150154
btn->repeatcounter = -1;
155+
btn->repeatdelay = repeat_delay;
151156
btn->keycode = id2keycode(id);
152157
btn->immediate_release = immediate_release;
153158
btn->ids.clear();
@@ -240,25 +245,25 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc, float density)
240245
rect<s32>(m_screensize.X - (0.75*button_size),
241246
m_screensize.Y - (2.25*button_size),
242247
m_screensize.X, m_screensize.Y - (button_size*1.5)),
243-
L"fly", true);
248+
L"fly", false, SLOW_BUTTON_REPEAT);
244249

245250
/* init noclip button */
246251
initButton(noclip_id,
247252
rect<s32>(m_screensize.X - (0.75*button_size), 2.25*button_size,
248253
m_screensize.X, 3*button_size),
249-
L"clip", true);
254+
L"clip", false, SLOW_BUTTON_REPEAT);
250255

251256
/* init fast button */
252257
initButton(fast_id,
253258
rect<s32>(m_screensize.X - (0.75*button_size), 1.5*button_size,
254259
m_screensize.X, 2.25*button_size),
255-
L"fast", true);
260+
L"fast", false, SLOW_BUTTON_REPEAT);
256261

257262
/* init debug button */
258263
initButton(debug_id,
259264
rect<s32>(m_screensize.X - (0.75*button_size), 0.75*button_size,
260265
m_screensize.X, 1.5*button_size),
261-
L"dbg", true);
266+
L"dbg", false, SLOW_BUTTON_REPEAT);
262267

263268
/* init chat button */
264269
initButton(chat_id,
@@ -270,13 +275,13 @@ void TouchScreenGUI::init(ISimpleTextureSource* tsrc, float density)
270275
initButton(camera_id,
271276
rect<s32>(m_screensize.X - (1.5*button_size), 0,
272277
m_screensize.X - (0.75*button_size), 0.75*button_size),
273-
L"cam", true);
278+
L"cam", false, SLOW_BUTTON_REPEAT);
274279

275280
/* init rangeselect button */
276281
initButton(range_id,
277282
rect<s32>(m_screensize.X - (2.25*button_size), 0,
278283
m_screensize.X - (1.5*button_size), 0.75*button_size),
279-
L"far", true);
284+
L"far", false, SLOW_BUTTON_REPEAT);
280285
}
281286

282287
touch_gui_button_id TouchScreenGUI::getButtonID(s32 x, s32 y)
@@ -687,7 +692,7 @@ void TouchScreenGUI::step(float dtime)
687692
if (m_move_id != -1)
688693
m_move_has_really_moved = true;
689694

690-
if (btn->repeatcounter < 0.2) continue;
695+
if (btn->repeatcounter < btn->repeatdelay) continue;
691696

692697
btn->repeatcounter = 0;
693698
SEvent translated;

Diff for: ‎src/touchscreengui.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef enum {
5454

5555
#define MIN_DIG_TIME_MS 500
5656
#define MAX_TOUCH_COUNT 64
57+
#define BUTTON_REPEAT_DELAY 0.2f
5758

5859
extern const char** touchgui_button_imagenames;
5960

@@ -105,6 +106,7 @@ class TouchScreenGUI
105106

106107
struct button_info {
107108
float repeatcounter;
109+
float repeatdelay;
108110
irr::EKEY_CODE keycode;
109111
std::vector<int> ids;
110112
IGUIButton* guibutton;
@@ -124,7 +126,8 @@ class TouchScreenGUI
124126

125127
/* initialize a button */
126128
void initButton(touch_gui_button_id id, rect<s32> button_rect,
127-
std::wstring caption, bool immediate_release );
129+
std::wstring caption, bool immediate_release,
130+
float repeat_delay = BUTTON_REPEAT_DELAY);
128131

129132
/* load texture */
130133
void loadButtonTexture(button_info* btn, const char* path);

0 commit comments

Comments
 (0)
Please sign in to comment.