mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-15 11:46:56 +02:00
convert text input rect to screen coordinates
workarounds SDL bug related to moving window ensuring that the input is always above the native keyboard kambala-decapitator/vcmi#31
This commit is contained in:
parent
1a45b97f5e
commit
217c83a7e7
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
double ios_screenScale() { return UIScreen.mainScreen.nativeScale; }
|
||||||
|
|
||||||
|
|
||||||
static int watchReturnKey(void * userdata, SDL_Event * event);
|
static int watchReturnKey(void * userdata, SDL_Event * event);
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#ifdef VCMI_APPLE
|
#ifdef VCMI_APPLE
|
||||||
#include <dispatch/dispatch.h>
|
#include <dispatch/dispatch.h>
|
||||||
|
|
||||||
|
extern double ios_screenScale(); // TODO ios: move to appropriate file
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 };
|
const SDL_Color Colors::YELLOW = { 229, 215, 123, 0 };
|
||||||
@ -790,15 +792,37 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
|
|||||||
|
|
||||||
void CSDL_Ext::startTextInput(SDL_Rect * where)
|
void CSDL_Ext::startTextInput(SDL_Rect * where)
|
||||||
{
|
{
|
||||||
#ifdef VCMI_APPLE
|
auto impl = [](SDL_Rect * where)
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
{
|
||||||
#endif
|
|
||||||
|
|
||||||
if (SDL_IsTextInputActive() == SDL_FALSE)
|
if (SDL_IsTextInputActive() == SDL_FALSE)
|
||||||
{
|
{
|
||||||
SDL_StartTextInput();
|
SDL_StartTextInput();
|
||||||
}
|
}
|
||||||
SDL_SetTextInputRect(where);
|
SDL_SetTextInputRect(where);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef VCMI_APPLE
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef VCMI_IOS
|
||||||
|
// TODO ios: looks like SDL bug actually, try fixing there
|
||||||
|
auto renderer = SDL_GetRenderer(mainWindow);
|
||||||
|
float scaleX, scaleY;
|
||||||
|
SDL_Rect viewport;
|
||||||
|
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
||||||
|
SDL_RenderGetViewport(renderer, &viewport);
|
||||||
|
|
||||||
|
auto nativeScale = ios_screenScale();
|
||||||
|
auto rectInScreenCoordinates = *where;
|
||||||
|
rectInScreenCoordinates.x = (viewport.x + rectInScreenCoordinates.x) * scaleX / nativeScale;
|
||||||
|
rectInScreenCoordinates.y = (viewport.y + rectInScreenCoordinates.y) * scaleY / nativeScale;
|
||||||
|
rectInScreenCoordinates.w = rectInScreenCoordinates.w * scaleX / nativeScale;
|
||||||
|
rectInScreenCoordinates.h = rectInScreenCoordinates.h * scaleY / nativeScale;
|
||||||
|
impl(&rectInScreenCoordinates);
|
||||||
|
#else
|
||||||
|
impl(where);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef VCMI_APPLE
|
#ifdef VCMI_APPLE
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user