mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Added IWindowHandler interface for OS screen/window utilities
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
#include "gui/NotificationHandler.h"
|
#include "gui/NotificationHandler.h"
|
||||||
#include "ClientCommandManager.h"
|
#include "ClientCommandManager.h"
|
||||||
#include "windows/CMessage.h"
|
#include "windows/CMessage.h"
|
||||||
#include "renderSDL/WindowHandler.h"
|
#include "render/IWindowHandler.h"
|
||||||
|
|
||||||
#include "../lib/filesystem/Filesystem.h"
|
#include "../lib/filesystem/Filesystem.h"
|
||||||
#include "../lib/CConsoleHandler.h"
|
#include "../lib/CConsoleHandler.h"
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ set(client_HEADERS
|
|||||||
render/IFont.h
|
render/IFont.h
|
||||||
render/IImage.h
|
render/IImage.h
|
||||||
render/IImageLoader.h
|
render/IImageLoader.h
|
||||||
|
render/IWindowHandler.h
|
||||||
|
|
||||||
renderSDL/CBitmapFont.h
|
renderSDL/CBitmapFont.h
|
||||||
renderSDL/CBitmapHanFont.h
|
renderSDL/CBitmapHanFont.h
|
||||||
|
|||||||
@@ -807,7 +807,7 @@ void CGuiHandler::pushUserEvent(EUserEvent usercode, void * userdata)
|
|||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowHandler & CGuiHandler::windowHandler()
|
IWindowHandler & CGuiHandler::windowHandler()
|
||||||
{
|
{
|
||||||
return *windowHandlerInstance;
|
return *windowHandlerInstance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class CIntObject;
|
|||||||
class IUpdateable;
|
class IUpdateable;
|
||||||
class IShowActivatable;
|
class IShowActivatable;
|
||||||
class IShowable;
|
class IShowable;
|
||||||
class WindowHandler;
|
class IWindowHandler;
|
||||||
|
|
||||||
// TODO: event handling need refactoring
|
// TODO: event handling need refactoring
|
||||||
enum class EUserEvent
|
enum class EUserEvent
|
||||||
@@ -96,7 +96,7 @@ private:
|
|||||||
CIntObjectList doubleClickInterested;
|
CIntObjectList doubleClickInterested;
|
||||||
CIntObjectList textInterested;
|
CIntObjectList textInterested;
|
||||||
|
|
||||||
std::unique_ptr<WindowHandler> windowHandlerInstance;
|
std::unique_ptr<IWindowHandler> windowHandlerInstance;
|
||||||
|
|
||||||
void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed);
|
void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed);
|
||||||
void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);
|
void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);
|
||||||
@@ -137,7 +137,7 @@ public:
|
|||||||
/// moves mouse pointer into specified position inside vcmi window
|
/// moves mouse pointer into specified position inside vcmi window
|
||||||
void moveCursorToPosition(const Point & position);
|
void moveCursorToPosition(const Point & position);
|
||||||
|
|
||||||
WindowHandler & windowHandler();
|
IWindowHandler & windowHandler();
|
||||||
|
|
||||||
IUpdateable *curInt;
|
IUpdateable *curInt;
|
||||||
|
|
||||||
|
|||||||
33
client/render/IWindowHandler.h
Normal file
33
client/render/IWindowHandler.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* IWindowHandler.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
class Point;
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
|
class IWindowHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IWindowHandler() = default;
|
||||||
|
|
||||||
|
/// Updates window state after fullscreen state has been changed in settings
|
||||||
|
virtual void onFullscreenChanged() = 0;
|
||||||
|
|
||||||
|
/// De-initializes window state
|
||||||
|
virtual void close() = 0;
|
||||||
|
|
||||||
|
/// Fills screen with black color, erasing any existing content
|
||||||
|
virtual void clearScreen() = 0;
|
||||||
|
|
||||||
|
/// Returns list of resolutions supported by current screen
|
||||||
|
virtual std::vector<Point> getSupportedResolutions() const = 0;
|
||||||
|
};
|
||||||
@@ -861,43 +861,6 @@ void CSDL_Ext::getClipRect(SDL_Surface * src, Rect & other)
|
|||||||
other = CSDL_Ext::fromSDL(rect);
|
other = CSDL_Ext::fromSDL(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSDL_Ext::isResolutionSupported(const std::vector<Point> & resolutions, const Point toTest )
|
|
||||||
{
|
|
||||||
#if defined(VCMI_MOBILE)
|
|
||||||
// ios can use any resolution
|
|
||||||
// presumably, same goes for Android
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
// in fullscreen only resolutions supported by monitor can be used
|
|
||||||
return vstd::contains(resolutions, toTest);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Point> CSDL_Ext::getSupportedResolutions()
|
|
||||||
{
|
|
||||||
int displayID = SDL_GetWindowDisplayIndex(mainWindow);
|
|
||||||
return getSupportedResolutions(displayID);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Point> CSDL_Ext::getSupportedResolutions( int displayIndex)
|
|
||||||
{
|
|
||||||
std::vector<Point> result;
|
|
||||||
|
|
||||||
int modesCount = SDL_GetNumDisplayModes(displayIndex);
|
|
||||||
|
|
||||||
for (int i =0; i < modesCount; ++i)
|
|
||||||
{
|
|
||||||
SDL_DisplayMode mode;
|
|
||||||
if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Point resolution(mode.w, mode.h);
|
|
||||||
|
|
||||||
result.push_back(resolution);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
|
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<2>(int, int);
|
||||||
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<3>(int, int);
|
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<3>(int, int);
|
||||||
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<4>(int, int);
|
template SDL_Surface * CSDL_Ext::createSurfaceWithBpp<4>(int, int);
|
||||||
|
|||||||
@@ -105,11 +105,6 @@ using TColorPutterAlpha = void (*)(uint8_t *&, const uint8_t &, const uint8_t &,
|
|||||||
void convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect);
|
void convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect);
|
||||||
void convertToGrayscale(SDL_Surface * surf, const Rect & rect);
|
void convertToGrayscale(SDL_Surface * surf, const Rect & rect);
|
||||||
|
|
||||||
bool isResolutionSupported(const std::vector<Point> & resolutions, const Point toTest);
|
|
||||||
|
|
||||||
std::vector<Point> getSupportedResolutions();
|
|
||||||
std::vector<Point> getSupportedResolutions(int displayIndex);
|
|
||||||
|
|
||||||
void setColorKey(SDL_Surface * surface, SDL_Color color);
|
void setColorKey(SDL_Surface * surface, SDL_Color color);
|
||||||
|
|
||||||
///set key-color to 0,255,255
|
///set key-color to 0,255,255
|
||||||
|
|||||||
@@ -424,3 +424,30 @@ void WindowHandler::clearScreen()
|
|||||||
SDL_RenderClear(mainRenderer);
|
SDL_RenderClear(mainRenderer);
|
||||||
SDL_RenderPresent(mainRenderer);
|
SDL_RenderPresent(mainRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Point> WindowHandler::getSupportedResolutions() const
|
||||||
|
{
|
||||||
|
int displayID = SDL_GetWindowDisplayIndex(mainWindow);
|
||||||
|
return getSupportedResolutions(displayID);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Point> WindowHandler::getSupportedResolutions( int displayIndex) const
|
||||||
|
{
|
||||||
|
//TODO: check this method on iOS / Android
|
||||||
|
|
||||||
|
std::vector<Point> result;
|
||||||
|
|
||||||
|
int modesCount = SDL_GetNumDisplayModes(displayIndex);
|
||||||
|
|
||||||
|
for (int i =0; i < modesCount; ++i)
|
||||||
|
{
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
if (SDL_GetDisplayMode(displayIndex, i, &mode) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Point resolution(mode.w, mode.h);
|
||||||
|
|
||||||
|
result.push_back(resolution);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ struct SDL_Renderer;
|
|||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
|
|
||||||
#include "../../lib/Point.h"
|
#include "../../lib/Point.h"
|
||||||
|
#include "../render/IWindowHandler.h"
|
||||||
|
|
||||||
enum class EWindowMode
|
enum class EWindowMode
|
||||||
{
|
{
|
||||||
@@ -29,7 +30,7 @@ enum class EWindowMode
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// This class is responsible for management of game window and its main rendering surface
|
/// This class is responsible for management of game window and its main rendering surface
|
||||||
class WindowHandler
|
class WindowHandler : public IWindowHandler
|
||||||
{
|
{
|
||||||
/// Dimensions of target surfaces/textures, this value is what game logic views as screen size
|
/// Dimensions of target surfaces/textures, this value is what game logic views as screen size
|
||||||
Point getPreferredLogicalResolution() const;
|
Point getPreferredLogicalResolution() const;
|
||||||
@@ -67,11 +68,14 @@ public:
|
|||||||
WindowHandler();
|
WindowHandler();
|
||||||
|
|
||||||
/// Updates and potentially recreates target screen to match selected fullscreen status
|
/// Updates and potentially recreates target screen to match selected fullscreen status
|
||||||
void onFullscreenChanged();
|
void onFullscreenChanged() final;
|
||||||
|
|
||||||
/// De-initializes and destroys screen, window and SDL state
|
/// De-initializes and destroys screen, window and SDL state
|
||||||
void close();
|
void close() final;
|
||||||
|
|
||||||
/// Fills screen with black color, erasing any existing content
|
/// Fills screen with black color, erasing any existing content
|
||||||
void clearScreen();
|
void clearScreen() final;
|
||||||
|
|
||||||
|
std::vector<Point> getSupportedResolutions() const final;
|
||||||
|
std::vector<Point> getSupportedResolutions(int displayIndex) const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user