mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
fix coordinates of long press (right click)
kambala-decapitator/vcmi#1 kambala-decapitator/vcmi#26
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
*/
|
||||
|
||||
/* Include the SDL main definition header */
|
||||
#include "SDL_main.h"
|
||||
#include <SDL_main.h>
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_render.h>
|
||||
|
||||
@import UIKit;
|
||||
|
||||
extern SDL_Window * mainWindow;
|
||||
|
||||
|
||||
@interface SDLViewObserver : NSObject
|
||||
@end
|
||||
@@ -18,6 +21,7 @@
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
|
||||
__auto_type longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
|
||||
longPress.minimumPressDuration = 0.1;
|
||||
longPress.delaysTouchesBegan = YES; // prevent normal clicks by SDL
|
||||
[(UIView *)[object valueForKey:keyPath] addGestureRecognizer:longPress];
|
||||
}
|
||||
|
||||
@@ -35,16 +39,38 @@
|
||||
return;
|
||||
}
|
||||
|
||||
__auto_type renderer = SDL_GetRenderer(mainWindow);
|
||||
float scaleX, scaleY;
|
||||
SDL_Rect viewport;
|
||||
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
__auto_type touchedPoint = [gesture locationInView:gesture.view];
|
||||
SDL_Event event;
|
||||
event.button = (SDL_MouseButtonEvent){
|
||||
__auto_type screenScale = UIScreen.mainScreen.nativeScale;
|
||||
Sint32 x = (int)touchedPoint.x * screenScale / scaleX - viewport.x;
|
||||
Sint32 y = (int)touchedPoint.y * screenScale / scaleY - viewport.y;
|
||||
|
||||
SDL_Event rmbEvent;
|
||||
rmbEvent.button = (SDL_MouseButtonEvent){
|
||||
.type = mouseButtonType,
|
||||
.button = SDL_BUTTON_RIGHT,
|
||||
.clicks = 1,
|
||||
.x = touchedPoint.x,
|
||||
.y = touchedPoint.y,
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
SDL_PushEvent(&event);
|
||||
SDL_PushEvent(&rmbEvent);
|
||||
|
||||
// small hack to prevent cursor jumping
|
||||
if (mouseButtonType == SDL_MOUSEBUTTONUP)
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.025 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
SDL_Event motionEvent;
|
||||
motionEvent.motion = (SDL_MouseMotionEvent){
|
||||
.type = SDL_MOUSEMOTION,
|
||||
.x = x,
|
||||
.y = y,
|
||||
};
|
||||
SDL_PushEvent(&motionEvent);
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user