mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Moved SDL renderer access to ScreenHandler class
This commit is contained in:
@@ -10,13 +10,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct SDL_Texture;
|
struct SDL_Texture;
|
||||||
struct SDL_Window;
|
|
||||||
struct SDL_Renderer;
|
struct SDL_Renderer;
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
|
|
||||||
extern SDL_Texture * screenTexture;
|
extern SDL_Texture * screenTexture;
|
||||||
|
|
||||||
extern SDL_Window * mainWindow;
|
|
||||||
extern SDL_Renderer * mainRenderer;
|
extern SDL_Renderer * mainRenderer;
|
||||||
|
|
||||||
extern SDL_Surface *screen; // main screen surface
|
extern SDL_Surface *screen; // main screen surface
|
||||||
|
@@ -14,11 +14,12 @@
|
|||||||
#include "../CMT.h"
|
#include "../CMT.h"
|
||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/EventDispatcher.h"
|
#include "../gui/EventDispatcher.h"
|
||||||
|
#include "../render/IScreenHandler.h"
|
||||||
|
#include "../renderSDL/SDL_Extensions.h"
|
||||||
|
|
||||||
#include "../../lib/Rect.h"
|
#include "../../lib/Rect.h"
|
||||||
|
|
||||||
#include <SDL_events.h>
|
#include <SDL_events.h>
|
||||||
#include <SDL_render.h>
|
|
||||||
|
|
||||||
#ifdef VCMI_APPLE
|
#ifdef VCMI_APPLE
|
||||||
# include <dispatch/dispatch.h>
|
# include <dispatch/dispatch.h>
|
||||||
@@ -40,30 +41,15 @@ void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
|
|||||||
|
|
||||||
void InputSourceText::startTextInput(const Rect & whereInput)
|
void InputSourceText::startTextInput(const Rect & whereInput)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef VCMI_APPLE
|
#ifdef VCMI_APPLE
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO ios: looks like SDL bug actually, try fixing there
|
Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
|
||||||
auto renderer = SDL_GetRenderer(mainWindow);
|
SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
|
||||||
float scaleX, scaleY;
|
|
||||||
SDL_Rect viewport;
|
|
||||||
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
|
||||||
SDL_RenderGetViewport(renderer, &viewport);
|
|
||||||
|
|
||||||
#ifdef VCMI_IOS
|
SDL_SetTextInputRect(&textInputRect);
|
||||||
const auto nativeScale = iOS_utils::screenScale();
|
|
||||||
scaleX /= nativeScale;
|
|
||||||
scaleY /= nativeScale;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SDL_Rect rectInScreenCoordinates;
|
|
||||||
rectInScreenCoordinates.x = (viewport.x + whereInput.x) * scaleX;
|
|
||||||
rectInScreenCoordinates.y = (viewport.y + whereInput.y) * scaleY;
|
|
||||||
rectInScreenCoordinates.w = whereInput.w * scaleX;
|
|
||||||
rectInScreenCoordinates.h = whereInput.h * scaleY;
|
|
||||||
|
|
||||||
SDL_SetTextInputRect(&rectInScreenCoordinates);
|
|
||||||
|
|
||||||
if (SDL_IsTextInputActive() == SDL_FALSE)
|
if (SDL_IsTextInputActive() == SDL_FALSE)
|
||||||
{
|
{
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
class Point;
|
class Point;
|
||||||
|
class Rect;
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
class IScreenHandler
|
class IScreenHandler
|
||||||
@@ -33,4 +34,7 @@ public:
|
|||||||
|
|
||||||
/// Returns <min, max> range of possible values for screen scaling percentage
|
/// Returns <min, max> range of possible values for screen scaling percentage
|
||||||
virtual std::tuple<int, int> getSupportedScalingRange() const = 0;
|
virtual std::tuple<int, int> getSupportedScalingRange() const = 0;
|
||||||
|
|
||||||
|
/// Converts provided rect from logical coordinates into coordinates within window, accounting for scaling and viewport
|
||||||
|
virtual Rect convertLogicalPointsToWindow(const Rect & input) const = 0;
|
||||||
};
|
};
|
||||||
|
@@ -50,6 +50,32 @@ std::tuple<int, int> ScreenHandler::getSupportedScalingRange() const
|
|||||||
return { minimalScaling, maximalScaling };
|
return { minimalScaling, maximalScaling };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect ScreenHandler::convertLogicalPointsToWindow(const Rect & input) const
|
||||||
|
{
|
||||||
|
Rect result;
|
||||||
|
|
||||||
|
// FIXME: use SDL_RenderLogicalToWindow instead? Needs to be tested on ios
|
||||||
|
|
||||||
|
float scaleX, scaleY;
|
||||||
|
SDL_Rect viewport;
|
||||||
|
SDL_RenderGetScale(mainRenderer, &scaleX, &scaleY);
|
||||||
|
SDL_RenderGetViewport(mainRenderer, &viewport);
|
||||||
|
|
||||||
|
#ifdef VCMI_IOS
|
||||||
|
// TODO ios: looks like SDL bug actually, try fixing there
|
||||||
|
const auto nativeScale = iOS_utils::screenScale();
|
||||||
|
scaleX /= nativeScale;
|
||||||
|
scaleY /= nativeScale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result.x = (viewport.x + input.x) * scaleX;
|
||||||
|
result.y = (viewport.y + input.y) * scaleY;
|
||||||
|
result.w = input.w * scaleX;
|
||||||
|
result.h = input.h * scaleY;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Point ScreenHandler::getPreferredLogicalResolution() const
|
Point ScreenHandler::getPreferredLogicalResolution() const
|
||||||
{
|
{
|
||||||
Point renderResolution = getPreferredRenderingResolution();
|
Point renderResolution = getPreferredRenderingResolution();
|
||||||
|
@@ -86,4 +86,5 @@ public:
|
|||||||
std::vector<Point> getSupportedResolutions() const final;
|
std::vector<Point> getSupportedResolutions() const final;
|
||||||
std::vector<Point> getSupportedResolutions(int displayIndex) const;
|
std::vector<Point> getSupportedResolutions(int displayIndex) const;
|
||||||
std::tuple<int, int> getSupportedScalingRange() const final;
|
std::tuple<int, int> getSupportedScalingRange() const final;
|
||||||
|
Rect convertLogicalPointsToWindow(const Rect & input) const final;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user