Skip to content

Instantly share code, notes, and snippets.

@xyx0no646
Last active February 13, 2021 12:58
Show Gist options
  • Select an option

  • Save xyx0no646/dafdb5e126a8780503aabcc0a64fd7c9 to your computer and use it in GitHub Desktop.

Select an option

Save xyx0no646/dafdb5e126a8780503aabcc0a64fd7c9 to your computer and use it in GitHub Desktop.
/**
* These snipets are licensed under CC0.
* http://creativecommons.org/publicdomain/zero/1.0/deed.ja
*
* Rewrite to SDL_uikitview.m and LongPressGesture is associated to "Right-Click"
*/
- (instancetype)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
/* ...add it to the end of this block */
UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(longPressGestureBegan:)];
// allows 10px Error
longPressGesture.allowableMovement = 100;
// waiting time to tap until the event occurs
longPressGesture.minimumPressDuration = 1.0f;
// number of tapping.1 time = 0
longPressGesture.numberOfTapsRequired = 0;
// number of fingure(s)
longPressGesture.numberOfTouchesRequired = 1;
// add Gesture
[self addGestureRecognizer:longPressGesture];
}
return self;
}
/*detected longpress gesture*/
-(void) longPressGestureBegan:(UILongPressGestureRecognizer *)sender {
SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, SDL_BUTTON_RIGHT);
[[NSRunLoop mainRunLoop]
addTimer:[NSTimer
timerWithTimeInterval:0.5f
target:self
selector:@selector(longPressGestureStop)
userInfo:nil
repeats:false
]
forMode:NSDefaultRunLoopMode
];
}
/**clear SDL_SendMouseButton*/
- (void) longPressGestureStop {
SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, SDL_BUTTON_RIGHT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment