Skip to content

Commit

Permalink
[iOS] Enable scrolling with a two fingers panning gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Goyet committed Dec 21, 2011
1 parent 77b0244 commit 461e623
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/gui_ios.m
Expand Up @@ -133,9 +133,17 @@ - (void)viewDidLoad {
[tapGestureRecognizer release];

UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
panGestureRecognizer.minimumNumberOfTouches = 1;
panGestureRecognizer.maximumNumberOfTouches = 1;
[_textView addGestureRecognizer:panGestureRecognizer];
[panGestureRecognizer release];

UIPanGestureRecognizer * scrollGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(scroll:)];
scrollGestureRecognizer.minimumNumberOfTouches = 2;
scrollGestureRecognizer.maximumNumberOfTouches = 2;
[_textView addGestureRecognizer:scrollGestureRecognizer];
[scrollGestureRecognizer release];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
Expand Down Expand Up @@ -219,6 +227,36 @@ - (void)pan:(UIPanGestureRecognizer *)sender {
gui_send_mouse_event(event, clickLocation.x, clickLocation.y, 1, 0);
}

- (void)scroll:(UIPanGestureRecognizer *)sender {
CGPoint clickLocation = [sender locationInView:sender.view];
CGPoint translation = [sender translationInView:sender.view];
static int totalScrollX = 0;
static int totalScrollY = 0;
if (sender.state == UIGestureRecognizerStateBegan) {
totalScrollX = 0;
totalScrollY = 0;
}
int targetScrollX = translation.x / gui.char_width;
int targetScrollY = translation.y / gui.char_height;

while (targetScrollX < totalScrollX) {
gui_send_mouse_event(MOUSE_6, clickLocation.x, clickLocation.y, 0, 0);
totalScrollX--;
}
while (targetScrollX > totalScrollX) {
gui_send_mouse_event(MOUSE_7, clickLocation.x, clickLocation.y, 0, 0);
totalScrollX++;
}
while (targetScrollY < totalScrollY) {
gui_send_mouse_event(MOUSE_5, clickLocation.x, clickLocation.y, 0, 0);
totalScrollY--;
}
while (targetScrollY > totalScrollY) {
gui_send_mouse_event(MOUSE_4, clickLocation.x, clickLocation.y, 0, 0);
totalScrollY++;
}
}

- (void)keyboardWasShown:(NSNotification *)notification {
CGRect keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGRect keyboardRectInView = [self.view.window convertRect:keyboardRect toView:_textView];
Expand Down Expand Up @@ -414,6 +452,10 @@ int main(int argc, char *argv[]) {
gui.def_norm_pixel = gui.norm_pixel;
gui.def_back_pixel = gui.back_pixel;

#ifdef FEAT_GUI_SCROLL_WHEEL_FORCE
gui.scroll_wheel_force = 1;
#endif

return OK;
}

Expand Down
1 change: 1 addition & 0 deletions src/os_ios_rsrc/ios_prefix.pch
Expand Up @@ -9,6 +9,7 @@
#define HAVE_OPENDIR 1
#define MACOS_X_UNIX 1
#define ALWAYS_USE_GUI 1
#define FEAT_GUI_SCROLL_WHEEL_FORCE 1

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
Expand Down

0 comments on commit 461e623

Please sign in to comment.