Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.2] [iOS] Add touch delay value to project settings #42457

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,9 @@
<member name="input_devices/pointing/emulate_touch_from_mouse" type="bool" setter="" getter="" default="false">
If [code]true[/code], sends touch input events when clicking or dragging the mouse.
</member>
<member name="input_devices/pointing/ios/touch_delay" type="float" setter="" getter="" default="0.150">
Default delay for touch events. This only affects iOS devices.
</member>
<member name="layer_names/2d_physics/layer_1" type="String" setter="" getter="" default="&quot;&quot;">
Optional name for the 2D physics layer 1.
</member>
Expand Down
1 change: 1 addition & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
ProjectSettings::get_singleton()->set_custom_property_info("application/run/low_processor_mode_sleep_usec", PropertyInfo(Variant::INT, "application/run/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "0,33200,1,or_greater")); // No negative numbers

GLOBAL_DEF("display/window/ios/hide_home_indicator", true);
GLOBAL_DEF("input_devices/pointing/ios/touch_delay", 0.150);

Engine::get_singleton()->set_frame_delay(frame_delay);

Expand Down
2 changes: 1 addition & 1 deletion platform/iphone/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ iphone_lib = [
"in_app_store.mm",
"icloud.mm",
"ios.mm",
"gl_view_gesture_recognizer.m",
"gl_view_gesture_recognizer.mm",
]

env_ios = env.Clone()
Expand Down
2 changes: 2 additions & 0 deletions platform/iphone/gl_view_gesture_recognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
UIEvent *delayedEvent;
}

@property(nonatomic, readonly, assign) NSTimeInterval delayTimeInterval;

- (instancetype)init;

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*************************************************************************/
/* gl_view_gesture_recognizer.m */
/* gl_view_gesture_recognizer.mm */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -30,15 +30,20 @@

#import "gl_view_gesture_recognizer.h"

// Using same delay interval that is used for `UIScrollView`
const NSTimeInterval kGLGestureDelayInterval = 0.150;
#include "core/project_settings.h"

// Minimum distance for touches to move to fire
// a delay timer before scheduled time.
// Should be the low enough to not cause issues with dragging
// but big enough to allow click to work.
const CGFloat kGLGestureMovementDistance = 0.5;

@interface GLViewGestureRecognizer ()

@property(nonatomic, readwrite, assign) NSTimeInterval delayTimeInterval;

@end

@implementation GLViewGestureRecognizer

- (instancetype)init {
Expand All @@ -48,6 +53,8 @@ - (instancetype)init {
self.delaysTouchesBegan = YES;
self.delaysTouchesEnded = YES;

self.delayTimeInterval = GLOBAL_GET("input_devices/pointing/ios/touch_delay");

return self;
}

Expand All @@ -57,7 +64,7 @@ - (void)delayTouches:(NSSet *)touches andEvent:(UIEvent *)event {
delayedTouches = touches;
delayedEvent = event;

delayTimer = [NSTimer scheduledTimerWithTimeInterval:kGLGestureDelayInterval target:self selector:@selector(fireDelayedTouches:) userInfo:nil repeats:NO];
delayTimer = [NSTimer scheduledTimerWithTimeInterval:self.delayTimeInterval target:self selector:@selector(fireDelayedTouches:) userInfo:nil repeats:NO];
}

- (void)fireDelayedTouches:(id)timer {
Expand Down